2017-10-20 11:29:59 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright 2017, Georg Ehrke <oc.list@georgehrke.com>
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\DAV\Controller;
|
|
|
|
|
2017-11-11 10:25:40 +00:00
|
|
|
use OCA\DAV\BackgroundJob\GenerateBirthdayCalendarBackgroundJob;
|
|
|
|
use OCA\DAV\CalDAV\CalDavBackend;
|
2017-10-20 11:29:59 +00:00
|
|
|
use OCP\AppFramework\Controller;
|
|
|
|
use OCP\AppFramework\Http\JSONResponse;
|
|
|
|
use OCP\AppFramework\Http\Response;
|
2017-11-11 10:25:40 +00:00
|
|
|
use OCP\BackgroundJob\IJobList;
|
2017-10-20 11:29:59 +00:00
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
use OCP\IRequest;
|
2017-11-11 10:25:40 +00:00
|
|
|
use OCP\IUser;
|
|
|
|
use OCP\IUserManager;
|
2017-10-20 11:29:59 +00:00
|
|
|
|
|
|
|
class BirthdayCalendarController extends Controller {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var IDBConnection
|
|
|
|
*/
|
|
|
|
protected $db;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var IConfig
|
|
|
|
*/
|
|
|
|
protected $config;
|
|
|
|
|
2017-11-11 10:25:40 +00:00
|
|
|
/**
|
|
|
|
* @var IUserManager
|
|
|
|
*/
|
|
|
|
protected $userManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var CalDavBackend
|
|
|
|
*/
|
|
|
|
protected $caldavBackend;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var IJobList
|
|
|
|
*/
|
|
|
|
protected $jobList;
|
|
|
|
|
2017-10-20 11:29:59 +00:00
|
|
|
/**
|
|
|
|
* BirthdayCalendar constructor.
|
|
|
|
*
|
|
|
|
* @param string $appName
|
|
|
|
* @param IRequest $request
|
|
|
|
* @param IDBConnection $db
|
|
|
|
* @param IConfig $config
|
2017-11-11 10:25:40 +00:00
|
|
|
* @param IJobList $jobList
|
|
|
|
* @param IUserManager $userManager
|
|
|
|
* @param CalDavBackend $calDavBackend
|
2017-10-20 11:29:59 +00:00
|
|
|
*/
|
|
|
|
public function __construct($appName, IRequest $request,
|
2017-11-11 10:25:40 +00:00
|
|
|
IDBConnection $db, IConfig $config,
|
|
|
|
IJobList $jobList,
|
|
|
|
IUserManager $userManager,
|
|
|
|
CalDavBackend $calDavBackend){
|
2017-10-20 11:29:59 +00:00
|
|
|
parent::__construct($appName, $request);
|
|
|
|
$this->db = $db;
|
|
|
|
$this->config = $config;
|
2017-11-11 10:25:40 +00:00
|
|
|
$this->userManager = $userManager;
|
|
|
|
$this->jobList = $jobList;
|
|
|
|
$this->caldavBackend = $calDavBackend;
|
2017-10-20 11:29:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function enable() {
|
|
|
|
$this->config->setAppValue($this->appName, 'generateBirthdayCalendar', 'yes');
|
|
|
|
|
2017-11-11 10:25:40 +00:00
|
|
|
// add background job for each user
|
|
|
|
$this->userManager->callForAllUsers(function(IUser $user) {
|
|
|
|
$this->jobList->add(GenerateBirthdayCalendarBackgroundJob::class, [
|
|
|
|
'userId' => $user->getUID(),
|
|
|
|
]);
|
|
|
|
});
|
2017-10-20 11:29:59 +00:00
|
|
|
|
|
|
|
return new JSONResponse([]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function disable() {
|
|
|
|
$this->config->setAppValue($this->appName, 'generateBirthdayCalendar', 'no');
|
|
|
|
|
2017-11-11 10:25:40 +00:00
|
|
|
$this->jobList->remove(GenerateBirthdayCalendarBackgroundJob::class);
|
|
|
|
$this->caldavBackend->deleteAllBirthdayCalendars();
|
2017-10-20 11:29:59 +00:00
|
|
|
|
|
|
|
return new JSONResponse([]);
|
|
|
|
}
|
|
|
|
}
|