2017-11-11 10:25:40 +00:00
|
|
|
<?php
|
2022-02-22 10:24:38 +00:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2017-11-11 10:25:40 +00:00
|
|
|
/**
|
2024-05-27 15:39:07 +00:00
|
|
|
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2017-11-11 10:25:40 +00:00
|
|
|
*/
|
|
|
|
namespace OCA\DAV\BackgroundJob;
|
|
|
|
|
|
|
|
use OCA\DAV\CalDAV\BirthdayService;
|
2022-02-22 10:24:38 +00:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
|
|
|
use OCP\BackgroundJob\QueuedJob;
|
2017-11-11 10:25:40 +00:00
|
|
|
use OCP\IConfig;
|
|
|
|
|
|
|
|
class GenerateBirthdayCalendarBackgroundJob extends QueuedJob {
|
|
|
|
|
|
|
|
/** @var BirthdayService */
|
|
|
|
private $birthdayService;
|
|
|
|
|
|
|
|
/** @var IConfig */
|
|
|
|
private $config;
|
|
|
|
|
2022-02-22 10:24:38 +00:00
|
|
|
public function __construct(ITimeFactory $time,
|
2023-11-23 09:22:34 +00:00
|
|
|
BirthdayService $birthdayService,
|
|
|
|
IConfig $config) {
|
2022-02-22 10:24:38 +00:00
|
|
|
parent::__construct($time);
|
|
|
|
|
2017-11-11 10:25:40 +00:00
|
|
|
$this->birthdayService = $birthdayService;
|
|
|
|
$this->config = $config;
|
|
|
|
}
|
|
|
|
|
2022-05-05 22:01:08 +00:00
|
|
|
public function run($argument) {
|
|
|
|
$userId = $argument['userId'];
|
|
|
|
$purgeBeforeGenerating = $argument['purgeBeforeGenerating'] ?? false;
|
2017-11-11 10:25:40 +00:00
|
|
|
|
|
|
|
// make sure admin didn't change his mind
|
|
|
|
$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 15:18:58 +00:00
|
|
|
if ($purgeBeforeGenerating) {
|
|
|
|
$this->birthdayService->resetForUser($userId);
|
|
|
|
}
|
|
|
|
|
2017-11-11 10:25:40 +00:00
|
|
|
$this->birthdayService->syncUser($userId);
|
|
|
|
}
|
|
|
|
}
|