RefreshWebcalJobRegistrar.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\DAV\Migration;
  8. use OCA\DAV\BackgroundJob\RefreshWebcalJob;
  9. use OCP\BackgroundJob\IJobList;
  10. use OCP\IDBConnection;
  11. use OCP\Migration\IOutput;
  12. use OCP\Migration\IRepairStep;
  13. class RefreshWebcalJobRegistrar implements IRepairStep {
  14. /**
  15. * FixBirthdayCalendarComponent constructor.
  16. *
  17. * @param IDBConnection $connection
  18. * @param IJobList $jobList
  19. */
  20. public function __construct(
  21. private IDBConnection $connection,
  22. private IJobList $jobList,
  23. ) {
  24. }
  25. /**
  26. * @inheritdoc
  27. */
  28. public function getName() {
  29. return 'Registering background jobs to update cache for webcal calendars';
  30. }
  31. /**
  32. * @inheritdoc
  33. */
  34. public function run(IOutput $output) {
  35. $query = $this->connection->getQueryBuilder();
  36. $query->select(['principaluri', 'uri'])
  37. ->from('calendarsubscriptions');
  38. $stmt = $query->execute();
  39. $count = 0;
  40. while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
  41. $args = [
  42. 'principaluri' => $row['principaluri'],
  43. 'uri' => $row['uri'],
  44. ];
  45. if (!$this->jobList->has(RefreshWebcalJob::class, $args)) {
  46. $this->jobList->add(RefreshWebcalJob::class, $args);
  47. $count++;
  48. }
  49. }
  50. $output->info("Added $count background jobs to update webcal calendars");
  51. }
  52. }