wallabag/app/DoctrineMigrations/Version20190826204730.php
Kevin Decherf c675bd11c6 Add IgnoreOriginRule-related entities, db migration, update config
Add IgnoreOriginUserRule for user-defined rules and
IgnoreOriginInstanceRule for system-wide rules. Add an interface for
these two new entities.

Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
2020-04-25 15:59:23 +02:00

65 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Application\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Wallabag\CoreBundle\Doctrine\WallabagMigration;
/**
* Add tables for the ignore origin rules.
*/
final class Version20190826204730 extends WallabagMigration
{
public function up(Schema $schema): void
{
if (false === $schema->hasTable($this->getTable('ignore_origin_user_rule'))) {
$userTable = $schema->createTable($this->getTable('ignore_origin_user_rule', true));
$userTable->addColumn('id', 'integer', ['autoincrement' => true]);
$userTable->addColumn('config_id', 'integer');
$userTable->addColumn('rule', 'string', ['length' => 255]);
$userTable->addIndex(['config_id'], 'idx_config');
$userTable->setPrimaryKey(['id']);
$userTable->addForeignKeyConstraint($this->getTable('config'), ['config_id'], ['id'], [], 'fk_config');
if ('postgresql' === $this->connection->getDatabasePlatform()->getName()) {
$schema->dropSequence('ignore_origin_user_rule_id_seq');
$schema->createSequence('ignore_origin_user_rule_id_seq');
}
}
if (false === $schema->hasTable($this->getTable('ignore_origin_instance_rule'))) {
$instanceTable = $schema->createTable($this->getTable('ignore_origin_instance_rule', true));
$instanceTable->addColumn('id', 'integer', ['autoincrement' => true]);
$instanceTable->addColumn('rule', 'string', ['length' => 255]);
$instanceTable->setPrimaryKey(['id']);
if ('postgresql' === $this->connection->getDatabasePlatform()->getName()) {
$schema->dropSequence('ignore_origin_instance_rule_id_seq');
$schema->createSequence('ignore_origin_instance_rule_id_seq');
}
}
}
public function postUp(Schema $schema): void
{
foreach ($this->container->getParameter('wallabag_core.default_ignore_origin_instance_rules') as $entity) {
$previous_rule = $this->container
->get('doctrine.orm.default_entity_manager')
->getConnection()
->fetchArray('SELECT * FROM ' . $this->getTable('ignore_origin_instance_rule') . " WHERE rule = '" . $entity['rule'] . "'");
if (false === $previous_rule) {
$this->addSql('INSERT INTO ' . $this->getTable('ignore_origin_instance_rule') . " (rule) VALUES ('" . $entity['rule'] . "');");
}
}
}
public function down(Schema $schema): void
{
$schema->dropTable($this->getTable('ignore_origin_user_rule'));
$schema->dropTable($this->getTable('ignore_origin_instance_rule'));
}
}