aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorLouis Chemineau <louis@chmn.me>2024-02-08 15:31:19 +0100
committerLouis Chemineau <louis@chmn.me>2024-02-08 15:31:19 +0100
commit898df41de968321926e10ad532a64c3915ddad29 (patch)
tree57a0e5ada151890ddf71550f22b502e1f67aeffd /apps/dav
parentd9d60238c7aaab9c61bf2d50c15aa59bc88c8975 (diff)
downloadnextcloud-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 'apps/dav')
-rw-r--r--apps/dav/lib/BackgroundJob/RefreshWebcalJob.php51
-rw-r--r--apps/dav/lib/Migration/BuildCalendarSearchIndexBackgroundJob.php55
-rw-r--r--apps/dav/lib/Migration/BuildSocialSearchIndexBackgroundJob.php55
-rw-r--r--apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php9
4 files changed, 117 insertions, 53 deletions
diff --git a/apps/dav/lib/BackgroundJob/RefreshWebcalJob.php b/apps/dav/lib/BackgroundJob/RefreshWebcalJob.php
index a40aeee3d66..fbb944159fd 100644
--- a/apps/dav/lib/BackgroundJob/RefreshWebcalJob.php
+++ b/apps/dav/lib/BackgroundJob/RefreshWebcalJob.php
@@ -6,7 +6,6 @@ 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>
@@ -35,18 +34,42 @@ use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\BackgroundJob\Job;
use OCP\IConfig;
-use Psr\Log\LoggerInterface;
+use OCP\ILogger;
use Sabre\VObject\DateTimeParser;
use Sabre\VObject\InvalidDataException;
class RefreshWebcalJob extends Job {
- public function __construct(
- private RefreshWebcalService $refreshWebcalService,
- private IConfig $config,
- private LoggerInterface $logger,
- ITimeFactory $timeFactory,
- ) {
+
+ /**
+ * @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) {
parent::__construct($timeFactory);
+ $this->refreshWebcalService = $refreshWebcalService;
+ $this->config = $config;
+ $this->logger = $logger;
+ $this->timeFactory = $timeFactory;
}
/**
@@ -54,7 +77,7 @@ class RefreshWebcalJob extends Job {
*
* @inheritdoc
*/
- public function start(IJobList $jobList): void {
+ public function execute(IJobList $jobList, ILogger $logger = null) {
$subscription = $this->refreshWebcalService->getSubscription($this->argument['principaluri'], $this->argument['uri']);
if (!$subscription) {
return;
@@ -72,19 +95,17 @@ class RefreshWebcalJob extends Job {
/** @var DateInterval $dateInterval */
$dateInterval = DateTimeParser::parseDuration($refreshRate);
} catch (InvalidDataException $ex) {
- $this->logger->error(
- "Subscription $subscriptionId could not be refreshed, refreshrate in database is invalid",
- ['exception' => $ex]
- );
+ $this->logger->logException($ex);
+ $this->logger->warning("Subscription $subscriptionId could not be refreshed, refreshrate in database is invalid");
return;
}
$interval = $this->getIntervalFromDateInterval($dateInterval);
- if (($this->time->getTime() - $this->lastRun) <= $interval) {
+ if (($this->timeFactory->getTime() - $this->lastRun) <= $interval) {
return;
}
- parent::start($jobList);
+ parent::execute($jobList, $logger);
}
/**
diff --git a/apps/dav/lib/Migration/BuildCalendarSearchIndexBackgroundJob.php b/apps/dav/lib/Migration/BuildCalendarSearchIndexBackgroundJob.php
index 0b89a3d1d77..a816e2619a3 100644
--- a/apps/dav/lib/Migration/BuildCalendarSearchIndexBackgroundJob.php
+++ b/apps/dav/lib/Migration/BuildCalendarSearchIndexBackgroundJob.php
@@ -1,11 +1,7 @@
<?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>
*
@@ -27,22 +23,47 @@ declare(strict_types=1);
*/
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 Psr\Log\LoggerInterface;
+use OCP\ILogger;
class BuildCalendarSearchIndexBackgroundJob extends QueuedJob {
- public function __construct(
- private IDBConnection $db,
- private CalDavBackend $calDavBackend,
- private LoggerInterface $logger,
- private IJobList $jobList,
- ITimeFactory $timeFactory
- ) {
- parent::__construct($timeFactory);
+
+ /** @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 run($arguments) {
@@ -51,8 +72,8 @@ class BuildCalendarSearchIndexBackgroundJob extends QueuedJob {
$this->logger->info('Building calendar index (' . $offset .'/' . $stopAt . ')');
- $startTime = $this->time->getTime();
- while (($this->time->getTime() - $startTime) < 15) {
+ $startTime = $this->timeFactory->getTime();
+ while (($this->timeFactory->getTime() - $startTime) < 15) {
$offset = $this->buildIndex($offset, $stopAt);
if ($offset >= $stopAt) {
break;
@@ -84,7 +105,7 @@ class BuildCalendarSearchIndexBackgroundJob extends QueuedJob {
->orderBy('id', 'ASC')
->setMaxResults(500);
- $result = $query->executeQuery();
+ $result = $query->execute();
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 9a688970597..231749521be 100644
--- a/apps/dav/lib/Migration/BuildSocialSearchIndexBackgroundJob.php
+++ b/apps/dav/lib/Migration/BuildSocialSearchIndexBackgroundJob.php
@@ -1,12 +1,8 @@
<?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
*
@@ -26,22 +22,47 @@ declare(strict_types=1);
*/
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 Psr\Log\LoggerInterface;
+use OCP\ILogger;
class BuildSocialSearchIndexBackgroundJob extends QueuedJob {
- public function __construct(
- private IDBConnection $db,
- private CardDavBackend $davBackend,
- private LoggerInterface $logger,
- private IJobList $jobList,
- ITimeFactory $timeFactory,
- ) {
- parent::__construct($timeFactory);
+
+ /** @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 run($arguments) {
@@ -69,7 +90,7 @@ class BuildSocialSearchIndexBackgroundJob extends QueuedJob {
* @return int
*/
private function buildIndex($offset, $stopAt) {
- $startTime = $this->time->getTime();
+ $startTime = $this->timeFactory->getTime();
// get contacts with social profiles
$query = $this->db->getQueryBuilder();
@@ -78,7 +99,7 @@ class BuildSocialSearchIndexBackgroundJob extends QueuedJob {
->orderBy('id', 'ASC')
->where($query->expr()->like('carddata', $query->createNamedParameter('%SOCIALPROFILE%')))
->setMaxResults(100);
- $social_cards = $query->executeQuery()->fetchAll();
+ $social_cards = $query->execute()->fetchAll();
if (empty($social_cards)) {
return $stopAt;
@@ -90,7 +111,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->time->getTime() - $startTime) > 15) {
+ if (($this->timeFactory->getTime() - $startTime) > 15) {
break;
}
}
diff --git a/apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php b/apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php
index 7a7bd83f8c4..81b6118a265 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,7 +46,8 @@ class RefreshWebcalJobTest extends TestCase {
/** @var IConfig | MockObject */
private $config;
- private LoggerInterface $logger;
+ /** @var ILogger | MockObject */
+ private $logger;
/** @var ITimeFactory | MockObject */
private $timeFactory;
@@ -59,7 +60,7 @@ class RefreshWebcalJobTest extends TestCase {
$this->refreshWebcalService = $this->createMock(RefreshWebcalService::class);
$this->config = $this->createMock(IConfig::class);
- $this->logger = $this->createMock(LoggerInterface::class);
+ $this->logger = $this->createMock(ILogger::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->jobList = $this->createMock(IJobList::class);
@@ -114,7 +115,7 @@ class RefreshWebcalJobTest extends TestCase {
->with('principals/users/testuser', 'sub123');
}
- $backgroundJob->start($this->jobList);
+ $backgroundJob->execute($this->jobList, $this->logger);
}
/**