Add legacy backend storage functionality
This commit is contained in:
parent
3e72e8015b
commit
ca8ca05051
2 changed files with 55 additions and 1 deletions
|
@ -88,6 +88,9 @@ class StorageManager
|
||||||
*/
|
*/
|
||||||
public function getByName(string $name = null, $onlyUserBackend = false)
|
public function getByName(string $name = null, $onlyUserBackend = false)
|
||||||
{
|
{
|
||||||
|
// @todo 2020.09 Remove this call after 2 releases
|
||||||
|
$name = $this->checkLegacyBackend($name);
|
||||||
|
|
||||||
// If there's no cached instance create a new instance
|
// If there's no cached instance create a new instance
|
||||||
if (!isset($this->backendInstances[$name])) {
|
if (!isset($this->backendInstances[$name])) {
|
||||||
// If the current name isn't a valid backend (or the SystemResource instance) create it
|
// If the current name isn't a valid backend (or the SystemResource instance) create it
|
||||||
|
@ -140,6 +143,25 @@ class StorageManager
|
||||||
(!$onlyUserBackend && $name === Storage\SystemResource::getName());
|
(!$onlyUserBackend && $name === Storage\SystemResource::getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for legacy backend storage class names (= full model class name)
|
||||||
|
*
|
||||||
|
* @todo 2020.09 Remove this function after 2 releases, because there shouldn't be any legacy backend classes left
|
||||||
|
*
|
||||||
|
* @param string|null $name a potential, legacy storage name ("Friendica\Model\Storage\...")
|
||||||
|
*
|
||||||
|
* @return string|null The current storage name
|
||||||
|
*/
|
||||||
|
private function checkLegacyBackend(string $name = null)
|
||||||
|
{
|
||||||
|
if (stristr($name, 'Friendica\Model\Storage\\')) {
|
||||||
|
$this->logger->notice('Using deprecated storage class value', ['name' => $name]);
|
||||||
|
return substr($name, 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set current storage backend class
|
* @brief Set current storage backend class
|
||||||
*
|
*
|
||||||
|
|
|
@ -109,10 +109,42 @@ class StorageManagerTest extends DatabaseTest
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data array for legacy backends
|
||||||
|
*
|
||||||
|
* @todo 2020.09 After 2 releases, remove the legacy functionality and these data array with it
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function dataLegacyBackends()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'legacyDatabase' => [
|
||||||
|
'name' => 'Friendica\Model\Storage\Database',
|
||||||
|
'assert' => Storage\Database::class,
|
||||||
|
'assertName' => Storage\Database::NAME,
|
||||||
|
'userBackend' => true,
|
||||||
|
],
|
||||||
|
'legacyFilesystem' => [
|
||||||
|
'name' => 'Friendica\Model\Storage\Filesystem',
|
||||||
|
'assert' => Storage\Filesystem::class,
|
||||||
|
'assertName' => Storage\Filesystem::NAME,
|
||||||
|
'userBackend' => true,
|
||||||
|
],
|
||||||
|
'legacySystemResource' => [
|
||||||
|
'name' => 'Friendica\Model\Storage\SystemResource',
|
||||||
|
'assert' => Storage\SystemResource::class,
|
||||||
|
'assertName' => Storage\SystemResource::NAME,
|
||||||
|
'userBackend' => false,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the getByName() method
|
* Test the getByName() method
|
||||||
*
|
*
|
||||||
* @dataProvider dataStorages
|
* @dataProvider dataStorages
|
||||||
|
* @dataProvider dataLegacyBackends
|
||||||
*/
|
*/
|
||||||
public function testGetByName($name, $assert, $assertName, $userBackend)
|
public function testGetByName($name, $assert, $assertName, $userBackend)
|
||||||
{
|
{
|
||||||
|
@ -123,7 +155,6 @@ class StorageManagerTest extends DatabaseTest
|
||||||
if (!empty($assert)) {
|
if (!empty($assert)) {
|
||||||
$this->assertInstanceOf(Storage\IStorage::class, $storage);
|
$this->assertInstanceOf(Storage\IStorage::class, $storage);
|
||||||
$this->assertInstanceOf($assert, $storage);
|
$this->assertInstanceOf($assert, $storage);
|
||||||
$this->assertEquals($name, $storage::getName());
|
|
||||||
} else {
|
} else {
|
||||||
$this->assertNull($storage);
|
$this->assertNull($storage);
|
||||||
}
|
}
|
||||||
|
@ -178,6 +209,7 @@ class StorageManagerTest extends DatabaseTest
|
||||||
* Test the method getBackend() with a pre-configured backend
|
* Test the method getBackend() with a pre-configured backend
|
||||||
*
|
*
|
||||||
* @dataProvider dataStorages
|
* @dataProvider dataStorages
|
||||||
|
* @dataProvider dataLegacyBackends
|
||||||
*/
|
*/
|
||||||
public function testPresetBackend($name, $assert, $assertName, $userBackend)
|
public function testPresetBackend($name, $assert, $assertName, $userBackend)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue