]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Add IgnoreOriginRule-related entities, db migration, update config
authorKevin Decherf <kevin@kdecherf.com>
Sun, 23 Jun 2019 20:13:06 +0000 (22:13 +0200)
committerKevin Decherf <kevin@kdecherf.com>
Sat, 25 Apr 2020 13:59:23 +0000 (15:59 +0200)
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>
app/DoctrineMigrations/Version20190826204730.php [new file with mode: 0644]
src/Wallabag/CoreBundle/Entity/Config.php
src/Wallabag/CoreBundle/Entity/IgnoreOriginInstanceRule.php [new file with mode: 0644]
src/Wallabag/CoreBundle/Entity/IgnoreOriginRuleInterface.php [new file with mode: 0644]
src/Wallabag/CoreBundle/Entity/IgnoreOriginUserRule.php [new file with mode: 0644]
src/Wallabag/CoreBundle/Entity/RuleInterface.php [new file with mode: 0644]
src/Wallabag/CoreBundle/Entity/TaggingRule.php
src/Wallabag/CoreBundle/Repository/IgnoreOriginInstanceRuleRepository.php [new file with mode: 0644]
src/Wallabag/CoreBundle/Repository/IgnoreOriginUserRuleRepository.php [new file with mode: 0644]
src/Wallabag/CoreBundle/Resources/config/services.yml

