From 7439b3db64095e4075708d552bf2093b702851e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 12 May 2026 13:46:01 +0200 Subject: [PATCH] fix(files_external): Migrate call to now-deprecated static methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/files_external/lib/Command/Verify.php | 5 +++-- apps/files_external/lib/Config/ConfigAdapter.php | 5 +++-- .../lib/Controller/GlobalStoragesController.php | 5 ++++- .../lib/Controller/StoragesController.php | 5 +++-- .../lib/Controller/UserGlobalStoragesController.php | 5 ++++- .../lib/Controller/UserStoragesController.php | 5 ++++- apps/files_external/lib/Service/BackendService.php | 1 + .../lib/Service/ImportLegacyStoragesService.php | 7 ------- .../lib/Service/LegacyStoragesService.php | 10 ++++++---- apps/files_external/tests/Config/ConfigAdapterTest.php | 7 ++++++- .../tests/Controller/GlobalStoragesControllerTest.php | 3 ++- .../tests/Controller/UserStoragesControllerTest.php | 3 ++- 12 files changed, 38 insertions(+), 23 deletions(-) diff --git a/apps/files_external/lib/Command/Verify.php b/apps/files_external/lib/Command/Verify.php index 80ba831e6f5..c618291edf8 100644 --- a/apps/files_external/lib/Command/Verify.php +++ b/apps/files_external/lib/Command/Verify.php @@ -10,8 +10,8 @@ namespace OCA\Files_External\Command; use OC\Core\Command\Base; use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException; use OCA\Files_External\Lib\StorageConfig; -use OCA\Files_External\MountConfig; use OCA\Files_External\NotFoundException; +use OCA\Files_External\Service\BackendService; use OCA\Files_External\Service\GlobalStoragesService; use OCP\AppFramework\Http; use OCP\Files\StorageNotAvailableException; @@ -23,6 +23,7 @@ use Symfony\Component\Console\Output\OutputInterface; class Verify extends Base { public function __construct( protected GlobalStoragesService $globalService, + protected BackendService $backendService, ) { parent::__construct(); } @@ -96,7 +97,7 @@ class Verify extends Base { $backend = $storage->getBackend(); // update status (can be time-consuming) $storage->setStatus( - MountConfig::getBackendStatus( + $this->backendService->getBackendStatus( $backend->getStorageClass(), $storage->getBackendOptions(), ) diff --git a/apps/files_external/lib/Config/ConfigAdapter.php b/apps/files_external/lib/Config/ConfigAdapter.php index 6a306c0f117..ed65b0d8600 100644 --- a/apps/files_external/lib/Config/ConfigAdapter.php +++ b/apps/files_external/lib/Config/ConfigAdapter.php @@ -13,7 +13,7 @@ use OC\Files\Storage\Wrapper\Availability; use OC\Files\Storage\Wrapper\KnownMtime; use OCA\Files_External\Lib\PersonalMount; use OCA\Files_External\Lib\StorageConfig; -use OCA\Files_External\MountConfig; +use OCA\Files_External\Service\BackendService; use OCA\Files_External\Service\UserGlobalStoragesService; use OCA\Files_External\Service\UserStoragesService; use OCP\Files\Config\IAuthoritativeMountProvider; @@ -39,6 +39,7 @@ class ConfigAdapter implements IMountProvider, IAuthoritativeMountProvider, IPar public function __construct( private UserStoragesService $userStoragesService, private UserGlobalStoragesService $userGlobalStoragesService, + private BackendService $backendService, private ClockInterface $clock, ) { } @@ -63,7 +64,7 @@ class ConfigAdapter implements IMountProvider, IAuthoritativeMountProvider, IPar */ private function prepareStorageConfig(StorageConfig &$storage, IUser $user): void { foreach ($storage->getBackendOptions() as $option => $value) { - $storage->setBackendOption($option, MountConfig::substitutePlaceholdersInConfig($value, $user->getUID())); + $storage->setBackendOption($option, $this->backendService->applyConfigHandlers($value, $user->getUID())); } $objectStore = $storage->getBackendOption('objectstore'); diff --git a/apps/files_external/lib/Controller/GlobalStoragesController.php b/apps/files_external/lib/Controller/GlobalStoragesController.php index fa2fdfaa9a7..f3505763624 100644 --- a/apps/files_external/lib/Controller/GlobalStoragesController.php +++ b/apps/files_external/lib/Controller/GlobalStoragesController.php @@ -8,6 +8,7 @@ namespace OCA\Files_External\Controller; use OCA\Files_External\NotFoundException; +use OCA\Files_External\Service\BackendService; use OCA\Files_External\Service\GlobalStoragesService; use OCA\Files_External\Settings\Admin; use OCP\AppFramework\Http; @@ -37,6 +38,7 @@ class GlobalStoragesController extends StoragesController { IUserSession $userSession, IGroupManager $groupManager, IConfig $config, + BackendService $backendService, ) { parent::__construct( $appName, @@ -46,7 +48,8 @@ class GlobalStoragesController extends StoragesController { $logger, $userSession, $groupManager, - $config + $config, + $backendService, ); } diff --git a/apps/files_external/lib/Controller/StoragesController.php b/apps/files_external/lib/Controller/StoragesController.php index 9a61d9bfd6e..07afd0ceb44 100644 --- a/apps/files_external/lib/Controller/StoragesController.php +++ b/apps/files_external/lib/Controller/StoragesController.php @@ -11,8 +11,8 @@ use OCA\Files_External\Lib\Auth\AuthMechanism; use OCA\Files_External\Lib\Backend\Backend; use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException; use OCA\Files_External\Lib\StorageConfig; -use OCA\Files_External\MountConfig; use OCA\Files_External\NotFoundException; +use OCA\Files_External\Service\BackendService; use OCA\Files_External\Service\StoragesService; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; @@ -48,6 +48,7 @@ abstract class StoragesController extends Controller { protected IUserSession $userSession, protected IGroupManager $groupManager, protected IConfig $config, + protected BackendService $backendService, ) { parent::__construct($appName, $request); } @@ -222,7 +223,7 @@ abstract class StoragesController extends Controller { $backend = $storage->getBackend(); // update status (can be time-consuming) $storage->setStatus( - MountConfig::getBackendStatus( + $this->backendService->getBackendStatus( $backend->getStorageClass(), $storage->getBackendOptions(), ) diff --git a/apps/files_external/lib/Controller/UserGlobalStoragesController.php b/apps/files_external/lib/Controller/UserGlobalStoragesController.php index 5314dd57205..21fac9fccf0 100644 --- a/apps/files_external/lib/Controller/UserGlobalStoragesController.php +++ b/apps/files_external/lib/Controller/UserGlobalStoragesController.php @@ -14,6 +14,7 @@ use OCA\Files_External\Lib\Backend\Backend; use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException; use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\NotFoundException; +use OCA\Files_External\Service\BackendService; use OCA\Files_External\Service\UserGlobalStoragesService; use OCP\AppFramework\Http; use OCP\AppFramework\Http\Attribute\NoAdminRequired; @@ -50,6 +51,7 @@ class UserGlobalStoragesController extends StoragesController { IUserSession $userSession, IGroupManager $groupManager, IConfig $config, + BackendService $backendService, ) { parent::__construct( $appName, @@ -59,7 +61,8 @@ class UserGlobalStoragesController extends StoragesController { $logger, $userSession, $groupManager, - $config + $config, + $backendService, ); } diff --git a/apps/files_external/lib/Controller/UserStoragesController.php b/apps/files_external/lib/Controller/UserStoragesController.php index fcedad3dfdb..2ed6d4d92d1 100644 --- a/apps/files_external/lib/Controller/UserStoragesController.php +++ b/apps/files_external/lib/Controller/UserStoragesController.php @@ -11,6 +11,7 @@ use OCA\Files_External\Lib\Auth\AuthMechanism; use OCA\Files_External\Lib\Backend\Backend; use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\NotFoundException; +use OCA\Files_External\Service\BackendService; use OCA\Files_External\Service\UserStoragesService; use OCP\AppFramework\Http; use OCP\AppFramework\Http\Attribute\NoAdminRequired; @@ -40,6 +41,7 @@ class UserStoragesController extends StoragesController { IUserSession $userSession, IGroupManager $groupManager, IConfig $config, + BackendService $backendService, ) { parent::__construct( $appName, @@ -49,7 +51,8 @@ class UserStoragesController extends StoragesController { $logger, $userSession, $groupManager, - $config + $config, + $backendService, ); } diff --git a/apps/files_external/lib/Service/BackendService.php b/apps/files_external/lib/Service/BackendService.php index 7b12f41153a..c9fc5473acf 100644 --- a/apps/files_external/lib/Service/BackendService.php +++ b/apps/files_external/lib/Service/BackendService.php @@ -18,6 +18,7 @@ use OCA\Files_External\Lib\Config\IAuthMechanismProvider; use OCA\Files_External\Lib\Config\IBackendProvider; use OCP\EventDispatcher\GenericEvent; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\StorageNotAvailableException; use OCP\IAppConfig; use OCP\Server; use Psr\Container\ContainerExceptionInterface; diff --git a/apps/files_external/lib/Service/ImportLegacyStoragesService.php b/apps/files_external/lib/Service/ImportLegacyStoragesService.php index d143f2a4c43..a71aec79176 100644 --- a/apps/files_external/lib/Service/ImportLegacyStoragesService.php +++ b/apps/files_external/lib/Service/ImportLegacyStoragesService.php @@ -11,13 +11,6 @@ namespace OCA\Files_External\Service; class ImportLegacyStoragesService extends LegacyStoragesService { private $data; - /** - * @param BackendService $backendService - */ - public function __construct(BackendService $backendService) { - $this->backendService = $backendService; - } - public function setData($data) { $this->data = $data; } diff --git a/apps/files_external/lib/Service/LegacyStoragesService.php b/apps/files_external/lib/Service/LegacyStoragesService.php index 9f199a89b3f..08cef135bc7 100644 --- a/apps/files_external/lib/Service/LegacyStoragesService.php +++ b/apps/files_external/lib/Service/LegacyStoragesService.php @@ -16,9 +16,11 @@ use Psr\Log\LoggerInterface; * Read mount config from legacy mount.json */ abstract class LegacyStoragesService { - /** @var BackendService */ - protected $backendService; - + public function __construct( + protected BackendService $backendService, + protected EncryptionService $encryptionService, + ) { + } /** * Read legacy config data * @@ -132,7 +134,7 @@ abstract class LegacyStoragesService { $relativeMountPath = rtrim($parts[2], '/'); // note: we cannot do this after the loop because the decrypted config // options might be needed for the config hash - $storageOptions['options'] = MountConfig::decryptPasswords($storageOptions['options']); + $storageOptions['options'] = $this->encryptionService->decryptPasswords($storageOptions['options']); if (!isset($storageOptions['backend'])) { $storageOptions['backend'] = $storageOptions['class']; // legacy compat } diff --git a/apps/files_external/tests/Config/ConfigAdapterTest.php b/apps/files_external/tests/Config/ConfigAdapterTest.php index fe7aa7d30e3..6a84e913501 100644 --- a/apps/files_external/tests/Config/ConfigAdapterTest.php +++ b/apps/files_external/tests/Config/ConfigAdapterTest.php @@ -125,7 +125,12 @@ class ConfigAdapterTest extends TestCase { $this->userStoragesService = Server::get(UserStoragesService::class); $this->userGlobalStoragesService = Server::get(UserGlobalStoragesService::class); - $this->adapter = new ConfigAdapter($this->userStoragesService, $this->userGlobalStoragesService, $this->createMock(ClockInterface::class)); + $this->adapter = new ConfigAdapter( + $this->userStoragesService, + $this->userGlobalStoragesService, + $this->createMock(BackendService::class), + $this->createMock(ClockInterface::class), + ); $this->user = $this->createMock(IUser::class); $this->user->method('getUID')->willReturn('user1'); diff --git a/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php b/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php index 74a27eb15e4..7445c3e16d8 100644 --- a/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php +++ b/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php @@ -49,7 +49,8 @@ class GlobalStoragesControllerTest extends StoragesControllerTestCase { $this->createMock(LoggerInterface::class), $session, $this->createMock(IGroupManager::class), - $config + $config, + $this->createMock(BackendService::class), ); } diff --git a/apps/files_external/tests/Controller/UserStoragesControllerTest.php b/apps/files_external/tests/Controller/UserStoragesControllerTest.php index 3e8d89ec060..e2d5f301b12 100644 --- a/apps/files_external/tests/Controller/UserStoragesControllerTest.php +++ b/apps/files_external/tests/Controller/UserStoragesControllerTest.php @@ -58,7 +58,8 @@ class UserStoragesControllerTest extends StoragesControllerTestCase { $this->createMock(LoggerInterface::class), $session, $this->createMock(IGroupManager::class), - $config + $config, + $this->createMock(BackendService::class), ); }