Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bad revert commit #43465

Merged
merged 9 commits into from
Feb 8, 2024
51 changes: 15 additions & 36 deletions apps/dav/lib/BackgroundJob/RefreshWebcalJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @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>
Expand Down Expand Up @@ -34,50 +35,26 @@
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;
}

/**
* this function is called at most every hour
*
* @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;
Expand All @@ -95,17 +72,19 @@ public function execute(IJobList $jobList, ILogger $logger = null) {
/** @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);
}

/**
Expand Down
55 changes: 17 additions & 38 deletions apps/dav/lib/Migration/BuildCalendarSearchIndexBackgroundJob.php
Original file line number Diff line number Diff line change
@@ -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>
*
Expand All @@ -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) {
Expand All @@ -72,8 +51,8 @@ public function run($arguments) {

$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;
Expand Down Expand Up @@ -105,7 +84,7 @@ private function buildIndex(int $offset, int $stopAt): int {
->orderBy('id', 'ASC')
->setMaxResults(500);

$result = $query->execute();
$result = $query->executeQuery();
while ($row = $result->fetch(\PDO::FETCH_ASSOC)) {
$offset = $row['id'];

Expand Down
55 changes: 17 additions & 38 deletions apps/dav/lib/Migration/BuildSocialSearchIndexBackgroundJob.php
Original file line number Diff line number Diff line change
@@ -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
*
Expand All @@ -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) {
Expand Down Expand Up @@ -90,7 +69,7 @@ public function run($arguments) {
* @return int
*/
private function buildIndex($offset, $stopAt) {
$startTime = $this->timeFactory->getTime();
$startTime = $this->time->getTime();

// get contacts with social profiles
$query = $this->db->getQueryBuilder();
Expand All @@ -99,7 +78,7 @@ private function buildIndex($offset, $stopAt) {
->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;
Expand All @@ -111,7 +90,7 @@ private function buildIndex($offset, $stopAt) {
$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;
}
}
Expand Down
9 changes: 4 additions & 5 deletions apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
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;

Expand All @@ -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;
Expand All @@ -60,7 +59,7 @@ protected function setUp(): void {

$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);
Expand Down Expand Up @@ -115,7 +114,7 @@ public function testRun(int $lastRun, int $time, bool $process): void {
->with('principals/users/testuser', 'sub123');
}

$backgroundJob->execute($this->jobList, $this->logger);
$backgroundJob->start($this->jobList);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function testExecute(bool $isTrustedServer, bool $retainBackgroundJob): v
$this->jobList->expects($this->never())->method('add');
}

$getSharedSecret->execute($this->jobList);
$getSharedSecret->start($this->jobList);
}

