@@ -42,97 +42,97 @@ |
||
| 42 | 42 | * Migrate mount config from mount.json to the database |
| 43 | 43 | */ |
| 44 | 44 | class StorageMigrator { |
| 45 | - /** |
|
| 46 | - * @var BackendService |
|
| 47 | - */ |
|
| 48 | - private $backendService; |
|
| 45 | + /** |
|
| 46 | + * @var BackendService |
|
| 47 | + */ |
|
| 48 | + private $backendService; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @var DBConfigService |
|
| 52 | - */ |
|
| 53 | - private $dbConfig; |
|
| 50 | + /** |
|
| 51 | + * @var DBConfigService |
|
| 52 | + */ |
|
| 53 | + private $dbConfig; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @var IConfig |
|
| 57 | - */ |
|
| 58 | - private $config; |
|
| 55 | + /** |
|
| 56 | + * @var IConfig |
|
| 57 | + */ |
|
| 58 | + private $config; |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @var IDBConnection |
|
| 62 | - */ |
|
| 63 | - private $connection; |
|
| 60 | + /** |
|
| 61 | + * @var IDBConnection |
|
| 62 | + */ |
|
| 63 | + private $connection; |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @var ILogger |
|
| 67 | - */ |
|
| 68 | - private $logger; |
|
| 65 | + /** |
|
| 66 | + * @var ILogger |
|
| 67 | + */ |
|
| 68 | + private $logger; |
|
| 69 | 69 | |
| 70 | - /** @var IUserMountCache */ |
|
| 71 | - private $userMountCache; |
|
| 70 | + /** @var IUserMountCache */ |
|
| 71 | + private $userMountCache; |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * StorageMigrator constructor. |
|
| 75 | - * |
|
| 76 | - * @param BackendService $backendService |
|
| 77 | - * @param DBConfigService $dbConfig |
|
| 78 | - * @param IConfig $config |
|
| 79 | - * @param IDBConnection $connection |
|
| 80 | - * @param ILogger $logger |
|
| 81 | - * @param IUserMountCache $userMountCache |
|
| 82 | - */ |
|
| 83 | - public function __construct( |
|
| 84 | - BackendService $backendService, |
|
| 85 | - DBConfigService $dbConfig, |
|
| 86 | - IConfig $config, |
|
| 87 | - IDBConnection $connection, |
|
| 88 | - ILogger $logger, |
|
| 89 | - IUserMountCache $userMountCache |
|
| 90 | - ) { |
|
| 91 | - $this->backendService = $backendService; |
|
| 92 | - $this->dbConfig = $dbConfig; |
|
| 93 | - $this->config = $config; |
|
| 94 | - $this->connection = $connection; |
|
| 95 | - $this->logger = $logger; |
|
| 96 | - $this->userMountCache = $userMountCache; |
|
| 97 | - } |
|
| 73 | + /** |
|
| 74 | + * StorageMigrator constructor. |
|
| 75 | + * |
|
| 76 | + * @param BackendService $backendService |
|
| 77 | + * @param DBConfigService $dbConfig |
|
| 78 | + * @param IConfig $config |
|
| 79 | + * @param IDBConnection $connection |
|
| 80 | + * @param ILogger $logger |
|
| 81 | + * @param IUserMountCache $userMountCache |
|
| 82 | + */ |
|
| 83 | + public function __construct( |
|
| 84 | + BackendService $backendService, |
|
| 85 | + DBConfigService $dbConfig, |
|
| 86 | + IConfig $config, |
|
| 87 | + IDBConnection $connection, |
|
| 88 | + ILogger $logger, |
|
| 89 | + IUserMountCache $userMountCache |
|
| 90 | + ) { |
|
| 91 | + $this->backendService = $backendService; |
|
| 92 | + $this->dbConfig = $dbConfig; |
|
| 93 | + $this->config = $config; |
|
| 94 | + $this->connection = $connection; |
|
| 95 | + $this->logger = $logger; |
|
| 96 | + $this->userMountCache = $userMountCache; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - private function migrate(LegacyStoragesService $legacyService, StoragesService $storageService) { |
|
| 100 | - $existingStorage = $legacyService->getAllStorages(); |
|
| 99 | + private function migrate(LegacyStoragesService $legacyService, StoragesService $storageService) { |
|
| 100 | + $existingStorage = $legacyService->getAllStorages(); |
|
| 101 | 101 | |
| 102 | - $this->connection->beginTransaction(); |
|
| 103 | - try { |
|
| 104 | - foreach ($existingStorage as $storage) { |
|
| 105 | - $mountOptions = $storage->getMountOptions(); |
|
| 106 | - if (!empty($mountOptions) && !isset($mountOptions['enable_sharing'])) { |
|
| 107 | - // existing mounts must have sharing enabled by default to avoid surprises |
|
| 108 | - $mountOptions['enable_sharing'] = true; |
|
| 109 | - $storage->setMountOptions($mountOptions); |
|
| 110 | - } |
|
| 111 | - $storageService->addStorage($storage); |
|
| 112 | - } |
|
| 113 | - $this->connection->commit(); |
|
| 114 | - } catch (\Exception $e) { |
|
| 115 | - $this->logger->logException($e); |
|
| 116 | - $this->connection->rollBack(); |
|
| 117 | - } |
|
| 118 | - } |
|
| 102 | + $this->connection->beginTransaction(); |
|
| 103 | + try { |
|
| 104 | + foreach ($existingStorage as $storage) { |
|
| 105 | + $mountOptions = $storage->getMountOptions(); |
|
| 106 | + if (!empty($mountOptions) && !isset($mountOptions['enable_sharing'])) { |
|
| 107 | + // existing mounts must have sharing enabled by default to avoid surprises |
|
| 108 | + $mountOptions['enable_sharing'] = true; |
|
| 109 | + $storage->setMountOptions($mountOptions); |
|
| 110 | + } |
|
| 111 | + $storageService->addStorage($storage); |
|
| 112 | + } |
|
| 113 | + $this->connection->commit(); |
|
| 114 | + } catch (\Exception $e) { |
|
| 115 | + $this->logger->logException($e); |
|
| 116 | + $this->connection->rollBack(); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Migrate personal storages configured by the current user |
|
| 122 | - * |
|
| 123 | - * @param IUser $user |
|
| 124 | - */ |
|
| 125 | - public function migrateUser(IUser $user) { |
|
| 126 | - $dummySession = new DummyUserSession(); |
|
| 127 | - $dummySession->setUser($user); |
|
| 128 | - $userId = $user->getUID(); |
|
| 129 | - $userVersion = $this->config->getUserValue($userId, 'files_external', 'config_version', '0.0.0'); |
|
| 130 | - if (version_compare($userVersion, '0.5.0', '<')) { |
|
| 131 | - $this->config->setUserValue($userId, 'files_external', 'config_version', '0.5.0'); |
|
| 132 | - $legacyService = new UserLegacyStoragesService($this->backendService, $dummySession); |
|
| 133 | - $storageService = new UserStoragesService($this->backendService, $this->dbConfig, $dummySession, $this->userMountCache); |
|
| 120 | + /** |
|
| 121 | + * Migrate personal storages configured by the current user |
|
| 122 | + * |
|
| 123 | + * @param IUser $user |
|
| 124 | + */ |
|
| 125 | + public function migrateUser(IUser $user) { |
|
| 126 | + $dummySession = new DummyUserSession(); |
|
| 127 | + $dummySession->setUser($user); |
|
| 128 | + $userId = $user->getUID(); |
|
| 129 | + $userVersion = $this->config->getUserValue($userId, 'files_external', 'config_version', '0.0.0'); |
|
| 130 | + if (version_compare($userVersion, '0.5.0', '<')) { |
|
| 131 | + $this->config->setUserValue($userId, 'files_external', 'config_version', '0.5.0'); |
|
| 132 | + $legacyService = new UserLegacyStoragesService($this->backendService, $dummySession); |
|
| 133 | + $storageService = new UserStoragesService($this->backendService, $this->dbConfig, $dummySession, $this->userMountCache); |
|
| 134 | 134 | |
| 135 | - $this->migrate($legacyService, $storageService); |
|
| 136 | - } |
|
| 137 | - } |
|
| 135 | + $this->migrate($legacyService, $storageService); |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | 138 | } |