From 827a7b2911d9acfc615a1387c5ddf5752e550d3d Mon Sep 17 00:00:00 2001 From: inalgnu Date: Sat, 23 Feb 2013 18:07:41 +0100 Subject: [PATCH 1/5] Add a command to remove the acme demo bundle --- .../Command/RemoveDemoBundleCommand.php | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/Acme/DemoBundle/Command/RemoveDemoBundleCommand.php diff --git a/src/Acme/DemoBundle/Command/RemoveDemoBundleCommand.php b/src/Acme/DemoBundle/Command/RemoveDemoBundleCommand.php new file mode 100644 index 0000000000..b9bdb94be3 --- /dev/null +++ b/src/Acme/DemoBundle/Command/RemoveDemoBundleCommand.php @@ -0,0 +1,44 @@ +setName('acme:bundle:remove') + ->setDescription('Remove the Acme Demo Bundle') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $rootDir = $this->getContainer()->get('kernel')->getRootDir(); + + $route = Yaml::parse(file_get_contents($rootDir.'/config/routing_dev.yml')); + $security = Yaml::parse(file_get_contents($rootDir.'/config/security.yml')); + + unset($route['_demo'], $route['_demo_secured'], $route['_welcome']); + unset($security['security']['firewalls']['login'], $security['security']['firewalls']['secured_area']); + + file_put_contents($rootDir.'/config/routing_dev.yml', Yaml::dump($route, 6)); + file_put_contents($rootDir.'/config/security.yml', Yaml::dump($security, 6)); + + $appKernel = file_get_contents($rootDir.'/AppKernel.php'); + $appKernel = str_replace('$bundles[] = new Acme\DemoBundle\AcmeDemoBundle();', '', $appKernel); + file_put_contents($rootDir.'/AppKernel.php', $appKernel); + + $fs = new Filesystem(); + $fs->remove([$rootDir.'/../src/Acme/']); + + $output->writeln("Acme Bundle removed successfully"); + } +} From 6b35d94f2129576ec4155a1c220ab845195b2530 Mon Sep 17 00:00:00 2001 From: inalgnu Date: Sat, 23 Feb 2013 18:44:45 +0100 Subject: [PATCH 2/5] remove php 5.4 syntax --- src/Acme/DemoBundle/Command/RemoveDemoBundleCommand.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Acme/DemoBundle/Command/RemoveDemoBundleCommand.php b/src/Acme/DemoBundle/Command/RemoveDemoBundleCommand.php index b9bdb94be3..745699452b 100644 --- a/src/Acme/DemoBundle/Command/RemoveDemoBundleCommand.php +++ b/src/Acme/DemoBundle/Command/RemoveDemoBundleCommand.php @@ -26,8 +26,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $route = Yaml::parse(file_get_contents($rootDir.'/config/routing_dev.yml')); $security = Yaml::parse(file_get_contents($rootDir.'/config/security.yml')); - unset($route['_demo'], $route['_demo_secured'], $route['_welcome']); - unset($security['security']['firewalls']['login'], $security['security']['firewalls']['secured_area']); + unset($route['_demo'], $route['_demo_secured'], $route['_welcome'], + $security['security']['firewalls']['login'], $security['security']['firewalls']['secured_area']); file_put_contents($rootDir.'/config/routing_dev.yml', Yaml::dump($route, 6)); file_put_contents($rootDir.'/config/security.yml', Yaml::dump($security, 6)); @@ -37,7 +37,7 @@ protected function execute(InputInterface $input, OutputInterface $output) file_put_contents($rootDir.'/AppKernel.php', $appKernel); $fs = new Filesystem(); - $fs->remove([$rootDir.'/../src/Acme/']); + $fs->remove(array($rootDir.'/../src/Acme/')); $output->writeln("Acme Bundle removed successfully"); } From 6aac838fe548bf4c007d50ec598fcc212a06eacf Mon Sep 17 00:00:00 2001 From: inalgnu Date: Sat, 23 Feb 2013 23:09:15 +0100 Subject: [PATCH 3/5] Add instruction in README --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 186b846c91..142c5cb567 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,10 @@ playing with it, you can remove it by following these steps: `security.firewalls.secured_area` entries in the `security.yml` file or tweak the security configuration to fit your needs. +Or use the following command : + ``` php app/console acme:bundle:remove ``` + + What's inside? --------------- From f24308f297fec141b0b61c7d32b26bcce5a6a575 Mon Sep 17 00:00:00 2001 From: inalgnu Date: Sun, 24 Feb 2013 13:56:42 +0100 Subject: [PATCH 4/5] Remove yaml parsing, add default sercurity & routing_dev config --- .../Command/RemoveDemoBundleCommand.php | 83 ++++++++++++++++--- 1 file changed, 70 insertions(+), 13 deletions(-) diff --git a/src/Acme/DemoBundle/Command/RemoveDemoBundleCommand.php b/src/Acme/DemoBundle/Command/RemoveDemoBundleCommand.php index 745699452b..477026600e 100644 --- a/src/Acme/DemoBundle/Command/RemoveDemoBundleCommand.php +++ b/src/Acme/DemoBundle/Command/RemoveDemoBundleCommand.php @@ -6,8 +6,8 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\Yaml\Yaml; class RemoveDemoBundleCommand extends ContainerAwareCommand { @@ -23,22 +23,79 @@ protected function execute(InputInterface $input, OutputInterface $output) { $rootDir = $this->getContainer()->get('kernel')->getRootDir(); - $route = Yaml::parse(file_get_contents($rootDir.'/config/routing_dev.yml')); - $security = Yaml::parse(file_get_contents($rootDir.'/config/security.yml')); + file_put_contents($rootDir.'/config/security.yml', $this->getBaseSecurityConfig()); + file_put_contents($rootDir.'/config/routing_dev.yml', $this->getBaseRoutingDevConfig()); - unset($route['_demo'], $route['_demo_secured'], $route['_welcome'], - $security['security']['firewalls']['login'], $security['security']['firewalls']['secured_area']); - - file_put_contents($rootDir.'/config/routing_dev.yml', Yaml::dump($route, 6)); - file_put_contents($rootDir.'/config/security.yml', Yaml::dump($security, 6)); - - $appKernel = file_get_contents($rootDir.'/AppKernel.php'); - $appKernel = str_replace('$bundles[] = new Acme\DemoBundle\AcmeDemoBundle();', '', $appKernel); - file_put_contents($rootDir.'/AppKernel.php', $appKernel); + $appKernel = $rootDir.'/AppKernel.php'; + file_put_contents($appKernel, str_replace('$bundles[] = new Acme\DemoBundle\AcmeDemoBundle();', '', file_get_contents($appKernel))); $fs = new Filesystem(); - $fs->remove(array($rootDir.'/../src/Acme/')); + try { + $fs->remove(array($rootDir.'/../src/Acme/')); + } catch (IOException $e) { + $output->writeln("An error occurred while removing the AcmeDemoBundle directory"); + return; + } $output->writeln("Acme Bundle removed successfully"); } + + protected function getBaseSecurityConfig() + { + return +<< Date: Sun, 24 Feb 2013 16:34:37 +0100 Subject: [PATCH 5/5] additional verification before deleting --- .../Command/RemoveDemoBundleCommand.php | 116 +++++++++++++++++- 1 file changed, 111 insertions(+), 5 deletions(-) diff --git a/src/Acme/DemoBundle/Command/RemoveDemoBundleCommand.php b/src/Acme/DemoBundle/Command/RemoveDemoBundleCommand.php index 477026600e..c330e3c3de 100644 --- a/src/Acme/DemoBundle/Command/RemoveDemoBundleCommand.php +++ b/src/Acme/DemoBundle/Command/RemoveDemoBundleCommand.php @@ -21,12 +21,22 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { - $rootDir = $this->getContainer()->get('kernel')->getRootDir(); + $rootDir = $this->getContainer()->get('kernel')->getRootDir(); + $securityConfig = $rootDir. '/config/security.yml'; + $routingConfig = $rootDir. '/config/routing_dev.yml'; + $appKernel = $rootDir. '/AppKernel.php'; - file_put_contents($rootDir.'/config/security.yml', $this->getBaseSecurityConfig()); - file_put_contents($rootDir.'/config/routing_dev.yml', $this->getBaseRoutingDevConfig()); - $appKernel = $rootDir.'/AppKernel.php'; + $config = array('routing_dev' => file_get_contents($routingConfig), + 'security' => file_get_contents($securityConfig)); + + if ($this->hasDefaultsConfigChanged($config)) { + $output->writeln("This couldn't be performed, your config files have changed. You must remove the bundle manually"); + return; + } + + file_put_contents($securityConfig, $this->getBaseSecurityConfig()); + file_put_contents($routingConfig, $this->getBaseRoutingDevConfig()); file_put_contents($appKernel, str_replace('$bundles[] = new Acme\DemoBundle\AcmeDemoBundle();', '', file_get_contents($appKernel))); $fs = new Filesystem(); @@ -37,7 +47,7 @@ protected function execute(InputInterface $input, OutputInterface $output) return; } - $output->writeln("Acme Bundle removed successfully"); + $output->writeln("Acme Bundle has been removed successfully"); } protected function getBaseSecurityConfig() @@ -98,4 +108,100 @@ protected function getBaseRoutingDevConfig() resource: routing.yml EOT; } + + protected function getDefaultSecurityConfig() + { + return +<<getDefaultRoutingDevConfig()) { + return true; + } + if (trim($config['security']) !== $this->getDefaultSecurityConfig()) { + return true; + } + + return false; + } }