BuildSocialSearchIndex.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 BuildSocialSearchIndex implements IRepairStep {
  13. /**
  14. * @param IDBConnection $db
  15. * @param IJobList $jobList
  16. * @param IConfig $config
  17. */
  18. public function __construct(
  19. private IDBConnection $db,
  20. private IJobList $jobList,
  21. private IConfig $config,
  22. ) {
  23. }
  24. /**
  25. * @return string
  26. */
  27. public function getName() {
  28. return 'Register building of social profile search index as background job';
  29. }
  30. /**
  31. * @param IOutput $output
  32. */
  33. public function run(IOutput $output) {
  34. // only run once
  35. if ($this->config->getAppValue('dav', 'builtSocialSearchIndex') === 'yes') {
  36. $output->info('Repair step already executed');
  37. return;
  38. }
  39. $query = $this->db->getQueryBuilder();
  40. $query->select($query->func()->max('cardid'))
  41. ->from('cards_properties')
  42. ->where($query->expr()->eq('name', $query->createNamedParameter('X-SOCIALPROFILE')));
  43. $maxId = (int)$query->execute()->fetchOne();
  44. if ($maxId === 0) {
  45. return;
  46. }
  47. $output->info('Add background job');
  48. $this->jobList->add(BuildSocialSearchIndexBackgroundJob::class, [
  49. 'offset' => 0,
  50. 'stopAt' => $maxId
  51. ]);
  52. // no need to redo the repair during next upgrade
  53. $this->config->setAppValue('dav', 'builtSocialSearchIndex', 'yes');
  54. }
  55. }