Skip to content

Commit

Permalink
Reordering of vevent should not be a significant change (sabre-io#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
floerke authored and phil-davis committed Nov 14, 2021
1 parent 5c7ab23 commit f0827b5
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 5 deletions.
18 changes: 14 additions & 4 deletions lib/ITip/Broker.php
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,10 @@ protected function parseEventInfo(VCalendar $calendar = null)
$instances = [];
$exdate = [];

$significantChangeEventProperties = [];

foreach ($calendar->VEVENT as $vevent) {
$eventSignificantChangeHash = '';
$rrule = [];

if (is_null($uid)) {
Expand Down Expand Up @@ -934,19 +937,26 @@ protected function parseEventInfo(VCalendar $calendar = null)
if (isset($vevent->$prop)) {
$propertyValues = $vevent->select($prop);

$significantChangeHash .= $prop.':';
$eventSignificantChangeHash .= $prop.':';

if ('EXDATE' === $prop) {
$significantChangeHash .= implode(',', $exdate).';';
$eventSignificantChangeHash .= implode(',', $exdate).';';
} elseif ('RRULE' === $prop) {
$significantChangeHash .= implode(',', $rrule).';';
$eventSignificantChangeHash .= implode(',', $rrule).';';
} else {
foreach ($propertyValues as $val) {
$significantChangeHash .= $val->getValue().';';
$eventSignificantChangeHash .= $val->getValue().';';
}
}
}
}
$significantChangeEventProperties[] = $eventSignificantChangeHash;
}

asort($significantChangeEventProperties);

foreach ($significantChangeEventProperties as $eventSignificantChangeHash) {
$significantChangeHash .= $eventSignificantChangeHash;
}
$significantChangeHash = md5($significantChangeHash);

Expand Down
68 changes: 67 additions & 1 deletion tests/VObject/ITip/BrokerSignificantChangesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function testSignificantChangesRRuleOrderNoChange()

/**
* Check significant changes detection (no change).
* Reordering of the attendees should not be a signitifcant change (#540)
* Reordering of the attendees should not be a significant change (#540)
* https://github.com/sabre-io/vobject/issues/540.
*/
public function testSignificantChangesAttendeesOrderNoChange()
Expand Down Expand Up @@ -145,6 +145,72 @@ public function testSignificantChangesAttendeesOrderNoChange()
$expected[] = ['significantChange' => false];
$expected[] = ['significantChange' => false];

$this->parse($old, $new, $expected, 'mailto:martin@fruux.com');
}

/**
* Check significant changes detection (no change).
* Reordering of vevent in a recurring event with exceptions should
* not be a significant change
* https://github.com/sabre-io/vobject/issues/542.
*/
public function testSignificantChangesVeventOrderNoChange()
{
$vevent1 = <<<ICS
BEGIN:VEVENT
UID:20140813T153116Z-12176-1000-1065-6@johnny-lubuntu
DTSTAMP:20140813T142829Z
DTSTART;TZID=America/Toronto:20140815T110000
SEQUENCE:2
SUMMARY:Evo makes a Meeting
LOCATION:fruux HQ
CLASS:PUBLIC
RRULE:FREQ=WEEKLY;BYDAY=MO
ORGANIZER:MAILTO:martin@fruux.com
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=
TRUE;LANGUAGE=en:MAILTO:dominik@fruux.com
CREATED:20140813T153211Z
LAST-MODIFIED:20140813T155353Z
END:VEVENT
ICS;
// This event is slightly different. DTSTAMP is in 2021
$vevent2 = <<<ICS
BEGIN:VEVENT
UID:20140813T153116Z-12176-1000-1065-6@johnny-lubuntu
DTSTAMP:20210813T142829Z
DTSTART;TZID=America/Toronto:20140815T110000
SEQUENCE:2
SUMMARY:Evo makes a Meeting
LOCATION:fruux HQ
CLASS:PUBLIC
RRULE:FREQ=WEEKLY;BYDAY=MO
ORGANIZER:MAILTO:martin@fruux.com
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=
TRUE;LANGUAGE=en:MAILTO:dominik@fruux.com
CREATED:20140813T153211Z
LAST-MODIFIED:20140813T155353Z
END:VEVENT
ICS;

$head = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
PRODID:-//Ximian//NONSGML Evolution Calendar//EN
ICS;

$old = $head;
$old .= "\n".$vevent1;
$old .= "\n".$vevent2;
$old .= "\nEND:VCALENDAR";

$new = $head;
$new .= "\n".$vevent1;
$new .= "\n".$vevent2;
$new .= "\nEND:VCALENDAR";

$expected = [['significantChange' => false]];

$this->parse($old, $new, $expected, 'mailto:martin@fruux.com');
}
}

0 comments on commit f0827b5

Please sign in to comment.