generate Model using Propel command in Thelia app
This commit is contained in:
@@ -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";
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
88
core/lib/Thelia/Command/ModuleGenerateModelCommand.php
Normal file
88
core/lib/Thelia/Command/ModuleGenerateModelCommand.php
Normal 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");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user