Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix column/property type of the CalDAV deleted_at time stamp
The timestamp is an int, but we treated it as string. With this patch
the property map is enriched with types and settype casts the value if
necessary.

Signed-off-by: Christoph Wurst <[email protected]>
  • Loading branch information
ChristophWurst authored and backportbot[bot] committed Apr 1, 2022
commit 0d101135063982c74d4859024307f1775be4f498
92 changes: 45 additions & 47 deletions apps/dav/lib/CalDAV/CalDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,19 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
public const CLASSIFICATION_CONFIDENTIAL = 2;

/**
* List of CalDAV properties, and how they map to database field names
* List of CalDAV properties, and how they map to database field names and their type
* Add your own properties by simply adding on to this array.
*
* Note that only string-based properties are supported here.
*
* @var array
* @psalm-var array<string, string[]>
*/
public $propertyMap = [
'{DAV:}displayname' => 'displayname',
'{urn:ietf:params:xml:ns:caldav}calendar-description' => 'description',
'{urn:ietf:params:xml:ns:caldav}calendar-timezone' => 'timezone',
'{http://apple.com/ns/ical/}calendar-order' => 'calendarorder',
'{http://apple.com/ns/ical/}calendar-color' => 'calendarcolor',
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}deleted-at' => 'deleted_at',
'{DAV:}displayname' => ['displayname', 'string'],
'{urn:ietf:params:xml:ns:caldav}calendar-description' => ['description', 'string'],
'{urn:ietf:params:xml:ns:caldav}calendar-timezone' => ['timezone', 'string'],
'{http://apple.com/ns/ical/}calendar-order' => ['calendarorder', 'string'],
'{http://apple.com/ns/ical/}calendar-color' => ['calendarcolor', 'string'],
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}deleted-at' => ['deleted_at', 'int'],
];

/**
Expand Down Expand Up @@ -332,7 +331,7 @@ public function getDeletedCalendars(int $deletedBefore): array {
public function getCalendarsForUser($principalUri) {
$principalUriOriginal = $principalUri;
$principalUri = $this->convertPrincipal($principalUri, true);
$fields = array_values($this->propertyMap);
$fields = array_column($this->propertyMap, 0);
$fields[] = 'id';
$fields[] = 'uri';
$fields[] = 'synctoken';
Expand Down Expand Up @@ -373,10 +372,7 @@ public function getCalendarsForUser($principalUri) {
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint),
];

foreach ($this->propertyMap as $xmlName => $dbName) {
$calendar[$xmlName] = $row[$dbName];
}

$calendar = $this->rowToCalendar($row, $calendar);
$calendar = $this->addOwnerPrincipalToCalendar($calendar);
$calendar = $this->addResourceTypeToCalendar($row, $calendar);

Expand All @@ -392,7 +388,7 @@ public function getCalendarsForUser($principalUri) {

$principals[] = $principalUri;

$fields = array_values($this->propertyMap);
$fields = array_column($this->propertyMap, 0);
$fields[] = 'a.id';
$fields[] = 'a.uri';
$fields[] = 'a.synctoken';
Expand Down Expand Up @@ -450,10 +446,7 @@ public function getCalendarsForUser($principalUri) {
$readOnlyPropertyName => $readOnly,
];

foreach ($this->propertyMap as $xmlName => $dbName) {
$calendar[$xmlName] = $row[$dbName];
}

$calendar = $this->rowToCalendar($row, $calendar);
$calendar = $this->addOwnerPrincipalToCalendar($calendar);
$calendar = $this->addResourceTypeToCalendar($row, $calendar);

Expand All @@ -470,7 +463,7 @@ public function getCalendarsForUser($principalUri) {
*/
public function getUsersOwnCalendars($principalUri) {
$principalUri = $this->convertPrincipal($principalUri, true);
$fields = array_values($this->propertyMap);
$fields = array_column($this->propertyMap, 0);
$fields[] = 'id';
$fields[] = 'uri';
$fields[] = 'synctoken';
Expand Down Expand Up @@ -499,10 +492,8 @@ public function getUsersOwnCalendars($principalUri) {
'{' . 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];
}

$calendar = $this->rowToCalendar($row, $calendar);
$calendar = $this->addOwnerPrincipalToCalendar($calendar);
$calendar = $this->addResourceTypeToCalendar($row, $calendar);

Expand Down Expand Up @@ -537,7 +528,7 @@ private function getUserDisplayName($uid) {
* @return array
*/
public function getPublicCalendars() {
$fields = array_values($this->propertyMap);
$fields = array_column($this->propertyMap, 0);
$fields[] = 'a.id';
$fields[] = 'a.uri';
$fields[] = 'a.synctoken';
Expand Down Expand Up @@ -576,10 +567,7 @@ public function getPublicCalendars() {
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC,
];

foreach ($this->propertyMap as $xmlName => $dbName) {
$calendar[$xmlName] = $row[$dbName];
}

$calendar = $this->rowToCalendar($row, $calendar);
$calendar = $this->addOwnerPrincipalToCalendar($calendar);
$calendar = $this->addResourceTypeToCalendar($row, $calendar);

Expand All @@ -598,7 +586,7 @@ public function getPublicCalendars() {
* @throws NotFound
*/
public function getPublicCalendar($uri) {
$fields = array_values($this->propertyMap);
$fields = array_column($this->propertyMap, 0);
$fields[] = 'a.id';
$fields[] = 'a.uri';
$fields[] = 'a.synctoken';
Expand Down Expand Up @@ -644,10 +632,7 @@ public function getPublicCalendar($uri) {
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC,
];

foreach ($this->propertyMap as $xmlName => $dbName) {
$calendar[$xmlName] = $row[$dbName];
}

$calendar = $this->rowToCalendar($row, $calendar);
$calendar = $this->addOwnerPrincipalToCalendar($calendar);
$calendar = $this->addResourceTypeToCalendar($row, $calendar);

Expand All @@ -660,7 +645,7 @@ public function getPublicCalendar($uri) {
* @return array|null
*/
public function getCalendarByUri($principal, $uri) {
$fields = array_values($this->propertyMap);
$fields = array_column($this->propertyMap, 0);
$fields[] = 'id';
$fields[] = 'uri';
$fields[] = 'synctoken';
Expand Down Expand Up @@ -698,10 +683,7 @@ public function getCalendarByUri($principal, $uri) {
'{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'),
];

foreach ($this->propertyMap as $xmlName => $dbName) {
$calendar[$xmlName] = $row[$dbName];
}

$calendar = $this->rowToCalendar($row, $calendar);
$calendar = $this->addOwnerPrincipalToCalendar($calendar);
$calendar = $this->addResourceTypeToCalendar($row, $calendar);

Expand All @@ -713,7 +695,7 @@ public function getCalendarByUri($principal, $uri) {
* @return array|null
*/
public function getCalendarById($calendarId) {
$fields = array_values($this->propertyMap);
$fields = array_column($this->propertyMap, 0);
$fields[] = 'id';
$fields[] = 'uri';
$fields[] = 'synctoken';
Expand Down Expand Up @@ -750,10 +732,7 @@ public function getCalendarById($calendarId) {
'{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'),
];

foreach ($this->propertyMap as $xmlName => $dbName) {
$calendar[$xmlName] = $row[$dbName];
}

$calendar = $this->rowToCalendar($row, $calendar);
$calendar = $this->addOwnerPrincipalToCalendar($calendar);
$calendar = $this->addResourceTypeToCalendar($row, $calendar);

Expand Down Expand Up @@ -844,7 +823,7 @@ public function createCalendar($principalUri, $calendarUri, array $properties) {
$values['transparent'] = (int) ($properties[$transp]->getValue() === 'transparent');
}

foreach ($this->propertyMap as $xmlName => $dbName) {
foreach ($this->propertyMap as $xmlName => [$dbName, $type]) {
if (isset($properties[$xmlName])) {
$values[$dbName] = $properties[$xmlName];
}
Expand Down Expand Up @@ -893,7 +872,7 @@ public function updateCalendar($calendarId, PropPatch $propPatch) {
$newValues[$fieldName] = (int) ($propertyValue->getValue() === 'transparent');
break;
default:
$fieldName = $this->propertyMap[$propertyName];
$fieldName = $this->propertyMap[$propertyName][0];
$newValues[$fieldName] = $propertyValue;
break;
}
Expand Down Expand Up @@ -1090,7 +1069,7 @@ public function getDeletedCalendarObjects(int $deletedBefore): array {
'size' => (int) $row['size'],
'component' => strtolower($row['componenttype']),
'classification' => (int) $row['classification'],
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}deleted-at' => $row['deleted_at'],
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}deleted-at' => $row['deleted_at'] === null ? $row['deleted_at'] : (int) $row['deleted_at'],
];
}
$stmt->closeCursor();
Expand Down Expand Up @@ -1129,7 +1108,7 @@ public function getDeletedCalendarObjectsByPrincipal(string $principalUri): arra
'size' => (int)$row['size'],
'component' => strtolower($row['componenttype']),
'classification' => (int)$row['classification'],
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}deleted-at' => $row['deleted_at'],
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}deleted-at' => $row['deleted_at'] === null ? $row['deleted_at'] : (int) $row['deleted_at'],
];
}
$stmt->closeCursor();
Expand Down Expand Up @@ -3161,4 +3140,23 @@ private function addResourceTypeToCalendar(array $row, array $calendar): array {
}
return $calendar;
}

/**
* Amend the calendar info with database row data
*
* @param array $row
* @param array $calendar
*
* @return array
*/
private function rowToCalendar($row, array $calendar): array {
foreach ($this->propertyMap as $xmlName => [$dbName, $type]) {
$value = $row[$dbName];
if ($value !== null) {
settype($value, $type);
}
$calendar[$xmlName] = $value;
}
return $calendar;
}
}