fix model

This commit is contained in:
Etienne Roudeix
2014-01-06 12:23:01 +01:00
parent 6a64f827ce
commit 4e847bf5ae
9 changed files with 216 additions and 82 deletions

View File

@@ -1393,53 +1393,53 @@ abstract class Coupon implements ActiveRecordInterface
// check the columns in natural order for more readable SQL queries
if ($this->isColumnModified(CouponTableMap::ID)) {
$modifiedColumns[':p' . $index++] = 'ID';
$modifiedColumns[':p' . $index++] = '`ID`';
}
if ($this->isColumnModified(CouponTableMap::CODE)) {
$modifiedColumns[':p' . $index++] = 'CODE';
$modifiedColumns[':p' . $index++] = '`CODE`';
}
if ($this->isColumnModified(CouponTableMap::TYPE)) {
$modifiedColumns[':p' . $index++] = 'TYPE';
$modifiedColumns[':p' . $index++] = '`TYPE`';
}
if ($this->isColumnModified(CouponTableMap::SERIALIZED_EFFECTS)) {
$modifiedColumns[':p' . $index++] = 'SERIALIZED_EFFECTS';
$modifiedColumns[':p' . $index++] = '`SERIALIZED_EFFECTS`';
}
if ($this->isColumnModified(CouponTableMap::IS_ENABLED)) {
$modifiedColumns[':p' . $index++] = 'IS_ENABLED';
$modifiedColumns[':p' . $index++] = '`IS_ENABLED`';
}
if ($this->isColumnModified(CouponTableMap::EXPIRATION_DATE)) {
$modifiedColumns[':p' . $index++] = 'EXPIRATION_DATE';
$modifiedColumns[':p' . $index++] = '`EXPIRATION_DATE`';
}
if ($this->isColumnModified(CouponTableMap::MAX_USAGE)) {
$modifiedColumns[':p' . $index++] = 'MAX_USAGE';
$modifiedColumns[':p' . $index++] = '`MAX_USAGE`';
}
if ($this->isColumnModified(CouponTableMap::IS_CUMULATIVE)) {
$modifiedColumns[':p' . $index++] = 'IS_CUMULATIVE';
$modifiedColumns[':p' . $index++] = '`IS_CUMULATIVE`';
}
if ($this->isColumnModified(CouponTableMap::IS_REMOVING_POSTAGE)) {
$modifiedColumns[':p' . $index++] = 'IS_REMOVING_POSTAGE';
$modifiedColumns[':p' . $index++] = '`IS_REMOVING_POSTAGE`';
}
if ($this->isColumnModified(CouponTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS)) {
$modifiedColumns[':p' . $index++] = 'IS_AVAILABLE_ON_SPECIAL_OFFERS';
$modifiedColumns[':p' . $index++] = '`IS_AVAILABLE_ON_SPECIAL_OFFERS`';
}
if ($this->isColumnModified(CouponTableMap::IS_USED)) {
$modifiedColumns[':p' . $index++] = 'IS_USED';
$modifiedColumns[':p' . $index++] = '`IS_USED`';
}
if ($this->isColumnModified(CouponTableMap::SERIALIZED_CONDITIONS)) {
$modifiedColumns[':p' . $index++] = 'SERIALIZED_CONDITIONS';
$modifiedColumns[':p' . $index++] = '`SERIALIZED_CONDITIONS`';
}
if ($this->isColumnModified(CouponTableMap::CREATED_AT)) {
$modifiedColumns[':p' . $index++] = 'CREATED_AT';
$modifiedColumns[':p' . $index++] = '`CREATED_AT`';
}
if ($this->isColumnModified(CouponTableMap::UPDATED_AT)) {
$modifiedColumns[':p' . $index++] = 'UPDATED_AT';
$modifiedColumns[':p' . $index++] = '`UPDATED_AT`';
}
if ($this->isColumnModified(CouponTableMap::VERSION)) {
$modifiedColumns[':p' . $index++] = 'VERSION';
$modifiedColumns[':p' . $index++] = '`VERSION`';
}
$sql = sprintf(
'INSERT INTO coupon (%s) VALUES (%s)',
'INSERT INTO `coupon` (%s) VALUES (%s)',
implode(', ', $modifiedColumns),
implode(', ', array_keys($modifiedColumns))
);
@@ -1448,49 +1448,49 @@ abstract class Coupon implements ActiveRecordInterface
$stmt = $con->prepare($sql);
foreach ($modifiedColumns as $identifier => $columnName) {
switch ($columnName) {
case 'ID':
case '`ID`':
$stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
break;
case 'CODE':
case '`CODE`':
$stmt->bindValue($identifier, $this->code, PDO::PARAM_STR);
break;
case 'TYPE':
case '`TYPE`':
$stmt->bindValue($identifier, $this->type, PDO::PARAM_STR);
break;
case 'SERIALIZED_EFFECTS':
case '`SERIALIZED_EFFECTS`':
$stmt->bindValue($identifier, $this->serialized_effects, PDO::PARAM_STR);
break;
case 'IS_ENABLED':
case '`IS_ENABLED`':
$stmt->bindValue($identifier, (int) $this->is_enabled, PDO::PARAM_INT);
break;
case 'EXPIRATION_DATE':
case '`EXPIRATION_DATE`':
$stmt->bindValue($identifier, $this->expiration_date ? $this->expiration_date->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
break;
case 'MAX_USAGE':
case '`MAX_USAGE`':
$stmt->bindValue($identifier, $this->max_usage, PDO::PARAM_INT);
break;
case 'IS_CUMULATIVE':
case '`IS_CUMULATIVE`':
$stmt->bindValue($identifier, (int) $this->is_cumulative, PDO::PARAM_INT);
break;
case 'IS_REMOVING_POSTAGE':
case '`IS_REMOVING_POSTAGE`':
$stmt->bindValue($identifier, (int) $this->is_removing_postage, PDO::PARAM_INT);
break;
case 'IS_AVAILABLE_ON_SPECIAL_OFFERS':
case '`IS_AVAILABLE_ON_SPECIAL_OFFERS`':
$stmt->bindValue($identifier, (int) $this->is_available_on_special_offers, PDO::PARAM_INT);
break;
case 'IS_USED':
case '`IS_USED`':
$stmt->bindValue($identifier, (int) $this->is_used, PDO::PARAM_INT);
break;
case 'SERIALIZED_CONDITIONS':
case '`SERIALIZED_CONDITIONS`':
$stmt->bindValue($identifier, $this->serialized_conditions, PDO::PARAM_STR);
break;
case 'CREATED_AT':
case '`CREATED_AT`':
$stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
break;
case 'UPDATED_AT':
case '`UPDATED_AT`':
$stmt->bindValue($identifier, $this->updated_at ? $this->updated_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
break;
case 'VERSION':
case '`VERSION`':
$stmt->bindValue($identifier, $this->version, PDO::PARAM_INT);
break;
}

View File

@@ -195,7 +195,7 @@ abstract class CouponQuery extends ModelCriteria
*/
protected function findPkSimple($key, $con)
{
$sql = 'SELECT ID, CODE, TYPE, SERIALIZED_EFFECTS, IS_ENABLED, EXPIRATION_DATE, MAX_USAGE, IS_CUMULATIVE, IS_REMOVING_POSTAGE, IS_AVAILABLE_ON_SPECIAL_OFFERS, IS_USED, SERIALIZED_CONDITIONS, CREATED_AT, UPDATED_AT, VERSION FROM coupon WHERE ID = :p0';
$sql = 'SELECT `ID`, `CODE`, `TYPE`, `SERIALIZED_EFFECTS`, `IS_ENABLED`, `EXPIRATION_DATE`, `MAX_USAGE`, `IS_CUMULATIVE`, `IS_REMOVING_POSTAGE`, `IS_AVAILABLE_ON_SPECIAL_OFFERS`, `IS_USED`, `SERIALIZED_CONDITIONS`, `CREATED_AT`, `UPDATED_AT`, `VERSION` FROM `coupon` WHERE `ID` = :p0';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key, PDO::PARAM_INT);

View File

@@ -1305,53 +1305,53 @@ abstract class CouponVersion implements ActiveRecordInterface
// check the columns in natural order for more readable SQL queries
if ($this->isColumnModified(CouponVersionTableMap::ID)) {
$modifiedColumns[':p' . $index++] = 'ID';
$modifiedColumns[':p' . $index++] = '`ID`';
}
if ($this->isColumnModified(CouponVersionTableMap::CODE)) {
$modifiedColumns[':p' . $index++] = 'CODE';
$modifiedColumns[':p' . $index++] = '`CODE`';
}
if ($this->isColumnModified(CouponVersionTableMap::TYPE)) {
$modifiedColumns[':p' . $index++] = 'TYPE';
$modifiedColumns[':p' . $index++] = '`TYPE`';
}
if ($this->isColumnModified(CouponVersionTableMap::SERIALIZED_EFFECTS)) {
$modifiedColumns[':p' . $index++] = 'SERIALIZED_EFFECTS';
$modifiedColumns[':p' . $index++] = '`SERIALIZED_EFFECTS`';
}
if ($this->isColumnModified(CouponVersionTableMap::IS_ENABLED)) {
$modifiedColumns[':p' . $index++] = 'IS_ENABLED';
$modifiedColumns[':p' . $index++] = '`IS_ENABLED`';
}
if ($this->isColumnModified(CouponVersionTableMap::EXPIRATION_DATE)) {
$modifiedColumns[':p' . $index++] = 'EXPIRATION_DATE';
$modifiedColumns[':p' . $index++] = '`EXPIRATION_DATE`';
}
if ($this->isColumnModified(CouponVersionTableMap::MAX_USAGE)) {
$modifiedColumns[':p' . $index++] = 'MAX_USAGE';
$modifiedColumns[':p' . $index++] = '`MAX_USAGE`';
}
if ($this->isColumnModified(CouponVersionTableMap::IS_CUMULATIVE)) {
$modifiedColumns[':p' . $index++] = 'IS_CUMULATIVE';
$modifiedColumns[':p' . $index++] = '`IS_CUMULATIVE`';
}
if ($this->isColumnModified(CouponVersionTableMap::IS_REMOVING_POSTAGE)) {
$modifiedColumns[':p' . $index++] = 'IS_REMOVING_POSTAGE';
$modifiedColumns[':p' . $index++] = '`IS_REMOVING_POSTAGE`';
}
if ($this->isColumnModified(CouponVersionTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS)) {
$modifiedColumns[':p' . $index++] = 'IS_AVAILABLE_ON_SPECIAL_OFFERS';
$modifiedColumns[':p' . $index++] = '`IS_AVAILABLE_ON_SPECIAL_OFFERS`';
}
if ($this->isColumnModified(CouponVersionTableMap::IS_USED)) {
$modifiedColumns[':p' . $index++] = 'IS_USED';
$modifiedColumns[':p' . $index++] = '`IS_USED`';
}
if ($this->isColumnModified(CouponVersionTableMap::SERIALIZED_CONDITIONS)) {
$modifiedColumns[':p' . $index++] = 'SERIALIZED_CONDITIONS';
$modifiedColumns[':p' . $index++] = '`SERIALIZED_CONDITIONS`';
}
if ($this->isColumnModified(CouponVersionTableMap::CREATED_AT)) {
$modifiedColumns[':p' . $index++] = 'CREATED_AT';
$modifiedColumns[':p' . $index++] = '`CREATED_AT`';
}
if ($this->isColumnModified(CouponVersionTableMap::UPDATED_AT)) {
$modifiedColumns[':p' . $index++] = 'UPDATED_AT';
$modifiedColumns[':p' . $index++] = '`UPDATED_AT`';
}
if ($this->isColumnModified(CouponVersionTableMap::VERSION)) {
$modifiedColumns[':p' . $index++] = 'VERSION';
$modifiedColumns[':p' . $index++] = '`VERSION`';
}
$sql = sprintf(
'INSERT INTO coupon_version (%s) VALUES (%s)',
'INSERT INTO `coupon_version` (%s) VALUES (%s)',
implode(', ', $modifiedColumns),
implode(', ', array_keys($modifiedColumns))
);
@@ -1360,49 +1360,49 @@ abstract class CouponVersion implements ActiveRecordInterface
$stmt = $con->prepare($sql);
foreach ($modifiedColumns as $identifier => $columnName) {
switch ($columnName) {
case 'ID':
case '`ID`':
$stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
break;
case 'CODE':
case '`CODE`':
$stmt->bindValue($identifier, $this->code, PDO::PARAM_STR);
break;
case 'TYPE':
case '`TYPE`':
$stmt->bindValue($identifier, $this->type, PDO::PARAM_STR);
break;
case 'SERIALIZED_EFFECTS':
case '`SERIALIZED_EFFECTS`':
$stmt->bindValue($identifier, $this->serialized_effects, PDO::PARAM_STR);
break;
case 'IS_ENABLED':
case '`IS_ENABLED`':
$stmt->bindValue($identifier, (int) $this->is_enabled, PDO::PARAM_INT);
break;
case 'EXPIRATION_DATE':
case '`EXPIRATION_DATE`':
$stmt->bindValue($identifier, $this->expiration_date ? $this->expiration_date->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
break;
case 'MAX_USAGE':
case '`MAX_USAGE`':
$stmt->bindValue($identifier, $this->max_usage, PDO::PARAM_INT);
break;
case 'IS_CUMULATIVE':
case '`IS_CUMULATIVE`':
$stmt->bindValue($identifier, (int) $this->is_cumulative, PDO::PARAM_INT);
break;
case 'IS_REMOVING_POSTAGE':
case '`IS_REMOVING_POSTAGE`':
$stmt->bindValue($identifier, (int) $this->is_removing_postage, PDO::PARAM_INT);
break;
case 'IS_AVAILABLE_ON_SPECIAL_OFFERS':
case '`IS_AVAILABLE_ON_SPECIAL_OFFERS`':
$stmt->bindValue($identifier, (int) $this->is_available_on_special_offers, PDO::PARAM_INT);
break;
case 'IS_USED':
case '`IS_USED`':
$stmt->bindValue($identifier, (int) $this->is_used, PDO::PARAM_INT);
break;
case 'SERIALIZED_CONDITIONS':
case '`SERIALIZED_CONDITIONS`':
$stmt->bindValue($identifier, $this->serialized_conditions, PDO::PARAM_STR);
break;
case 'CREATED_AT':
case '`CREATED_AT`':
$stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
break;
case 'UPDATED_AT':
case '`UPDATED_AT`':
$stmt->bindValue($identifier, $this->updated_at ? $this->updated_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
break;
case 'VERSION':
case '`VERSION`':
$stmt->bindValue($identifier, $this->version, PDO::PARAM_INT);
break;
}

View File

@@ -183,7 +183,7 @@ abstract class CouponVersionQuery extends ModelCriteria
*/
protected function findPkSimple($key, $con)
{
$sql = 'SELECT ID, CODE, TYPE, SERIALIZED_EFFECTS, IS_ENABLED, EXPIRATION_DATE, MAX_USAGE, IS_CUMULATIVE, IS_REMOVING_POSTAGE, IS_AVAILABLE_ON_SPECIAL_OFFERS, IS_USED, SERIALIZED_CONDITIONS, CREATED_AT, UPDATED_AT, VERSION FROM coupon_version WHERE ID = :p0 AND VERSION = :p1';
$sql = 'SELECT `ID`, `CODE`, `TYPE`, `SERIALIZED_EFFECTS`, `IS_ENABLED`, `EXPIRATION_DATE`, `MAX_USAGE`, `IS_CUMULATIVE`, `IS_REMOVING_POSTAGE`, `IS_AVAILABLE_ON_SPECIAL_OFFERS`, `IS_USED`, `SERIALIZED_CONDITIONS`, `CREATED_AT`, `UPDATED_AT`, `VERSION` FROM `coupon_version` WHERE `ID` = :p0 AND `VERSION` = :p1';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key[0], PDO::PARAM_INT);

View File

@@ -183,7 +183,7 @@ abstract class OrderCouponQuery extends ModelCriteria
*/
protected function findPkSimple($key, $con)
{
$sql = 'SELECT ID, ORDER_ID, CODE, TYPE, AMOUNT, TITLE, SHORT_DESCRIPTION, DESCRIPTION, EXPIRATION_DATE, IS_CUMULATIVE, IS_REMOVING_POSTAGE, IS_AVAILABLE_ON_SPECIAL_OFFERS, SERIALIZED_CONDITIONS, CREATED_AT, UPDATED_AT FROM order_coupon WHERE ID = :p0';
$sql = 'SELECT `ID`, `ORDER_ID`, `CODE`, `TYPE`, `AMOUNT`, `TITLE`, `SHORT_DESCRIPTION`, `DESCRIPTION`, `EXPIRATION_DATE`, `IS_CUMULATIVE`, `IS_REMOVING_POSTAGE`, `IS_AVAILABLE_ON_SPECIAL_OFFERS`, `SERIALIZED_CONDITIONS`, `CREATED_AT`, `UPDATED_AT` FROM `order_coupon` WHERE `ID` = :p0';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key, PDO::PARAM_INT);

View File

@@ -140,6 +140,9 @@ abstract class ProductQuery extends ModelCriteria
*/
static $isVersioningEnabled = true;
// query_cache behavior
protected $queryKey = '';
/**
* Initializes internal state of \Thelia\Model\Base\ProductQuery object.
*
@@ -1995,4 +1998,126 @@ abstract class ProductQuery extends ModelCriteria
self::$isVersioningEnabled = false;
}
// query_cache behavior
public function setQueryKey($key)
{
$this->queryKey = $key;
return $this;
}
public function getQueryKey()
{
return $this->queryKey;
}
public function cacheContains($key)
{
return apc_fetch($key);
}
public function cacheFetch($key)
{
return apc_fetch($key);
}
public function cacheStore($key, $value, $lifetime = 3600)
{
apc_store($key, $value, $lifetime);
}
protected function doSelect($con)
{
// check that the columns of the main class are already added (if this is the primary ModelCriteria)
if (!$this->hasSelectClause() && !$this->getPrimaryCriteria()) {
$this->addSelfSelectColumns();
}
$this->configureSelectColumns();
$dbMap = Propel::getServiceContainer()->getDatabaseMap(ProductTableMap::DATABASE_NAME);
$db = Propel::getServiceContainer()->getAdapter(ProductTableMap::DATABASE_NAME);
$key = $this->getQueryKey();
if ($key && $this->cacheContains($key)) {
$params = $this->getParams();
$sql = $this->cacheFetch($key);
} else {
$params = array();
$sql = $this->createSelectSql($params);
if ($key) {
$this->cacheStore($key, $sql);
}
}
try {
$stmt = $con->prepare($sql);
$db->bindValues($stmt, $params, $dbMap);
$stmt->execute();
} catch (Exception $e) {
Propel::log($e->getMessage(), Propel::LOG_ERR);
throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e);
}
return $stmt;
}
protected function doCount($con)
{
$dbMap = Propel::getServiceContainer()->getDatabaseMap($this->getDbName());
$db = Propel::getServiceContainer()->getAdapter($this->getDbName());
$key = $this->getQueryKey();
if ($key && $this->cacheContains($key)) {
$params = $this->getParams();
$sql = $this->cacheFetch($key);
} else {
// check that the columns of the main class are already added (if this is the primary ModelCriteria)
if (!$this->hasSelectClause() && !$this->getPrimaryCriteria()) {
$this->addSelfSelectColumns();
}
$this->configureSelectColumns();
$needsComplexCount = $this->getGroupByColumns()
|| $this->getOffset()
|| $this->getLimit()
|| $this->getHaving()
|| in_array(Criteria::DISTINCT, $this->getSelectModifiers());
$params = array();
if ($needsComplexCount) {
if ($this->needsSelectAliases()) {
if ($this->getHaving()) {
throw new PropelException('Propel cannot create a COUNT query when using HAVING and duplicate column names in the SELECT part');
}
$db->turnSelectColumnsToAliases($this);
}
$selectSql = $this->createSelectSql($params);
$sql = 'SELECT COUNT(*) FROM (' . $selectSql . ') propelmatch4cnt';
} else {
// Replace SELECT columns with COUNT(*)
$this->clearSelectColumns()->addSelectColumn('COUNT(*)');
$sql = $this->createSelectSql($params);
}
if ($key) {
$this->cacheStore($key, $sql);
}
}
try {
$stmt = $con->prepare($sql);
$db->bindValues($stmt, $params, $dbMap);
$stmt->execute();
} catch (Exception $e) {
Propel::log($e->getMessage(), Propel::LOG_ERR);
throw new PropelException(sprintf('Unable to execute COUNT statement [%s]', $sql), 0, $e);
}
return $stmt;
}
} // ProductQuery