You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RegisterBuildReminderIndexBackgroundJob.php 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2019 Georg Ehrke <oc.list@georgehrke.com>
  5. *
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\DAV\Migration;
  27. use OCA\DAV\BackgroundJob\BuildReminderIndexBackgroundJob;
  28. use OCP\BackgroundJob\IJobList;
  29. use OCP\IConfig;
  30. use OCP\IDBConnection;
  31. use OCP\Migration\IOutput;
  32. use OCP\Migration\IRepairStep;
  33. /**
  34. * Class RegisterBuildReminderIndexBackgroundJob
  35. *
  36. * @package OCA\DAV\Migration
  37. */
  38. class RegisterBuildReminderIndexBackgroundJob implements IRepairStep {
  39. /** @var IDBConnection */
  40. private $db;
  41. /** @var IJobList */
  42. private $jobList;
  43. /** @var IConfig */
  44. private $config;
  45. /** @var string */
  46. private const CONFIG_KEY = 'buildCalendarReminderIndex';
  47. /**
  48. * @param IDBConnection $db
  49. * @param IJobList $jobList
  50. * @param IConfig $config
  51. */
  52. public function __construct(IDBConnection $db,
  53. IJobList $jobList,
  54. IConfig $config) {
  55. $this->db = $db;
  56. $this->jobList = $jobList;
  57. $this->config = $config;
  58. }
  59. /**
  60. * @return string
  61. */
  62. public function getName() {
  63. return 'Registering building of calendar reminder index as background job';
  64. }
  65. /**
  66. * @param IOutput $output
  67. */
  68. public function run(IOutput $output) {
  69. // only run once
  70. if ($this->config->getAppValue('dav', self::CONFIG_KEY) === 'yes') {
  71. $output->info('Repair step already executed');
  72. return;
  73. }
  74. $query = $this->db->getQueryBuilder();
  75. $query->select($query->createFunction('MAX(' . $query->getColumnName('id') . ')'))
  76. ->from('calendarobjects');
  77. $result = $query->execute();
  78. $maxId = (int) $result->fetchColumn();
  79. $result->closeCursor();
  80. $output->info('Add background job');
  81. $this->jobList->add(BuildReminderIndexBackgroundJob::class, [
  82. 'offset' => 0,
  83. 'stopAt' => $maxId
  84. ]);
  85. // if all were done, no need to redo the repair during next upgrade
  86. $this->config->setAppValue('dav', self::CONFIG_KEY, 'yes');
  87. }
  88. }