1
0

RefreshWebcalJobRegistrar.php 2.2 KB

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