Skip to content

Commit

Permalink
MDL-73948 report_loglive: Fix missing records
Browse files Browse the repository at this point in the history
  • Loading branch information
golenkovm committed Mar 31, 2022
1 parent 3ab09c7 commit f994a89
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 23 deletions.
15 changes: 15 additions & 0 deletions report/loglive/classes/table_log.php
Expand Up @@ -404,4 +404,19 @@ public function update_users_and_courses_used() {
}
}
}

/**
* Returns the latest timestamp of the records in the table.
*
* @return int
*/
public function get_until(): int {
$until = $this->filterparams->date;
if (!empty($this->rawdata)) {
foreach ($this->rawdata as $row) {
$until = max($row->timecreated, $until);
}
}
return $until;
}
}
7 changes: 3 additions & 4 deletions report/loglive/classes/table_log_ajax.php
Expand Up @@ -47,15 +47,14 @@ class report_loglive_table_log_ajax extends report_loglive_table_log {
public function out($pagesize, $useinitialsbar, $downloadhelpbutton = '') {
$this->query_db($pagesize, false);
$html = '';
$until = time();
if ($this->rawdata && $this->columns) {
foreach ($this->rawdata as $row) {
$formatedrow = $this->format_row($row, "newrow time$until");
$formatedrow = $this->format_row($row);
$formatedrow = $this->get_row_from_keyed($formatedrow);
$html .= $this->get_row_html($formatedrow, "newrow time$until");
$html .= $this->get_row_html($formatedrow, 'newrow');
}
}
$result = array('logs' => $html, 'until' => $until);
$result = array('logs' => $html, 'until' => $this->get_until());
return json_encode($result);
}

Expand Down
19 changes: 10 additions & 9 deletions report/loglive/index.php
Expand Up @@ -67,15 +67,6 @@
$refresh = $renderable->get_refresh_rate();
$logreader = $renderable->selectedlogreader;

// Include and trigger ajax requests.
if ($page == 0 && !empty($logreader)) {
// Tell Js to fetch new logs only, by passing time().
$jsparams = array('since' => time() , 'courseid' => $id, 'page' => $page, 'logreader' => $logreader,
'interval' => $refresh, 'perpage' => $renderable->perpage);
$PAGE->requires->strings_for_js(array('pause', 'resume'), 'report_loglive');
$PAGE->requires->yui_module('moodle-report_loglive-fetchlogs', 'Y.M.report_loglive.FetchLogs.init', array($jsparams));
}

$strlivelogs = get_string('livelogs', 'report_loglive');
$strupdatesevery = get_string('updatesevery', 'moodle', $refresh);

Expand All @@ -95,6 +86,16 @@
echo $output->toggle_liveupdate_button($renderable);
echo $output->render($renderable);

// Include and trigger ajax requests.
if ($page == 0 && !empty($logreader)) {
// Tell Js to fetch new logs only, by passing the latest timestamp of records in the table.
$until = $renderable->get_table()->get_until();
$jsparams = array('since' => $until , 'courseid' => $id, 'page' => $page, 'logreader' => $logreader,
'interval' => $refresh, 'perpage' => $renderable->perpage);
$PAGE->requires->strings_for_js(array('pause', 'resume'), 'report_loglive');
$PAGE->requires->yui_module('moodle-report_loglive-fetchlogs', 'Y.M.report_loglive.FetchLogs.init', array($jsparams));
}

// Trigger a logs viewed event.
$event = \report_loglive\event\report_viewed::create(array('context' => $context));
$event->trigger();
Expand Down
38 changes: 38 additions & 0 deletions report/loglive/tests/lib_test.php
Expand Up @@ -55,4 +55,42 @@ public function test_report_participation_supports_logstore() {
$this->assertContains($expectedstore, $stores);
}
}

/**
* Test the latest record timestamp of the report data set.
*
* @covers ::get_until()
*/
public function test_report_get_until() {
global $DB;
$this->resetAfterTest();
$this->preventResetByRollback();
$now = time();

// Configure log store.
set_config('enabled_stores', 'logstore_standard', 'tool_log');
$manager = get_log_manager();
$stores = $manager->get_readers();
$store = $stores['logstore_standard'];
$DB->delete_records('logstore_standard_log');

// Build the report.
$url = new \moodle_url("/report/loglive/index.php");
$renderable = new \report_loglive_renderable('logstore_standard', 0, $url);
$table = $renderable->get_table();
$table->query_db(100);
$until = $table->get_until();

// There is no record in the log table at this stage so until date is supposed to be equal to CUTOFF date.
$this->assertLessThanOrEqual(time() - \report_loglive_renderable::CUTOFF, $until);

// Create a user, store the event and re-build the report.
$this->getDataGenerator()->create_user();
$store->flush();
$table->query_db(100);
$until = $table->get_until();

// Assert that until date reflects user creation event date (now).
$this->assertGreaterThanOrEqual($now, $until);
}
}
Expand Up @@ -145,7 +145,7 @@ Y.extend(FetchLogs, Y.Base, {
// Let us chop off some data from end of table to prevent really long pages.
var oldChildren = tbody.get('children').slice(this.get('perpage'));
oldChildren.remove();
Y.later(5000, this, 'removeHighlight', responseobject.until); // Remove highlighting from new rows.
Y.later(5000, this, 'removeHighlight'); // Remove highlighting from new rows.
}
},

Expand All @@ -154,8 +154,8 @@ Y.extend(FetchLogs, Y.Base, {
*
* @method removeHighlight
*/
removeHighlight: function(timeStamp) {
Y.all('.time' + timeStamp).removeClass(CSS.NEWROW);
removeHighlight: function() {
Y.all(SELECTORS.NEWROW).removeClass(CSS.NEWROW);
},

/**
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -145,7 +145,7 @@ Y.extend(FetchLogs, Y.Base, {
// Let us chop off some data from end of table to prevent really long pages.
var oldChildren = tbody.get('children').slice(this.get('perpage'));
oldChildren.remove();
Y.later(5000, this, 'removeHighlight', responseobject.until); // Remove highlighting from new rows.
Y.later(5000, this, 'removeHighlight'); // Remove highlighting from new rows.
}
},

Expand All @@ -154,8 +154,8 @@ Y.extend(FetchLogs, Y.Base, {
*
* @method removeHighlight
*/
removeHighlight: function(timeStamp) {
Y.all('.time' + timeStamp).removeClass(CSS.NEWROW);
removeHighlight: function() {
Y.all(SELECTORS.NEWROW).removeClass(CSS.NEWROW);
},

/**
Expand Down
6 changes: 3 additions & 3 deletions report/loglive/yui/src/fetchlogs/js/fetchlogs.js
Expand Up @@ -143,7 +143,7 @@ Y.extend(FetchLogs, Y.Base, {
// Let us chop off some data from end of table to prevent really long pages.
var oldChildren = tbody.get('children').slice(this.get('perpage'));
oldChildren.remove();
Y.later(5000, this, 'removeHighlight', responseobject.until); // Remove highlighting from new rows.
Y.later(5000, this, 'removeHighlight'); // Remove highlighting from new rows.
}
},

Expand All @@ -152,8 +152,8 @@ Y.extend(FetchLogs, Y.Base, {
*
* @method removeHighlight
*/
removeHighlight: function(timeStamp) {
Y.all('.time' + timeStamp).removeClass(CSS.NEWROW);
removeHighlight: function() {
Y.all(SELECTORS.NEWROW).removeClass(CSS.NEWROW);
},

/**
Expand Down

0 comments on commit f994a89

Please sign in to comment.