MDL-62907 Logging: remove plugin interdependencies
- Move decode_other() from standard to tool_log\helper\reader trait. - Change all ocurrences to "use" the trait method. But a unit test. - Duplicate the admin lang strings in database and use them. - An incorrect phpdoc @package.
This commit is contained in:
committed by
sam marshall
parent
12f9acbe76
commit
3d915f5345
@@ -62,6 +62,25 @@ trait reader {
|
||||
return $this->store;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function decodes the other field into an array using either PHP serialisation or JSON.
|
||||
*
|
||||
* Note that this does not rely on the config setting, it supports both formats, so you can
|
||||
* use it for data before/after making a change to the config setting.
|
||||
*
|
||||
* The return value is usually an array but it can also be null or a boolean or something.
|
||||
*
|
||||
* @param string $other Other value
|
||||
* @return mixed Decoded value
|
||||
*/
|
||||
public static function decode_other(string $other) {
|
||||
if ($other === 'N;' || preg_match('~^.:~', $other)) {
|
||||
return unserialize($other);
|
||||
} else {
|
||||
return json_decode($other, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds ID column to $sort to make sure events from one request
|
||||
* within 1 second are returned in the same order.
|
||||
|
||||
@@ -37,6 +37,7 @@ use core_privacy\local\request\transform;
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class helper {
|
||||
use \tool_log\helper\reader;
|
||||
|
||||
/**
|
||||
* Returns an event from a standard record.
|
||||
@@ -49,7 +50,7 @@ class helper {
|
||||
$extra = ['origin' => $data->origin, 'ip' => $data->ip, 'realuserid' => $data->realuserid];
|
||||
$data = (array) $data;
|
||||
$id = $data['id'];
|
||||
$data['other'] = \logstore_standard\log\store::decode_other($data['other']);
|
||||
$data['other'] = self::decode_other($data['other']);
|
||||
if ($data['other'] === false) {
|
||||
$data['other'] = [];
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ class store implements \tool_log\log\writer, \core\log\sql_reader {
|
||||
$extra = array('origin' => $data->origin, 'ip' => $data->ip, 'realuserid' => $data->realuserid);
|
||||
$data = (array)$data;
|
||||
$id = $data['id'];
|
||||
$data['other'] = \logstore_standard\log\store::decode_other($data['other']);
|
||||
$data['other'] = self::decode_other($data['other']);
|
||||
if ($data['other'] === false) {
|
||||
$data['other'] = array();
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@ $string['includeactions'] = 'Include actions of these types';
|
||||
$string['includelevels'] = 'Include actions with these educational levels';
|
||||
$string['filters'] = 'Filter logs';
|
||||
$string['filters_help'] = 'Enable filters that exclude some actions from being logged.';
|
||||
$string['jsonformat'] = 'JSON format';
|
||||
$string['jsonformat_desc'] = 'Use standard JSON format instead of PHP serialised data in the \'other\' database field.';
|
||||
$string['logguests'] = 'Log guest actions';
|
||||
$string['other'] = 'Other';
|
||||
$string['participating'] = 'Participating';
|
||||
|
||||
@@ -60,8 +60,8 @@ if ($hassiteconfig) {
|
||||
'logstore_database'), get_string('buffersize_help', 'logstore_database'), 50));
|
||||
|
||||
$settings->add(new admin_setting_configcheckbox('logstore_database/jsonformat',
|
||||
new lang_string('jsonformat', 'logstore_standard'),
|
||||
new lang_string('jsonformat_desc', 'logstore_standard'), 1));
|
||||
new lang_string('jsonformat', 'logstore_database'),
|
||||
new lang_string('jsonformat_desc', 'logstore_database'), 1));
|
||||
|
||||
// Filters.
|
||||
$settings->add(new admin_setting_heading('filters', get_string('filters', 'logstore_database'), get_string('filters_help',
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
/**
|
||||
* External database log store.
|
||||
*
|
||||
* @package logstore_standard
|
||||
* @package logstore_database
|
||||
* @copyright 2013 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
@@ -112,25 +112,6 @@ class store implements \tool_log\log\writer, \core\log\sql_internal_table_reader
|
||||
return new \core\dml\recordset_walk($recordset, array($this, 'get_log_event'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Function decodes the other field into an array using either PHP serialisation or JSON.
|
||||
*
|
||||
* Note that this does not rely on the config setting, it supports both formats, so you can
|
||||
* use it for data before/after making a change to the config setting.
|
||||
*
|
||||
* The return value is usually an array but it can also be null or a boolean or something.
|
||||
*
|
||||
* @param string $other Other value
|
||||
* @return mixed Decoded value
|
||||
*/
|
||||
public static function decode_other(string $other) {
|
||||
if ($other === 'N;' || preg_match('~^.:~', $other)) {
|
||||
return unserialize($other);
|
||||
} else {
|
||||
return json_decode($other, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an event from the log data.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user