aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/DoctrineMigrations/Version20190826204730.php
diff options
context:
space:
mode:
authorKevin Decherf <kevin@kdecherf.com>2020-04-26 15:39:57 +0200
committerGitHub <noreply@github.com>2020-04-26 15:39:57 +0200
commit0e8a0f77d0b643a884e6687bd9c463267852a970 (patch)
tree88c6761b4215637bba34b263015e87750c92a187 /app/DoctrineMigrations/Version20190826204730.php
parent8a8a78a64c116caf81aaa4339906298bdc0e32e0 (diff)
parent71f7e58fbd84e1d15c7a405a3c5872adb937dc37 (diff)
downloadwallabag-0e8a0f77d0b643a884e6687bd9c463267852a970.tar.gz
wallabag-0e8a0f77d0b643a884e6687bd9c463267852a970.tar.zst
wallabag-0e8a0f77d0b643a884e6687bd9c463267852a970.zip
Merge pull request #4026 from wallabag/3760-ignorelist-db
Move Ignore Origin rules to database
Diffstat (limited to 'app/DoctrineMigrations/Version20190826204730.php')
-rw-r--r--app/DoctrineMigrations/Version20190826204730.php64
1 files changed, 64 insertions, 0 deletions
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 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Application\Migrations;
6
7use Doctrine\DBAL\Schema\Schema;
8use Wallabag\CoreBundle\Doctrine\WallabagMigration;
9
10/**
11 * Add tables for the ignore origin rules.
12 */
13final class Version20190826204730 extends WallabagMigration
14{
15 public function up(Schema $schema): void
16 {
17 if (false === $schema->hasTable($this->getTable('ignore_origin_user_rule'))) {
18 $userTable = $schema->createTable($this->getTable('ignore_origin_user_rule', true));
19 $userTable->addColumn('id', 'integer', ['autoincrement' => true]);
20 $userTable->addColumn('config_id', 'integer');
21 $userTable->addColumn('rule', 'string', ['length' => 255]);
22 $userTable->addIndex(['config_id'], 'idx_config');
23 $userTable->setPrimaryKey(['id']);
24 $userTable->addForeignKeyConstraint($this->getTable('config'), ['config_id'], ['id'], [], 'fk_config');
25
26 if ('postgresql' === $this->connection->getDatabasePlatform()->getName()) {
27 $schema->dropSequence('ignore_origin_user_rule_id_seq');
28 $schema->createSequence('ignore_origin_user_rule_id_seq');
29 }
30 }
31
32 if (false === $schema->hasTable($this->getTable('ignore_origin_instance_rule'))) {
33 $instanceTable = $schema->createTable($this->getTable('ignore_origin_instance_rule', true));
34 $instanceTable->addColumn('id', 'integer', ['autoincrement' => true]);
35 $instanceTable->addColumn('rule', 'string', ['length' => 255]);
36 $instanceTable->setPrimaryKey(['id']);
37
38 if ('postgresql' === $this->connection->getDatabasePlatform()->getName()) {
39 $schema->dropSequence('ignore_origin_instance_rule_id_seq');
40 $schema->createSequence('ignore_origin_instance_rule_id_seq');
41 }
42 }
43 }
44
45 public function postUp(Schema $schema): void
46 {
47 foreach ($this->container->getParameter('wallabag_core.default_ignore_origin_instance_rules') as $entity) {
48 $previous_rule = $this->container
49 ->get('doctrine.orm.default_entity_manager')
50 ->getConnection()
51 ->fetchArray('SELECT * FROM ' . $this->getTable('ignore_origin_instance_rule') . " WHERE rule = '" . $entity['rule'] . "'");
52
53 if (false === $previous_rule) {
54 $this->addSql('INSERT INTO ' . $this->getTable('ignore_origin_instance_rule') . " (rule) VALUES ('" . $entity['rule'] . "');");
55 }
56 }
57 }
58
59 public function down(Schema $schema): void
60 {
61 $schema->dropTable($this->getTable('ignore_origin_user_rule'));
62 $schema->dropTable($this->getTable('ignore_origin_instance_rule'));
63 }
64}