From 2495b197614d82b99eed6bbec4562078f4429ad7 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 11 Aug 2019 23:55:12 +0200 Subject: Add default system-wide ignore origin rules with install support Signed-off-by: Kevin Decherf --- src/Wallabag/CoreBundle/Command/InstallCommand.php | 8 +++++ .../IgnoreOriginInstanceRuleFixtures.php | 36 ++++++++++++++++++++++ .../DependencyInjection/Configuration.php | 7 +++++ .../DependencyInjection/WallabagCoreExtension.php | 1 + 4 files changed, 52 insertions(+) create mode 100644 src/Wallabag/CoreBundle/DataFixtures/IgnoreOriginInstanceRuleFixtures.php (limited to 'src/Wallabag') diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php index 3aa332f1..8d08187a 100644 --- a/src/Wallabag/CoreBundle/Command/InstallCommand.php +++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php @@ -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('Config successfully setup.'); diff --git a/src/Wallabag/CoreBundle/DataFixtures/IgnoreOriginInstanceRuleFixtures.php b/src/Wallabag/CoreBundle/DataFixtures/IgnoreOriginInstanceRuleFixtures.php new file mode 100644 index 00000000..8a0a06ed --- /dev/null +++ b/src/Wallabag/CoreBundle/DataFixtures/IgnoreOriginInstanceRuleFixtures.php @@ -0,0 +1,36 @@ +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(); + } +} diff --git a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php index 7ae73371..85747256 100644 --- a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php +++ b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php @@ -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() ; diff --git a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php index e9a1e9e0..af91e588 100644 --- a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php +++ b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php @@ -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'); -- cgit v1.2.3