From 940608f34ffb58fb0314bb7699a72e549d918fdd Mon Sep 17 00:00:00 2001 From: Didier 'OdyX' Raboud Date: Thu, 14 Mar 2019 14:00:27 +0100 Subject: [PATCH 1/2] MDL-65067 analytics: Strengthen format_weeks detection The public function get_section_dates($section, $startdate = false) is only defined in format_weeks, not in format_base. As other formats can (and format_topcoll has) declare a different get_section_dates public method, merely checking that it exists is not sufficient to guarantee that it can be called with just a section object. Check that the format either is, or is a subclass of format_weeks. --- .../classes/local/indicator/community_of_inquiry_activity.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/analytics/classes/local/indicator/community_of_inquiry_activity.php b/analytics/classes/local/indicator/community_of_inquiry_activity.php index 5deaeb6049e..555bb420e7c 100644 --- a/analytics/classes/local/indicator/community_of_inquiry_activity.php +++ b/analytics/classes/local/indicator/community_of_inquiry_activity.php @@ -836,7 +836,8 @@ abstract class community_of_inquiry_activity extends linear { // When the course is using format weeks we use the week's end date. $format = course_get_format($activity->get_modinfo()->get_course()); // We should change this in MDL-60702. - if (method_exists($format, 'get_section_dates')) { + if (get_class($format) == 'format_weeks' || is_subclass_of($format, 'format_weeks') + && method_exists($format, 'get_section_dates')) { $dates = $format->get_section_dates($section); // We need to consider the +2 hours added by get_section_dates. From 7ad4cd372897fc18736d1fbfb3df7837a53e4ff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Monlla=C3=B3?= Date: Fri, 17 May 2019 16:57:46 +0200 Subject: [PATCH 2/2] MDL-65067 tool_analytics: Limit update_end_date to format_weeks --- admin/tool/analytics/cli/guess_course_start_and_end.php | 3 ++- .../classes/local/indicator/community_of_inquiry_activity.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/admin/tool/analytics/cli/guess_course_start_and_end.php b/admin/tool/analytics/cli/guess_course_start_and_end.php index e0c8974b5d5..631ab97e1d6 100644 --- a/admin/tool/analytics/cli/guess_course_start_and_end.php +++ b/admin/tool/analytics/cli/guess_course_start_and_end.php @@ -173,7 +173,8 @@ function tool_analytics_calculate_course_dates($course, $options) { $formatoptions = $format->get_format_options(); // Change this for a course formats API level call in MDL-60702. - if (method_exists($format, 'update_end_date') && $formatoptions['automaticenddate']) { + if ((get_class($format) == 'format_weeks' || is_subclass_of($format, 'format_weeks')) && + method_exists($format, 'update_end_date') && $formatoptions['automaticenddate']) { // Special treatment for weeks-based formats with automatic end date. if ($options['update']) { diff --git a/analytics/classes/local/indicator/community_of_inquiry_activity.php b/analytics/classes/local/indicator/community_of_inquiry_activity.php index 555bb420e7c..d3bdcdbd871 100644 --- a/analytics/classes/local/indicator/community_of_inquiry_activity.php +++ b/analytics/classes/local/indicator/community_of_inquiry_activity.php @@ -836,7 +836,7 @@ abstract class community_of_inquiry_activity extends linear { // When the course is using format weeks we use the week's end date. $format = course_get_format($activity->get_modinfo()->get_course()); // We should change this in MDL-60702. - if (get_class($format) == 'format_weeks' || is_subclass_of($format, 'format_weeks') + if ((get_class($format) == 'format_weeks' || is_subclass_of($format, 'format_weeks')) && method_exists($format, 'get_section_dates')) { $dates = $format->get_section_dates($section);