Do not query data that is already in the appconfig

This is already available. We better use a simple regex.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2016-10-08 14:46:00 +02:00
parent 3f40bb69f8
commit 1ba2b7e5d4
No known key found for this signature in database
GPG Key ID: 1E152838F164D13B
1 changed files with 11 additions and 22 deletions

View File

@ -55,32 +55,21 @@ class Helper {
public function getServerConfigurationPrefixes($activeConfigurations = false) {
$referenceConfigkey = 'ldap_configuration_active';
$sql = '
SELECT DISTINCT `configkey`
FROM `*PREFIX*appconfig`
WHERE `appid` = \'user_ldap\'
AND `configkey` LIKE ?
';
$config = \OC::$server->getConfig();
if($activeConfigurations) {
if (\OC::$server->getConfig()->getSystemValue( 'dbtype', 'sqlite' ) === 'oci') {
//FIXME oracle hack: need to explicitly cast CLOB to CHAR for comparison
$sql .= ' AND to_char(`configvalue`)=\'1\'';
} else {
$sql .= ' AND `configvalue` = \'1\'';
$keys = $config->getAppKeys('user_ldap');
$prefixes = [];
foreach ($keys as $key) {
if (preg_match('/ldap_configuration_active$/S', $key) === 1) {
if ($activeConfigurations && $config->getAppValue('user_ldap', $key, '0') !== '1') {
continue;
}
$len = strlen($key) - strlen($referenceConfigkey);
$prefixes[] = substr($key, 0, $len);
}
}
$stmt = \OCP\DB::prepare($sql);
$serverConfigs = $stmt->execute(array('%'.$referenceConfigkey))->fetchAll();
$prefixes = array();
foreach($serverConfigs as $serverConfig) {
$len = strlen($serverConfig['configkey']) - strlen($referenceConfigkey);
$prefixes[] = substr($serverConfig['configkey'], 0, $len);
}
return $prefixes;
}