Skip to content

Commit

Permalink
MDL-62907 Logging: remove plugin interdependencies
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
stronk7 authored and sammarshallou committed Apr 12, 2019
1 parent 12f9acb commit 3d915f5
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 24 deletions.
19 changes: 19 additions & 0 deletions admin/tool/log/classes/helper/reader.php
Expand Up @@ -62,6 +62,25 @@ public function get_description() {
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.
Expand Down
3 changes: 2 additions & 1 deletion admin/tool/log/classes/local/privacy/helper.php
Expand Up @@ -37,6 +37,7 @@
* @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.
Expand All @@ -49,7 +50,7 @@ protected static function restore_event_from_standard_record($data) {
$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'] = [];
}
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/log/store/database/classes/log/store.php
Expand Up @@ -226,7 +226,7 @@ public function get_log_event($data) {
$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();
}
Expand Down
2 changes: 2 additions & 0 deletions admin/tool/log/store/database/lang/en/logstore_database.php
Expand Up @@ -39,6 +39,8 @@
$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';
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/log/store/database/settings.php
Expand Up @@ -60,8 +60,8 @@
'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',
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/log/store/database/version.php
Expand Up @@ -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
*/
Expand Down
19 changes: 0 additions & 19 deletions admin/tool/log/store/standard/classes/log/store.php
Expand Up @@ -112,25 +112,6 @@ public function get_events_select_iterator($selectwhere, array $params, $sort, $
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.
*
Expand Down

0 comments on commit 3d915f5

Please sign in to comment.