diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2024-02-06 11:22:09 +0100 |
---|---|---|
committer | Côme Chilliet <91878298+come-nc@users.noreply.github.com> | 2024-02-08 10:28:29 +0100 |
commit | 166773879ba20bf7b81f3996a7c4e2a9ff7ee16d (patch) | |
tree | ee8c3115167e71c115f56479612be08c574761f1 /apps/dav | |
parent | 9e9040196f94e9650ce847e9feb9f23ad8d19ada (diff) | |
download | nextcloud-server-166773879ba20bf7b81f3996a7c4e2a9ff7ee16d.tar.gz nextcloud-server-166773879ba20bf7b81f3996a7c4e2a9ff7ee16d.zip |
fix!: Migrate jobs away from deprecated interfaces
BREAKING CHANGE: Removed ILogFactory::getCustomLogger deprecated method
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps/dav')
4 files changed, 53 insertions, 117 deletions
diff --git a/apps/dav/lib/BackgroundJob/RefreshWebcalJob.php b/apps/dav/lib/BackgroundJob/RefreshWebcalJob.php index fbb944159fd..a40aeee3d66 100644 --- a/apps/dav/lib/BackgroundJob/RefreshWebcalJob.php +++ b/apps/dav/lib/BackgroundJob/RefreshWebcalJob.php @@ -6,6 +6,7 @@ declare(strict_types=1); * @copyright 2018 Georg Ehrke <oc.list@georgehrke.com> * * @author Christoph Wurst <christoph@winzerhof-wurst.at> + * @author Côme Chilliet <come.chilliet@nextcloud.com> * @author Georg Ehrke <oc.list@georgehrke.com> * @author Roeland Jago Douma <roeland@famdouma.nl> * @author Thomas Citharel <nextcloud@tcit.fr> @@ -34,42 +35,18 @@ use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\IJobList; use OCP\BackgroundJob\Job; use OCP\IConfig; -use OCP\ILogger; +use Psr\Log\LoggerInterface; use Sabre\VObject\DateTimeParser; use Sabre\VObject\InvalidDataException; class RefreshWebcalJob extends Job { - - /** - * @var RefreshWebcalService - */ - private $refreshWebcalService; - - /** - * @var IConfig - */ - private $config; - - /** @var ILogger */ - private $logger; - - /** @var ITimeFactory */ - private $timeFactory; - - /** - * RefreshWebcalJob constructor. - * - * @param RefreshWebcalService $refreshWebcalService - * @param IConfig $config - * @param ILogger $logger - * @param ITimeFactory $timeFactory - */ - public function __construct(RefreshWebcalService $refreshWebcalService, IConfig $config, ILogger $logger, ITimeFactory $timeFactory) { + public function __construct( + private RefreshWebcalService $refreshWebcalService, + private IConfig $config, + private LoggerInterface $logger, + ITimeFactory $timeFactory, + ) { parent::__construct($timeFactory); - $this->refreshWebcalService = $refreshWebcalService; - $this->config = $config; - $this->logger = $logger; - $this->timeFactory = $timeFactory; } /** @@ -77,7 +54,7 @@ class RefreshWebcalJob extends Job { * * @inheritdoc */ - public function execute(IJobList $jobList, ILogger $logger = null) { + public function start(IJobList $jobList): void { $subscription = $this->refreshWebcalService->getSubscription($this->argument['principaluri'], $this->argument['uri']); if (!$subscription) { return; @@ -95,17 +72,19 @@ class RefreshWebcalJob extends Job { /** @var DateInterval $dateInterval */ $dateInterval = DateTimeParser::parseDuration($refreshRate); } catch (InvalidDataException $ex) { - $this->logger->logException($ex); - $this->logger->warning("Subscription $subscriptionId could not be refreshed, refreshrate in database is invalid"); + $this->logger->error( + "Subscription $subscriptionId could not be refreshed, refreshrate in database is invalid", + ['exception' => $ex] + ); return; } $interval = $this->getIntervalFromDateInterval($dateInterval); - if (($this->timeFactory->getTime() - $this->lastRun) <= $interval) { + if (($this->time->getTime() - $this->lastRun) <= $interval) { return; } - parent::execute($jobList, $logger); + parent::start($jobList); } /** diff --git a/apps/dav/lib/Migration/BuildCalendarSearchIndexBackgroundJob.php b/apps/dav/lib/Migration/BuildCalendarSearchIndexBackgroundJob.php index a816e2619a3..0b89a3d1d77 100644 --- a/apps/dav/lib/Migration/BuildCalendarSearchIndexBackgroundJob.php +++ b/apps/dav/lib/Migration/BuildCalendarSearchIndexBackgroundJob.php @@ -1,7 +1,11 @@ <?php + +declare(strict_types=1); + /** * @copyright 2017 Georg Ehrke <oc.list@georgehrke.com> * + * @author Côme Chilliet <come.chilliet@nextcloud.com> * @author Georg Ehrke <oc.list@georgehrke.com> * @author Joas Schilling <coding@schilljs.com> * @@ -23,47 +27,22 @@ */ namespace OCA\DAV\Migration; -use OC\BackgroundJob\QueuedJob; use OCA\DAV\CalDAV\CalDavBackend; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\IJobList; +use OCP\BackgroundJob\QueuedJob; use OCP\IDBConnection; -use OCP\ILogger; +use Psr\Log\LoggerInterface; class BuildCalendarSearchIndexBackgroundJob extends QueuedJob { - - /** @var IDBConnection */ - private $db; - - /** @var CalDavBackend */ - private $calDavBackend; - - /** @var ILogger */ - private $logger; - - /** @var IJobList */ - private $jobList; - - /** @var ITimeFactory */ - private $timeFactory; - - /** - * @param IDBConnection $db - * @param CalDavBackend $calDavBackend - * @param ILogger $logger - * @param IJobList $jobList - * @param ITimeFactory $timeFactory - */ - public function __construct(IDBConnection $db, - CalDavBackend $calDavBackend, - ILogger $logger, - IJobList $jobList, - ITimeFactory $timeFactory) { - $this->db = $db; - $this->calDavBackend = $calDavBackend; - $this->logger = $logger; - $this->jobList = $jobList; - $this->timeFactory = $timeFactory; + public function __construct( + private IDBConnection $db, + private CalDavBackend $calDavBackend, + private LoggerInterface $logger, + private IJobList $jobList, + ITimeFactory $timeFactory + ) { + parent::__construct($timeFactory); } public function run($arguments) { @@ -72,8 +51,8 @@ class BuildCalendarSearchIndexBackgroundJob extends QueuedJob { $this->logger->info('Building calendar index (' . $offset .'/' . $stopAt . ')'); - $startTime = $this->timeFactory->getTime(); - while (($this->timeFactory->getTime() - $startTime) < 15) { + $startTime = $this->time->getTime(); + while (($this->time->getTime() - $startTime) < 15) { $offset = $this->buildIndex($offset, $stopAt); if ($offset >= $stopAt) { break; @@ -105,7 +84,7 @@ class BuildCalendarSearchIndexBackgroundJob extends QueuedJob { ->orderBy('id', 'ASC') ->setMaxResults(500); - $result = $query->execute(); + $result = $query->executeQuery(); while ($row = $result->fetch(\PDO::FETCH_ASSOC)) { $offset = $row['id']; diff --git a/apps/dav/lib/Migration/BuildSocialSearchIndexBackgroundJob.php b/apps/dav/lib/Migration/BuildSocialSearchIndexBackgroundJob.php index 231749521be..9a688970597 100644 --- a/apps/dav/lib/Migration/BuildSocialSearchIndexBackgroundJob.php +++ b/apps/dav/lib/Migration/BuildSocialSearchIndexBackgroundJob.php @@ -1,8 +1,12 @@ <?php + +declare(strict_types=1); + /** * @copyright 2020 Matthias Heinisch <nextcloud@matthiasheinisch.de> * * @author call-me-matt <nextcloud@matthiasheinisch.de> + * @author Côme Chilliet <come.chilliet@nextcloud.com> * * @license GNU AGPL version 3 or any later version * @@ -22,47 +26,22 @@ */ namespace OCA\DAV\Migration; -use OC\BackgroundJob\QueuedJob; use OCA\DAV\CardDAV\CardDavBackend; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\IJobList; +use OCP\BackgroundJob\QueuedJob; use OCP\IDBConnection; -use OCP\ILogger; +use Psr\Log\LoggerInterface; class BuildSocialSearchIndexBackgroundJob extends QueuedJob { - - /** @var IDBConnection */ - private $db; - - /** @var CardDavBackend */ - private $davBackend; - - /** @var ILogger */ - private $logger; - - /** @var IJobList */ - private $jobList; - - /** @var ITimeFactory */ - private $timeFactory; - - /** - * @param IDBConnection $db - * @param CardDavBackend $davBackend - * @param ILogger $logger - * @param IJobList $jobList - * @param ITimeFactory $timeFactory - */ - public function __construct(IDBConnection $db, - CardDavBackend $davBackend, - ILogger $logger, - IJobList $jobList, - ITimeFactory $timeFactory) { - $this->db = $db; - $this->davBackend = $davBackend; - $this->logger = $logger; - $this->jobList = $jobList; - $this->timeFactory = $timeFactory; + public function __construct( + private IDBConnection $db, + private CardDavBackend $davBackend, + private LoggerInterface $logger, + private IJobList $jobList, + ITimeFactory $timeFactory, + ) { + parent::__construct($timeFactory); } public function run($arguments) { @@ -90,7 +69,7 @@ class BuildSocialSearchIndexBackgroundJob extends QueuedJob { * @return int */ private function buildIndex($offset, $stopAt) { - $startTime = $this->timeFactory->getTime(); + $startTime = $this->time->getTime(); // get contacts with social profiles $query = $this->db->getQueryBuilder(); @@ -99,7 +78,7 @@ class BuildSocialSearchIndexBackgroundJob extends QueuedJob { ->orderBy('id', 'ASC') ->where($query->expr()->like('carddata', $query->createNamedParameter('%SOCIALPROFILE%'))) ->setMaxResults(100); - $social_cards = $query->execute()->fetchAll(); + $social_cards = $query->executeQuery()->fetchAll(); if (empty($social_cards)) { return $stopAt; @@ -111,7 +90,7 @@ class BuildSocialSearchIndexBackgroundJob extends QueuedJob { $this->davBackend->updateCard($contact['addressbookid'], $contact['uri'], $contact['carddata']); // stop after 15sec (to be continued with next chunk) - if (($this->timeFactory->getTime() - $startTime) > 15) { + if (($this->time->getTime() - $startTime) > 15) { break; } } diff --git a/apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php b/apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php index 81b6118a265..7a7bd83f8c4 100644 --- a/apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php +++ b/apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php @@ -33,8 +33,8 @@ use OCA\DAV\CalDAV\WebcalCaching\RefreshWebcalService; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\IJobList; use OCP\IConfig; -use OCP\ILogger; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; use Test\TestCase; @@ -46,8 +46,7 @@ class RefreshWebcalJobTest extends TestCase { /** @var IConfig | MockObject */ private $config; - /** @var ILogger | MockObject */ - private $logger; + private LoggerInterface $logger; /** @var ITimeFactory | MockObject */ private $timeFactory; @@ -60,7 +59,7 @@ class RefreshWebcalJobTest extends TestCase { $this->refreshWebcalService = $this->createMock(RefreshWebcalService::class); $this->config = $this->createMock(IConfig::class); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->timeFactory = $this->createMock(ITimeFactory::class); $this->jobList = $this->createMock(IJobList::class); @@ -115,7 +114,7 @@ class RefreshWebcalJobTest extends TestCase { ->with('principals/users/testuser', 'sub123'); } - $backgroundJob->execute($this->jobList, $this->logger); + $backgroundJob->start($this->jobList); } /** |