public function dataTestExecute() {
Expand Down
11 changes: 7 additions & 4 deletions apps/files/l10n/ar.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ OC.L10N.register(
"Edit locally" : "تعديل محليًا",
"Open" : "افتح",
"_Delete file_::_Delete files_" : ["حذف ملفات","حذف ملف","حذف ملفات","حذف ملفات","حذف ملفات","حذف ملفات"],
"_Delete folder_::_Delete folders_" : ["حذف 0 مجلد","حذف مجلد واحد","حذف مجلدين","حذف مجلدات","حذف مجلدات","حذف مجلدات"],
"_Disconnect storage_::_Disconnect storages_" : ["فصل 0 وحدة تخزين","فصل وحدة تخزين واحدة","فصل وحدتيْ تخزين","فصل وحدات تخزين","فصل وحدات تخزين","فصل وحدات تخزين"],
"_Leave this share_::_Leave these shares_" : ["مغادرة 0 مشاركة","مغادرة هذه المشاركة","مغادرة هاتين المشاركتين","مغادرة هذه المشاركات","مغادرة هذه المشاركات","مغادرة هذه المشاركات"],
"Could not load info for file \"{file}\"" : "لم يستطع تحميل معلومات الملف \"{file}\"",
"Files" : "الملفات",
"Details" : "التفاصيل",
Expand Down Expand Up @@ -172,7 +175,6 @@ OC.L10N.register(
"Drag and drop files here to upload" : "إسحَب و أفلِت الملفات هنا لرفعها",
"Your have used your space quota and cannot upload files anymore" : "لقد استنفذت حصتك التخزينية و لم يعد بإمكانك رفع أي ملفات بعدُ",
"You don’t have permission to upload or create files here" : "لا تملك الصلاحية لرفع او انشاء ملف هنا ",
"Upload successful" : "تمّ الرفع بنجاحٍ",
"\"{displayName}\" action executed successfully" : "\"{displayName}\" الأمر نُفّذ بنجاح",
"\"{displayName}\" action failed" : "\"{dispalyName}\" الأمر أخفق عند التنفيذ",
"Toggle selection for file \"{displayName}\"" : "تبديل الاختيار للملف \"{displayName}\"",
Expand All @@ -191,8 +193,6 @@ OC.L10N.register(
"Could not rename \"{oldName}\", it does not exist any more" : "تعذر إعادة تسمية \"{oldName}\"، لم يعد موجودًا",
"The name \"{newName}\" is already used in the folder \"{dir}\". Please choose a different name." : "الاسم \"{newName}\" مُستعمَلٌ سلفاً في المجلّد\"{dir}\". إختَر اسماً آخر رجاءً.",
"Could not rename \"{oldName}\"" : "تعذرت إعادة تسمية \"{oldName}\"",
"Could not copy {file}. {message}" : "تعذّر نسخ {file}. {message}",
"Could not move {file}. {message}" : "تعذّر نقل {file}. {message}",
"Total rows summary" : "ملخص مجموع الأسطر",
"Toggle selection for all files and folders" : "تبديل الاختيار لكل الملفات و المجلدات",
"\"{displayName}\" failed on some elements " : "\"{displayName}\" فشل في بعض العناصر",
Expand Down Expand Up @@ -261,6 +261,8 @@ OC.L10N.register(
"Unable to create new file from template" : "تعذر إنشاء الملف الجديد من القالب",
"Delete permanently" : "حذف بشكل دائم",
"Delete and unshare" : "إحذِف و الغٍ المشاركات ",
"Confirm deletion" : "أكِّد على الحذف",
"Cancel" : "الغاء",
"Destination is not a folder" : "المَقصَد ليس مُجلّداً",
"This file/folder is already in that directory" : "هذا الملف/المجلد موجود سلفاً في ذلك المجلد",
"You cannot move a file/folder onto itself or into a subfolder of itself" : "لا يمكنك نقل ملف/مجلد إلى نفسه أو إلى مجلد فرعي منه",
Expand All @@ -277,6 +279,8 @@ OC.L10N.register(
"Open folder {displayName}" : "إفتح المجلد {displayName}",
"Open in Files" : "إفتَح في \"الملفات\"",
"Open details" : "افتح التفاصيل",
"Could not copy {file}. {message}" : "تعذّر نسخ {file}. {message}",
"Could not move {file}. {message}" : "تعذّر نقل {file}. {message}",
"Create new templates folder" : "إنشيْ مجلد جديد للقوالب",
"Templates" : "القوالب",
"Unable to initialize the templates directory" : "تعذر تهيئة دليل القوالب",
Expand Down Expand Up @@ -305,7 +309,6 @@ OC.L10N.register(
"You can only favorite a single file or folder at a time" : "يمكنك فقط تفضيل ملف أو مجلد واحد في المرة الواحدة",
"Search users" : "ابحث عن مستخدمين",
"You might not have have permissions to view it, ask the sender to share it" : "يمكن ألاّ تكون لديك صلاحية لعرضه، أطلب من المُرسل إن يشاركه معك",
"Cancel" : "الغاء",
"Set up templates folder" : "إعداد مجلد القوالب",
"Toggle %1$s sublist" : "تبديل %1$s قائمة فرعية",
"Toggle grid view" : "تفعيل/تعطيل القائمة",
Expand Down
Loading
Loading