diff options
author | Kevin Decherf <kevin@kdecherf.com> | 2019-06-23 22:13:06 +0200 |
---|---|---|
committer | Kevin Decherf <kevin@kdecherf.com> | 2020-04-25 15:59:23 +0200 |
commit | c675bd11c66e60a1976dfd66484448dcc9d80f0f (patch) | |
tree | 609a1b8d355365ccf83b70bf5df6b140bb86e196 /app | |
parent | 8a8a78a64c116caf81aaa4339906298bdc0e32e0 (diff) | |
download | wallabag-c675bd11c66e60a1976dfd66484448dcc9d80f0f.tar.gz wallabag-c675bd11c66e60a1976dfd66484448dcc9d80f0f.tar.zst wallabag-c675bd11c66e60a1976dfd66484448dcc9d80f0f.zip |
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>
Diffstat (limited to 'app')
-rw-r--r-- | app/DoctrineMigrations/Version20190826204730.php | 64 |
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 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Application\Migrations; | ||
6 | |||
7 | use Doctrine\DBAL\Schema\Schema; | ||
8 | use Wallabag\CoreBundle\Doctrine\WallabagMigration; | ||
9 | |||
10 | /** | ||
11 | * Add tables for the ignore origin rules. | ||
12 | */ | ||
13 | final 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 | } | ||