From 643e3a5b6db19b9ba0210fef89f6ee163bc0edef Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Thu, 20 Aug 2015 12:23:12 +0100 Subject: Convert string booleans to real booleans Legacy compatibility, from the days in stable8 when checkbox boolean values were stored as the strings 'true' and 'false'. --- apps/files_external/lib/definitionparameter.php | 21 +++++++++++++++------ apps/files_external/lib/frontenddefinitiontrait.php | 4 ++-- apps/files_external/lib/ftp.php | 6 +----- 3 files changed, 18 insertions(+), 13 deletions(-) (limited to 'apps/files_external/lib') diff --git a/apps/files_external/lib/definitionparameter.php b/apps/files_external/lib/definitionparameter.php index 4b560908b69..7f883e5fad1 100644 --- a/apps/files_external/lib/definitionparameter.php +++ b/apps/files_external/lib/definitionparameter.php @@ -154,22 +154,31 @@ class DefinitionParameter implements \JsonSerializable { /** * Validate a parameter value against this + * Convert type as necessary * * @param mixed $value Value to check * @return bool success */ - public function validateValue($value) { - if ($this->getFlags() & self::FLAG_OPTIONAL) { - return true; - } + public function validateValue(&$value) { + $optional = $this->getFlags() & self::FLAG_OPTIONAL; + switch ($this->getType()) { case self::VALUE_BOOLEAN: if (!is_bool($value)) { - return false; + switch ($value) { + case 'true': + $value = true; + break; + case 'false': + $value = false; + break; + default: + return false; + } } break; default: - if (empty($value)) { + if (!$value && !$optional) { return false; } break; diff --git a/apps/files_external/lib/frontenddefinitiontrait.php b/apps/files_external/lib/frontenddefinitiontrait.php index 4b826372d2f..a5fb1a3f62f 100644 --- a/apps/files_external/lib/frontenddefinitiontrait.php +++ b/apps/files_external/lib/frontenddefinitiontrait.php @@ -134,12 +134,12 @@ trait FrontendDefinitionTrait { * @return bool */ public function validateStorageDefinition(StorageConfig $storage) { - $options = $storage->getBackendOptions(); foreach ($this->getParameters() as $name => $parameter) { - $value = isset($options[$name]) ? $options[$name] : null; + $value = $storage->getBackendOption($name); if (!$parameter->validateValue($value)) { return false; } + $storage->setBackendOption($name, $value); } return true; } diff --git a/apps/files_external/lib/ftp.php b/apps/files_external/lib/ftp.php index aeca17c4f4c..f3631e53fa1 100644 --- a/apps/files_external/lib/ftp.php +++ b/apps/files_external/lib/ftp.php @@ -45,11 +45,7 @@ class FTP extends \OC\Files\Storage\StreamWrapper{ $this->user=$params['user']; $this->password=$params['password']; if (isset($params['secure'])) { - if (is_string($params['secure'])) { - $this->secure = ($params['secure'] === 'true'); - } else { - $this->secure = (bool)$params['secure']; - } + $this->secure = $params['secure']; } else { $this->secure = false; } -- cgit v1.2.3