Skip to content

Commit

Permalink
Merge pull request #164 from sarahjcotton/search-all-configs
Browse files Browse the repository at this point in the history
Search for all settings in config_plugins
  • Loading branch information
brendanheywood authored Nov 1, 2023
2 parents 173f062 + 188ad6d commit 391dee8
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions cleaner/environment_matrix/classes/local/matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public static function environmentbar_exists() {
* @return array
*/
public static function search($search, $configitems = []) {
global $DB;
$result = [];

$adminroot = admin_get_root();
Expand Down Expand Up @@ -117,6 +118,42 @@ public static function search($search, $configitems = []) {

}

// Get all configs that match the search term from config_plugins.
$likeplugin = $DB->sql_like('plugin', ':likeplugin');
$likename = $DB->sql_like('name', ':likename');
$notlikename = $DB->sql_like('name', ':notlikename', true, true, true);
$likevalue = $DB->sql_like('value', ':likevalue');
$nontreefindings = $DB->get_records_sql(
"SELECT *
FROM {config_plugins}
WHERE ({$likeplugin}
OR {$likename}
OR {$likevalue})
AND $notlikename",
[
'likeplugin' => '%' . $DB->sql_like_escape($search) . '%',
'likename' => '%' . $DB->sql_like_escape($search) . '%',
'likevalue' => '%' . $DB->sql_like_escape($search) . '%',
'notlikename' => 'version',
]
);

// Add those to the result array as well.
foreach ($nontreefindings as $setting) {
$record = new stdClass();
$record->plugin = (empty($setting->plugin) ? 'core' : $setting->plugin);
$record->value = get_config($record->plugin, $setting->name);
$record->name = $setting->name;
$record->textarea = false;
$record->display = true;
// Make sure we don't overwrite things that have already been added to the result array
// as they might have been created as admin_setting_configtextarea or admin_setting_confightmleditor
// and we won't be able to tell that here.
if (empty($result[$record->plugin][$record->name])) {
$result[$record->plugin][$record->name] = $record;
}
}

return $result;
}

Expand Down

0 comments on commit 391dee8

Please sign in to comment.