aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLouis Chemineau <louis@chmn.me>2024-02-08 15:23:28 +0100
committerLouis Chemineau <louis@chmn.me>2024-02-08 15:23:28 +0100
commitd9d60238c7aaab9c61bf2d50c15aa59bc88c8975 (patch)
tree4f0277b12a3608c09a88a67f3934b6174e47ba1d /lib
parentba3fdb0cdcfbb84f0080a2146a4ba2f01569915d (diff)
parentca5f7adebc671b9e18ecdba0afda62fc23a381e4 (diff)
downloadnextcloud-server-d9d60238c7aaab9c61bf2d50c15aa59bc88c8975.tar.gz
nextcloud-server-d9d60238c7aaab9c61bf2d50c15aa59bc88c8975.zip
Merge branch 'master' of github.com:nextcloud/server
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php3
-rw-r--r--lib/composer/composer/autoload_static.php3
-rw-r--r--lib/private/BackgroundJob/Job.php98
-rw-r--r--lib/private/BackgroundJob/QueuedJob.php49
-rw-r--r--lib/private/BackgroundJob/TimedJob.php63
-rw-r--r--lib/private/Command/CallableJob.php2
-rw-r--r--lib/private/Command/ClosureJob.php2
-rw-r--r--lib/private/Command/CommandJob.php2
-rw-r--r--lib/private/Command/CronBus.php28
-rw-r--r--lib/private/DB/MigrationService.php59
-rw-r--r--lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php47
-rw-r--r--lib/private/Repair/Owncloud/MoveAvatarsBackgroundJob.php34
-rw-r--r--lib/public/BackgroundJob/IJobList.php4
-rw-r--r--lib/public/BackgroundJob/Job.php13
-rw-r--r--lib/public/Log/ILogFactory.php10
15 files changed, 102 insertions, 315 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 2fffd0c2f2d..90ab0c8e207 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -955,10 +955,7 @@ 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 d38db8050cc..983a1081621 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -988,10 +988,7 @@ 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
deleted file mode 100644
index ffcaaf8c36d..00000000000
--- a/lib/private/BackgroundJob/Job.php
+++ /dev/null
@@ -1,98 +0,0 @@
-<?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
deleted file mode 100644
index 28d86481e62..00000000000
--- a/lib/private/BackgroundJob/QueuedJob.php
+++ /dev/null
@@ -1,49 +0,0 @@
-<?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
deleted file mode 100644
index 0f0951e1aec..00000000000
--- a/lib/private/BackgroundJob/TimedJob.php
+++ /dev/null
@@ -1,63 +0,0 @@
-<?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 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/DB/MigrationService.php b/lib/private/DB/MigrationService.php
index 60f9b65cd5f..f885422c928 100644
--- a/lib/private/DB/MigrationService.php
+++ b/lib/private/DB/MigrationService.php
@@ -43,6 +43,7 @@ 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 {
@@ -51,6 +52,7 @@ class MigrationService {
private string $migrationsPath;
private string $migrationsNamespace;
private IOutput $output;
+ private LoggerInterface $logger;
private Connection $connection;
private string $appName;
private bool $checkOracle;
@@ -58,11 +60,16 @@ class MigrationService {
/**
* @throws \Exception
*/
- public function __construct(string $appName, Connection $connection, ?IOutput $output = null, ?AppLocator $appLocator = null) {
+ public function __construct(string $appName, Connection $connection, ?IOutput $output = null, ?AppLocator $appLocator = null, ?LoggerInterface $logger = 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(\OC::$server->get(LoggerInterface::class), $appName);
+ $this->output = new SimpleOutput($this->logger, $appName);
} else {
$this->output = $output;
}
@@ -433,7 +440,7 @@ class MigrationService {
if ($toSchema instanceof SchemaWrapper) {
$this->output->debug('- Checking target database schema');
$targetSchema = $toSchema->getWrappedSchema();
- $this->ensureUniqueNamesConstraints($targetSchema);
+ $this->ensureUniqueNamesConstraints($targetSchema, true);
if ($this->checkOracle) {
$beforeSchema = $this->connection->createSchema();
$this->ensureOracleConstraints($beforeSchema, $targetSchema, strlen($this->connection->getPrefix()));
@@ -514,7 +521,7 @@ class MigrationService {
if ($toSchema instanceof SchemaWrapper) {
$targetSchema = $toSchema->getWrappedSchema();
- $this->ensureUniqueNamesConstraints($targetSchema);
+ $this->ensureUniqueNamesConstraints($targetSchema, $schemaOnly);
if ($this->checkOracle) {
$sourceSchema = $this->connection->createSchema();
$this->ensureOracleConstraints($sourceSchema, $targetSchema, strlen($this->connection->getPrefix()));
@@ -650,14 +657,26 @@ 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): void {
+ public function ensureUniqueNamesConstraints(Schema $targetSchema, bool $isInstalling): void {
$constraintNames = [];
-
$sequences = $targetSchema->getSequences();
foreach ($targetSchema->getTables() as $table) {
@@ -668,14 +687,20 @@ class MigrationService {
}
if (isset($constraintNames[$thing->getName()])) {
- throw new \InvalidArgumentException('Index name "' . $thing->getName() . '" for table "' . $table->getName() . '" collides with the constraint on table "' . $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()] . '".');
}
$constraintNames[$thing->getName()] = $table->getName();
}
foreach ($table->getForeignKeys() as $thing) {
if (isset($constraintNames[$thing->getName()])) {
- throw new \InvalidArgumentException('Foreign key name "' . $thing->getName() . '" for table "' . $table->getName() . '" collides with the constraint on table "' . $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()] . '".');
}
$constraintNames[$thing->getName()] = $table->getName();
}
@@ -688,7 +713,10 @@ class MigrationService {
}
if (isset($constraintNames[$indexName])) {
- throw new \InvalidArgumentException('Primary index name "' . $indexName . '" for table "' . $table->getName() . '" collides with the constraint on table "' . $constraintNames[$thing->getName()] . '".');
+ 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()] . '".');
}
$constraintNames[$indexName] = $table->getName();
}
@@ -696,12 +724,23 @@ class MigrationService {
foreach ($sequences as $sequence) {
if (isset($constraintNames[$sequence->getName()])) {
- throw new \InvalidArgumentException('Sequence name "' . $sequence->getName() . '" for table "' . $table->getName() . '" collides with the constraint on table "' . $constraintNames[$thing->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()] . '".');
}
$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 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.
*
diff --git a/lib/public/BackgroundJob/Job.php b/lib/public/BackgroundJob/Job.php
index 2842486b74d..3d1a117ac9e 100644
--- a/lib/public/BackgroundJob/Job.php
+++ b/lib/public/BackgroundJob/Job.php
@@ -44,7 +44,6 @@ abstract class Job implements IJob, IParallelAwareJob {
protected $argument;
protected ITimeFactory $time;
protected bool $allowParallelRuns = true;
- private ?ILogger $logger = null;
/**
* @since 15.0.0
@@ -56,14 +55,13 @@ abstract class Job implements IJob, IParallelAwareJob {
/**
* The function to prepare the execution of the job.
*
- *
- * @param IJobList $jobList
- * @param ILogger|null $logger
+ * @return void
*
* @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) {
- $this->logger = $logger;
+ public function execute(IJobList $jobList, ?ILogger $logger = null) {
$this->start($jobList);
}
@@ -73,7 +71,7 @@ abstract class Job implements IJob, IParallelAwareJob {
*/
public function start(IJobList $jobList): void {
$jobList->setLastRun($this);
- $logger = $this->logger ?? \OCP\Server::get(LoggerInterface::class);
+ $logger = \OCP\Server::get(LoggerInterface::class);
try {
$jobDetails = get_class($this) . ' (id: ' . $this->getId() . ', arguments: ' . json_encode($this->getArgument()) . ')';
@@ -159,6 +157,7 @@ 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 e0128d6b11c..e51a674afbd 100644
--- a/lib/public/Log/ILogFactory.php
+++ b/lib/public/Log/ILogFactory.php
@@ -24,7 +24,6 @@
*/
namespace OCP\Log;
-use OCP\ILogger;
use Psr\Log\LoggerInterface;
/**
@@ -42,15 +41,6 @@ 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