Use the event dispatcher
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
d3e8463de2
commit
52dd27892b
8 changed files with 189 additions and 177 deletions
|
@ -48,10 +48,8 @@ $principalBackend = new Principal(
|
|||
$db = \OC::$server->getDatabaseConnection();
|
||||
$userManager = \OC::$server->getUserManager();
|
||||
$random = \OC::$server->getSecureRandom();
|
||||
$groupManager = \OC::$server->getGroupManager();
|
||||
$activityManager = \OC::$server->getActivityManager();
|
||||
$userSession = \OC::$server->getUserSession();
|
||||
$calDavBackend = new CalDavBackend($db, $principalBackend, $userManager, $groupManager, $random, $activityManager, $userSession);
|
||||
$dispatcher = \OC::$server->getEventDispatcher();
|
||||
$calDavBackend = new CalDavBackend($db, $principalBackend, $userManager, $random, $dispatcher);
|
||||
|
||||
$debugging = \OC::$server->getConfig()->getSystemValue('debug', false);
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
namespace OCA\DAV\AppInfo;
|
||||
|
||||
use OCA\DAV\CalDAV\Activity\Backend;
|
||||
use OCA\DAV\CalDAV\Activity\Extension;
|
||||
use OCA\DAV\CalDAV\BirthdayService;
|
||||
use OCA\DAV\Capabilities;
|
||||
|
@ -90,6 +91,62 @@ class Application extends App {
|
|||
}
|
||||
});
|
||||
|
||||
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function(GenericEvent $event) {
|
||||
/** @var Backend $backend */
|
||||
$backend = $this->getContainer()->query(Backend::class);
|
||||
$backend->onCalendarAdd(
|
||||
$event->getArgument('calendarData')
|
||||
);
|
||||
});
|
||||
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function(GenericEvent $event) {
|
||||
/** @var Backend $backend */
|
||||
$backend = $this->getContainer()->query(Backend::class);
|
||||
$backend->onCalendarUpdate(
|
||||
$event->getArgument('calendarData'),
|
||||
$event->getArgument('shares'),
|
||||
$event->getArgument('propertyMutations')
|
||||
);
|
||||
});
|
||||
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function(GenericEvent $event) {
|
||||
/** @var Backend $backend */
|
||||
$backend = $this->getContainer()->query(Backend::class);
|
||||
$backend->onCalendarDelete(
|
||||
$event->getArgument('calendarData'),
|
||||
$event->getArgument('shares')
|
||||
);
|
||||
});
|
||||
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function(GenericEvent $event) {
|
||||
/** @var Backend $backend */
|
||||
$backend = $this->getContainer()->query(Backend::class);
|
||||
$backend->onCalendarUpdateShares(
|
||||
$event->getArgument('calendarData'),
|
||||
$event->getArgument('shares'),
|
||||
$event->getArgument('add'),
|
||||
$event->getArgument('remove')
|
||||
);
|
||||
});
|
||||
|
||||
$listener = function(GenericEvent $event, $eventName) {
|
||||
/** @var Backend $backend */
|
||||
$backend = $this->getContainer()->query(Backend::class);
|
||||
|
||||
$subject = Extension::SUBJECT_OBJECT_ADD;
|
||||
if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') {
|
||||
$subject = Extension::SUBJECT_OBJECT_UPDATE;
|
||||
} else if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') {
|
||||
$subject = Extension::SUBJECT_OBJECT_DELETE;
|
||||
}
|
||||
$backend->onTouchCalendarObject(
|
||||
$subject,
|
||||
$event->getArgument('calendarData'),
|
||||
$event->getArgument('shares'),
|
||||
$event->getArgument('objectData')
|
||||
);
|
||||
};
|
||||
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener);
|
||||
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener);
|
||||
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener);
|
||||
|
||||
$aM = $this->getContainer()->getServer()->getActivityManager();
|
||||
$aM->registerExtension(function() {
|
||||
return $this->getContainer()->query(Extension::class);
|
||||
|
|
|
@ -22,8 +22,6 @@
|
|||
namespace OCA\DAV\CalDAV\Activity;
|
||||
|
||||
|
||||
use OCA\DAV\CalDAV\CalDavBackend;
|
||||
use OCA\DAV\CalDAV\Calendar;
|
||||
use OCP\Activity\IEvent;
|
||||
use OCP\Activity\IManager as IActivityManager;
|
||||
use OCP\IGroup;
|
||||
|
@ -39,9 +37,6 @@ use Sabre\VObject\Reader;
|
|||
*/
|
||||
class Backend {
|
||||
|
||||
/** @var CalDavBackend */
|
||||
protected $calDavBackend;
|
||||
|
||||
/** @var IActivityManager */
|
||||
protected $activityManager;
|
||||
|
||||
|
@ -52,13 +47,11 @@ class Backend {
|
|||
protected $userSession;
|
||||
|
||||
/**
|
||||
* @param CalDavBackend $calDavBackend
|
||||
* @param IActivityManager $activityManager
|
||||
* @param IGroupManager $groupManager
|
||||
* @param IUserSession $userSession
|
||||
*/
|
||||
public function __construct(CalDavBackend $calDavBackend, IActivityManager $activityManager, IGroupManager $groupManager, IUserSession $userSession) {
|
||||
$this->calDavBackend = $calDavBackend;
|
||||
public function __construct(IActivityManager $activityManager, IGroupManager $groupManager, IUserSession $userSession) {
|
||||
$this->activityManager = $activityManager;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->userSession = $userSession;
|
||||
|
@ -67,46 +60,47 @@ class Backend {
|
|||
/**
|
||||
* Creates activities when a calendar was creates
|
||||
*
|
||||
* @param int $calendarId
|
||||
* @param array $properties
|
||||
* @param array $calendarData
|
||||
*/
|
||||
public function addCalendar($calendarId, array $properties) {
|
||||
$this->triggerCalendarActivity(Extension::SUBJECT_ADD, $calendarId, $properties);
|
||||
public function onCalendarAdd(array $calendarData) {
|
||||
$this->triggerCalendarActivity(Extension::SUBJECT_ADD, $calendarData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates activities when a calendar was updated
|
||||
*
|
||||
* @param int $calendarId
|
||||
* @param array $calendarData
|
||||
* @param array $shares
|
||||
* @param array $properties
|
||||
*/
|
||||
public function updateCalendar($calendarId, array $properties) {
|
||||
$this->triggerCalendarActivity(Extension::SUBJECT_UPDATE, $calendarId, $properties);
|
||||
public function onCalendarUpdate(array $calendarData, array $shares, array $properties) {
|
||||
$this->triggerCalendarActivity(Extension::SUBJECT_UPDATE, $calendarData, $shares, $properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates activities when a calendar was deleted
|
||||
*
|
||||
* @param int $calendarId
|
||||
* @param array $calendarData
|
||||
* @param array $shares
|
||||
*/
|
||||
public function deleteCalendar($calendarId) {
|
||||
$this->triggerCalendarActivity(Extension::SUBJECT_DELETE, $calendarId);
|
||||
public function onCalendarDelete(array $calendarData, array $shares) {
|
||||
$this->triggerCalendarActivity(Extension::SUBJECT_DELETE, $calendarData, $shares);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates activities for all related users when a calendar was touched
|
||||
*
|
||||
* @param string $action
|
||||
* @param int $calendarId
|
||||
* @param array $calendarData
|
||||
* @param array $shares
|
||||
* @param array $changedProperties
|
||||
*/
|
||||
protected function triggerCalendarActivity($action, $calendarId, array $changedProperties = []) {
|
||||
$properties = $this->calDavBackend->getCalendarById($calendarId);
|
||||
if (!isset($properties['principaluri'])) {
|
||||
protected function triggerCalendarActivity($action, array $calendarData, array $shares = [], array $changedProperties = []) {
|
||||
if (!isset($calendarData['principaluri'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$principal = explode('/', $properties['principaluri']);
|
||||
$principal = explode('/', $calendarData['principaluri']);
|
||||
$owner = $principal[2];
|
||||
|
||||
$currentUser = $this->userSession->getUser();
|
||||
|
@ -118,7 +112,7 @@ class Backend {
|
|||
|
||||
$event = $this->activityManager->generateEvent();
|
||||
$event->setApp('dav')
|
||||
->setObject(Extension::CALENDAR, $calendarId)
|
||||
->setObject(Extension::CALENDAR, $calendarData['id'])
|
||||
->setType(Extension::CALENDAR)
|
||||
->setAuthor($currentUser);
|
||||
|
||||
|
@ -127,10 +121,10 @@ class Backend {
|
|||
'{http://apple.com/ns/ical/}calendar-color'
|
||||
], array_keys($changedProperties));
|
||||
|
||||
if ($action === Extension::SUBJECT_UPDATE && empty($changedVisibleInformation)) {
|
||||
if (empty($shares) || ($action === Extension::SUBJECT_UPDATE && empty($changedVisibleInformation))) {
|
||||
$users = [$owner];
|
||||
} else {
|
||||
$users = $this->getUsersForCalendar($calendarId);
|
||||
$users = $this->getUsersForShares($shares);
|
||||
$users[] = $owner;
|
||||
}
|
||||
|
||||
|
@ -140,7 +134,7 @@ class Backend {
|
|||
$user === $currentUser ? $action . '_self' : $action,
|
||||
[
|
||||
$currentUser,
|
||||
$properties['{DAV:}displayname'],
|
||||
$calendarData['{DAV:}displayname'],
|
||||
]
|
||||
);
|
||||
$this->activityManager->publish($event);
|
||||
|
@ -150,16 +144,13 @@ class Backend {
|
|||
/**
|
||||
* Creates activities for all related users when a calendar was (un-)shared
|
||||
*
|
||||
* @param Calendar $calendar
|
||||
* @param array $calendarData
|
||||
* @param array $shares
|
||||
* @param array $add
|
||||
* @param array $remove
|
||||
*/
|
||||
public function updateCalendarShares(Calendar $calendar, array $add, array $remove) {
|
||||
$calendarId = $calendar->getResourceId();
|
||||
$shares = $this->calDavBackend->getShares($calendarId);
|
||||
|
||||
$properties = $this->calDavBackend->getCalendarById($calendarId);
|
||||
$principal = explode('/', $properties['principaluri']);
|
||||
public function onCalendarUpdateShares(array $calendarData, array $shares, array $add, array $remove) {
|
||||
$principal = explode('/', $calendarData['principaluri']);
|
||||
$owner = $principal[2];
|
||||
|
||||
$currentUser = $this->userSession->getUser();
|
||||
|
@ -171,7 +162,7 @@ class Backend {
|
|||
|
||||
$event = $this->activityManager->generateEvent();
|
||||
$event->setApp('dav')
|
||||
->setObject(Extension::CALENDAR, $calendarId)
|
||||
->setObject(Extension::CALENDAR, $calendarData['id'])
|
||||
->setType(Extension::CALENDAR)
|
||||
->setAuthor($currentUser);
|
||||
|
||||
|
@ -187,7 +178,7 @@ class Backend {
|
|||
$this->triggerActivityUser(
|
||||
$principal[2],
|
||||
$event,
|
||||
$properties,
|
||||
$calendarData,
|
||||
Extension::SUBJECT_UNSHARE_USER,
|
||||
Extension::SUBJECT_DELETE . '_self'
|
||||
);
|
||||
|
@ -195,7 +186,7 @@ class Backend {
|
|||
if ($owner !== $principal[2]) {
|
||||
$parameters = [
|
||||
$principal[2],
|
||||
$properties['{DAV:}displayname'],
|
||||
$calendarData['{DAV:}displayname'],
|
||||
];
|
||||
|
||||
if ($owner === $event->getAuthor()) {
|
||||
|
@ -216,11 +207,11 @@ class Backend {
|
|||
$this->activityManager->publish($event);
|
||||
}
|
||||
} else if ($principal[1] === 'groups') {
|
||||
$this->triggerActivityGroup($principal[2], $event, $properties, Extension::SUBJECT_UNSHARE_USER);
|
||||
$this->triggerActivityGroup($principal[2], $event, $calendarData, Extension::SUBJECT_UNSHARE_USER);
|
||||
|
||||
$parameters = [
|
||||
$principal[2],
|
||||
$properties['{DAV:}displayname'],
|
||||
$calendarData['{DAV:}displayname'],
|
||||
];
|
||||
|
||||
if ($owner === $event->getAuthor()) {
|
||||
|
@ -253,12 +244,12 @@ class Backend {
|
|||
$principal = explode('/', $parts[1]);
|
||||
|
||||
if ($principal[1] === 'users') {
|
||||
$this->triggerActivityUser($principal[2], $event, $properties, Extension::SUBJECT_SHARE_USER);
|
||||
$this->triggerActivityUser($principal[2], $event, $calendarData, Extension::SUBJECT_SHARE_USER);
|
||||
|
||||
if ($owner !== $principal[2]) {
|
||||
$parameters = [
|
||||
$principal[2],
|
||||
$properties['{DAV:}displayname'],
|
||||
$calendarData['{DAV:}displayname'],
|
||||
];
|
||||
|
||||
if ($owner === $event->getAuthor()) {
|
||||
|
@ -277,11 +268,11 @@ class Backend {
|
|||
$this->activityManager->publish($event);
|
||||
}
|
||||
} else if ($principal[1] === 'groups') {
|
||||
$this->triggerActivityGroup($principal[2], $event, $properties, Extension::SUBJECT_SHARE_USER);
|
||||
$this->triggerActivityGroup($principal[2], $event, $calendarData, Extension::SUBJECT_SHARE_USER);
|
||||
|
||||
$parameters = [
|
||||
$principal[2],
|
||||
$properties['{DAV:}displayname'],
|
||||
$calendarData['{DAV:}displayname'],
|
||||
];
|
||||
|
||||
if ($owner === $event->getAuthor()) {
|
||||
|
@ -363,49 +354,19 @@ class Backend {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates activities when a calendar object was created
|
||||
*
|
||||
* @param int $calendarId
|
||||
* @param string $objectUri
|
||||
*/
|
||||
public function addCalendarObject($calendarId, $objectUri) {
|
||||
$this->triggerCalendarObjectActivity(Extension::SUBJECT_OBJECT_ADD, $calendarId, $objectUri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates activities when a calendar object was updated
|
||||
*
|
||||
* @param int $calendarId
|
||||
* @param string $objectUri
|
||||
*/
|
||||
public function updateCalendarObject($calendarId, $objectUri) {
|
||||
$this->triggerCalendarObjectActivity(Extension::SUBJECT_OBJECT_UPDATE, $calendarId, $objectUri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates activities when a calendar object was deleted
|
||||
*
|
||||
* @param int $calendarId
|
||||
* @param string $objectUri
|
||||
*/
|
||||
public function deleteCalendarObject($calendarId, $objectUri) {
|
||||
$this->triggerCalendarObjectActivity(Extension::SUBJECT_OBJECT_DELETE, $calendarId, $objectUri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates activities for all related users when a calendar was touched
|
||||
* Creates activities when a calendar object was created/updated/deleted
|
||||
*
|
||||
* @param string $action
|
||||
* @param int $calendarId
|
||||
* @param string $objectUri
|
||||
* @param array $calendarData
|
||||
* @param array $shares
|
||||
* @param array $objectData
|
||||
*/
|
||||
protected function triggerCalendarObjectActivity($action, $calendarId, $objectUri) {
|
||||
$properties = $this->calDavBackend->getCalendarById($calendarId);
|
||||
if (!isset($properties['principaluri'])) {
|
||||
public function onTouchCalendarObject($action, array $calendarData, array $shares, array $objectData) {
|
||||
if (!isset($calendarData['principaluri'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$principal = explode('/', $properties['principaluri']);
|
||||
$principal = explode('/', $calendarData['principaluri']);
|
||||
$owner = $principal[2];
|
||||
|
||||
$currentUser = $this->userSession->getUser();
|
||||
|
@ -415,7 +376,7 @@ class Backend {
|
|||
$currentUser = $owner;
|
||||
}
|
||||
|
||||
$object = $this->getObjectNameAndType($calendarId, $objectUri);
|
||||
$object = $this->getObjectNameAndType($objectData);
|
||||
$action = $action . '_' . $object['type'];
|
||||
|
||||
if ($object['type'] === 'todo' && strpos($action, Extension::SUBJECT_OBJECT_UPDATE) === 0 && $object['status'] === 'COMPLETED') {
|
||||
|
@ -426,11 +387,11 @@ class Backend {
|
|||
|
||||
$event = $this->activityManager->generateEvent();
|
||||
$event->setApp('dav')
|
||||
->setObject(Extension::CALENDAR, $calendarId)
|
||||
->setObject(Extension::CALENDAR, $calendarData['id'])
|
||||
->setType($object['type'] === 'event' ? Extension::CALENDAR_EVENT : Extension::CALENDAR_TODO)
|
||||
->setAuthor($currentUser);
|
||||
|
||||
$users = $this->getUsersForCalendar($calendarId);
|
||||
$users = $this->getUsersForShares($shares);
|
||||
$users[] = $owner;
|
||||
|
||||
foreach ($users as $user) {
|
||||
|
@ -439,7 +400,7 @@ class Backend {
|
|||
$user === $currentUser ? $action . '_self' : $action,
|
||||
[
|
||||
$currentUser,
|
||||
$properties['{DAV:}displayname'],
|
||||
$calendarData['{DAV:}displayname'],
|
||||
$object['name'],
|
||||
]
|
||||
);
|
||||
|
@ -448,14 +409,11 @@ class Backend {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param int $calendarId
|
||||
* @param string $objectUri
|
||||
* @param array $objectData
|
||||
* @return string[]|bool
|
||||
*/
|
||||
protected function getObjectNameAndType($calendarId, $objectUri) {
|
||||
$data = $this->calDavBackend->getCalendarObject($calendarId, $objectUri);
|
||||
|
||||
$vObject = Reader::read($data['calendardata']);
|
||||
protected function getObjectNameAndType(array $objectData) {
|
||||
$vObject = Reader::read($objectData['calendardata']);
|
||||
$component = $componentType = null;
|
||||
foreach($vObject->getComponents() as $component) {
|
||||
if (in_array($component->name, ['VEVENT', 'VTODO'])) {
|
||||
|
@ -478,12 +436,11 @@ class Backend {
|
|||
/**
|
||||
* Get all users that have access to a given calendar
|
||||
*
|
||||
* @param int $calendarId
|
||||
* @param array $shares
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getUsersForCalendar($calendarId) {
|
||||
protected function getUsersForShares(array $shares) {
|
||||
$users = $groups = [];
|
||||
$shares = $this->calDavBackend->getShares($calendarId);
|
||||
foreach ($shares as $share) {
|
||||
$prinical = explode('/', $share['{http://owncloud.org/ns}principal']);
|
||||
if ($prinical[1] === 'users') {
|
||||
|
|
|
@ -26,16 +26,12 @@
|
|||
namespace OCA\DAV\CalDAV;
|
||||
|
||||
use OCA\DAV\DAV\Sharing\IShareable;
|
||||
use OCA\DAV\CalDAV\Activity\Backend as ActivityBackend;
|
||||
use OCP\Activity\IManager as IActivityManager;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
use OCA\DAV\Connector\Sabre\Principal;
|
||||
use OCA\DAV\DAV\Sharing\Backend;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
use OCP\Security\ISecureRandom;
|
||||
use Sabre\CalDAV\Backend\AbstractBackend;
|
||||
use Sabre\CalDAV\Backend\SchedulingSupport;
|
||||
|
@ -52,6 +48,8 @@ use Sabre\HTTP\URLUtil;
|
|||
use Sabre\VObject\DateTimeParser;
|
||||
use Sabre\VObject\Reader;
|
||||
use Sabre\VObject\Recur\EventIterator;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||
|
||||
/**
|
||||
* Class CalDavBackend
|
||||
|
@ -131,8 +129,8 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
/** @var ISecureRandom */
|
||||
private $random;
|
||||
|
||||
/** @var ActivityBackend */
|
||||
private $activityBackend;
|
||||
/** @var EventDispatcherInterface */
|
||||
private $dispatcher;
|
||||
|
||||
/**
|
||||
* CalDavBackend constructor.
|
||||
|
@ -140,25 +138,20 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
* @param IDBConnection $db
|
||||
* @param Principal $principalBackend
|
||||
* @param IUserManager $userManager
|
||||
* @param IGroupManager $groupManager
|
||||
* @param ISecureRandom $random
|
||||
* @param IActivityManager $activityManager
|
||||
* @param IUserSession $userSession
|
||||
* @param EventDispatcherInterface $dispatcher
|
||||
*/
|
||||
public function __construct(IDBConnection $db,
|
||||
Principal $principalBackend,
|
||||
IUserManager $userManager,
|
||||
IGroupManager $groupManager,
|
||||
ISecureRandom $random,
|
||||
IActivityManager $activityManager,
|
||||
IUserSession $userSession) {
|
||||
EventDispatcherInterface $dispatcher) {
|
||||
$this->db = $db;
|
||||
$this->principalBackend = $principalBackend;
|
||||
$this->userManager = $userManager;
|
||||
$this->userManager = $groupManager;
|
||||
$this->sharingBackend = new Backend($this->db, $principalBackend, 'calendar');
|
||||
$this->activityBackend = new ActivityBackend($this, $activityManager, $groupManager, $userSession);
|
||||
$this->random = $random;
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -623,7 +616,12 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
$query->execute();
|
||||
$calendarId = $query->getLastInsertId();
|
||||
|
||||
$this->activityBackend->addCalendar($calendarId, $values);
|
||||
$this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', new GenericEvent(
|
||||
'\OCA\DAV\CalDAV\CalDavBackend::createCalendar',
|
||||
[
|
||||
'calendarId' => $calendarId,
|
||||
'calendarData' => $this->getCalendarById($calendarId),
|
||||
]));
|
||||
|
||||
return $calendarId;
|
||||
}
|
||||
|
@ -673,7 +671,14 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
|
||||
$this->addChange($calendarId, "", 2);
|
||||
|
||||
$this->activityBackend->updateCalendar($calendarId, $mutations);
|
||||
$this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', new GenericEvent(
|
||||
'\OCA\DAV\CalDAV\CalDavBackend::updateCalendar',
|
||||
[
|
||||
'calendarId' => $calendarId,
|
||||
'calendarData' => $this->getCalendarById($calendarId),
|
||||
'shares' => $this->getShares($calendarId),
|
||||
'propertyMutations' => $mutations,
|
||||
]));
|
||||
|
||||
return true;
|
||||
});
|
||||
|
@ -686,7 +691,13 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
* @return void
|
||||
*/
|
||||
function deleteCalendar($calendarId) {
|
||||
$this->activityBackend->deleteCalendar($calendarId);
|
||||
$this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', new GenericEvent(
|
||||
'\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar',
|
||||
[
|
||||
'calendarId' => $calendarId,
|
||||
'calendarData' => $this->getCalendarById($calendarId),
|
||||
'shares' => $this->getShares($calendarId),
|
||||
]));
|
||||
|
||||
$stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ?');
|
||||
$stmt->execute([$calendarId]);
|
||||
|
@ -892,7 +903,15 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
])
|
||||
->execute();
|
||||
|
||||
$this->activityBackend->addCalendarObject($calendarId, $objectUri);
|
||||
$this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', new GenericEvent(
|
||||
'\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject',
|
||||
[
|
||||
'calendarId' => $calendarId,
|
||||
'calendarData' => $this->getCalendarById($calendarId),
|
||||
'shares' => $this->getShares($calendarId),
|
||||
'objectData' => $this->getCalendarObject($calendarId, $objectUri),
|
||||
]
|
||||
));
|
||||
$this->addChange($calendarId, $objectUri, 1);
|
||||
|
||||
return '"' . $extraData['etag'] . '"';
|
||||
|
@ -934,7 +953,18 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri)))
|
||||
->execute();
|
||||
|
||||
$this->activityBackend->updateCalendarObject($calendarId, $objectUri);
|
||||
$data = $this->getCalendarObject($calendarId, $objectUri);
|
||||
if (is_array($data)) {
|
||||
$this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', new GenericEvent(
|
||||
'\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject',
|
||||
[
|
||||
'calendarId' => $calendarId,
|
||||
'calendarData' => $this->getCalendarById($calendarId),
|
||||
'shares' => $this->getShares($calendarId),
|
||||
'objectData' => $data,
|
||||
]
|
||||
));
|
||||
}
|
||||
$this->addChange($calendarId, $objectUri, 2);
|
||||
|
||||
return '"' . $extraData['etag'] . '"';
|
||||
|
@ -967,7 +997,18 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
* @return void
|
||||
*/
|
||||
function deleteCalendarObject($calendarId, $objectUri) {
|
||||
$this->activityBackend->deleteCalendarObject($calendarId, $objectUri);
|
||||
$data = $this->getCalendarObject($calendarId, $objectUri);
|
||||
if (is_array($data)) {
|
||||
$this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', new GenericEvent(
|
||||
'\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject',
|
||||
[
|
||||
'calendarId' => $calendarId,
|
||||
'calendarData' => $this->getCalendarById($calendarId),
|
||||
'shares' => $this->getShares($calendarId),
|
||||
'objectData' => $data,
|
||||
]
|
||||
));
|
||||
}
|
||||
|
||||
$stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ? AND `uri` = ?');
|
||||
$stmt->execute([$calendarId, $objectUri]);
|
||||
|
@ -1668,8 +1709,16 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
* @param array $remove
|
||||
*/
|
||||
public function updateShares($shareable, $add, $remove) {
|
||||
/** @var Calendar $shareable */
|
||||
$this->activityBackend->updateCalendarShares($shareable, $add, $remove);
|
||||
$calendarId = $shareable->getResourceId();
|
||||
$this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateShares', new GenericEvent(
|
||||
'\OCA\DAV\CalDAV\CalDavBackend::updateShares',
|
||||
[
|
||||
'calendarId' => $calendarId,
|
||||
'calendarData' => $this->getCalendarById($calendarId),
|
||||
'shares' => $this->getShares($calendarId),
|
||||
'add' => $add,
|
||||
'remove' => $remove,
|
||||
]));
|
||||
$this->sharingBackend->updateShares($shareable, $add, $remove);
|
||||
}
|
||||
|
||||
|
|
|
@ -76,11 +76,10 @@ class CreateCalendar extends Command {
|
|||
$this->groupManager
|
||||
);
|
||||
$random = \OC::$server->getSecureRandom();
|
||||
$activityManager = \OC::$server->getActivityManager();
|
||||
$userSession = \OC::$server->getUserSession();
|
||||
$dispatcher = \OC::$server->getEventDispatcher();
|
||||
|
||||
$name = $input->getArgument('name');
|
||||
$caldav = new CalDavBackend($this->dbConnection, $principalBackend, $this->userManager, $this->groupManager, $random, $activityManager, $userSession);
|
||||
$caldav = new CalDavBackend($this->dbConnection, $principalBackend, $this->userManager, $random, $dispatcher);
|
||||
$caldav->createCalendar("principals/users/$user", $name, []);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,9 +41,6 @@ class RootCollection extends SimpleCollection {
|
|||
$config = \OC::$server->getConfig();
|
||||
$random = \OC::$server->getSecureRandom();
|
||||
$userManager = \OC::$server->getUserManager();
|
||||
$groupManager = \OC::$server->getGroupManager();
|
||||
$activityManager = \OC::$server->getActivityManager();
|
||||
$userSession = \OC::$server->getUserSession();
|
||||
$db = \OC::$server->getDatabaseConnection();
|
||||
$dispatcher = \OC::$server->getEventDispatcher();
|
||||
$userPrincipalBackend = new Principal(
|
||||
|
@ -65,7 +62,7 @@ class RootCollection extends SimpleCollection {
|
|||
$systemPrincipals->disableListing = $disableListing;
|
||||
$filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users');
|
||||
$filesCollection->disableListing = $disableListing;
|
||||
$caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $activityManager, $userSession);
|
||||
$caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $random, $dispatcher);
|
||||
$calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users');
|
||||
$calendarRoot->disableListing = $disableListing;
|
||||
$publicCalendarRoot = new PublicCalendarRoot($caldavBackend);
|
||||
|
|
|
@ -22,15 +22,12 @@
|
|||
|
||||
namespace OCA\DAV\Tests\unit\CalDAV;
|
||||
|
||||
use OCA\DAV\CalDAV\Activity\Backend as ActivityBackend;
|
||||
use OCA\DAV\CalDAV\CalDavBackend;
|
||||
use OCA\DAV\Connector\Sabre\Principal;
|
||||
use OCP\Activity\IManager as IActivityManager;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
use OCP\Security\ISecureRandom;
|
||||
use Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Test\TestCase;
|
||||
|
||||
/**
|
||||
|
@ -49,8 +46,6 @@ abstract class AbstractCalDavBackendTest extends TestCase {
|
|||
protected $principal;
|
||||
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $userManager;
|
||||
/** @var ActivityBackend|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $activityBackend;
|
||||
|
||||
/** @var ISecureRandom */
|
||||
private $random;
|
||||
|
@ -63,9 +58,7 @@ abstract class AbstractCalDavBackendTest extends TestCase {
|
|||
parent::setUp();
|
||||
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
$groupManager = $this->createMock(IGroupManager::class);
|
||||
$activityManager = $this->createMock(IActivityManager::class);
|
||||
$userSession = $this->createMock(IUserSession::class);
|
||||
$dispatcher = $this->createMock(EventDispatcherInterface::class);
|
||||
$this->principal = $this->getMockBuilder('OCA\DAV\Connector\Sabre\Principal')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['getPrincipalByPath', 'getGroupMembership'])
|
||||
|
@ -80,10 +73,7 @@ abstract class AbstractCalDavBackendTest extends TestCase {
|
|||
|
||||
$db = \OC::$server->getDatabaseConnection();
|
||||
$this->random = \OC::$server->getSecureRandom();
|
||||
$this->backend = new CalDavBackend($db, $this->principal, $this->userManager, $groupManager, $this->random, $activityManager, $userSession);
|
||||
|
||||
$this->activityBackend = $this->createMock(ActivityBackend::class);
|
||||
$this->invokePrivate($this->backend, 'activityBackend', [$this->activityBackend]);
|
||||
$this->backend = new CalDavBackend($db, $this->principal, $this->userManager, $this->random, $dispatcher);
|
||||
|
||||
$this->cleanUpBackend();
|
||||
}
|
||||
|
|
|
@ -2,17 +2,14 @@
|
|||
|
||||
namespace OCA\DAV\Tests\unit\CalDAV;
|
||||
|
||||
use OCA\DAV\CalDAV\Activity\Backend as ActivityBackend;
|
||||
use OCA\DAV\CalDAV\Calendar;
|
||||
use OCA\DAV\Connector\Sabre\Principal;
|
||||
use OCP\Activity\IManager as IActivityManager;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IL10N;
|
||||
use OCA\DAV\CalDAV\CalDavBackend;
|
||||
use OCA\DAV\CalDAV\PublicCalendarRoot;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
use OCP\Security\ISecureRandom;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Test\TestCase;
|
||||
|
||||
/**
|
||||
|
@ -35,14 +32,6 @@ class PublicCalendarRootTest extends TestCase {
|
|||
private $principal;
|
||||
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $userManager;
|
||||
/** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $groupManager;
|
||||
/** @var IActivityManager|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $activityManager;
|
||||
/** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $userSession;
|
||||
/** @var ActivityBackend|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $activityBackend;
|
||||
|
||||
/** @var ISecureRandom */
|
||||
private $random;
|
||||
|
@ -53,24 +42,17 @@ class PublicCalendarRootTest extends TestCase {
|
|||
$db = \OC::$server->getDatabaseConnection();
|
||||
$this->principal = $this->createMock('OCA\DAV\Connector\Sabre\Principal');
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
$groupManager = $this->createMock(IGroupManager::class);
|
||||
$activityManager = $this->createMock(IActivityManager::class);
|
||||
$userSession = $this->createMock(IUserSession::class);
|
||||
$this->random = \OC::$server->getSecureRandom();
|
||||
$dispatcher = $this->createMock(EventDispatcherInterface::class);
|
||||
|
||||
$this->backend = new CalDavBackend(
|
||||
$db,
|
||||
$this->principal,
|
||||
$this->userManager,
|
||||
$groupManager,
|
||||
$this->random,
|
||||
$activityManager,
|
||||
$userSession
|
||||
$dispatcher
|
||||
);
|
||||
|
||||
$this->activityBackend = $this->createMock(ActivityBackend::class);
|
||||
$this->invokePrivate($this->backend, 'activityBackend', [$this->activityBackend]);
|
||||
|
||||
$this->publicCalendarRoot = new PublicCalendarRoot($this->backend);
|
||||
|
||||
$this->l10n = $this->getMockBuilder('\OCP\IL10N')
|
||||
|
@ -95,14 +77,6 @@ class PublicCalendarRootTest extends TestCase {
|
|||
}
|
||||
|
||||
public function testGetChild() {
|
||||
$this->activityBackend->expects($this->exactly(1))
|
||||
->method('addCalendar');
|
||||
$this->activityBackend->expects($this->never())
|
||||
->method('updateCalendar');
|
||||
$this->activityBackend->expects($this->never())
|
||||
->method('deleteCalendar');
|
||||
$this->activityBackend->expects($this->never())
|
||||
->method('updateCalendarShares');
|
||||
|
||||
$calendar = $this->createPublicCalendar();
|
||||
|
||||
|
@ -117,15 +91,6 @@ class PublicCalendarRootTest extends TestCase {
|
|||
}
|
||||
|
||||
public function testGetChildren() {
|
||||
$this->activityBackend->expects($this->exactly(1))
|
||||
->method('addCalendar');
|
||||
$this->activityBackend->expects($this->never())
|
||||
->method('updateCalendar');
|
||||
$this->activityBackend->expects($this->never())
|
||||
->method('deleteCalendar');
|
||||
$this->activityBackend->expects($this->never())
|
||||
->method('updateCalendarShares');
|
||||
|
||||
$this->createPublicCalendar();
|
||||
|
||||
$publicCalendars = $this->backend->getPublicCalendars();
|
||||
|
|
Loading…
Reference in a new issue