diff options
author | Louis Chemineau <louis@chmn.me> | 2024-02-08 15:31:19 +0100 |
---|---|---|
committer | Louis Chemineau <louis@chmn.me> | 2024-02-08 15:31:19 +0100 |
commit | 898df41de968321926e10ad532a64c3915ddad29 (patch) | |
tree | 57a0e5ada151890ddf71550f22b502e1f67aeffd /lib | |
parent | d9d60238c7aaab9c61bf2d50c15aa59bc88c8975 (diff) | |
download | nextcloud-server-898df41de968321926e10ad532a64c3915ddad29.tar.gz nextcloud-server-898df41de968321926e10ad532a64c3915ddad29.zip |
Revert "Merge branch 'master' of github.com:nextcloud/server"
This reverts commit d9d60238c7aaab9c61bf2d50c15aa59bc88c8975, reversing
changes made to ba3fdb0cdcfbb84f0080a2146a4ba2f01569915d.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 3 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 3 | ||||
-rw-r--r-- | lib/private/BackgroundJob/Job.php | 98 | ||||
-rw-r--r-- | lib/private/BackgroundJob/QueuedJob.php | 49 | ||||
-rw-r--r-- | lib/private/BackgroundJob/TimedJob.php | 63 | ||||
-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/DB/MigrationService.php | 59 | ||||
-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 | ||||
-rw-r--r-- | lib/public/BackgroundJob/Job.php | 13 | ||||
-rw-r--r-- | lib/public/Log/ILogFactory.php | 10 |
15 files changed, 315 insertions, 102 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 90ab0c8e207..2fffd0c2f2d 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -955,7 +955,10 @@ return array( 'OC\\Avatar\\GuestAvatar' => $baseDir . '/lib/private/Avatar/GuestAvatar.php', 'OC\\Avatar\\PlaceholderAvatar' => $baseDir . '/lib/private/Avatar/PlaceholderAvatar.php', 'OC\\Avatar\\UserAvatar' => $baseDir . '/lib/private/Avatar/UserAvatar.php', + 'OC\\BackgroundJob\\Job' => $baseDir . '/lib/private/BackgroundJob/Job.php', 'OC\\BackgroundJob\\JobList' => $baseDir . '/lib/private/BackgroundJob/JobList.php', + 'OC\\BackgroundJob\\QueuedJob' => $baseDir . '/lib/private/BackgroundJob/QueuedJob.php', + 'OC\\BackgroundJob\\TimedJob' => $baseDir . '/lib/private/BackgroundJob/TimedJob.php', 'OC\\BinaryFinder' => $baseDir . '/lib/private/BinaryFinder.php', 'OC\\Blurhash\\Listener\\GenerateBlurhashMetadata' => $baseDir . '/lib/private/Blurhash/Listener/GenerateBlurhashMetadata.php', 'OC\\Broadcast\\Events\\BroadcastEvent' => $baseDir . '/lib/private/Broadcast/Events/BroadcastEvent.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 983a1081621..d38db8050cc 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -988,7 +988,10 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OC\\Avatar\\GuestAvatar' => __DIR__ . '/../../..' . '/lib/private/Avatar/GuestAvatar.php', 'OC\\Avatar\\PlaceholderAvatar' => __DIR__ . '/../../..' . '/lib/private/Avatar/PlaceholderAvatar.php', 'OC\\Avatar\\UserAvatar' => __DIR__ . '/../../..' . '/lib/private/Avatar/UserAvatar.php', + 'OC\\BackgroundJob\\Job' => __DIR__ . '/../../..' . '/lib/private/BackgroundJob/Job.php', 'OC\\BackgroundJob\\JobList' => __DIR__ . '/../../..' . '/lib/private/BackgroundJob/JobList.php', + 'OC\\BackgroundJob\\QueuedJob' => __DIR__ . '/../../..' . '/lib/private/BackgroundJob/QueuedJob.php', + 'OC\\BackgroundJob\\TimedJob' => __DIR__ . '/../../..' . '/lib/private/BackgroundJob/TimedJob.php', 'OC\\BinaryFinder' => __DIR__ . '/../../..' . '/lib/private/BinaryFinder.php', 'OC\\Blurhash\\Listener\\GenerateBlurhashMetadata' => __DIR__ . '/../../..' . '/lib/private/Blurhash/Listener/GenerateBlurhashMetadata.php', 'OC\\Broadcast\\Events\\BroadcastEvent' => __DIR__ . '/../../..' . '/lib/private/Broadcast/Events/BroadcastEvent.php', diff --git a/lib/private/BackgroundJob/Job.php b/lib/private/BackgroundJob/Job.php new file mode 100644 index 00000000000..ffcaaf8c36d --- /dev/null +++ b/lib/private/BackgroundJob/Job.php @@ -0,0 +1,98 @@ +<?php +/** + * @copyright Copyright (c) 2016, ownCloud, Inc. + * + * @author Daniel Kesselberg <mail@danielkesselberg.de> + * @author Morris Jobke <hey@morrisjobke.de> + * @author Noveen Sachdeva <noveen.sachdeva@research.iiit.ac.in> + * @author Robin Appelman <robin@icewind.nl> + * @author Thomas Müller <thomas.mueller@tmit.eu> + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OC\BackgroundJob; + +use OCP\BackgroundJob\IJob; +use OCP\BackgroundJob\IJobList; +use OCP\ILogger; + +/** + * @deprecated internal class, use \OCP\BackgroundJob\Job + */ +abstract class Job implements IJob { + /** @var int */ + protected $id; + + /** @var int */ + protected $lastRun; + + /** @var mixed */ + protected $argument; + + public function execute(IJobList $jobList, ILogger $logger = null) { + $jobList->setLastRun($this); + if ($logger === null) { + $logger = \OC::$server->getLogger(); + } + + try { + $jobStartTime = time(); + $logger->debug('Run ' . get_class($this) . ' job with ID ' . $this->getId(), ['app' => 'cron']); + $this->run($this->argument); + $timeTaken = time() - $jobStartTime; + + $logger->debug('Finished ' . get_class($this) . ' job with ID ' . $this->getId() . ' in ' . $timeTaken . ' seconds', ['app' => 'cron']); + $jobList->setExecutionTime($this, $timeTaken); + } catch (\Throwable $e) { + if ($logger) { + $logger->logException($e, [ + 'app' => 'core', + 'message' => 'Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')' + ]); + } + } + } + + public function start(IJobList $jobList): void { + $this->execute($jobList); + } + + abstract protected function run($argument); + + public function setId(int $id) { + $this->id = $id; + } + + public function setLastRun(int $lastRun) { + $this->lastRun = $lastRun; + } + + public function setArgument($argument) { + $this->argument = $argument; + } + + public function getId() { + return $this->id; + } + + public function getLastRun() { + return $this->lastRun; + } + + public function getArgument() { + return $this->argument; + } +} diff --git a/lib/private/BackgroundJob/QueuedJob.php b/lib/private/BackgroundJob/QueuedJob.php new file mode 100644 index 00000000000..28d86481e62 --- /dev/null +++ b/lib/private/BackgroundJob/QueuedJob.php @@ -0,0 +1,49 @@ +<?php +/** + * @copyright Copyright (c) 2016, ownCloud, Inc. + * + * @author Christoph Wurst <christoph@winzerhof-wurst.at> + * @author Lukas Reschke <lukas@statuscode.ch> + * @author Morris Jobke <hey@morrisjobke.de> + * @author Robin Appelman <robin@icewind.nl> + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OC\BackgroundJob; + +use OCP\ILogger; + +/** + * Class QueuedJob + * + * create a background job that is to be executed once + * + * @package OC\BackgroundJob + * + * @deprecated internal class, use \OCP\BackgroundJob\QueuedJob + */ +abstract class QueuedJob extends Job { + /** + * run the job, then remove it from the joblist + * + * @param JobList $jobList + * @param ILogger|null $logger + */ + public function execute($jobList, ILogger $logger = null) { + $jobList->remove($this, $this->argument); + parent::execute($jobList, $logger); + } +} diff --git a/lib/private/BackgroundJob/TimedJob.php b/lib/private/BackgroundJob/TimedJob.php new file mode 100644 index 00000000000..0f0951e1aec --- /dev/null +++ b/lib/private/BackgroundJob/TimedJob.php @@ -0,0 +1,63 @@ +<?php +/** + * @copyright Copyright (c) 2016, ownCloud, Inc. + * + * @author Christoph Wurst <christoph@winzerhof-wurst.at> + * @author Daniel Kesselberg <mail@danielkesselberg.de> + * @author Lukas Reschke <lukas@statuscode.ch> + * @author Morris Jobke <hey@morrisjobke.de> + * @author Robin Appelman <robin@icewind.nl> + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OC\BackgroundJob; + +use OCP\BackgroundJob\IJobList; +use OCP\ILogger; + +/** + * Class QueuedJob + * + * create a background job that is to be executed at an interval + * + * @package OC\BackgroundJob + * + * @deprecated internal class, use \OCP\BackgroundJob\TimedJob + */ +abstract class TimedJob extends Job { + protected $interval = 0; + + /** + * set the interval for the job + * + * @param int $interval + */ + public function setInterval($interval) { + $this->interval = $interval; + } + + /** + * run the job if + * + * @param IJobList $jobList + * @param ILogger|null $logger + */ + public function execute($jobList, ILogger $logger = null) { + if ((time() - $this->lastRun) > $this->interval) { + parent::execute($jobList, $logger); + } + } +} diff --git a/lib/private/Command/CallableJob.php b/lib/private/Command/CallableJob.php index 7f515660955..8bb3c76c9af 100644 --- a/lib/private/Command/CallableJob.php +++ b/lib/private/Command/CallableJob.php @@ -21,7 +21,7 @@ */ namespace OC\Command; -use OCP\BackgroundJob\QueuedJob; +use OC\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 3e0fe73b029..f7b0ee1a3d3 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 OCP\BackgroundJob\QueuedJob; +use OC\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 368d264f3bb..e34ffe9440b 100644 --- a/lib/private/Command/CommandJob.php +++ b/lib/private/Command/CommandJob.php @@ -22,7 +22,7 @@ */ namespace OC\Command; -use OCP\BackgroundJob\QueuedJob; +use OC\BackgroundJob\QueuedJob; use OCP\Command\ICommand; /** diff --git a/lib/private/Command/CronBus.php b/lib/private/Command/CronBus.php index 495cd011db1..42ff458a95c 100644 --- a/lib/private/Command/CronBus.php +++ b/lib/private/Command/CronBus.php @@ -26,25 +26,31 @@ namespace OC\Command; use Laravel\SerializableClosure\SerializableClosure; -use OCP\BackgroundJob\IJob; -use OCP\BackgroundJob\IJobList; use OCP\Command\ICommand; class CronBus extends AsyncBus { - public function __construct( - private IJobList $jobList, - ) { + /** + * @var \OCP\BackgroundJob\IJobList + */ + private $jobList; + + + /** + * @param \OCP\BackgroundJob\IJobList $jobList + */ + public function __construct($jobList) { + $this->jobList = $jobList; } - protected function queueCommand($command): void { + protected function queueCommand($command) { $this->jobList->add($this->getJobClass($command), $this->serializeCommand($command)); } /** - * @param ICommand|callable $command - * @return class-string<IJob> + * @param \OCP\Command\ICommand | callable $command + * @return string */ - private function getJobClass($command): string { + private function getJobClass($command) { if ($command instanceof \Closure) { return ClosureJob::class; } elseif (is_callable($command)) { @@ -57,10 +63,10 @@ class CronBus extends AsyncBus { } /** - * @param ICommand|callable $command + * @param \OCP\Command\ICommand | callable $command * @return string */ - private function serializeCommand($command): string { + private function serializeCommand($command) { if ($command instanceof \Closure) { return serialize(new SerializableClosure($command)); } elseif (is_callable($command) or $command instanceof ICommand) { diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php index f885422c928..60f9b65cd5f 100644 --- a/lib/private/DB/MigrationService.php +++ b/lib/private/DB/MigrationService.php @@ -43,7 +43,6 @@ use OCP\AppFramework\QueryException; use OCP\DB\ISchemaWrapper; use OCP\Migration\IMigrationStep; use OCP\Migration\IOutput; -use OCP\Server; use Psr\Log\LoggerInterface; class MigrationService { @@ -52,7 +51,6 @@ class MigrationService { private string $migrationsPath; private string $migrationsNamespace; private IOutput $output; - private LoggerInterface $logger; private Connection $connection; private string $appName; private bool $checkOracle; @@ -60,16 +58,11 @@ class MigrationService { /** * @throws \Exception */ - public function __construct(string $appName, Connection $connection, ?IOutput $output = null, ?AppLocator $appLocator = null, ?LoggerInterface $logger = null) { + public function __construct(string $appName, Connection $connection, ?IOutput $output = null, ?AppLocator $appLocator = null) { $this->appName = $appName; $this->connection = $connection; - if ($logger === null) { - $this->logger = Server::get(LoggerInterface::class); - } else { - $this->logger = $logger; - } if ($output === null) { - $this->output = new SimpleOutput($this->logger, $appName); + $this->output = new SimpleOutput(\OC::$server->get(LoggerInterface::class), $appName); } else { $this->output = $output; } @@ -440,7 +433,7 @@ class MigrationService { if ($toSchema instanceof SchemaWrapper) { $this->output->debug('- Checking target database schema'); $targetSchema = $toSchema->getWrappedSchema(); - $this->ensureUniqueNamesConstraints($targetSchema, true); + $this->ensureUniqueNamesConstraints($targetSchema); if ($this->checkOracle) { $beforeSchema = $this->connection->createSchema(); $this->ensureOracleConstraints($beforeSchema, $targetSchema, strlen($this->connection->getPrefix())); @@ -521,7 +514,7 @@ class MigrationService { if ($toSchema instanceof SchemaWrapper) { $targetSchema = $toSchema->getWrappedSchema(); - $this->ensureUniqueNamesConstraints($targetSchema, $schemaOnly); + $this->ensureUniqueNamesConstraints($targetSchema); if ($this->checkOracle) { $sourceSchema = $this->connection->createSchema(); $this->ensureOracleConstraints($sourceSchema, $targetSchema, strlen($this->connection->getPrefix())); @@ -657,26 +650,14 @@ class MigrationService { } /** - * Ensure naming constraints - * * Naming constraints: * - Index, sequence and primary key names must be unique within a Postgres Schema * - * Only on installation we want to break hard, so that all developers notice - * the bugs when installing the app on any database or CI, and can work on - * fixing their migrations before releasing a version incompatible with Postgres. - * - * In case of updates we might be running on production instances and the - * administrators being faced with the error would not know how to resolve it - * anyway. This can also happen with instances, that had the issue before the - * current update, so we don't want to make their life more complicated - * than needed. - * * @param Schema $targetSchema - * @param bool $isInstalling */ - public function ensureUniqueNamesConstraints(Schema $targetSchema, bool $isInstalling): void { + public function ensureUniqueNamesConstraints(Schema $targetSchema): void { $constraintNames = []; + $sequences = $targetSchema->getSequences(); foreach ($targetSchema->getTables() as $table) { @@ -687,20 +668,14 @@ class MigrationService { } if (isset($constraintNames[$thing->getName()])) { - if ($isInstalling) { - throw new \InvalidArgumentException('Index name "' . $thing->getName() . '" for table "' . $table->getName() . '" collides with the constraint on table "' . $constraintNames[$thing->getName()] . '".'); - } - $this->logErrorOrWarning('Index name "' . $thing->getName() . '" for table "' . $table->getName() . '" collides with the constraint on table "' . $constraintNames[$thing->getName()] . '".'); + throw new \InvalidArgumentException('Index name "' . $thing->getName() . '" for table "' . $table->getName() . '" collides with the constraint on table "' . $constraintNames[$thing->getName()] . '".'); } $constraintNames[$thing->getName()] = $table->getName(); } foreach ($table->getForeignKeys() as $thing) { if (isset($constraintNames[$thing->getName()])) { - if ($isInstalling) { - throw new \InvalidArgumentException('Foreign key name "' . $thing->getName() . '" for table "' . $table->getName() . '" collides with the constraint on table "' . $constraintNames[$thing->getName()] . '".'); - } - $this->logErrorOrWarning('Foreign key name "' . $thing->getName() . '" for table "' . $table->getName() . '" collides with the constraint on table "' . $constraintNames[$thing->getName()] . '".'); + throw new \InvalidArgumentException('Foreign key name "' . $thing->getName() . '" for table "' . $table->getName() . '" collides with the constraint on table "' . $constraintNames[$thing->getName()] . '".'); } $constraintNames[$thing->getName()] = $table->getName(); } @@ -713,10 +688,7 @@ class MigrationService { } if (isset($constraintNames[$indexName])) { - if ($isInstalling) { - throw new \InvalidArgumentException('Primary index name "' . $indexName . '" for table "' . $table->getName() . '" collides with the constraint on table "' . $constraintNames[$thing->getName()] . '".'); - } - $this->logErrorOrWarning('Primary index name "' . $indexName . '" for table "' . $table->getName() . '" collides with the constraint on table "' . $constraintNames[$thing->getName()] . '".'); + throw new \InvalidArgumentException('Primary index name "' . $indexName . '" for table "' . $table->getName() . '" collides with the constraint on table "' . $constraintNames[$thing->getName()] . '".'); } $constraintNames[$indexName] = $table->getName(); } @@ -724,23 +696,12 @@ class MigrationService { foreach ($sequences as $sequence) { if (isset($constraintNames[$sequence->getName()])) { - if ($isInstalling) { - throw new \InvalidArgumentException('Sequence name "' . $sequence->getName() . '" for table "' . $table->getName() . '" collides with the constraint on table "' . $constraintNames[$thing->getName()] . '".'); - } - $this->logErrorOrWarning('Sequence name "' . $sequence->getName() . '" for table "' . $table->getName() . '" collides with the constraint on table "' . $constraintNames[$thing->getName()] . '".'); + throw new \InvalidArgumentException('Sequence name "' . $sequence->getName() . '" for table "' . $table->getName() . '" collides with the constraint on table "' . $constraintNames[$thing->getName()] . '".'); } $constraintNames[$sequence->getName()] = 'sequence'; } } - protected function logErrorOrWarning(string $log): void { - if ($this->output instanceof SimpleOutput) { - $this->output->warning($log); - } else { - $this->logger->error($log); - } - } - private function ensureMigrationsAreLoaded() { if (empty($this->migrations)) { $this->migrations = $this->findMigrations(); diff --git a/lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php b/lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php index a23816e4711..4ba9ad083e3 100644 --- a/lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php +++ b/lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php @@ -1,7 +1,4 @@ <?php - -declare(strict_types=1); - /** * @copyright 2016 Roeland Jago Douma <roeland@famdouma.nl> * @@ -25,9 +22,9 @@ declare(strict_types=1); */ 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; @@ -36,14 +33,33 @@ use OCP\IUserManager; use Psr\Log\LoggerInterface; class CleanPreviewsBackgroundJob extends QueuedJob { - public function __construct( - private IRootFolder $rootFolder, - private LoggerInterface $logger, - private IJobList $jobList, + /** @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, ITimeFactory $timeFactory, - private IUserManager $userManager, - ) { - parent::__construct($timeFactory); + IUserManager $userManager) { + $this->rootFolder = $rootFolder; + $this->logger = $logger; + $this->jobList = $jobList; + $this->timeFactory = $timeFactory; + $this->userManager = $userManager; } public function run($arguments) { @@ -64,9 +80,10 @@ class CleanPreviewsBackgroundJob extends QueuedJob { } /** - * @param string $uid + * @param $uid + * @return bool */ - private function cleanupPreviews($uid): bool { + private function cleanupPreviews($uid) { try { $userFolder = $this->rootFolder->getUserFolder($uid); } catch (NotFoundException $e) { @@ -84,7 +101,7 @@ class CleanPreviewsBackgroundJob extends QueuedJob { $thumbnails = $thumbnailFolder->getDirectoryListing(); - $start = $this->time->getTime(); + $start = $this->timeFactory->getTime(); foreach ($thumbnails as $thumbnail) { try { $thumbnail->delete(); @@ -92,7 +109,7 @@ class CleanPreviewsBackgroundJob extends QueuedJob { // Ignore } - if (($this->time->getTime() - $start) > 15) { + if (($this->timeFactory->getTime() - $start) > 15) { return false; } } diff --git a/lib/private/Repair/Owncloud/MoveAvatarsBackgroundJob.php b/lib/private/Repair/Owncloud/MoveAvatarsBackgroundJob.php index 9f01c4051e6..83c78c2cba4 100644 --- a/lib/private/Repair/Owncloud/MoveAvatarsBackgroundJob.php +++ b/lib/private/Repair/Owncloud/MoveAvatarsBackgroundJob.php @@ -1,7 +1,4 @@ <?php - -declare(strict_types=1); - /** * @copyright 2016 Roeland Jago Douma <roeland@famdouma.nl> * @@ -26,11 +23,10 @@ declare(strict_types=1); */ namespace OC\Repair\Owncloud; -use OCP\AppFramework\Utility\ITimeFactory; -use OCP\BackgroundJob\QueuedJob; +use OC\BackgroundJob\QueuedJob; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; -use OCP\Files\Storage\IStorage; +use OCP\Files\Storage; use OCP\IAvatarManager; use OCP\IUser; use OCP\IUserManager; @@ -38,16 +34,22 @@ use Psr\Log\LoggerInterface; use function is_resource; class MoveAvatarsBackgroundJob extends QueuedJob { - private ?IStorage $owncloudAvatarStorage = null; + /** @var IUserManager */ + private $userManager; + + /** @var LoggerInterface */ + private $logger; + + /** @var IAvatarManager */ + private $avatarManager; + + /** @var Storage */ + private $owncloudAvatarStorage; - public function __construct( - private IUserManager $userManager, - private LoggerInterface $logger, - private IAvatarManager $avatarManager, - private IRootFolder $rootFolder, - ITimeFactory $time, - ) { - parent::__construct($time); + public function __construct(IUserManager $userManager, LoggerInterface $logger, IAvatarManager $avatarManager, IRootFolder $rootFolder) { + $this->userManager = $userManager; + $this->logger = $logger; + $this->avatarManager = $avatarManager; try { $this->owncloudAvatarStorage = $rootFolder->get('avatars')->getStorage(); } catch (\Exception $e) { @@ -67,7 +69,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 07b5ebcf48b..0b00326ca1a 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 - * \OCP\BackgroundJob\Job, \OCP\BackgroundJob\QueuedJob or - * \OCP\BackgroundJob\TimedJob and register it using ->add($job, $argument), + * \OC\BackgroundJob\Job, \OC\BackgroundJob\QueuedJob or + * \OC\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. * diff --git a/lib/public/BackgroundJob/Job.php b/lib/public/BackgroundJob/Job.php index 3d1a117ac9e..2842486b74d 100644 --- a/lib/public/BackgroundJob/Job.php +++ b/lib/public/BackgroundJob/Job.php @@ -44,6 +44,7 @@ abstract class Job implements IJob, IParallelAwareJob { protected $argument; protected ITimeFactory $time; protected bool $allowParallelRuns = true; + private ?ILogger $logger = null; /** * @since 15.0.0 @@ -55,13 +56,14 @@ abstract class Job implements IJob, IParallelAwareJob { /** * The function to prepare the execution of the job. * - * @return void + * + * @param IJobList $jobList + * @param ILogger|null $logger * * @since 15.0.0 - * @deprecated since 25.0.0 Use start() instead. This method will be removed - * with the ILogger interface */ - public function execute(IJobList $jobList, ?ILogger $logger = null) { + public function execute(IJobList $jobList, ILogger $logger = null) { + $this->logger = $logger; $this->start($jobList); } @@ -71,7 +73,7 @@ abstract class Job implements IJob, IParallelAwareJob { */ public function start(IJobList $jobList): void { $jobList->setLastRun($this); - $logger = \OCP\Server::get(LoggerInterface::class); + $logger = $this->logger ?? \OCP\Server::get(LoggerInterface::class); try { $jobDetails = get_class($this) . ' (id: ' . $this->getId() . ', arguments: ' . json_encode($this->getArgument()) . ')'; @@ -157,7 +159,6 @@ abstract class Job implements IJob, IParallelAwareJob { * The actual function that is called to run the job * * @param $argument - * @return void * * @since 15.0.0 */ diff --git a/lib/public/Log/ILogFactory.php b/lib/public/Log/ILogFactory.php index e51a674afbd..e0128d6b11c 100644 --- a/lib/public/Log/ILogFactory.php +++ b/lib/public/Log/ILogFactory.php @@ -24,6 +24,7 @@ */ namespace OCP\Log; +use OCP\ILogger; use Psr\Log\LoggerInterface; /** @@ -41,6 +42,15 @@ interface ILogFactory { /** * @param string $path + * @return ILogger + * @since 14.0.0 + * @deprecated 22.0.0 Use \OCP\Log\ILogFactory::getCustomPsrLogger + * @see \OCP\Log\ILogFactory::getCustomPsrLogger + */ + public function getCustomLogger(string $path): ILogger; + + /** + * @param string $path * @param string $type * @param string $tag * @return LoggerInterface |