Skip to content

Commit

Permalink
Merge branch 'MDL-66871-38-v2' of git://github.com/lameze/moodle into…
Browse files Browse the repository at this point in the history
… MOODLE_38_STABLE
  • Loading branch information
andrewnicols committed Jan 7, 2020
2 parents 701d27e + dafe4c5 commit ec63d3e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
5 changes: 3 additions & 2 deletions calendar/lib.php
Expand Up @@ -3016,7 +3016,7 @@ function calendar_get_icalendar($url) {
* Import events from an iCalendar object into a course calendar.
*
* @param iCalendar $ical The iCalendar object.
* @param int $courseid The course ID for the calendar.
* @param int $unused Deprecated
* @param int $subscriptionid The subscription ID.
* @return string A log of the import progress, including errors.
*/
Expand Down Expand Up @@ -3066,7 +3066,8 @@ function calendar_import_icalendar_events($ical, $unused = null, $subscriptionid
}
}

if (!empty($subscriptionid)) {
$existing = $DB->get_field('event_subscriptions', 'lastupdated', ['id' => $subscriptionid]);
if (!empty($existing)) {
$eventsuuids = $DB->get_records_menu('event', ['subscriptionid' => $subscriptionid], '', 'id, uuid');

$icaleventscount = count($icaluuids);
Expand Down
18 changes: 18 additions & 0 deletions calendar/tests/lib_test.php
Expand Up @@ -227,6 +227,24 @@ public function test_add_subscription() {
calendar_import_icalendar_events($ical, null, $sub->id);
$count = $DB->count_records('event', array('subscriptionid' => $sub->id));
$this->assertEquals($count, 1);

// Test for ICS file with repeated events.
$subscription = new stdClass();
$subscription->name = 'Repeated events';
$subscription->importfrom = CALENDAR_IMPORT_FROM_FILE;
$subscription->eventtype = 'site';
$id = calendar_add_subscription($subscription);
$calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/repeated_events.ics');
$ical = new iCalendar();
$ical->unserialize($calendar);
$this->assertEquals($ical->parser_errors, []);

$sub = calendar_get_subscription($id);
$output = calendar_import_icalendar_events($ical, null, $sub->id);
$this->assertStringNotContainsString('Events deleted: 17', $output);
$this->assertStringContainsString('Events imported: 1', $output);
$this->assertStringContainsString('Events skipped: 0', $output);
$this->assertStringContainsString('Events updated: 0', $output);
}

/**
Expand Down
34 changes: 34 additions & 0 deletions lib/tests/fixtures/repeated_events.ics
@@ -0,0 +1,34 @@
BEGIN:VCALENDAR
PRODID:QIS-LSF HIS eG
VERSION:2.0
BEGIN:VTIMEZONE
TZID:Europe/Berlin
X-LIC-LOCATION:Europe/Berlin
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
TZNAME:CEST
DTSTART:19700329T020000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
TZNAME:CET
DTSTART:19701025T030000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
END:STANDARD
END:VTIMEZONE
METHOD:PUBLISH
BEGIN:VEVENT
DTSTART;TZID=Europe/Berlin:20191015T160000
DTEND;TZID=Europe/Berlin:20191015T180000
RRULE:FREQ=WEEKLY;UNTIL=20200211T235900Z;INTERVAL=1;BYDAY=TU
LOCATION:O27 - 122
DTSTAMP:20191002T151421Z
UID:115808212972
DESCRIPTION:
SUMMARY:CS6307.000 - Introduction to Computer Science (for Non-Computer Scientists)
CATEGORIES:Vorlesung/ Übung
END:VEVENT
END:VCALENDAR

0 comments on commit ec63d3e

Please sign in to comment.