2017-10-20 14:29:59 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright 2017, Georg Ehrke <oc.list@georgehrke.com>
|
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2017-10-20 14:29:59 +03:00
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-10-20 14:29:59 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\DAV\Controller;
|
|
|
|
|
2017-11-11 13:25:40 +03:00
|
|
|
use OCA\DAV\BackgroundJob\GenerateBirthdayCalendarBackgroundJob;
|
|
|
|
use OCA\DAV\CalDAV\CalDavBackend;
|
2017-10-20 14:29:59 +03:00
|
|
|
use OCP\AppFramework\Controller;
|
|
|
|
use OCP\AppFramework\Http\JSONResponse;
|
|
|
|
use OCP\AppFramework\Http\Response;
|
2017-11-11 13:25:40 +03:00
|
|
|
use OCP\BackgroundJob\IJobList;
|
2017-10-20 14:29:59 +03:00
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
use OCP\IRequest;
|
2017-11-11 13:25:40 +03:00
|
|
|
use OCP\IUser;
|
|
|
|
use OCP\IUserManager;
|
2017-10-20 14:29:59 +03:00
|
|
|
|
|
|
|
class BirthdayCalendarController extends Controller {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var IDBConnection
|
|
|
|
*/
|
|
|
|
protected $db;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var IConfig
|
|
|
|
*/
|
|
|
|
protected $config;
|
|
|
|
|
2017-11-11 13:25:40 +03:00
|
|
|
/**
|
|
|
|
* @var IUserManager
|
|
|
|
*/
|
|
|
|
protected $userManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var CalDavBackend
|
|
|
|
*/
|
|
|
|
protected $caldavBackend;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var IJobList
|
|
|
|
*/
|
|
|
|
protected $jobList;
|
|
|
|
|
2017-10-20 14:29:59 +03:00
|
|
|
/**
|
|
|
|
* BirthdayCalendar constructor.
|
|
|
|
*
|
|
|
|
* @param string $appName
|
|
|
|
* @param IRequest $request
|
|
|
|
* @param IDBConnection $db
|
|
|
|
* @param IConfig $config
|
2017-11-11 13:25:40 +03:00
|
|
|
* @param IJobList $jobList
|
|
|
|
* @param IUserManager $userManager
|
|
|
|
* @param CalDavBackend $calDavBackend
|
2017-10-20 14:29:59 +03:00
|
|
|
*/
|
|
|
|
public function __construct($appName, IRequest $request,
|
2017-11-11 13:25:40 +03:00
|
|
|
IDBConnection $db, IConfig $config,
|
|
|
|
IJobList $jobList,
|
|
|
|
IUserManager $userManager,
|
2020-04-09 14:53:40 +03:00
|
|
|
CalDavBackend $calDavBackend) {
|
2017-10-20 14:29:59 +03:00
|
|
|
parent::__construct($appName, $request);
|
|
|
|
$this->db = $db;
|
|
|
|
$this->config = $config;
|
2017-11-11 13:25:40 +03:00
|
|
|
$this->userManager = $userManager;
|
|
|
|
$this->jobList = $jobList;
|
|
|
|
$this->caldavBackend = $calDavBackend;
|
2017-10-20 14:29:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function enable() {
|
|
|
|
$this->config->setAppValue($this->appName, 'generateBirthdayCalendar', 'yes');
|
|
|
|
|
2017-11-11 13:25:40 +03:00
|
|
|
// add background job for each user
|
2020-04-09 14:53:40 +03:00
|
|
|
$this->userManager->callForSeenUsers(function (IUser $user) {
|
2017-11-11 13:25:40 +03:00
|
|
|
$this->jobList->add(GenerateBirthdayCalendarBackgroundJob::class, [
|
|
|
|
'userId' => $user->getUID(),
|
|
|
|
]);
|
|
|
|
});
|
2017-10-20 14:29:59 +03:00
|
|
|
|
|
|
|
return new JSONResponse([]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function disable() {
|
|
|
|
$this->config->setAppValue($this->appName, 'generateBirthdayCalendar', 'no');
|
|
|
|
|
2017-11-11 13:25:40 +03:00
|
|
|
$this->jobList->remove(GenerateBirthdayCalendarBackgroundJob::class);
|
|
|
|
$this->caldavBackend->deleteAllBirthdayCalendars();
|
2017-10-20 14:29:59 +03:00
|
|
|
|
|
|
|
return new JSONResponse([]);
|
|
|
|
}
|
|
|
|
}
|