-
Notifications
You must be signed in to change notification settings - Fork 349
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 description is coherent when only the main field is modified #1577
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -597,8 +597,9 @@ | |
} | ||
|
||
/** | ||
* This method looks at an old iCalendar object, a new iCalendar object and | ||
* starts sending scheduling messages based on the changes. | ||
* This method looks at an old iCalendar object, a new iCalendar object and: | ||
* - starts sending scheduling messages based on the changes. | ||
* - ensures the description fields are coherent | ||
* | ||
* A list of addresses needs to be specified, so the system knows who made | ||
* the update, because the behavior may be different based on if it's an | ||
|
@@ -612,6 +613,8 @@ | |
*/ | ||
protected function processICalendarChange($oldObject, VCalendar $newObject, array $addresses, array $ignore = [], &$modified = false) | ||
{ | ||
$this->ensureDescriptionConsistency($oldObject, $newObject, $modified); | ||
|
||
$broker = $this->createITipBroker(); | ||
$messages = $broker->parseEvent($newObject, $addresses, $oldObject); | ||
|
||
|
@@ -1003,4 +1006,41 @@ | |
{ | ||
return new Broker(); | ||
} | ||
|
||
/** | ||
* Ensure the alternate version of the description is removed if only the main one is changed | ||
*/ | ||
private function ensureDescriptionConsistency($oldObj, VCalendar $vCal, &$modified) { | ||
if (!$oldObj) { | ||
return; // No previous version to compare | ||
} | ||
|
||
$xAltDescPropName = "X-ALT-DESC"; | ||
|
||
// 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please add some unit test(s) that will exercise this new code block? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to run actual tests either directly from a Windows terminal or WSL, but I am getting I tried everything I thought. Nothing works. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Running
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know what version of I have:
I have an actual Ubuntu laptop, no Windows. The CI runs in Ubuntu Linux, no Windows anywhere. Maybe use VirtualBox and create a full Ubuntu VM? The "Failed to open stream" message is maybe coming from a line in ServerPropsTest.php
Try adding a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I created myself a Docker container to run the unit tests. Is this a normal execution result? (I still did not add mine, I will when I will be sure that this is the normal expections). I will add this Dockerfile with my PR so others could use it to test easily. The docker is setup using Ubuntu 24.04, with your version of PHP and composer. I have the same result with or without running BTW, the last part of the path (vendor/sabre/http/tests/www) does not exist when:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @phil-davis I pushed a commit including docker support for the unit tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is the normal unit test result. Some unit tests need exgtra environment set up, so they are skipped by default (the "S"). |
||
// Get descriptions | ||
$oldDescription = (string) $oldObj->VTODO->DESCRIPTION; | ||
$newDescription = (string) $vCal->VTODO->DESCRIPTION; | ||
$oldXAltDesc = (string) $oldObj->VTODO->{$xAltDescPropName}; | ||
$newXAltDesc = (string) $vCal->VTODO->{$xAltDescPropName}; | ||
|
||
// 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; | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add PHPdoc for the
$oldObj
and$modified
parameters.(They will be the same as for
processICalendarChange
)