RegenerateBirthdayCalendars.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * @copyright 2019 Georg Ehrke <oc.list@georgehrke.com>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  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\RegisterRegenerateBirthdayCalendars;
  27. use OCP\BackgroundJob\IJobList;
  28. use OCP\IConfig;
  29. use OCP\Migration\IOutput;
  30. use OCP\Migration\IRepairStep;
  31. class RegenerateBirthdayCalendars implements IRepairStep {
  32. /** @var IJobList */
  33. private $jobList;
  34. /** @var IConfig */
  35. private $config;
  36. /**
  37. * @param IJobList $jobList
  38. * @param IConfig $config
  39. */
  40. public function __construct(IJobList $jobList,
  41. IConfig $config) {
  42. $this->jobList = $jobList;
  43. $this->config = $config;
  44. }
  45. /**
  46. * @return string
  47. */
  48. public function getName() {
  49. return 'Regenerating birthday calendars to use new icons and fix old birthday events without year';
  50. }
  51. /**
  52. * @param IOutput $output
  53. */
  54. public function run(IOutput $output) {
  55. // only run once
  56. if ($this->config->getAppValue('dav', 'regeneratedBirthdayCalendarsForYearFix') === 'yes') {
  57. $output->info('Repair step already executed');
  58. return;
  59. }
  60. $output->info('Adding background jobs to regenerate birthday calendar');
  61. $this->jobList->add(RegisterRegenerateBirthdayCalendars::class);
  62. // if all were done, no need to redo the repair during next upgrade
  63. $this->config->setAppValue('dav', 'regeneratedBirthdayCalendarsForYearFix', 'yes');
  64. }
  65. }