mirror of
https://github.com/wallabag/wallabag.git
synced 2024-12-13 17:09:07 +01:00
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>
This commit is contained in:
parent
8a8a78a64c
commit
c675bd11c6
64
app/DoctrineMigrations/Version20190826204730.php
Normal file
64
app/DoctrineMigrations/Version20190826204730.php
Normal file
@ -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'));
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
71
src/Wallabag/CoreBundle/Entity/IgnoreOriginInstanceRule.php
Normal file
71
src/Wallabag/CoreBundle/Entity/IgnoreOriginInstanceRule.php
Normal file
@ -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;
|
||||
}
|
||||
}
|
12
src/Wallabag/CoreBundle/Entity/IgnoreOriginRuleInterface.php
Normal file
12
src/Wallabag/CoreBundle/Entity/IgnoreOriginRuleInterface.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Entity;
|
||||
|
||||
interface IgnoreOriginRuleInterface
|
||||
{
|
||||
public function getId();
|
||||
|
||||
public function setRule(string $rule);
|
||||
|
||||
public function getRule();
|
||||
}
|
98
src/Wallabag/CoreBundle/Entity/IgnoreOriginUserRule.php
Normal file
98
src/Wallabag/CoreBundle/Entity/IgnoreOriginUserRule.php
Normal file
@ -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;
|
||||
}
|
||||
}
|
7
src/Wallabag/CoreBundle/Entity/RuleInterface.php
Normal file
7
src/Wallabag/CoreBundle/Entity/RuleInterface.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Entity;
|
||||
|
||||
interface RuleInterface
|
||||
{
|
||||
}
|
@ -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
|
||||
|
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Repository;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
class IgnoreOriginInstanceRuleRepository extends EntityRepository
|
||||
{
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Repository;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
class IgnoreOriginUserRuleRepository extends EntityRepository
|
||||
{
|
||||
}
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user