diff options
10 files changed, 302 insertions, 1 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 | } | ||
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 | |||
119 | */ | 119 | */ |
120 | private $taggingRules; | 120 | private $taggingRules; |
121 | 121 | ||
122 | /** | ||
123 | * @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\IgnoreOriginUserRule", mappedBy="config", cascade={"remove"}) | ||
124 | * @ORM\OrderBy({"id" = "ASC"}) | ||
125 | */ | ||
126 | private $ignoreOriginRules; | ||
127 | |||
122 | /* | 128 | /* |
123 | * @param User $user | 129 | * @param User $user |
124 | */ | 130 | */ |
@@ -126,6 +132,7 @@ class Config | |||
126 | { | 132 | { |
127 | $this->user = $user; | 133 | $this->user = $user; |
128 | $this->taggingRules = new ArrayCollection(); | 134 | $this->taggingRules = new ArrayCollection(); |
135 | $this->ignoreOriginRules = new ArrayCollection(); | ||
129 | } | 136 | } |
130 | 137 | ||
131 | /** | 138 | /** |
@@ -387,4 +394,22 @@ class Config | |||
387 | { | 394 | { |
388 | return $this->taggingRules; | 395 | return $this->taggingRules; |
389 | } | 396 | } |
397 | |||
398 | /** | ||
399 | * @return Config | ||
400 | */ | ||
401 | public function addIgnoreOriginRule(IgnoreOriginUserRule $rule) | ||
402 | { | ||
403 | $this->ignoreOriginRules[] = $rule; | ||
404 | |||
405 | return $this; | ||
406 | } | ||
407 | |||
408 | /** | ||
409 | * @return ArrayCollection<IgnoreOriginUserRule> | ||
410 | */ | ||
411 | public function getIgnoreOriginRules() | ||
412 | { | ||
413 | return $this->ignoreOriginRules; | ||
414 | } | ||
390 | } | 415 | } |
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 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Entity; | ||
4 | |||
5 | use Doctrine\ORM\Mapping as ORM; | ||
6 | use Symfony\Bridge\RulerZ\Validator\Constraints as RulerZAssert; | ||
7 | use Symfony\Component\Validator\Constraints as Assert; | ||
8 | |||
9 | /** | ||
10 | * Ignore Origin rule. | ||
11 | * | ||
12 | * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\IgnoreOriginInstanceRuleRepository") | ||
13 | * @ORM\Table(name="`ignore_origin_instance_rule`") | ||
14 | * @ORM\Entity | ||
15 | */ | ||
16 | class IgnoreOriginInstanceRule implements IgnoreOriginRuleInterface, RuleInterface | ||
17 | { | ||
18 | /** | ||
19 | * @var int | ||
20 | * | ||
21 | * @ORM\Column(name="id", type="integer") | ||
22 | * @ORM\Id | ||
23 | * @ORM\GeneratedValue(strategy="AUTO") | ||
24 | */ | ||
25 | private $id; | ||
26 | |||
27 | /** | ||
28 | * @var string | ||
29 | * | ||
30 | * @Assert\NotBlank() | ||
31 | * @Assert\Length(max=255) | ||
32 | * @RulerZAssert\ValidRule( | ||
33 | * allowed_variables={"host","pattern"}, | ||
34 | * allowed_operators={"=","~"} | ||
35 | * ) | ||
36 | * @ORM\Column(name="rule", type="string", nullable=false) | ||
37 | */ | ||
38 | private $rule; | ||
39 | |||
40 | /** | ||
41 | * Get id. | ||
42 | * | ||
43 | * @return int | ||
44 | */ | ||
45 | public function getId() | ||
46 | { | ||
47 | return $this->id; | ||
48 | } | ||
49 | |||
50 | /** | ||
51 | * Set rule. | ||
52 | * | ||
53 | * @return IgnoreOriginRuleInterface | ||
54 | */ | ||
55 | public function setRule(string $rule) | ||
56 | { | ||
57 | $this->rule = $rule; | ||
58 | |||
59 | return $this; | ||
60 | } | ||
61 | |||
62 | /** | ||
63 | * Get rule. | ||
64 | * | ||
65 | * @return string | ||
66 | */ | ||
67 | public function getRule() | ||
68 | { | ||
69 | return $this->rule; | ||
70 | } | ||
71 | } | ||
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 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Entity; | ||
4 | |||
5 | interface IgnoreOriginRuleInterface | ||
6 | { | ||
7 | public function getId(); | ||
8 | |||
9 | public function setRule(string $rule); | ||
10 | |||
11 | public function getRule(); | ||
12 | } | ||
diff --git a/src/Wallabag/CoreBundle/Entity/IgnoreOriginUserRule.php b/src/Wallabag/CoreBundle/Entity/IgnoreOriginUserRule.php new file mode 100644 index 00000000..befd6090 --- /dev/null +++ b/src/Wallabag/CoreBundle/Entity/IgnoreOriginUserRule.php | |||
@@ -0,0 +1,98 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Entity; | ||
4 | |||
5 | use Doctrine\ORM\Mapping as ORM; | ||
6 | use Symfony\Bridge\RulerZ\Validator\Constraints as RulerZAssert; | ||
7 | use Symfony\Component\Validator\Constraints as Assert; | ||
8 | |||
9 | /** | ||
10 | * Ignore Origin rule. | ||
11 | * | ||
12 | * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\IgnoreOriginUserRuleRepository") | ||
13 | * @ORM\Table(name="`ignore_origin_user_rule`") | ||
14 | * @ORM\Entity | ||
15 | */ | ||
16 | class IgnoreOriginUserRule implements IgnoreOriginRuleInterface, RuleInterface | ||
17 | { | ||
18 | /** | ||
19 | * @var int | ||
20 | * | ||
21 | * @ORM\Column(name="id", type="integer") | ||
22 | * @ORM\Id | ||
23 | * @ORM\GeneratedValue(strategy="AUTO") | ||
24 | */ | ||
25 | private $id; | ||
26 | |||
27 | /** | ||
28 | * @var string | ||
29 | * | ||
30 | * @Assert\NotBlank() | ||
31 | * @Assert\Length(max=255) | ||
32 | * @RulerZAssert\ValidRule( | ||
33 | * allowed_variables={"host","pattern"}, | ||
34 | * allowed_operators={"=","~"} | ||
35 | * ) | ||
36 | * @ORM\Column(name="rule", type="string", nullable=false) | ||
37 | */ | ||
38 | private $rule; | ||
39 | |||
40 | /** | ||
41 | * @ORM\ManyToOne(targetEntity="Wallabag\CoreBundle\Entity\Config", inversedBy="ignoreOriginRules") | ||
42 | */ | ||
43 | private $config; | ||
44 | |||
45 | /** | ||
46 | * Get id. | ||
47 | * | ||
48 | * @return int | ||
49 | */ | ||
50 | public function getId() | ||
51 | { | ||
52 | return $this->id; | ||
53 | } | ||
54 | |||
55 | /** | ||
56 | * Set rule. | ||
57 | * | ||
58 | * @return IgnoreOriginRuleInterface | ||
59 | */ | ||
60 | public function setRule(string $rule) | ||
61 | { | ||
62 | $this->rule = $rule; | ||
63 | |||
64 | return $this; | ||
65 | } | ||
66 | |||
67 | /** | ||
68 | * Get rule. | ||
69 | * | ||
70 | * @return string | ||
71 | */ | ||
72 | public function getRule() | ||
73 | { | ||
74 | return $this->rule; | ||
75 | } | ||
76 | |||
77 | /** | ||
78 | * Set config. | ||
79 | * | ||
80 | * @return IgnoreOriginUserRule | ||
81 | */ | ||
82 | public function setConfig(Config $config) | ||
83 | { | ||
84 | $this->config = $config; | ||
85 | |||
86 | return $this; | ||
87 | } | ||
88 | |||
89 | /** | ||
90 | * Get config. | ||
91 | * | ||
92 | * @return Config | ||
93 | */ | ||
94 | public function getConfig() | ||
95 | { | ||
96 | return $this->config; | ||
97 | } | ||
98 | } | ||
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 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Entity; | ||
4 | |||
5 | interface RuleInterface | ||
6 | { | ||
7 | } | ||
diff --git a/src/Wallabag/CoreBundle/Entity/TaggingRule.php b/src/Wallabag/CoreBundle/Entity/TaggingRule.php index f7166087..7bed7a69 100644 --- a/src/Wallabag/CoreBundle/Entity/TaggingRule.php +++ b/src/Wallabag/CoreBundle/Entity/TaggingRule.php | |||
@@ -17,7 +17,7 @@ use Symfony\Component\Validator\Constraints as Assert; | |||
17 | * @ORM\Table(name="`tagging_rule`") | 17 | * @ORM\Table(name="`tagging_rule`") |
18 | * @ORM\Entity | 18 | * @ORM\Entity |
19 | */ | 19 | */ |
20 | class TaggingRule | 20 | class TaggingRule implements RuleInterface |
21 | { | 21 | { |
22 | /** | 22 | /** |
23 | * @var int | 23 | * @var int |
diff --git a/src/Wallabag/CoreBundle/Repository/IgnoreOriginInstanceRuleRepository.php b/src/Wallabag/CoreBundle/Repository/IgnoreOriginInstanceRuleRepository.php new file mode 100644 index 00000000..708a0ede --- /dev/null +++ b/src/Wallabag/CoreBundle/Repository/IgnoreOriginInstanceRuleRepository.php | |||
@@ -0,0 +1,9 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Repository; | ||
4 | |||
5 | use Doctrine\ORM\EntityRepository; | ||
6 | |||
7 | class IgnoreOriginInstanceRuleRepository extends EntityRepository | ||
8 | { | ||
9 | } | ||
diff --git a/src/Wallabag/CoreBundle/Repository/IgnoreOriginUserRuleRepository.php b/src/Wallabag/CoreBundle/Repository/IgnoreOriginUserRuleRepository.php new file mode 100644 index 00000000..8aa4c265 --- /dev/null +++ b/src/Wallabag/CoreBundle/Repository/IgnoreOriginUserRuleRepository.php | |||
@@ -0,0 +1,9 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Repository; | ||
4 | |||
5 | use Doctrine\ORM\EntityRepository; | ||
6 | |||
7 | class IgnoreOriginUserRuleRepository extends EntityRepository | ||
8 | { | ||
9 | } | ||
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index 3f3d4de7..4ece046a 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml | |||
@@ -131,6 +131,12 @@ services: | |||
131 | calls: | 131 | calls: |
132 | - [ setCrypto, [ "@wallabag_core.helper.crypto_proxy" ] ] | 132 | - [ setCrypto, [ "@wallabag_core.helper.crypto_proxy" ] ] |
133 | 133 | ||
134 | wallabag_core.ignore_origin_instance_rule_repository: | ||
135 | class: Wallabag\CoreBundle\Repository\IgnoreOriginInstanceRuleRepository | ||
136 | factory: [ "@doctrine.orm.default_entity_manager", getRepository ] | ||
137 | arguments: | ||
138 | - WallabagCoreBundle:IgnoreOriginInstanceRule | ||
139 | |||
134 | wallabag_core.helper.entries_export: | 140 | wallabag_core.helper.entries_export: |
135 | class: Wallabag\CoreBundle\Helper\EntriesExport | 141 | class: Wallabag\CoreBundle\Helper\EntriesExport |
136 | arguments: | 142 | arguments: |