mirror of
https://github.com/wallabag/wallabag.git
synced 2025-08-26 18:21:02 +00:00
Stop using ContainerAwareInterface in migrations
This commit is contained in:
parent
bcf0f2f52c
commit
e715da7e91
19 changed files with 83 additions and 66 deletions
38
src/Doctrine/MigrationFactoryDecorator.php
Normal file
38
src/Doctrine/MigrationFactoryDecorator.php
Normal 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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue