From 6ed9c8d8c5af201caaa0be47b4a48ae950721891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Egyed?= Date: Tue, 4 Jul 2017 11:39:25 +0200 Subject: [PATCH] [FrameworkBundle] Do not remove files from assets dir --- .../Command/AssetsInstallCommand.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php index 0a3ea2871d..27cccd869e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php @@ -92,7 +92,9 @@ EOT $validAssetDirs = array(); foreach ($this->getContainer()->get('kernel')->getBundles() as $bundle) { if (is_dir($originDir = $bundle->getPath().'/Resources/public')) { - $targetDir = $bundlesDir.preg_replace('/bundle$/', '', strtolower($bundle->getName())); + $assetDir = preg_replace('/bundle$/', '', strtolower($bundle->getName())); + $targetDir = $bundlesDir.$assetDir; + $validAssetDirs[] = $assetDir; $output->writeln(sprintf('Installing assets for %s into %s', $bundle->getNamespace(), $targetDir)); @@ -132,15 +134,12 @@ EOT } else { $this->hardCopy($originDir, $targetDir); } - $validAssetDirs[] = $targetDir; } } + // remove the assets of the bundles that no longer exist - foreach (new \FilesystemIterator($bundlesDir) as $dir) { - if (!in_array($dir, $validAssetDirs)) { - $filesystem->remove($dir); - } - } + $dirsToRemove = Finder::create()->depth(0)->directories()->exclude($validAssetDirs)->in($bundlesDir); + $filesystem->remove($dirsToRemove); } /**