// Remove unused $tables property from ObjectModel + improve Cache

This commit is contained in:
rMalie
2011-12-09 10:24:48 +00:00
parent 091025371e
commit 2daf87f506
16 changed files with 24 additions and 43 deletions
-3
View File
@@ -70,9 +70,6 @@ class CMSCategoryCore extends ObjectModel
protected static $_links = array(); protected static $_links = array();
protected $tables = array ('cms_category', 'cms_category_lang');
protected $fieldsRequired = array('id_parent', 'active'); protected $fieldsRequired = array('id_parent', 'active');
protected $fieldsSize = array('id_parent' => 10, 'active' => 1); protected $fieldsSize = array('id_parent' => 10, 'active' => 1);
protected $fieldsValidate = array('active' => 'isBool', 'id_parent' => 'isUnsignedInt'); protected $fieldsValidate = array('active' => 'isBool', 'id_parent' => 'isUnsignedInt');
-2
View File
@@ -78,8 +78,6 @@ class CategoryCore extends ObjectModel
protected static $_links = array(); protected static $_links = array();
protected $tables = array ('category', 'category_lang');
protected $fieldsRequired = array('active'); protected $fieldsRequired = array('active');
protected $fieldsSize = array('active' => 1); protected $fieldsSize = array('active' => 1);
protected $fieldsValidate = array( protected $fieldsValidate = array(
-2
View File
@@ -64,8 +64,6 @@ class CountryCore extends ObjectModel
protected static $_idZones = array(); protected static $_idZones = array();
protected $tables = array ('country', 'country_lang');
protected $fieldsRequired = array('id_zone', 'iso_code', 'contains_states', 'need_identification_number', 'display_tax_label'); protected $fieldsRequired = array('id_zone', 'iso_code', 'contains_states', 'need_identification_number', 'display_tax_label');
protected $fieldsSize = array('iso_code' => 3); protected $fieldsSize = array('iso_code' => 3);
protected $fieldsValidate = array( protected $fieldsValidate = array(
-1
View File
@@ -107,7 +107,6 @@ class CustomerCore extends ObjectModel
/** @var int id_guest meaning the guest table, not the guest customer */ /** @var int id_guest meaning the guest table, not the guest customer */
public $id_guest; public $id_guest;
protected $tables = array ('customer');
public $groupBox; public $groupBox;
protected $fieldsRequired = array('lastname', 'passwd', 'firstname', 'email'); protected $fieldsRequired = array('lastname', 'passwd', 'firstname', 'email');
-2
View File
@@ -44,8 +44,6 @@ class GroupCore extends ObjectModel
/** @var string Object last modification date */ /** @var string Object last modification date */
public $date_upd; public $date_upd;
protected $tables = array ('group');
protected $fieldsRequired = array('price_display_method'); protected $fieldsRequired = array('price_display_method');
protected $fieldsSize = array(); protected $fieldsSize = array();
protected $fieldsValidate = array('reduction' => 'isFloat', 'price_display_method' => 'isPriceDisplayMethod'); protected $fieldsValidate = array('reduction' => 'isFloat', 'price_display_method' => 'isPriceDisplayMethod');
-2
View File
@@ -59,8 +59,6 @@ class ImageCore extends ObjectModel
/** @var int access rights of created folders (octal) */ /** @var int access rights of created folders (octal) */
protected static $access_rights = 0775; protected static $access_rights = 0775;
protected $tables = array ('image', 'image_lang');
protected $fieldsRequired = array('id_product'); protected $fieldsRequired = array('id_product');
protected $fieldsValidate = array('id_product' => 'isUnsignedId', 'position' => 'isUnsignedInt', 'cover' => 'isBool'); protected $fieldsValidate = array('id_product' => 'isUnsignedId', 'position' => 'isUnsignedInt', 'cover' => 'isBool');
protected $fieldsRequiredLang = array('legend'); protected $fieldsRequiredLang = array('legend');
+13 -12
View File
@@ -39,13 +39,13 @@ abstract class ObjectModelCore
/** /**
* @var string SQL This property shouldn't be overloaded anymore in class, use static $definition['table'] property instead * @var string SQL This property shouldn't be overloaded anymore in class, use static $definition['table'] property instead
* @deprecated * @deprecated 1.5.0
*/ */
protected $table; protected $table;
/** /**
* @var string SQL This property shouldn't be overloaded anymore in class, use static $definition['primary'] property instead * @var string SQL This property shouldn't be overloaded anymore in class, use static $definition['primary'] property instead
* @deprecated * @deprecated 1.5.0
*/ */
protected $identifier; protected $identifier;
@@ -70,14 +70,14 @@ abstract class ObjectModelCore
/** @var array Multilingual fields validity functions for admin panel forms */ /** @var array Multilingual fields validity functions for admin panel forms */
protected $fieldsValidateLang = array(); protected $fieldsValidateLang = array();
/** @var array tables */ /**
* @deprecated 1.5.0
*/
protected $tables = array(); protected $tables = array();
/** @var array tables */ /** @var array tables */
protected $webserviceParameters = array(); protected $webserviceParameters = array();
protected static $_cache = array();
/** @var string path to image directory. Used for image deletion. */ /** @var string path to image directory. Used for image deletion. */
protected $image_dir = null; protected $image_dir = null;
@@ -155,17 +155,18 @@ abstract class ObjectModelCore
if ($id) if ($id)
{ {
// Load object from database if object id is present // Load object from database if object id is present
if (!isset(self::$_cache[$this->table][(int)$id][(int)$id_shop][(int)$id_lang])) $cache_id = 'objectmodel_'.$this->table.'_'.(int)$id.'_'.(int)$id_shop.'_'.(int)$id_lang;
if (!Cache::isStored($cache_id))
{ {
$sql = 'SELECT * $sql = 'SELECT *
FROM `'._DB_PREFIX_.$this->table.'` a '. FROM `'._DB_PREFIX_.$this->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->table).'_lang` b ON (a.`'.$this->identifier.'` = b.`'.$this->identifier).'` AND `id_lang` = '.(int)($id_lang).')' : '')
.' WHERE 1 AND a.`'.$this->identifier.'` = '.(int)$id. .' WHERE 1 AND a.`'.$this->identifier.'` = '.(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 : '');
self::$_cache[$this->table][(int)($id)][(int)$id_shop][(int)$id_lang] = Db::getInstance()->getRow($sql); Cache::store($cache_id, Db::getInstance()->getRow($sql));
} }
$result = self::$_cache[$this->table][(int)$id][(int)$id_shop][(int)$id_lang]; $result = Cache::retrieve($cache_id);
if ($result) if ($result)
{ {
$this->id = (int)$id; $this->id = (int)$id;
@@ -799,10 +800,10 @@ abstract class ObjectModelCore
public function clearCache($all = false) public function clearCache($all = false)
{ {
if ($all AND isset(self::$_cache[$this->table])) if ($all)
unset(self::$_cache[$this->table]); Cache::clean('objectmodel_'.$this->table.'_*');
elseif ($this->id AND isset(self::$_cache[$this->table][(int)$this->id])) else if ($this->id)
unset(self::$_cache[$this->table][(int)$this->id]); Cache::clean('objectmodel_'.$this->table.'_'.(int)$this->id.'_*');
} }
/** /**
-3
View File
@@ -208,9 +208,6 @@ class ProductCore extends ObjectModel
/** @var array cache stock data in getStock() method */ /** @var array cache stock data in getStock() method */
protected static $cacheStock = array(); protected static $cacheStock = array();
/** @var array tables */
protected $tables = array ('product', 'product_lang');
protected $fieldsRequired = array('price'); protected $fieldsRequired = array('price');
protected $fieldsSize = array('reference' => 32, 'supplier_reference' => 32, 'location' => 64, 'ean13' => 13, 'upc' => 12, 'unity' => 10); protected $fieldsSize = array('reference' => 32, 'supplier_reference' => 32, 'location' => 64, 'ean13' => 13, 'upc' => 12, 'unity' => 10);
protected $fieldsValidate = array( protected $fieldsValidate = array(
+11 -1
View File
@@ -314,6 +314,16 @@ abstract class CacheCore
public static function clean($key) public static function clean($key)
{ {
unset(Cache::$local[$key]); if (strpos($key, '*'))
{
$regexp = str_replace('\\*', '.*', preg_quote($key, '#'));
foreach (array_keys(Cache::$local) as $key)
if (preg_match('#^'.$regexp.'$#', $key))
unset(Cache::$local[$key]);
}
else
unset(Cache::$local[$key]);
d(array_keys(Cache::$local));
} }
} }
-3
View File
@@ -147,9 +147,6 @@ class OrderCore extends ObjectModel
*/ */
public $reference; public $reference;
protected $tables = array ('orders');
protected $fieldsRequired = array('conversion_rate', 'id_address_delivery', 'id_address_invoice', 'id_cart', 'id_currency', 'id_lang', 'id_customer', 'id_carrier', 'payment', 'total_paid', 'total_paid_real', 'total_products', 'total_products_wt'); protected $fieldsRequired = array('conversion_rate', 'id_address_delivery', 'id_address_invoice', 'id_cart', 'id_currency', 'id_lang', 'id_customer', 'id_carrier', 'payment', 'total_paid', 'total_paid_real', 'total_products', 'total_products_wt');
protected $fieldsValidate = array( protected $fieldsValidate = array(
'id_address_delivery' => 'isUnsignedId', 'id_address_delivery' => 'isUnsignedId',
-2
View File
@@ -55,8 +55,6 @@ class OrderCarrierCore extends ObjectModel
/** @var string Object creation date */ /** @var string Object creation date */
public $date_add; public $date_add;
protected $tables = array ('order_carrier');
protected $fieldsRequired = array ('id_order', 'id_carrier'); protected $fieldsRequired = array ('id_order', 'id_carrier');
protected $fieldsValidate = array ( protected $fieldsValidate = array (
'id_order_carrier' => 'isUnsignedId', 'id_order_carrier' => 'isUnsignedId',
-2
View File
@@ -42,8 +42,6 @@ class OrderCartRuleCore extends ObjectModel
/** @var integer */ /** @var integer */
public $value; public $value;
protected $tables = array ('order_cart_rule');
protected $fieldsRequired = array ('id_order', 'name', 'value'); protected $fieldsRequired = array ('id_order', 'name', 'value');
protected $fieldsValidate = array ('id_order' => 'isUnsignedId', 'name' => 'isGenericName', 'value' => 'isInt'); protected $fieldsValidate = array ('id_order' => 'isUnsignedId', 'name' => 'isGenericName', 'value' => 'isInt');
-2
View File
@@ -129,8 +129,6 @@ class OrderDetailCore extends ObjectModel
/** @var int Id warehouse */ /** @var int Id warehouse */
public $id_warehouse; public $id_warehouse;
protected $tables = array('order_detail');
protected $fieldsRequired = array( protected $fieldsRequired = array(
'id_order', 'id_order',
'id_warehouse', 'id_warehouse',
-2
View File
@@ -42,8 +42,6 @@ class OrderHistoryCore extends ObjectModel
/** @var string Object last modification date */ /** @var string Object last modification date */
public $date_upd; public $date_upd;
protected $tables = array ('order_history');
protected $fieldsRequired = array('id_order', 'id_order_state'); protected $fieldsRequired = array('id_order', 'id_order_state');
protected $fieldsValidate = array('id_order' => 'isUnsignedId', 'id_order_state' => 'isUnsignedId', 'id_employee' => 'isUnsignedId'); protected $fieldsValidate = array('id_order' => 'isUnsignedId', 'id_order_state' => 'isUnsignedId', 'id_employee' => 'isUnsignedId');
-2
View File
@@ -48,8 +48,6 @@ class OrderReturnCore extends ObjectModel
/** @var string Object last modification date */ /** @var string Object last modification date */
public $date_upd; public $date_upd;
protected $tables = array ('order_return');
protected $fieldsRequired = array ('id_customer', 'id_order'); protected $fieldsRequired = array ('id_customer', 'id_order');
protected $fieldsValidate = array('id_customer' => 'isUnsignedId', 'id_order' => 'isUnsignedId', 'question' => 'isMessage'); protected $fieldsValidate = array('id_customer' => 'isUnsignedId', 'id_order' => 'isUnsignedId', 'question' => 'isMessage');
-2
View File
@@ -57,8 +57,6 @@ class OrderSlipCore extends ObjectModel
/** @var string Object last modification date */ /** @var string Object last modification date */
public $date_upd; public $date_upd;
protected $tables = array ('order_slip');
protected $fieldsRequired = array ('id_customer', 'id_order', 'conversion_rate'); protected $fieldsRequired = array ('id_customer', 'id_order', 'conversion_rate');
protected $fieldsValidate = array('id_customer' => 'isUnsignedId', 'id_order' => 'isUnsignedId', 'conversion_rate' => 'isFloat'); protected $fieldsValidate = array('id_customer' => 'isUnsignedId', 'id_order' => 'isUnsignedId', 'conversion_rate' => 'isFloat');