Skip to content

Commit

Permalink
Add migration for storages that are not rebuildable
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <[email protected]>
  • Loading branch information
artonge committed Oct 11, 2023
1 parent 23205d8 commit 60cb863
Showing 1 changed file with 37 additions and 3 deletions.
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

0 comments on commit 60cb863

Please sign in to comment.