Add default system-wide ignore origin rules with install support

Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
This commit is contained in:
Kevin Decherf 2019-08-11 23:55:12 +02:00
parent f39c5a2a70
commit 2495b19761
5 changed files with 60 additions and 0 deletions

View file

@ -165,6 +165,14 @@ wallabag_core:
value: 0
section: entry
default_ignore_origin_instance_rules:
-
rule: host = "feedproxy.google.com"
-
rule: host = "feeds.reuters.com"
-
rule: _all ~ "https?://www\.lemonde\.fr/tiny.*"
wallabag_user:
registration_enabled: "%fosuser_registration%"

View file

@ -12,6 +12,7 @@ use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Style\SymfonyStyle;
use Wallabag\CoreBundle\Entity\IgnoreOriginInstanceRule;
use Wallabag\CoreBundle\Entity\InternalSetting;
class InstallCommand extends ContainerAwareCommand
@ -277,6 +278,7 @@ class InstallCommand extends ContainerAwareCommand
// cleanup before insert new stuff
$em->createQuery('DELETE FROM WallabagCoreBundle:InternalSetting')->execute();
$em->createQuery('DELETE FROM WallabagCoreBundle:IgnoreOriginInstanceRule')->execute();
foreach ($this->getContainer()->getParameter('wallabag_core.default_internal_settings') as $setting) {
$newSetting = new InternalSetting();
@ -286,6 +288,12 @@ class InstallCommand extends ContainerAwareCommand
$em->persist($newSetting);
}
foreach ($this->getContainer()->getParameter('wallabag_core.default_ignore_origin_instance_rules') as $ignore_origin_instance_rule) {
$newIgnoreOriginInstanceRule = new IgnoreOriginInstanceRule();
$newIgnoreOriginInstanceRule->setRule($ignore_origin_instance_rule['rule']);
$em->persist($newIgnoreOriginInstanceRule);
}
$em->flush();
$this->io->text('<info>Config successfully setup.</info>');

View file

@ -0,0 +1,36 @@
<?php
namespace Wallabag\CoreBundle\DataFixtures;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Wallabag\CoreBundle\Entity\IgnoreOriginInstanceRule;
class IgnoreOriginInstanceRuleFixtures extends Fixture implements ContainerAwareInterface
{
/**
* @var ContainerInterface
*/
private $container;
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
/**
* {@inheritdoc}
*/
public function load(ObjectManager $manager)
{
foreach ($this->container->getParameter('wallabag_core.default_ignore_origin_instance_rules') as $ignore_origin_instance_rule) {
$newIgnoreOriginInstanceRule = new IgnoreOriginInstanceRule();
$newIgnoreOriginInstanceRule->setRule($ignore_origin_instance_rule['rule']);
$manager->persist($newIgnoreOriginInstanceRule);
}
$manager->flush();
}
}

View file

@ -65,6 +65,13 @@ class Configuration implements ConfigurationInterface
->end()
->scalarNode('encryption_key_path')
->end()
->arrayNode('default_ignore_origin_instance_rules')
->prototype('array')
->children()
->scalarNode('rule')->end()
->end()
->end()
->end()
->end()
;

View file

@ -30,6 +30,7 @@ class WallabagCoreExtension extends Extension
$container->setParameter('wallabag_core.api_limit_mass_actions', $config['api_limit_mass_actions']);
$container->setParameter('wallabag_core.default_internal_settings', $config['default_internal_settings']);
$container->setParameter('wallabag_core.site_credentials.encryption_key_path', $config['encryption_key_path']);
$container->setParameter('wallabag_core.default_ignore_origin_instance_rules', $config['default_ignore_origin_instance_rules']);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');