RefreshWebcalJobRegistrar.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2018 Georg Ehrke <oc.list@georgehrke.com>
  5. *
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\DAV\Migration;
  25. use OCA\DAV\BackgroundJob\RefreshWebcalJob;
  26. use OCP\BackgroundJob\IJobList;
  27. use OCP\IDBConnection;
  28. use OCP\Migration\IOutput;
  29. use OCP\Migration\IRepairStep;
  30. class RefreshWebcalJobRegistrar implements IRepairStep {
  31. /** @var IDBConnection */
  32. private $connection;
  33. /** @var IJobList */
  34. private $jobList;
  35. /**
  36. * FixBirthdayCalendarComponent constructor.
  37. *
  38. * @param IDBConnection $connection
  39. * @param IJobList $jobList
  40. */
  41. public function __construct(IDBConnection $connection, IJobList $jobList) {
  42. $this->connection = $connection;
  43. $this->jobList = $jobList;
  44. }
  45. /**
  46. * @inheritdoc
  47. */
  48. public function getName() {
  49. return 'Registering background jobs to update cache for webcal calendars';
  50. }
  51. /**
  52. * @inheritdoc
  53. */
  54. public function run(IOutput $output) {
  55. $query = $this->connection->getQueryBuilder();
  56. $query->select(['principaluri', 'uri'])
  57. ->from('calendarsubscriptions');
  58. $stmt = $query->execute();
  59. $count = 0;
  60. while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
  61. $args = [
  62. 'principaluri' => $row['principaluri'],
  63. 'uri' => $row['uri'],
  64. ];
  65. if (!$this->jobList->has(RefreshWebcalJob::class, $args)) {
  66. $this->jobList->add(RefreshWebcalJob::class, $args);
  67. $count++;
  68. }
  69. }
  70. $output->info("Added $count background jobs to update webcal calendars");
  71. }
  72. }