mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-37813 remove missing filters when configuring string filters and fix filter uninstall
This commit is contained in:
parent
4e47920f08
commit
a67ea663b1
3 changed files with 59 additions and 14 deletions
|
@ -112,11 +112,25 @@ class filter extends base {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
public function uninstall_cleanup() {
|
public function uninstall_cleanup() {
|
||||||
global $DB;
|
global $DB, $CFG;
|
||||||
|
|
||||||
$DB->delete_records('filter_active', array('filter' => $this->name));
|
$DB->delete_records('filter_active', array('filter' => $this->name));
|
||||||
$DB->delete_records('filter_config', array('filter' => $this->name));
|
$DB->delete_records('filter_config', array('filter' => $this->name));
|
||||||
|
|
||||||
|
if (empty($CFG->filterall)) {
|
||||||
|
$stringfilters = array();
|
||||||
|
} else if (!empty($CFG->stringfilters)) {
|
||||||
|
$stringfilters = explode(',', $CFG->stringfilters);
|
||||||
|
$stringfilters = array_combine($stringfilters, $stringfilters);
|
||||||
|
} else {
|
||||||
|
$stringfilters = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($stringfilters[$this->name]);
|
||||||
|
|
||||||
|
set_config('stringfilters', implode(',', $stringfilters));
|
||||||
|
set_config('filterall', !empty($stringfilters));
|
||||||
|
|
||||||
parent::uninstall_cleanup();
|
parent::uninstall_cleanup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -721,13 +721,23 @@ function filter_get_string_filters() {
|
||||||
*/
|
*/
|
||||||
function filter_set_applies_to_strings($filter, $applytostrings) {
|
function filter_set_applies_to_strings($filter, $applytostrings) {
|
||||||
$stringfilters = filter_get_string_filters();
|
$stringfilters = filter_get_string_filters();
|
||||||
$numstringfilters = count($stringfilters);
|
$prevfilters = $stringfilters;
|
||||||
|
$allfilters = core_component::get_plugin_list('filter');
|
||||||
|
|
||||||
if ($applytostrings) {
|
if ($applytostrings) {
|
||||||
$stringfilters[$filter] = $filter;
|
$stringfilters[$filter] = $filter;
|
||||||
} else {
|
} else {
|
||||||
unset($stringfilters[$filter]);
|
unset($stringfilters[$filter]);
|
||||||
}
|
}
|
||||||
if (count($stringfilters) != $numstringfilters) {
|
|
||||||
|
// Remove missing filters.
|
||||||
|
foreach ($stringfilters as $filter) {
|
||||||
|
if (!isset($allfilters[$filter])) {
|
||||||
|
unset($stringfilters[$filter]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($prevfilters != $stringfilters) {
|
||||||
set_config('stringfilters', implode(',', $stringfilters));
|
set_config('stringfilters', implode(',', $stringfilters));
|
||||||
set_config('filterall', !empty($stringfilters));
|
set_config('filterall', !empty($stringfilters));
|
||||||
}
|
}
|
||||||
|
|
|
@ -606,23 +606,39 @@ class core_filterlib_testcase extends advanced_testcase {
|
||||||
|
|
||||||
public function test_set() {
|
public function test_set() {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
|
$this->assertFileExists("$CFG->dirroot/filter/emailprotect"); // Any standard filter.
|
||||||
|
$this->assertFileExists("$CFG->dirroot/filter/tidy"); // Any standard filter.
|
||||||
|
$this->assertFileNotExists("$CFG->dirroot/filter/grgrggr"); // Any non-existent filter
|
||||||
|
|
||||||
// Setup fixture.
|
// Setup fixture.
|
||||||
$CFG->filterall = 0;
|
set_config('filterall', 0);
|
||||||
$CFG->stringfilters = '';
|
set_config('stringfilters', '');
|
||||||
// Exercise SUT.
|
// Exercise SUT.
|
||||||
filter_set_applies_to_strings('name', true);
|
filter_set_applies_to_strings('tidy', true);
|
||||||
// Validate.
|
// Validate.
|
||||||
$this->assertEquals('name', $CFG->stringfilters);
|
$this->assertEquals('tidy', $CFG->stringfilters);
|
||||||
|
$this->assertEquals(1, $CFG->filterall);
|
||||||
|
|
||||||
|
filter_set_applies_to_strings('grgrggr', true);
|
||||||
|
$this->assertEquals('tidy', $CFG->stringfilters);
|
||||||
|
$this->assertEquals(1, $CFG->filterall);
|
||||||
|
|
||||||
|
filter_set_applies_to_strings('emailprotect', true);
|
||||||
|
$this->assertEquals('tidy,emailprotect', $CFG->stringfilters);
|
||||||
$this->assertEquals(1, $CFG->filterall);
|
$this->assertEquals(1, $CFG->filterall);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_unset_to_empty() {
|
public function test_unset_to_empty() {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
|
$this->assertFileExists("$CFG->dirroot/filter/tidy"); // Any standard filter.
|
||||||
|
|
||||||
// Setup fixture.
|
// Setup fixture.
|
||||||
$CFG->filterall = 1;
|
set_config('filterall', 1);
|
||||||
$CFG->stringfilters = 'name';
|
set_config('stringfilters', 'tidy');
|
||||||
// Exercise SUT.
|
// Exercise SUT.
|
||||||
filter_set_applies_to_strings('name', false);
|
filter_set_applies_to_strings('tidy', false);
|
||||||
// Validate.
|
// Validate.
|
||||||
$this->assertEquals('', $CFG->stringfilters);
|
$this->assertEquals('', $CFG->stringfilters);
|
||||||
$this->assertEquals('', $CFG->filterall);
|
$this->assertEquals('', $CFG->filterall);
|
||||||
|
@ -630,13 +646,18 @@ class core_filterlib_testcase extends advanced_testcase {
|
||||||
|
|
||||||
public function test_unset_multi() {
|
public function test_unset_multi() {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
|
$this->assertFileExists("$CFG->dirroot/filter/emailprotect"); // Any standard filter.
|
||||||
|
$this->assertFileExists("$CFG->dirroot/filter/tidy"); // Any standard filter.
|
||||||
|
$this->assertFileExists("$CFG->dirroot/filter/multilang"); // Any standard filter.
|
||||||
|
|
||||||
// Setup fixture.
|
// Setup fixture.
|
||||||
$CFG->filterall = 1;
|
set_config('filterall', 1);
|
||||||
$CFG->stringfilters = 'name,other';
|
set_config('stringfilters', 'emailprotect,tidy,multilang');
|
||||||
// Exercise SUT.
|
// Exercise SUT.
|
||||||
filter_set_applies_to_strings('name', false);
|
filter_set_applies_to_strings('tidy', false);
|
||||||
// Validate.
|
// Validate.
|
||||||
$this->assertEquals('other', $CFG->stringfilters);
|
$this->assertEquals('emailprotect,multilang', $CFG->stringfilters);
|
||||||
$this->assertEquals(1, $CFG->filterall);
|
$this->assertEquals(1, $CFG->filterall);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue