Browse Source

fix deletion of calendars

Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
tags/v11.0RC2
Thomas Citharel 7 years ago
parent
commit
da1543eef7
No account linked to committer's email address

+ 42
- 0
apps/dav/lib/CalDAV/CalDavBackend.php View File

@@ -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);

+ 12
- 5
apps/dav/lib/HookManager.php View File

@@ -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']);
}
}

+ 1
- 1
apps/dav/tests/unit/DAV/HookManagerTest.php View File

@@ -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');

Loading…
Cancel
Save