2017-04-25 05:55:31 -04:00
|
|
|
<?php
|
|
|
|
|
/**
|
2024-05-27 11:39:07 -04:00
|
|
|
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2017-04-25 05:55:31 -04:00
|
|
|
*/
|
|
|
|
|
namespace OCA\DAV\Migration;
|
|
|
|
|
|
|
|
|
|
use OCP\BackgroundJob\IJobList;
|
|
|
|
|
use OCP\IConfig;
|
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
|
use OCP\Migration\IOutput;
|
|
|
|
|
use OCP\Migration\IRepairStep;
|
|
|
|
|
|
|
|
|
|
class BuildCalendarSearchIndex implements IRepairStep {
|
|
|
|
|
|
|
|
|
|
/** @var IDBConnection */
|
|
|
|
|
private $db;
|
|
|
|
|
|
|
|
|
|
/** @var IJobList */
|
|
|
|
|
private $jobList;
|
|
|
|
|
|
|
|
|
|
/** @var IConfig */
|
|
|
|
|
private $config;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param IDBConnection $db
|
|
|
|
|
* @param IJobList $jobList
|
|
|
|
|
* @param IConfig $config
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(IDBConnection $db,
|
2023-11-23 04:22:34 -05:00
|
|
|
IJobList $jobList,
|
|
|
|
|
IConfig $config) {
|
2017-04-25 05:55:31 -04:00
|
|
|
$this->db = $db;
|
|
|
|
|
$this->jobList = $jobList;
|
|
|
|
|
$this->config = $config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getName() {
|
|
|
|
|
return 'Registering building of calendar search index as background job';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param IOutput $output
|
|
|
|
|
*/
|
|
|
|
|
public function run(IOutput $output) {
|
|
|
|
|
// only run once
|
|
|
|
|
if ($this->config->getAppValue('dav', 'buildCalendarSearchIndex') === 'yes') {
|
|
|
|
|
$output->info('Repair step already executed');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$query = $this->db->getQueryBuilder();
|
2018-10-16 08:55:41 -04:00
|
|
|
$query->select($query->createFunction('MAX(' . $query->getColumnName('id') . ')'))
|
2017-04-25 05:55:31 -04:00
|
|
|
->from('calendarobjects');
|
2020-11-05 04:50:53 -05:00
|
|
|
$result = $query->execute();
|
2021-01-03 09:28:31 -05:00
|
|
|
$maxId = (int) $result->fetchOne();
|
2020-11-05 04:50:53 -05:00
|
|
|
$result->closeCursor();
|
2017-04-25 05:55:31 -04:00
|
|
|
|
|
|
|
|
$output->info('Add background job');
|
|
|
|
|
$this->jobList->add(BuildCalendarSearchIndexBackgroundJob::class, [
|
|
|
|
|
'offset' => 0,
|
|
|
|
|
'stopAt' => $maxId
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// if all were done, no need to redo the repair during next upgrade
|
|
|
|
|
$this->config->setAppValue('dav', 'buildCalendarSearchIndex', 'yes');
|
|
|
|
|
}
|
2019-11-22 14:52:10 -05:00
|
|
|
}
|