From 6d268e077bcd00a10ce4c6fa67fb36eb3fb3d662 Mon Sep 17 00:00:00 2001 From: Nicolas Pion Date: Thu, 15 Jun 2017 13:02:39 +0200 Subject: [PATCH] [FrameworkBundle] [Command] Clean bundle directory, fixes #23177 --- .../FrameworkBundle/Command/AssetsInstallCommand.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php index 136b1c21fae98..e4dd3c92928e5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php @@ -114,6 +114,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $rows = array(); $copyUsed = false; $exitCode = 0; + $validAssetDir = array(); /** @var BundleInterface $bundle */ foreach ($this->getContainer()->get('kernel')->getBundles() as $bundle) { if (!is_dir($originDir = $bundle->getPath().'/Resources/public')) { @@ -148,12 +149,22 @@ protected function execute(InputInterface $input, OutputInterface $output) } else { $rows[] = array(sprintf('%s', '\\' === DIRECTORY_SEPARATOR ? 'WARNING' : '!'), $message, $method); } + array_push($validAssetDir, $targetDir); } catch (\Exception $e) { $exitCode = 1; $rows[] = array(sprintf('%s', '\\' === DIRECTORY_SEPARATOR ? 'ERROR' : "\xE2\x9C\x98" /* HEAVY BALLOT X (U+2718) */), $message, $e->getMessage()); } } + // Check in $bundlesDir, if all links/folder still have an existing Bundle + if ($dir = opendir($bundlesDir)) { + while (($file = readdir($dir)) !== false) { + if ($file != '.' && $file != '..' && !in_array($bundlesDir.$file, $validAssetDir)) { + $this->filesystem->remove($bundlesDir.$file); + } + } + } + closedir($dir); $io->table(array('', 'Bundle', 'Method / Error'), $rows); if (0 !== $exitCode) {