From 9ca4065ef5ccce3a4bc807e4b7bfddd76f50724c Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 20 Jan 2017 21:57:12 +0100 Subject: LDAP PUT command now supports setting multiple keys at once Signed-off-by: Arthur Schiwon --- .../lib/Controller/ConfigAPIController.php | 30 ++++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'apps/user_ldap') diff --git a/apps/user_ldap/lib/Controller/ConfigAPIController.php b/apps/user_ldap/lib/Controller/ConfigAPIController.php index 5256b0d8aad..7a5a5c5b7ba 100644 --- a/apps/user_ldap/lib/Controller/ConfigAPIController.php +++ b/apps/user_ldap/lib/Controller/ConfigAPIController.php @@ -133,7 +133,7 @@ class ConfigAPIController extends OCSController { * * * ok - * 100 + * 200 * OK * * @@ -170,7 +170,7 @@ class ConfigAPIController extends OCSController { * modifies a configuration * * Example: - * curl -X PUT -d "key=ldapHost&value=ldaps://my.ldap.server" \ + * curl -X PUT -d "configData[ldapHost]=ldaps://my.ldap.server&configData[ldapPort]=636" \ * -H "OCS-APIREQUEST: true" -u $admin:$password \ * https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config/s60 * @@ -178,33 +178,35 @@ class ConfigAPIController extends OCSController { * * * ok - * 100 + * 200 * OK * * * * * @param string $configID - * @param string $key - * @param string $value + * @param array $configData * @return DataResponse * @throws OCSException */ - public function modify($configID, $key, $value) { + public function modify($configID, $configData) { $this->ensureConfigIDExists($configID); + if(!is_array($configData)) { + throw new OCSBadRequestException('configData is not properly set'); + } + try { - $config = new Configuration($configID); + $configuration = new Configuration($configID); + $configKeys = $configuration->getConfigTranslationArray(); - $configKeys = $config->getConfigTranslationArray(); - if(!isset($configKeys[$key]) && !in_array($key, $configKeys, true)) { - throw new OCSBadRequestException('Invalid config key'); + foreach ($configKeys as $i => $key) { + if(isset($configData[$key])) { + $configuration->$key = $configData[$key]; + } } - $config->$key = $value; - $config->saveConfiguration(); - } catch(OCSException $e) { - throw $e; + $configuration->saveConfiguration(); } catch (\Exception $e) { $this->logger->logException($e); throw new OCSException('An issue occurred when modifying the config.'); -- cgit v1.2.3