From 53e6d0845ba384011729cf9b8f2952d77f0dc575 Mon Sep 17 00:00:00 2001 From: Acrack Date: Wed, 26 Mar 2014 11:25:20 +0100 Subject: [PATCH] refacto + install templates to web/images --- .../AssetsInstallCommand.php} | 16 +++++--- .../GenerateCrudCommand.php} | 6 ++- .../ThemeInstallCommand.php} | 37 ++++++++++++++++--- 3 files changed, 45 insertions(+), 14 deletions(-) rename Command/{BigfootAssetsInstallCommand.php => Bigfoot/AssetsInstallCommand.php} (86%) rename Command/{GenerateBigfootCrudCommand.php => Bigfoot/GenerateCrudCommand.php} (95%) rename Command/{BigfootThemeInstallCommand.php => Bigfoot/ThemeInstallCommand.php} (72%) diff --git a/Command/BigfootAssetsInstallCommand.php b/Command/Bigfoot/AssetsInstallCommand.php similarity index 86% rename from Command/BigfootAssetsInstallCommand.php rename to Command/Bigfoot/AssetsInstallCommand.php index 3c54301..a34448b 100644 --- a/Command/BigfootAssetsInstallCommand.php +++ b/Command/Bigfoot/AssetsInstallCommand.php @@ -1,6 +1,6 @@ getArgument('target'); - $symlink = $input->getOption('symlink'); + $target = $input->getArgument('target'); + $symlink = $input->getOption('symlink'); $relative = $input->getOption('relative'); + $input = new ArrayInput(array( - 'target' => $target, - '--symlink' => $symlink, + 'target' => $target, + '--symlink' => $symlink, '--relative' => $relative, )); @@ -59,6 +62,7 @@ protected function execute(InputInterface $input, OutputInterface $output) protected function runCommand($name, ArrayInput $input, OutputInterface $output) { $command = $this->getApplication()->find($name); + return $command->run($input, $output); } } diff --git a/Command/GenerateBigfootCrudCommand.php b/Command/Bigfoot/GenerateCrudCommand.php similarity index 95% rename from Command/GenerateBigfootCrudCommand.php rename to Command/Bigfoot/GenerateCrudCommand.php index ee46feb..664f637 100644 --- a/Command/GenerateBigfootCrudCommand.php +++ b/Command/Bigfoot/GenerateCrudCommand.php @@ -1,19 +1,21 @@ getContainer()->get('filesystem'); + $filesystem = $this->getContainer()->get('filesystem'); + $themeBundle = $this->getContainer()->get('kernel')->getBundle($this->getContainer()->getParameter('bigfoot.theme.bundle')); + $contentBundle = $this->getContainer()->get('kernel')->getBundle('BigfootContentBundle'); + $images = $contentBundle->getPath().'/Resources/public/images'; + + $this->recurseCopy($images, $targetArg.'/images'); - $bundle = $this->getContainer()->get('kernel')->getBundle($this->getContainer()->getParameter('bigfoot.theme.bundle')); - if (is_dir($originDir = $bundle->getPath().'/Resources/assets')) { + if (is_dir($originDir = $themeBundle->getPath().'/Resources/assets')) { $targetDir = $targetArg.'/admin'; - $output->writeln(sprintf('Installing bigfoot theme assets from %s into %s', $bundle->getNamespace(), $targetDir)); + $output->writeln(sprintf('Installing bigfoot theme assets from %s into %s', $themeBundle->getNamespace(), $targetDir)); $filesystem->remove($targetDir); @@ -83,12 +89,31 @@ protected function execute(InputInterface $input, OutputInterface $output) } else { $relativeOriginDir = $originDir; } + $filesystem->symlink($relativeOriginDir, $targetDir); } else { $filesystem->mkdir($targetDir, 0777); + // We use a custom iterator to ignore VCS files $filesystem->mirror($originDir, $targetDir, Finder::create()->in($originDir)); } } } + + protected function recurseCopy($src, $dst) { + $dir = opendir($src); + @mkdir($dst); + + while (false !== ($file = readdir($dir))) { + if (($file != '.') && ( $file != '..' )) { + if (is_dir($src.'/'.$file)) { + $this->recurseCopy($src.'/'.$file, $dst.'/'.$file); + } else { + copy($src.'/'.$file, $dst.'/'.$file); + } + } + } + + closedir($dir); + } }