MDL-74390 filter admin: log filter order changes in config_log
This commit is contained in:
@@ -664,6 +664,13 @@ function filter_set_global_state($filtername, $state, $move = 0) {
|
||||
|
||||
// Move only active.
|
||||
if ($move != 0 and isset($on[$filter->filter])) {
|
||||
// Capture the old order for logging.
|
||||
$oldorder = implode(', ', array_map(
|
||||
function($f) {
|
||||
return $f->filter;
|
||||
}, $on));
|
||||
|
||||
// Work out the new order.
|
||||
$i = 1;
|
||||
foreach ($on as $f) {
|
||||
$f->newsortorder = $i;
|
||||
@@ -686,6 +693,13 @@ function filter_set_global_state($filtername, $state, $move = 0) {
|
||||
}
|
||||
|
||||
core_collator::asort_objects_by_property($on, 'newsortorder', core_collator::SORT_NUMERIC);
|
||||
|
||||
// Log in config_log.
|
||||
$neworder = implode(', ', array_map(
|
||||
function($f) {
|
||||
return $f->filter;
|
||||
}, $on));
|
||||
add_to_config_log('order', $oldorder, $neworder, 'core_filter');
|
||||
}
|
||||
|
||||
// Inactive are sorted by filter name.
|
||||
|
||||
@@ -131,6 +131,8 @@ class core_filterlib_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
public function test_update_reorder_down() {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->remove_all_filters_from_config(); // Remove all filters.
|
||||
// Setup fixture.
|
||||
@@ -141,9 +143,19 @@ class core_filterlib_testcase extends advanced_testcase {
|
||||
filter_set_global_state('two', TEXTFILTER_ON, -1);
|
||||
// Validate.
|
||||
$this->assert_global_sort_order(array('two', 'one', 'three'));
|
||||
|
||||
// Check this was logged in config log.
|
||||
$logs = $DB->get_records('config_log', null, 'id DESC', '*', 0, 1);
|
||||
$log = reset($logs);
|
||||
$this->assertEquals('core_filter', $log->plugin);
|
||||
$this->assertEquals('order', $log->name);
|
||||
$this->assertEquals('two, one, three', $log->value);
|
||||
$this->assertEquals('one, two, three', $log->oldvalue);
|
||||
}
|
||||
|
||||
public function test_update_reorder_up() {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->remove_all_filters_from_config(); // Remove all filters.
|
||||
// Setup fixture.
|
||||
@@ -155,6 +167,14 @@ class core_filterlib_testcase extends advanced_testcase {
|
||||
filter_set_global_state('two', TEXTFILTER_ON, 1);
|
||||
// Validate.
|
||||
$this->assert_global_sort_order(array('one', 'three', 'two', 'four'));
|
||||
|
||||
// Check this was logged in config log.
|
||||
$logs = $DB->get_records('config_log', null, 'id DESC', '*', 0, 1);
|
||||
$log = reset($logs);
|
||||
$this->assertEquals('core_filter', $log->plugin);
|
||||
$this->assertEquals('order', $log->name);
|
||||
$this->assertEquals('one, three, two, four', $log->value);
|
||||
$this->assertEquals('one, two, three, four', $log->oldvalue);
|
||||
}
|
||||
|
||||
public function test_auto_sort_order_change_to_enabled() {
|
||||
|
||||
Reference in New Issue
Block a user