Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure no description changes are lost #41370

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions apps/dav/lib/CalDAV/Schedule/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@
if (!$this->pathOfCalendarObjectChange) {
$this->pathOfCalendarObjectChange = $request->getPath();
}

// Ensure description consistency
if (!$isNew) {
$this->ensureDescriptionConsistency($request, $vCal, $modified);
}

parent::calendarObjectChange($request, $response, $vCal, $calendarPath, $modified, $isNew);
}
Expand Down Expand Up @@ -632,4 +637,38 @@
'{DAV:}displayname' => $displayName,
]);
}

private function ensureDescriptionConsistency(RequestInterface $request, VCalendar $vCal, &$modified) {

Check notice

Code scanning / Psalm

MissingReturnType Note

Method OCA\DAV\CalDAV\Schedule\Plugin::ensureDescriptionConsistency does not have a return type, expecting void

Check notice

Code scanning / Psalm

MissingParamType Note

Parameter $modified has no provided type
$xAltDescPropName = "X-ALT-DESC";

// Obtain previous version
$node = $this->server->tree->getNodeForPath($request->getPath());
$oldObj = Reader::read($node->get());

Check failure on line 646 in apps/dav/lib/CalDAV/Schedule/Plugin.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedInterfaceMethod

apps/dav/lib/CalDAV/Schedule/Plugin.php:646:36: UndefinedInterfaceMethod: Method Sabre\DAV\INode::get does not exist (see https://psalm.dev/181)

Check failure

Code scanning / Psalm

UndefinedInterfaceMethod Error

Method Sabre\DAV\INode::get does not exist

// Get presence of description fields
$hasOldDescription = isset($oldObj->VTODO) && isset($oldObj->VTODO->DESCRIPTION);
$hasNewDescription = isset($vCal->VTODO) && isset($vCal->VTODO->DESCRIPTION);
$hasOldXAltDesc = isset($oldObj->VTODO) && isset($oldObj->VTODO->{$xAltDescPropName});
$hasNewXAltDesc = isset($vCal->VTODO) && isset($vCal->VTODO->{$xAltDescPropName});
$hasAllDesc = $hasOldDescription && $hasNewDescription && $hasOldXAltDesc && $hasNewXAltDesc;

// If all description fields are present, then verify consistency
if ($hasAllDesc) {
// Get descriptions
$oldDescription = (string) $oldObj->VTODO->DESCRIPTION;

Check failure on line 658 in apps/dav/lib/CalDAV/Schedule/Plugin.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedPropertyFetch

apps/dav/lib/CalDAV/Schedule/Plugin.php:658:37: UndefinedPropertyFetch: Instance property Sabre\VObject\Property::$DESCRIPTION is not defined (see https://psalm.dev/039)

Check failure

Code scanning / Psalm

UndefinedPropertyFetch Error

Instance property Sabre\VObject\Property::$DESCRIPTION is not defined

Check notice

Code scanning / Psalm

PossiblyNullPropertyFetch Note

Cannot get property on possibly null variable $oldObj->VTODO of type Sabre\VObject\Property|null
$newDescription = (string) $vCal->VTODO->DESCRIPTION;

Check failure on line 659 in apps/dav/lib/CalDAV/Schedule/Plugin.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedPropertyFetch

apps/dav/lib/CalDAV/Schedule/Plugin.php:659:37: UndefinedPropertyFetch: Instance property Sabre\VObject\Property::$DESCRIPTION is not defined (see https://psalm.dev/039)

Check failure

Code scanning / Psalm

UndefinedPropertyFetch Error

Instance property Sabre\VObject\Property::$DESCRIPTION is not defined

Check notice

Code scanning / Psalm

PossiblyNullPropertyFetch Note

Cannot get property on possibly null variable $vCal->VTODO of type Sabre\VObject\Property|null
$oldXAltDesc = (string) $oldObj->VTODO->{$xAltDescPropName};

Check failure on line 660 in apps/dav/lib/CalDAV/Schedule/Plugin.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedPropertyFetch

apps/dav/lib/CalDAV/Schedule/Plugin.php:660:34: UndefinedPropertyFetch: Instance property Sabre\VObject\Property::$X-ALT-DESC is not defined (see https://psalm.dev/039)

Check failure

Code scanning / Psalm

UndefinedPropertyFetch Error

Instance property Sabre\VObject\Property::$X-ALT-DESC is not defined
$newXAltDesc = (string) $vCal->VTODO->{$xAltDescPropName};

Check failure on line 661 in apps/dav/lib/CalDAV/Schedule/Plugin.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedPropertyFetch

apps/dav/lib/CalDAV/Schedule/Plugin.php:661:34: UndefinedPropertyFetch: Instance property Sabre\VObject\Property::$X-ALT-DESC is not defined (see https://psalm.dev/039)

Check failure

Code scanning / Psalm

UndefinedPropertyFetch Error

Instance property Sabre\VObject\Property::$X-ALT-DESC is not defined

// Compare descriptions
$isSameDescription = $oldDescription === $newDescription;
$isSameXAltDesc = $oldXAltDesc === $newXAltDesc;

// If the description changed, but not the alternate one, then delete the latest
if (!$isSameDescription && $isSameXAltDesc) {
unset($vCal->VTODO->{$xAltDescPropName});
$modified = true;
}
}
}
}