start to create config process for Thelia

This commit is contained in:
Manuel Raynaud
2013-03-28 16:43:01 +01:00
parent 2154bbc1ed
commit 879a2e09a8
8 changed files with 133 additions and 45 deletions

View File

@@ -35,6 +35,9 @@ namespace Thelia\Core;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Config\Util\XmlUtils;
use Symfony\Component\Yaml\Yaml;
@@ -42,12 +45,15 @@ use Thelia\Core\Bundle;
use Thelia\Log\Tlog;
use Thelia\Config\DatabaseConfiguration;
use Thelia\Config\DefinePropel;
use Thelia\Config\Dumper\TpexConfigDumper;
use Propel;
use PropelConfiguration;
class Thelia extends Kernel
{
protected $tpexConfig;
public function init()
{
@@ -114,33 +120,97 @@ class Thelia extends Kernel
* manage Tpex configuration here
*/
$config =\Symfony\Component\Config\Util\XmlUtils::loadFile(THELIA_PLUGIN_DIR . "/Test/Config/config.xml");
var_dump(\Symfony\Component\Config\Util\XmlUtils::convertDomElementToArray($config->documentElement));
$file = $this->getCacheDir() . "/TpexConfig.php";
$configCache = new ConfigCache($file, $this->debug);
$this->getLoopConfig();
if (!$configCache->isFresh()) {
$this->generateTpexConfigCache($configCache);
}
$container->set("loop", array(
"foo" => "Test\Loop\Foo",
"doobitch" => "Test\Loop\Doobitch"
));
require_once $configCache;
$container->set("filter", array());
$this->tpexConfig = new \TpexConfig();
$container->set("baseParam", array());
$container->set("loop", $this->tpexConfig->getLoopConfig());
$container->set("testLoop", array(
"equal" => "Test\TestLoop\Equal"
));
$container->set("filter", $this->tpexConfig->getFilterConfig());
$container->set("baseParam", $this->tpexConfig->getBaseParamConfig());
$container->set("testLoop", $this->tpexConfig->getLoopTestConfig());
}
protected function getLoopConfig()
protected function generateTpexConfigCache(ConfigCache $cache)
{
$loopConfig = array();
$filterConfig = array();
$baseParamConfig = array();
$loopTestConfig = array();
$resources = array();
//load master config, can be overload using modules
$masterConfigFile = THELIA_ROOT . "/core/lib/Thelia/config.xml";
if (file_exists($masterConfigFile)) {
$resources[] = new FileResource($masterConfigFile);
$dom = XmlUtils::loadFile($masterConfigFile);
$loopConfig = $this->processConfig($dom->getElementsByTagName("loop"));
$filterConfig = $this->processConfig($dom->getElementsByTagName("filter"));
$baseParamConfig = $this->processConfig($dom->getElementsByTagName("baseParam"));
$loopTestConfig = $this->processConfig($dom->getElementsByTagName("testLoop"));
}
$modules = \Thelia\Model\ModuleQuery::getActivated();
var_dump($modules);
foreach ($modules as $module) {
$configFile = THELIA_PLUGIN_DIR . "/" . ucfirst($module->getCode()) . "/Config/config.xml";
if (file_exists($configFile)) {
$resources[] = new FileResource($configFile);
$dom = XmlUtils::loadFile($configFile);
$loopConfig = array_merge($loopConfig, $this->processConfig($dom->getElementsByTagName("loop")));
$filterConfig = array_merge($filterConfig, $this->processConfig($dom->getElementsByTagName("filter")));
$baseParamConfig = array_merge(
$baseParamConfig,
$this->processConfig($dom->getElementsByTagName("baseParam"))
);
$loopTestConfig = array_merge(
$loopTestConfig,
$this->processConfig($dom->getElementsByTagName("testLoop"))
);
}
}
$tpexConfig = new TpexConfigDumper(
$loopConfig,
$filterConfig,
$baseParamConfig,
$loopTestConfig
);
$cache->write($tpexConfig->dump(), $resources);
}
protected function processConfig(\DOMNodeList $elements)
{
$result = array();
for ($i = 0; $i < $elements->length; $i ++) {
$element = XmlUtils::convertDomElementToArray($elements->item($i));
$result[$element["name"]] = $element["class"];
}
return $result;
}
/**
@@ -152,7 +222,7 @@ class Thelia extends Kernel
* @param \Symfony\Component\HttpFoundation\Request $request
*/
/**
*
* boot parent kernel and after current kernel
@@ -160,9 +230,6 @@ class Thelia extends Kernel
*/
public function boot()
{
parent::boot();
$this->loadConfiguration();

View File

@@ -18,10 +18,14 @@ use Thelia\Model\om\BaseModuleQuery;
*/
class ModuleQuery extends BaseModuleQuery
{
/**
* @return array|mixed|\PropelObjectCollection
*/
public static function getActivated()
{
return self::create()
->findByActivate(1)
->find();
->filterByActivate(1)
->find()
;
}
}

View File

@@ -40,7 +40,7 @@ class ModuleTableMap extends TableMap
$this->setPhpName('Module');
$this->setClassname('Thelia\\Model\\Module');
$this->setPackage('Thelia.Model');
$this->setUseIdGenerator(false);
$this->setUseIdGenerator(true);
// columns
$this->addPrimaryKey('id', 'Id', 'INTEGER', true, null, null);
$this->addColumn('code', 'Code', 'VARCHAR', true, 55, null);

View File

@@ -735,6 +735,10 @@ abstract class BaseModule extends BaseObject implements Persistent
$modifiedColumns = array();
$index = 0;
$this->modifiedColumns[] = ModulePeer::ID;
if (null !== $this->id) {
throw new PropelException('Cannot insert a value for auto-increment primary key (' . ModulePeer::ID . ')');
}
// check the columns in natural order for more readable SQL queries
if ($this->isColumnModified(ModulePeer::ID)) {
@@ -798,6 +802,13 @@ abstract class BaseModule extends BaseObject implements Persistent
throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), $e);
}
try {
$pk = $con->lastInsertId();
} catch (Exception $e) {
throw new PropelException('Unable to get autoincrement id.', $e);
}
$this->setId($pk);
$this->setNew(false);
}

