From 96253c7c1b02c9e3a5506198c179dd7a32d01fbe Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 14 Dec 2020 16:35:12 +0100 Subject: [PATCH] Add missing parent::__construct() calls to Jobs Signed-off-by: Joas Schilling --- .../lib/BackgroundJob/RetryJob.php | 33 +++++-------------- .../lib/BackgroundJob/GetSharedSecret.php | 11 +++---- .../lib/BackgroundJob/RequestSharedSecret.php | 11 +++---- .../lib/BackgroundJobs/VerifyUserData.php | 12 ++----- 4 files changed, 19 insertions(+), 48 deletions(-) diff --git a/apps/federatedfilesharing/lib/BackgroundJob/RetryJob.php b/apps/federatedfilesharing/lib/BackgroundJob/RetryJob.php index 4949e5794b4..14d86d4b444 100644 --- a/apps/federatedfilesharing/lib/BackgroundJob/RetryJob.php +++ b/apps/federatedfilesharing/lib/BackgroundJob/RetryJob.php @@ -29,6 +29,7 @@ namespace OCA\FederatedFileSharing\BackgroundJob; use OCA\FederatedFileSharing\AddressHandler; use OCA\FederatedFileSharing\Notifications; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\IJobList; use OCP\BackgroundJob\Job; use OCP\ILogger; @@ -55,29 +56,11 @@ class RetryJob extends Job { /** @var int how much time should be between two tries (10 minutes) */ private $interval = 600; - /** - * UnShare constructor. - * - * @param Notifications $notifications - */ - public function __construct(Notifications $notifications = null) { - if ($notifications) { - $this->notifications = $notifications; - } else { - $addressHandler = new AddressHandler( - \OC::$server->getURLGenerator(), - \OC::$server->getL10N('federatedfilesharing'), - \OC::$server->getCloudIdManager() - ); - $this->notifications = new Notifications( - $addressHandler, - \OC::$server->getHTTPClientService(), - \OC::$server->query(\OCP\OCS\IDiscoveryService::class), - \OC::$server->getJobList(), - \OC::$server->getCloudFederationProviderManager(), - \OC::$server->getCloudFederationFactory() - ); - } + + public function __construct(Notifications $notifications, + ITimeFactory $timeFactory) { + parent::__construct($timeFactory); + $this->notifications = $notifications; } /** @@ -126,7 +109,7 @@ class RetryJob extends Job { 'data' => $argument['data'], 'action' => $argument['action'], 'try' => (int)$argument['try'] + 1, - 'lastRun' => time() + 'lastRun' => $this->time->getTime() ] ); } @@ -139,6 +122,6 @@ class RetryJob extends Job { */ protected function shouldRun(array $argument) { $lastRun = (int)$argument['lastRun']; - return ((time() - $lastRun) > $this->interval); + return (($this->time->getTime() - $lastRun) > $this->interval); } } diff --git a/apps/federation/lib/BackgroundJob/GetSharedSecret.php b/apps/federation/lib/BackgroundJob/GetSharedSecret.php index 71ea5417dd0..9390b047a91 100644 --- a/apps/federation/lib/BackgroundJob/GetSharedSecret.php +++ b/apps/federation/lib/BackgroundJob/GetSharedSecret.php @@ -71,9 +71,6 @@ class GetSharedSecret extends Job { /** @var ILogger */ private $logger; - /** @var ITimeFactory */ - private $timeFactory; - /** @var bool */ protected $retainJob = false; @@ -102,13 +99,13 @@ class GetSharedSecret extends Job { IDiscoveryService $ocsDiscoveryService, ITimeFactory $timeFactory ) { + parent::__construct($timeFactory); $this->logger = $logger; $this->httpClient = $httpClientService->newClient(); $this->jobList = $jobList; $this->urlGenerator = $urlGenerator; $this->ocsDiscoveryService = $ocsDiscoveryService; $this->trustedServers = $trustedServers; - $this->timeFactory = $timeFactory; } /** @@ -143,8 +140,8 @@ class GetSharedSecret extends Job { protected function run($argument) { $target = $argument['url']; - $created = isset($argument['created']) ? (int)$argument['created'] : $this->timeFactory->getTime(); - $currentTime = $this->timeFactory->getTime(); + $created = isset($argument['created']) ? (int)$argument['created'] : $this->time->getTime(); + $currentTime = $this->time->getTime(); $source = $this->urlGenerator->getAbsoluteURL('/'); $source = rtrim($source, '/'); $token = $argument['token']; @@ -239,7 +236,7 @@ class GetSharedSecret extends Job { */ protected function reAddJob(array $argument) { $url = $argument['url']; - $created = isset($argument['created']) ? (int)$argument['created'] : $this->timeFactory->getTime(); + $created = isset($argument['created']) ? (int)$argument['created'] : $this->time->getTime(); $token = $argument['token']; $this->jobList->add( GetSharedSecret::class, diff --git a/apps/federation/lib/BackgroundJob/RequestSharedSecret.php b/apps/federation/lib/BackgroundJob/RequestSharedSecret.php index 1c9b2539b3d..c9bee9fa6be 100644 --- a/apps/federation/lib/BackgroundJob/RequestSharedSecret.php +++ b/apps/federation/lib/BackgroundJob/RequestSharedSecret.php @@ -69,9 +69,6 @@ class RequestSharedSecret extends Job { /** @var ILogger */ private $logger; - /** @var ITimeFactory */ - private $timeFactory; - /** @var bool */ protected $retainJob = false; @@ -100,13 +97,13 @@ class RequestSharedSecret extends Job { ILogger $logger, ITimeFactory $timeFactory ) { + parent::__construct($timeFactory); $this->httpClient = $httpClientService->newClient(); $this->jobList = $jobList; $this->urlGenerator = $urlGenerator; $this->logger = $logger; $this->ocsDiscoveryService = $ocsDiscoveryService; $this->trustedServers = $trustedServers; - $this->timeFactory = $timeFactory; } @@ -142,8 +139,8 @@ class RequestSharedSecret extends Job { protected function run($argument) { $target = $argument['url']; - $created = isset($argument['created']) ? (int)$argument['created'] : $this->timeFactory->getTime(); - $currentTime = $this->timeFactory->getTime(); + $created = isset($argument['created']) ? (int)$argument['created'] : $this->time->getTime(); + $currentTime = $this->time->getTime(); $source = $this->urlGenerator->getAbsoluteURL('/'); $source = rtrim($source, '/'); $token = $argument['token']; @@ -211,7 +208,7 @@ class RequestSharedSecret extends Job { */ protected function reAddJob(array $argument) { $url = $argument['url']; - $created = isset($argument['created']) ? (int)$argument['created'] : $this->timeFactory->getTime(); + $created = isset($argument['created']) ? (int)$argument['created'] : $this->time->getTime(); $token = $argument['token']; $this->jobList->add( diff --git a/apps/settings/lib/BackgroundJobs/VerifyUserData.php b/apps/settings/lib/BackgroundJobs/VerifyUserData.php index d1b6d835fa4..cb671f33466 100644 --- a/apps/settings/lib/BackgroundJobs/VerifyUserData.php +++ b/apps/settings/lib/BackgroundJobs/VerifyUserData.php @@ -32,6 +32,7 @@ namespace OCA\Settings\BackgroundJobs; use OC\Accounts\AccountManager; use OCP\Accounts\IAccountManager; use OCP\AppFramework\Http; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\IJobList; use OCP\BackgroundJob\Job; use OCP\Http\Client\IClientService; @@ -68,21 +69,14 @@ class VerifyUserData extends Job { /** @var IConfig */ private $config; - /** - * VerifyUserData constructor. - * - * @param AccountManager $accountManager - * @param IUserManager $userManager - * @param IClientService $clientService - * @param ILogger $logger - * @param IConfig $config - */ public function __construct(AccountManager $accountManager, IUserManager $userManager, IClientService $clientService, ILogger $logger, + ITimeFactory $timeFactory, IConfig $config ) { + parent::__construct($timeFactory); $this->accountManager = $accountManager; $this->userManager = $userManager; $this->httpClientService = $clientService; -- 2.39.5