Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search for all settings in config_plugins (Totara) #165

Open
wants to merge 1 commit into
base: TOTARA_13
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading