Rename ISelectableStorage to IWritableStorage
This commit is contained in:
parent
eb035771f1
commit
d0536ebea7
16 changed files with 64 additions and 63 deletions
|
@ -132,7 +132,7 @@ HELP;
|
|||
}
|
||||
|
||||
$name = $this->args[1];
|
||||
$class = $this->storageManager->getSelectableStorageByName($name);
|
||||
$class = $this->storageManager->getWritableStorageByName($name);
|
||||
|
||||
if (is_null($class)) {
|
||||
$this->out($name . ' is not a registered backend.');
|
||||
|
|
|
@ -82,13 +82,13 @@ class StorageManager
|
|||
$currentName = $this->config->get('storage', 'name', '');
|
||||
|
||||
// you can only use user backends as a "default" backend, so the second parameter is true
|
||||
$this->currentBackend = $this->getSelectableStorageByName($currentName);
|
||||
$this->currentBackend = $this->getWritableStorageByName($currentName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current storage backend class
|
||||
*
|
||||
* @return Storage\ISelectableStorage|null
|
||||
* @return Storage\IWritableStorage|null
|
||||
*/
|
||||
public function getBackend()
|
||||
{
|
||||
|
@ -96,16 +96,16 @@ class StorageManager
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a selectable storage backend class by registered name
|
||||
* Returns a writable storage backend class by registered name
|
||||
*
|
||||
* @param string $name Backend name
|
||||
*
|
||||
* @return Storage\ISelectableStorage
|
||||
* @return Storage\IWritableStorage
|
||||
*
|
||||
* @throws Storage\ReferenceStorageException in case there's no backend class for the name
|
||||
* @throws Storage\StorageException in case of an unexpected failure during the hook call
|
||||
*/
|
||||
public function getSelectableStorageByName(string $name = null)
|
||||
public function getWritableStorageByName(string $name = null)
|
||||
{
|
||||
// @todo 2020.09 Remove this call after 2 releases
|
||||
$name = $this->checkLegacyBackend($name);
|
||||
|
@ -130,7 +130,7 @@ class StorageManager
|
|||
];
|
||||
try {
|
||||
Hook::callAll('storage_instance', $data);
|
||||
if (($data['storage'] ?? null) instanceof Storage\ISelectableStorage) {
|
||||
if (($data['storage'] ?? null) instanceof Storage\IWritableStorage) {
|
||||
$this->backendInstances[$data['name'] ?? $name] = $data['storage'];
|
||||
} else {
|
||||
throw new Storage\ReferenceStorageException(sprintf('Backend %s was not found', $name));
|
||||
|
@ -244,11 +244,11 @@ class StorageManager
|
|||
/**
|
||||
* Set current storage backend class
|
||||
*
|
||||
* @param Storage\ISelectableStorage $storage The storage class
|
||||
* @param Storage\IWritableStorage $storage The storage class
|
||||
*
|
||||
* @return boolean True, if the set was successful
|
||||
*/
|
||||
public function setBackend(Storage\ISelectableStorage $storage)
|
||||
public function setBackend(Storage\IWritableStorage $storage)
|
||||
{
|
||||
if ($this->config->set('storage', 'name', $storage::getName())) {
|
||||
$this->currentBackend = $storage;
|
||||
|
@ -327,15 +327,15 @@ class StorageManager
|
|||
* Copy existing data to destination storage and delete from source.
|
||||
* This method cannot move to legacy in-table `data` field.
|
||||
*
|
||||
* @param Storage\ISelectableStorage $destination Destination storage class name
|
||||
* @param array $tables Tables to look in for resources. Optional, defaults to ['photo', 'attach']
|
||||
* @param int $limit Limit of the process batch size, defaults to 5000
|
||||
* @param Storage\IWritableStorage $destination Destination storage class name
|
||||
* @param array $tables Tables to look in for resources. Optional, defaults to ['photo', 'attach']
|
||||
* @param int $limit Limit of the process batch size, defaults to 5000
|
||||
*
|
||||
* @return int Number of moved resources
|
||||
* @throws Storage\StorageException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function move(Storage\ISelectableStorage $destination, array $tables = self::TABLES, int $limit = 5000)
|
||||
public function move(Storage\IWritableStorage $destination, array $tables = self::TABLES, int $limit = 5000)
|
||||
{
|
||||
if (!$this->isValidBackend($destination, true)) {
|
||||
throw new Storage\StorageException(sprintf("Can't move to storage backend '%s'", $destination::getName()));
|
||||
|
@ -354,7 +354,7 @@ class StorageManager
|
|||
while ($resource = $this->dba->fetch($resources)) {
|
||||
$id = $resource['id'];
|
||||
$data = $resource['data'];
|
||||
$source = $this->getSelectableStorageByName($resource['backend-class']);
|
||||
$source = $this->getWritableStorageByName($resource['backend-class']);
|
||||
$sourceRef = $resource['backend-ref'];
|
||||
|
||||
if (!empty($source)) {
|
||||
|
|
|
@ -387,11 +387,11 @@ abstract class DI
|
|||
}
|
||||
|
||||
/**
|
||||
* @return Model\Storage\ISelectableStorage
|
||||
* @return Model\Storage\IWritableStorage
|
||||
*/
|
||||
public static function storage()
|
||||
{
|
||||
return self::$dice->create(Model\Storage\ISelectableStorage::class);
|
||||
return self::$dice->create(Model\Storage\IWritableStorage::class);
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -284,7 +284,7 @@ class Attach
|
|||
$items = self::selectToArray(['backend-class','backend-ref'], $conditions);
|
||||
|
||||
foreach($items as $item) {
|
||||
$backend_class = DI::storageManager()->getSelectableStorageByName($item['backend-class'] ?? '');
|
||||
$backend_class = DI::storageManager()->getWritableStorageByName($item['backend-class'] ?? '');
|
||||
if (!empty($backend_class)) {
|
||||
$fields['backend-ref'] = $backend_class->put($img->asString(), $item['backend-ref'] ?? '');
|
||||
} else {
|
||||
|
@ -316,7 +316,7 @@ class Attach
|
|||
$items = self::selectToArray(['backend-class','backend-ref'], $conditions);
|
||||
|
||||
foreach($items as $item) {
|
||||
$backend_class = DI::storageManager()->getSelectableStorageByName($item['backend-class'] ?? '');
|
||||
$backend_class = DI::storageManager()->getWritableStorageByName($item['backend-class'] ?? '');
|
||||
if (!empty($backend_class)) {
|
||||
try {
|
||||
$backend_class->delete($item['backend-ref'] ?? '');
|
||||
|
|
|
@ -347,7 +347,7 @@ class Photo
|
|||
|
||||
if (DBA::isResult($existing_photo)) {
|
||||
$backend_ref = (string)$existing_photo["backend-ref"];
|
||||
$storage = DI::storageManager()->getSelectableStorageByName($existing_photo["backend-class"] ?? '');
|
||||
$storage = DI::storageManager()->getWritableStorageByName($existing_photo["backend-class"] ?? '');
|
||||
} else {
|
||||
$storage = DI::storage();
|
||||
}
|
||||
|
@ -411,7 +411,7 @@ class Photo
|
|||
$photos = DBA::select('photo', ['id', 'backend-class', 'backend-ref'], $conditions);
|
||||
|
||||
while ($photo = DBA::fetch($photos)) {
|
||||
$backend_class = DI::storageManager()->getSelectableStorageByName($photo['backend-class'] ?? '');
|
||||
$backend_class = DI::storageManager()->getWritableStorageByName($photo['backend-class'] ?? '');
|
||||
if (!empty($backend_class)) {
|
||||
try {
|
||||
$backend_class->delete($item['backend-ref'] ?? '');
|
||||
|
@ -448,7 +448,7 @@ class Photo
|
|||
$photos = self::selectToArray(['backend-class', 'backend-ref'], $conditions);
|
||||
|
||||
foreach($photos as $photo) {
|
||||
$backend_class = DI::storageManager()->getSelectableStorageByName($photo['backend-class'] ?? '');
|
||||
$backend_class = DI::storageManager()->getWritableStorageByName($photo['backend-class'] ?? '');
|
||||
if (!empty($backend_class)) {
|
||||
$fields["backend-ref"] = $backend_class->put($img->asString(), $photo['backend-ref']);
|
||||
} else {
|
||||
|
|
|
@ -29,7 +29,7 @@ use Friendica\Database\Database as DBA;
|
|||
*
|
||||
* This class manage data stored in database table.
|
||||
*/
|
||||
class Database implements ISelectableStorage
|
||||
class Database implements IWritableStorage
|
||||
{
|
||||
const NAME = 'Database';
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ use Friendica\Util\Strings;
|
|||
* Each new resource gets a value as reference and is saved in a
|
||||
* folder tree stucture created from that value.
|
||||
*/
|
||||
class Filesystem implements ISelectableStorage
|
||||
class Filesystem implements IWritableStorage
|
||||
{
|
||||
const NAME = 'Filesystem';
|
||||
|
||||
|
|
|
@ -22,12 +22,12 @@
|
|||
namespace Friendica\Model\Storage;
|
||||
|
||||
/**
|
||||
* Interface for selectable storage backends
|
||||
* Interface for writable storage backends
|
||||
*
|
||||
* Used for storages with CRUD functionality, mainly used for user data (e.g. photos, attachements).
|
||||
* There's only one active, selectable storage possible and can be selected by the current administrator
|
||||
* There's only one active, writable storage possible. This type of storages are selectable by the current administrator
|
||||
*/
|
||||
interface ISelectableStorage extends IStorage
|
||||
interface IWritableStorage extends IStorage
|
||||
{
|
||||
/**
|
||||
* Put data in backend as $ref. If $ref is not defined a new reference is created.
|
|
@ -23,7 +23,7 @@ namespace Friendica\Module\Admin;
|
|||
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Storage\ISelectableStorage;
|
||||
use Friendica\Model\Storage\IWritableStorage;
|
||||
use Friendica\Module\BaseAdmin;
|
||||
use Friendica\Util\Strings;
|
||||
|
||||
|
@ -37,8 +37,8 @@ class Storage extends BaseAdmin
|
|||
|
||||
$storagebackend = Strings::escapeTags(trim($parameters['name'] ?? ''));
|
||||
|
||||
/** @var ISelectableStorage $newstorage */
|
||||
$newstorage = DI::storageManager()->getSelectableStorageByName($storagebackend);
|
||||
/** @var IWritableStorage $newstorage */
|
||||
$newstorage = DI::storageManager()->getWritableStorageByName($storagebackend);
|
||||
|
||||
// save storage backend form
|
||||
$storage_opts = $newstorage->getOptions();
|
||||
|
@ -68,8 +68,8 @@ class Storage extends BaseAdmin
|
|||
}
|
||||
|
||||
if (!empty($_POST['submit_save_set'])) {
|
||||
/** @var ISelectableStorage $newstorage */
|
||||
$newstorage = DI::storageManager()->getSelectableStorageByName($storagebackend);
|
||||
/** @var IWritableStorage $newstorage */
|
||||
$newstorage = DI::storageManager()->getWritableStorageByName($storagebackend);
|
||||
|
||||
if (!DI::storageManager()->setBackend($newstorage)) {
|
||||
notice(DI::l10n()->t('Invalid storage backend setting value.'));
|
||||
|
@ -92,7 +92,7 @@ class Storage extends BaseAdmin
|
|||
$storage_form_prefix = preg_replace('|[^a-zA-Z0-9]|', '', $name);
|
||||
|
||||
$storage_form = [];
|
||||
foreach (DI::storageManager()->getSelectableStorageByName($name)->getOptions() as $option => $info) {
|
||||
foreach (DI::storageManager()->getWritableStorageByName($name)->getOptions() as $option => $info) {
|
||||
$type = $info[0];
|
||||
// Backward compatibilty with yesno field description
|
||||
if ($type == 'yesno') {
|
||||
|
@ -111,7 +111,7 @@ class Storage extends BaseAdmin
|
|||
'name' => $name,
|
||||
'prefix' => $storage_form_prefix,
|
||||
'form' => $storage_form,
|
||||
'active' => $current_storage_backend instanceof ISelectableStorage && $name === $current_storage_backend::getName(),
|
||||
'active' => $current_storage_backend instanceof IWritableStorage && $name === $current_storage_backend::getName(),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -127,7 +127,7 @@ class Storage extends BaseAdmin
|
|||
'$noconfig' => DI::l10n()->t('This backend doesn\'t have custom settings'),
|
||||
'$baseurl' => DI::baseUrl()->get(true),
|
||||
'$form_security_token' => self::getFormSecurityToken("admin_storage"),
|
||||
'$storagebackend' => $current_storage_backend instanceof ISelectableStorage ? $current_storage_backend::getName() : DI::l10n()->t('Database (legacy)'),
|
||||
'$storagebackend' => $current_storage_backend instanceof IWritableStorage ? $current_storage_backend::getName() : DI::l10n()->t('Database (legacy)'),
|
||||
'$availablestorageforms' => $available_storage_forms,
|
||||
]);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue