BuildCalendarSearchIndex.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\DAV\Migration;
  7. use OCP\BackgroundJob\IJobList;
  8. use OCP\IConfig;
  9. use OCP\IDBConnection;
  10. use OCP\Migration\IOutput;
  11. use OCP\Migration\IRepairStep;
  12. class BuildCalendarSearchIndex implements IRepairStep {
  13. public function __construct(
  14. private IDBConnection $db,
  15. private IJobList $jobList,
  16. private IConfig $config,
  17. ) {
  18. }
  19. /**
  20. * @return string
  21. */
  22. public function getName() {
  23. return 'Registering building of calendar search index as background job';
  24. }
  25. /**
  26. * @param IOutput $output
  27. */
  28. public function run(IOutput $output) {
  29. // only run once
  30. if ($this->config->getAppValue('dav', 'buildCalendarSearchIndex') === 'yes') {
  31. $output->info('Repair step already executed');
  32. return;
  33. }
  34. $query = $this->db->getQueryBuilder();
  35. $query->select($query->createFunction('MAX(' . $query->getColumnName('id') . ')'))
  36. ->from('calendarobjects');
  37. $result = $query->executeQuery();
  38. $maxId = (int)$result->fetchOne();
  39. $result->closeCursor();
  40. $output->info('Add background job');
  41. $this->jobList->add(BuildCalendarSearchIndexBackgroundJob::class, [
  42. 'offset' => 0,
  43. 'stopAt' => $maxId
  44. ]);
  45. // if all were done, no need to redo the repair during next upgrade
  46. $this->config->setAppValue('dav', 'buildCalendarSearchIndex', 'yes');
  47. }
  48. }