--- /dev/null
+<?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'));
+ }
+}
*/
private $taggingRules;
+ /**
+ * @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\IgnoreOriginUserRule", mappedBy="config", cascade={"remove"})
+ * @ORM\OrderBy({"id" = "ASC"})
+ */
+ private $ignoreOriginRules;
+
/*
* @param User $user
*/
{
$this->user = $user;
$this->taggingRules = new ArrayCollection();
+ $this->ignoreOriginRules = new ArrayCollection();
}
/**
{
return $this->taggingRules;
}
+
+ /**
+ * @return Config
+ */
+ public function addIgnoreOriginRule(IgnoreOriginUserRule $rule)
+ {
+ $this->ignoreOriginRules[] = $rule;
+
+ return $this;
+ }
+
+ /**
+ * @return ArrayCollection<IgnoreOriginUserRule>
+ */
+ public function getIgnoreOriginRules()
+ {
+ return $this->ignoreOriginRules;
+ }
}
--- /dev/null
+<?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;
+ }
+}
--- /dev/null
+<?php
+
+namespace Wallabag\CoreBundle\Entity;
+
+interface IgnoreOriginRuleInterface
+{
+ public function getId();
+
+ public function setRule(string $rule);
+
+ public function getRule();
+}
--- /dev/null
+<?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;
+ }
+}
--- /dev/null
+<?php
+
+namespace Wallabag\CoreBundle\Entity;
+
+interface RuleInterface
+{
+}
* @ORM\Table(name="`tagging_rule`")
* @ORM\Entity
*/
-class TaggingRule
+class TaggingRule implements RuleInterface
{
/**
* @var int
--- /dev/null
+<?php
+
+namespace Wallabag\CoreBundle\Repository;
+
+use Doctrine\ORM\EntityRepository;
+
+class IgnoreOriginInstanceRuleRepository extends EntityRepository
+{
+}
--- /dev/null
+<?php
+
+namespace Wallabag\CoreBundle\Repository;
+
+use Doctrine\ORM\EntityRepository;
+
+class IgnoreOriginUserRuleRepository extends EntityRepository
+{
+}
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: