Merge pull request #20729 from owncloud/issue_20599
Add different storage status error codes managed by StoragedNotAvailableExc…
This commit is contained in:
commit
e62b6c1617
|
@ -238,18 +238,18 @@ abstract class StoragesController extends Controller {
|
||||||
);
|
);
|
||||||
} catch (InsufficientDataForMeaningfulAnswerException $e) {
|
} catch (InsufficientDataForMeaningfulAnswerException $e) {
|
||||||
$storage->setStatus(
|
$storage->setStatus(
|
||||||
\OC_Mount_Config::STATUS_INDETERMINATE,
|
StorageNotAvailableException::STATUS_INDETERMINATE,
|
||||||
$this->l10n->t('Insufficient data: %s', [$e->getMessage()])
|
$this->l10n->t('Insufficient data: %s', [$e->getMessage()])
|
||||||
);
|
);
|
||||||
} catch (StorageNotAvailableException $e) {
|
} catch (StorageNotAvailableException $e) {
|
||||||
$storage->setStatus(
|
$storage->setStatus(
|
||||||
\OC_Mount_Config::STATUS_ERROR,
|
$e->getCode(),
|
||||||
$e->getMessage()
|
$this->l10n->t('%s', [$e->getMessage()])
|
||||||
);
|
);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
// FIXME: convert storage exceptions to StorageNotAvailableException
|
// FIXME: convert storage exceptions to StorageNotAvailableException
|
||||||
$storage->setStatus(
|
$storage->setStatus(
|
||||||
\OC_Mount_Config::STATUS_ERROR,
|
StorageNotAvailableException::STATUS_ERROR,
|
||||||
get_class($e).': '.$e->getMessage()
|
get_class($e).': '.$e->getMessage()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ use \OCA\Files_External\Appinfo\Application;
|
||||||
use \OCA\Files_External\Lib\Backend\LegacyBackend;
|
use \OCA\Files_External\Lib\Backend\LegacyBackend;
|
||||||
use \OCA\Files_External\Lib\StorageConfig;
|
use \OCA\Files_External\Lib\StorageConfig;
|
||||||
use \OCA\Files_External\Lib\Backend\Backend;
|
use \OCA\Files_External\Lib\Backend\Backend;
|
||||||
|
use \OCP\Files\StorageNotAvailableException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to configure mount.json globally and for users
|
* 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_USER = 'user';
|
||||||
const MOUNT_TYPE_PERSONAL = 'personal';
|
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)
|
// whether to skip backend test (for unit tests, as this static class is not mockable)
|
||||||
public static $skipTest = false;
|
public static $skipTest = false;
|
||||||
|
|
||||||
|
@ -219,7 +215,7 @@ class OC_Mount_Config {
|
||||||
*/
|
*/
|
||||||
public static function getBackendStatus($class, $options, $isPersonal) {
|
public static function getBackendStatus($class, $options, $isPersonal) {
|
||||||
if (self::$skipTest) {
|
if (self::$skipTest) {
|
||||||
return self::STATUS_SUCCESS;
|
return StorageNotAvailableException::STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
foreach ($options as &$option) {
|
foreach ($options as &$option) {
|
||||||
$option = self::setUserVars(OCP\User::getUser(), $option);
|
$option = self::setUserVars(OCP\User::getUser(), $option);
|
||||||
|
@ -233,7 +229,7 @@ class OC_Mount_Config {
|
||||||
$result = $storage->test($isPersonal);
|
$result = $storage->test($isPersonal);
|
||||||
$storage->setAvailability($result);
|
$storage->setAvailability($result);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return self::STATUS_SUCCESS;
|
return StorageNotAvailableException::STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$storage->setAvailability(false);
|
$storage->setAvailability(false);
|
||||||
|
@ -244,7 +240,7 @@ class OC_Mount_Config {
|
||||||
throw $exception;
|
throw $exception;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return self::STATUS_ERROR;
|
return StorageNotAvailableException::STATUS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -31,6 +31,7 @@ use \OCA\Files_external\NotFoundException;
|
||||||
use \OCA\Files_External\Service\BackendService;
|
use \OCA\Files_External\Service\BackendService;
|
||||||
use \OCA\Files_External\Lib\Backend\Backend;
|
use \OCA\Files_External\Lib\Backend\Backend;
|
||||||
use \OCA\Files_External\Lib\Auth\AuthMechanism;
|
use \OCA\Files_External\Lib\Auth\AuthMechanism;
|
||||||
|
use \OCP\Files\StorageNotAvailableException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service class to manage external storages
|
* Service class to manage external storages
|
||||||
|
@ -411,7 +412,7 @@ abstract class StoragesService {
|
||||||
|
|
||||||
$this->triggerHooks($newStorage, Filesystem::signal_create_mount);
|
$this->triggerHooks($newStorage, Filesystem::signal_create_mount);
|
||||||
|
|
||||||
$newStorage->setStatus(\OC_Mount_Config::STATUS_SUCCESS);
|
$newStorage->setStatus(StorageNotAvailableException::STATUS_SUCCESS);
|
||||||
return $newStorage;
|
return $newStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Jesus Macias <jesus@owncloud.com>
|
||||||
|
*
|
||||||
|
* @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 <http://www.gnu.org/licenses/>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
namespace OCP\Files;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Storage authentication exception
|
||||||
|
* @since 9.0.0
|
||||||
|
*/
|
||||||
|
class StorageAuthException extends StorageNotAvailableException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StorageAuthException constructor.
|
||||||
|
*
|
||||||
|
* @param string $message
|
||||||
|
* @param int $code
|
||||||
|
* @param \Exception $previous
|
||||||
|
* @since 9.0.0
|
||||||
|
*/
|
||||||
|
public function __construct($message = '', \Exception $previous = null) {
|
||||||
|
$l = \OC::$server->getL10N('core');
|
||||||
|
parent::__construct($l->t('Storage unauthorized. %s', $message), self::STATUS_UNAUTHORIZED, $previous);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Jesus Macias <jesus@owncloud.com>
|
||||||
|
*
|
||||||
|
* @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 <http://www.gnu.org/licenses/>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
namespace OCP\Files;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Storage has bad or missing config params
|
||||||
|
* @since 9.0.0
|
||||||
|
*/
|
||||||
|
class StorageBadConfigException extends StorageNotAvailableException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ExtStorageBadConfigException constructor.
|
||||||
|
*
|
||||||
|
* @param string $message
|
||||||
|
* @param int $code
|
||||||
|
* @param \Exception $previous
|
||||||
|
* @since 9.0.0
|
||||||
|
*/
|
||||||
|
public function __construct($message = '', \Exception $previous = null) {
|
||||||
|
$l = \OC::$server->getL10N('core');
|
||||||
|
parent::__construct($l->t('Storage incomplete configuration. %s', $message), self::STATUS_INCOMPLETE_CONF, $previous);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Jesus Macias <jesus@owncloud.com>
|
||||||
|
*
|
||||||
|
* @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 <http://www.gnu.org/licenses/>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
namespace OCP\Files;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Storage authentication exception
|
||||||
|
* @since 9.0.0
|
||||||
|
*/
|
||||||
|
class StorageConnectionException extends StorageNotAvailableException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StorageConnectionException constructor.
|
||||||
|
*
|
||||||
|
* @param string $message
|
||||||
|
* @param int $code
|
||||||
|
* @param \Exception $previous
|
||||||
|
* @since 9.0.0
|
||||||
|
*/
|
||||||
|
public function __construct($message = '', \Exception $previous = null) {
|
||||||
|
$l = \OC::$server->getL10N('core');
|
||||||
|
parent::__construct($l->t('Storage connection error. %s', $message), self::STATUS_NETWORK_ERROR, $previous);
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,6 +37,14 @@ use OC\HintException;
|
||||||
*/
|
*/
|
||||||
class StorageNotAvailableException extends 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;
|
||||||
|
const STATUS_NETWORK_ERROR = 6;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StorageNotAvailableException constructor.
|
* StorageNotAvailableException constructor.
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Jesus Macias <jesus@owncloud.com>
|
||||||
|
*
|
||||||
|
* @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 <http://www.gnu.org/licenses/>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
namespace OCP\Files;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Storage authentication exception
|
||||||
|
* @since 9.0.0
|
||||||
|
*/
|
||||||
|
class StorageTimeoutException extends StorageNotAvailableException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StorageTimeoutException constructor.
|
||||||
|
*
|
||||||
|
* @param string $message
|
||||||
|
* @param int $code
|
||||||
|
* @param \Exception $previous
|
||||||
|
* @since 9.0.0
|
||||||
|
*/
|
||||||
|
public function __construct($message = '', \Exception $previous = null) {
|
||||||
|
$l = \OC::$server->getL10N('core');
|
||||||
|
parent::__construct($l->t('Storage connection timeout. %s', $message), self::STATUS_TIMEOUT, $previous);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue