2016-02-09 13:58:29 -05:00
|
|
|
<?php
|
2019-12-03 13:57:53 -05:00
|
|
|
|
2018-01-17 07:42:02 -05:00
|
|
|
declare(strict_types=1);
|
2019-12-03 13:57:53 -05:00
|
|
|
|
2016-02-09 13:58:29 -05:00
|
|
|
/**
|
2024-05-30 14:13:41 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2016-02-09 13:58:29 -05:00
|
|
|
*/
|
2024-03-02 15:04:56 -05:00
|
|
|
namespace OCA\UpdateNotification\BackgroundJob;
|
2016-02-09 13:58:29 -05:00
|
|
|
|
|
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
2022-05-25 02:52:39 -04:00
|
|
|
use OCP\BackgroundJob\TimedJob;
|
2024-03-02 15:04:56 -05:00
|
|
|
use OCP\IAppConfig;
|
2016-02-09 13:58:29 -05:00
|
|
|
use OCP\IConfig;
|
|
|
|
|
|
|
|
|
|
/**
|
2024-03-02 15:04:56 -05:00
|
|
|
* Deletes the updater secret after if it is older than 48h
|
2016-02-09 13:58:29 -05:00
|
|
|
*/
|
2024-03-02 15:04:56 -05:00
|
|
|
class ResetToken extends TimedJob {
|
2016-02-09 13:58:29 -05:00
|
|
|
|
|
|
|
|
/**
|
2018-01-11 04:59:10 -05:00
|
|
|
* @param IConfig $config
|
|
|
|
|
* @param ITimeFactory $timeFactory
|
2016-02-09 13:58:29 -05:00
|
|
|
*/
|
2024-03-02 15:04:56 -05:00
|
|
|
public function __construct(
|
|
|
|
|
ITimeFactory $time,
|
|
|
|
|
private IConfig $config,
|
|
|
|
|
private IAppConfig $appConfig,
|
|
|
|
|
) {
|
|
|
|
|
parent::__construct($time);
|
2016-02-09 13:58:29 -05:00
|
|
|
// Run all 10 minutes
|
2022-05-25 02:52:39 -04:00
|
|
|
parent::setInterval(60 * 10);
|
2016-02-09 13:58:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param $argument
|
|
|
|
|
*/
|
|
|
|
|
protected function run($argument) {
|
2024-03-04 06:03:09 -05:00
|
|
|
if ($this->config->getSystemValueBool('config_is_read_only')) {
|
2024-03-02 15:04:56 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$secretCreated = $this->appConfig->getValueInt('core', 'updater.secret.created', $this->time->getTime());
|
2016-02-10 08:41:47 -05:00
|
|
|
// Delete old tokens after 2 days
|
2024-03-02 15:04:56 -05:00
|
|
|
if ($secretCreated >= 172800) {
|
2016-02-09 13:58:29 -05:00
|
|
|
$this->config->deleteSystemValue('updater.secret');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|