diff --git a/bin/doctrine-migrations-diff.sh b/bin/doctrine-migrations-diff.sh index 189d22ed5..4350c0599 100755 --- a/bin/doctrine-migrations-diff.sh +++ b/bin/doctrine-migrations-diff.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -bin/console doctrine:migrations:diff --em=middleware --filter-expression='~^(?!event_stream).*$~' +bin/console doctrine:migrations:diff --em=middleware --env=dev --filter-expression='~^(?!event_stream).*$~' sleep 1 -bin/console doctrine:migrations:diff --em=gateway \ No newline at end of file +bin/console doctrine:migrations:diff --em=gateway --env=dev \ No newline at end of file diff --git a/ci/qa/phpstan-baseline.neon b/ci/qa/phpstan-baseline.neon index a0e51d67c..dd7e15771 100644 --- a/ci/qa/phpstan-baseline.neon +++ b/ci/qa/phpstan-baseline.neon @@ -1,185 +1,5 @@ parameters: ignoreErrors: - - - message: "#^Cannot call method getParameter\\(\\) on Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\|null\\.$#" - count: 2 - path: ../../src/Surfnet/Migrations/Version20141125173004.php - - - - message: "#^Method Surfnet\\\\Migrations\\\\Version20141125173004\\:\\:getGatewaySchema\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20141125173004.php - - - - message: "#^Method Surfnet\\\\Migrations\\\\Version20141125173004\\:\\:getMiddlewareUser\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20141125173004.php - - - - message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, array\\|bool\\|float\\|int\\|string\\|null given\\.$#" - count: 4 - path: ../../src/Surfnet/Migrations/Version20141125173004.php - - - - message: "#^Parameter \\#3 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, array\\|bool\\|float\\|int\\|string\\|null given\\.$#" - count: 2 - path: ../../src/Surfnet/Migrations/Version20141125173004.php - - - - message: "#^Cannot call method getParameter\\(\\) on Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\|null\\.$#" - count: 2 - path: ../../src/Surfnet/Migrations/Version20141209150426.php - - - - message: "#^Method Surfnet\\\\Migrations\\\\Version20141209150426\\:\\:getGatewaySchema\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20141209150426.php - - - - message: "#^Method Surfnet\\\\Migrations\\\\Version20141209150426\\:\\:getMiddlewareUser\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20141209150426.php - - - - message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, array\\|bool\\|float\\|int\\|string\\|null given\\.$#" - count: 3 - path: ../../src/Surfnet/Migrations/Version20141209150426.php - - - - message: "#^Parameter \\#3 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, array\\|bool\\|float\\|int\\|string\\|null given\\.$#" - count: 2 - path: ../../src/Surfnet/Migrations/Version20141209150426.php - - - - message: "#^Cannot call method getParameter\\(\\) on Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\|null\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20141210174213.php - - - - message: "#^Method Surfnet\\\\Migrations\\\\Version20141210174213\\:\\:getGatewaySchema\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20141210174213.php - - - - message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, array\\|bool\\|float\\|int\\|string\\|null given\\.$#" - count: 7 - path: ../../src/Surfnet/Migrations/Version20141210174213.php - - - - message: "#^Cannot call method getParameter\\(\\) on Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\|null\\.$#" - count: 2 - path: ../../src/Surfnet/Migrations/Version20150312162849.php - - - - message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, array\\|bool\\|float\\|int\\|string\\|null given\\.$#" - count: 2 - path: ../../src/Surfnet/Migrations/Version20150312162849.php - - - - message: "#^Cannot call method getParameter\\(\\) on Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\|null\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20150508085838.php - - - - message: "#^Method Surfnet\\\\Migrations\\\\Version20150508085838\\:\\:getGatewaySchema\\(\\) should return string but returns array\\|bool\\|float\\|int\\|string\\|null\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20150508085838.php - - - - message: "#^Cannot call method getParameter\\(\\) on Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\|null\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20150522163053.php - - - - message: "#^Method Surfnet\\\\Migrations\\\\Version20150522163053\\:\\:getGatewaySchema\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20150522163053.php - - - - message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, array\\|bool\\|float\\|int\\|string\\|null given\\.$#" - count: 8 - path: ../../src/Surfnet/Migrations/Version20150522163053.php - - - - message: "#^Cannot call method getParameter\\(\\) on Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\|null\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20150522164907.php - - - - message: "#^Method Surfnet\\\\Migrations\\\\Version20150522164907\\:\\:getGatewaySchema\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20150522164907.php - - - - message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, array\\|bool\\|float\\|int\\|string\\|null given\\.$#" - count: 2 - path: ../../src/Surfnet/Migrations/Version20150522164907.php - - - - message: "#^Cannot call method getParameter\\(\\) on Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\|null\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20150528154959.php - - - - message: "#^Method Surfnet\\\\Migrations\\\\Version20150528154959\\:\\:getGatewaySchema\\(\\) should return string but returns array\\|bool\\|float\\|int\\|string\\|null\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20150528154959.php - - - - message: "#^Cannot call method getParameter\\(\\) on Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\|null\\.$#" - count: 3 - path: ../../src/Surfnet/Migrations/Version20150615114646.php - - - - message: "#^Method Surfnet\\\\Migrations\\\\Version20150615114646\\:\\:getGatewaySchema\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20150615114646.php - - - - message: "#^Method Surfnet\\\\Migrations\\\\Version20150615114646\\:\\:getMiddlewareSchema\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20150615114646.php - - - - message: "#^Method Surfnet\\\\Migrations\\\\Version20150615114646\\:\\:getMiddlewareUser\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20150615114646.php - - - - message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, array\\|bool\\|float\\|int\\|string\\|null given\\.$#" - count: 6 - path: ../../src/Surfnet/Migrations/Version20150615114646.php - - - - message: "#^Parameter \\#3 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, array\\|bool\\|float\\|int\\|string\\|null given\\.$#" - count: 2 - path: ../../src/Surfnet/Migrations/Version20150615114646.php - - - - message: "#^Cannot call method getParameter\\(\\) on Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\|null\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20180131150800.php - - - - message: "#^Method Surfnet\\\\Migrations\\\\Version20180131150800\\:\\:getGatewaySchema\\(\\) should return string but returns array\\|bool\\|float\\|int\\|string\\|null\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20180131150800.php - - - - message: "#^Cannot call method getParameter\\(\\) on Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\|null\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20200114161618.php - - - - message: "#^Method Surfnet\\\\Migrations\\\\Version20200114161618\\:\\:getGatewaySchema\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20200114161618.php - - - - message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, array\\|bool\\|float\\|int\\|string\\|null given\\.$#" - count: 2 - path: ../../src/Surfnet/Migrations/Version20200114161618.php - - message: "#^Cannot access offset 'payload' on mixed\\.$#" count: 1 @@ -210,36 +30,6 @@ parameters: count: 1 path: ../../src/Surfnet/Migrations/Version20210610131957.php - - - message: "#^Cannot call method getParameter\\(\\) on Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\|null\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20220519134637.php - - - - message: "#^Method Surfnet\\\\Migrations\\\\Version20220519134637\\:\\:getGatewaySchema\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20220519134637.php - - - - message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, array\\|bool\\|float\\|int\\|string\\|null given\\.$#" - count: 2 - path: ../../src/Surfnet/Migrations/Version20220519134637.php - - - - message: "#^Cannot call method getParameter\\(\\) on Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\|null\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20221102143350.php - - - - message: "#^Method Surfnet\\\\Migrations\\\\Version20221102143350\\:\\:getGatewaySchema\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: ../../src/Surfnet/Migrations/Version20221102143350.php - - - - message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, array\\|bool\\|float\\|int\\|string\\|null given\\.$#" - count: 2 - path: ../../src/Surfnet/Migrations/Version20221102143350.php - - message: "#^Cannot access offset 'email_templates' on mixed\\.$#" count: 1 diff --git a/config/packages/doctrine_migrations.yaml b/config/packages/doctrine_migrations.yaml index 84f8ecdac..fc920395a 100644 --- a/config/packages/doctrine_migrations.yaml +++ b/config/packages/doctrine_migrations.yaml @@ -8,3 +8,5 @@ doctrine_migrations: table_name: 'migration_versions' version_column_name: 'version' version_column_length: 192 + services: + Doctrine\Migrations\Version\MigrationFactory: 'Surfnet\Stepup\MigrationsFactory\ConfigurationMigrationFactory' \ No newline at end of file diff --git a/config/services.yaml b/config/services.yaml index cd898a123..082d1bdf8 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -53,3 +53,10 @@ services: - location - contactInformation - [] # Allowed functions + + Surfnet\Stepup\MigrationsFactory\ConfigurationMigrationFactory: + arguments: + - "@doctrine.migrations.migrations_factory" + - "%database_gateway_name%" + - "%database_middleware_name%" + - "%database_middleware_user%" diff --git a/src/Surfnet/Migrations/Version20141125173004.php b/src/Surfnet/Migrations/Version20141125173004.php index 290c68db7..f8df2b3a6 100644 --- a/src/Surfnet/Migrations/Version20141125173004.php +++ b/src/Surfnet/Migrations/Version20141125173004.php @@ -20,20 +20,15 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; -use Symfony\Component\DependencyInjection\ContainerAwareInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationInterface; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationTrait; /** * Auto-generated Migration: Please modify to your needs! */ -class Version20141125173004 extends AbstractMigration implements ContainerAwareInterface +class Version20141125173004 extends AbstractMigration implements ConfigurationAwareMigrationInterface { - private ?ContainerInterface $container = null; - - public function setContainer(ContainerInterface $container = null): void - { - $this->container = $container; - } + use ConfigurationAwareMigrationTrait; public function up(Schema $schema): void { @@ -73,14 +68,4 @@ public function down(Schema $schema): void ); $this->addSql(sprintf('DROP TABLE %s.saml_entity', $gatewaySchema)); } - - private function getGatewaySchema(): float|array|bool|int|string|null - { - return $this->container->getParameter('database_gateway_name'); - } - - private function getMiddlewareUser(): float|array|bool|int|string|null - { - return $this->container->getParameter('database_middleware_user'); - } } diff --git a/src/Surfnet/Migrations/Version20141209150426.php b/src/Surfnet/Migrations/Version20141209150426.php index a388124e9..3bb0ee217 100644 --- a/src/Surfnet/Migrations/Version20141209150426.php +++ b/src/Surfnet/Migrations/Version20141209150426.php @@ -19,20 +19,18 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationInterface; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationTrait; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Auto-generated Migration: Please modify to your needs! */ -class Version20141209150426 extends AbstractMigration implements ContainerAwareInterface +class Version20141209150426 extends AbstractMigration implements ConfigurationAwareMigrationInterface { - private ?ContainerInterface $container = null; + use ConfigurationAwareMigrationTrait; - public function setContainer(ContainerInterface $container = null): void - { - $this->container = $container; - } public function up(Schema $schema): void { @@ -78,14 +76,4 @@ public function down(Schema $schema): void ); $this->addSql('DROP TABLE second_factor'); } - - private function getGatewaySchema(): float|array|bool|int|string|null - { - return $this->container->getParameter('database_gateway_name'); - } - - private function getMiddlewareUser(): float|array|bool|int|string|null - { - return $this->container->getParameter('database_middleware_user'); - } } diff --git a/src/Surfnet/Migrations/Version20141210174213.php b/src/Surfnet/Migrations/Version20141210174213.php index 36a5234fe..9cfe3e009 100644 --- a/src/Surfnet/Migrations/Version20141210174213.php +++ b/src/Surfnet/Migrations/Version20141210174213.php @@ -20,15 +20,17 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationInterface; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationTrait; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Auto-generated Migration: Please modify to your needs! */ -class Version20141210174213 extends AbstractMigration implements ContainerAwareInterface +class Version20141210174213 extends AbstractMigration implements ConfigurationAwareMigrationInterface { - private ?ContainerInterface $container = null; + use ConfigurationAwareMigrationTrait; public function up(Schema $schema): void { @@ -62,14 +64,4 @@ public function down(Schema $schema): void $this->addSql(sprintf('ALTER TABLE %s.second_factor DROP id', $gatewaySchema)); $this->addSql(sprintf('ALTER TABLE %s.second_factor ADD PRIMARY KEY (identity_id)', $gatewaySchema)); } - - private function getGatewaySchema(): float|array|bool|int|string|null - { - return $this->container->getParameter('database_gateway_name'); - } - - public function setContainer(ContainerInterface $container = null): void - { - $this->container = $container; - } } diff --git a/src/Surfnet/Migrations/Version20150312162849.php b/src/Surfnet/Migrations/Version20150312162849.php index 010a22008..170300ecf 100644 --- a/src/Surfnet/Migrations/Version20150312162849.php +++ b/src/Surfnet/Migrations/Version20150312162849.php @@ -20,15 +20,15 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; -use Symfony\Component\DependencyInjection\ContainerAwareInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationInterface; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationTrait; /** * Auto-generated Migration: Please modify to your needs! */ -class Version20150312162849 extends AbstractMigration implements ContainerAwareInterface +class Version20150312162849 extends AbstractMigration implements ConfigurationAwareMigrationInterface { - private ?ContainerInterface $container = null; + use ConfigurationAwareMigrationTrait; public function up(Schema $schema): void { @@ -38,7 +38,7 @@ public function up(Schema $schema): void 'Migration can only be executed safely on \'mysql\'.', ); - $gatewaySchema = $this->container->getParameter('database_gateway_name'); + $gatewaySchema = $this->getGatewaySchema(); $this->addSql( sprintf( 'ALTER TABLE %s.second_factor CHANGE second_factor_identifier second_factor_identifier VARCHAR(255) NOT NULL', @@ -55,7 +55,7 @@ public function down(Schema $schema): void 'Migration can only be executed safely on \'mysql\'.', ); - $gatewaySchema = $this->container->getParameter('database_gateway_name'); + $gatewaySchema = $this->getGatewaySchema(); $this->addSql( sprintf( 'ALTER TABLE %s.second_factor CHANGE second_factor_identifier second_factor_identifier VARCHAR(36) NOT NULL COLLATE utf8_unicode_ci', @@ -63,9 +63,4 @@ public function down(Schema $schema): void ), ); } - - public function setContainer(ContainerInterface $container = null): void - { - $this->container = $container; - } } diff --git a/src/Surfnet/Migrations/Version20150508085838.php b/src/Surfnet/Migrations/Version20150508085838.php index 8aeecccd4..3b1ac5108 100644 --- a/src/Surfnet/Migrations/Version20150508085838.php +++ b/src/Surfnet/Migrations/Version20150508085838.php @@ -20,20 +20,17 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationInterface; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationTrait; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Auto-generated Migration: Please modify to your needs! */ -class Version20150508085838 extends AbstractMigration implements ContainerAwareInterface +class Version20150508085838 extends AbstractMigration implements ConfigurationAwareMigrationInterface { - private ?ContainerInterface $container = null; - - public function setContainer(ContainerInterface $container = null): void - { - $this->container = $container; - } + use ConfigurationAwareMigrationTrait; /** * @param Schema $schema @@ -75,12 +72,4 @@ public function down(Schema $schema): void $this->addSql(sprintf('ALTER TABLE %s.second_factor ADD id INT PRIMARY KEY AUTO_INCREMENT', $gatewaySchema)); $this->addSql(sprintf('ALTER TABLE %s.second_factor DROP COLUMN uuid', $gatewaySchema)); } - - /** - * @return string - */ - private function getGatewaySchema(): string - { - return $this->container->getParameter('database_gateway_name'); - } } diff --git a/src/Surfnet/Migrations/Version20150522163053.php b/src/Surfnet/Migrations/Version20150522163053.php index 4488eed3e..d43aef09d 100644 --- a/src/Surfnet/Migrations/Version20150522163053.php +++ b/src/Surfnet/Migrations/Version20150522163053.php @@ -19,20 +19,18 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationInterface; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationTrait; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Auto-generated Migration: Please modify to your needs! */ -class Version20150522163053 extends AbstractMigration implements ContainerAwareInterface +class Version20150522163053 extends AbstractMigration implements ConfigurationAwareMigrationInterface { - private ?ContainerInterface $container = null; + use ConfigurationAwareMigrationTrait; - public function setContainer(ContainerInterface $container = null): void - { - $this->container = $container; - } /** * @param Schema $schema @@ -72,8 +70,4 @@ public function down(Schema $schema): void $this->addSql(sprintf('ALTER TABLE %s.saml_entity ADD PRIMARY KEY (entity_id)', $gatewaySchema)); } - private function getGatewaySchema(): float|array|bool|int|string|null - { - return $this->container->getParameter('database_gateway_name'); - } } diff --git a/src/Surfnet/Migrations/Version20150522164907.php b/src/Surfnet/Migrations/Version20150522164907.php index fecb0f9d2..0bd343a8e 100644 --- a/src/Surfnet/Migrations/Version20150522164907.php +++ b/src/Surfnet/Migrations/Version20150522164907.php @@ -20,20 +20,17 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationInterface; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationTrait; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Auto-generated Migration: Please modify to your needs! */ -class Version20150522164907 extends AbstractMigration implements ContainerAwareInterface +class Version20150522164907 extends AbstractMigration implements ConfigurationAwareMigrationInterface { - private ?ContainerInterface $container = null; - - public function setContainer(ContainerInterface $container = null): void - { - $this->container = $container; - } + use ConfigurationAwareMigrationTrait; /** * @param Schema $schema @@ -71,9 +68,4 @@ public function down(Schema $schema): void $this->addSql(sprintf('DROP INDEX unq_saml_entity_entity_id_type ON %s.saml_entity', $gatewaySchema)); } - - private function getGatewaySchema(): float|array|bool|int|string|null - { - return $this->container->getParameter('database_gateway_name'); - } } diff --git a/src/Surfnet/Migrations/Version20150528154959.php b/src/Surfnet/Migrations/Version20150528154959.php index aaab64c1d..90eb359e9 100644 --- a/src/Surfnet/Migrations/Version20150528154959.php +++ b/src/Surfnet/Migrations/Version20150528154959.php @@ -20,20 +20,17 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationInterface; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationTrait; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Auto-generated Migration: Please modify to your needs! */ -class Version20150528154959 extends AbstractMigration implements ContainerAwareInterface +class Version20150528154959 extends AbstractMigration implements ConfigurationAwareMigrationInterface { - private ?ContainerInterface $container = null; - - public function setContainer(ContainerInterface $container = null): void - { - $this->container = $container; - } + use ConfigurationAwareMigrationTrait; /** * @param Schema $schema @@ -66,12 +63,4 @@ public function down(Schema $schema): void $this->addSql(sprintf('ALTER TABLE %s.second_factor DROP display_locale', $gatewaySchema)); } - - /** - * @return string - */ - private function getGatewaySchema(): string - { - return $this->container->getParameter('database_gateway_name'); - } } diff --git a/src/Surfnet/Migrations/Version20150615114646.php b/src/Surfnet/Migrations/Version20150615114646.php index 91642c8d5..ff472375c 100644 --- a/src/Surfnet/Migrations/Version20150615114646.php +++ b/src/Surfnet/Migrations/Version20150615114646.php @@ -20,20 +20,17 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationInterface; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationTrait; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Auto-generated Migration: Please modify to your needs! */ -class Version20150615114646 extends AbstractMigration implements ContainerAwareInterface +class Version20150615114646 extends AbstractMigration implements ConfigurationAwareMigrationInterface { - private ?ContainerInterface $container = null; - - public function setContainer(ContainerInterface $container = null): void - { - $this->container = $container; - } + use ConfigurationAwareMigrationTrait; public function up(Schema $schema): void { @@ -90,19 +87,4 @@ public function down(Schema $schema): void $this->addSql(sprintf('DROP TABLE %s.saml_entity', $middlewareSchema)); $this->addSql(sprintf('DROP TABLE %s.saml_entity', $gatewaySchema)); } - - private function getGatewaySchema(): float|array|bool|int|string|null - { - return $this->container->getParameter('database_gateway_name'); - } - - private function getMiddlewareUser(): float|array|bool|int|string|null - { - return $this->container->getParameter('database_middleware_user'); - } - - private function getMiddlewareSchema(): float|array|bool|int|string|null - { - return $this->container->getParameter('database_middleware_name'); - } } diff --git a/src/Surfnet/Migrations/Version20180131150800.php b/src/Surfnet/Migrations/Version20180131150800.php index 35f45d192..9964700d4 100644 --- a/src/Surfnet/Migrations/Version20180131150800.php +++ b/src/Surfnet/Migrations/Version20180131150800.php @@ -20,20 +20,17 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationInterface; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationTrait; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Update the Gateway `second_factor` table setting the primary key on the `id` and `identity_id` fields. */ -class Version20180131150800 extends AbstractMigration implements ContainerAwareInterface +class Version20180131150800 extends AbstractMigration implements ConfigurationAwareMigrationInterface { - private ?ContainerInterface $container = null; - - public function setContainer(ContainerInterface $container = null): void - { - $this->container = $container; - } + use ConfigurationAwareMigrationTrait; /** * @param Schema $schema @@ -68,12 +65,4 @@ public function down(Schema $schema): void $this->addSql(sprintf('ALTER TABLE %s.second_factor DROP PRIMARY KEY', $gatewaySchema)); $this->addSql(sprintf('ALTER TABLE %s.second_factor ADD PRIMARY KEY (id)', $gatewaySchema)); } - - /** - * @return string - */ - private function getGatewaySchema(): string - { - return $this->container->getParameter('database_gateway_name'); - } } diff --git a/src/Surfnet/Migrations/Version20200114161618.php b/src/Surfnet/Migrations/Version20200114161618.php index 8ec0055e5..595af7569 100644 --- a/src/Surfnet/Migrations/Version20200114161618.php +++ b/src/Surfnet/Migrations/Version20200114161618.php @@ -20,20 +20,17 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationInterface; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationTrait; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Auto-generated Migration: Please modify to your needs! */ -class Version20200114161618 extends AbstractMigration implements ContainerAwareInterface +class Version20200114161618 extends AbstractMigration implements ConfigurationAwareMigrationInterface { - private ?ContainerInterface $container = null; - - public function setContainer(ContainerInterface $container = null): void - { - $this->container = $container; - } + use ConfigurationAwareMigrationTrait; /** * @param Schema $schema @@ -78,9 +75,4 @@ public function down(Schema $schema): void $this->throwIrreversibleMigrationException('This migration is irreversible'); } - - private function getGatewaySchema(): float|array|bool|int|string|null - { - return $this->container->getParameter('database_gateway_name'); - } } diff --git a/src/Surfnet/Migrations/Version20220519134637.php b/src/Surfnet/Migrations/Version20220519134637.php index 995f5748e..9e21e175a 100644 --- a/src/Surfnet/Migrations/Version20220519134637.php +++ b/src/Surfnet/Migrations/Version20220519134637.php @@ -22,20 +22,17 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationInterface; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationTrait; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Adds the Self asserted tokens feature to the middleware and gateway databases */ -final class Version20220519134637 extends AbstractMigration implements ContainerAwareInterface +final class Version20220519134637 extends AbstractMigration implements ConfigurationAwareMigrationInterface { - private ?ContainerInterface $container = null; - - public function setContainer(ContainerInterface $container = null): void - { - $this->container = $container; - } + use ConfigurationAwareMigrationTrait; public function up(Schema $schema): void { @@ -95,9 +92,4 @@ public function down(Schema $schema): void $gatewaySchema = $this->getGatewaySchema(); $this->addSql(sprintf('ALTER TABLE %s.second_factor DROP identity_vetted', $gatewaySchema)); } - - private function getGatewaySchema(): float|array|bool|int|string|null - { - return $this->container->getParameter('database_gateway_name'); - } } diff --git a/src/Surfnet/Migrations/Version20221102143350.php b/src/Surfnet/Migrations/Version20221102143350.php index 1c8cb9911..7f209a80c 100644 --- a/src/Surfnet/Migrations/Version20221102143350.php +++ b/src/Surfnet/Migrations/Version20221102143350.php @@ -22,17 +22,14 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationInterface; +use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationTrait; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -final class Version20221102143350 extends AbstractMigration implements ContainerAwareInterface +final class Version20221102143350 extends AbstractMigration implements ConfigurationAwareMigrationInterface { - private ?ContainerInterface $container = null; - - public function setContainer(ContainerInterface $container = null): void - { - $this->container = $container; - } + use ConfigurationAwareMigrationTrait; public function up(Schema $schema): void { @@ -64,9 +61,4 @@ public function down(Schema $schema): void $gatewaySchema = $this->getGatewaySchema(); $this->addSql(sprintf('DROP TABLE %s.institution_configuration', $gatewaySchema)); } - - private function getGatewaySchema(): float|array|bool|int|string|null - { - return $this->container->getParameter('database_gateway_name'); - } } diff --git a/src/Surfnet/Stepup/MigrationsFactory/ConfigurationAwareMigrationInterface.php b/src/Surfnet/Stepup/MigrationsFactory/ConfigurationAwareMigrationInterface.php new file mode 100644 index 000000000..6f56d876a --- /dev/null +++ b/src/Surfnet/Stepup/MigrationsFactory/ConfigurationAwareMigrationInterface.php @@ -0,0 +1,26 @@ +gatewaySchema = $gatewaySchema; + $this->middlewareSchema = $middlewareSchema; + $this->middlewareUser = $middlewareUser; + } + + public function getGatewaySchema(): string + { + if (empty($this->gatewaySchema)) { + throw new RuntimeException("Gateway schema must be set"); + } + return $this->gatewaySchema; + } + + public function getMiddlewareSchema(): string + { + if (empty($this->middlewareSchema)) { + throw new RuntimeException("Middleware schema must be set"); + } + return $this->middlewareSchema; + } + + public function getMiddlewareUser(): string + { + if (empty($this->middlewareUser)) { + throw new RuntimeException("Middleware user must be set"); + } + return $this->middlewareUser; + } +} diff --git a/src/Surfnet/Stepup/MigrationsFactory/ConfigurationMigrationFactory.php b/src/Surfnet/Stepup/MigrationsFactory/ConfigurationMigrationFactory.php new file mode 100644 index 000000000..34dc1322c --- /dev/null +++ b/src/Surfnet/Stepup/MigrationsFactory/ConfigurationMigrationFactory.php @@ -0,0 +1,46 @@ +migrationFactory->createVersion($migrationClassName); + + if ($migration instanceof ConfigurationAwareMigrationInterface) { + $migration->setConfiguration($this->gatewaySchema, $this->middlewareSchema, $this->middlewareUser); + } + + return $migration; + } +}