1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-06-27 16:36:00 +00:00

Stop using ContainerAwareInterface in migrations

This commit is contained in:
Yassine Guedidi 2025-01-18 14:44:31 +01:00
parent bcf0f2f52c
commit e715da7e91
19 changed files with 83 additions and 66 deletions

View file

@ -95,6 +95,8 @@ doctrine_migrations:
version_column_name: 'version' version_column_name: 'version'
version_column_length: 192 version_column_length: 192
executed_at_column_name: 'executed_at' executed_at_column_name: 'executed_at'
services:
Doctrine\Migrations\Version\MigrationFactory: Wallabag\Doctrine\MigrationFactoryDecorator
fos_rest: fos_rest:
param_fetcher_listener: true param_fetcher_listener: true

View file

@ -30,6 +30,7 @@ services:
$storeArticleHeaders: '@=service(''craue_config'').get(''store_article_headers'')' $storeArticleHeaders: '@=service(''craue_config'').get(''store_article_headers'')'
$supportUrl: '@=service(''craue_config'').get(''wallabag_support_url'')' $supportUrl: '@=service(''craue_config'').get(''wallabag_support_url'')'
$fonts: '%wallabag.fonts%' $fonts: '%wallabag.fonts%'
$defaultIgnoreOriginInstanceRules: '%wallabag.default_ignore_origin_instance_rules%'
Wallabag\: Wallabag\:
resource: '../../src/*' resource: '../../src/*'
@ -107,6 +108,9 @@ services:
$rabbitMqProducer: '@old_sound_rabbit_mq.import_pocket_html_producer' $rabbitMqProducer: '@old_sound_rabbit_mq.import_pocket_html_producer'
$redisProducer: '@wallabag.producer.redis.pocket_html' $redisProducer: '@wallabag.producer.redis.pocket_html'
Wallabag\Doctrine\MigrationFactoryDecorator:
decorates: doctrine.migrations.migrations_factory
Doctrine\DBAL\Connection: Doctrine\DBAL\Connection:
alias: doctrine.dbal.default_connection alias: doctrine.dbal.default_connection

View file

