Skip to content

Commit

Permalink
MDL-45128 include only education related events from real users in st…
Browse files Browse the repository at this point in the history
…atistics processing
  • Loading branch information
skodak committed Apr 28, 2014
1 parent 1e902fe commit 8dcb7ae
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
16 changes: 13 additions & 3 deletions lib/statslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions lib/tests/fixtures/stats_events.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
6 changes: 6 additions & 0 deletions lib/tests/statslib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8dcb7ae

Please sign in to comment.