diff --git a/apps/files_external/lib/Command/MigrateOc.php b/apps/files_external/lib/Command/MigrateOc.php index ec35523ca9fd5..6e1950785d181 100644 --- a/apps/files_external/lib/Command/MigrateOc.php +++ b/apps/files_external/lib/Command/MigrateOc.php @@ -104,17 +104,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln("Successfully migrated"); } - $passwords = $this->getV2StoragePasswords(); - - if (count($passwords)) { - $output->writeln("Found " . count($passwords) . " stored passwords that need re-encoding"); - foreach ($passwords as $id => $password) { - $decoded = $this->decodePassword($password); - if (!$dryRun) { - $this->setStorageConfig($id, $this->encryptPassword($decoded)); - } - } - } + $this->migrateV2StoragePasswords() + $this->migrateUserCredentials() return 0; } @@ -167,6 +158,20 @@ private function getV2StoragePasswords(): array { return $configs; } + private function migrateV2StoragePasswords(): void { + $passwords = $this->getV2StoragePasswords(); + + if (count($passwords)) { + $output->writeln("Found " . count($passwords) . " stored passwords that need re-encoding"); + foreach ($passwords as $id => $password) { + $decoded = $this->decodePassword($password); + if (!$dryRun) { + $this->setStorageConfig($id, $this->encryptPassword($decoded)); + } + } + } + } + private function setStorageConfig(int $id, string $value) { $query = $this->connection->getQueryBuilder(); $query->update('external_config') @@ -175,6 +180,43 @@ private function setStorageConfig(int $id, string $value) { $query->executeStatement(); } + /** + * @return array + */ + private function getUserCredentials(): array { + $query = $this->connection->getQueryBuilder(); + $query->select('user', 'identifier', 'credentials') + ->from('credentials'); + + return $query->executeQuery()->fetchAll(); + } + + private function migrateUserCredentials(): void { + $passwords = $this->getV2StoragePasswords(); + + if (count($passwords)) { + $output->writeln("Found " . count($passwords) . " stored user credentials that need re-encoding"); + foreach ($passwords as $passwordRow) { + $decoded = $this->decodePassword($passwordRow["credentials"]); + if (!$dryRun) { + $this->setStorageCredentials($passwordRow, $this->encryptPassword($decoded)); + } + } + } + } + + private function setStorageCredentials(array $row, string $encryptedPassword) { + $query = $this->connection->getQueryBuilder(); + + $query->insert('storages_credentials') + ->values([ + 'user' => $query->createNamedParameter($row['user']), + 'identifier' => $query->createNamedParameter($row['identifier']), + 'credentials' => $query->createNamedParameter($encryptedPassword), + ]) + ->executeStatement(); + } + private function setStorageId(string $old, string $new): bool { $query = $this->connection->getQueryBuilder(); $query->update('storages')