diff --git a/lib/statslib.php b/lib/statslib.php index d54874754a9a9..e88f9e959859e 100644 --- a/lib/statslib.php +++ b/lib/statslib.php @@ -1752,7 +1752,13 @@ function stats_temp_table_fill($timestart, $timeend) { // First decide from where we want the data. - $params = array('timestart' => $timestart, 'timeend' => $timeend, 'loginevent' => '\core\event\user_loggedin'); + $params = array('timestart' => $timestart, + 'timeend' => $timeend, + 'participating' => \core\event\base::LEVEL_PARTICIPATING, + 'teaching' => \core\event\base::LEVEL_TEACHING, + 'loginevent1' => '\core\event\user_loggedin', + 'loginevent2' => '\core\event\user_loggedin', + ); $filled = false; $manager = get_log_manager(); @@ -1773,6 +1779,8 @@ function stats_temp_table_fill($timestart, $timeend) { } // Let's fake the old records using new log data. + // We want only data relevant to educational process + // done by real users. $sql = "INSERT INTO {temp_log1} (userid, course, action) @@ -1783,12 +1791,14 @@ function stats_temp_table_fill($timestart, $timeend) { ELSE courseid END, CASE - WHEN eventname = :loginevent THEN 'login' + WHEN eventname = :loginevent1 THEN 'login' WHEN crud = 'r' THEN 'view' ELSE 'update' END FROM {{$logtable}} - WHERE timecreated >= :timestart AND timecreated < :timeend"; + WHERE timecreated >= :timestart AND timecreated < :timeend + AND (origin = 'web' OR origin = 'ws') + AND (edulevel = :participating OR edulevel = :teaching OR eventname = :loginevent2)"; $DB->execute($sql, $params); $filled = true; diff --git a/lib/tests/fixtures/stats_events.php b/lib/tests/fixtures/stats_events.php index c9a86599a3f42..ed52ae0afdc48 100644 --- a/lib/tests/fixtures/stats_events.php +++ b/lib/tests/fixtures/stats_events.php @@ -31,27 +31,27 @@ class create_executed extends \core\event\base { protected function init() { $this->data['crud'] = 'c'; - $this->data['edulevel'] = self::LEVEL_OTHER; + $this->data['edulevel'] = self::LEVEL_PARTICIPATING; } } class read_executed extends \core\event\base { protected function init() { $this->data['crud'] = 'r'; - $this->data['edulevel'] = self::LEVEL_OTHER; + $this->data['edulevel'] = self::LEVEL_PARTICIPATING; } } class update_executed extends \core\event\base { protected function init() { $this->data['crud'] = 'u'; - $this->data['edulevel'] = self::LEVEL_OTHER; + $this->data['edulevel'] = self::LEVEL_PARTICIPATING; } } class delete_executed extends \core\event\base { protected function init() { $this->data['crud'] = 'd'; - $this->data['edulevel'] = self::LEVEL_OTHER; + $this->data['edulevel'] = self::LEVEL_PARTICIPATING; } } diff --git a/lib/tests/statslib_test.php b/lib/tests/statslib_test.php index 0317aed603986..d88824e8fe0dd 100644 --- a/lib/tests/statslib_test.php +++ b/lib/tests/statslib_test.php @@ -367,6 +367,9 @@ public function test_statslib_get_start_from() { \core_tests\event\update_executed::create(array('context' => context_system::instance()))->trigger(); \core_tests\event\delete_executed::create(array('context' => context_system::instance()))->trigger(); + // Fake the origin of events. + $DB->set_field('logstore_standard_log', 'origin', 'web', array()); + $logs = $DB->get_records('logstore_standard_log'); $this->assertCount(4, $logs); @@ -584,6 +587,9 @@ public function test_statslib_temp_table_fill() { \core_tests\event\delete_executed::create(array('context' => context_system::instance()))->trigger(); \core_tests\event\delete_executed::create(array('context' => context_system::instance()))->trigger(); + // Fake the origin of events. + $DB->set_field('logstore_standard_log', 'origin', 'web', array()); + $this->assertEquals(7, $DB->count_records('logstore_standard_log')); stats_temp_table_fill(9, 11);