Merge pull request #7964 from wallabag/stop-using-containerawareinterface

Stop using ContainerAwareInterface
This commit is contained in:
Yassine Guedidi 2025-01-20 10:01:02 +01:00 committed by GitHub
commit cab9b02b80
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 116 additions and 118 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

@ -6,6 +6,9 @@ services:
# fixtures # fixtures
Wallabag\DataFixtures\: Wallabag\DataFixtures\:
bind:
$defaultIgnoreOriginInstanceRules: '%wallabag.default_ignore_origin_instance_rules%'
$defaultInternalSettings: '%wallabag.default_internal_settings%'
resource: '../../fixtures/*' resource: '../../fixtures/*'
tags: ['doctrine.fixture.orm'] tags: ['doctrine.fixture.orm']
autowire: true autowire: true

View file

@ -4,27 +4,22 @@ namespace Wallabag\DataFixtures;
use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager; use Doctrine\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Wallabag\Entity\IgnoreOriginInstanceRule; use Wallabag\Entity\IgnoreOriginInstanceRule;
class IgnoreOriginInstanceRuleFixtures extends Fixture implements ContainerAwareInterface class IgnoreOriginInstanceRuleFixtures extends Fixture
{ {
/** private array $defaultIgnoreOriginInstanceRules;
* @var ContainerInterface
*/
private $container;
public function setContainer(?ContainerInterface $container = null) public function __construct(array $defaultIgnoreOriginInstanceRules)
{ {
$this->container = $container; $this->defaultIgnoreOriginInstanceRules = $defaultIgnoreOriginInstanceRules;
} }
public function load(ObjectManager $manager): void public function load(ObjectManager $manager): void
{ {
foreach ($this->container->getParameter('wallabag.default_ignore_origin_instance_rules') as $ignore_origin_instance_rule) { foreach ($this->defaultIgnoreOriginInstanceRules as $ignoreOriginInstanceRule) {
$newIgnoreOriginInstanceRule = new IgnoreOriginInstanceRule(); $newIgnoreOriginInstanceRule = new IgnoreOriginInstanceRule();
$newIgnoreOriginInstanceRule->setRule($ignore_origin_instance_rule['rule']); $newIgnoreOriginInstanceRule->setRule($ignoreOriginInstanceRule['rule']);
$manager->persist($newIgnoreOriginInstanceRule); $manager->persist($newIgnoreOriginInstanceRule);
} }

View file

@ -4,25 +4,20 @@ namespace Wallabag\DataFixtures;
use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager; use Doctrine\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Wallabag\Entity\InternalSetting; use Wallabag\Entity\InternalSetting;
class InternalSettingFixtures extends Fixture implements ContainerAwareInterface class InternalSettingFixtures extends Fixture
{ {
/** private array $defaultInternalSettings;
* @var ContainerInterface
*/
private $container;
public function setContainer(?ContainerInterface $container = null) public function __construct(array $defaultInternalSettings)
{ {
$this->container = $container; $this->defaultInternalSettings = $defaultInternalSettings;
} }
public function load(ObjectManager $manager): void public function load(ObjectManager $manager): void
{ {
foreach ($this->container->getParameter('wallabag.default_internal_settings') as $setting) { foreach ($this->defaultInternalSettings as $setting) {
$newSetting = new InternalSetting(); $newSetting = new InternalSetting();
$newSetting->setName($setting['name']); $newSetting->setName($setting['name']);
$newSetting->setValue($setting['value']); $newSetting->setValue($setting['value']);

View file

@ -5,37 +5,32 @@ namespace Wallabag\DataFixtures;
use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface; use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager; use Doctrine\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Wallabag\Entity\SiteCredential; use Wallabag\Entity\SiteCredential;
use Wallabag\Entity\User; use Wallabag\Entity\User;
use Wallabag\Helper\CryptoProxy; use Wallabag\Helper\CryptoProxy;
class SiteCredentialFixtures extends Fixture implements DependentFixtureInterface, ContainerAwareInterface class SiteCredentialFixtures extends Fixture implements DependentFixtureInterface
{ {
/** private CryptoProxy $cryptoProxy;
* @var ContainerInterface
*/
private $container;
public function setContainer(?ContainerInterface $container = null) public function __construct(CryptoProxy $cryptoProxy)
{ {
$this->container = $container; $this->cryptoProxy = $cryptoProxy;
} }
public function load(ObjectManager $manager): void public function load(ObjectManager $manager): void
{ {
$credential = new SiteCredential($this->getReference('admin-user', User::class)); $credential = new SiteCredential($this->getReference('admin-user', User::class));
$credential->setHost('.super.com'); $credential->setHost('.super.com');
$credential->setUsername($this->container->get(CryptoProxy::class)->crypt('.super')); $credential->setUsername($this->cryptoProxy->crypt('.super'));
$credential->setPassword($this->container->get(CryptoProxy::class)->crypt('bar')); $credential->setPassword($this->cryptoProxy->crypt('bar'));
$manager->persist($credential); $manager->persist($credential);
$credential = new SiteCredential($this->getReference('admin-user', User::class)); $credential = new SiteCredential($this->getReference('admin-user', User::class));
$credential->setHost('paywall.example.com'); $credential->setHost('paywall.example.com');
$credential->setUsername($this->container->get(CryptoProxy::class)->crypt('paywall.example')); $credential->setUsername($this->cryptoProxy->crypt('paywall.example'));
$credential->setPassword($this->container->get(CryptoProxy::class)->crypt('bar')); $credential->setPassword($this->cryptoProxy->crypt('bar'));
$manager->persist($credential); $manager->persist($credential);

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

@ -20,13 +20,12 @@ class Version20160812120952 extends WallabagMigration
// Can't use $clientsTable->addColumn('name', 'blob'); // Can't use $clientsTable->addColumn('name', 'blob');
// because of the error: // because of the error:
// SQLSTATE[HY000]: General error: 1 Cannot add a NOT NULL column with default value NULL // SQLSTATE[HY000]: General error: 1 Cannot add a NOT NULL column with default value NULL
$databaseTablePrefix = $this->container->getParameter('database_table_prefix'); $this->addSql('CREATE TEMPORARY TABLE __temp__' . $this->getTable('oauth2_clients', true) . ' AS SELECT id, random_id, redirect_uris, secret, allowed_grant_types FROM ' . $this->getTable('oauth2_clients', true));
$this->addSql('CREATE TEMPORARY TABLE __temp__' . $databaseTablePrefix . 'oauth2_clients AS SELECT id, random_id, redirect_uris, secret, allowed_grant_types FROM ' . $databaseTablePrefix . 'oauth2_clients'); $this->addSql('DROP TABLE ' . $this->getTable('oauth2_clients', true));
$this->addSql('DROP TABLE ' . $databaseTablePrefix . 'oauth2_clients'); $this->addSql('CREATE TABLE ' . $this->getTable('oauth2_clients', true) . ' (id INTEGER NOT NULL, user_id INTEGER DEFAULT NULL, random_id VARCHAR(255) NOT NULL COLLATE BINARY, secret VARCHAR(255) NOT NULL COLLATE BINARY, redirect_uris CLOB NOT NULL, allowed_grant_types CLOB NOT NULL, name CLOB NOT NULL, PRIMARY KEY(id), CONSTRAINT FK_635D765EA76ED395 FOREIGN KEY (user_id) REFERENCES "' . $this->getTable('user', true) . '" (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('CREATE TABLE ' . $databaseTablePrefix . 'oauth2_clients (id INTEGER NOT NULL, user_id INTEGER DEFAULT NULL, random_id VARCHAR(255) NOT NULL COLLATE BINARY, secret VARCHAR(255) NOT NULL COLLATE BINARY, redirect_uris CLOB NOT NULL, allowed_grant_types CLOB NOT NULL, name CLOB NOT NULL, PRIMARY KEY(id), CONSTRAINT FK_635D765EA76ED395 FOREIGN KEY (user_id) REFERENCES "' . $databaseTablePrefix . 'user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE)'); $this->addSql('INSERT INTO ' . $this->getTable('oauth2_clients', true) . ' (id, random_id, redirect_uris, secret, allowed_grant_types) SELECT id, random_id, redirect_uris, secret, allowed_grant_types FROM __temp__' . $this->getTable('oauth2_clients', true));
$this->addSql('INSERT INTO ' . $databaseTablePrefix . 'oauth2_clients (id, random_id, redirect_uris, secret, allowed_grant_types) SELECT id, random_id, redirect_uris, secret, allowed_grant_types FROM __temp__' . $databaseTablePrefix . 'oauth2_clients'); $this->addSql('DROP TABLE __temp__' . $this->getTable('oauth2_clients', true));
$this->addSql('DROP TABLE __temp__' . $databaseTablePrefix . 'oauth2_clients'); $this->addSql('CREATE INDEX IDX_635D765EA76ED395 ON ' . $this->getTable('oauth2_clients', true) . ' (user_id)');
$this->addSql('CREATE INDEX IDX_635D765EA76ED395 ON ' . $databaseTablePrefix . 'oauth2_clients (user_id)');
} else { } else {
$clientsTable->addColumn('name', 'blob'); $clientsTable->addColumn('name', 'blob');
} }
@ -37,13 +36,12 @@ class Version20160812120952 extends WallabagMigration
$clientsTable = $schema->getTable($this->getTable('oauth2_clients')); $clientsTable = $schema->getTable($this->getTable('oauth2_clients'));
if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) { if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
$databaseTablePrefix = $this->container->getParameter('database_table_prefix');
$this->addSql('DROP INDEX IDX_635D765EA76ED395'); $this->addSql('DROP INDEX IDX_635D765EA76ED395');
$this->addSql('CREATE TEMPORARY TABLE __temp__' . $databaseTablePrefix . 'oauth2_clients AS SELECT id, random_id, redirect_uris, secret, allowed_grant_types FROM ' . $databaseTablePrefix . 'oauth2_clients'); $this->addSql('CREATE TEMPORARY TABLE __temp__' . $this->getTable('oauth2_clients', true) . ' AS SELECT id, random_id, redirect_uris, secret, allowed_grant_types FROM ' . $this->getTable('oauth2_clients', true));
$this->addSql('DROP TABLE ' . $databaseTablePrefix . 'oauth2_clients'); $this->addSql('DROP TABLE ' . $this->getTable('oauth2_clients', true));
$this->addSql('CREATE TABLE ' . $databaseTablePrefix . 'oauth2_clients (id INTEGER NOT NULL, random_id VARCHAR(255) NOT NULL, secret VARCHAR(255) NOT NULL, redirect_uris CLOB NOT NULL COLLATE BINARY, allowed_grant_types CLOB NOT NULL COLLATE BINARY, PRIMARY KEY(id))'); $this->addSql('CREATE TABLE ' . $this->getTable('oauth2_clients', true) . ' (id INTEGER NOT NULL, random_id VARCHAR(255) NOT NULL, secret VARCHAR(255) NOT NULL, redirect_uris CLOB NOT NULL COLLATE BINARY, allowed_grant_types CLOB NOT NULL COLLATE BINARY, PRIMARY KEY(id))');
$this->addSql('INSERT INTO ' . $databaseTablePrefix . 'oauth2_clients (id, random_id, redirect_uris, secret, allowed_grant_types) SELECT id, random_id, redirect_uris, secret, allowed_grant_types FROM __temp__' . $databaseTablePrefix . 'oauth2_clients'); $this->addSql('INSERT INTO ' . $this->getTable('oauth2_clients', true) . ' (id, random_id, redirect_uris, secret, allowed_grant_types) SELECT id, random_id, redirect_uris, secret, allowed_grant_types FROM __temp__' . $this->getTable('oauth2_clients', true));
$this->addSql('DROP TABLE __temp__' . $databaseTablePrefix . 'oauth2_clients'); $this->addSql('DROP TABLE __temp__' . $this->getTable('oauth2_clients', true));
} else { } else {
$clientsTable->dropColumn('name'); $clientsTable->dropColumn('name');
} }

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

@ -301,7 +301,7 @@ final class Version20240310150000 extends WallabagMigration
$this->addSql('ALTER TABLE ' . $this->getTable('oauth2_clients') . ' ALTER name TYPE BYTEA USING name::bytea;'); $this->addSql('ALTER TABLE ' . $this->getTable('oauth2_clients') . ' ALTER name TYPE BYTEA USING name::bytea;');
$this->addSql('ALTER TABLE ' . $this->getTable('ignore_origin_instance_rule') . ' ALTER id SET DEFAULT nextval(\'' . $this->getTablePrefix() . 'ignore_origin_instance_rule_id_seq\');'); $this->addSql('ALTER TABLE ' . $this->getTable('ignore_origin_instance_rule') . ' ALTER id SET DEFAULT nextval(\'' . $this->getTable('ignore_origin_instance_rule_id_seq', true) . '\');');
$this->addSql('ALTER TABLE ' . $this->getTable('user') . ' ALTER salt SET NOT NULL;'); $this->addSql('ALTER TABLE ' . $this->getTable('user') . ' ALTER salt SET NOT NULL;');
$this->addSql('ALTER TABLE ' . $this->getTable('user') . ' ALTER confirmation_token TYPE VARCHAR(255);'); $this->addSql('ALTER TABLE ' . $this->getTable('user') . ' ALTER confirmation_token TYPE VARCHAR(255);');
@ -315,9 +315,9 @@ final class Version20240310150000 extends WallabagMigration
$this->addSql('ALTER TABLE ' . $this->getTable('entry') . ' ALTER hashed_given_url TYPE TEXT;'); $this->addSql('ALTER TABLE ' . $this->getTable('entry') . ' ALTER hashed_given_url TYPE TEXT;');
$this->addSql('ALTER TABLE ' . $this->getTable('entry') . ' ALTER is_not_parsed DROP NOT NULL;'); $this->addSql('ALTER TABLE ' . $this->getTable('entry') . ' ALTER is_not_parsed DROP NOT NULL;');
$this->addSql('ALTER TABLE ' . $this->getTable('site_credential') . ' ALTER id SET DEFAULT nextval(\'' . $this->getTablePrefix() . 'site_credential_id_seq\');'); $this->addSql('ALTER TABLE ' . $this->getTable('site_credential') . ' ALTER id SET DEFAULT nextval(\'' . $this->getTable('site_credential_id_seq', true) . '\');');
$this->addSql('ALTER TABLE ' . $this->getTable('ignore_origin_user_rule') . ' ALTER id SET DEFAULT nextval(\'' . $this->getTablePrefix() . 'ignore_origin_user_rule_id_seq\');'); $this->addSql('ALTER TABLE ' . $this->getTable('ignore_origin_user_rule') . ' ALTER id SET DEFAULT nextval(\'' . $this->getTable('ignore_origin_user_rule_id_seq', true) . '\');');
break; break;
} }

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,14 +33,24 @@ abstract class WallabagMigration extends AbstractMigration implements ContainerA
return false; return false;
} }
protected function getTablePrefix(): string public function setTablePrefix(string $tablePrefix): void
{ {
return (string) $this->container->getParameter('database_table_prefix'); $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;