ResetTokenBackgroundJob.php 2.0 KB

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