Skip to content

Commit

Permalink
feat(upgrade): migration attributes
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <[email protected]>
  • Loading branch information
ArtificialOwl committed Aug 2, 2024
1 parent 7b32dd5 commit 7b67067
Show file tree
Hide file tree
Showing 23 changed files with 1,312 additions and 0 deletions.
102 changes: 102 additions & 0 deletions core/Command/Db/Migrations/PreviewCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Core\Command\Db\Migrations;

use OC\Migration\MetadataManager;
use OC\Updater\ReleaseMetadata;
use OCP\Migration\Attributes\MigrationAttribute;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Helper\TableCell;
use Symfony\Component\Console\Helper\TableCellStyle;
use Symfony\Component\Console\Helper\TableSeparator;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @since 30.0.0
*/
class PreviewCommand extends Command {
private bool $initiated = false;
public function __construct(
private MetadataManager $metadataManager,
private ReleaseMetadata $releaseMetadata,
) {
parent::__construct();
}

protected function configure(): void {
$this
->setName('migrations:preview')
->setDescription('Get preview of available DB migrations in case of initiating an upgrade')
->addArgument('version', InputArgument::REQUIRED, 'The destination version number');

parent::configure();
}

public function execute(InputInterface $input, OutputInterface $output): int {
$version = $input->getArgument('version');
if (filter_var($version, FILTER_VALIDATE_URL)) {
$metadata = $this->releaseMetadata->downloadMetadata($version);
} elseif (str_starts_with($version, '/')) {
$metadata = json_decode(file_get_contents($version), true, flags: JSON_THROW_ON_ERROR);
} else {
$metadata = $this->releaseMetadata->getMetadata($version);
}

$parsed = $this->metadataManager->getMigrationsAttributesFromReleaseMetadata($metadata['migrations'] ?? [], true);

$table = new Table($output);
$this->displayMigrations($table, 'core', $parsed['core'] ?? []);
foreach ($parsed['apps'] as $appId => $migrations) {
if (!empty($migrations)) {
$this->displayMigrations($table, $appId, $migrations);
}
}
$table->render();

return 0;
}

private function displayMigrations(Table $table, string $appId, array $data): void {
if (empty($data)) {
return;
}

if ($this->initiated) {
$table->addRow(new TableSeparator());
}
$this->initiated = true;

$table->addRow(
[
new TableCell(
$appId,
[
'colspan' => 2,
'style' => new TableCellStyle(['cellFormat' => '<info>%s</info>'])
]
)
]
)->addRow(new TableSeparator());

/** @var MigrationAttribute[] $attributes */
foreach($data as $migration => $attributes) {
$attributesStr = [];
foreach($attributes as $attribute) {
$definition = '<info>' . $attribute->definition() . "</info>";
$definition .= empty($attribute->getDescription()) ? '' : "\n " . $attribute->getDescription();
$definition .= empty($attribute->getNotes()) ? '' : "\n <comment>" . implode("</comment>\n <comment>", $attribute->getNotes()) . '</comment>';
$attributesStr[] = $definition;
}
$table->addRow([$migration, implode("\n", $attributesStr)]);
}
}
}
1 change: 1 addition & 0 deletions core/register_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
$application->add(Server::get(Command\Db\AddMissingIndices::class));
$application->add(Server::get(Command\Db\AddMissingPrimaryKeys::class));

$application->add(Server::get(Command\Db\Migrations\PreviewCommand::class));
if ($config->getSystemValueBool('debug', false)) {
$application->add(Server::get(Command\Db\Migrations\StatusCommand::class));
$application->add(Server::get(Command\Db\Migrations\MigrateCommand::class));
Expand Down
19 changes: 19 additions & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,20 @@
'OCP\\Mail\\IEMailTemplate' => $baseDir . '/lib/public/Mail/IEMailTemplate.php',
'OCP\\Mail\\IMailer' => $baseDir . '/lib/public/Mail/IMailer.php',
'OCP\\Mail\\IMessage' => $baseDir . '/lib/public/Mail/IMessage.php',
'OCP\\Migration\\Attributes\\AddColumn' => $baseDir . '/lib/public/Migration/Attributes/AddColumn.php',
'OCP\\Migration\\Attributes\\AddIndex' => $baseDir . '/lib/public/Migration/Attributes/AddIndex.php',
'OCP\\Migration\\Attributes\\ColumnMigrationAttribute' => $baseDir . '/lib/public/Migration/Attributes/ColumnMigrationAttribute.php',
'OCP\\Migration\\Attributes\\ColumnType' => $baseDir . '/lib/public/Migration/Attributes/ColumnType.php',
'OCP\\Migration\\Attributes\\CreateTable' => $baseDir . '/lib/public/Migration/Attributes/CreateTable.php',
'OCP\\Migration\\Attributes\\DropColumn' => $baseDir . '/lib/public/Migration/Attributes/DropColumn.php',
'OCP\\Migration\\Attributes\\DropIndex' => $baseDir . '/lib/public/Migration/Attributes/DropIndex.php',
'OCP\\Migration\\Attributes\\DropTable' => $baseDir . '/lib/public/Migration/Attributes/DropTable.php',
'OCP\\Migration\\Attributes\\GenericMigrationAttribute' => $baseDir . '/lib/public/Migration/Attributes/GenericMigrationAttribute.php',
'OCP\\Migration\\Attributes\\IndexMigrationAttribute' => $baseDir . '/lib/public/Migration/Attributes/IndexMigrationAttribute.php',
'OCP\\Migration\\Attributes\\IndexType' => $baseDir . '/lib/public/Migration/Attributes/IndexType.php',
'OCP\\Migration\\Attributes\\MigrationAttribute' => $baseDir . '/lib/public/Migration/Attributes/MigrationAttribute.php',
'OCP\\Migration\\Attributes\\ModifyColumn' => $baseDir . '/lib/public/Migration/Attributes/ModifyColumn.php',
'OCP\\Migration\\Attributes\\TableMigrationAttribute' => $baseDir . '/lib/public/Migration/Attributes/TableMigrationAttribute.php',
'OCP\\Migration\\BigIntMigration' => $baseDir . '/lib/public/Migration/BigIntMigration.php',
'OCP\\Migration\\IMigrationStep' => $baseDir . '/lib/public/Migration/IMigrationStep.php',
'OCP\\Migration\\IOutput' => $baseDir . '/lib/public/Migration/IOutput.php',
Expand Down Expand Up @@ -1071,6 +1085,7 @@
'OC\\Core\\Command\\Db\\Migrations\\ExecuteCommand' => $baseDir . '/core/Command/Db/Migrations/ExecuteCommand.php',
'OC\\Core\\Command\\Db\\Migrations\\GenerateCommand' => $baseDir . '/core/Command/Db/Migrations/GenerateCommand.php',
'OC\\Core\\Command\\Db\\Migrations\\MigrateCommand' => $baseDir . '/core/Command/Db/Migrations/MigrateCommand.php',
'OC\\Core\\Command\\Db\\Migrations\\PreviewCommand' => $baseDir . '/core/Command/Db/Migrations/PreviewCommand.php',
'OC\\Core\\Command\\Db\\Migrations\\StatusCommand' => $baseDir . '/core/Command/Db/Migrations/StatusCommand.php',
'OC\\Core\\Command\\Encryption\\ChangeKeyStorageRoot' => $baseDir . '/core/Command/Encryption/ChangeKeyStorageRoot.php',
'OC\\Core\\Command\\Encryption\\DecryptAll' => $baseDir . '/core/Command/Encryption/DecryptAll.php',
Expand Down Expand Up @@ -1565,6 +1580,8 @@
'OC\\MemoryInfo' => $baseDir . '/lib/private/MemoryInfo.php',
'OC\\Migration\\BackgroundRepair' => $baseDir . '/lib/private/Migration/BackgroundRepair.php',
'OC\\Migration\\ConsoleOutput' => $baseDir . '/lib/private/Migration/ConsoleOutput.php',
'OC\\Migration\\Exceptions\\AttributeException' => $baseDir . '/lib/private/Migration/Exceptions/AttributeException.php',
'OC\\Migration\\MetadataManager' => $baseDir . '/lib/private/Migration/MetadataManager.php',
'OC\\Migration\\NullOutput' => $baseDir . '/lib/private/Migration/NullOutput.php',
'OC\\Migration\\SimpleOutput' => $baseDir . '/lib/private/Migration/SimpleOutput.php',
'OC\\NaturalSort' => $baseDir . '/lib/private/NaturalSort.php',
Expand Down Expand Up @@ -1844,6 +1861,8 @@
'OC\\Updater\\Changes' => $baseDir . '/lib/private/Updater/Changes.php',
'OC\\Updater\\ChangesCheck' => $baseDir . '/lib/private/Updater/ChangesCheck.php',
'OC\\Updater\\ChangesMapper' => $baseDir . '/lib/private/Updater/ChangesMapper.php',
'OC\\Updater\\Exceptions\\ReleaseMetadataException' => $baseDir . '/lib/private/Updater/Exceptions/ReleaseMetadataException.php',
'OC\\Updater\\ReleaseMetadata' => $baseDir . '/lib/private/Updater/ReleaseMetadata.php',
'OC\\Updater\\VersionCheck' => $baseDir . '/lib/private/Updater/VersionCheck.php',
'OC\\UserStatus\\ISettableProvider' => $baseDir . '/lib/private/UserStatus/ISettableProvider.php',
'OC\\UserStatus\\Manager' => $baseDir . '/lib/private/UserStatus/Manager.php',
Expand Down
19 changes: 19 additions & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,20 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\Mail\\IEMailTemplate' => __DIR__ . '/../../..' . '/lib/public/Mail/IEMailTemplate.php',
'OCP\\Mail\\IMailer' => __DIR__ . '/../../..' . '/lib/public/Mail/IMailer.php',
'OCP\\Mail\\IMessage' => __DIR__ . '/../../..' . '/lib/public/Mail/IMessage.php',
'OCP\\Migration\\Attributes\\AddColumn' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/AddColumn.php',
'OCP\\Migration\\Attributes\\AddIndex' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/AddIndex.php',
'OCP\\Migration\\Attributes\\ColumnMigrationAttribute' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/ColumnMigrationAttribute.php',
'OCP\\Migration\\Attributes\\ColumnType' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/ColumnType.php',
'OCP\\Migration\\Attributes\\CreateTable' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/CreateTable.php',
'OCP\\Migration\\Attributes\\DropColumn' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/DropColumn.php',
'OCP\\Migration\\Attributes\\DropIndex' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/DropIndex.php',
'OCP\\Migration\\Attributes\\DropTable' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/DropTable.php',
'OCP\\Migration\\Attributes\\GenericMigrationAttribute' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/GenericMigrationAttribute.php',
'OCP\\Migration\\Attributes\\IndexMigrationAttribute' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/IndexMigrationAttribute.php',
'OCP\\Migration\\Attributes\\IndexType' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/IndexType.php',
'OCP\\Migration\\Attributes\\MigrationAttribute' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/MigrationAttribute.php',
'OCP\\Migration\\Attributes\\ModifyColumn' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/ModifyColumn.php',
'OCP\\Migration\\Attributes\\TableMigrationAttribute' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/TableMigrationAttribute.php',
'OCP\\Migration\\BigIntMigration' => __DIR__ . '/../../..' . '/lib/public/Migration/BigIntMigration.php',
'OCP\\Migration\\IMigrationStep' => __DIR__ . '/../../..' . '/lib/public/Migration/IMigrationStep.php',
'OCP\\Migration\\IOutput' => __DIR__ . '/../../..' . '/lib/public/Migration/IOutput.php',
Expand Down Expand Up @@ -1104,6 +1118,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Core\\Command\\Db\\Migrations\\ExecuteCommand' => __DIR__ . '/../../..' . '/core/Command/Db/Migrations/ExecuteCommand.php',
'OC\\Core\\Command\\Db\\Migrations\\GenerateCommand' => __DIR__ . '/../../..' . '/core/Command/Db/Migrations/GenerateCommand.php',
'OC\\Core\\Command\\Db\\Migrations\\MigrateCommand' => __DIR__ . '/../../..' . '/core/Command/Db/Migrations/MigrateCommand.php',
'OC\\Core\\Command\\Db\\Migrations\\PreviewCommand' => __DIR__ . '/../../..' . '/core/Command/Db/Migrations/PreviewCommand.php',
'OC\\Core\\Command\\Db\\Migrations\\StatusCommand' => __DIR__ . '/../../..' . '/core/Command/Db/Migrations/StatusCommand.php',
'OC\\Core\\Command\\Encryption\\ChangeKeyStorageRoot' => __DIR__ . '/../../..' . '/core/Command/Encryption/ChangeKeyStorageRoot.php',
'OC\\Core\\Command\\Encryption\\DecryptAll' => __DIR__ . '/../../..' . '/core/Command/Encryption/DecryptAll.php',
Expand Down Expand Up @@ -1598,6 +1613,8 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\MemoryInfo' => __DIR__ . '/../../..' . '/lib/private/MemoryInfo.php',
'OC\\Migration\\BackgroundRepair' => __DIR__ . '/../../..' . '/lib/private/Migration/BackgroundRepair.php',
'OC\\Migration\\ConsoleOutput' => __DIR__ . '/../../..' . '/lib/private/Migration/ConsoleOutput.php',
'OC\\Migration\\Exceptions\\AttributeException' => __DIR__ . '/../../..' . '/lib/private/Migration/Exceptions/AttributeException.php',
'OC\\Migration\\MetadataManager' => __DIR__ . '/../../..' . '/lib/private/Migration/MetadataManager.php',
'OC\\Migration\\NullOutput' => __DIR__ . '/../../..' . '/lib/private/Migration/NullOutput.php',
'OC\\Migration\\SimpleOutput' => __DIR__ . '/../../..' . '/lib/private/Migration/SimpleOutput.php',
'OC\\NaturalSort' => __DIR__ . '/../../..' . '/lib/private/NaturalSort.php',
Expand Down Expand Up @@ -1877,6 +1894,8 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Updater\\Changes' => __DIR__ . '/../../..' . '/lib/private/Updater/Changes.php',
'OC\\Updater\\ChangesCheck' => __DIR__ . '/../../..' . '/lib/private/Updater/ChangesCheck.php',
'OC\\Updater\\ChangesMapper' => __DIR__ . '/../../..' . '/lib/private/Updater/ChangesMapper.php',
'OC\\Updater\\Exceptions\\ReleaseMetadataException' => __DIR__ . '/../../..' . '/lib/private/Updater/Exceptions/ReleaseMetadataException.php',
'OC\\Updater\\ReleaseMetadata' => __DIR__ . '/../../..' . '/lib/private/Updater/ReleaseMetadata.php',
'OC\\Updater\\VersionCheck' => __DIR__ . '/../../..' . '/lib/private/Updater/VersionCheck.php',
'OC\\UserStatus\\ISettableProvider' => __DIR__ . '/../../..' . '/lib/private/UserStatus/ISettableProvider.php',
'OC\\UserStatus\\Manager' => __DIR__ . '/../../..' . '/lib/private/UserStatus/Manager.php',
Expand Down
17 changes: 17 additions & 0 deletions lib/private/Migration/Exceptions/AttributeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Migration\Exceptions;

use Exception;

/**
* @since 30.0.0
*/
class AttributeException extends Exception {
}
156 changes: 156 additions & 0 deletions lib/private/Migration/MetadataManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OC\Migration;

use OC\DB\Connection;
use OC\DB\MigrationService;
use OC\Migration\Exceptions\AttributeException;
use OCP\App\IAppManager;
use OCP\Migration\Attributes\GenericMigrationAttribute;
use OCP\Migration\Attributes\MigrationAttribute;
use Psr\Log\LoggerInterface;
use ReflectionClass;

/**
* Helps managing DB Migrations' Metadata
*
* @since 30.0.0
*/
class MetadataManager {
public function __construct(
private readonly IAppManager $appManager,

Check failure

Code scanning / Psalm

InvalidDocblock Error

Param1 of OC\Migration\MetadataManager::__construct has invalid syntax

Check failure

Code scanning / Psalm

ParseError Error

Syntax error, unexpected T_STRING, expecting T_VARIABLE on line 27

Check failure on line 27 in lib/private/Migration/MetadataManager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidDocblock

lib/private/Migration/MetadataManager.php:27:3: InvalidDocblock: Param1 of OC\Migration\MetadataManager::__construct has invalid syntax (see https://psalm.dev/008)

Check failure on line 27 in lib/private/Migration/MetadataManager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

ParseError

lib/private/Migration/MetadataManager.php:27:20: ParseError: Syntax error, unexpected T_STRING, expecting T_VARIABLE on line 27 (see https://psalm.dev/173)
private readonly Connection $connection,
private readonly LoggerInterface $logger,
) {
}

/**
* We get all migrations from an app (or 'core'), and
* for each migration files we extract its attributes
*
* @param string $appId
*
* @return array<string, MigrationAttribute[]>
* @since 30.0.0
*/
public function extractMigrationAttributes(string $appId): array {
$ms = new MigrationService($appId, $this->connection);

Check failure

Code scanning / Psalm

UndefinedThisPropertyFetch Error

Instance property OC\Migration\MetadataManager::$connection is not defined

Check failure on line 43 in lib/private/Migration/MetadataManager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedThisPropertyFetch

lib/private/Migration/MetadataManager.php:43:38: UndefinedThisPropertyFetch: Instance property OC\Migration\MetadataManager::$connection is not defined (see https://psalm.dev/041)

$metadata = [];
foreach($ms->getAvailableVersions() as $version) {
$metadata[$version] = [];
$class = new ReflectionClass($ms->createInstance($version));

Check failure

Code scanning / Psalm

InaccessibleMethod Error

Cannot access protected method OC\DB\MigrationService::createInstance from context OC\Migration\MetadataManager

Check failure on line 48 in lib/private/Migration/MetadataManager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InaccessibleMethod

lib/private/Migration/MetadataManager.php:48:38: InaccessibleMethod: Cannot access protected method OC\DB\MigrationService::createInstance from context OC\Migration\MetadataManager (see https://psalm.dev/003)
$attributes = $class->getAttributes();
foreach ($attributes as $attribute) {
$item = $attribute->newInstance();
if ($item instanceof MigrationAttribute) {
$metadata[$version][] = $item;
}
}
}

return $metadata;
}

/**
* convert direct data from release metadata into a list of Migrations' Attribute
*
* @param array<array-key, array<array-key, array>> $metadata
* @param bool $filterKnownMigrations ignore metadata already done in local instance
*
* @return array{apps: array<array-key, array<string, MigrationAttribute[]>>, core: array<string, MigrationAttribute[]>}
* @since 30.0.0
*/
public function getMigrationsAttributesFromReleaseMetadata(
array $metadata,
bool $filterKnownMigrations = false
): array {
$appsAttributes = [];
foreach (array_keys($metadata['apps']) as $appId) {
if ($filterKnownMigrations && !$this->appManager->isInstalled($appId)) {

Check failure

Code scanning / Psalm

UndefinedThisPropertyFetch Error

Instance property OC\Migration\MetadataManager::$appManager is not defined

Check failure on line 76 in lib/private/Migration/MetadataManager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedThisPropertyFetch

lib/private/Migration/MetadataManager.php:76:35: UndefinedThisPropertyFetch: Instance property OC\Migration\MetadataManager::$appManager is not defined (see https://psalm.dev/041)
continue; // if not interested and app is not installed
}

$done = ($filterKnownMigrations) ? $this->getKnownMigrations($appId) : [];
$appsAttributes[$appId] = $this->parseMigrations($metadata['apps'][$appId] ?? [], $done);
}

$done = ($filterKnownMigrations) ? $this->getKnownMigrations('core') : [];
return [
'core' => $this->parseMigrations($metadata['core'] ?? [], $done),
'apps' => $appsAttributes
];
}

/**
* convert raw data to a list of MigrationAttribute
*
* @param array $migrations
* @param array $ignoreMigrations
*
* @return array<string, MigrationAttribute[]>
*/
private function parseMigrations(array $migrations, array $ignoreMigrations = []): array {
$parsed = [];
foreach (array_keys($migrations) as $entry) {
if (in_array($entry, $ignoreMigrations)) {
continue;
}

$parsed[$entry] = [];
foreach ($migrations[$entry] as $item) {
try {
$parsed[$entry][] = $this->createAttribute($item);
} catch (AttributeException $e) {
$this->logger->warning('exception while trying to create attribute', ['exception' => $e, 'item' => json_encode($item)]);

Check failure

Code scanning / Psalm

UndefinedThisPropertyFetch Error

Instance property OC\Migration\MetadataManager::$logger is not defined

Check failure on line 111 in lib/private/Migration/MetadataManager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedThisPropertyFetch

lib/private/Migration/MetadataManager.php:111:6: UndefinedThisPropertyFetch: Instance property OC\Migration\MetadataManager::$logger is not defined (see https://psalm.dev/041)
$parsed[$entry][] = new GenericMigrationAttribute($item);

Check failure

Code scanning / Psalm

TooManyArguments Error

Too many arguments for OCP\Migration\Attributes\GenericMigrationAttribute::__construct - expecting 0 but saw 1

Check failure on line 112 in lib/private/Migration/MetadataManager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

TooManyArguments

lib/private/Migration/MetadataManager.php:112:26: TooManyArguments: Too many arguments for OCP\Migration\Attributes\GenericMigrationAttribute::__construct - expecting 0 but saw 1 (see https://psalm.dev/026)
}
}
}

return $parsed;
}

/**
* returns migrations already done
*
* @param string $appId
*
* @return array
* @throws \Exception
*/
private function getKnownMigrations(string $appId): array {
$ms = new MigrationService($appId, $this->connection);

Check failure

Code scanning / Psalm

UndefinedThisPropertyFetch Error

Instance property OC\Migration\MetadataManager::$connection is not defined

Check failure on line 129 in lib/private/Migration/MetadataManager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedThisPropertyFetch

lib/private/Migration/MetadataManager.php:129:38: UndefinedThisPropertyFetch: Instance property OC\Migration\MetadataManager::$connection is not defined (see https://psalm.dev/041)
return $ms->getMigratedVersions();
}

/**
* generate (deserialize) a MigrationAttribute from a serialized version
*
* @param array $item
*
* @return MigrationAttribute
* @throws AttributeException
*/
private function createAttribute(array $item): MigrationAttribute {
$class = $item['class'] ?? '';
$namespace = 'OCP\Migration\Attributes\\';
if (!str_starts_with($class, $namespace)
|| !ctype_alpha(substr($class, strlen($namespace)))) {
throw new AttributeException('class name does not looks valid');
}

try {
$attribute = new $class($item['table'] ?? '');
return $attribute->import($item);
} catch (\Error) {
throw new AttributeException('cannot import Attribute');
}
}
}
17 changes: 17 additions & 0 deletions lib/private/Updater/Exceptions/ReleaseMetadataException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Updater\Exceptions;

use Exception;

/**
* @since 30.0.0
*/
class ReleaseMetadataException extends Exception {
}
Loading

0 comments on commit 7b67067

Please sign in to comment.