1
0

BuildSocialSearchIndex.php 1.7 KB

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