View File

@@ -565,6 +565,10 @@ abstract class BaseModulePeer
$criteria = $values->buildCriteria(); // build Criteria from Module object
}
if ($criteria->containsKey(ModulePeer::ID) && $criteria->keyContainsValue(ModulePeer::ID) ) {
throw new PropelException('Cannot insert a value for auto-increment primary key ('.ModulePeer::ID.')');
}
// Set the correct dbName
$criteria->setDbName(ModulePeer::DATABASE_NAME);

View File

@@ -8,4 +8,6 @@
$env = "test";
require_once __DIR__ . '/../../../bootstrap.php';
\Propel::init(THELIA_ROOT . "/local/config/config_thelia.php");
\Propel::init(THELIA_ROOT . "/core/lib/Thelia/Tests/Db/thelia-conf.php");

View File

@@ -901,9 +901,9 @@ DROP TABLE IF EXISTS `module`;
CREATE TABLE `module`
(
`id` INTEGER NOT NULL,
`id` INTEGER NOT NULL AUTO_INCREMENT,
`code` VARCHAR(55) NOT NULL,
` type` TINYINT NOT NULL,
`type` TINYINT NOT NULL,
`activate` TINYINT,
`position` INTEGER,
`created_at` DATETIME,
@@ -1305,7 +1305,7 @@ DROP TABLE IF EXISTS `category_i18n`;
CREATE TABLE `category_i18n`
(
`id` INTEGER NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL,
`title` VARCHAR(255),
`description` LONGTEXT,
`chapo` TEXT,
@@ -1326,7 +1326,7 @@ DROP TABLE IF EXISTS `product_i18n`;
CREATE TABLE `product_i18n`
(
`id` INTEGER NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL,
`title` VARCHAR(255),
`description` LONGTEXT,
`chapo` TEXT,
@@ -1347,7 +1347,7 @@ DROP TABLE IF EXISTS `country_i18n`;
CREATE TABLE `country_i18n`
(
`id` INTEGER NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL,
`title` VARCHAR(255),
`description` LONGTEXT,
`chapo` TEXT,
@@ -1368,7 +1368,7 @@ DROP TABLE IF EXISTS `tax_i18n`;
CREATE TABLE `tax_i18n`
(
`id` INTEGER NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL,
`title` VARCHAR(255),
`description` TEXT,
PRIMARY KEY (`id`,`locale`),
@@ -1387,7 +1387,7 @@ DROP TABLE IF EXISTS `tax_rule_i18n`;
CREATE TABLE `tax_rule_i18n`
(
`id` INTEGER NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL,
PRIMARY KEY (`id`,`locale`),
CONSTRAINT `tax_rule_i18n_FK_1`
FOREIGN KEY (`id`)
@@ -1404,7 +1404,7 @@ DROP TABLE IF EXISTS `feature_i18n`;
CREATE TABLE `feature_i18n`
(
`id` INTEGER NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL,
`title` VARCHAR(255),
`description` LONGTEXT,
`chapo` TEXT,
@@ -1425,7 +1425,7 @@ DROP TABLE IF EXISTS `feature_av_i18n`;
CREATE TABLE `feature_av_i18n`
(
`id` INTEGER NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL,
`title` VARCHAR(255),
`description` LONGTEXT,
`chapo` TEXT,
@@ -1446,7 +1446,7 @@ DROP TABLE IF EXISTS `attribute_i18n`;
CREATE TABLE `attribute_i18n`
(
`id` INTEGER NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL,
`title` VARCHAR(255),
`description` LONGTEXT,
`chapo` TEXT,
@@ -1467,7 +1467,7 @@ DROP TABLE IF EXISTS `attribute_av_i18n`;
CREATE TABLE `attribute_av_i18n`
(
`id` INTEGER NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL,
`title` VARCHAR(255),
`description` LONGTEXT,
`chapo` TEXT,
@@ -1488,7 +1488,7 @@ DROP TABLE IF EXISTS `config_i18n`;
CREATE TABLE `config_i18n`
(
`id` INTEGER NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL,
`title` VARCHAR(255),
`description` LONGTEXT,
`chapo` TEXT,
@@ -1509,7 +1509,7 @@ DROP TABLE IF EXISTS `customer_title_i18n`;
CREATE TABLE `customer_title_i18n`
(
`id` INTEGER NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL,
`short` VARCHAR(10),
`long` VARCHAR(45),
PRIMARY KEY (`id`,`locale`),
@@ -1528,7 +1528,7 @@ DROP TABLE IF EXISTS `folder_i18n`;
CREATE TABLE `folder_i18n`
(
`id` INTEGER NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL,
`title` VARCHAR(255),
`description` LONGTEXT,
`chapo` TEXT,
@@ -1549,7 +1549,7 @@ DROP TABLE IF EXISTS `content_i18n`;
CREATE TABLE `content_i18n`
(
`id` INTEGER NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL,
`title` VARCHAR(255),
`description` LONGTEXT,
`chapo` TEXT,
@@ -1570,7 +1570,7 @@ DROP TABLE IF EXISTS `image_i18n`;
CREATE TABLE `image_i18n`
(
`id` INTEGER NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL,
`title` VARCHAR(255),
`description` LONGTEXT,
`chapo` TEXT,
@@ -1591,7 +1591,7 @@ DROP TABLE IF EXISTS `document_i18n`;
CREATE TABLE `document_i18n`
(
`id` INTEGER NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL,
`title` VARCHAR(255),
`description` LONGTEXT,
`chapo` TEXT,
@@ -1612,7 +1612,7 @@ DROP TABLE IF EXISTS `order_status_i18n`;
CREATE TABLE `order_status_i18n`
(
`id` INTEGER NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL,
`title` VARCHAR(255),
`description` LONGTEXT,
`chapo` TEXT,
@@ -1633,7 +1633,7 @@ DROP TABLE IF EXISTS `module_i18n`;
CREATE TABLE `module_i18n`
(
`id` INTEGER NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL,
`title` VARCHAR(255),
`description` LONGTEXT,
`chapo` TEXT,
@@ -1654,7 +1654,7 @@ DROP TABLE IF EXISTS `group_i18n`;
CREATE TABLE `group_i18n`
(
`id` INTEGER NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL,
`title` VARCHAR(255),
`description` LONGTEXT,
`chapo` TEXT,
@@ -1675,7 +1675,7 @@ DROP TABLE IF EXISTS `resource_i18n`;
CREATE TABLE `resource_i18n`
(
`id` INTEGER NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL,
`title` VARCHAR(255),
`description` LONGTEXT,
`chapo` TEXT,
@@ -1696,7 +1696,7 @@ DROP TABLE IF EXISTS `message_i18n`;
CREATE TABLE `message_i18n`
(
`id` INTEGER NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_EN' NOT NULL,
`locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL,
`title` TEXT,
`description` LONGTEXT,
`description_html` LONGTEXT,

View File

@@ -671,7 +671,7 @@
<behavior name="timestampable" />
</table>
<table name="module">
<column name="id" primaryKey="true" required="true" type="INTEGER" />
<column autoIncrement="true" name="id" primaryKey="true" required="true" type="INTEGER" />
<column name="code" required="true" size="55" type="VARCHAR" />
<column name="type" required="true" type="TINYINT" />
<column name="activate" type="TINYINT" />