resettokenbackgroundjob.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * @author Lukas Reschke <lukas@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2016, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace OCA\UpdateNotification;
  22. use OC\AppFramework\Utility\TimeFactory;
  23. use OC\BackgroundJob\TimedJob;
  24. use OCP\AppFramework\Utility\ITimeFactory;
  25. use OCP\IConfig;
  26. /**
  27. * Class ResetTokenBackgroundJob deletes any configured token all 24 hours for
  28. *
  29. *
  30. * @package OCA\UpdateNotification
  31. */
  32. class ResetTokenBackgroundJob extends TimedJob {
  33. /** @var IConfig */
  34. private $config;
  35. /** @var ITimeFactory */
  36. private $timeFactory;
  37. /**
  38. * @param IConfig|null $config
  39. * @param ITimeFactory|null $timeFactory
  40. */
  41. public function __construct(IConfig $config = null,
  42. ITimeFactory $timeFactory = null) {
  43. // Run all 10 minutes
  44. $this->setInterval(60 * 10);
  45. if ($config instanceof IConfig && $timeFactory instanceof ITimeFactory) {
  46. $this->config = $config;
  47. $this->timeFactory = $timeFactory;
  48. } else {
  49. $this->fixDIForJobs();
  50. }
  51. }
  52. /**
  53. * DI for jobs
  54. */
  55. private function fixDIForJobs() {
  56. $this->config = \OC::$server->getConfig();
  57. $this->timeFactory = new TimeFactory();
  58. }
  59. /**
  60. * @param $argument
  61. */
  62. protected function run($argument) {
  63. // Delete old tokens after 2 days
  64. if($this->timeFactory->getTime() - $this->config->getAppValue('core', 'updater.secret.created', $this->timeFactory->getTime()) >= 172800) {
  65. $this->config->deleteSystemValue('updater.secret');
  66. }
  67. }
  68. }