MDL-45128 include only education related events from real users in statistics processing

This commit is contained in:
Petr Skoda 2014-04-28 11:28:07 +08:00
parent 1e902feb66
commit 8dcb7ae62e
3 changed files with 23 additions and 7 deletions

View File

@ -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;

View File

@ -31,27 +31,27 @@ defined('MOODLE_INTERNAL') || die();
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;
}
}

View File

@ -367,6 +367,9 @@ class core_statslib_testcase extends advanced_testcase {
\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 @@ class core_statslib_testcase extends advanced_testcase {
\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);