2017-11-11 05:25:40 -05:00
|
|
|
<?php
|
2022-02-22 05:24:38 -05:00
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2017-11-11 05:25:40 -05:00
|
|
|
/**
|
2024-05-27 11:39:07 -04:00
|
|
|
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2017-11-11 05:25:40 -05:00
|
|
|
*/
|
|
|
|
|
namespace OCA\DAV\BackgroundJob;
|
|
|
|
|
|
|
|
|
|
use OCA\DAV\CalDAV\BirthdayService;
|
2022-02-22 05:24:38 -05:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
|
|
|
|
use OCP\BackgroundJob\QueuedJob;
|
2017-11-11 05:25:40 -05:00
|
|
|
use OCP\IConfig;
|
|
|
|
|
|
|
|
|
|
class GenerateBirthdayCalendarBackgroundJob extends QueuedJob {
|
|
|
|
|
|
2024-10-18 06:04:22 -04:00
|
|
|
public function __construct(
|
|
|
|
|
ITimeFactory $time,
|
|
|
|
|
private BirthdayService $birthdayService,
|
|
|
|
|
private IConfig $config,
|
|
|
|
|
) {
|
2022-02-22 05:24:38 -05:00
|
|
|
parent::__construct($time);
|
2017-11-11 05:25:40 -05:00
|
|
|
}
|
|
|
|
|
|
2022-05-05 18:01:08 -04:00
|
|
|
public function run($argument) {
|
|
|
|
|
$userId = $argument['userId'];
|
|
|
|
|
$purgeBeforeGenerating = $argument['purgeBeforeGenerating'] ?? false;
|
2017-11-11 05:25:40 -05:00
|
|
|
|
2024-10-14 06:09:35 -04:00
|
|
|
// make sure admin didn't change their mind
|
2017-11-11 05:25:40 -05:00
|
|
|
$isGloballyEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes');
|
|
|
|
|
if ($isGloballyEnabled !== 'yes') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// did the user opt out?
|
|
|
|
|
$isUserEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes');
|
|
|
|
|
if ($isUserEnabled !== 'yes') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-16 10:18:58 -05:00
|
|
|
if ($purgeBeforeGenerating) {
|
|
|
|
|
$this->birthdayService->resetForUser($userId);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-11 05:25:40 -05:00
|
|
|
$this->birthdayService->syncUser($userId);
|
|
|
|
|
}
|
|
|
|
|
}
|