diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2024-02-06 12:02:54 +0100 |
---|---|---|
committer | Côme Chilliet <91878298+come-nc@users.noreply.github.com> | 2024-02-08 10:28:29 +0100 |
commit | 65981f99bfaa4f05469b32eaf0faa21e3b01d812 (patch) | |
tree | 7f01e10ae5cfd3b11cd478260a2bbf56936b5086 /lib | |
parent | 166773879ba20bf7b81f3996a7c4e2a9ff7ee16d (diff) | |
download | nextcloud-server-65981f99bfaa4f05469b32eaf0faa21e3b01d812.tar.gz nextcloud-server-65981f99bfaa4f05469b32eaf0faa21e3b01d812.zip |
chore: Migrate away from internal Job classes
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Command/CallableJob.php | 2 | ||||
-rw-r--r-- | lib/private/Command/ClosureJob.php | 2 | ||||
-rw-r--r-- | lib/private/Command/CommandJob.php | 2 | ||||
-rw-r--r-- | lib/private/Command/CronBus.php | 28 | ||||
-rw-r--r-- | lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php | 47 | ||||
-rw-r--r-- | lib/private/Repair/Owncloud/MoveAvatarsBackgroundJob.php | 34 | ||||
-rw-r--r-- | lib/public/BackgroundJob/IJobList.php | 4 |
7 files changed, 47 insertions, 72 deletions
diff --git a/lib/private/Command/CallableJob.php b/lib/private/Command/CallableJob.php index 8bb3c76c9af..7f515660955 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 f7b0ee1a3d3..3e0fe73b029 100644 --- a/lib/private/Command/ClosureJob.php +++ b/lib/private/Command/ClosureJob.php @@ -23,7 +23,7 @@ namespace OC\Command; use Laravel\SerializableClosure\SerializableClosure as LaravelClosure; -use OC\BackgroundJob\QueuedJob; +use OCP\BackgroundJob\QueuedJob; class ClosureJob extends QueuedJob { protected function run($argument) { diff --git a/lib/private/Command/CommandJob.php b/lib/private/Command/CommandJob.php index e34ffe9440b..368d264f3bb 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/Command/CronBus.php b/lib/private/Command/CronBus.php index 42ff458a95c..495cd011db1 100644 --- a/lib/private/Command/CronBus.php +++ b/lib/private/Command/CronBus.php @@ -26,31 +26,25 @@ namespace OC\Command; use Laravel\SerializableClosure\SerializableClosure; +use OCP\BackgroundJob\IJob; +use OCP\BackgroundJob\IJobList; use OCP\Command\ICommand; class CronBus extends AsyncBus { - /** - * @var \OCP\BackgroundJob\IJobList - */ - private $jobList; - - - /** - * @param \OCP\BackgroundJob\IJobList $jobList - */ - public function __construct($jobList) { - $this->jobList = $jobList; + public function __construct( + private IJobList $jobList, + ) { } - protected function queueCommand($command) { + protected function queueCommand($command): void { $this->jobList->add($this->getJobClass($command), $this->serializeCommand($command)); } /** - * @param \OCP\Command\ICommand | callable $command - * @return string + * @param ICommand|callable $command + * @return class-string<IJob> */ - private function getJobClass($command) { + private function getJobClass($command): string { if ($command instanceof \Closure) { return ClosureJob::class; } elseif (is_callable($command)) { @@ -63,10 +57,10 @@ class CronBus extends AsyncBus { } /** - * @param \OCP\Command\ICommand | callable $command + * @param ICommand|callable $command * @return string */ - private function serializeCommand($command) { + private function serializeCommand($command): string { if ($command instanceof \Closure) { return serialize(new SerializableClosure($command)); } elseif (is_callable($command) or $command instanceof ICommand) { diff --git a/lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php b/lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php index 4ba9ad083e3..a23816e4711 100644 --- a/lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php +++ b/lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @copyright 2016 Roeland Jago Douma <roeland@famdouma.nl> * @@ -22,9 +25,9 @@ */ namespace OC\Repair\Owncloud; -use OC\BackgroundJob\QueuedJob; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\IJobList; +use OCP\BackgroundJob\QueuedJob; use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; @@ -33,33 +36,14 @@ use OCP\IUserManager; use Psr\Log\LoggerInterface; class CleanPreviewsBackgroundJob extends QueuedJob { - /** @var IRootFolder */ - private $rootFolder; - - private LoggerInterface $logger; - - /** @var IJobList */ - private $jobList; - - /** @var ITimeFactory */ - private $timeFactory; - - /** @var IUserManager */ - private $userManager; - - /** - * CleanPreviewsBackgroundJob constructor. - */ - public function __construct(IRootFolder $rootFolder, - LoggerInterface $logger, - IJobList $jobList, + public function __construct( + private IRootFolder $rootFolder, + private LoggerInterface $logger, + private IJobList $jobList, ITimeFactory $timeFactory, - IUserManager $userManager) { - $this->rootFolder = $rootFolder; - $this->logger = $logger; - $this->jobList = $jobList; - $this->timeFactory = $timeFactory; - $this->userManager = $userManager; + private IUserManager $userManager, + ) { + parent::__construct($timeFactory); } public function run($arguments) { @@ -80,10 +64,9 @@ class CleanPreviewsBackgroundJob extends QueuedJob { } /** - * @param $uid - * @return bool + * @param string $uid */ - private function cleanupPreviews($uid) { + private function cleanupPreviews($uid): bool { try { $userFolder = $this->rootFolder->getUserFolder($uid); } catch (NotFoundException $e) { @@ -101,7 +84,7 @@ class CleanPreviewsBackgroundJob extends QueuedJob { $thumbnails = $thumbnailFolder->getDirectoryListing(); - $start = $this->timeFactory->getTime(); + $start = $this->time->getTime(); foreach ($thumbnails as $thumbnail) { try { $thumbnail->delete(); @@ -109,7 +92,7 @@ class CleanPreviewsBackgroundJob extends QueuedJob { // Ignore } - if (($this->timeFactory->getTime() - $start) > 15) { + if (($this->time->getTime() - $start) > 15) { return false; } } diff --git a/lib/private/Repair/Owncloud/MoveAvatarsBackgroundJob.php b/lib/private/Repair/Owncloud/MoveAvatarsBackgroundJob.php index 83c78c2cba4..9f01c4051e6 100644 --- a/lib/private/Repair/Owncloud/MoveAvatarsBackgroundJob.php +++ b/lib/private/Repair/Owncloud/MoveAvatarsBackgroundJob.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @copyright 2016 Roeland Jago Douma <roeland@famdouma.nl> * @@ -23,10 +26,11 @@ */ namespace OC\Repair\Owncloud; -use OC\BackgroundJob\QueuedJob; +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\BackgroundJob\QueuedJob; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; -use OCP\Files\Storage; +use OCP\Files\Storage\IStorage; use OCP\IAvatarManager; use OCP\IUser; use OCP\IUserManager; @@ -34,22 +38,16 @@ use Psr\Log\LoggerInterface; use function is_resource; class MoveAvatarsBackgroundJob extends QueuedJob { - /** @var IUserManager */ - private $userManager; - - /** @var LoggerInterface */ - private $logger; - - /** @var IAvatarManager */ - private $avatarManager; - - /** @var Storage */ - private $owncloudAvatarStorage; + private ?IStorage $owncloudAvatarStorage = null; - public function __construct(IUserManager $userManager, LoggerInterface $logger, IAvatarManager $avatarManager, IRootFolder $rootFolder) { - $this->userManager = $userManager; - $this->logger = $logger; - $this->avatarManager = $avatarManager; + public function __construct( + private IUserManager $userManager, + private LoggerInterface $logger, + private IAvatarManager $avatarManager, + private IRootFolder $rootFolder, + ITimeFactory $time, + ) { + parent::__construct($time); try { $this->owncloudAvatarStorage = $rootFolder->get('avatars')->getStorage(); } catch (\Exception $e) { @@ -69,7 +67,7 @@ class MoveAvatarsBackgroundJob extends QueuedJob { } $counter = 0; - $this->userManager->callForSeenUsers(function (IUser $user) use ($counter) { + $this->userManager->callForSeenUsers(function (IUser $user) use (&$counter) { $uid = $user->getUID(); $path = 'avatars/' . $this->buildOwnCloudAvatarPath($uid); diff --git a/lib/public/BackgroundJob/IJobList.php b/lib/public/BackgroundJob/IJobList.php index 0b00326ca1a..07b5ebcf48b 100644 --- a/lib/public/BackgroundJob/IJobList.php +++ b/lib/public/BackgroundJob/IJobList.php @@ -32,8 +32,8 @@ namespace OCP\BackgroundJob; * This interface provides functions to register background jobs * * To create a new background job create a new class that inherits from either - * \OC\BackgroundJob\Job, \OC\BackgroundJob\QueuedJob or - * \OC\BackgroundJob\TimedJob and register it using ->add($job, $argument), + * \OCP\BackgroundJob\Job, \OCP\BackgroundJob\QueuedJob or + * \OCP\BackgroundJob\TimedJob and register it using ->add($job, $argument), * $argument will be passed to the run() function of the job when the job is * executed. * |