MDL-73948 report_loglive: Fix missing records

This commit is contained in:
Mikhail Golenkov
2022-03-31 18:36:38 +11:00
parent 3ab09c775d
commit f994a89ce5
8 changed files with 76 additions and 23 deletions
+15
View File
@@ -404,4 +404,19 @@ class report_loglive_table_log extends table_sql {
}
}
}
/**
* 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;
}
}
+3 -4
View File
@@ -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);
}
+10 -9
View File
@@ -67,15 +67,6 @@ $renderable = new report_loglive_renderable($logreader, $id, $url, 0, $page);
$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);
@@ -95,6 +86,16 @@ echo $output->reader_selector($renderable);
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();
+38
View File
@@ -55,4 +55,42 @@ class lib_test extends \advanced_testcase {
$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);
}
}
@@ -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.
}
},
@@ -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);
},
/**
@@ -1 +1 @@
YUI.add("moodle-report_loglive-fetchlogs",function(a,e){function t(){t.superclass.constructor.apply(this,arguments)}var i="newrow",r={NEWROW:"."+i,TBODY:".flexible tbody",ACTIONLINK:'[data-action="action-popup"]',PAUSEBUTTON:"#livelogs-pause-button",SPINNER:"."+"spinner"};a.extend(t,a.Base,{callBack:{},spinner:{},pauseButton:{},initializer:function(){0===this.get("page")&&(this.callBack=a.later(1e3*this.get("interval"),this,this.fetchRecentLogs,null,!0)),this.spinner=a.one(r.SPINNER),this.pauseButton=a.one(r.PAUSEBUTTON),this.spinner.hide(),a.one(r.TBODY).delegate("click",this.openActionLink,r.ACTIONLINK,this),a.one(r.PAUSEBUTTON).on("click",this.toggleUpdate,this)},fetchRecentLogs:function(){var e,t;this.spinner.show(),e={logreader:this.get("logreader"),since:this.get("since"),page:this.get("page"),id:this.get("courseid")},e={method:"get",context:this,on:{complete:this.updateLogTable},data:e},t=M.cfg.wwwroot+"/report/loglive/loglive_ajax.php",a.io(t,e)},updateLogTable:function(e,t){var i,n,o;a.later(600,this,"hideLoadingIcon");try{if((i=a.JSON.parse(t.responseText)).error)return a.use("moodle-core-notification-ajaxexception",function(){return new M.core.ajaxException(i)}),this}catch(s){return a.use("moodle-core-notification-exception",function(){return new M.core.exception(s)}),this}this.set("since",i.until),t=i.logs,(n=a.one(r.TBODY))&&t&&((o=n.get("firstChild"))&&n.insertBefore(t,o),n.get("children").slice(this.get("perpage")).remove(),a.later(5e3,this,"removeHighlight",i.until))},removeHighlight:function(e){a.all(".time"+e).removeClass(i)},hideLoadingIcon:function(){this.spinner.hide()},openActionLink:function(e){var t=JSON.parse(e.target.get("dataset").popupAction);window.openpopup(e,t.jsfunctionargs)},toggleUpdate:function(){this.callBack?(this.callBack.cancel(),this.callBack="",this.pauseButton.setContent(M.util.get_string("resume","report_loglive"))):(this.callBack=a.later(1e3*this.get("interval"),this,this.fetchRecentLogs,null,!0),this.pauseButton.setContent(M.util.get_string("pause","report_loglive")))}},{NAME:"fetchLogs",ATTRS:{since:null,courseid:0,page:0,perpage:100,interval:60,logreader:"logstore_standard"}}),a.namespace("M.report_loglive.FetchLogs").init=function(e){return new t(e)}},"@VERSION@",{requires:["base","event","node","io","node-event-delegate"]});
YUI.add("moodle-report_loglive-fetchlogs",function(a,e){function t(){t.superclass.constructor.apply(this,arguments)}var i="newrow",r={NEWROW:"."+i,TBODY:".flexible tbody",ACTIONLINK:'[data-action="action-popup"]',PAUSEBUTTON:"#livelogs-pause-button",SPINNER:"."+"spinner"};a.extend(t,a.Base,{callBack:{},spinner:{},pauseButton:{},initializer:function(){0===this.get("page")&&(this.callBack=a.later(1e3*this.get("interval"),this,this.fetchRecentLogs,null,!0)),this.spinner=a.one(r.SPINNER),this.pauseButton=a.one(r.PAUSEBUTTON),this.spinner.hide(),a.one(r.TBODY).delegate("click",this.openActionLink,r.ACTIONLINK,this),a.one(r.PAUSEBUTTON).on("click",this.toggleUpdate,this)},fetchRecentLogs:function(){var e,t;this.spinner.show(),e={logreader:this.get("logreader"),since:this.get("since"),page:this.get("page"),id:this.get("courseid")},e={method:"get",context:this,on:{complete:this.updateLogTable},data:e},t=M.cfg.wwwroot+"/report/loglive/loglive_ajax.php",a.io(t,e)},updateLogTable:function(e,t){var i,n,o;a.later(600,this,"hideLoadingIcon");try{if((i=a.JSON.parse(t.responseText)).error)return a.use("moodle-core-notification-ajaxexception",function(){return new M.core.ajaxException(i)}),this}catch(s){return a.use("moodle-core-notification-exception",function(){return new M.core.exception(s)}),this}this.set("since",i.until),t=i.logs,(n=a.one(r.TBODY))&&t&&((o=n.get("firstChild"))&&n.insertBefore(t,o),n.get("children").slice(this.get("perpage")).remove(),a.later(5e3,this,"removeHighlight"))},removeHighlight:function(){a.all(r.NEWROW).removeClass(i)},hideLoadingIcon:function(){this.spinner.hide()},openActionLink:function(e){var t=JSON.parse(e.target.get("dataset").popupAction);window.openpopup(e,t.jsfunctionargs)},toggleUpdate:function(){this.callBack?(this.callBack.cancel(),this.callBack="",this.pauseButton.setContent(M.util.get_string("resume","report_loglive"))):(this.callBack=a.later(1e3*this.get("interval"),this,this.fetchRecentLogs,null,!0),this.pauseButton.setContent(M.util.get_string("pause","report_loglive")))}},{NAME:"fetchLogs",ATTRS:{since:null,courseid:0,page:0,perpage:100,interval:60,logreader:"logstore_standard"}}),a.namespace("M.report_loglive.FetchLogs").init=function(e){return new t(e)}},"@VERSION@",{requires:["base","event","node","io","node-event-delegate"]});
@@ -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.
}
},
@@ -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);
},
/**
+3 -3
View File
@@ -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.
}
},
@@ -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);
},
/**