diff --git a/app/config/config.yml b/app/config/config.yml index 96412a383..d1d83f22b 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -95,6 +95,8 @@ doctrine_migrations: version_column_name: 'version' version_column_length: 192 executed_at_column_name: 'executed_at' + services: + Doctrine\Migrations\Version\MigrationFactory: Wallabag\Doctrine\MigrationFactoryDecorator fos_rest: param_fetcher_listener: true diff --git a/app/config/services.yml b/app/config/services.yml index 34c1bd13c..662a858ef 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -30,6 +30,7 @@ services: $storeArticleHeaders: '@=service(''craue_config'').get(''store_article_headers'')' $supportUrl: '@=service(''craue_config'').get(''wallabag_support_url'')' $fonts: '%wallabag.fonts%' + $defaultIgnoreOriginInstanceRules: '%wallabag.default_ignore_origin_instance_rules%' Wallabag\: resource: '../../src/*' @@ -107,6 +108,9 @@ services: $rabbitMqProducer: '@old_sound_rabbit_mq.import_pocket_html_producer' $redisProducer: '@wallabag.producer.redis.pocket_html' + Wallabag\Doctrine\MigrationFactoryDecorator: + decorates: doctrine.migrations.migrations_factory + Doctrine\DBAL\Connection: alias: doctrine.dbal.default_connection diff --git a/migrations/Version20160410190541.php b/migrations/Version20160410190541.php index e6374ae5f..c99b9f666 100644 --- a/migrations/Version20160410190541.php +++ b/migrations/Version20160410190541.php @@ -21,9 +21,7 @@ class Version20160410190541 extends WallabagMigration 'length' => 23, ]); - $sharePublic = $this->container - ->get('doctrine.orm.default_entity_manager') - ->getConnection() + $sharePublic = $this->connection ->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'share_public'"); if (false === $sharePublic) { diff --git a/migrations/Version20160911214952.php b/migrations/Version20160911214952.php index 2029a2445..078d95f0c 100644 --- a/migrations/Version20160911214952.php +++ b/migrations/Version20160911214952.php @@ -12,18 +12,14 @@ class Version20160911214952 extends WallabagMigration { public function up(Schema $schema): void { - $redis = $this->container - ->get('doctrine.orm.default_entity_manager') - ->getConnection() + $redis = $this->connection ->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'import_with_redis'"); if (false === $redis) { $this->addSql('INSERT INTO ' . $this->getTable('craue_config_setting') . " (name, value, section) VALUES ('import_with_redis', 0, 'import')"); } - $rabbitmq = $this->container - ->get('doctrine.orm.default_entity_manager') - ->getConnection() + $rabbitmq = $this->connection ->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'import_with_rabbitmq'"); if (false === $rabbitmq) { diff --git a/migrations/Version20161031132655.php b/migrations/Version20161031132655.php index e5a3567ab..00f67004c 100644 --- a/migrations/Version20161031132655.php +++ b/migrations/Version20161031132655.php @@ -12,9 +12,7 @@ class Version20161031132655 extends WallabagMigration { public function up(Schema $schema): void { - $images = $this->container - ->get('doctrine.orm.default_entity_manager') - ->getConnection() + $images = $this->connection ->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'download_images_enabled'"); $this->skipIf(false !== $images, 'It seems that you already played this migration.'); diff --git a/migrations/Version20161117071626.php b/migrations/Version20161117071626.php index 954fd4aa5..ba690099c 100644 --- a/migrations/Version20161117071626.php +++ b/migrations/Version20161117071626.php @@ -12,18 +12,14 @@ class Version20161117071626 extends WallabagMigration { public function up(Schema $schema): void { - $share = $this->container - ->get('doctrine.orm.default_entity_manager') - ->getConnection() + $share = $this->connection ->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'share_unmark'"); if (false === $share) { $this->addSql('INSERT INTO ' . $this->getTable('craue_config_setting') . " (name, value, section) VALUES ('share_unmark', 0, 'entry')"); } - $unmark = $this->container - ->get('doctrine.orm.default_entity_manager') - ->getConnection() + $unmark = $this->connection ->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'unmark_url'"); if (false === $unmark) { diff --git a/migrations/Version20161122144743.php b/migrations/Version20161122144743.php index 5082ecf3f..bdea4934c 100644 --- a/migrations/Version20161122144743.php +++ b/migrations/Version20161122144743.php @@ -12,9 +12,7 @@ class Version20161122144743 extends WallabagMigration { public function up(Schema $schema): void { - $access = $this->container - ->get('doctrine.orm.default_entity_manager') - ->getConnection() + $access = $this->connection ->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'restricted_access'"); $this->skipIf(false !== $access, 'It seems that you already played this migration.'); diff --git a/migrations/Version20170327194233.php b/migrations/Version20170327194233.php index a8d39ce9b..d617cfd99 100644 --- a/migrations/Version20170327194233.php +++ b/migrations/Version20170327194233.php @@ -12,9 +12,7 @@ class Version20170327194233 extends WallabagMigration { public function up(Schema $schema): void { - $scuttle = $this->container - ->get('doctrine.orm.default_entity_manager') - ->getConnection() + $scuttle = $this->connection ->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'share_scuttle'"); $this->skipIf(false !== $scuttle, 'It seems that you already played this migration.'); diff --git a/migrations/Version20170420134133.php b/migrations/Version20170420134133.php index de0e59f42..dc4059f14 100644 --- a/migrations/Version20170420134133.php +++ b/migrations/Version20170420134133.php @@ -17,9 +17,7 @@ class Version20170420134133 extends WallabagMigration public function down(Schema $schema): void { - $downloadPictures = $this->container - ->get('doctrine.orm.default_entity_manager') - ->getConnection() + $downloadPictures = $this->connection ->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'download_pictures'"); $this->skipIf(false !== $downloadPictures, 'It seems that you already played this migration.'); diff --git a/migrations/Version20170602075214.php b/migrations/Version20170602075214.php index 31267efab..d402c1eb2 100644 --- a/migrations/Version20170602075214.php +++ b/migrations/Version20170602075214.php @@ -12,9 +12,7 @@ class Version20170602075214 extends WallabagMigration { public function up(Schema $schema): void { - $apiUserRegistration = $this->container - ->get('doctrine.orm.default_entity_manager') - ->getConnection() + $apiUserRegistration = $this->connection ->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'api_user_registration'"); $this->skipIf(false !== $apiUserRegistration, 'It seems that you already played this migration.'); diff --git a/migrations/Version20170606155640.php b/migrations/Version20170606155640.php index 584dee95b..75721712e 100644 --- a/migrations/Version20170606155640.php +++ b/migrations/Version20170606155640.php @@ -19,9 +19,7 @@ class Version20170606155640 extends WallabagMigration return; } - $apiUserRegistration = $this->container - ->get('doctrine.orm.default_entity_manager') - ->getConnection() + $apiUserRegistration = $this->connection ->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'wallabag_url'"); if (false === $apiUserRegistration) { diff --git a/migrations/Version20171120163128.php b/migrations/Version20171120163128.php index c3bb7ac95..d6f019fba 100644 --- a/migrations/Version20171120163128.php +++ b/migrations/Version20171120163128.php @@ -12,9 +12,7 @@ class Version20171120163128 extends WallabagMigration { public function up(Schema $schema): void { - $storeArticleHeaders = $this->container - ->get('doctrine.orm.default_entity_manager') - ->getConnection() + $storeArticleHeaders = $this->connection ->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'store_article_headers'"); $this->skipIf(false !== $storeArticleHeaders, 'It seems that you already played this migration.'); diff --git a/migrations/Version20171125164500.php b/migrations/Version20171125164500.php index 17b4fb3ce..3211a4b65 100644 --- a/migrations/Version20171125164500.php +++ b/migrations/Version20171125164500.php @@ -12,9 +12,7 @@ class Version20171125164500 extends WallabagMigration { public function up(Schema $schema): void { - $shaarliShareOriginUrl = $this->container - ->get('doctrine.orm.default_entity_manager') - ->getConnection() + $shaarliShareOriginUrl = $this->connection ->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'shaarli_share_origin_url'"); $this->skipIf(false !== $shaarliShareOriginUrl, 'It seems that you already played this migration.'); diff --git a/migrations/Version20190129120000.php b/migrations/Version20190129120000.php index 176f41d96..6007aa649 100644 --- a/migrations/Version20190129120000.php +++ b/migrations/Version20190129120000.php @@ -121,9 +121,7 @@ final class Version20190129120000 extends WallabagMigration public function up(Schema $schema): void { foreach ($this->settings as $setting) { - $settingEnabled = $this->container - ->get('doctrine.orm.default_entity_manager') - ->getConnection() + $settingEnabled = $this->connection ->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = '" . $setting['name'] . "'"); if (false !== $settingEnabled) { diff --git a/migrations/Version20190826204730.php b/migrations/Version20190826204730.php index 59d4e4008..170bf873c 100644 --- a/migrations/Version20190826204730.php +++ b/migrations/Version20190826204730.php @@ -45,10 +45,8 @@ final class Version20190826204730 extends WallabagMigration public function postUp(Schema $schema): void { - foreach ($this->container->getParameter('wallabag.default_ignore_origin_instance_rules') as $entity) { - $previous_rule = $this->container - ->get('doctrine.orm.default_entity_manager') - ->getConnection() + foreach ($this->defaultIgnoreOriginInstanceRules as $entity) { + $previous_rule = $this->connection ->fetchOne('SELECT * FROM ' . $this->getTable('ignore_origin_instance_rule') . " WHERE rule = '" . $entity['rule'] . "'"); if (false === $previous_rule) { diff --git a/migrations/Version20230728093912.php b/migrations/Version20230728093912.php index 74394ecce..e6b11c09a 100644 --- a/migrations/Version20230728093912.php +++ b/migrations/Version20230728093912.php @@ -37,7 +37,7 @@ final class Version20230728093912 extends WallabagMigration 'UPDATE ' . $this->getTable('entry') . ' SET is_not_parsed = :isNotParsed WHERE content LIKE :content', [ 'isNotParsed' => true, - 'content' => str_replace("\n", '', addslashes($this->container->getParameter('wallabag.fetching_error_message'))) . '%', + 'content' => str_replace("\n", '', addslashes($this->fetchingErrorMessage)) . '%', ] ); } diff --git a/migrations/Version20240521152037.php b/migrations/Version20240521152037.php index 5f4eda065..44cf660eb 100644 --- a/migrations/Version20240521152037.php +++ b/migrations/Version20240521152037.php @@ -12,18 +12,14 @@ final class Version20240521152037 extends WallabagMigration { public function up(Schema $schema): void { - $share = $this->container - ->get('doctrine.orm.default_entity_manager') - ->getConnection() + $share = $this->connection ->fetchOne('SELECT * FROM ' . $this->getTable('internal_setting') . " WHERE name = 'share_linkding'"); if (false === $share) { $this->addSql('INSERT INTO ' . $this->getTable('internal_setting') . " (name, value, section) VALUES ('share_linkding', 0, 'entry')"); } - $linkding = $this->container - ->get('doctrine.orm.default_entity_manager') - ->getConnection() + $linkding = $this->connection ->fetchOne('SELECT * FROM ' . $this->getTable('internal_setting') . " WHERE name = 'linkding_url'"); if (false === $linkding) { diff --git a/src/Doctrine/MigrationFactoryDecorator.php b/src/Doctrine/MigrationFactoryDecorator.php new file mode 100644 index 000000000..2872159f2 --- /dev/null +++ b/src/Doctrine/MigrationFactoryDecorator.php @@ -0,0 +1,38 @@ +migrationFactory = $migrationFactory; + $this->tablePrefix = $tablePrefix; + $this->defaultIgnoreOriginInstanceRules = $defaultIgnoreOriginInstanceRules; + $this->fetchingErrorMessage = $fetchingErrorMessage; + } + + public function createVersion(string $migrationClassName): AbstractMigration + { + $instance = $this->migrationFactory->createVersion($migrationClassName); + + if ($instance instanceof WallabagMigration) { + $instance->setTablePrefix($this->tablePrefix); + $instance->setDefaultIgnoreOriginInstanceRules($this->defaultIgnoreOriginInstanceRules); + $instance->setFetchingErrorMessage($this->fetchingErrorMessage); + } + + return $instance; + } +} diff --git a/src/Doctrine/WallabagMigration.php b/src/Doctrine/WallabagMigration.php index af9358b69..60d0a026c 100644 --- a/src/Doctrine/WallabagMigration.php +++ b/src/Doctrine/WallabagMigration.php @@ -5,17 +5,14 @@ namespace Wallabag\Doctrine; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; -use Symfony\Component\DependencyInjection\ContainerAwareInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; -abstract class WallabagMigration extends AbstractMigration implements ContainerAwareInterface +abstract class WallabagMigration extends AbstractMigration { public const UN_ESCAPED_TABLE = true; - /** - * @var ContainerInterface - */ - protected $container; + protected string $tablePrefix; + protected array $defaultIgnoreOriginInstanceRules; + protected string $fetchingErrorMessage; // because there are declared as abstract in `AbstractMigration` we need to delarer here too public function up(Schema $schema): void @@ -26,11 +23,6 @@ abstract class WallabagMigration extends AbstractMigration implements ContainerA { } - public function setContainer(?ContainerInterface $container = null) - { - $this->container = $container; - } - /** * @todo remove when upgrading DoctrineMigration (only needed for PHP 8) * @@ -41,9 +33,24 @@ abstract class WallabagMigration extends AbstractMigration implements ContainerA return false; } + public function setTablePrefix(string $tablePrefix): void + { + $this->tablePrefix = $tablePrefix; + } + + public function setDefaultIgnoreOriginInstanceRules(array $defaultIgnoreOriginInstanceRules): void + { + $this->defaultIgnoreOriginInstanceRules = $defaultIgnoreOriginInstanceRules; + } + + public function setFetchingErrorMessage(string $fetchingErrorMessage): void + { + $this->fetchingErrorMessage = $fetchingErrorMessage; + } + protected function getTable($tableName, $unEscaped = false) { - $table = $this->container->getParameter('database_table_prefix') . $tableName; + $table = $this->tablePrefix . $tableName; if (self::UN_ESCAPED_TABLE === $unEscaped) { return $table;