Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add migration for storages that are not rebuildable
Signed-off-by: Louis Chemineau <[email protected]>
  • Loading branch information
artonge committed Oct 11, 2023
commit 60cb8637709d513a10fdbbb6852a8bdea70e3fb7
40 changes: 37 additions & 3 deletions apps/files_external/lib/Command/MigrateOc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <info>" . count($storages) . "</info> 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 <info>" . $storage['id'] . "</info> to <info>$newId</info>");

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 <info>" . count($configs) . "</info> wnd storages");
$output->writeln("Found <info>" . count($storages) . "</info> wnd storages");

foreach ($configs as $config) {
$output->writeln("<info>" . $config['host'] . ' - ' . $config['auth_backend'] . "</info>");
Expand Down Expand Up @@ -205,6 +227,18 @@ private function getWndExternalStorageConfigs(): array {
return $configs;
}

/**
* @return array<int, array<string, string>>
*/
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<int, string>
*/
Expand Down