1
0

ResetToken.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\UpdateNotification\BackgroundJob;
  8. use OCP\AppFramework\Utility\ITimeFactory;
  9. use OCP\BackgroundJob\TimedJob;
  10. use OCP\IAppConfig;
  11. use OCP\IConfig;
  12. /**
  13. * Deletes the updater secret after if it is older than 48h
  14. */
  15. class ResetToken extends TimedJob {
  16. /**
  17. * @param IConfig $config
  18. * @param ITimeFactory $timeFactory
  19. */
  20. public function __construct(
  21. ITimeFactory $time,
  22. private IConfig $config,
  23. private IAppConfig $appConfig,
  24. ) {
  25. parent::__construct($time);
  26. // Run all 10 minutes
  27. parent::setInterval(60 * 10);
  28. }
  29. /**
  30. * @param $argument
  31. */
  32. protected function run($argument) {
  33. if ($this->config->getSystemValueBool('config_is_read_only')) {
  34. return;
  35. }
  36. $secretCreated = $this->appConfig->getValueInt('core', 'updater.secret.created', $this->time->getTime());
  37. // Delete old tokens after 2 days
  38. if ($secretCreated >= 172800) {
  39. $this->config->deleteSystemValue('updater.secret');
  40. }
  41. }
  42. }