0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-02-07 09:59:46 +00:00
nextcloud_server/apps/dav/lib/Migration/RefreshWebcalJobRegistrar.php
Git'Fellow a1681b0756 chore(db): Apply query prepared statements
Fix: psalm

fix: bad file

fix: bug

chore: add batch

chore: add batch

chore: add batch

fix: psalm
2024-10-17 20:30:47 +02:00

62 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\DAV\Migration;
use OCA\DAV\BackgroundJob\RefreshWebcalJob;
use OCP\BackgroundJob\IJobList;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
class RefreshWebcalJobRegistrar implements IRepairStep {
/**
* FixBirthdayCalendarComponent constructor.
*
* @param IDBConnection $connection
* @param IJobList $jobList
*/
public function __construct(
private IDBConnection $connection,
private IJobList $jobList,
) {
}
/**
* @inheritdoc
*/
public function getName() {
return 'Registering background jobs to update cache for webcal calendars';
}
/**
* @inheritdoc
*/
public function run(IOutput $output) {
$query = $this->connection->getQueryBuilder();
$query->select(['principaluri', 'uri'])
->from('calendarsubscriptions');
$stmt = $query->execute();
$count = 0;
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$args = [
'principaluri' => $row['principaluri'],
'uri' => $row['uri'],
];
if (!$this->jobList->has(RefreshWebcalJob::class, $args)) {
$this->jobList->add(RefreshWebcalJob::class, $args);
$count++;
}
}
$output->info("Added $count background jobs to update webcal calendars");
}
}