Introduce InvalidClassStorageException and adapt the code for it

This commit is contained in:
Philipp 2021-08-10 23:56:30 +02:00
parent b798ca2da6
commit c17bc55158
No known key found for this signature in database
GPG key ID: 9A28B7D4FF5667BD
9 changed files with 259 additions and 267 deletions

View file

@ -23,6 +23,7 @@ namespace Friendica\Console;
use Asika\SimpleConsole\CommandArgsException;
use Friendica\Core\StorageManager;
use Friendica\Model\Storage\ReferenceStorageException;
use Friendica\Model\Storage\StorageException;
/**
@ -127,23 +128,23 @@ HELP;
protected function doSet()
{
if (count($this->args) !== 2) {
if (count($this->args) !== 2 || empty($this->args[1])) {
throw new CommandArgsException('Invalid arguments');
}
$name = $this->args[1];
$class = $this->storageManager->getWritableStorageByName($name);
$name = $this->args[1];
try {
$class = $this->storageManager->getWritableStorageByName($name);
if (is_null($class)) {
if (!$this->storageManager->setBackend($class)) {
$this->out($class . ' is not a valid backend storage class.');
return -1;
}
} catch (ReferenceStorageException $exception) {
$this->out($name . ' is not a registered backend.');
return -1;
}
if (!$this->storageManager->setBackend($class)) {
$this->out($class . ' is not a valid backend storage class.');
return -1;
}
return 0;
}