1
0

RefreshWebcalJobRegistrar.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. /** @var IDBConnection */
  15. private $connection;
  16. /** @var IJobList */
  17. private $jobList;
  18. /**
  19. * FixBirthdayCalendarComponent constructor.
  20. *
  21. * @param IDBConnection $connection
  22. * @param IJobList $jobList
  23. */
  24. public function __construct(IDBConnection $connection, IJobList $jobList) {
  25. $this->connection = $connection;
  26. $this->jobList = $jobList;
  27. }
  28. /**
  29. * @inheritdoc
  30. */
  31. public function getName() {
  32. return 'Registering background jobs to update cache for webcal calendars';
  33. }
  34. /**
  35. * @inheritdoc
  36. */
  37. public function run(IOutput $output) {
  38. $query = $this->connection->getQueryBuilder();
  39. $query->select(['principaluri', 'uri'])
  40. ->from('calendarsubscriptions');
  41. $stmt = $query->execute();
  42. $count = 0;
  43. while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
  44. $args = [
  45. 'principaluri' => $row['principaluri'],
  46. 'uri' => $row['uri'],
  47. ];
  48. if (!$this->jobList->has(RefreshWebcalJob::class, $args)) {
  49. $this->jobList->add(RefreshWebcalJob::class, $args);
  50. $count++;
  51. }
  52. }
  53. $output->info("Added $count background jobs to update webcal calendars");
  54. }
  55. }