From b700c8bc17154d0ecc87eae3b143a96b281b4fcf Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Tue, 28 Jun 2022 12:55:26 +0200 Subject: [PATCH] Port existing server code to new interface Signed-off-by: Carl Schwan --- .../lib/BackgroundJob/RetryJob.php | 36 ++++--------- .../lib/BackgroundJob/GetSharedSecret.php | 31 +++-------- .../BackgroundJob/GetSharedSecretTest.php | 3 +- apps/files/lib/BackgroundJob/ScanFiles.php | 23 ++++---- .../tests/BackgroundJob/ScanFilesTest.php | 2 + .../lib/BackgroundJob/ExpireTrash.php | 52 ++++++------------- .../lib/BackgroundJob/ExpireVersions.php | 26 ++++------ .../lib/BackgroundJobs/RetryJob.php | 37 +++++-------- apps/user_ldap/lib/Jobs/Sync.php | 8 +-- .../BackgroundCleanupUpdaterBackupsJob.php | 6 ++- .../CheckForUserCertificates.php | 6 ++- .../LookupServerSendCheckBackgroundJob.php | 6 ++- lib/private/BackgroundJob/Job.php | 4 ++ .../BackgroundJob/Legacy/QueuedJob.php | 2 +- .../BackgroundJob/Legacy/RegularJob.php | 2 +- lib/private/BackgroundJob/QueuedJob.php | 1 + lib/private/Command/CallableJob.php | 2 +- lib/private/Command/ClosureJob.php | 2 +- lib/private/Command/CommandJob.php | 2 +- lib/private/Log/Rotate.php | 2 +- lib/private/Migration/BackgroundRepair.php | 41 +++++---------- .../Security/VerificationToken/CleanUpJob.php | 30 +++++------ lib/public/BackgroundJob/Job.php | 1 + lib/public/BackgroundJob/QueuedJob.php | 2 +- 24 files changed, 123 insertions(+), 204 deletions(-) diff --git a/apps/federatedfilesharing/lib/BackgroundJob/RetryJob.php b/apps/federatedfilesharing/lib/BackgroundJob/RetryJob.php index cf0691de3ac15..f785f4fc52861 100644 --- a/apps/federatedfilesharing/lib/BackgroundJob/RetryJob.php +++ b/apps/federatedfilesharing/lib/BackgroundJob/RetryJob.php @@ -41,19 +41,14 @@ * @package OCA\FederatedFileSharing\BackgroundJob */ class RetryJob extends Job { - - /** @var bool */ - private $retainJob = true; - - /** @var Notifications */ - private $notifications; + private bool $retainJob = true; + private Notifications $notifications; /** @var int max number of attempts to send the request */ - private $maxTry = 20; + private int $maxTry = 20; /** @var int how much time should be between two tries (10 minutes) */ - private $interval = 600; - + private int $interval = 600; public function __construct(Notifications $notifications, ITimeFactory $time) { @@ -62,14 +57,11 @@ public function __construct(Notifications $notifications, } /** - * run the job, then remove it from the jobList - * - * @param IJobList $jobList - * @param ILogger|null $logger + * Run the job, then remove it from the jobList */ - public function execute(IJobList $jobList, ILogger $logger = null) { + public function start(IJobList $jobList): void { if ($this->shouldRun($this->argument)) { - parent::execute($jobList, $logger); + parent::start($jobList); $jobList->remove($this, $this->argument); if ($this->retainJob) { $this->reAddJob($jobList, $this->argument); @@ -93,12 +85,9 @@ protected function run($argument) { } /** - * re-add background job with new arguments - * - * @param IJobList $jobList - * @param array $argument + * Re-add background job with new arguments */ - protected function reAddJob(IJobList $jobList, array $argument) { + protected function reAddJob(IJobList $jobList, array $argument): void { $jobList->add(RetryJob::class, [ 'remote' => $argument['remote'], @@ -113,12 +102,9 @@ protected function reAddJob(IJobList $jobList, array $argument) { } /** - * test if it is time for the next run - * - * @param array $argument - * @return bool + * Test if it is time for the next run */ - protected function shouldRun(array $argument) { + protected function shouldRun(array $argument): bool { $lastRun = (int)$argument['lastRun']; return (($this->time->getTime() - $lastRun) > $this->interval); } diff --git a/apps/federation/lib/BackgroundJob/GetSharedSecret.php b/apps/federation/lib/BackgroundJob/GetSharedSecret.php index 75faa7ce1d960..46629e76f1342 100644 --- a/apps/federation/lib/BackgroundJob/GetSharedSecret.php +++ b/apps/federation/lib/BackgroundJob/GetSharedSecret.php @@ -39,7 +39,6 @@ use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; use OCP\Http\Client\IResponse; -use OCP\ILogger; use OCP\IURLGenerator; use OCP\OCS\IDiscoveryService; use Psr\Log\LoggerInterface; @@ -60,7 +59,6 @@ class GetSharedSecret extends Job { private LoggerInterface $logger; protected bool $retainJob = false; private string $defaultEndPoint = '/ocs/v2.php/apps/federation/api/v1/shared-secret'; - /** 30 day = 2592000sec */ private int $maxLifespan = 2592000; @@ -83,16 +81,13 @@ public function __construct( } /** - * run the job, then remove it from the joblist - * - * @param IJobList $jobList - * @param ILogger|null $logger + * Run the job, then remove it from the joblist */ - public function execute(IJobList $jobList, ILogger $logger = null) { + public function start(IJobList $jobList): void { $target = $this->argument['url']; // only execute if target is still in the list of trusted domains if ($this->trustedServers->isTrustedServer($target)) { - $this->parentExecute($jobList, $logger); + parent::start($jobList); } $jobList->remove($this, $this->argument); @@ -102,16 +97,6 @@ public function execute(IJobList $jobList, ILogger $logger = null) { } } - /** - * Call execute() method of parent - * - * @param IJobList $jobList - * @param ILogger $logger - */ - protected function parentExecute($jobList, $logger = null) { - parent::execute($jobList, $logger); - } - protected function run($argument) { $target = $argument['url']; $created = isset($argument['created']) ? (int)$argument['created'] : $this->time->getTime(); @@ -162,12 +147,10 @@ protected function run($argument) { $status = -1; // There is no status code if we could not connect $this->logger->info('Could not connect to ' . $target, [ 'exception' => $e, - 'app' => 'federation', ]); } catch (\Throwable $e) { $status = Http::STATUS_INTERNAL_SERVER_ERROR; $this->logger->error($e->getMessage(), [ - 'app' => 'federation', 'exception' => $e, ]); } @@ -190,8 +173,8 @@ protected function run($argument) { ); } else { $this->logger->error( - 'remote server "' . $target . '"" does not return a valid shared secret. Received data: ' . $body, - ['app' => 'federation'] + 'remote server "' . $target . '"" does not return a valid shared secret. Received data: ' . $body, + ['app' => 'federation'] ); $this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE); } @@ -199,13 +182,13 @@ protected function run($argument) { } /** - * re-add background job + * Re-add background job * * @param array $argument */ protected function reAddJob(array $argument): void { $url = $argument['url']; - $created = isset($argument['created']) ? (int)$argument['created'] : $this->time->getTime(); + $created = $argument['created'] ?? $this->time->getTime(); $token = $argument['token']; $this->jobList->add( GetSharedSecret::class, diff --git a/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php b/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php index 5344736b7f9dd..ae4fb4d3b1b38 100644 --- a/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php +++ b/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php @@ -76,8 +76,7 @@ class GetSharedSecretTest extends TestCase { /** @var \PHPUnit\Framework\MockObject\MockObject|ITimeFactory */ private $timeFactory; - /** @var GetSharedSecret */ - private $getSharedSecret; + private GetSharedSecret $getSharedSecret; protected function setUp(): void { parent::setUp(); diff --git a/apps/files/lib/BackgroundJob/ScanFiles.php b/apps/files/lib/BackgroundJob/ScanFiles.php index 07794a2877454..8dc9dcf37ff9e 100644 --- a/apps/files/lib/BackgroundJob/ScanFiles.php +++ b/apps/files/lib/BackgroundJob/ScanFiles.php @@ -25,6 +25,8 @@ namespace OCA\Files\BackgroundJob; use OC\Files\Utils\Scanner; +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\BackgroundJob\TimedJob; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; @@ -37,13 +39,11 @@ * * @package OCA\Files\BackgroundJob */ -class ScanFiles extends \OC\BackgroundJob\TimedJob { - /** @var IConfig */ - private $config; - /** @var IEventDispatcher */ - private $dispatcher; +class ScanFiles extends TimedJob { + private IConfig $config; + private IEventDispatcher $dispatcher; private LoggerInterface $logger; - private $connection; + private IDBConnection $connection; /** Amount of users that should get scanned per execution */ public const USERS_PER_SESSION = 500; @@ -52,8 +52,10 @@ public function __construct( IConfig $config, IEventDispatcher $dispatcher, LoggerInterface $logger, - IDBConnection $connection + IDBConnection $connection, + ITimeFactory $time ) { + parent::__construct($time); // Run once per 10 minutes $this->setInterval(60 * 10); @@ -63,10 +65,7 @@ public function __construct( $this->connection = $connection; } - /** - * @param string $user - */ - protected function runScanner(string $user) { + protected function runScanner(string $user): void { try { $scanner = new Scanner( $user, @@ -95,7 +94,7 @@ private function getUserToScan() { ->andWhere($query->expr()->gt('parent', $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT))) ->setMaxResults(1); - return $query->execute()->fetchOne(); + return $query->executeQuery()->fetchOne(); } /** diff --git a/apps/files/tests/BackgroundJob/ScanFilesTest.php b/apps/files/tests/BackgroundJob/ScanFilesTest.php index 5b2d52b48d3c8..cf0120da09d6e 100644 --- a/apps/files/tests/BackgroundJob/ScanFilesTest.php +++ b/apps/files/tests/BackgroundJob/ScanFilesTest.php @@ -26,6 +26,7 @@ use OC\Files\Mount\MountPoint; use OC\Files\Storage\Temporary; use OCA\Files\BackgroundJob\ScanFiles; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IUser; @@ -64,6 +65,7 @@ protected function setUp(): void { $dispatcher, $logger, $connection, + $this->createMock(ITimeFactory::class) ]) ->setMethods(['runScanner']) ->getMock(); diff --git a/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php index 9e35273544b85..c76033e0c7944 100644 --- a/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php +++ b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php @@ -30,46 +30,30 @@ use OCA\Files_Trashbin\Expiration; use OCA\Files_Trashbin\Helper; use OCA\Files_Trashbin\Trashbin; +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\BackgroundJob\TimedJob; use OCP\IConfig; use OCP\IUser; use OCP\IUserManager; -class ExpireTrash extends \OC\BackgroundJob\TimedJob { +class ExpireTrash extends TimedJob { + private IConfig $config; + private Expiration $expiration; + private IUserManager $userManager; - /** @var IConfig */ - private $config; - - /** - * @var Expiration - */ - private $expiration; - - /** - * @var IUserManager - */ - private $userManager; - - public function __construct(IConfig $config = null, - IUserManager $userManager = null, - Expiration $expiration = null) { + public function __construct( + IConfig $config, + IUserManager $userManager, + Expiration $expiration, + ITimeFactory $time + ) { + parent::__construct($time); // Run once per 30 minutes $this->setInterval(60 * 30); - if ($config === null || $expiration === null || $userManager === null) { - $this->fixDIForJobs(); - } else { - $this->config = $config; - $this->userManager = $userManager; - $this->expiration = $expiration; - } - } - - protected function fixDIForJobs() { - /** @var Application $application */ - $application = \OC::$server->query(Application::class); - $this->config = $application->getContainer()->get(IConfig::class); - $this->userManager = \OC::$server->getUserManager(); - $this->expiration = $application->getContainer()->query('Expiration'); + $this->config = $config; + $this->userManager = $userManager; + $this->expiration = $expiration; } /** @@ -101,10 +85,8 @@ protected function run($argument) { /** * Act on behalf on trash item owner - * @param string $user - * @return boolean */ - protected function setupFS($user) { + protected function setupFS(string $user): bool { \OC_Util::tearDownFS(); \OC_Util::setupFS($user); diff --git a/apps/files_versions/lib/BackgroundJob/ExpireVersions.php b/apps/files_versions/lib/BackgroundJob/ExpireVersions.php index a8a311f0a057b..7e714a059d078 100644 --- a/apps/files_versions/lib/BackgroundJob/ExpireVersions.php +++ b/apps/files_versions/lib/BackgroundJob/ExpireVersions.php @@ -27,27 +27,21 @@ use OCA\Files_Versions\Expiration; use OCA\Files_Versions\Storage; +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\BackgroundJob\TimedJob; use OCP\IConfig; use OCP\IUser; use OCP\IUserManager; -class ExpireVersions extends \OC\BackgroundJob\TimedJob { +class ExpireVersions extends TimedJob { public const ITEMS_PER_SESSION = 1000; - /** @var IConfig */ - private $config; + private IConfig $config; + private Expiration $expiration; + private IUserManager $userManager; - /** - * @var Expiration - */ - private $expiration; - - /** - * @var IUserManager - */ - private $userManager; - - public function __construct(IConfig $config, IUserManager $userManager, Expiration $expiration) { + public function __construct(IConfig $config, IUserManager $userManager, Expiration $expiration, ITimeFactory $time) { + parent::__construct($time); // Run once per 30 minutes $this->setInterval(60 * 30); @@ -78,10 +72,8 @@ public function run($argument) { /** * Act on behalf on trash item owner - * @param string $user - * @return boolean */ - protected function setupFS($user) { + protected function setupFS(string $user): bool { \OC_Util::tearDownFS(); \OC_Util::setupFS($user); diff --git a/apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php b/apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php index f905f9173b658..39d8118abe71d 100644 --- a/apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php +++ b/apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php @@ -44,22 +44,14 @@ use OCP\IUserManager; class RetryJob extends Job { - /** @var IClientService */ - private $clientService; - /** @var string */ - private $lookupServer; - /** @var IConfig */ - private $config; - /** @var IUserManager */ - private $userManager; - /** @var IAccountManager */ - private $accountManager; - /** @var Signer */ - private $signer; - /** @var int */ - protected $retries = 0; - /** @var bool */ - protected $retainJob = false; + private IClientService $clientService; + private string $lookupServer; + private IConfig $config; + private IUserManager $userManager; + private IAccountManager $accountManager; + private Signer $signer; + protected int $retries = 0; + protected bool $retainJob = false; /** * @param ITimeFactory $time @@ -90,19 +82,16 @@ public function __construct(ITimeFactory $time, } /** - * run the job, then remove it from the jobList - * - * @param IJobList $jobList - * @param ILogger|null $logger + * Run the job, then remove it from the jobList */ - public function execute(IJobList $jobList, ILogger $logger = null): void { + public function start(IJobList $jobList): void { if (!isset($this->argument['userId'])) { // Old background job without user id, just drop it. $jobList->remove($this, $this->argument); return; } - $this->retries = (int) $this->config->getUserValue($this->argument['userId'], 'lookup_server_connector', 'update_retries', 0); + $this->retries = (int) $this->config->getUserValue($this->argument['userId'], 'lookup_server_connector', 'update_retries', '0'); if ($this->shouldRemoveBackgroundJob()) { $jobList->remove($this, $this->argument); @@ -110,7 +99,7 @@ public function execute(IJobList $jobList, ILogger $logger = null): void { } if ($this->shouldRun()) { - parent::execute($jobList, $logger); + parent::start($jobList); if (!$this->retainJob) { $jobList->remove($this, $this->argument); } @@ -124,8 +113,6 @@ public function execute(IJobList $jobList, ILogger $logger = null): void { * - no valid lookup server URL given * - lookup server was disabled by the admin * - max retries are reached (set to 5) - * - * @return bool */ protected function shouldRemoveBackgroundJob(): bool { return $this->config->getSystemValueBool('has_internet_connection', true) === false || diff --git a/apps/user_ldap/lib/Jobs/Sync.php b/apps/user_ldap/lib/Jobs/Sync.php index 3d0dd88dfd248..d9171f4aab722 100644 --- a/apps/user_ldap/lib/Jobs/Sync.php +++ b/apps/user_ldap/lib/Jobs/Sync.php @@ -24,7 +24,6 @@ */ namespace OCA\User_LDAP\Jobs; -use OC\BackgroundJob\TimedJob; use OC\ServerNotAvailableException; use OCA\User_LDAP\AccessFactory; use OCA\User_LDAP\Configuration; @@ -33,6 +32,8 @@ use OCA\User_LDAP\LDAP; use OCA\User_LDAP\Mapping\UserMapping; use OCA\User_LDAP\User\Manager; +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\BackgroundJob\TimedJob; use OCP\IAvatarManager; use OCP\IConfig; use OCP\IDBConnection; @@ -68,7 +69,8 @@ class Sync extends TimedJob { /** @var AccessFactory */ protected $accessFactory; - public function __construct(Manager $userManager) { + public function __construct(Manager $userManager, ITimeFactory $time) { + parent::__construct($time); $this->userManager = $userManager; $this->setInterval( \OC::$server->getConfig()->getAppValue( @@ -298,8 +300,6 @@ protected function getNextPrefix($lastPrefix) { /** * "fixes" DI - * - * @param array $argument */ public function setArgument($argument) { if (isset($argument['config'])) { diff --git a/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php b/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php index ceff579b1c793..7ab9fb47d54e2 100644 --- a/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php +++ b/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php @@ -26,7 +26,8 @@ */ namespace OC\Core\BackgroundJobs; -use OC\BackgroundJob\QueuedJob; +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\BackgroundJob\QueuedJob; use OCP\IConfig; use Psr\Log\LoggerInterface; @@ -34,7 +35,8 @@ class BackgroundCleanupUpdaterBackupsJob extends QueuedJob { protected IConfig $config; protected LoggerInterface $log; - public function __construct(IConfig $config, LoggerInterface $log) { + public function __construct(IConfig $config, LoggerInterface $log, ITimeFactory $time) { + parent::__construct($time); $this->config = $config; $this->log = $log; } diff --git a/core/BackgroundJobs/CheckForUserCertificates.php b/core/BackgroundJobs/CheckForUserCertificates.php index 492fadde854dc..11b851fff94a9 100644 --- a/core/BackgroundJobs/CheckForUserCertificates.php +++ b/core/BackgroundJobs/CheckForUserCertificates.php @@ -26,7 +26,8 @@ */ namespace OC\Core\BackgroundJobs; -use OC\BackgroundJob\QueuedJob; +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\BackgroundJob\QueuedJob; use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; @@ -39,7 +40,8 @@ class CheckForUserCertificates extends QueuedJob { private IUserManager $userManager; private IRootFolder $rootFolder; - public function __construct(IConfig $config, IUserManager $userManager, IRootFolder $rootFolder) { + public function __construct(IConfig $config, IUserManager $userManager, IRootFolder $rootFolder, ITimeFactory $time) { + parent::__construct($time); $this->config = $config; $this->userManager = $userManager; $this->rootFolder = $rootFolder; diff --git a/core/BackgroundJobs/LookupServerSendCheckBackgroundJob.php b/core/BackgroundJobs/LookupServerSendCheckBackgroundJob.php index 8945be11a1cb2..76e0550830c50 100644 --- a/core/BackgroundJobs/LookupServerSendCheckBackgroundJob.php +++ b/core/BackgroundJobs/LookupServerSendCheckBackgroundJob.php @@ -25,7 +25,8 @@ */ namespace OC\Core\BackgroundJobs; -use OC\BackgroundJob\QueuedJob; +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\BackgroundJob\QueuedJob; use OCP\IConfig; use OCP\IUser; use OCP\IUserManager; @@ -34,7 +35,8 @@ class LookupServerSendCheckBackgroundJob extends QueuedJob { protected IConfig $config; private IUserManager $userManager; - public function __construct(IConfig $config, IUserManager $userManager) { + public function __construct(IConfig $config, IUserManager $userManager, ITimeFactory $time) { + parent::__construct($time); $this->config = $config; $this->userManager = $userManager; } diff --git a/lib/private/BackgroundJob/Job.php b/lib/private/BackgroundJob/Job.php index 399ff05134e71..ffcaaf8c36d76 100644 --- a/lib/private/BackgroundJob/Job.php +++ b/lib/private/BackgroundJob/Job.php @@ -66,6 +66,10 @@ public function execute(IJobList $jobList, ILogger $logger = null) { } } + public function start(IJobList $jobList): void { + $this->execute($jobList); + } + abstract protected function run($argument); public function setId(int $id) { diff --git a/lib/private/BackgroundJob/Legacy/QueuedJob.php b/lib/private/BackgroundJob/Legacy/QueuedJob.php index fd001738d4fa1..680c12046c91e 100644 --- a/lib/private/BackgroundJob/Legacy/QueuedJob.php +++ b/lib/private/BackgroundJob/Legacy/QueuedJob.php @@ -26,7 +26,7 @@ /** * @deprecated internal class, use \OCP\BackgroundJob\QueuedJob */ -class QueuedJob extends \OC\BackgroundJob\QueuedJob { +class QueuedJob extends \OCP\BackgroundJob\QueuedJob { public function run($argument) { $class = $argument['klass']; $method = $argument['method']; diff --git a/lib/private/BackgroundJob/Legacy/RegularJob.php b/lib/private/BackgroundJob/Legacy/RegularJob.php index 0f337a35eb0ad..c01d58efa2fba 100644 --- a/lib/private/BackgroundJob/Legacy/RegularJob.php +++ b/lib/private/BackgroundJob/Legacy/RegularJob.php @@ -27,7 +27,7 @@ /** * @deprecated internal class, use \OCP\BackgroundJob\QueuedJob */ -class RegularJob extends \OC\BackgroundJob\Job { +class RegularJob extends \OCP\BackgroundJob\Job { public function run($argument) { try { if (is_callable($argument)) { diff --git a/lib/private/BackgroundJob/QueuedJob.php b/lib/private/BackgroundJob/QueuedJob.php index 28d86481e6276..0c381015961e7 100644 --- a/lib/private/BackgroundJob/QueuedJob.php +++ b/lib/private/BackgroundJob/QueuedJob.php @@ -25,6 +25,7 @@ namespace OC\BackgroundJob; use OCP\ILogger; +use Psr\Log\LoggerInterface; /** * Class QueuedJob diff --git a/lib/private/Command/CallableJob.php b/lib/private/Command/CallableJob.php index 8bb3c76c9afad..7f515660955e8 100644 --- a/lib/private/Command/CallableJob.php +++ b/lib/private/Command/CallableJob.php @@ -21,7 +21,7 @@ */ namespace OC\Command; -use OC\BackgroundJob\QueuedJob; +use OCP\BackgroundJob\QueuedJob; class CallableJob extends QueuedJob { protected function run($serializedCallable) { diff --git a/lib/private/Command/ClosureJob.php b/lib/private/Command/ClosureJob.php index 5639852e4db89..7ca45cd5fc01d 100644 --- a/lib/private/Command/ClosureJob.php +++ b/lib/private/Command/ClosureJob.php @@ -22,7 +22,7 @@ */ namespace OC\Command; -use OC\BackgroundJob\QueuedJob; +use OCP\BackgroundJob\QueuedJob; use Laravel\SerializableClosure\SerializableClosure as LaravelClosure; use Opis\Closure\SerializableClosure as OpisClosure; diff --git a/lib/private/Command/CommandJob.php b/lib/private/Command/CommandJob.php index 5b267162c81a1..477fd2a868333 100644 --- a/lib/private/Command/CommandJob.php +++ b/lib/private/Command/CommandJob.php @@ -22,7 +22,7 @@ */ namespace OC\Command; -use OC\BackgroundJob\QueuedJob; +use OCP\BackgroundJob\QueuedJob; use OCP\Command\ICommand; /** diff --git a/lib/private/Log/Rotate.php b/lib/private/Log/Rotate.php index 58b2932b417c4..20bc3327f92aa 100644 --- a/lib/private/Log/Rotate.php +++ b/lib/private/Log/Rotate.php @@ -32,7 +32,7 @@ * For more professional log management set the 'logfile' config to a different * location and manage that with your own tools. */ -class Rotate extends \OC\BackgroundJob\Job { +class Rotate extends \OCP\BackgroundJob\Job { use RotationTrait; public function run($dummy) { diff --git a/lib/private/Migration/BackgroundRepair.php b/lib/private/Migration/BackgroundRepair.php index 03a3d3f4a7c00..f3ae8f4bdcf3a 100644 --- a/lib/private/Migration/BackgroundRepair.php +++ b/lib/private/Migration/BackgroundRepair.php @@ -26,13 +26,12 @@ */ namespace OC\Migration; -use OC\BackgroundJob\JobList; -use OC\BackgroundJob\TimedJob; use OC\NeedsUpdateException; use OC\Repair; use OC_App; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\IJobList; -use OCP\ILogger; +use OCP\BackgroundJob\TimedJob; use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -42,33 +41,16 @@ * @package OC\Migration */ class BackgroundRepair extends TimedJob { + private IJobList $jobList; + private LoggerInterface $logger; + private EventDispatcherInterface $dispatcher; - /** @var IJobList */ - private $jobList; - - /** @var ILogger */ - private $logger; - - /** @var EventDispatcherInterface */ - private $dispatcher; - - public function __construct(EventDispatcherInterface $dispatcher) { + public function __construct(EventDispatcherInterface $dispatcher, ITimeFactory $time, LoggerInterface $logger, IJobList $jobList) { + parent::__construct($time); $this->dispatcher = $dispatcher; - } - - /** - * run the job, then remove it from the job list - * - * @param JobList $jobList - * @param ILogger|null $logger - */ - public function execute($jobList, ILogger $logger = null) { - // add an interval of 15 mins - $this->setInterval(15 * 60); - - $this->jobList = $jobList; $this->logger = $logger; - parent::execute($jobList, $logger); + $this->jobList = $jobList; + $this->setInterval(15 * 60); } /** @@ -97,8 +79,9 @@ protected function run($argument) { try { $repair->addStep($step); } catch (\Exception $ex) { - $this->logger->logException($ex, [ - 'app' => 'migration' + $this->logger->error($ex->getMessage(), [ + 'app' => 'migration', + 'exception' => $ex, ]); // remove the job - we can never execute it diff --git a/lib/private/Security/VerificationToken/CleanUpJob.php b/lib/private/Security/VerificationToken/CleanUpJob.php index be9d24ece45ea..a3c900e100e6f 100644 --- a/lib/private/Security/VerificationToken/CleanUpJob.php +++ b/lib/private/Security/VerificationToken/CleanUpJob.php @@ -30,25 +30,19 @@ use OCP\IConfig; use OCP\ILogger; use OCP\IUserManager; +use OCP\BackgroundJob\IJobList; +use OCP\BackgroundJob\Job; use OCP\Security\VerificationToken\InvalidTokenException; use OCP\Security\VerificationToken\IVerificationToken; -class CleanUpJob extends \OCP\BackgroundJob\Job { - - /** @var int */ - protected $runNotBefore; - /** @var string */ - protected $userId; - /** @var string */ - protected $subject; - /** @var string */ - protected $pwdPrefix; - /** @var IConfig */ - private $config; - /** @var IVerificationToken */ - private $verificationToken; - /** @var IUserManager */ - private $userManager; +class CleanUpJob extends Job { + protected ?int $runNotBefore = null; + protected ?string $userId = null; + protected ?string $subject = null; + protected ?string $pwdPrefix = null; + private IConfig $config; + private IVerificationToken $verificationToken; + private IUserManager $userManager; public function __construct(ITimeFactory $time, IConfig $config, IVerificationToken $verificationToken, IUserManager $userManager) { parent::__construct($time); @@ -81,10 +75,10 @@ protected function run($argument) { } } - public function execute($jobList, ILogger $logger = null) { + public function start(IJobList $jobList): void { if ($this->time->getTime() >= $this->runNotBefore) { $jobList->remove($this, $this->argument); - parent::execute($jobList, $logger); + parent::start($jobList); } } } diff --git a/lib/public/BackgroundJob/Job.php b/lib/public/BackgroundJob/Job.php index 5831891705aa9..d60fb5905c9d1 100644 --- a/lib/public/BackgroundJob/Job.php +++ b/lib/public/BackgroundJob/Job.php @@ -28,6 +28,7 @@ use OCP\AppFramework\Utility\ITimeFactory; use OCP\ILogger; +use Psr\Log\LoggerInterface; /** * Base class for background jobs diff --git a/lib/public/BackgroundJob/QueuedJob.php b/lib/public/BackgroundJob/QueuedJob.php index 71f09fccdeaa4..b9c4d693b8fbd 100644 --- a/lib/public/BackgroundJob/QueuedJob.php +++ b/lib/public/BackgroundJob/QueuedJob.php @@ -51,7 +51,7 @@ final public function execute($jobList, ILogger $logger = null) { /** * Run the job, then remove it from the joblist * - * @since 15.0.0 + * @since 25.0.0 */ final public function start(IJobList $jobList): void { $jobList->remove($this, $this->argument);