@ -21,9 +21,7 @@ class Version20160410190541 extends WallabagMigration
'length' => 23, 'length' => 23,
]); ]);
$sharePublic = $this->container $sharePublic = $this->connection
->get('doctrine.orm.default_entity_manager')
->getConnection()
->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'share_public'"); ->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'share_public'");
if (false === $sharePublic) { if (false === $sharePublic) {

View file

@ -12,18 +12,14 @@ class Version20160911214952 extends WallabagMigration
{ {
public function up(Schema $schema): void public function up(Schema $schema): void
{ {
$redis = $this->container $redis = $this->connection
->get('doctrine.orm.default_entity_manager')
->getConnection()
->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'import_with_redis'"); ->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'import_with_redis'");
if (false === $redis) { if (false === $redis) {
$this->addSql('INSERT INTO ' . $this->getTable('craue_config_setting') . " (name, value, section) VALUES ('import_with_redis', 0, 'import')"); $this->addSql('INSERT INTO ' . $this->getTable('craue_config_setting') . " (name, value, section) VALUES ('import_with_redis', 0, 'import')");
} }
$rabbitmq = $this->container $rabbitmq = $this->connection
->get('doctrine.orm.default_entity_manager')
->getConnection()
->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'import_with_rabbitmq'"); ->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'import_with_rabbitmq'");
if (false === $rabbitmq) { if (false === $rabbitmq) {

View file

@ -12,9 +12,7 @@ class Version20161031132655 extends WallabagMigration
{ {
public function up(Schema $schema): void public function up(Schema $schema): void
{ {
$images = $this->container $images = $this->connection
->get('doctrine.orm.default_entity_manager')
->getConnection()
->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'download_images_enabled'"); ->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.'); $this->skipIf(false !== $images, 'It seems that you already played this migration.');

View file

@ -12,18 +12,14 @@ class Version20161117071626 extends WallabagMigration
{ {
public function up(Schema $schema): void public function up(Schema $schema): void
{ {
$share = $this->container $share = $this->connection
->get('doctrine.orm.default_entity_manager')
->getConnection()
->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'share_unmark'"); ->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'share_unmark'");
if (false === $share) { if (false === $share) {
$this->addSql('INSERT INTO ' . $this->getTable('craue_config_setting') . " (name, value, section) VALUES ('share_unmark', 0, 'entry')"); $this->addSql('INSERT INTO ' . $this->getTable('craue_config_setting') . " (name, value, section) VALUES ('share_unmark', 0, 'entry')");
} }
$unmark = $this->container $unmark = $this->connection
->get('doctrine.orm.default_entity_manager')
->getConnection()
->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'unmark_url'"); ->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'unmark_url'");
if (false === $unmark) { if (false === $unmark) {

View file

@ -12,9 +12,7 @@ class Version20161122144743 extends WallabagMigration
{ {
public function up(Schema $schema): void public function up(Schema $schema): void
{ {
$access = $this->container $access = $this->connection
->get('doctrine.orm.default_entity_manager')
->getConnection()
->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'restricted_access'"); ->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'restricted_access'");
$this->skipIf(false !== $access, 'It seems that you already played this migration.'); $this->skipIf(false !== $access, 'It seems that you already played this migration.');

View file

@ -12,9 +12,7 @@ class Version20170327194233 extends WallabagMigration
{ {
public function up(Schema $schema): void public function up(Schema $schema): void
{ {
$scuttle = $this->container $scuttle = $this->connection
->get('doctrine.orm.default_entity_manager')
->getConnection()
->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'share_scuttle'"); ->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'share_scuttle'");
$this->skipIf(false !== $scuttle, 'It seems that you already played this migration.'); $this->skipIf(false !== $scuttle, 'It seems that you already played this migration.');

View file

@ -17,9 +17,7 @@ class Version20170420134133 extends WallabagMigration
public function down(Schema $schema): void public function down(Schema $schema): void
{ {
$downloadPictures = $this->container $downloadPictures = $this->connection
->get('doctrine.orm.default_entity_manager')
->getConnection()
->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'download_pictures'"); ->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'download_pictures'");
$this->skipIf(false !== $downloadPictures, 'It seems that you already played this migration.'); $this->skipIf(false !== $downloadPictures, 'It seems that you already played this migration.');

View file

@ -12,9 +12,7 @@ class Version20170602075214 extends WallabagMigration
{ {
public function up(Schema $schema): void public function up(Schema $schema): void
{ {
$apiUserRegistration = $this->container $apiUserRegistration = $this->connection
->get('doctrine.orm.default_entity_manager')
->getConnection()
->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'api_user_registration'"); ->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.'); $this->skipIf(false !== $apiUserRegistration, 'It seems that you already played this migration.');

View file

@ -19,9 +19,7 @@ class Version20170606155640 extends WallabagMigration
return; return;
} }
$apiUserRegistration = $this->container $apiUserRegistration = $this->connection
->get('doctrine.orm.default_entity_manager')
->getConnection()
->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'wallabag_url'"); ->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'wallabag_url'");
if (false === $apiUserRegistration) { if (false === $apiUserRegistration) {

View file

@ -12,9 +12,7 @@ class Version20171120163128 extends WallabagMigration
{ {
public function up(Schema $schema): void public function up(Schema $schema): void
{ {
$storeArticleHeaders = $this->container $storeArticleHeaders = $this->connection
->get('doctrine.orm.default_entity_manager')
->getConnection()
->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'store_article_headers'"); ->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.'); $this->skipIf(false !== $storeArticleHeaders, 'It seems that you already played this migration.');

View file

@ -12,9 +12,7 @@ class Version20171125164500 extends WallabagMigration
{ {
public function up(Schema $schema): void public function up(Schema $schema): void
{ {
$shaarliShareOriginUrl = $this->container $shaarliShareOriginUrl = $this->connection
->get('doctrine.orm.default_entity_manager')
->getConnection()
->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'shaarli_share_origin_url'"); ->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.'); $this->skipIf(false !== $shaarliShareOriginUrl, 'It seems that you already played this migration.');

View file

@ -121,9 +121,7 @@ final class Version20190129120000 extends WallabagMigration
public function up(Schema $schema): void public function up(Schema $schema): void
{ {
foreach ($this->settings as $setting) { foreach ($this->settings as $setting) {
$settingEnabled = $this->container $settingEnabled = $this->connection
->get('doctrine.orm.default_entity_manager')
->getConnection()
->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = '" . $setting['name'] . "'"); ->fetchOne('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = '" . $setting['name'] . "'");
if (false !== $settingEnabled) { if (false !== $settingEnabled) {

View file

@ -45,10 +45,8 @@ final class Version20190826204730 extends WallabagMigration
public function postUp(Schema $schema): void public function postUp(Schema $schema): void
{ {
foreach ($this->container->getParameter('wallabag.default_ignore_origin_instance_rules') as $entity) { foreach ($this->defaultIgnoreOriginInstanceRules as $entity) {
$previous_rule = $this->container $previous_rule = $this->connection
->get('doctrine.orm.default_entity_manager')
->getConnection()
->fetchOne('SELECT * FROM ' . $this->getTable('ignore_origin_instance_rule') . " WHERE rule = '" . $entity['rule'] . "'"); ->fetchOne('SELECT * FROM ' . $this->getTable('ignore_origin_instance_rule') . " WHERE rule = '" . $entity['rule'] . "'");
if (false === $previous_rule) { if (false === $previous_rule) {

View file

@ -37,7 +37,7 @@ final class Version20230728093912 extends WallabagMigration
'UPDATE ' . $this->getTable('entry') . ' SET is_not_parsed = :isNotParsed WHERE content LIKE :content', 'UPDATE ' . $this->getTable('entry') . ' SET is_not_parsed = :isNotParsed WHERE content LIKE :content',
[ [
'isNotParsed' => true, 'isNotParsed' => true,
'content' => str_replace("\n", '', addslashes($this->container->getParameter('wallabag.fetching_error_message'))) . '%', 'content' => str_replace("\n", '', addslashes($this->fetchingErrorMessage)) . '%',
] ]
); );
} }

View file

@ -12,18 +12,14 @@ final class Version20240521152037 extends WallabagMigration
{ {
public function up(Schema $schema): void public function up(Schema $schema): void
{ {
$share = $this->container $share = $this->connection
->get('doctrine.orm.default_entity_manager')
->getConnection()
->fetchOne('SELECT * FROM ' . $this->getTable('internal_setting') . " WHERE name = 'share_linkding'"); ->fetchOne('SELECT * FROM ' . $this->getTable('internal_setting') . " WHERE name = 'share_linkding'");
if (false === $share) { if (false === $share) {
$this->addSql('INSERT INTO ' . $this->getTable('internal_setting') . " (name, value, section) VALUES ('share_linkding', 0, 'entry')"); $this->addSql('INSERT INTO ' . $this->getTable('internal_setting') . " (name, value, section) VALUES ('share_linkding', 0, 'entry')");
} }
$linkding = $this->container $linkding = $this->connection
->get('doctrine.orm.default_entity_manager')
->getConnection()
->fetchOne('SELECT * FROM ' . $this->getTable('internal_setting') . " WHERE name = 'linkding_url'"); ->fetchOne('SELECT * FROM ' . $this->getTable('internal_setting') . " WHERE name = 'linkding_url'");
if (false === $linkding) { if (false === $linkding) {

View file

@ -0,0 +1,38 @@
<?php
namespace Wallabag\Doctrine;
use Doctrine\Migrations\AbstractMigration;
use Doctrine\Migrations\Version\MigrationFactory;
/**
* Decorates the migration factory to pass some additional information to the migration instances.
*/
class MigrationFactoryDecorator implements MigrationFactory
{
private MigrationFactory $migrationFactory;
private string $tablePrefix;
private array $defaultIgnoreOriginInstanceRules;
private string $fetchingErrorMessage;
public function __construct(MigrationFactory $migrationFactory, string $tablePrefix, array $defaultIgnoreOriginInstanceRules, string $fetchingErrorMessage)
{
$this->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;
}
}

View file

@ -5,17 +5,14 @@ namespace Wallabag\Doctrine;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration; 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; public const UN_ESCAPED_TABLE = true;
/** protected string $tablePrefix;
* @var ContainerInterface protected array $defaultIgnoreOriginInstanceRules;
*/ protected string $fetchingErrorMessage;
protected $container;
// because there are declared as abstract in `AbstractMigration` we need to delarer here too // because there are declared as abstract in `AbstractMigration` we need to delarer here too
public function up(Schema $schema): void 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) * @todo remove when upgrading DoctrineMigration (only needed for PHP 8)
* *
@ -41,9 +33,24 @@ abstract class WallabagMigration extends AbstractMigration implements ContainerA
return false; 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) protected function getTable($tableName, $unEscaped = false)
{ {
$table = $this->container->getParameter('database_table_prefix') . $tableName; $table = $this->tablePrefix . $tableName;
if (self::UN_ESCAPED_TABLE === $unEscaped) { if (self::UN_ESCAPED_TABLE === $unEscaped) {
return $table; return $table;