From d00715e410e672ab536eeaf3a3bdb8f8fadd417b Mon Sep 17 00:00:00 2001 From: Matt Porritt Date: Tue, 25 Jun 2019 20:17:53 +0800 Subject: [PATCH 1/4] MDL-56835 report_participation: release session lock --- report/participation/index.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/report/participation/index.php b/report/participation/index.php index ef66eef7fd7..9df2fa23399 100644 --- a/report/participation/index.php +++ b/report/participation/index.php @@ -31,6 +31,9 @@ require_once($CFG->dirroot.'/report/participation/locallib.php'); define('DEFAULT_PAGE_SIZE', 20); define('SHOW_ALL_PAGE_SIZE', 5000); +// Release session lock. +\core\session\manager::write_close(); + $id = required_param('id', PARAM_INT); // course id. $roleid = optional_param('roleid', 0, PARAM_INT); // which role to show $instanceid = optional_param('instanceid', 0, PARAM_INT); // instance we're looking at. From 5a9e1bc18ed5e6f5637a5a6d03c9c02b985b18d9 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 25 Jun 2019 20:15:20 +0800 Subject: [PATCH 2/4] MDL-56835 report_participation: use course timecreated as minlog --- report/participation/index.php | 36 ++++------------------------------ 1 file changed, 4 insertions(+), 32 deletions(-) diff --git a/report/participation/index.php b/report/participation/index.php index 9df2fa23399..3bb24c4236f 100644 --- a/report/participation/index.php +++ b/report/participation/index.php @@ -83,7 +83,8 @@ $PAGE->set_title(format_string($course->shortname, true, array('context' => $con $PAGE->set_heading(format_string($course->fullname, true, array('context' => $context))); echo $OUTPUT->header(); -$uselegacyreader = false; // Use legacy reader with sql_internal_table_reader to aggregate records. +// Logs will not have been recorded before the course timecreated time. +$minlog = $course->timecreated; $onlyuselegacyreader = false; // Use only legacy log table to aggregate records. $logtable = report_participation_get_log_table_name(); // Log table to use for fetaching records. @@ -104,31 +105,6 @@ if (!$onlyuselegacyreader && empty($logtable)) { $modinfo = get_fast_modinfo($course); -$minloginternalreader = 0; // Time of first record in sql_internal_table_reader. - -if ($onlyuselegacyreader) { - // If no sql_inrenal_reader enabled then get min. time from log table. - $minlog = $DB->get_field_sql('SELECT min(time) FROM {log} WHERE course = ?', array($course->id)); -} else { - $uselegacyreader = true; - $minlog = $DB->get_field_sql('SELECT min(time) FROM {log} WHERE course = ?', array($course->id)); - - // If legacy reader is not logging then get data from new log table. - // Get minimum log time for this course from preferred log reader. - $minloginternalreader = $DB->get_field_sql('SELECT min(timecreated) FROM {' . $logtable . '} - WHERE courseid = ?', array($course->id)); - // If new log store has oldest data then don't use old log table. - if (empty($minlog) || ($minloginternalreader <= $minlog)) { - $uselegacyreader = false; - $minlog = $minloginternalreader; - } - - // If timefrom is greater then first record in sql_internal_table_reader then get record from sql_internal_table_reader only. - if (!empty($timefrom) && ($minloginternalreader < $timefrom)) { - $uselegacyreader = false; - } -} - // Print first controls. report_participation_print_filter_form($course, $timefrom, $minlog, $action, $roleid, $instanceid); @@ -157,6 +133,7 @@ $groupmode = groups_get_course_groupmode($course); $currentgroup = $SESSION->activegroup[$course->id][$groupmode][$course->defaultgroupingid]; if (!empty($instanceid) && !empty($roleid)) { + $uselegacyreader = $DB->record_exists('log', ['course' => $course->id]); // Trigger a report viewed event. $event = \report_participation\event\report_viewed::create(array('context' => $context, @@ -253,11 +230,6 @@ if (!empty($instanceid) && !empty($roleid)) { $users = array(); // If using legacy log then get users from old table. if ($uselegacyreader || $onlyuselegacyreader) { - $limittime = ''; - if ($uselegacyreader && !empty($minloginternalreader)) { - $limittime = ' AND time < :tilltime '; - $params['tilltime'] = $minloginternalreader; - } $sql = "SELECT ra.userid, $usernamefields, u.idnumber, l.actioncount AS count FROM (SELECT DISTINCT userid FROM {role_assignments} WHERE contextid $relatedctxsql AND roleid = :roleid ) ra JOIN {user} u ON u.id = ra.userid @@ -266,7 +238,7 @@ if (!empty($instanceid) && !empty($roleid)) { SELECT userid, COUNT(action) AS actioncount FROM {log} WHERE cmid = :instanceid - AND time > :timefrom " . $limittime . $actionsql . + AND time > :timefrom " . $actionsql . " GROUP BY userid) l ON (l.userid = ra.userid)"; if ($twhere) { $sql .= ' WHERE '.$twhere; // Initial bar. From 260499815057ecea562204f714ba451cd7e27669 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 26 Jun 2019 14:06:12 +0800 Subject: [PATCH 3/4] MDL-56835 report_participation: initialise action variables --- report/participation/locallib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/report/participation/locallib.php b/report/participation/locallib.php index 77b48a22bda..8ab59b47a9b 100644 --- a/report/participation/locallib.php +++ b/report/participation/locallib.php @@ -98,8 +98,8 @@ function report_participation_get_time_options($minlog) { function report_participation_get_action_sql($action, $modname) { global $CFG, $DB; - $crudsql = ''; - $crudparams = array(); + $actionsql = ''; + $actionparams = array(); $viewnames = array(); $postnames = array(); From 11362b4aaf1e63aaa22fa9183f0a91ae16bb1e3b Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 9 Jul 2019 09:14:15 +0800 Subject: [PATCH 4/4] MDL-56835 report_participation: remove unreachable if condition --- report/participation/index.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/report/participation/index.php b/report/participation/index.php index 3bb24c4236f..9708951c6cf 100644 --- a/report/participation/index.php +++ b/report/participation/index.php @@ -94,15 +94,6 @@ if (empty($logtable)) { $onlyuselegacyreader = true; } -// If no legacy and no logtable then don't proceed. -if (!$onlyuselegacyreader && empty($logtable)) { - echo $OUTPUT->box_start('generalbox', 'notice'); - echo get_string('nologreaderenabled', 'report_participation'); - echo $OUTPUT->box_end(); - echo $OUTPUT->footer(); - die(); -} - $modinfo = get_fast_modinfo($course); // Print first controls.