// Remove $this->table and $this->identifier from objectModels + normalize

This commit is contained in:
rMalie committed 2011-12-09 14:05:24 +00:00
1 parent 540858527b
commit a284e2ef8b
20 files changed
+124 -115

No files matched your search

+1 -1
View File
@@ -526,7 +526,7 @@ class AddressFormatCore extends ObjectModel
{ {
$result = Db::getInstance()->getRow(' $result = Db::getInstance()->getRow('
SELECT format SELECT format
FROM `'._DB_PREFIX_.$this->table.'` FROM `'._DB_PREFIX_.$this->def['table'].'`
WHERE `id_country` = '.(int)($id_country)); WHERE `id_country` = '.(int)($id_country));
return isset($result['format']) ? trim($result['format']) : ''; return isset($result['format']) ? trim($result['format']) : '';
+4 -4
View File
@@ -40,11 +40,11 @@ class AliasCore extends ObjectModel
'primary' => 'id_alias', 'primary' => 'id_alias',
); );
function __construct($id = NULL, $alias = NULL, $search = NULL, $id_lang = NULL) public function __construct($id = NULL, $alias = NULL, $search = NULL, $id_lang = NULL)
{ {
if ($id) if ($id)
parent::__construct($id); parent::__construct($id);
elseif ($alias AND Validate::isValidSearch($alias)) else if ($alias && Validate::isValidSearch($alias))
{ {
if (!self::isFeatureActive()) if (!self::isFeatureActive())
{ {
@@ -89,7 +89,7 @@ class AliasCore extends ObjectModel
if (parent::delete()) if (parent::delete())
{ {
// Refresh cache of feature detachable // Refresh cache of feature detachable
Configuration::updateGlobalValue('PS_ALIAS_FEATURE_ACTIVE', self::isCurrentlyUsed($this->table, true)); Configuration::updateGlobalValue('PS_ALIAS_FEATURE_ACTIVE', self::isCurrentlyUsed($this->def['table'], true));
return true; return true;
} }
return false; return false;
@@ -115,7 +115,7 @@ class AliasCore extends ObjectModel
$fields['alias'] = pSQL($this->alias); $fields['alias'] = pSQL($this->alias);
$fields['search'] = pSQL($this->search); $fields['search'] = pSQL($this->search);
$fields['active'] = (int)($this->active); $fields['active'] = (int)$this->active;
return $fields; return $fields;
} }
+2 -2
View File
@@ -92,7 +92,7 @@ class AttributeCore extends ObjectModel
$result = Db::getInstance()->executeS(' $result = Db::getInstance()->executeS('
SELECT `id_product_attribute` SELECT `id_product_attribute`
FROM `'._DB_PREFIX_.'product_attribute_combination` FROM `'._DB_PREFIX_.'product_attribute_combination`
WHERE `'.$this->identifier.'` = '.(int)$this->id WHERE `'.$this->def['primary'].'` = '.(int)$this->id
); );
if ($result === false) if ($result === false)
@@ -106,7 +106,7 @@ class AttributeCore extends ObjectModel
if (Db::getInstance()->execute(' if (Db::getInstance()->execute('
DELETE FROM `'._DB_PREFIX_.'product_attribute_combination` DELETE FROM `'._DB_PREFIX_.'product_attribute_combination`
WHERE `'.$this->identifier.'` = '.(int)$this->id) === false) WHERE `'.$this->def['primary'].'` = '.(int)$this->id) === false)
return false; return false;
if (Db::getInstance()->execute(' if (Db::getInstance()->execute('
+4 -4
View File
@@ -190,7 +190,7 @@ class CarrierCore extends ObjectModel
{ {
if (!parent::add($autodate, $null_values) || !Validate::isLoadedObject($this)) if (!parent::add($autodate, $null_values) || !Validate::isLoadedObject($this))
return false; return false;
if (!Db::getInstance()->executeS('SELECT `id_carrier` FROM `'._DB_PREFIX_.$this->table.'` WHERE `deleted` = 0')) if (!Db::getInstance()->executeS('SELECT `id_carrier` FROM `'._DB_PREFIX_.$this->def['table'].'` WHERE `deleted` = 0'))
return false; return false;
if (!$num_rows = Db::getInstance()->NumRows()) if (!$num_rows = Db::getInstance()->NumRows())
return false; return false;
@@ -198,7 +198,7 @@ class CarrierCore extends ObjectModel
Configuration::updateValue('PS_CARRIER_DEFAULT', (int)$this->id); Configuration::updateValue('PS_CARRIER_DEFAULT', (int)$this->id);
// Register reference // Register reference
Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.$this->table.'` SET `id_reference` = '.$this->id.' WHERE `id_carrier` = '.$this->id); Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.$this->def['table'].'` SET `id_reference` = '.$this->id.' WHERE `id_carrier` = '.$this->id);
return true; return true;
} }
@@ -794,8 +794,8 @@ class CarrierCore extends ObjectModel
Configuration::updateValue('PS_CARRIER_DEFAULT', (int)$this->id); Configuration::updateValue('PS_CARRIER_DEFAULT', (int)$this->id);
// Copy reference // Copy reference
$id_reference = Db::getInstance()->getValue('SELECT `id_reference` FROM `'._DB_PREFIX_.$this->table.'` WHERE id_carrier = '.$old_id); $id_reference = Db::getInstance()->getValue('SELECT `id_reference` FROM `'._DB_PREFIX_.$this->def['table'].'` WHERE id_carrier = '.$old_id);
Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.$this->table.'` Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.$this->def['table'].'`
SET `id_reference` = '.$id_reference.' SET `id_reference` = '.$id_reference.'
WHERE `id_carrier` = '.$this->id); WHERE `id_carrier` = '.$this->id);
} }
+1 -1
View File
@@ -152,7 +152,7 @@ class CartRuleCore extends ObjectModel
if (!parent::delete()) if (!parent::delete())
return false; return false;
Configuration::updateGlobalValue('PS_CART_RULE_FEATURE_ACTIVE', CartRule::isCurrentlyUsed($this->table, true)); Configuration::updateGlobalValue('PS_CART_RULE_FEATURE_ACTIVE', CartRule::isCurrentlyUsed($this->def['table'], true));
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_cart_rule` WHERE `id_cart_rule` = '.(int)$this->id); Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_cart_rule` WHERE `id_cart_rule` = '.(int)$this->id);
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_rule_carrier` WHERE `id_cart_rule` = '.(int)$this->id); Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_rule_carrier` WHERE `id_cart_rule` = '.(int)$this->id);
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_rule_group` WHERE `id_cart_rule` = '.(int)$this->id); Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_rule_group` WHERE `id_cart_rule` = '.(int)$this->id);
+2 -2
View File
@@ -494,11 +494,11 @@ class ConfigurationCore extends ObjectModel
public function getWebserviceObjectList($sql_join, $sql_filter, $sql_sort, $sql_limit) public function getWebserviceObjectList($sql_join, $sql_filter, $sql_sort, $sql_limit)
{ {
$query = ' $query = '
SELECT DISTINCT main.`'.$this->identifier.'` FROM `'._DB_PREFIX_.$this->table.'` main SELECT DISTINCT main.`'.$this->def['primary'].'` FROM `'._DB_PREFIX_.$this->def['table'].'` main
'.$sql_join.' '.$sql_join.'
WHERE id_configuration NOT IN WHERE id_configuration NOT IN
( SELECT id_configuration ( SELECT id_configuration
FROM '._DB_PREFIX_.$this->table.'_lang FROM '._DB_PREFIX_.$this->def['table'].'_lang
) '.$sql_filter.' ) '.$sql_filter.'
'.($sql_sort != '' ? $sql_sort : '').' '.($sql_sort != '' ? $sql_sort : '').'
'.($sql_limit != '' ? $sql_limit : '').' '.($sql_limit != '' ? $sql_limit : '').'
+5 -3
View File
@@ -147,14 +147,16 @@ class CurrencyCore extends ObjectModel
public function deleteSelection($selection) public function deleteSelection($selection)
{ {
if (!is_array($selection) OR !Validate::isTableOrIdentifier($this->identifier) OR !Validate::isTableOrIdentifier($this->table)) if (!is_array($selection))
die(Tools::displayError()); die(Tools::displayError());
foreach ($selection AS $id)
foreach ($selection as $id)
{ {
$obj = new Currency((int)($id)); $obj = new Currency((int)($id));
$res[$id] = $obj->delete(); $res[$id] = $obj->delete();
} }
foreach ($res AS $value)
foreach ($res as $value)
if (!$value) if (!$value)
return false; return false;
return true; return true;
+2 -2
View File
@@ -607,9 +607,9 @@ class CustomerCore extends ObjectModel
/* Change status to active/inactive */ /* Change status to active/inactive */
return Db::getInstance()->execute(' return Db::getInstance()->execute('
UPDATE `'.pSQL(_DB_PREFIX_.$this->table).'` UPDATE `'.pSQL(_DB_PREFIX_.$this->def['table']).'`
SET `date_upd` = NOW() SET `date_upd` = NOW()
WHERE `'.pSQL($this->identifier).'` = '.(int)$this->id); WHERE `'.$this->def['primary'].'` = '.(int)$this->id);
} }
+9 -5
View File
@@ -169,13 +169,17 @@ class FeatureCore extends ObjectModel
if (!Validate::isTableOrIdentifier($key)) if (!Validate::isTableOrIdentifier($key))
die(Tools::displayError()); die(Tools::displayError());
$sql = 'SELECT `id_lang` FROM `'.pSQL(_DB_PREFIX_.$this->table).'_lang` $sql = 'SELECT `id_lang` FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'_lang`
WHERE `'.pSQL($this->identifier).'` = '.(int)$this->id.' WHERE `'.$this->def['primary'].'` = '.(int)$this->id.'
AND `id_lang` = '.(int)$field['id_lang']; AND `id_lang` = '.(int)$field['id_lang'];
$mode = Db::getInstance()->getRow($sql); $mode = Db::getInstance()->getRow($sql);
$result &= (!$mode) ? Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->table.'_lang', $field, 'INSERT') : $result &= (!$mode) ? Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->def['table'].'_lang', $field, 'INSERT') :
Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->table.'_lang', $field, 'UPDATE', '`'. Db::getInstance()->AutoExecute(
pSQL($this->identifier).'` = '.(int)$this->id.' AND `id_lang` = '.(int)$field['id_lang']); _DB_PREFIX_.$this->def['table'].'_lang',
$field,
'UPDATE',
'`'.$this->def['primary'].'` = '.(int)$this->id.' AND `id_lang` = '.(int)$field['id_lang']
);
} }
Hook::exec('afterSaveFeature', array('id_feature' => $this->id)); Hook::exec('afterSaveFeature', array('id_feature' => $this->id));
return $result; return $result;
+1 -1
View File
@@ -123,7 +123,7 @@ class ImageCore extends ObjectModel
{ {
$row['position'] = $i++; $row['position'] = $i++;
Db::getInstance()->AutoExecute( Db::getInstance()->AutoExecute(
_DB_PREFIX_.$this->table, _DB_PREFIX_.$this->def['table'],
$row, $row,
'UPDATE', 'UPDATE',
'`id_image` = '.(int)$row['id_image'], 1 '`id_image` = '.(int)$row['id_image'], 1
+8 -7
View File
@@ -477,10 +477,11 @@ class LanguageCore extends ObjectModel
public function deleteSelection($selection) public function deleteSelection($selection)
{ {
if (!is_array($selection) OR !Validate::isTableOrIdentifier($this->identifier) OR !Validate::isTableOrIdentifier($this->table)) if (!is_array($selection))
die(Tools::displayError()); die(Tools::displayError());
$result = true; $result = true;
foreach ($selection AS $id) foreach ($selection as $id)
{ {
$this->id = (int)($id); $this->id = (int)($id);
$result = $result AND $this->delete(); $result = $result AND $this->delete();
@@ -491,11 +492,11 @@ class LanguageCore extends ObjectModel
return true; return true;
Tools::generateHtaccess(dirname(__FILE__).'/../.htaccess', Tools::generateHtaccess(dirname(__FILE__).'/../.htaccess',
(int)(Configuration::get('PS_REWRITING_SETTINGS')), (int)Configuration::get('PS_REWRITING_SETTINGS'),
(int)(Configuration::get('PS_HTACCESS_CACHE_CONTROL')), (int)Configuration::get('PS_HTACCESS_CACHE_CONTROL'),
'', '',
(int)Configuration::get('PS_HTACCESS_DISABLE_MULTIVIEWS') (int)Configuration::get('PS_HTACCESS_DISABLE_MULTIVIEWS')
); );
return $result; return $result;
} }
+1 -1
View File
@@ -156,7 +156,7 @@ class ManufacturerCore extends ObjectModel
*/ */
public function deleteSelection($selection) public function deleteSelection($selection)
{ {
if (!is_array($selection) || !Validate::isTableOrIdentifier($this->identifier) || !Validate::isTableOrIdentifier($this->table)) if (!is_array($selection))
die(Tools::displayError()); die(Tools::displayError());
$result = true; $result = true;
+1 -1
View File
@@ -167,7 +167,7 @@ class MetaCore extends ObjectModel
public function deleteSelection($selection) public function deleteSelection($selection)
{ {
if (!is_array($selection) OR !Validate::isTableOrIdentifier($this->identifier) OR !Validate::isTableOrIdentifier($this->table)) if (!is_array($selection))
die(Tools::displayError()); die(Tools::displayError());
$result = true; $result = true;
foreach ($selection AS $id) foreach ($selection AS $id)
+61 -61
View File
@@ -149,19 +149,19 @@ abstract class ObjectModelCore
if ($this->isLangMultishop() && !$this->id_shop) if ($this->isLangMultishop() && !$this->id_shop)
$this->id_shop = Context::getContext()->shop->getID(true); $this->id_shop = Context::getContext()->shop->getID(true);
if (!Validate::isTableOrIdentifier($this->identifier) || !Validate::isTableOrIdentifier($this->table)) if (!Validate::isTableOrIdentifier($this->def['primary']) || !Validate::isTableOrIdentifier($this->def['table']))
throw new PrestashopException('Identifier or table format not valid for class '.get_class($this)); throw new PrestashopException('Identifier or table format not valid for class '.get_class($this));
if ($id) if ($id)
{ {
// Load object from database if object id is present // Load object from database if object id is present
$cache_id = 'objectmodel_'.$this->table.'_'.(int)$id.'_'.(int)$id_shop.'_'.(int)$id_lang; $cache_id = 'objectmodel_'.$this->def['table'].'_'.(int)$id.'_'.(int)$id_shop.'_'.(int)$id_lang;
if (!Cache::isStored($cache_id)) if (!Cache::isStored($cache_id))
{ {
$sql = 'SELECT * $sql = 'SELECT *
FROM `'._DB_PREFIX_.$this->table.'` a '. FROM `'._DB_PREFIX_.$this->def['table'].'` a '.
($id_lang ? ('LEFT JOIN `'.pSQL(_DB_PREFIX_.$this->table).'_lang` b ON (a.`'.$this->identifier.'` = b.`'.$this->identifier).'` AND `id_lang` = '.(int)($id_lang).')' : '') ($id_lang ? ('LEFT JOIN `'.pSQL(_DB_PREFIX_.$this->def['table']).'_lang` b ON (a.`'.$this->def['primary'].'` = b.`'.$this->def['primary']).'` AND `id_lang` = '.(int)($id_lang).')' : '')
.' WHERE 1 AND a.`'.$this->identifier.'` = '.(int)$id. .' WHERE 1 AND a.`'.$this->def['primary'].'` = '.(int)$id.
(($this->id_shop AND $id_lang) ? ' AND b.id_shop = '.$this->id_shop : ''); (($this->id_shop AND $id_lang) ? ' AND b.id_shop = '.$this->id_shop : '');
Cache::store($cache_id, Db::getInstance()->getRow($sql)); Cache::store($cache_id, Db::getInstance()->getRow($sql));
} }
@@ -176,15 +176,15 @@ abstract class ObjectModelCore
if (!$id_lang && method_exists($this, 'getTranslationsFieldsChild')) if (!$id_lang && method_exists($this, 'getTranslationsFieldsChild'))
{ {
$sql = 'SELECT * FROM `'.pSQL(_DB_PREFIX_.$this->table).'_lang` $sql = 'SELECT * FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'_lang`
WHERE `'.$this->identifier.'` = '.(int)$id WHERE `'.$this->def['primary'].'` = '.(int)$id
.(($this->id_shop) ? ' AND `id_shop` = '.$this->id_shop : ''); .(($this->id_shop) ? ' AND `id_shop` = '.$this->id_shop : '');
$result = Db::getInstance()->executeS($sql); $result = Db::getInstance()->executeS($sql);
if ($result) if ($result)
foreach ($result as $row) foreach ($result as $row)
foreach ($row AS $key => $value) foreach ($row AS $key => $value)
{ {
if (array_key_exists($key, $this) && $key != $this->identifier) if (array_key_exists($key, $this) && $key != $this->def['primary'])
{ {
if (!is_array($this->{$key})) if (!is_array($this->{$key}))
$this->{$key} = array(); $this->{$key} = array();
@@ -235,9 +235,9 @@ abstract class ObjectModelCore
$this->date_upd = date('Y-m-d H:i:s'); $this->date_upd = date('Y-m-d H:i:s');
/* Database insertion */ /* Database insertion */
if ($nullValues) if ($nullValues)
$result = Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_.$this->table, $this->getFields(), 'INSERT'); $result = Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_.$this->def['table'], $this->getFields(), 'INSERT');
else else
$result = Db::getInstance()->autoExecute(_DB_PREFIX_.$this->table, $this->getFields(), 'INSERT'); $result = Db::getInstance()->autoExecute(_DB_PREFIX_.$this->def['table'], $this->getFields(), 'INSERT');
if (!$result) if (!$result)
return false; return false;
@@ -256,28 +256,28 @@ abstract class ObjectModelCore
foreach (array_keys($field) AS $key) foreach (array_keys($field) AS $key)
if (!Validate::isTableOrIdentifier($key)) if (!Validate::isTableOrIdentifier($key))
throw new PrestashopException('key '.$key.' is not table or identifier, '); throw new PrestashopException('key '.$key.' is not table or identifier, ');
$field[$this->identifier] = (int)$this->id; $field[$this->def['primary']] = (int)$this->id;
if (isset($assos[$this->table.'_lang']) && $assos[$this->table.'_lang']['type'] == 'fk_shop') if (isset($assos[$this->def['table'].'_lang']) && $assos[$this->def['table'].'_lang']['type'] == 'fk_shop')
{ {
foreach ($shops as $id_shop) foreach ($shops as $id_shop)
{ {
$field['id_shop'] = (int)$id_shop; $field['id_shop'] = (int)$id_shop;
$result &= Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->table.'_lang', $field, 'INSERT'); $result &= Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->def['table'].'_lang', $field, 'INSERT');
} }
} }
else else
$result &= Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->table.'_lang', $field, 'INSERT'); $result &= Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->def['table'].'_lang', $field, 'INSERT');
} }
} }
if (!Shop::isFeatureActive()) if (!Shop::isFeatureActive())
{ {
if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'shop') if (isset($assos[$this->def['table']]) && $assos[$this->def['table']]['type'] == 'shop')
$result &= $this->associateTo(Context::getContext()->shop->getID(true), 'shop'); $result &= $this->associateTo(Context::getContext()->shop->getID(true), 'shop');
$assos = GroupShop::getAssoTables(); $assos = GroupShop::getAssoTables();
if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'group_shop') if (isset($assos[$this->def['table']]) && $assos[$this->def['table']]['type'] == 'group_shop')
$result &= $this->associateTo(Context::getContext()->shop->getGroupID(), 'group_shop'); $result &= $this->associateTo(Context::getContext()->shop->getGroupID(), 'group_shop');
} }
@@ -304,9 +304,9 @@ abstract class ObjectModelCore
/* Database update */ /* Database update */
if ($nullValues) if ($nullValues)
$result = Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_.$this->table, $this->getFields(), 'UPDATE', '`'.pSQL($this->identifier).'` = '.(int)($this->id)); $result = Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_.$this->def['table'], $this->getFields(), 'UPDATE', '`'.pSQL($this->def['primary']).'` = '.(int)($this->id));
else else
$result = Db::getInstance()->autoExecute(_DB_PREFIX_.$this->table, $this->getFields(), 'UPDATE', '`'.pSQL($this->identifier).'` = '.(int)($this->id)); $result = Db::getInstance()->autoExecute(_DB_PREFIX_.$this->def['table'], $this->getFields(), 'UPDATE', '`'.pSQL($this->def['primary']).'` = '.(int)($this->id));
if (!$result) if (!$result)
return false; return false;
@@ -329,25 +329,25 @@ abstract class ObjectModelCore
foreach ($listShops as $shop) foreach ($listShops as $shop)
{ {
$field['id_shop'] = $shop; $field['id_shop'] = $shop;
$where = pSQL($this->identifier).' = '.(int)$this->id $where = pSQL($this->def['primary']).' = '.(int)$this->id
.' AND id_lang = '.(int)$field['id_lang'] .' AND id_lang = '.(int)$field['id_lang']
.' AND id_shop = '.$field['id_shop']; .' AND id_shop = '.$field['id_shop'];
if (Db::getInstance()->getValue('SELECT COUNT(*) FROM '.pSQL(_DB_PREFIX_.$this->table).'_lang WHERE '.$where)) if (Db::getInstance()->getValue('SELECT COUNT(*) FROM '.pSQL(_DB_PREFIX_.$this->def['table']).'_lang WHERE '.$where))
$result &= Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->table.'_lang', $field, 'UPDATE', $where); $result &= Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->def['table'].'_lang', $field, 'UPDATE', $where);
else else
$result &= Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->table.'_lang', $field, 'INSERT'); $result &= Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->def['table'].'_lang', $field, 'INSERT');
} }
} }
// If this table is not linked to multishop system ... // If this table is not linked to multishop system ...
else else
{ {
$where = pSQL($this->identifier).' = '.(int)$this->id $where = pSQL($this->def['primary']).' = '.(int)$this->id
.' AND id_lang = '.(int)$field['id_lang']; .' AND id_lang = '.(int)$field['id_lang'];
if (Db::getInstance()->getValue('SELECT COUNT(*) FROM '.pSQL(_DB_PREFIX_.$this->table).'_lang WHERE '.$where)) if (Db::getInstance()->getValue('SELECT COUNT(*) FROM '.pSQL(_DB_PREFIX_.$this->def['table']).'_lang WHERE '.$where))
$result &= Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->table.'_lang', $field, 'UPDATE', $where); $result &= Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->def['table'].'_lang', $field, 'UPDATE', $where);
else else
$result &= Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->table.'_lang', $field, 'INSERT'); $result &= Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->def['table'].'_lang', $field, 'INSERT');
} }
} }
} }
@@ -372,21 +372,21 @@ abstract class ObjectModelCore
$this->clearCache(); $this->clearCache();
/* Database deletion */ /* Database deletion */
$result = Db::getInstance()->execute('DELETE FROM `'.pSQL(_DB_PREFIX_.$this->table).'` WHERE `'.pSQL($this->identifier).'` = '.(int)($this->id)); $result = Db::getInstance()->execute('DELETE FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'` WHERE `'.pSQL($this->def['primary']).'` = '.(int)($this->id));
if (!$result) if (!$result)
return false; return false;
/* Database deletion for multilingual fields related to the object */ /* Database deletion for multilingual fields related to the object */
if (method_exists($this, 'getTranslationsFieldsChild')) if (method_exists($this, 'getTranslationsFieldsChild'))
Db::getInstance()->execute('DELETE FROM `'.pSQL(_DB_PREFIX_.$this->table).'_lang` WHERE `'.pSQL($this->identifier).'` = '.(int)($this->id)); Db::getInstance()->execute('DELETE FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'_lang` WHERE `'.pSQL($this->def['primary']).'` = '.(int)($this->id));
$assos = Shop::getAssoTables(); $assos = Shop::getAssoTables();
if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'shop') if (isset($assos[$this->def['table']]) && $assos[$this->def['table']]['type'] == 'shop')
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.$this->table.'_shop` WHERE `'.$this->identifier.'`='.(int)$this->id); Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.$this->def['table'].'_shop` WHERE `'.$this->def['primary'].'`='.(int)$this->id);
$assos = GroupShop::getAssoTables(); $assos = GroupShop::getAssoTables();
if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'group_shop') if (isset($assos[$this->def['table']]) && $assos[$this->def['table']]['type'] == 'group_shop')
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.$this->table.'_group_shop` WHERE `'.$this->identifier.'`='.(int)$this->id); Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.$this->def['table'].'_group_shop` WHERE `'.$this->def['primary'].'`='.(int)$this->id);
/* Hook */ /* Hook */
Hook::exec('actionObject'.get_class($this).'DeleteAfter', array('object' => $this)); Hook::exec('actionObject'.get_class($this).'DeleteAfter', array('object' => $this));
@@ -426,9 +426,9 @@ abstract class ObjectModelCore
/* Change status to active/inactive */ /* Change status to active/inactive */
return Db::getInstance()->execute(' return Db::getInstance()->execute('
UPDATE `'.pSQL(_DB_PREFIX_.$this->table).'` UPDATE `'.pSQL(_DB_PREFIX_.$this->def['table']).'`
SET `active` = !`active` SET `active` = !`active`
WHERE `'.pSQL($this->identifier).'` = '.(int)($this->id)); WHERE `'.pSQL($this->def['primary']).'` = '.(int)($this->id));
} }
/** /**
@@ -454,7 +454,7 @@ abstract class ObjectModelCore
protected function makeTranslationFields(&$fields, &$fieldsArray, $id_language) protected function makeTranslationFields(&$fields, &$fieldsArray, $id_language)
{ {
$fields[$id_language]['id_lang'] = $id_language; $fields[$id_language]['id_lang'] = $id_language;
$fields[$id_language][$this->identifier] = (int)($this->id); $fields[$id_language][$this->def['primary']] = (int)($this->id);
if ($this->id_shop && $this->isLangMultishop()) if ($this->id_shop && $this->isLangMultishop())
$fields[$id_language]['id_shop'] = (int)$this->id_shop; $fields[$id_language]['id_shop'] = (int)$this->id_shop;
foreach ($fieldsArray as $k => $field) foreach ($fieldsArray as $k => $field)
@@ -624,15 +624,15 @@ abstract class ObjectModelCore
public function getWebserviceParameters($wsParamsAttributeName = null) public function getWebserviceParameters($wsParamsAttributeName = null)
{ {
$defaultResourceParameters = array( $defaultResourceParameters = array(
'objectSqlId' => $this->identifier, 'objectSqlId' => $this->def['primary'],
'retrieveData' => array( 'retrieveData' => array(
'className' => get_class($this), 'className' => get_class($this),
'retrieveMethod' => 'getWebserviceObjectList', 'retrieveMethod' => 'getWebserviceObjectList',
'params' => array(), 'params' => array(),
'table' => $this->table, 'table' => $this->def['table'],
), ),
'fields' => array( 'fields' => array(
'id' => array('sqlId' => $this->identifier, 'i18n' => false), 'id' => array('sqlId' => $this->def['primary'], 'i18n' => false),
), ),
); );
@@ -641,9 +641,9 @@ abstract class ObjectModelCore
if (!isset($this->{$wsParamsAttributeName}['objectNodeName'])) if (!isset($this->{$wsParamsAttributeName}['objectNodeName']))
$defaultResourceParameters['objectNodeName'] = $this->table; $defaultResourceParameters['objectNodeName'] = $this->def['table'];
if (!isset($this->{$wsParamsAttributeName}['objectsNodeName'])) if (!isset($this->{$wsParamsAttributeName}['objectsNodeName']))
$defaultResourceParameters['objectsNodeName'] = $this->table.'s'; $defaultResourceParameters['objectsNodeName'] = $this->def['table'].'s';
if (isset($this->{$wsParamsAttributeName}['associations'])) if (isset($this->{$wsParamsAttributeName}['associations']))
foreach ($this->{$wsParamsAttributeName}['associations'] as $assocName => &$association) foreach ($this->{$wsParamsAttributeName}['associations'] as $assocName => &$association)
@@ -755,19 +755,19 @@ abstract class ObjectModelCore
{ {
$assoc = Shop::getAssoTables(); $assoc = Shop::getAssoTables();
if (array_key_exists($this->table ,$assoc)) if (array_key_exists($this->def['table'] ,$assoc))
{ {
$multi_shop_join = ' LEFT JOIN `'._DB_PREFIX_.$this->table.'_'.$assoc[$this->table]['type'].'` AS multi_shop_'.$this->table.' ON (main.'.$this->identifier.' = '.'multi_shop_'.$this->table.'.'.$this->identifier.')'; $multi_shop_join = ' LEFT JOIN `'._DB_PREFIX_.$this->def['table'].'_'.$assoc[$this->def['table']]['type'].'` AS multi_shop_'.$this->def['table'].' ON (main.'.$this->def['primary'].' = '.'multi_shop_'.$this->def['table'].'.'.$this->def['primary'].')';
$class_name = WebserviceRequest::$ws_current_classname; $class_name = WebserviceRequest::$ws_current_classname;
$vars = get_class_vars($class_name); $vars = get_class_vars($class_name);
foreach ($vars['shopIDs'] as $id_shop) foreach ($vars['shopIDs'] as $id_shop)
$OR[] = ' multi_shop_'.$this->table.'.id_shop = '.$id_shop.' '; $OR[] = ' multi_shop_'.$this->def['table'].'.id_shop = '.$id_shop.' ';
$multi_shop_filter = ' AND ('.implode('OR', $OR).') '; $multi_shop_filter = ' AND ('.implode('OR', $OR).') ';
$sql_filter = $multi_shop_filter.' '.$sql_filter; $sql_filter = $multi_shop_filter.' '.$sql_filter;
$sql_join = $multi_shop_join .' '. $sql_join; $sql_join = $multi_shop_join .' '. $sql_join;
} }
$query = ' $query = '
SELECT DISTINCT main.`'.$this->identifier.'` FROM `'._DB_PREFIX_.$this->table.'` AS main SELECT DISTINCT main.`'.$this->def['primary'].'` FROM `'._DB_PREFIX_.$this->def['table'].'` AS main
'.$sql_join.' '.$sql_join.'
WHERE 1 '.$sql_filter.' WHERE 1 '.$sql_filter.'
'.($sql_sort != '' ? $sql_sort : '').' '.($sql_sort != '' ? $sql_sort : '').'
@@ -801,9 +801,9 @@ abstract class ObjectModelCore
public function clearCache($all = false) public function clearCache($all = false)
{ {
if ($all) if ($all)
Cache::clean('objectmodel_'.$this->table.'_*'); Cache::clean('objectmodel_'.$this->def['table'].'_*');
else if ($this->id) else if ($this->id)
Cache::clean('objectmodel_'.$this->table.'_'.(int)$this->id.'_*'); Cache::clean('objectmodel_'.$this->def['table'].'_'.(int)$this->id.'_*');
} }
/** /**
@@ -819,8 +819,8 @@ abstract class ObjectModelCore
$id_shop = Context::getContext()->shop->getID(); $id_shop = Context::getContext()->shop->getID();
$sql = 'SELECT id_shop $sql = 'SELECT id_shop
FROM `'.pSQL(_DB_PREFIX_.$this->table).'_shop` FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'_shop`
WHERE `'.$this->identifier.'` = '.(int)$this->id.' WHERE `'.$this->def['primary'].'` = '.(int)$this->id.'
AND id_shop = '.(int)$id_shop; AND id_shop = '.(int)$id_shop;
return (bool)Db::getInstance()->getValue($sql); return (bool)Db::getInstance()->getValue($sql);
} }
@@ -847,7 +847,7 @@ abstract class ObjectModelCore
} }
if (!empty($sql)) if (!empty($sql))
return (bool)Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.$this->table.'_'.$type.'` (`'.$this->identifier.'`, `id_'.$type.'`) VALUES '.rtrim($sql,',')); return (bool)Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.$this->def['table'].'_'.$type.'` (`'.$this->def['primary'].'`, `id_'.$type.'`) VALUES '.rtrim($sql,','));
return true; return true;
} }
@@ -864,8 +864,8 @@ abstract class ObjectModelCore
$id_group_shop = Context::getContext()->shop->getGroupID(); $id_group_shop = Context::getContext()->shop->getGroupID();
$sql = 'SELECT id_group_shop $sql = 'SELECT id_group_shop
FROM `'.pSQL(_DB_PREFIX_.$this->table).'_group_shop` FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'_group_shop`
WHERE `'.$this->identifier.'`='.(int)$this->id.' AND id_group_shop='.(int)$id_group_shop; WHERE `'.$this->def['primary'].'`='.(int)$this->id.' AND id_group_shop='.(int)$id_group_shop;
return (bool)Db::getInstance()->getValue($sql); return (bool)Db::getInstance()->getValue($sql);
} }
@@ -875,12 +875,12 @@ abstract class ObjectModelCore
public function duplicateShops($id) public function duplicateShops($id)
{ {
$asso = Shop::getAssoTables(); $asso = Shop::getAssoTables();
if (!isset($asso[$this->table]) || $asso[$this->table]['type'] != 'shop') if (!isset($asso[$this->def['table']]) || $asso[$this->def['table']]['type'] != 'shop')
return false; return false;
$sql = 'SELECT id_shop $sql = 'SELECT id_shop
FROM '._DB_PREFIX_.$this->table.'_shop FROM '._DB_PREFIX_.$this->def['table'].'_shop
WHERE '.$this->identifier.' = '.(int)$id; WHERE '.$this->def['primary'].' = '.(int)$id;
if ($results = Db::getInstance()->executeS($sql)) if ($results = Db::getInstance()->executeS($sql))
{ {
$ids = array(); $ids = array();
@@ -914,11 +914,11 @@ abstract class ObjectModelCore
&& !unlink($this->image_dir.$this->id.'.'.$this->image_format)) && !unlink($this->image_dir.$this->id.'.'.$this->image_format))
return false; return false;
} }
if (file_exists(_PS_TMP_IMG_DIR_.$this->table.'_'.$this->id.'.'.$this->image_format) if (file_exists(_PS_TMP_IMG_DIR_.$this->def['table'].'_'.$this->id.'.'.$this->image_format)
&& !unlink(_PS_TMP_IMG_DIR_.$this->table.'_'.$this->id.'.'.$this->image_format)) && !unlink(_PS_TMP_IMG_DIR_.$this->def['table'].'_'.$this->id.'.'.$this->image_format))
return false; return false;
if (file_exists(_PS_TMP_IMG_DIR_.$this->table.'_mini_'.$this->id.'.'.$this->image_format) if (file_exists(_PS_TMP_IMG_DIR_.$this->def['table'].'_mini_'.$this->id.'.'.$this->image_format)
&& !unlink(_PS_TMP_IMG_DIR_.$this->table.'_mini_'.$this->id.'.'.$this->image_format)) && !unlink(_PS_TMP_IMG_DIR_.$this->def['table'].'_mini_'.$this->id.'.'.$this->image_format))
return false; return false;
$types = ImageType::getImagesTypes(); $types = ImageType::getImagesTypes();
@@ -970,7 +970,7 @@ abstract class ObjectModelCore
*/ */
public function getIdentifier() public function getIdentifier()
{ {
return $this->identifier; return $this->def['primary'];
} }
/** /**
@@ -994,8 +994,8 @@ abstract class ObjectModelCore
public function hydrate(array $data, $id_lang = null) public function hydrate(array $data, $id_lang = null)
{ {
$this->id_lang = $id_lang; $this->id_lang = $id_lang;
if (isset($data[$this->identifier])) if (isset($data[$this->def['primary']]))
$this->id = $data[$this->identifier]; $this->id = $data[$this->def['primary']];
foreach ($data as $key => $value) foreach ($data as $key => $value)
if (array_key_exists($key, $this)) if (array_key_exists($key, $this))
$this->$key = $value; $this->$key = $value;
+1 -1
View File
@@ -119,7 +119,7 @@ class ProductDownloadCore extends ObjectModel
if (parent::update($nullValues)) if (parent::update($nullValues))
{ {
// Refresh cache of feature detachable because the row can be deactive // Refresh cache of feature detachable because the row can be deactive
Configuration::updateGlobalValue('PS_VIRTUAL_PROD_FEATURE_ACTIVE', self::isCurrentlyUsed($this->table, true)); Configuration::updateGlobalValue('PS_VIRTUAL_PROD_FEATURE_ACTIVE', self::isCurrentlyUsed($this->def['table'], true));
return true; return true;
} }
return false; return false;
+2 -2
View File
@@ -95,7 +95,7 @@ class SceneCore extends ObjectModel
if (parent::update($nullValues)) if (parent::update($nullValues))
{ {
// Refresh cache of feature detachable // Refresh cache of feature detachable
Configuration::updateGlobalValue('PS_SCENE_FEATURE_ACTIVE', self::isCurrentlyUsed($this->table, true)); Configuration::updateGlobalValue('PS_SCENE_FEATURE_ACTIVE', self::isCurrentlyUsed($this->def['table'], true));
return true; return true;
} }
return false; return false;
@@ -126,7 +126,7 @@ class SceneCore extends ObjectModel
if (parent::delete()) if (parent::delete())
{ {
return $this->deleteImage() && return $this->deleteImage() &&
Configuration::updateGlobalValue('PS_SCENE_FEATURE_ACTIVE', self::isCurrentlyUsed($this->table, true)); Configuration::updateGlobalValue('PS_SCENE_FEATURE_ACTIVE', self::isCurrentlyUsed($this->def['table'], true));
} }
return false; return false;
} }
+1 -1
View File
@@ -87,7 +87,7 @@ class SpecificPriceCore extends ObjectModel
if (parent::delete()) if (parent::delete())
{ {
// Refresh cache of feature detachable // Refresh cache of feature detachable
Configuration::updateGlobalValue('PS_SPECIFIC_PRICE_FEATURE_ACTIVE', self::isCurrentlyUsed($this->table)); Configuration::updateGlobalValue('PS_SPECIFIC_PRICE_FEATURE_ACTIVE', self::isCurrentlyUsed($this->def['table']));
return true; return true;
} }
return false; return false;
+3 -6
View File
@@ -132,19 +132,16 @@ class StateCore extends ObjectModel
*/ */
public function delete() public function delete()
{ {
if (!Validate::isTableOrIdentifier($this->identifier) OR !Validate::isTableOrIdentifier($this->table))
die(Tools::displayError());
if (!$this->isUsed()) if (!$this->isUsed())
{ {
/* Database deletion */ /* Database deletion */
$result = Db::getInstance()->execute('DELETE FROM `'.pSQL(_DB_PREFIX_.$this->table).'` WHERE `'.pSQL($this->identifier).'` = '.(int)($this->id)); $result = Db::getInstance()->execute('DELETE FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'` WHERE `'.$this->def['primary'] .'` = '.(int)$this->id);
if (!$result) if (!$result)
return false; return false;
/* Database deletion for multilingual fields related to the object */ /* Database deletion for multilingual fields related to the object */
if (method_exists($this, 'getTranslationsFieldsChild')) if (method_exists($this, 'getTranslationsFieldsChild'))
Db::getInstance()->execute('DELETE FROM `'.pSQL(_DB_PREFIX_.$this->table).'_lang` WHERE `'.pSQL($this->identifier).'` = '.(int)($this->id)); Db::getInstance()->execute('DELETE FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'_lang` WHERE `'.$this->def['primary'].'` = '.(int)$this->id);
return $result; return $result;
} }
else else
@@ -171,7 +168,7 @@ class StateCore extends ObjectModel
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT COUNT(*) AS nb_used SELECT COUNT(*) AS nb_used
FROM `'._DB_PREFIX_.'address` FROM `'._DB_PREFIX_.'address`
WHERE `'.pSQL($this->identifier).'` = '.(int)($this->id)); WHERE `'.$this->def['primary'].'` = '.(int)($this->id));
return $row['nb_used']; return $row['nb_used'];
} }
+8 -3
View File
@@ -43,7 +43,12 @@ class TranslatedConfigurationCore extends Configuration
// Otherwise configuration is not set as translated configuration. // Otherwise configuration is not set as translated configuration.
if ($id !== null) if ($id !== null)
{ {
$id_translated = Db::getInstance()->executeS('SELECT `'.$this->identifier.'` FROM `'.pSQL(_DB_PREFIX_.$this->table).'_lang` WHERE `'.$this->identifier.'`='.pSQL($id).' LIMIT 0,1'); $id_translated = Db::getInstance()->executeS('
SELECT `'.$this->def['primary'].'`
FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'_lang`
WHERE `'.$this->def['primary'].'`='.pSQL($id).' LIMIT 0,1
');
if (empty($id_translated)) if (empty($id_translated))
$id = null; $id = null;
} }
@@ -81,11 +86,11 @@ class TranslatedConfigurationCore extends Configuration
public function getWebserviceObjectList($sql_join, $sql_filter, $sql_sort, $sql_limit) public function getWebserviceObjectList($sql_join, $sql_filter, $sql_sort, $sql_limit)
{ {
$query = ' $query = '
SELECT DISTINCT main.`'.$this->identifier.'` FROM `'._DB_PREFIX_.$this->table.'` main SELECT DISTINCT main.`'.$this->def['primary'].'` FROM `'._DB_PREFIX_.$this->def['table'].'` main
'.$sql_join.' '.$sql_join.'
WHERE id_configuration IN WHERE id_configuration IN
( SELECT id_configuration ( SELECT id_configuration
FROM '._DB_PREFIX_.$this->table.'_lang FROM '._DB_PREFIX_.$this->def['table'].'_lang
) '.$sql_filter.' ) '.$sql_filter.'
'.($sql_sort != '' ? $sql_sort : '').' '.($sql_sort != '' ? $sql_sort : '').'
'.($sql_limit != '' ? $sql_limit : '').' '.($sql_limit != '' ? $sql_limit : '').'
+7 -7
View File
@@ -113,7 +113,7 @@ class WarehouseCore extends ObjectModel
$query->select('ws.id_shop, s.name'); $query->select('ws.id_shop, s.name');
$query->from('warehouse_shop ws'); $query->from('warehouse_shop ws');
$query->leftJoin('shop s ON (s.id_shop = ws.id_shop)'); $query->leftJoin('shop s ON (s.id_shop = ws.id_shop)');
$query->where($this->identifier.' = '.(int)$this->id); $query->where($this->def['primary'].' = '.(int)$this->id);
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
return $res; return $res;
@@ -128,11 +128,11 @@ class WarehouseCore extends ObjectModel
{ {
$row_to_insert = array(); $row_to_insert = array();
foreach ($ids_shop as $id_shop) foreach ($ids_shop as $id_shop)
$row_to_insert[] = array($this->identifier => $this->id, 'id_shop' => (int)$id_shop); $row_to_insert[] = array($this->def['primary'] => $this->id, 'id_shop' => (int)$id_shop);
Db::getInstance()->execute(' Db::getInstance()->execute('
DELETE FROM '._DB_PREFIX_.'warehouse_shop DELETE FROM '._DB_PREFIX_.'warehouse_shop
WHERE '.$this->identifier.' = '.(int)$this->id); WHERE '.$this->def['primary'].' = '.(int)$this->id);
Db::getInstance()->autoExecute(_DB_PREFIX_.'warehouse_shop', $row_to_insert, 'INSERT'); Db::getInstance()->autoExecute(_DB_PREFIX_.'warehouse_shop', $row_to_insert, 'INSERT');
} }
@@ -149,7 +149,7 @@ class WarehouseCore extends ObjectModel
$query = new DbQuery(); $query = new DbQuery();
$query->select('wc.id_carrier'); $query->select('wc.id_carrier');
$query->from('warehouse_carrier wc'); $query->from('warehouse_carrier wc');
$query->where($this->identifier.' = '.(int)$this->id); $query->where($this->def['primary'].' = '.(int)$this->id);
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
@@ -169,11 +169,11 @@ class WarehouseCore extends ObjectModel
{ {
$row_to_insert = array(); $row_to_insert = array();
foreach ($ids_carriers as $id_carrier) foreach ($ids_carriers as $id_carrier)
$row_to_insert[] = array($this->identifier => $this->id, 'id_carrier' => (int)$id_carrier); $row_to_insert[] = array($this->def['primary'] => $this->id, 'id_carrier' => (int)$id_carrier);
Db::getInstance()->execute(' Db::getInstance()->execute('
DELETE FROM '._DB_PREFIX_.'warehouse_carrier DELETE FROM '._DB_PREFIX_.'warehouse_carrier
WHERE '.$this->identifier.' = '.(int)$this->id); WHERE '.$this->def['primary'].' = '.(int)$this->id);
Db::getInstance()->autoExecute(_DB_PREFIX_.'warehouse_carrier', $row_to_insert, 'INSERT'); Db::getInstance()->autoExecute(_DB_PREFIX_.'warehouse_carrier', $row_to_insert, 'INSERT');
} }
@@ -203,7 +203,7 @@ class WarehouseCore extends ObjectModel
$query = new DbQuery(); $query = new DbQuery();
$query->select('SUM(s.physical_quantity)'); $query->select('SUM(s.physical_quantity)');
$query->from('stock s'); $query->from('stock s');
$query->where($this->identifier.' = '.(int)$this->id); $query->where($this->def['primary'].' = '.(int)$this->id);
return (Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query) == 0); return (Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query) == 0);
} }