Rename ISelectableStorage to IWritableStorage
This commit is contained in:
parent
eb035771f1
commit
d0536ebea7
|
@ -10,12 +10,12 @@ A storage backend is implemented as a class, and the plugin register the class t
|
||||||
|
|
||||||
The class must live in `Friendica\Addon\youraddonname` namespace, where `youraddonname` the folder name of your addon.
|
The class must live in `Friendica\Addon\youraddonname` namespace, where `youraddonname` the folder name of your addon.
|
||||||
|
|
||||||
The class must implement `Friendica\Model\Storage\ISelectableStorage` interface. All method in the interface must be implemented:
|
The class must implement `Friendica\Model\Storage\IWritableStorage` interface. All method in the interface must be implemented:
|
||||||
|
|
||||||
namespace Friendica\Model\ISelectableStorage;
|
namespace Friendica\Model\IWritableStorage;
|
||||||
|
|
||||||
```php
|
```php
|
||||||
interface ISelectableStorage
|
interface IWritableStorage
|
||||||
{
|
{
|
||||||
public function get(string $reference);
|
public function get(string $reference);
|
||||||
public function put(string $data, string $reference = '');
|
public function put(string $data, string $reference = '');
|
||||||
|
@ -79,7 +79,7 @@ Each label should be translatable
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
See doxygen documentation of `ISelectableStorage` interface for details about each method.
|
See doxygen documentation of `IWritableStorage` interface for details about each method.
|
||||||
|
|
||||||
## Register a storage backend class
|
## Register a storage backend class
|
||||||
|
|
||||||
|
@ -105,8 +105,9 @@ Each new Storage class should be added to the test-environment at [Storage Tests
|
||||||
Add a new test class which's naming convention is `StorageClassTest`, which extend the `StorageTest` in the same directory.
|
Add a new test class which's naming convention is `StorageClassTest`, which extend the `StorageTest` in the same directory.
|
||||||
|
|
||||||
Override the two necessary instances:
|
Override the two necessary instances:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
use Friendica\Model\Storage\ISelectableStorage;
|
use Friendica\Model\Storage\IWritableStorage;
|
||||||
|
|
||||||
abstract class StorageTest
|
abstract class StorageTest
|
||||||
{
|
{
|
||||||
|
@ -114,7 +115,7 @@ abstract class StorageTest
|
||||||
abstract protected function getInstance();
|
abstract protected function getInstance();
|
||||||
|
|
||||||
// Assertion for the option array you return for your new StorageClass
|
// Assertion for the option array you return for your new StorageClass
|
||||||
abstract protected function assertOption(ISelectableStorage $storage);
|
abstract protected function assertOption(IWritableStorage $storage);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -138,9 +139,9 @@ If there's a predecessor to this exception (e.g. you caught an exception and are
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
use Friendica\Model\Storage\ISelectableStorage;
|
use Friendica\Model\Storage\IWritableStorage;
|
||||||
|
|
||||||
class ExampleStorage implements ISelectableStorage
|
class ExampleStorage implements IWritableStorage
|
||||||
{
|
{
|
||||||
public function get(string $reference) : string
|
public function get(string $reference) : string
|
||||||
{
|
{
|
||||||
|
@ -168,12 +169,12 @@ The file will be `addon/samplestorage/SampleStorageBackend.php`:
|
||||||
<?php
|
<?php
|
||||||
namespace Friendica\Addon\samplestorage;
|
namespace Friendica\Addon\samplestorage;
|
||||||
|
|
||||||
use Friendica\Model\Storage\ISelectableStorage;
|
use Friendica\Model\Storage\IWritableStorage;
|
||||||
|
|
||||||
use Friendica\Core\Config\IConfig;
|
use Friendica\Core\Config\IConfig;
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
|
|
||||||
class SampleStorageBackend implements ISelectableStorage
|
class SampleStorageBackend implements IWritableStorage
|
||||||
{
|
{
|
||||||
const NAME = 'Sample Storage';
|
const NAME = 'Sample Storage';
|
||||||
|
|
||||||
|
@ -305,7 +306,7 @@ function samplestorage_storage_instance(\Friendica\App $a, array $data)
|
||||||
**Theoretically - until tests for Addons are enabled too - create a test class with the name `addon/tests/SampleStorageTest.php`:
|
**Theoretically - until tests for Addons are enabled too - create a test class with the name `addon/tests/SampleStorageTest.php`:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
use Friendica\Model\Storage\ISelectableStorage;
|
use Friendica\Model\Storage\IWritableStorage;
|
||||||
use Friendica\Test\src\Model\Storage\StorageTest;
|
use Friendica\Test\src\Model\Storage\StorageTest;
|
||||||
|
|
||||||
class SampleStorageTest extends StorageTest
|
class SampleStorageTest extends StorageTest
|
||||||
|
@ -319,7 +320,7 @@ class SampleStorageTest extends StorageTest
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assertion for the option array you return for your new StorageClass
|
// Assertion for the option array you return for your new StorageClass
|
||||||
protected function assertOption(ISelectableStorage $storage)
|
protected function assertOption(IWritableStorage $storage)
|
||||||
{
|
{
|
||||||
$this->assertEquals([
|
$this->assertEquals([
|
||||||
'filename' => [
|
'filename' => [
|
||||||
|
|
|
@ -132,7 +132,7 @@ HELP;
|
||||||
}
|
}
|
||||||
|
|
||||||
$name = $this->args[1];
|
$name = $this->args[1];
|
||||||
$class = $this->storageManager->getSelectableStorageByName($name);
|
$class = $this->storageManager->getWritableStorageByName($name);
|
||||||
|
|
||||||
if (is_null($class)) {
|
if (is_null($class)) {
|
||||||
$this->out($name . ' is not a registered backend.');
|
$this->out($name . ' is not a registered backend.');
|
||||||
|
|
|
@ -82,13 +82,13 @@ class StorageManager
|
||||||
$currentName = $this->config->get('storage', 'name', '');
|
$currentName = $this->config->get('storage', 'name', '');
|
||||||
|
|
||||||
// you can only use user backends as a "default" backend, so the second parameter is true
|
// 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 current storage backend class
|
||||||
*
|
*
|
||||||
* @return Storage\ISelectableStorage|null
|
* @return Storage\IWritableStorage|null
|
||||||
*/
|
*/
|
||||||
public function getBackend()
|
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
|
* @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\ReferenceStorageException in case there's no backend class for the name
|
||||||
* @throws Storage\StorageException in case of an unexpected failure during the hook call
|
* @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
|
// @todo 2020.09 Remove this call after 2 releases
|
||||||
$name = $this->checkLegacyBackend($name);
|
$name = $this->checkLegacyBackend($name);
|
||||||
|
@ -130,7 +130,7 @@ class StorageManager
|
||||||
];
|
];
|
||||||
try {
|
try {
|
||||||
Hook::callAll('storage_instance', $data);
|
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'];
|
$this->backendInstances[$data['name'] ?? $name] = $data['storage'];
|
||||||
} else {
|
} else {
|
||||||
throw new Storage\ReferenceStorageException(sprintf('Backend %s was not found', $name));
|
throw new Storage\ReferenceStorageException(sprintf('Backend %s was not found', $name));
|
||||||
|
@ -244,11 +244,11 @@ class StorageManager
|
||||||
/**
|
/**
|
||||||
* Set current storage backend class
|
* 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
|
* @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())) {
|
if ($this->config->set('storage', 'name', $storage::getName())) {
|
||||||
$this->currentBackend = $storage;
|
$this->currentBackend = $storage;
|
||||||
|
@ -327,15 +327,15 @@ class StorageManager
|
||||||
* Copy existing data to destination storage and delete from source.
|
* Copy existing data to destination storage and delete from source.
|
||||||
* This method cannot move to legacy in-table `data` field.
|
* This method cannot move to legacy in-table `data` field.
|
||||||
*
|
*
|
||||||
* @param Storage\ISelectableStorage $destination Destination storage class name
|
* @param Storage\IWritableStorage $destination Destination storage class name
|
||||||
* @param array $tables Tables to look in for resources. Optional, defaults to ['photo', 'attach']
|
* @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 int $limit Limit of the process batch size, defaults to 5000
|
||||||
*
|
*
|
||||||
* @return int Number of moved resources
|
* @return int Number of moved resources
|
||||||
* @throws Storage\StorageException
|
* @throws Storage\StorageException
|
||||||
* @throws Exception
|
* @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)) {
|
if (!$this->isValidBackend($destination, true)) {
|
||||||
throw new Storage\StorageException(sprintf("Can't move to storage backend '%s'", $destination::getName()));
|
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)) {
|
while ($resource = $this->dba->fetch($resources)) {
|
||||||
$id = $resource['id'];
|
$id = $resource['id'];
|
||||||
$data = $resource['data'];
|
$data = $resource['data'];
|
||||||
$source = $this->getSelectableStorageByName($resource['backend-class']);
|
$source = $this->getWritableStorageByName($resource['backend-class']);
|
||||||
$sourceRef = $resource['backend-ref'];
|
$sourceRef = $resource['backend-ref'];
|
||||||
|
|
||||||
if (!empty($source)) {
|
if (!empty($source)) {
|
||||||
|
|
|
@ -387,11 +387,11 @@ abstract class DI
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Model\Storage\ISelectableStorage
|
* @return Model\Storage\IWritableStorage
|
||||||
*/
|
*/
|
||||||
public static function storage()
|
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);
|
$items = self::selectToArray(['backend-class','backend-ref'], $conditions);
|
||||||
|
|
||||||
foreach($items as $item) {
|
foreach($items as $item) {
|
||||||
$backend_class = DI::storageManager()->getSelectableStorageByName($item['backend-class'] ?? '');
|
$backend_class = DI::storageManager()->getWritableStorageByName($item['backend-class'] ?? '');
|
||||||
if (!empty($backend_class)) {
|
if (!empty($backend_class)) {
|
||||||
$fields['backend-ref'] = $backend_class->put($img->asString(), $item['backend-ref'] ?? '');
|
$fields['backend-ref'] = $backend_class->put($img->asString(), $item['backend-ref'] ?? '');
|
||||||
} else {
|
} else {
|
||||||
|
@ -316,7 +316,7 @@ class Attach
|
||||||
$items = self::selectToArray(['backend-class','backend-ref'], $conditions);
|
$items = self::selectToArray(['backend-class','backend-ref'], $conditions);
|
||||||
|
|
||||||
foreach($items as $item) {
|
foreach($items as $item) {
|
||||||
$backend_class = DI::storageManager()->getSelectableStorageByName($item['backend-class'] ?? '');
|
$backend_class = DI::storageManager()->getWritableStorageByName($item['backend-class'] ?? '');
|
||||||
if (!empty($backend_class)) {
|
if (!empty($backend_class)) {
|
||||||
try {
|
try {
|
||||||
$backend_class->delete($item['backend-ref'] ?? '');
|
$backend_class->delete($item['backend-ref'] ?? '');
|
||||||
|
|
|
@ -347,7 +347,7 @@ class Photo
|
||||||
|
|
||||||
if (DBA::isResult($existing_photo)) {
|
if (DBA::isResult($existing_photo)) {
|
||||||
$backend_ref = (string)$existing_photo["backend-ref"];
|
$backend_ref = (string)$existing_photo["backend-ref"];
|
||||||
$storage = DI::storageManager()->getSelectableStorageByName($existing_photo["backend-class"] ?? '');
|
$storage = DI::storageManager()->getWritableStorageByName($existing_photo["backend-class"] ?? '');
|
||||||
} else {
|
} else {
|
||||||
$storage = DI::storage();
|
$storage = DI::storage();
|
||||||
}
|
}
|
||||||
|
@ -411,7 +411,7 @@ class Photo
|
||||||
$photos = DBA::select('photo', ['id', 'backend-class', 'backend-ref'], $conditions);
|
$photos = DBA::select('photo', ['id', 'backend-class', 'backend-ref'], $conditions);
|
||||||
|
|
||||||
while ($photo = DBA::fetch($photos)) {
|
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)) {
|
if (!empty($backend_class)) {
|
||||||
try {
|
try {
|
||||||
$backend_class->delete($item['backend-ref'] ?? '');
|
$backend_class->delete($item['backend-ref'] ?? '');
|
||||||
|
@ -448,7 +448,7 @@ class Photo
|
||||||
$photos = self::selectToArray(['backend-class', 'backend-ref'], $conditions);
|
$photos = self::selectToArray(['backend-class', 'backend-ref'], $conditions);
|
||||||
|
|
||||||
foreach($photos as $photo) {
|
foreach($photos as $photo) {
|
||||||
$backend_class = DI::storageManager()->getSelectableStorageByName($photo['backend-class'] ?? '');
|
$backend_class = DI::storageManager()->getWritableStorageByName($photo['backend-class'] ?? '');
|
||||||
if (!empty($backend_class)) {
|
if (!empty($backend_class)) {
|
||||||
$fields["backend-ref"] = $backend_class->put($img->asString(), $photo['backend-ref']);
|
$fields["backend-ref"] = $backend_class->put($img->asString(), $photo['backend-ref']);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -29,7 +29,7 @@ use Friendica\Database\Database as DBA;
|
||||||
*
|
*
|
||||||
* This class manage data stored in database table.
|
* This class manage data stored in database table.
|
||||||
*/
|
*/
|
||||||
class Database implements ISelectableStorage
|
class Database implements IWritableStorage
|
||||||
{
|
{
|
||||||
const NAME = 'Database';
|
const NAME = 'Database';
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ use Friendica\Util\Strings;
|
||||||
* Each new resource gets a value as reference and is saved in a
|
* Each new resource gets a value as reference and is saved in a
|
||||||
* folder tree stucture created from that value.
|
* folder tree stucture created from that value.
|
||||||
*/
|
*/
|
||||||
class Filesystem implements ISelectableStorage
|
class Filesystem implements IWritableStorage
|
||||||
{
|
{
|
||||||
const NAME = 'Filesystem';
|
const NAME = 'Filesystem';
|
||||||
|
|
||||||
|
|
|
@ -22,12 +22,12 @@
|
||||||
namespace Friendica\Model\Storage;
|
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).
|
* 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.
|
* 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\Core\Renderer;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Model\Storage\ISelectableStorage;
|
use Friendica\Model\Storage\IWritableStorage;
|
||||||
use Friendica\Module\BaseAdmin;
|
use Friendica\Module\BaseAdmin;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
|
|
||||||
|
@ -37,8 +37,8 @@ class Storage extends BaseAdmin
|
||||||
|
|
||||||
$storagebackend = Strings::escapeTags(trim($parameters['name'] ?? ''));
|
$storagebackend = Strings::escapeTags(trim($parameters['name'] ?? ''));
|
||||||
|
|
||||||
/** @var ISelectableStorage $newstorage */
|
/** @var IWritableStorage $newstorage */
|
||||||
$newstorage = DI::storageManager()->getSelectableStorageByName($storagebackend);
|
$newstorage = DI::storageManager()->getWritableStorageByName($storagebackend);
|
||||||
|
|
||||||
// save storage backend form
|
// save storage backend form
|
||||||
$storage_opts = $newstorage->getOptions();
|
$storage_opts = $newstorage->getOptions();
|
||||||
|
@ -68,8 +68,8 @@ class Storage extends BaseAdmin
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($_POST['submit_save_set'])) {
|
if (!empty($_POST['submit_save_set'])) {
|
||||||
/** @var ISelectableStorage $newstorage */
|
/** @var IWritableStorage $newstorage */
|
||||||
$newstorage = DI::storageManager()->getSelectableStorageByName($storagebackend);
|
$newstorage = DI::storageManager()->getWritableStorageByName($storagebackend);
|
||||||
|
|
||||||
if (!DI::storageManager()->setBackend($newstorage)) {
|
if (!DI::storageManager()->setBackend($newstorage)) {
|
||||||
notice(DI::l10n()->t('Invalid storage backend setting value.'));
|
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_prefix = preg_replace('|[^a-zA-Z0-9]|', '', $name);
|
||||||
|
|
||||||
$storage_form = [];
|
$storage_form = [];
|
||||||
foreach (DI::storageManager()->getSelectableStorageByName($name)->getOptions() as $option => $info) {
|
foreach (DI::storageManager()->getWritableStorageByName($name)->getOptions() as $option => $info) {
|
||||||
$type = $info[0];
|
$type = $info[0];
|
||||||
// Backward compatibilty with yesno field description
|
// Backward compatibilty with yesno field description
|
||||||
if ($type == 'yesno') {
|
if ($type == 'yesno') {
|
||||||
|
@ -111,7 +111,7 @@ class Storage extends BaseAdmin
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'prefix' => $storage_form_prefix,
|
'prefix' => $storage_form_prefix,
|
||||||
'form' => $storage_form,
|
'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'),
|
'$noconfig' => DI::l10n()->t('This backend doesn\'t have custom settings'),
|
||||||
'$baseurl' => DI::baseUrl()->get(true),
|
'$baseurl' => DI::baseUrl()->get(true),
|
||||||
'$form_security_token' => self::getFormSecurityToken("admin_storage"),
|
'$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,
|
'$availablestorageforms' => $available_storage_forms,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ use Friendica\Core\Session\ISession;
|
||||||
use Friendica\Core\StorageManager;
|
use Friendica\Core\StorageManager;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
use Friendica\Factory;
|
use Friendica\Factory;
|
||||||
use Friendica\Model\Storage\ISelectableStorage;
|
use Friendica\Model\Storage\IWritableStorage;
|
||||||
use Friendica\Model\User\Cookie;
|
use Friendica\Model\User\Cookie;
|
||||||
use Friendica\Network;
|
use Friendica\Network;
|
||||||
use Friendica\Util;
|
use Friendica\Util;
|
||||||
|
@ -213,7 +213,7 @@ return [
|
||||||
$_SERVER, $_COOKIE
|
$_SERVER, $_COOKIE
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
ISelectableStorage::class => [
|
IWritableStorage::class => [
|
||||||
'instanceOf' => StorageManager::class,
|
'instanceOf' => StorageManager::class,
|
||||||
'call' => [
|
'call' => [
|
||||||
['getBackend', [], Dice::CHAIN_CALL],
|
['getBackend', [], Dice::CHAIN_CALL],
|
||||||
|
|
|
@ -22,14 +22,14 @@
|
||||||
namespace Friendica\Test\Util;
|
namespace Friendica\Test\Util;
|
||||||
|
|
||||||
use Friendica\Core\Hook;
|
use Friendica\Core\Hook;
|
||||||
use Friendica\Model\Storage\ISelectableStorage;
|
use Friendica\Model\Storage\IWritableStorage;
|
||||||
|
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A backend storage example class
|
* A backend storage example class
|
||||||
*/
|
*/
|
||||||
class SampleStorageBackend implements ISelectableStorage
|
class SampleStorageBackend implements IWritableStorage
|
||||||
{
|
{
|
||||||
const NAME = 'Sample Storage';
|
const NAME = 'Sample Storage';
|
||||||
|
|
||||||
|
|
|
@ -178,7 +178,7 @@ class StorageManagerTest extends DatabaseTest
|
||||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
|
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
|
||||||
|
|
||||||
if ($userBackend) {
|
if ($userBackend) {
|
||||||
$storage = $storageManager->getSelectableStorageByName($name);
|
$storage = $storageManager->getWritableStorageByName($name);
|
||||||
} else {
|
} else {
|
||||||
$storage = $storageManager->getByName($name);
|
$storage = $storageManager->getByName($name);
|
||||||
}
|
}
|
||||||
|
@ -230,7 +230,7 @@ class StorageManagerTest extends DatabaseTest
|
||||||
self::assertNull($storageManager->getBackend());
|
self::assertNull($storageManager->getBackend());
|
||||||
|
|
||||||
if ($userBackend) {
|
if ($userBackend) {
|
||||||
$selBackend = $storageManager->getSelectableStorageByName($name);
|
$selBackend = $storageManager->getWritableStorageByName($name);
|
||||||
$storageManager->setBackend($selBackend);
|
$storageManager->setBackend($selBackend);
|
||||||
|
|
||||||
self::assertInstanceOf($assert, $storageManager->getBackend());
|
self::assertInstanceOf($assert, $storageManager->getBackend());
|
||||||
|
@ -287,7 +287,7 @@ class StorageManagerTest extends DatabaseTest
|
||||||
SampleStorageBackend::registerHook();
|
SampleStorageBackend::registerHook();
|
||||||
Hook::loadHooks();
|
Hook::loadHooks();
|
||||||
|
|
||||||
self::assertTrue($storageManager->setBackend( $storageManager->getSelectableStorageByName(SampleStorageBackend::NAME)));
|
self::assertTrue($storageManager->setBackend( $storageManager->getWritableStorageByName(SampleStorageBackend::NAME)));
|
||||||
self::assertEquals(SampleStorageBackend::NAME, $this->config->get('storage', 'name'));
|
self::assertEquals(SampleStorageBackend::NAME, $this->config->get('storage', 'name'));
|
||||||
|
|
||||||
self::assertInstanceOf(SampleStorageBackend::class, $storageManager->getBackend());
|
self::assertInstanceOf(SampleStorageBackend::class, $storageManager->getBackend());
|
||||||
|
@ -314,7 +314,7 @@ class StorageManagerTest extends DatabaseTest
|
||||||
$this->loadFixture(__DIR__ . '/../../datasets/storage/database.fixture.php', $this->dba);
|
$this->loadFixture(__DIR__ . '/../../datasets/storage/database.fixture.php', $this->dba);
|
||||||
|
|
||||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
||||||
$storage = $storageManager->getSelectableStorageByName($name);
|
$storage = $storageManager->getWritableStorageByName($name);
|
||||||
$storageManager->move($storage);
|
$storageManager->move($storage);
|
||||||
|
|
||||||
$photos = $this->dba->select('photo', ['backend-ref', 'backend-class', 'id', 'data']);
|
$photos = $this->dba->select('photo', ['backend-ref', 'backend-class', 'id', 'data']);
|
||||||
|
@ -333,12 +333,12 @@ class StorageManagerTest extends DatabaseTest
|
||||||
/**
|
/**
|
||||||
* Test moving data to a WRONG storage
|
* Test moving data to a WRONG storage
|
||||||
*/
|
*/
|
||||||
public function testWrongSelectableStorage()
|
public function testWrongWritableStorage()
|
||||||
{
|
{
|
||||||
$this->expectException(\TypeError::class);
|
$this->expectException(\TypeError::class);
|
||||||
|
|
||||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
||||||
$storage = $storageManager->getSelectableStorageByName(Storage\SystemResource::getName());
|
$storage = $storageManager->getWritableStorageByName(Storage\SystemResource::getName());
|
||||||
$storageManager->move($storage);
|
$storageManager->move($storage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace Friendica\Test\src\Model\Storage;
|
||||||
|
|
||||||
use Friendica\Factory\ConfigFactory;
|
use Friendica\Factory\ConfigFactory;
|
||||||
use Friendica\Model\Storage\Database;
|
use Friendica\Model\Storage\Database;
|
||||||
use Friendica\Model\Storage\ISelectableStorage;
|
use Friendica\Model\Storage\IWritableStorage;
|
||||||
use Friendica\Test\DatabaseTestTrait;
|
use Friendica\Test\DatabaseTestTrait;
|
||||||
use Friendica\Test\Util\Database\StaticDatabase;
|
use Friendica\Test\Util\Database\StaticDatabase;
|
||||||
use Friendica\Test\Util\VFSTrait;
|
use Friendica\Test\Util\VFSTrait;
|
||||||
|
@ -63,7 +63,7 @@ class DatabaseStorageTest extends StorageTest
|
||||||
return new Database($dba);
|
return new Database($dba);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function assertOption(ISelectableStorage $storage)
|
protected function assertOption(IWritableStorage $storage)
|
||||||
{
|
{
|
||||||
self::assertEmpty($storage->getOptions());
|
self::assertEmpty($storage->getOptions());
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace Friendica\Test\src\Model\Storage;
|
||||||
use Friendica\Core\Config\IConfig;
|
use Friendica\Core\Config\IConfig;
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
use Friendica\Model\Storage\Filesystem;
|
use Friendica\Model\Storage\Filesystem;
|
||||||
use Friendica\Model\Storage\ISelectableStorage;
|
use Friendica\Model\Storage\IWritableStorage;
|
||||||
use Friendica\Model\Storage\StorageException;
|
use Friendica\Model\Storage\StorageException;
|
||||||
use Friendica\Test\Util\VFSTrait;
|
use Friendica\Test\Util\VFSTrait;
|
||||||
use Friendica\Util\Profiler;
|
use Friendica\Util\Profiler;
|
||||||
|
@ -64,7 +64,7 @@ class FilesystemStorageTest extends StorageTest
|
||||||
return new Filesystem($this->config, $l10n);
|
return new Filesystem($this->config, $l10n);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function assertOption(ISelectableStorage $storage)
|
protected function assertOption(IWritableStorage $storage)
|
||||||
{
|
{
|
||||||
self::assertEquals([
|
self::assertEquals([
|
||||||
'storagepath' => [
|
'storagepath' => [
|
||||||
|
|
|
@ -21,17 +21,17 @@
|
||||||
|
|
||||||
namespace Friendica\Test\src\Model\Storage;
|
namespace Friendica\Test\src\Model\Storage;
|
||||||
|
|
||||||
use Friendica\Model\Storage\ISelectableStorage;
|
use Friendica\Model\Storage\IWritableStorage;
|
||||||
use Friendica\Model\Storage\IStorage;
|
use Friendica\Model\Storage\IStorage;
|
||||||
use Friendica\Model\Storage\ReferenceStorageException;
|
use Friendica\Model\Storage\ReferenceStorageException;
|
||||||
use Friendica\Test\MockedTest;
|
use Friendica\Test\MockedTest;
|
||||||
|
|
||||||
abstract class StorageTest extends MockedTest
|
abstract class StorageTest extends MockedTest
|
||||||
{
|
{
|
||||||
/** @return ISelectableStorage */
|
/** @return IWritableStorage */
|
||||||
abstract protected function getInstance();
|
abstract protected function getInstance();
|
||||||
|
|
||||||
abstract protected function assertOption(ISelectableStorage $storage);
|
abstract protected function assertOption(IWritableStorage $storage);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if the instance is "really" implementing the interface
|
* Test if the instance is "really" implementing the interface
|
||||||
|
|
Loading…
Reference in a new issue