Skip to content

Commit

Permalink
Fix CalDAV subscriptions calendarorder column/prop type
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
  • Loading branch information
ChristophWurst authored and backportbot[bot] committed Apr 1, 2022
1 parent 5527170 commit dd36e9c
Showing 1 changed file with 33 additions and 25 deletions.
58 changes: 33 additions & 25 deletions apps/dav/lib/CalDAV/CalDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
use Sabre\VObject\Recur\EventIterator;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use function array_column;
use function array_merge;
use function array_values;
use function explode;
Expand Down Expand Up @@ -163,13 +164,13 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
* @var array
*/
public $subscriptionPropertyMap = [
'{DAV:}displayname' => 'displayname',
'{http://apple.com/ns/ical/}refreshrate' => 'refreshrate',
'{http://apple.com/ns/ical/}calendar-order' => 'calendarorder',
'{http://apple.com/ns/ical/}calendar-color' => 'calendarcolor',
'{http://calendarserver.org/ns/}subscribed-strip-todos' => 'striptodos',
'{http://calendarserver.org/ns/}subscribed-strip-alarms' => 'stripalarms',
'{http://calendarserver.org/ns/}subscribed-strip-attachments' => 'stripattachments',
'{DAV:}displayname' => ['displayname', 'string'],
'{http://apple.com/ns/ical/}refreshrate' => ['refreshrate', 'string'],
'{http://apple.com/ns/ical/}calendar-order' => ['calendarorder', 'int'],
'{http://apple.com/ns/ical/}calendar-color' => ['calendarcolor', 'string'],
'{http://calendarserver.org/ns/}subscribed-strip-todos' => ['striptodos', 'bool'],
'{http://calendarserver.org/ns/}subscribed-strip-alarms' => ['stripalarms', 'string'],
'{http://calendarserver.org/ns/}subscribed-strip-attachments' => ['stripattachments', 'string'],
];

/** @var array properties to index */
Expand Down Expand Up @@ -747,7 +748,7 @@ public function getCalendarById($calendarId) {
* @param $subscriptionId
*/
public function getSubscriptionById($subscriptionId) {
$fields = array_values($this->subscriptionPropertyMap);
$fields = array_column($this->subscriptionPropertyMap, 0);
$fields[] = 'id';
$fields[] = 'uri';
$fields[] = 'source';
Expand Down Expand Up @@ -779,13 +780,7 @@ public function getSubscriptionById($subscriptionId) {
'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
];

foreach ($this->subscriptionPropertyMap as $xmlName => $dbName) {
if (!is_null($row[$dbName])) {
$subscription[$xmlName] = $row[$dbName];
}
}

return $subscription;
return $this->rowToSubscription($row, $subscription);
}

/**
Expand Down Expand Up @@ -2366,7 +2361,7 @@ public function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limi
* @return array
*/
public function getSubscriptionsForUser($principalUri) {
$fields = array_values($this->subscriptionPropertyMap);
$fields = array_column($this->subscriptionPropertyMap, 0);
$fields[] = 'id';
$fields[] = 'uri';
$fields[] = 'source';
Expand Down Expand Up @@ -2394,13 +2389,7 @@ public function getSubscriptionsForUser($principalUri) {
'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
];

foreach ($this->subscriptionPropertyMap as $xmlName => $dbName) {
if (!is_null($row[$dbName])) {
$subscription[$xmlName] = $row[$dbName];
}
}

$subscriptions[] = $subscription;
$subscriptions[] = $this->rowToSubscription($row, $subscription);
}

return $subscriptions;
Expand Down Expand Up @@ -2431,7 +2420,7 @@ public function createSubscription($principalUri, $uri, array $properties) {

$propertiesBoolean = ['striptodos', 'stripalarms', 'stripattachments'];

foreach ($this->subscriptionPropertyMap as $xmlName => $dbName) {
foreach ($this->subscriptionPropertyMap as $xmlName => [$dbName, $type]) {
if (array_key_exists($xmlName, $properties)) {
$values[$dbName] = $properties[$xmlName];
if (in_array($dbName, $propertiesBoolean)) {
Expand Down Expand Up @@ -2493,7 +2482,7 @@ public function updateSubscription($subscriptionId, PropPatch $propPatch) {
if ($propertyName === '{http://calendarserver.org/ns/}source') {
$newValues['source'] = $propertyValue->getHref();
} else {
$fieldName = $this->subscriptionPropertyMap[$propertyName];
$fieldName = $this->subscriptionPropertyMap[$propertyName][0];
$newValues[$fieldName] = $propertyValue;
}
}
Expand Down Expand Up @@ -3196,4 +3185,23 @@ private function rowToCalendar($row, array $calendar): array {
}
return $calendar;
}

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

0 comments on commit dd36e9c

Please sign in to comment.