summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2016-09-25 13:35:53 +0200
committerLukas Reschke <lukas@statuscode.ch>2016-09-27 18:33:56 +0200
commitda1543eef7d0e00a928b582858fc0f906c671b36 (patch)
tree458f63f4a00c9834ea3d08e757617fe07c5f6d3e /apps
parent5215833fe4b661c46dfed88eb29754011dbb899f (diff)
downloadnextcloud-server-da1543eef7d0e00a928b582858fc0f906c671b36.tar.gz
nextcloud-server-da1543eef7d0e00a928b582858fc0f906c671b36.zip
fix deletion of calendars
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'apps')
-rw-r--r--apps/dav/lib/CalDAV/CalDavBackend.php42
-rw-r--r--apps/dav/lib/HookManager.php17
-rw-r--r--apps/dav/tests/unit/DAV/HookManagerTest.php2
3 files changed, 55 insertions, 6 deletions
diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php
index 367b239a67d..535bf3956e8 100644
--- a/apps/dav/lib/CalDAV/CalDavBackend.php
+++ b/apps/dav/lib/CalDAV/CalDavBackend.php
@@ -282,6 +282,48 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
return array_values($calendars);
}
+ public function getUsersOwnCalendars($principalUri) {
+ $principalUri = $this->convertPrincipal($principalUri, true);
+ $fields = array_values($this->propertyMap);
+ $fields[] = 'id';
+ $fields[] = 'uri';
+ $fields[] = 'synctoken';
+ $fields[] = 'components';
+ $fields[] = 'principaluri';
+ $fields[] = 'transparent';
+ // Making fields a comma-delimited list
+ $query = $this->db->getQueryBuilder();
+ $query->select($fields)->from('calendars')
+ ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)))
+ ->orderBy('calendarorder', 'ASC');
+ $stmt = $query->execute();
+ $calendars = [];
+ while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
+ $components = [];
+ if ($row['components']) {
+ $components = explode(',',$row['components']);
+ }
+ $calendar = [
+ 'id' => $row['id'],
+ 'uri' => $row['uri'],
+ 'principaluri' => $this->convertPrincipal($row['principaluri'], false),
+ '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'),
+ '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
+ '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components),
+ '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'),
+ ];
+ foreach($this->propertyMap as $xmlName=>$dbName) {
+ $calendar[$xmlName] = $row[$dbName];
+ }
+ if (!isset($calendars[$calendar['id']])) {
+ $calendars[$calendar['id']] = $calendar;
+ }
+ }
+ $stmt->closeCursor();
+ return array_values($calendars);
+ }
+
+
private function getUserDisplayName($uid) {
if (!isset($this->userDisplayNames[$uid])) {
$user = $this->userManager->get($uid);
diff --git a/apps/dav/lib/HookManager.php b/apps/dav/lib/HookManager.php
index 1680a907755..e54a39acf2f 100644
--- a/apps/dav/lib/HookManager.php
+++ b/apps/dav/lib/HookManager.php
@@ -46,6 +46,12 @@ class HookManager {
/** @var CardDavBackend */
private $cardDav;
+ /** @var array */
+ private $calendarsToDelete;
+
+ /** @var array */
+ private $addressBooksToDelete;
+
public function __construct(IUserManager $userManager,
SyncService $syncService,
CalDavBackend $calDav,
@@ -85,7 +91,10 @@ class HookManager {
}
public function preDeleteUser($params) {
- $this->usersToDelete[$params['uid']] = $this->userManager->get($params['uid']);
+ $uid = $params['uid'];
+ $this->usersToDelete[$uid] = $this->userManager->get($uid);
+ $this->calendarsToDelete = $this->calDav->getUsersOwnCalendars('principals/users/' . $uid);
+ $this->addressBooksToDelete = $this->cardDav->getAddressBooksForUser('principals/users/' . $uid);
}
public function postDeleteUser($params) {
@@ -94,14 +103,12 @@ class HookManager {
$this->syncService->deleteUser($this->usersToDelete[$uid]);
}
- $calendarsToDelete = $this->calDav->getCalendarsForUser('principals/users/' . $uid);
- foreach ($calendarsToDelete as $calendar) {
+ foreach ($this->calendarsToDelete as $calendar) {
$this->calDav->deleteCalendar($calendar['id']);
}
$this->calDav->deleteAllSharesForUser('principals/users/' . $uid);
- $addressBooksToDelete = $this->cardDav->getAddressBooksForUser('principals/users/' . $uid);
- foreach ($addressBooksToDelete as $addressBook) {
+ foreach ($this->addressBooksToDelete as $addressBook) {
$this->cardDav->deleteAddressBook($addressBook['id']);
}
}
diff --git a/apps/dav/tests/unit/DAV/HookManagerTest.php b/apps/dav/tests/unit/DAV/HookManagerTest.php
index cde24214dd1..4a60542a01d 100644
--- a/apps/dav/tests/unit/DAV/HookManagerTest.php
+++ b/apps/dav/tests/unit/DAV/HookManagerTest.php
@@ -168,7 +168,7 @@ class HookManagerTest extends TestCase {
$cal = $this->getMockBuilder(CalDavBackend::class)
->disableOriginalConstructor()
->getMock();
- $cal->expects($this->once())->method('getCalendarsForUser')->willReturn([
+ $cal->expects($this->once())->method('getUsersOwnCalendars')->willReturn([
['id' => 'personal']
]);
$cal->expects($this->once())->method('deleteCalendar');