1
0

ResetTokenBackgroundJob.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. }