From 0287928c4bbe2b4011487b65afb0b7db7a9c7a88 Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Mon, 16 Dec 2019 08:36:26 +0800 Subject: [PATCH 1/3] MDL-66871 calendar: fix ics importing logic --- calendar/lib.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/calendar/lib.php b/calendar/lib.php index 43e9de89abc..381580eec01 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -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); From 550c4e1c424ee205e43a1e6419f56740ffa49e5e Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Mon, 16 Dec 2019 08:36:56 +0800 Subject: [PATCH 2/3] MDL-66871 calendar: add unit test coverage for ics importing --- calendar/tests/lib_test.php | 18 ++++++++++++++ lib/tests/fixtures/repeated_events.ics | 34 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 lib/tests/fixtures/repeated_events.ics diff --git a/calendar/tests/lib_test.php b/calendar/tests/lib_test.php index 96af6075ba8..94a3cb4c9f4 100644 --- a/calendar/tests/lib_test.php +++ b/calendar/tests/lib_test.php @@ -227,6 +227,24 @@ class core_calendar_lib_testcase extends advanced_testcase { 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); } /** diff --git a/lib/tests/fixtures/repeated_events.ics b/lib/tests/fixtures/repeated_events.ics new file mode 100644 index 00000000000..7157007a5a2 --- /dev/null +++ b/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 From dafe4c5a78f7b9dd494acfce90db26291bc9b7fa Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Mon, 16 Dec 2019 08:39:04 +0800 Subject: [PATCH 3/3] MDL-66871 calendar: fix deprecated parameter in the phpDoc --- calendar/lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/calendar/lib.php b/calendar/lib.php index 381580eec01..f378c102b0a 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -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. */