From: Kevin Decherf Date: Sun, 23 Jun 2019 20:13:06 +0000 (+0200) Subject: Add IgnoreOriginRule-related entities, db migration, update config X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=c675bd11c66e60a1976dfd66484448dcc9d80f0f;hp=8a8a78a64c116caf81aaa4339906298bdc0e32e0;p=github%2Fwallabag%2Fwallabag.git 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 --- 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')); + } +} diff --git a/src/Wallabag/CoreBundle/Entity/Config.php b/src/Wallabag/CoreBundle/Entity/Config.php index fe7942ee..1bed4513 100644 --- a/src/Wallabag/CoreBundle/Entity/Config.php +++ b/src/Wallabag/CoreBundle/Entity/Config.php @@ -119,6 +119,12 @@ class Config */ private $taggingRules; + /** + * @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\IgnoreOriginUserRule", mappedBy="config", cascade={"remove"}) + * @ORM\OrderBy({"id" = "ASC"}) + */ + private $ignoreOriginRules; + /* * @param User $user */ @@ -126,6 +132,7 @@ class Config { $this->user = $user; $this->taggingRules = new ArrayCollection(); + $this->ignoreOriginRules = new ArrayCollection(); } /** @@ -387,4 +394,22 @@ class Config { return $this->taggingRules; } + + /** + * @return Config + */ + public function addIgnoreOriginRule(IgnoreOriginUserRule $rule) + { + $this->ignoreOriginRules[] = $rule; + + return $this; + } + + /** + * @return ArrayCollection + */ + public function getIgnoreOriginRules() + { + return $this->ignoreOriginRules; + } } diff --git a/src/Wallabag/CoreBundle/Entity/IgnoreOriginInstanceRule.php b/src/Wallabag/CoreBundle/Entity/IgnoreOriginInstanceRule.php new file mode 100644 index 00000000..34aed50c --- /dev/null +++ b/src/Wallabag/CoreBundle/Entity/IgnoreOriginInstanceRule.php @@ -0,0 +1,71 @@ +id; + } + + /** + * Set rule. + * + * @return IgnoreOriginRuleInterface + */ + public function setRule(string $rule) + { + $this->rule = $rule; + + return $this; + } + + /** + * Get rule. + * + * @return string + */ + public function getRule() + { + return $this->rule; + } +} diff --git a/src/Wallabag/CoreBundle/Entity/IgnoreOriginRuleInterface.php b/src/Wallabag/CoreBundle/Entity/IgnoreOriginRuleInterface.php new file mode 100644 index 00000000..eb865a3a --- /dev/null +++ b/src/Wallabag/CoreBundle/Entity/IgnoreOriginRuleInterface.php @@ -0,0 +1,12 @@ +id; + } + + /** + * Set rule. + * + * @return IgnoreOriginRuleInterface + */ + public function setRule(string $rule) + { + $this->rule = $rule; + + return $this; + } + + /** + * Get rule. + * + * @return string + */ + public function getRule() + { + return $this->rule; + } + + /** + * Set config. + * + * @return IgnoreOriginUserRule + */ + public function setConfig(Config $config) + { + $this->config = $config; + + return $this; + } + + /** + * Get config. + * + * @return Config + */ + public function getConfig() + { + return $this->config; + } +} diff --git a/src/Wallabag/CoreBundle/Entity/RuleInterface.php b/src/Wallabag/CoreBundle/Entity/RuleInterface.php new file mode 100644 index 00000000..8e9b5c45 --- /dev/null +++ b/src/Wallabag/CoreBundle/Entity/RuleInterface.php @@ -0,0 +1,7 @@ +