generate Model using Propel command in Thelia app

This commit is contained in:
Manuel Raynaud
2013-07-11 16:44:18 +02:00
parent 1a7c9b2fd2
commit 98589cc2b6
4 changed files with 99 additions and 1 deletions

View File

@@ -11,6 +11,7 @@ define('THELIA_CONF_DIR' , THELIA_LOCAL_DIR . 'config/');
define('THELIA_MODULE_DIR' , THELIA_LOCAL_DIR . 'modules/'); define('THELIA_MODULE_DIR' , THELIA_LOCAL_DIR . 'modules/');
define('THELIA_WEB_DIR' , THELIA_ROOT . '/web/'); define('THELIA_WEB_DIR' , THELIA_ROOT . '/web/');
define('THELIA_TEMPLATE_DIR' , THELIA_ROOT . '/templates/'); define('THELIA_TEMPLATE_DIR' , THELIA_ROOT . '/templates/');
define('DS', DIRECTORY_SEPARATOR);
$loader = require __DIR__ . "/vendor/autoload.php"; $loader = require __DIR__ . "/vendor/autoload.php";

View File

@@ -22,8 +22,11 @@
/*************************************************************************************/ /*************************************************************************************/
namespace Thelia\Command; namespace Thelia\Command;
use Propel\Runtime\Propel;
use Symfony\Component\Console\Application;
abstract class BaseModuleGenerate extends ContainerAwareCommand {
abstract class BaseModuleGenerate extends ContainerAwareCommand {
protected $module; protected $module;
protected $moduleDirectory; protected $moduleDirectory;
@@ -52,4 +55,9 @@ namespace Thelia\Command;
} }
return ucfirst($name); return ucfirst($name);
} }
protected function getPropelApplication()
{
return new Application("Propel", Propel::VERSION);
}
} }

View File

@@ -0,0 +1,88 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Command;
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\Output\OutputInterface;
use Symfony\Component\Console\Output\StreamOutput;
use Symfony\Component\Filesystem\Filesystem;
class ModuleGenerateModelCommand extends BaseModuleGenerate {
protected function configure()
{
$this
->setName("module:generate:model")
->setDescription("generate model for a specific module")
->addArgument(
"name",
InputArgument::REQUIRED,
"module name"
)
;
}
public function execute(InputInterface $input, OutputInterface $output)
{
$this->module = $this->formatModuleName($input->getArgument("name"));
$this->moduleDirectory = THELIA_MODULE_DIR . DS . $this->module;
$fs = new Filesystem();
if ($fs->exists($this->moduleDirectory) === false) {
throw new \RuntimeException(sprintf("%s module does not exists"));
}
if ($fs->exists($this->moduleDirectory . DS . "Config" . DS . "schema.xml") === false) {
throw new \RuntimeException("schema.xml not found in Config directory. Needed file for generating model");
}
$propelApp = $this->getPropelApplication();
$moduleBuildPropel = new ModelBuildCommand();
$moduleBuildPropel->setApplication($propelApp);
$moduleBuildPropel->run(
new ArrayInput(array(
"command" => $moduleBuildPropel->getName(),
"--output-dir" => THELIA_MODULE_DIR,
"--input-dir" => $this->moduleDirectory . DS ."Config"
)),
new StreamOutput(fopen('php://memory', 'w', false))
);
if ($fs->exists(THELIA_MODULE_DIR . DS . "Thelia")) {
$fs->remove(THELIA_MODULE_DIR . DS . "Thelia");
}
}
}

View File

@@ -35,6 +35,7 @@
<command class="Thelia\Command\CacheClear"/> <command class="Thelia\Command\CacheClear"/>
<command class="Thelia\Command\Install"/> <command class="Thelia\Command\Install"/>
<command class="Thelia\Command\ModuleGenerateCommand"/> <command class="Thelia\Command\ModuleGenerateCommand"/>
<command class="Thelia\Command\ModuleGenerateModelCommand"/>
</commands> </commands>
<services> <services>