From ac170ac25f4a84fbdbd216c63715cf8b972fc34c Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 11 Jul 2013 17:15:32 +0200 Subject: [PATCH] generate sql from generat model command --- .../Command/ModuleGenerateModelCommand.php | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Command/ModuleGenerateModelCommand.php b/core/lib/Thelia/Command/ModuleGenerateModelCommand.php index fd87fa48d..41638414e 100644 --- a/core/lib/Thelia/Command/ModuleGenerateModelCommand.php +++ b/core/lib/Thelia/Command/ModuleGenerateModelCommand.php @@ -28,6 +28,7 @@ use Propel\Generator\Command\ModelBuildCommand; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\StreamOutput; use Symfony\Component\Filesystem\Filesystem; @@ -44,6 +45,12 @@ class ModuleGenerateModelCommand extends BaseModuleGenerate { InputArgument::REQUIRED, "module name" ) + ->addOption( + "generate-sql", + null, + InputOption::VALUE_NONE, + "with this option generate sql file at the same time" + ) ; } @@ -63,7 +70,30 @@ class ModuleGenerateModelCommand extends BaseModuleGenerate { throw new \RuntimeException("schema.xml not found in Config directory. Needed file for generating model"); } + $this->generateModel(); + if ($input->getOption("generate-sql")) { + $this->generateSql(); + } + } + + protected function generateSql() + { + $sqlBuild = new ModuleGenerateSqlCommand(); + $sqlBuild->setApplication($this->getApplication()); + + $sqlBuild->run( + new ArrayInput(array( + "command" => $sqlBuild->getName(), + "name" => $this->module + )), + new StreamOutput(fopen('php://memory', 'w', false)) + ); + } + + protected function generateModel() + { + $fs = new Filesystem(); $moduleBuildPropel = new ModelBuildCommand(); $moduleBuildPropel->setApplication($this->getApplication()); @@ -79,8 +109,6 @@ class ModuleGenerateModelCommand extends BaseModuleGenerate { if ($fs->exists(THELIA_MODULE_DIR . DS . "Thelia")) { $fs->remove(THELIA_MODULE_DIR . DS . "Thelia"); } - - } } \ No newline at end of file