mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-41266 add new is_logging() method to log readers
This will be useful in live logs report where we want only readers that have latest data.
This commit is contained in:
parent
0852f9c625
commit
bdae738e38
@ -220,6 +220,18 @@ class store implements \tool_log\log\writer, \core\log\reader {
|
||||
public function cron() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Are the new events appearing in the reader?
|
||||
*
|
||||
* @return bool true means new log events are being added, false means no new data will be added
|
||||
*/
|
||||
public function is_logging() {
|
||||
if (!$this->init()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispose off database connection after pushing any buffered events to the database.
|
||||
*/
|
||||
|
@ -44,6 +44,12 @@ class logstore_database_store_testcase extends advanced_testcase {
|
||||
$course2 = $this->getDataGenerator()->create_course();
|
||||
$module2 = $this->getDataGenerator()->create_module('resource', array('course' => $course2));
|
||||
|
||||
// Test all plugins are disabled by this command.
|
||||
set_config('enabled_stores', '', 'tool_log');
|
||||
$manager = get_log_manager(true);
|
||||
$stores = $manager->get_readers();
|
||||
$this->assertCount(0, $stores);
|
||||
|
||||
// Fake the settings, we will abuse the standard plugin table here...
|
||||
$parts = explode('_', get_class($DB));
|
||||
set_config('dbdriver', $parts[1] . '/' . $parts[0], 'logstore_database');
|
||||
@ -90,6 +96,7 @@ class logstore_database_store_testcase extends advanced_testcase {
|
||||
$store = $stores['logstore_database'];
|
||||
$this->assertInstanceOf('logstore_database\log\store', $store);
|
||||
$this->assertInstanceOf('tool_log\log\writer', $store);
|
||||
$this->assertTrue($store->is_logging());
|
||||
|
||||
$logs = $DB->get_records('logstore_standard_log', array(), 'id ASC');
|
||||
$this->assertCount(0, $logs);
|
||||
|
@ -102,6 +102,15 @@ class store implements \tool_log\log\store, \core\log\reader {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Are the new events appearing in the reader?
|
||||
*
|
||||
* @return bool true means new log events are being added, false means no new data will be added
|
||||
*/
|
||||
public function is_logging() {
|
||||
return (bool)$this->get_config('loglegacy', true);
|
||||
}
|
||||
|
||||
public function dispose() {
|
||||
}
|
||||
|
||||
@ -121,7 +130,7 @@ class store implements \tool_log\log\store, \core\log\reader {
|
||||
// This is for a good reason: it is the most frequently used DB update function,
|
||||
// so it has been optimised for speed.
|
||||
global $DB, $CFG, $USER;
|
||||
if (!$this->legacy_logging_enabled()) {
|
||||
if (!$this->is_logging()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -200,12 +209,4 @@ class store implements \tool_log\log\store, \core\log\reader {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Did admin request to keep adding new data to legacy log table?
|
||||
* @return bool
|
||||
*/
|
||||
protected function legacy_logging_enabled() {
|
||||
return (bool)get_config('logstore_legacy', 'loglegacy');
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,15 @@ class logstore_legacy_store_testcase extends advanced_testcase {
|
||||
// Enable legacy logging plugin.
|
||||
set_config('enabled_stores', 'logstore_legacy', 'tool_log');
|
||||
set_config('loglegacy', 1, 'logstore_legacy');
|
||||
get_log_manager(true);
|
||||
$manager = get_log_manager(true);
|
||||
|
||||
$stores = $manager->get_readers();
|
||||
$this->assertCount(1, $stores);
|
||||
$this->assertEquals(array('logstore_legacy'), array_keys($stores));
|
||||
$store = $stores['logstore_legacy'];
|
||||
$this->assertInstanceOf('logstore_legacy\log\store', $store);
|
||||
$this->assertInstanceOf('core\log\reader', $store);
|
||||
$this->assertTrue($store->is_logging());
|
||||
|
||||
$logs = $DB->get_records('log', array(), 'id ASC');
|
||||
$this->assertCount(0, $logs);
|
||||
@ -126,7 +134,10 @@ class logstore_legacy_store_testcase extends advanced_testcase {
|
||||
// Test if disabling works.
|
||||
set_config('enabled_stores', 'logstore_legacy', 'tool_log');
|
||||
set_config('loglegacy', 0, 'logstore_legacy');
|
||||
get_log_manager(true);
|
||||
$manager = get_log_manager(true);
|
||||
$stores = $manager->get_readers();
|
||||
$store = $stores['logstore_legacy'];
|
||||
$this->assertFalse($store->is_logging());
|
||||
|
||||
\logstore_legacy\event\unittest_executed::create(
|
||||
array('context' => \context_system::instance(), 'other' => array('sample' => 5, 'xx' => 10)))->trigger();
|
||||
@ -144,7 +155,6 @@ class logstore_legacy_store_testcase extends advanced_testcase {
|
||||
add_to_log($course1->id, 'xxxx', 'yyyy', '', '7', 0, 0);
|
||||
//$this->assertDebuggingCalled();
|
||||
$this->assertEquals(4, $DB->count_records('log'));
|
||||
|
||||
// Set everything back.
|
||||
set_config('enabled_stores', '', 'tool_log');
|
||||
set_config('loglegacy', 0, 'logstore_legacy');
|
||||
|
@ -121,4 +121,15 @@ class store implements \tool_log\log\writer, \core\log\sql_reader {
|
||||
mtrace(" Deleted old log records from standard store.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Are the new events appearing in the reader?
|
||||
*
|
||||
* @return bool true means new log events are being added, false means no new data will be added
|
||||
*/
|
||||
public function is_logging() {
|
||||
// Only enabled stpres are queried,
|
||||
// this means we can return true here unless store has some extra switch.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +40,12 @@ class logstore_standard_store_testcase extends advanced_testcase {
|
||||
$course2 = $this->getDataGenerator()->create_course();
|
||||
$module2 = $this->getDataGenerator()->create_module('resource', array('course' => $course2));
|
||||
|
||||
// Test all plugins are disabled by this command.
|
||||
set_config('enabled_stores', '', 'tool_log');
|
||||
$manager = get_log_manager(true);
|
||||
$stores = $manager->get_readers();
|
||||
$this->assertCount(0, $stores);
|
||||
|
||||
// Enable logging plugin.
|
||||
set_config('enabled_stores', 'logstore_standard', 'tool_log');
|
||||
set_config('buffersize', 0, 'logstore_standard');
|
||||
@ -52,6 +58,7 @@ class logstore_standard_store_testcase extends advanced_testcase {
|
||||
$store = $stores['logstore_standard'];
|
||||
$this->assertInstanceOf('logstore_standard\log\store', $store);
|
||||
$this->assertInstanceOf('tool_log\log\writer', $store);
|
||||
$this->assertTrue($store->is_logging());
|
||||
|
||||
$logs = $DB->get_records('logstore_standard_log', array(), 'id ASC');
|
||||
$this->assertCount(0, $logs);
|
||||
|
@ -69,4 +69,11 @@ interface reader {
|
||||
* @return int
|
||||
*/
|
||||
public function get_events_count($selectwhere, array $params);
|
||||
|
||||
/**
|
||||
* Are the new events appearing in the reader?
|
||||
*
|
||||
* @return bool true means new log events are being added, false means no new data will be added
|
||||
*/
|
||||
public function is_logging();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user