Merge pull request #10441 from MrPetovan/bug/10435-external-storage-di
Add ExternalStorage dependency to StorageManager
This commit is contained in:
commit
ce575a88fc
|
@ -25,6 +25,7 @@ use Exception;
|
||||||
use Friendica\Core\Config\IConfig;
|
use Friendica\Core\Config\IConfig;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
use Friendica\Model\Storage;
|
use Friendica\Model\Storage;
|
||||||
|
use Friendica\Network\IHTTPRequest;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,6 +61,8 @@ class StorageManager
|
||||||
private $logger;
|
private $logger;
|
||||||
/** @var L10n */
|
/** @var L10n */
|
||||||
private $l10n;
|
private $l10n;
|
||||||
|
/** @var IHTTPRequest */
|
||||||
|
private $httpRequest;
|
||||||
|
|
||||||
/** @var Storage\IStorage */
|
/** @var Storage\IStorage */
|
||||||
private $currentBackend;
|
private $currentBackend;
|
||||||
|
@ -70,12 +73,13 @@ class StorageManager
|
||||||
* @param LoggerInterface $logger
|
* @param LoggerInterface $logger
|
||||||
* @param L10n $l10n
|
* @param L10n $l10n
|
||||||
*/
|
*/
|
||||||
public function __construct(Database $dba, IConfig $config, LoggerInterface $logger, L10n $l10n)
|
public function __construct(Database $dba, IConfig $config, LoggerInterface $logger, L10n $l10n, IHTTPRequest $httpRequest)
|
||||||
{
|
{
|
||||||
$this->dba = $dba;
|
$this->dba = $dba;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->l10n = $l10n;
|
$this->l10n = $l10n;
|
||||||
|
$this->httpRequest = $httpRequest;
|
||||||
$this->backends = $config->get('storage', 'backends', self::DEFAULT_BACKENDS);
|
$this->backends = $config->get('storage', 'backends', self::DEFAULT_BACKENDS);
|
||||||
|
|
||||||
$currentName = $this->config->get('storage', 'name', '');
|
$currentName = $this->config->get('storage', 'name', '');
|
||||||
|
@ -127,7 +131,7 @@ class StorageManager
|
||||||
$this->backendInstances[$name] = new Storage\SystemResource();
|
$this->backendInstances[$name] = new Storage\SystemResource();
|
||||||
break;
|
break;
|
||||||
case Storage\ExternalResource::getName():
|
case Storage\ExternalResource::getName():
|
||||||
$this->backendInstances[$name] = new Storage\ExternalResource();
|
$this->backendInstances[$name] = new Storage\ExternalResource($this->httpRequest);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$data = [
|
$data = [
|
||||||
|
|
|
@ -35,6 +35,7 @@ use Friendica\Model\Config\Config;
|
||||||
use Friendica\Model\Storage;
|
use Friendica\Model\Storage;
|
||||||
use Friendica\Core\Session;
|
use Friendica\Core\Session;
|
||||||
use Friendica\Model\Storage\StorageException;
|
use Friendica\Model\Storage\StorageException;
|
||||||
|
use Friendica\Network\HTTPRequest;
|
||||||
use Friendica\Test\DatabaseTest;
|
use Friendica\Test\DatabaseTest;
|
||||||
use Friendica\Test\Util\Database\StaticDatabase;
|
use Friendica\Test\Util\Database\StaticDatabase;
|
||||||
use Friendica\Test\Util\VFSTrait;
|
use Friendica\Test\Util\VFSTrait;
|
||||||
|
@ -54,6 +55,8 @@ class StorageManagerTest extends DatabaseTest
|
||||||
private $logger;
|
private $logger;
|
||||||
/** @var L10n */
|
/** @var L10n */
|
||||||
private $l10n;
|
private $l10n;
|
||||||
|
/** @var HTTPRequest */
|
||||||
|
private $httpRequest;
|
||||||
|
|
||||||
use VFSTrait;
|
use VFSTrait;
|
||||||
|
|
||||||
|
@ -79,6 +82,8 @@ class StorageManagerTest extends DatabaseTest
|
||||||
$this->config = new PreloadConfig($configCache, $configModel);
|
$this->config = new PreloadConfig($configCache, $configModel);
|
||||||
|
|
||||||
$this->l10n = \Mockery::mock(L10n::class);
|
$this->l10n = \Mockery::mock(L10n::class);
|
||||||
|
|
||||||
|
$this->httpRequest = \Mockery::mock(HTTPRequest::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,7 +91,7 @@ class StorageManagerTest extends DatabaseTest
|
||||||
*/
|
*/
|
||||||
public function testInstance()
|
public function testInstance()
|
||||||
{
|
{
|
||||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
|
||||||
|
|
||||||
self::assertInstanceOf(StorageManager::class, $storageManager);
|
self::assertInstanceOf(StorageManager::class, $storageManager);
|
||||||
}
|
}
|
||||||
|
@ -168,7 +173,7 @@ class StorageManagerTest extends DatabaseTest
|
||||||
*/
|
*/
|
||||||
public function testGetByName($name, $assert, $assertName, $userBackend)
|
public function testGetByName($name, $assert, $assertName, $userBackend)
|
||||||
{
|
{
|
||||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
|
||||||
|
|
||||||
$storage = $storageManager->getByName($name, $userBackend);
|
$storage = $storageManager->getByName($name, $userBackend);
|
||||||
|
|
||||||
|
@ -188,7 +193,7 @@ class StorageManagerTest extends DatabaseTest
|
||||||
*/
|
*/
|
||||||
public function testIsValidBackend($name, $assert, $assertName, $userBackend)
|
public function testIsValidBackend($name, $assert, $assertName, $userBackend)
|
||||||
{
|
{
|
||||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
|
||||||
|
|
||||||
// true in every of the backends
|
// true in every of the backends
|
||||||
self::assertEquals(!empty($assertName), $storageManager->isValidBackend($name));
|
self::assertEquals(!empty($assertName), $storageManager->isValidBackend($name));
|
||||||
|
@ -202,7 +207,7 @@ class StorageManagerTest extends DatabaseTest
|
||||||
*/
|
*/
|
||||||
public function testListBackends()
|
public function testListBackends()
|
||||||
{
|
{
|
||||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
|
||||||
|
|
||||||
self::assertEquals(StorageManager::DEFAULT_BACKENDS, $storageManager->listBackends());
|
self::assertEquals(StorageManager::DEFAULT_BACKENDS, $storageManager->listBackends());
|
||||||
}
|
}
|
||||||
|
@ -214,7 +219,7 @@ class StorageManagerTest extends DatabaseTest
|
||||||
*/
|
*/
|
||||||
public function testGetBackend($name, $assert, $assertName, $userBackend)
|
public function testGetBackend($name, $assert, $assertName, $userBackend)
|
||||||
{
|
{
|
||||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
|
||||||
|
|
||||||
self::assertNull($storageManager->getBackend());
|
self::assertNull($storageManager->getBackend());
|
||||||
|
|
||||||
|
@ -235,7 +240,7 @@ class StorageManagerTest extends DatabaseTest
|
||||||
{
|
{
|
||||||
$this->config->set('storage', 'name', $name);
|
$this->config->set('storage', 'name', $name);
|
||||||
|
|
||||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
|
||||||
|
|
||||||
if ($userBackend) {
|
if ($userBackend) {
|
||||||
self::assertInstanceOf($assert, $storageManager->getBackend());
|
self::assertInstanceOf($assert, $storageManager->getBackend());
|
||||||
|
@ -260,7 +265,7 @@ class StorageManagerTest extends DatabaseTest
|
||||||
->addRule(ISession::class, ['instanceOf' => Session\Memory::class, 'shared' => true, 'call' => null]);
|
->addRule(ISession::class, ['instanceOf' => Session\Memory::class, 'shared' => true, 'call' => null]);
|
||||||
DI::init($dice);
|
DI::init($dice);
|
||||||
|
|
||||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
|
||||||
|
|
||||||
self::assertTrue($storageManager->register(SampleStorageBackend::class));
|
self::assertTrue($storageManager->register(SampleStorageBackend::class));
|
||||||
|
|
||||||
|
@ -301,7 +306,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, $this->httpRequest);
|
||||||
$storage = $storageManager->getByName($name);
|
$storage = $storageManager->getByName($name);
|
||||||
$storageManager->move($storage);
|
$storageManager->move($storage);
|
||||||
|
|
||||||
|
@ -326,7 +331,7 @@ class StorageManagerTest extends DatabaseTest
|
||||||
$this->expectExceptionMessage("Can't move to storage backend 'SystemResource'");
|
$this->expectExceptionMessage("Can't move to storage backend 'SystemResource'");
|
||||||
$this->expectException(StorageException::class);
|
$this->expectException(StorageException::class);
|
||||||
|
|
||||||
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
|
$storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n, $this->httpRequest);
|
||||||
$storage = $storageManager->getByName(Storage\SystemResource::getName());
|
$storage = $storageManager->getByName(Storage\SystemResource::getName());
|
||||||
$storageManager->move($storage);
|
$storageManager->move($storage);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue