From b17f26834df37819656b83936c34d8957c344fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Macias?= Date: Wed, 25 Nov 2015 11:58:54 +0100 Subject: [PATCH 1/8] Add different storage status codes managed by StoragedNotAvailableException --- .../controller/storagescontroller.php | 42 +++++++++++++++++-- apps/files_external/lib/config.php | 4 ++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/apps/files_external/controller/storagescontroller.php b/apps/files_external/controller/storagescontroller.php index c66bd902d8..7efe761140 100644 --- a/apps/files_external/controller/storagescontroller.php +++ b/apps/files_external/controller/storagescontroller.php @@ -242,10 +242,44 @@ abstract class StoragesController extends Controller { $this->l10n->t('Insufficient data: %s', [$e->getMessage()]) ); } catch (StorageNotAvailableException $e) { - $storage->setStatus( - \OC_Mount_Config::STATUS_ERROR, - $e->getMessage() - ); + switch ($e->getCode()) { + case 1: + $storage->setStatus( + \OC_Mount_Config::STATUS_ERROR, + $this->l10n->t('%s', [$e->getMessage()]) + ); + break; + case 3: + $storage->setStatus( + \OC_Mount_Config::STATUS_INCOMPLETE_CONF, + $this->l10n->t('Incomplete configuration. %s', [$e->getMessage()]) + ); + break; + case 4: + $storage->setStatus( + \OC_Mount_Config::STATUS_UNAUTHORIZED, + $this->l10n->t('Unauthorized. %s', [$e->getMessage()]) + $e->getMessage() + ); + break; + case 5: + $storage->setStatus( + \OC_Mount_Config::STATUS_TIMEOUT, + $this->l10n->t('Timeout. %s', [$e->getMessage()]) + ); + break; + case 6: + $storage->setStatus( + \OC_Mount_Config::STATUS_NETWORK_ERROR, + $this->l10n->t('Network error. %s', [$e->getMessage()]) + ); + break; + default: + $storage->setStatus( + \OC_Mount_Config::STATUS_ERROR, + $this->l10n->t('%s', [$e->getMessage()]) + ); + } } catch (\Exception $e) { // FIXME: convert storage exceptions to StorageNotAvailableException $storage->setStatus( diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 1e96fac814..bf50723303 100644 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -52,6 +52,10 @@ class OC_Mount_Config { const STATUS_SUCCESS = 0; const STATUS_ERROR = 1; const STATUS_INDETERMINATE = 2; + const STATUS_INCOMPLETE_CONF = 3; + const STATUS_UNAUTHORIZED = 4; + const STATUS_TIMEOUT = 5; + const STATUS_NETWORK_ERROR = 6; // whether to skip backend test (for unit tests, as this static class is not mockable) public static $skipTest = false; From 7cd13f462a41ebde9e151bb7e753a842262ad416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Macias?= Date: Wed, 25 Nov 2015 17:52:58 +0100 Subject: [PATCH 2/8] Add new external storage exceptions for different errors --- .../controller/storagescontroller.php | 62 +++++++------------ lib/public/files/extstorageauthexception.php | 44 +++++++++++++ .../files/extstoragebadconfigexception.php | 45 ++++++++++++++ .../files/extstorageconnectionexception.php | 44 +++++++++++++ .../files/extstoragetimeoutexception.php | 44 +++++++++++++ 5 files changed, 201 insertions(+), 38 deletions(-) create mode 100644 lib/public/files/extstorageauthexception.php create mode 100644 lib/public/files/extstoragebadconfigexception.php create mode 100644 lib/public/files/extstorageconnectionexception.php create mode 100644 lib/public/files/extstoragetimeoutexception.php diff --git a/apps/files_external/controller/storagescontroller.php b/apps/files_external/controller/storagescontroller.php index 7efe761140..ddd7fe6df1 100644 --- a/apps/files_external/controller/storagescontroller.php +++ b/apps/files_external/controller/storagescontroller.php @@ -242,44 +242,30 @@ abstract class StoragesController extends Controller { $this->l10n->t('Insufficient data: %s', [$e->getMessage()]) ); } catch (StorageNotAvailableException $e) { - switch ($e->getCode()) { - case 1: - $storage->setStatus( - \OC_Mount_Config::STATUS_ERROR, - $this->l10n->t('%s', [$e->getMessage()]) - ); - break; - case 3: - $storage->setStatus( - \OC_Mount_Config::STATUS_INCOMPLETE_CONF, - $this->l10n->t('Incomplete configuration. %s', [$e->getMessage()]) - ); - break; - case 4: - $storage->setStatus( - \OC_Mount_Config::STATUS_UNAUTHORIZED, - $this->l10n->t('Unauthorized. %s', [$e->getMessage()]) - $e->getMessage() - ); - break; - case 5: - $storage->setStatus( - \OC_Mount_Config::STATUS_TIMEOUT, - $this->l10n->t('Timeout. %s', [$e->getMessage()]) - ); - break; - case 6: - $storage->setStatus( - \OC_Mount_Config::STATUS_NETWORK_ERROR, - $this->l10n->t('Network error. %s', [$e->getMessage()]) - ); - break; - default: - $storage->setStatus( - \OC_Mount_Config::STATUS_ERROR, - $this->l10n->t('%s', [$e->getMessage()]) - ); - } + $storage->setStatus( + \OC_Mount_Config::STATUS_ERROR, + $this->l10n->t('%s', [$e->getMessage()]) + ); + } catch (ExtStorageBadConfigException $e) { + $storage->setStatus( + $e->getCode(), + $this->l10n->t('%s', [$e->getMessage()]) + ); + } catch (ExtStorageAuthException $e) { + $storage->setStatus( + $e->getCode(), + $this->l10n->t('%s', [$e->getMessage()]) + ); + } catch (ExtStorageTimeoutException $e) { + $storage->setStatus( + $e->getCode(), + $this->l10n->t('%s', [$e->getMessage()]) + ); + } catch (ExtStorageConnectionException $e) { + $storage->setStatus( + $e->getCode(), + $this->l10n->t('%s', [$e->getMessage()]) + ); } catch (\Exception $e) { // FIXME: convert storage exceptions to StorageNotAvailableException $storage->setStatus( diff --git a/lib/public/files/extstorageauthexception.php b/lib/public/files/extstorageauthexception.php new file mode 100644 index 0000000000..4f070b6c0e --- /dev/null +++ b/lib/public/files/extstorageauthexception.php @@ -0,0 +1,44 @@ + + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * External Storage authentication exception + * @since 9.0.0 + */ +class ExtStorageAuthException extends StorageNotAvailableException { + + /** + * ExtStorageAuthException constructor. + * + * @param string $message + * @param int $code + * @param \Exception $previous + * @since 9.0.0 + */ + public function __construct($message = '', $code, \Exception $previous = null) { + $l = \OC::$server->getL10N('core'); + parent::__construct($message, $l->t('External storage unauthorized'), 3, $previous); + } +} diff --git a/lib/public/files/extstoragebadconfigexception.php b/lib/public/files/extstoragebadconfigexception.php new file mode 100644 index 0000000000..869c2d1d13 --- /dev/null +++ b/lib/public/files/extstoragebadconfigexception.php @@ -0,0 +1,45 @@ + + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * External Storage has bad or missing config params + * @since 9.0.0 + */ +class ExtStorageBadConfigException extends StorageNotAvailableException { + + /** + * ExtStorageBadConfigException constructor. + * + * @param string $message + * @param int $code + * @param \Exception $previous + * @since 9.0.0 + */ + public function __construct($message = '', $code, \Exception $previous = null) { + $l = \OC::$server->getL10N('core'); + parent::__construct($message, $l->t('External storage incomplete configuration'), 2, $previous); + } + +} diff --git a/lib/public/files/extstorageconnectionexception.php b/lib/public/files/extstorageconnectionexception.php new file mode 100644 index 0000000000..472d5cd6c5 --- /dev/null +++ b/lib/public/files/extstorageconnectionexception.php @@ -0,0 +1,44 @@ + + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * External Storage authentication exception + * @since 9.0.0 + */ +class ExtStorageConnectionException extends StorageNotAvailableException { + + /** + * ExtStorageConnectionException constructor. + * + * @param string $message + * @param int $code + * @param \Exception $previous + * @since 9.0.0 + */ + public function __construct($message = '', $code, \Exception $previous = null) { + $l = \OC::$server->getL10N('core'); + parent::__construct($message, $l->t('External storage connection error'), 5, $previous); + } +} diff --git a/lib/public/files/extstoragetimeoutexception.php b/lib/public/files/extstoragetimeoutexception.php new file mode 100644 index 0000000000..99932776a8 --- /dev/null +++ b/lib/public/files/extstoragetimeoutexception.php @@ -0,0 +1,44 @@ + + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * External Storage authentication exception + * @since 9.0.0 + */ +class ExtStorageTimeoutException extends StorageNotAvailableException { + + /** + * ExtStorageTimeoutException constructor. + * + * @param string $message + * @param int $code + * @param \Exception $previous + * @since 9.0.0 + */ + public function __construct($message = '', $code, \Exception $previous = null) { + $l = \OC::$server->getL10N('core'); + parent::__construct($message, $l->t('External storage connection timeout'), 4, $previous); + } +} From 332c6748f9a96c8d718577605e6c061fdd8ba939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Macias?= Date: Wed, 25 Nov 2015 17:55:40 +0100 Subject: [PATCH 3/8] Delete unnecessary storage status constans --- apps/files_external/lib/config.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index bf50723303..1e96fac814 100644 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -52,10 +52,6 @@ class OC_Mount_Config { const STATUS_SUCCESS = 0; const STATUS_ERROR = 1; const STATUS_INDETERMINATE = 2; - const STATUS_INCOMPLETE_CONF = 3; - const STATUS_UNAUTHORIZED = 4; - const STATUS_TIMEOUT = 5; - const STATUS_NETWORK_ERROR = 6; // whether to skip backend test (for unit tests, as this static class is not mockable) public static $skipTest = false; From 9d1ec02c5ac72879a2b9b2e04917282c370526f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Macias?= Date: Wed, 25 Nov 2015 18:04:31 +0100 Subject: [PATCH 4/8] Change exception catch order --- apps/files_external/controller/storagescontroller.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/files_external/controller/storagescontroller.php b/apps/files_external/controller/storagescontroller.php index ddd7fe6df1..3f781ef655 100644 --- a/apps/files_external/controller/storagescontroller.php +++ b/apps/files_external/controller/storagescontroller.php @@ -241,11 +241,6 @@ abstract class StoragesController extends Controller { \OC_Mount_Config::STATUS_INDETERMINATE, $this->l10n->t('Insufficient data: %s', [$e->getMessage()]) ); - } catch (StorageNotAvailableException $e) { - $storage->setStatus( - \OC_Mount_Config::STATUS_ERROR, - $this->l10n->t('%s', [$e->getMessage()]) - ); } catch (ExtStorageBadConfigException $e) { $storage->setStatus( $e->getCode(), @@ -266,6 +261,11 @@ abstract class StoragesController extends Controller { $e->getCode(), $this->l10n->t('%s', [$e->getMessage()]) ); + } catch (StorageNotAvailableException $e) { + $storage->setStatus( + \OC_Mount_Config::STATUS_ERROR, + $this->l10n->t('%s', [$e->getMessage()]) + ); } catch (\Exception $e) { // FIXME: convert storage exceptions to StorageNotAvailableException $storage->setStatus( From 4ead2bc8610d11802c8814976bd80c544459235e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Macias?= Date: Thu, 26 Nov 2015 08:26:07 +0100 Subject: [PATCH 5/8] Fix code from PR comments --- .../controller/storagescontroller.php | 22 +------------------ lib/public/files/extstorageauthexception.php | 4 ++-- .../files/extstoragebadconfigexception.php | 4 ++-- .../files/extstorageconnectionexception.php | 4 ++-- .../files/extstoragetimeoutexception.php | 4 ++-- .../files/storagenotavailableexception.php | 5 +++++ 6 files changed, 14 insertions(+), 29 deletions(-) diff --git a/apps/files_external/controller/storagescontroller.php b/apps/files_external/controller/storagescontroller.php index 3f781ef655..76096f7665 100644 --- a/apps/files_external/controller/storagescontroller.php +++ b/apps/files_external/controller/storagescontroller.php @@ -241,29 +241,9 @@ abstract class StoragesController extends Controller { \OC_Mount_Config::STATUS_INDETERMINATE, $this->l10n->t('Insufficient data: %s', [$e->getMessage()]) ); - } catch (ExtStorageBadConfigException $e) { - $storage->setStatus( - $e->getCode(), - $this->l10n->t('%s', [$e->getMessage()]) - ); - } catch (ExtStorageAuthException $e) { - $storage->setStatus( - $e->getCode(), - $this->l10n->t('%s', [$e->getMessage()]) - ); - } catch (ExtStorageTimeoutException $e) { - $storage->setStatus( - $e->getCode(), - $this->l10n->t('%s', [$e->getMessage()]) - ); - } catch (ExtStorageConnectionException $e) { - $storage->setStatus( - $e->getCode(), - $this->l10n->t('%s', [$e->getMessage()]) - ); } catch (StorageNotAvailableException $e) { $storage->setStatus( - \OC_Mount_Config::STATUS_ERROR, + $e->getCode(), $this->l10n->t('%s', [$e->getMessage()]) ); } catch (\Exception $e) { diff --git a/lib/public/files/extstorageauthexception.php b/lib/public/files/extstorageauthexception.php index 4f070b6c0e..7e7e6f5caa 100644 --- a/lib/public/files/extstorageauthexception.php +++ b/lib/public/files/extstorageauthexception.php @@ -37,8 +37,8 @@ class ExtStorageAuthException extends StorageNotAvailableException { * @param \Exception $previous * @since 9.0.0 */ - public function __construct($message = '', $code, \Exception $previous = null) { + public function __construct($message = '', \Exception $previous = null) { $l = \OC::$server->getL10N('core'); - parent::__construct($message, $l->t('External storage unauthorized'), 3, $previous); + parent::__construct($l->t('External storage unauthorized. %s', $message), self::STATUS_UNAUTHORIZED, $previous); } } diff --git a/lib/public/files/extstoragebadconfigexception.php b/lib/public/files/extstoragebadconfigexception.php index 869c2d1d13..beb7ff32c8 100644 --- a/lib/public/files/extstoragebadconfigexception.php +++ b/lib/public/files/extstoragebadconfigexception.php @@ -37,9 +37,9 @@ class ExtStorageBadConfigException extends StorageNotAvailableException { * @param \Exception $previous * @since 9.0.0 */ - public function __construct($message = '', $code, \Exception $previous = null) { + public function __construct($message = '', \Exception $previous = null) { $l = \OC::$server->getL10N('core'); - parent::__construct($message, $l->t('External storage incomplete configuration'), 2, $previous); + parent::__construct($l->t('External storage incomplete configuration. %s', $message), self::STATUS_INCOMPLETE_CONF, $previous); } } diff --git a/lib/public/files/extstorageconnectionexception.php b/lib/public/files/extstorageconnectionexception.php index 472d5cd6c5..96d2551dda 100644 --- a/lib/public/files/extstorageconnectionexception.php +++ b/lib/public/files/extstorageconnectionexception.php @@ -37,8 +37,8 @@ class ExtStorageConnectionException extends StorageNotAvailableException { * @param \Exception $previous * @since 9.0.0 */ - public function __construct($message = '', $code, \Exception $previous = null) { + public function __construct($message = '', \Exception $previous = null) { $l = \OC::$server->getL10N('core'); - parent::__construct($message, $l->t('External storage connection error'), 5, $previous); + parent::__construct($l->t('External storage connection error. %s', $message), self::STATUS_NETWORK_ERROR, $previous); } } diff --git a/lib/public/files/extstoragetimeoutexception.php b/lib/public/files/extstoragetimeoutexception.php index 99932776a8..208f752143 100644 --- a/lib/public/files/extstoragetimeoutexception.php +++ b/lib/public/files/extstoragetimeoutexception.php @@ -37,8 +37,8 @@ class ExtStorageTimeoutException extends StorageNotAvailableException { * @param \Exception $previous * @since 9.0.0 */ - public function __construct($message = '', $code, \Exception $previous = null) { + public function __construct($message = '', \Exception $previous = null) { $l = \OC::$server->getL10N('core'); - parent::__construct($message, $l->t('External storage connection timeout'), 4, $previous); + parent::__construct($l->t('External storage connection timeout. %s', $message), self::STATUS_TIMEOUT, $previous); } } diff --git a/lib/public/files/storagenotavailableexception.php b/lib/public/files/storagenotavailableexception.php index a6665b38ce..fe270e76b4 100644 --- a/lib/public/files/storagenotavailableexception.php +++ b/lib/public/files/storagenotavailableexception.php @@ -37,6 +37,11 @@ use OC\HintException; */ class StorageNotAvailableException extends HintException { + const STATUS_INCOMPLETE_CONF = 3; + const STATUS_UNAUTHORIZED = 4; + const STATUS_TIMEOUT = 5; + const STATUS_NETWORK_ERROR = 6; + /** * StorageNotAvailableException constructor. * From 98f5c50aa47207d98d99dde97f56204ef53d066c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Macias?= Date: Thu, 26 Nov 2015 17:51:47 +0100 Subject: [PATCH 6/8] Migrate storate status code to storagenotavailablexception --- .../files_external/controller/storagescontroller.php | 5 +++-- apps/files_external/lib/config.php | 12 ++++-------- apps/files_external/service/storagesservice.php | 3 ++- lib/public/files/storagenotavailableexception.php | 3 +++ 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/apps/files_external/controller/storagescontroller.php b/apps/files_external/controller/storagescontroller.php index 76096f7665..da17f76cc6 100644 --- a/apps/files_external/controller/storagescontroller.php +++ b/apps/files_external/controller/storagescontroller.php @@ -38,6 +38,7 @@ use \OCA\Files_External\Lib\Auth\AuthMechanism; use \OCP\Files\StorageNotAvailableException; use \OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException; use \OCA\Files_External\Service\BackendService; +use \OCP\Files\StorageNotAvailableException; /** * Base class for storages controllers @@ -238,7 +239,7 @@ abstract class StoragesController extends Controller { ); } catch (InsufficientDataForMeaningfulAnswerException $e) { $storage->setStatus( - \OC_Mount_Config::STATUS_INDETERMINATE, + StorageNotAvailableException::STATUS_INDETERMINATE, $this->l10n->t('Insufficient data: %s', [$e->getMessage()]) ); } catch (StorageNotAvailableException $e) { @@ -249,7 +250,7 @@ abstract class StoragesController extends Controller { } catch (\Exception $e) { // FIXME: convert storage exceptions to StorageNotAvailableException $storage->setStatus( - \OC_Mount_Config::STATUS_ERROR, + StorageNotAvailableException::STATUS_ERROR, get_class($e).': '.$e->getMessage() ); } diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 1e96fac814..7a869847a6 100644 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -36,6 +36,7 @@ use \OCA\Files_External\Appinfo\Application; use \OCA\Files_External\Lib\Backend\LegacyBackend; use \OCA\Files_External\Lib\StorageConfig; use \OCA\Files_External\Lib\Backend\Backend; +use \OCP\Files\StorageNotAvailableException; /** * Class to configure mount.json globally and for users @@ -48,11 +49,6 @@ class OC_Mount_Config { const MOUNT_TYPE_USER = 'user'; const MOUNT_TYPE_PERSONAL = 'personal'; - // getBackendStatus return types - const STATUS_SUCCESS = 0; - const STATUS_ERROR = 1; - const STATUS_INDETERMINATE = 2; - // whether to skip backend test (for unit tests, as this static class is not mockable) public static $skipTest = false; @@ -219,7 +215,7 @@ class OC_Mount_Config { */ public static function getBackendStatus($class, $options, $isPersonal) { if (self::$skipTest) { - return self::STATUS_SUCCESS; + return StorageNotAvailableException::STATUS_SUCCESS; } foreach ($options as &$option) { $option = self::setUserVars(OCP\User::getUser(), $option); @@ -233,7 +229,7 @@ class OC_Mount_Config { $result = $storage->test($isPersonal); $storage->setAvailability($result); if ($result) { - return self::STATUS_SUCCESS; + return StorageNotAvailableException::STATUS_SUCCESS; } } catch (\Exception $e) { $storage->setAvailability(false); @@ -244,7 +240,7 @@ class OC_Mount_Config { throw $exception; } } - return self::STATUS_ERROR; + return StorageNotAvailableException::STATUS_ERROR; } /** diff --git a/apps/files_external/service/storagesservice.php b/apps/files_external/service/storagesservice.php index 3446ed0dab..c847930ba2 100644 --- a/apps/files_external/service/storagesservice.php +++ b/apps/files_external/service/storagesservice.php @@ -31,6 +31,7 @@ use \OCA\Files_external\NotFoundException; use \OCA\Files_External\Service\BackendService; use \OCA\Files_External\Lib\Backend\Backend; use \OCA\Files_External\Lib\Auth\AuthMechanism; +use \OCP\Files\StorageNotAvailableException; /** * Service class to manage external storages @@ -411,7 +412,7 @@ abstract class StoragesService { $this->triggerHooks($newStorage, Filesystem::signal_create_mount); - $newStorage->setStatus(\OC_Mount_Config::STATUS_SUCCESS); + $newStorage->setStatus(StorageNotAvailableException::STATUS_SUCCESS); return $newStorage; } diff --git a/lib/public/files/storagenotavailableexception.php b/lib/public/files/storagenotavailableexception.php index fe270e76b4..323f5d9b7f 100644 --- a/lib/public/files/storagenotavailableexception.php +++ b/lib/public/files/storagenotavailableexception.php @@ -37,6 +37,9 @@ use OC\HintException; */ class StorageNotAvailableException extends HintException { + const STATUS_SUCCESS = 0; + const STATUS_ERROR = 1; + const STATUS_INDETERMINATE = 2; const STATUS_INCOMPLETE_CONF = 3; const STATUS_UNAUTHORIZED = 4; const STATUS_TIMEOUT = 5; From f4f53e328dbf2c4cc002c0796a60d214746b8f55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Macias?= Date: Tue, 1 Dec 2015 12:54:32 +0100 Subject: [PATCH 7/8] Fix duplicate use in storage controller --- apps/files_external/controller/storagescontroller.php | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/files_external/controller/storagescontroller.php b/apps/files_external/controller/storagescontroller.php index da17f76cc6..7712f9769c 100644 --- a/apps/files_external/controller/storagescontroller.php +++ b/apps/files_external/controller/storagescontroller.php @@ -38,7 +38,6 @@ use \OCA\Files_External\Lib\Auth\AuthMechanism; use \OCP\Files\StorageNotAvailableException; use \OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException; use \OCA\Files_External\Service\BackendService; -use \OCP\Files\StorageNotAvailableException; /** * Base class for storages controllers From 9dd11091d4f9a970a3e76d77e772b5905666ed30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Macias?= Date: Tue, 1 Dec 2015 17:27:06 +0100 Subject: [PATCH 8/8] Fix code from comments --- ...nnectionexception.php => storageauthexception.php} | 11 ++++------- ...figexception.php => storagebadconfigexception.php} | 9 +++------ ...utexception.php => storageconnectionexception.php} | 11 ++++------- ...eauthexception.php => storagetimeoutexception.php} | 11 ++++------- 4 files changed, 15 insertions(+), 27 deletions(-) rename lib/public/files/{extstorageconnectionexception.php => storageauthexception.php} (69%) rename lib/public/files/{extstoragebadconfigexception.php => storagebadconfigexception.php} (72%) rename lib/public/files/{extstoragetimeoutexception.php => storageconnectionexception.php} (70%) rename lib/public/files/{extstorageauthexception.php => storagetimeoutexception.php} (71%) diff --git a/lib/public/files/extstorageconnectionexception.php b/lib/public/files/storageauthexception.php similarity index 69% rename from lib/public/files/extstorageconnectionexception.php rename to lib/public/files/storageauthexception.php index 96d2551dda..6b49065038 100644 --- a/lib/public/files/extstorageconnectionexception.php +++ b/lib/public/files/storageauthexception.php @@ -18,19 +18,16 @@ * along with this program. If not, see * */ - -// use OCP namespace for all classes that are considered public. -// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP\Files; /** - * External Storage authentication exception + * Storage authentication exception * @since 9.0.0 */ -class ExtStorageConnectionException extends StorageNotAvailableException { +class StorageAuthException extends StorageNotAvailableException { /** - * ExtStorageConnectionException constructor. + * StorageAuthException constructor. * * @param string $message * @param int $code @@ -39,6 +36,6 @@ class ExtStorageConnectionException extends StorageNotAvailableException { */ public function __construct($message = '', \Exception $previous = null) { $l = \OC::$server->getL10N('core'); - parent::__construct($l->t('External storage connection error. %s', $message), self::STATUS_NETWORK_ERROR, $previous); + parent::__construct($l->t('Storage unauthorized. %s', $message), self::STATUS_UNAUTHORIZED, $previous); } } diff --git a/lib/public/files/extstoragebadconfigexception.php b/lib/public/files/storagebadconfigexception.php similarity index 72% rename from lib/public/files/extstoragebadconfigexception.php rename to lib/public/files/storagebadconfigexception.php index beb7ff32c8..d72ad3358e 100644 --- a/lib/public/files/extstoragebadconfigexception.php +++ b/lib/public/files/storagebadconfigexception.php @@ -18,16 +18,13 @@ * along with this program. If not, see * */ - -// use OCP namespace for all classes that are considered public. -// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP\Files; /** - * External Storage has bad or missing config params + * Storage has bad or missing config params * @since 9.0.0 */ -class ExtStorageBadConfigException extends StorageNotAvailableException { +class StorageBadConfigException extends StorageNotAvailableException { /** * ExtStorageBadConfigException constructor. @@ -39,7 +36,7 @@ class ExtStorageBadConfigException extends StorageNotAvailableException { */ public function __construct($message = '', \Exception $previous = null) { $l = \OC::$server->getL10N('core'); - parent::__construct($l->t('External storage incomplete configuration. %s', $message), self::STATUS_INCOMPLETE_CONF, $previous); + parent::__construct($l->t('Storage incomplete configuration. %s', $message), self::STATUS_INCOMPLETE_CONF, $previous); } } diff --git a/lib/public/files/extstoragetimeoutexception.php b/lib/public/files/storageconnectionexception.php similarity index 70% rename from lib/public/files/extstoragetimeoutexception.php rename to lib/public/files/storageconnectionexception.php index 208f752143..c17367046e 100644 --- a/lib/public/files/extstoragetimeoutexception.php +++ b/lib/public/files/storageconnectionexception.php @@ -18,19 +18,16 @@ * along with this program. If not, see * */ - -// use OCP namespace for all classes that are considered public. -// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP\Files; /** - * External Storage authentication exception + * Storage authentication exception * @since 9.0.0 */ -class ExtStorageTimeoutException extends StorageNotAvailableException { +class StorageConnectionException extends StorageNotAvailableException { /** - * ExtStorageTimeoutException constructor. + * StorageConnectionException constructor. * * @param string $message * @param int $code @@ -39,6 +36,6 @@ class ExtStorageTimeoutException extends StorageNotAvailableException { */ public function __construct($message = '', \Exception $previous = null) { $l = \OC::$server->getL10N('core'); - parent::__construct($l->t('External storage connection timeout. %s', $message), self::STATUS_TIMEOUT, $previous); + parent::__construct($l->t('Storage connection error. %s', $message), self::STATUS_NETWORK_ERROR, $previous); } } diff --git a/lib/public/files/extstorageauthexception.php b/lib/public/files/storagetimeoutexception.php similarity index 71% rename from lib/public/files/extstorageauthexception.php rename to lib/public/files/storagetimeoutexception.php index 7e7e6f5caa..c6682604b6 100644 --- a/lib/public/files/extstorageauthexception.php +++ b/lib/public/files/storagetimeoutexception.php @@ -18,19 +18,16 @@ * along with this program. If not, see * */ - -// use OCP namespace for all classes that are considered public. -// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP\Files; /** - * External Storage authentication exception + * Storage authentication exception * @since 9.0.0 */ -class ExtStorageAuthException extends StorageNotAvailableException { +class StorageTimeoutException extends StorageNotAvailableException { /** - * ExtStorageAuthException constructor. + * StorageTimeoutException constructor. * * @param string $message * @param int $code @@ -39,6 +36,6 @@ class ExtStorageAuthException extends StorageNotAvailableException { */ public function __construct($message = '', \Exception $previous = null) { $l = \OC::$server->getL10N('core'); - parent::__construct($l->t('External storage unauthorized. %s', $message), self::STATUS_UNAUTHORIZED, $previous); + parent::__construct($l->t('Storage connection timeout. %s', $message), self::STATUS_TIMEOUT, $previous); } }