From c675bd11c66e60a1976dfd66484448dcc9d80f0f Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 23 Jun 2019 22:13:06 +0200 Subject: 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 --- app/DoctrineMigrations/Version20190826204730.php | 64 ++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 app/DoctrineMigrations/Version20190826204730.php (limited to 'app/DoctrineMigrations') diff --git a/app/DoctrineMigrations/Version20190826204730.php b/app/DoctrineMigrations/Version20190826204730.php new file mode 100644 index 00000000..ee1ba6bf --- /dev/null +++ b/app/DoctrineMigrations/Version20190826204730.php @@ -0,0 +1,64 @@ +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')); + } +} -- cgit v1.2.3