Skip to content

Commit

Permalink
fix(migration-attributes): privatizing AttributeException
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <[email protected]>
  • Loading branch information
ArtificialOwl committed Jul 26, 2024
1 parent ff4f309 commit 9538865
Show file tree
Hide file tree
Showing 19 changed files with 215 additions and 25 deletions.
7 changes: 4 additions & 3 deletions core/Command/Db/Migrations/GenerateMetadataCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @since 30.0.0
*/
class GenerateMetadataCommand extends Command {
public function __construct(
private readonly MetadataManager $metadataManager,
Expand Down Expand Up @@ -43,9 +46,7 @@ public function execute(InputInterface $input, OutputInterface $output): int {
return 0;
}



public function extractMigrationMetadata(): array {
private function extractMigrationMetadata(): array {
return [
'core' => $this->extractMigrationMetadataFromCore(),
'apps' => $this->extractMigrationMetadataFromApps()
Expand Down
3 changes: 3 additions & 0 deletions core/Command/Db/Migrations/PreviewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
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(
Expand Down
10 changes: 5 additions & 5 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,6 @@
'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',
<<<<<<< HEAD
'OCP\\Mail\\Provider\\Address' => $baseDir . '/lib/public/Mail/Provider/Address.php',
'OCP\\Mail\\Provider\\Attachment' => $baseDir . '/lib/public/Mail/Provider/Attachment.php',
'OCP\\Mail\\Provider\\Exception\\Exception' => $baseDir . '/lib/public/Mail/Provider/Exception/Exception.php',
Expand All @@ -585,24 +584,21 @@
'OCP\\Mail\\Provider\\IProvider' => $baseDir . '/lib/public/Mail/Provider/IProvider.php',
'OCP\\Mail\\Provider\\IService' => $baseDir . '/lib/public/Mail/Provider/IService.php',
'OCP\\Mail\\Provider\\Message' => $baseDir . '/lib/public/Mail/Provider/Message.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\\DeleteTable' => $baseDir . '/lib/public/Migration/Attributes/DeleteTable.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',
>>>>>>> 2f771df35a9 (feat(upgrade): migration attributes)
'OCP\\Migration\\BigIntMigration' => $baseDir . '/lib/public/Migration/BigIntMigration.php',
'OCP\\Migration\\Exceptions\\AttributeException' => $baseDir . '/lib/public/Migration/Exceptions/AttributeException.php',
'OCP\\Migration\\IMigrationStep' => $baseDir . '/lib/public/Migration/IMigrationStep.php',
'OCP\\Migration\\IOutput' => $baseDir . '/lib/public/Migration/IOutput.php',
'OCP\\Migration\\IRepairStep' => $baseDir . '/lib/public/Migration/IRepairStep.php',
Expand Down Expand Up @@ -1672,6 +1668,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 @@ -1961,6 +1959,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
10 changes: 5 additions & 5 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,6 @@ 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',
<<<<<<< HEAD
'OCP\\Mail\\Provider\\Address' => __DIR__ . '/../../..' . '/lib/public/Mail/Provider/Address.php',
'OCP\\Mail\\Provider\\Attachment' => __DIR__ . '/../../..' . '/lib/public/Mail/Provider/Attachment.php',
'OCP\\Mail\\Provider\\Exception\\Exception' => __DIR__ . '/../../..' . '/lib/public/Mail/Provider/Exception/Exception.php',
Expand All @@ -618,24 +617,21 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\Mail\\Provider\\IProvider' => __DIR__ . '/../../..' . '/lib/public/Mail/Provider/IProvider.php',
'OCP\\Mail\\Provider\\IService' => __DIR__ . '/../../..' . '/lib/public/Mail/Provider/IService.php',
'OCP\\Mail\\Provider\\Message' => __DIR__ . '/../../..' . '/lib/public/Mail/Provider/Message.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\\DeleteTable' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/DeleteTable.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',
>>>>>>> 2f771df35a9 (feat(upgrade): migration attributes)
'OCP\\Migration\\BigIntMigration' => __DIR__ . '/../../..' . '/lib/public/Migration/BigIntMigration.php',
'OCP\\Migration\\Exceptions\\AttributeException' => __DIR__ . '/../../..' . '/lib/public/Migration/Exceptions/AttributeException.php',
'OCP\\Migration\\IMigrationStep' => __DIR__ . '/../../..' . '/lib/public/Migration/IMigrationStep.php',
'OCP\\Migration\\IOutput' => __DIR__ . '/../../..' . '/lib/public/Migration/IOutput.php',
'OCP\\Migration\\IRepairStep' => __DIR__ . '/../../..' . '/lib/public/Migration/IRepairStep.php',
Expand Down Expand Up @@ -1705,6 +1701,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 @@ -1994,6 +1992,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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Migration\Exceptions;
namespace OC\Migration\Exceptions;

use Exception;

Expand Down
8 changes: 4 additions & 4 deletions lib/private/Migration/MetadataManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

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 OCP\Migration\Exceptions\AttributeException;
use Psr\Log\LoggerInterface;
use ReflectionClass;

Expand Down Expand Up @@ -58,10 +58,10 @@ public function extractMigrationAttributes(string $appId): array {
/**
* convert direct data from release metadata into a list of Migrations' Attribute
*
* @param array $metadata
* @param array<array-key, array<array-key, array>> $metadata
* @param bool $filterKnownMigrations ignore metadata already done in local instance
*
* @return array
* @return array{apps: array<array-key, array<string, MigrationAttribute[]>>, core: array<string, MigrationAttribute[]>}
* @since 30.0.0
*/
public function getMigrationsAttributesFromReleaseMetadata(
Expand All @@ -73,6 +73,7 @@ public function getMigrationsAttributesFromReleaseMetadata(
if ($filterKnownMigrations && !$this->appManager->isInstalled($appId)) {
continue; // if not interested and app is not installed
}

$done = ($filterKnownMigrations) ? $this->getKnownMigrations($appId) : [];
$appsAttributes[$appId] = $this->parseMigrations($metadata['apps'][$appId] ?? [], $done);
}
Expand Down Expand Up @@ -126,7 +127,6 @@ private function getKnownMigrations(string $appId): array {
return $ms->getMigratedVersions();
}


/**
* generate (deserialize) a MigrationAttribute from a serialized version
*
Expand Down
7 changes: 7 additions & 0 deletions lib/public/Migration/Attributes/AddColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@

use Attribute;

/**
* @since 30.0.0
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
class AddColumn extends ColumnMigrationAttribute {
/**
* @return string
* @since 30.0.0
*/
public function definition(): string {
$type = is_null($this->getType()) ? '' : ' (' . $this->getType()->value . ')';
$table = empty($this->getTable()) ? '' : ' to table \'' . $this->getTable() . '\'';
Expand Down
7 changes: 7 additions & 0 deletions lib/public/Migration/Attributes/AddIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@

use Attribute;

/**
* @since 30.0.0
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
class AddIndex extends IndexMigrationAttribute {
/**
* @return string
* @since 30.0.0
*/
public function definition(): string {
$type = is_null($this->getType()) ? '' : ' (' . $this->getType()->value . ')';
$table = empty($this->getTable()) ? '' : ' to table \'' . $this->getTable() . '\'';
Expand Down
33 changes: 33 additions & 0 deletions lib/public/Migration/Attributes/ColumnMigrationAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

use JsonSerializable;

/**
* @since 30.0.0
*/
class ColumnMigrationAttribute extends MigrationAttribute implements JsonSerializable {
public function __construct(

Check failure on line 17 in lib/public/Migration/Attributes/ColumnMigrationAttribute.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-ocp

InvalidDocblock

lib/public/Migration/Attributes/ColumnMigrationAttribute.php:17:2: InvalidDocblock: PHPDoc is required for methods in OCP. (see https://psalm.dev/008)
string $table = '',
Expand All @@ -21,31 +24,61 @@ public function __construct(
parent::__construct($table, $description, $notes);
}

/**
* @param string $name
*
* @return $this
* @since 30.0.0
*/
public function setName(string $name): self {
$this->name = $name;
return $this;
}

/**
* @return string
* @since 30.0.0
*/
public function getName(): string {
return $this->name;
}

/**
* @param ColumnType|null $type
*
* @return $this
* @since 30.0.0
*/
public function setType(?ColumnType $type): self {
$this->type = $type;
return $this;
}

/**
* @return ColumnType|null
* @since 30.0.0
*/
public function getType(): ?ColumnType {
return $this->type;
}

/**
* @param array $data
*
* @return $this
* @since 30.0.0
*/
public function import(array $data): self {
parent::import($data);
$this->setName($data['name'] ?? '');
$this->setType(ColumnType::tryFrom($data['type'] ?? ''));
return $this;
}

/**
* @return array
* @since 30.0.0
*/
public function jsonSerialize(): array {
return array_merge(
parent::jsonSerialize(),
Expand Down
9 changes: 8 additions & 1 deletion lib/public/Migration/Attributes/CreateTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@

use Attribute;

/**
* @since 30.0.0
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
class CreateTable extends TableMigrationAttribute {
/**
* @return string
* @since 30.0.0
*/
public function definition(): string {
$definition = empty($this->getTable()) ? 'Creation of a new table' : 'Creation of new table \'' . $this->getTable() . '\'';
$definition = 'Creation of new table \'' . $this->getTable() . '\'';
$definition .= empty($this->getColumns()) ? '' : ' with columns ' . implode(', ', $this->getColumns());
return $definition;
}
Expand Down
7 changes: 7 additions & 0 deletions lib/public/Migration/Attributes/DropColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@

use Attribute;

/**
* @since 30.0.0
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
class DropColumn extends ColumnMigrationAttribute {
/**
* @return string
* @since 30.0.0
*/
public function definition(): string {
$table = empty($this->getTable()) ? '' : ' from table \'' . $this->getTable() . '\'';
return empty($this->getName()) ?
Expand Down
7 changes: 7 additions & 0 deletions lib/public/Migration/Attributes/DropIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@

use Attribute;

/**
* @since 30.0.0
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
class DropIndex extends IndexMigrationAttribute {
/**
* @return string
* @since 30.0.0
*/
public function definition(): string {
return empty($this->getTable()) ?
'Deletion of an index'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@

use Attribute;

/**
*
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]

Check failure on line 16 in lib/public/Migration/Attributes/DropTable.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-ocp

InvalidDocblock

lib/public/Migration/Attributes/DropTable.php:16:1: InvalidDocblock: @SInCE is required for classes/interfaces in OCP. (see https://psalm.dev/008)
class DeleteTable extends MigrationAttribute {
class DropTable extends TableMigrationAttribute {
/**
* @return string
* @since 30.0.0
*/
public function definition(): string {
return empty($this->getTable()) ? 'Deletion of a table' : 'Deletion of table \'' . $this->getTable() . '\'';
return 'Deletion of table \'' . $this->getTable() . '\'';
}
}
11 changes: 11 additions & 0 deletions lib/public/Migration/Attributes/GenericMigrationAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

use JsonSerializable;

/**
* @since 30.0.0
*/
class GenericMigrationAttribute extends MigrationAttribute implements JsonSerializable {
public function __construct(

Check failure on line 17 in lib/public/Migration/Attributes/GenericMigrationAttribute.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-ocp

InvalidDocblock

lib/public/Migration/Attributes/GenericMigrationAttribute.php:17:2: InvalidDocblock: PHPDoc is required for methods in OCP. (see https://psalm.dev/008)
private readonly array $details = []
Expand All @@ -21,10 +24,18 @@ public function __construct(
);
}

/**
* @return string
* @since 30.0.0
*/
public function definition(): string {
return json_encode($this->jsonSerialize(), JSON_UNESCAPED_SLASHES);
}

/**
* @return array
* @since 30.0.0
*/
public function jsonSerialize(): array {
return $this->details;
}
Expand Down
Loading

0 comments on commit 9538865

Please sign in to comment.