fix deletion of calendars

Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
This commit is contained in:
Thomas Citharel 2016-09-25 13:35:53 +02:00 committed by Lukas Reschke
parent 5215833fe4
commit da1543eef7
No known key found for this signature in database
GPG key ID: B9F6980CF6E759B1
3 changed files with 55 additions and 6 deletions

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

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

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