diff --git a/app/DoctrineMigrations/Version20190826204730.php b/app/DoctrineMigrations/Version20190826204730.php
new file mode 100644 (file)
index 0000000..ee1ba6b
--- /dev/null
@@ -0,0 +1,64 @@
+<?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'));
+    }
+}
index fe7942ee261bca550ff3ef2ece24634124c37599..1bed451380eafb16a9a645efe59a9161bb1f1edb 100644 (file)
@@ -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<IgnoreOriginUserRule>
+     */
+    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 (file)
index 0000000..34aed50
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+
+namespace Wallabag\CoreBundle\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+use Symfony\Bridge\RulerZ\Validator\Constraints as RulerZAssert;
+use Symfony\Component\Validator\Constraints as Assert;
+
+/**
+ * Ignore Origin rule.
+ *
+ * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\IgnoreOriginInstanceRuleRepository")
+ * @ORM\Table(name="`ignore_origin_instance_rule`")
+ * @ORM\Entity
+ */
+class IgnoreOriginInstanceRule implements IgnoreOriginRuleInterface, RuleInterface
+{
+    /**
+     * @var int
+     *
+     * @ORM\Column(name="id", type="integer")
+     * @ORM\Id
+     * @ORM\GeneratedValue(strategy="AUTO")
+     */
+    private $id;
+
+    /**
+     * @var string
+     *
+     * @Assert\NotBlank()
+     * @Assert\Length(max=255)
+     * @RulerZAssert\ValidRule(
+     *  allowed_variables={"host","pattern"},
+     *  allowed_operators={"=","~"}
+     * )
+     * @ORM\Column(name="rule", type="string", nullable=false)
+     */
+    private $rule;
+
+    /**
+     * Get id.
+     *
+     * @return int
+     */
+    public function getId()
+    {
+        return $this->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 (file)
index 0000000..eb865a3
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+
+namespace Wallabag\CoreBundle\Entity;
+
+interface IgnoreOriginRuleInterface
+{
+    public function getId();
+
+    public function setRule(string $rule);
+
+    public function getRule();
+}
diff --git a/src/Wallabag/CoreBundle/Entity/IgnoreOriginUserRule.php b/src/Wallabag/CoreBundle/Entity/IgnoreOriginUserRule.php
new file mode 100644 (file)
index 0000000..befd609
--- /dev/null
@@ -0,0 +1,98 @@
+<?php
+
+namespace Wallabag\CoreBundle\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+use Symfony\Bridge\RulerZ\Validator\Constraints as RulerZAssert;
+use Symfony\Component\Validator\Constraints as Assert;
+
+/**
+ * Ignore Origin rule.
+ *
+ * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\IgnoreOriginUserRuleRepository")
+ * @ORM\Table(name="`ignore_origin_user_rule`")
+ * @ORM\Entity
+ */
+class IgnoreOriginUserRule implements IgnoreOriginRuleInterface, RuleInterface
+{
+    /**
+     * @var int
+     *
+     * @ORM\Column(name="id", type="integer")
+     * @ORM\Id
+     * @ORM\GeneratedValue(strategy="AUTO")
+     */
+    private $id;
+
+    /**
+     * @var string
+     *
+     * @Assert\NotBlank()
+     * @Assert\Length(max=255)
+     * @RulerZAssert\ValidRule(
+     *  allowed_variables={"host","pattern"},
+     *  allowed_operators={"=","~"}
+     * )
+     * @ORM\Column(name="rule", type="string", nullable=false)
+     */
+    private $rule;
+
+    /**
+     * @ORM\ManyToOne(targetEntity="Wallabag\CoreBundle\Entity\Config", inversedBy="ignoreOriginRules")
+     */
+    private $config;
+
+    /**
+     * Get id.
+     *
+     * @return int
+     */
+    public function getId()
+    {
+        return $this->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 (file)
index 0000000..8e9b5c4
--- /dev/null
@@ -0,0 +1,7 @@
+<?php
+
+namespace Wallabag\CoreBundle\Entity;
+
+interface RuleInterface
+{
+}
index f716608716f1dbde4cc82cf24ff5d4ef03a5bbab..7bed7a69139d5e82a5d6986349814cfeddcc1d09 100644 (file)
@@ -17,7 +17,7 @@ use Symfony\Component\Validator\Constraints as Assert;
  * @ORM\Table(name="`tagging_rule`")
  * @ORM\Entity
  */
-class TaggingRule
+class TaggingRule implements RuleInterface
 {
     /**
      * @var int
diff --git a/src/Wallabag/CoreBundle/Repository/IgnoreOriginInstanceRuleRepository.php b/src/Wallabag/CoreBundle/Repository/IgnoreOriginInstanceRuleRepository.php
new file mode 100644 (file)
index 0000000..708a0ed
--- /dev/null
@@ -0,0 +1,9 @@
+<?php
+
+namespace Wallabag\CoreBundle\Repository;
+
+use Doctrine\ORM\EntityRepository;
+
+class IgnoreOriginInstanceRuleRepository extends EntityRepository
+{
+}
diff --git a/src/Wallabag/CoreBundle/Repository/IgnoreOriginUserRuleRepository.php b/src/Wallabag/CoreBundle/Repository/IgnoreOriginUserRuleRepository.php
new file mode 100644 (file)
index 0000000..8aa4c26
--- /dev/null
@@ -0,0 +1,9 @@
+<?php
+
+namespace Wallabag\CoreBundle\Repository;
+
+use Doctrine\ORM\EntityRepository;
+
+class IgnoreOriginUserRuleRepository extends EntityRepository
+{
+}
index 3f3d4de7124dacf376063daf59d626c285776e29..4ece046a8e262879c8d89fd7daf15e1f68ee2ea8 100644 (file)
@@ -131,6 +131,12 @@ services:
         calls:
             - [ setCrypto, [ "@wallabag_core.helper.crypto_proxy" ] ]
 
+    wallabag_core.ignore_origin_instance_rule_repository:
+        class: Wallabag\CoreBundle\Repository\IgnoreOriginInstanceRuleRepository
+        factory: [ "@doctrine.orm.default_entity_manager", getRepository ]
+        arguments:
+            - WallabagCoreBundle:IgnoreOriginInstanceRule
+
     wallabag_core.helper.entries_export:
         class: Wallabag\CoreBundle\Helper\EntriesExport
         arguments: