diff --git a/apps/files_external/appinfo/app.php b/apps/files_external/appinfo/app.php index 37a489535e..6c659af8aa 100644 --- a/apps/files_external/appinfo/app.php +++ b/apps/files_external/appinfo/app.php @@ -47,8 +47,9 @@ OC::$CLASSPATH['OCA\Files\External\Api'] = 'files_external/lib/api.php'; require_once __DIR__ . '/../3rdparty/autoload.php'; -$app = new \OCA\Files_external\Appinfo\Application(); -$appContainer = $app->getContainer(); +// register Application object singleton +\OC_Mount_Config::$app = new \OCA\Files_external\Appinfo\Application(); +$appContainer = \OC_Mount_Config::$app->getContainer(); $l = \OC::$server->getL10N('files_external'); @@ -65,9 +66,6 @@ if (OCP\Config::getAppValue('files_external', 'allow_user_mounting', 'yes') == ' "name" => $l->t('External storage') ]); -// Teach OC_Mount_Config about the AppFramework -\OC_Mount_Config::initApp($appContainer); - // connecting hooks OCP\Util::connectHook('OC_Filesystem', 'post_initMountPoints', '\OC_Mount_Config', 'initMountPointsHook'); OCP\Util::connectHook('OC_User', 'post_login', 'OC\Files\Storage\SMB_OC', 'login'); diff --git a/apps/files_external/appinfo/routes.php b/apps/files_external/appinfo/routes.php index bc4b0e98c9..213e7b28dc 100644 --- a/apps/files_external/appinfo/routes.php +++ b/apps/files_external/appinfo/routes.php @@ -28,8 +28,7 @@ namespace OCA\Files_External\AppInfo; /** * @var $this \OC\Route\Router **/ -$application = new Application(); -$application->registerRoutes( +\OC_Mount_Config::$app->registerRoutes( $this, array( 'resources' => array( diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 6fdf050fb6..5c38a3ba0c 100644 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -32,7 +32,7 @@ */ use phpseclib\Crypt\AES; -use \OCP\AppFramework\IAppContainer; +use \OCA\Files_External\Appinfo\Application; use \OCA\Files_External\Lib\BackendConfig; use \OCA\Files_External\Service\BackendService; use \OCA\Files_External\Lib\Backend\LegacyBackend; @@ -56,17 +56,8 @@ class OC_Mount_Config { // whether to skip backend test (for unit tests, as this static class is not mockable) public static $skipTest = false; - /** @var IAppContainer */ - private static $appContainer; - - /** - * Teach OC_Mount_Config about the AppFramework - * - * @param IAppContainer $appContainer - */ - public static function initApp(IAppContainer $appContainer) { - self::$appContainer = $appContainer; - } + /** @var Application */ + public static $app; /** * @param string $class @@ -75,8 +66,8 @@ class OC_Mount_Config { * @deprecated 8.2.0 use \OCA\Files_External\Service\BackendService::registerBackend() */ public static function registerBackend($class, $definition) { - $backendService = self::$appContainer->query('OCA\Files_External\Service\BackendService'); - $auth = self::$appContainer->query('OCA\Files_External\Lib\Auth\Builtin'); + $backendService = self::$app->getContainer()->query('OCA\Files_External\Service\BackendService'); + $auth = self::$app->getContainer()->query('OCA\Files_External\Lib\Auth\Builtin'); $backendService->registerBackend(new LegacyBackend($class, $definition, $auth)); @@ -128,9 +119,9 @@ class OC_Mount_Config { public static function getAbsoluteMountPoints($uid) { $mountPoints = array(); - $userGlobalStoragesService = self::$appContainer->query('OCA\Files_External\Service\UserGlobalStoragesService'); - $userStoragesService = self::$appContainer->query('OCA\Files_External\Service\UserStoragesService'); - $user = self::$appContainer->query('OCP\IUserManager')->get($uid); + $userGlobalStoragesService = self::$app->getContainer()->query('OCA\Files_External\Service\UserGlobalStoragesService'); + $userStoragesService = self::$app->getContainer()->query('OCA\Files_External\Service\UserStoragesService'); + $user = self::$app->getContainer()->query('OCP\IUserManager')->get($uid); $userGlobalStoragesService->setUser($user); $userStoragesService->setUser($user); @@ -168,7 +159,7 @@ class OC_Mount_Config { */ public static function getSystemMountPoints() { $mountPoints = []; - $service = self::$appContainer->query('OCA\Files_External\Service\GlobalStoragesService'); + $service = self::$app->getContainer()->query('OCA\Files_External\Service\GlobalStoragesService'); foreach ($service->getAllStorages() as $storage) { $mountPoints[] = self::prepareMountPointEntry($storage, false); @@ -184,7 +175,7 @@ class OC_Mount_Config { */ public static function getPersonalMountPoints() { $mountPoints = []; - $service = self::$appContainer->query('OCA\Files_External\Service\UserStoragesService'); + $service = self::$app->getContainer()->query('OCA\Files_External\Service\UserStoragesService'); foreach ($service->getAllStorages() as $storage) { $mountPoints[] = self::prepareMountPointEntry($storage, true); @@ -533,7 +524,7 @@ class OC_Mount_Config { return false; } - $service = self::$appContainer->query('OCA\Files_External\Service\BackendService'); + $service = self::$app->getContainer()->query('OCA\Files_External\Service\BackendService'); $class = $service->getBackend($options['backend'])->getStorageClass(); try { /** @var \OC\Files\Storage\Storage $storage */ diff --git a/apps/files_external/personal.php b/apps/files_external/personal.php index fec1c195bb..696ca51b2e 100644 --- a/apps/files_external/personal.php +++ b/apps/files_external/personal.php @@ -26,8 +26,8 @@ use \OCA\Files_External\Service\BackendService; -$app = new \OCA\Files_external\Appinfo\Application(); -$appContainer = $app->getContainer(); +// we must use the same container +$appContainer = \OC_Mount_Config::$app->getContainer(); $backendService = $appContainer->query('OCA\Files_External\Service\BackendService'); $userStoragesService = $appContainer->query('OCA\Files_external\Service\UserStoragesService'); diff --git a/apps/files_external/settings.php b/apps/files_external/settings.php index 7e20af0c60..2ad31a3113 100644 --- a/apps/files_external/settings.php +++ b/apps/files_external/settings.php @@ -30,8 +30,8 @@ use \OCA\Files_External\Service\BackendService; OC_Util::checkAdminUser(); -$app = new \OCA\Files_external\Appinfo\Application(); -$appContainer = $app->getContainer(); +// we must use the same container +$appContainer = \OC_Mount_Config::$app->getContainer(); $backendService = $appContainer->query('OCA\Files_External\Service\BackendService'); $globalStoragesService = $appContainer->query('OCA\Files_external\Service\GlobalStoragesService'); diff --git a/apps/files_external/tests/service/storagesservicetest.php b/apps/files_external/tests/service/storagesservicetest.php index 07286106c7..28220c9bc2 100644 --- a/apps/files_external/tests/service/storagesservicetest.php +++ b/apps/files_external/tests/service/storagesservicetest.php @@ -121,7 +121,12 @@ abstract class StoragesServiceTest extends \Test\TestCase { return $this->backendService; } })); - \OC_Mount_Config::initApp($containerMock); + + \OC_Mount_Config::$app = $this->getMockBuilder('\OCA\Files_External\Appinfo\Application') + ->disableOriginalConstructor() + ->getMock(); + \OC_Mount_Config::$app->method('getContainer') + ->willReturn($containerMock); } public function tearDown() {