diff --git a/apps/files_external/lib/Command/MigrateOc.php b/apps/files_external/lib/Command/MigrateOc.php
index 7ac1ace48d245..e8a055bd7e02f 100644
--- a/apps/files_external/lib/Command/MigrateOc.php
+++ b/apps/files_external/lib/Command/MigrateOc.php
@@ -66,15 +66,37 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->migrateStorageConfigPasswords($dryRun, $output);
$this->migrateStorageCredentials($dryRun, $output);
- $this->migrateWndStorage($dryRun, $output);
+ $this->rebuildWndStoragesId($dryRun, $output);
$this->migrateWndExternalStorages($dryRun, $output);
+ $this->migrateWndStorageId($dryRun, $output);
return 0;
}
- private function migrateWndStorage(bool $dryRun, OutputInterface $output): void {
+ private function migrateWndStorageId(bool $dryRun, OutputInterface $output): void {
+ $storages = $this->getStorages();
+ $output->writeln("Found " . count($storages) . " wnd storages that cannot be rebuilt");
+
+ foreach ($storages as $storage) {
+ $newId = preg_replace('/^wnd::/', 'smb::', $storage['id']);
+ $newId = preg_replace('/(^smb::.+@.+)\/(.+\/\/$)/', '$1//$2', $newId);
+
+ $output->writeln(" - Rewriting " . $storage['id'] . " to $newId");
+
+ if (!$dryRun) {
+ $query = $this->connection->getQueryBuilder();
+ $query->update('storages')
+ ->set('id', $query->createNamedParameter($newId))
+ ->where($query->expr()->eq('numeric_id', $query->createNamedParameter($storage['numeric_id'])))
+ ->executeStatement();
+ }
+ }
+ }
+
+ private function rebuildWndStoragesId(bool $dryRun, OutputInterface $output): void {
+ $storages = $this->getStorages();
$configs = $this->getWndExternalStorageConfigs();
- $output->writeln("Found " . count($configs) . " wnd storages");
+ $output->writeln("Found " . count($storages) . " wnd storages");
foreach ($configs as $config) {
$output->writeln("" . $config['host'] . ' - ' . $config['auth_backend'] . "");
@@ -205,6 +227,18 @@ private function getWndExternalStorageConfigs(): array {
return $configs;
}
+ /**
+ * @return array>
+ */
+ private function getStorages(): array {
+ $query = $this->connection->getQueryBuilder();
+ return $query->select('numeric_id', 'id')
+ ->from('storages')
+ ->where($query->expr()->like('id', $query->createNamedParameter('wnd::%')))
+ ->executeQuery()
+ ->fetchAll();
+ }
+
/**
* @return array
*/