From 2daf87f506d6a5ebb8ae1c03472f2a28bee04307 Mon Sep 17 00:00:00 2001 From: rMalie Date: Fri, 9 Dec 2011 10:24:48 +0000 Subject: [PATCH] // Remove unused $tables property from ObjectModel + improve Cache --- classes/CMSCategory.php | 3 --- classes/Category.php | 2 -- classes/Country.php | 2 -- classes/Customer.php | 1 - classes/Group.php | 2 -- classes/Image.php | 2 -- classes/ObjectModel.php | 25 +++++++++++++------------ classes/Product.php | 3 --- classes/cache/Cache.php | 12 +++++++++++- classes/order/Order.php | 3 --- classes/order/OrderCarrier.php | 2 -- classes/order/OrderCartRule.php | 2 -- classes/order/OrderDetail.php | 2 -- classes/order/OrderHistory.php | 2 -- classes/order/OrderReturn.php | 2 -- classes/order/OrderSlip.php | 2 -- 16 files changed, 24 insertions(+), 43 deletions(-) diff --git a/classes/CMSCategory.php b/classes/CMSCategory.php index bb64444c0..86fa84938 100644 --- a/classes/CMSCategory.php +++ b/classes/CMSCategory.php @@ -70,9 +70,6 @@ class CMSCategoryCore extends ObjectModel protected static $_links = array(); - - protected $tables = array ('cms_category', 'cms_category_lang'); - protected $fieldsRequired = array('id_parent', 'active'); protected $fieldsSize = array('id_parent' => 10, 'active' => 1); protected $fieldsValidate = array('active' => 'isBool', 'id_parent' => 'isUnsignedInt'); diff --git a/classes/Category.php b/classes/Category.php index 7c9f7af05..2e193803f 100644 --- a/classes/Category.php +++ b/classes/Category.php @@ -78,8 +78,6 @@ class CategoryCore extends ObjectModel protected static $_links = array(); - protected $tables = array ('category', 'category_lang'); - protected $fieldsRequired = array('active'); protected $fieldsSize = array('active' => 1); protected $fieldsValidate = array( diff --git a/classes/Country.php b/classes/Country.php index 0c9ea6428..c5852e724 100644 --- a/classes/Country.php +++ b/classes/Country.php @@ -64,8 +64,6 @@ class CountryCore extends ObjectModel 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 $fieldsSize = array('iso_code' => 3); protected $fieldsValidate = array( diff --git a/classes/Customer.php b/classes/Customer.php index 01b4e3e0c..2b488b83e 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -107,7 +107,6 @@ class CustomerCore extends ObjectModel /** @var int id_guest meaning the guest table, not the guest customer */ public $id_guest; - protected $tables = array ('customer'); public $groupBox; protected $fieldsRequired = array('lastname', 'passwd', 'firstname', 'email'); diff --git a/classes/Group.php b/classes/Group.php index adbc818ff..40886c9ea 100644 --- a/classes/Group.php +++ b/classes/Group.php @@ -44,8 +44,6 @@ class GroupCore extends ObjectModel /** @var string Object last modification date */ public $date_upd; - protected $tables = array ('group'); - protected $fieldsRequired = array('price_display_method'); protected $fieldsSize = array(); protected $fieldsValidate = array('reduction' => 'isFloat', 'price_display_method' => 'isPriceDisplayMethod'); diff --git a/classes/Image.php b/classes/Image.php index a2000ee43..1f80dcd91 100644 --- a/classes/Image.php +++ b/classes/Image.php @@ -59,8 +59,6 @@ class ImageCore extends ObjectModel /** @var int access rights of created folders (octal) */ protected static $access_rights = 0775; - protected $tables = array ('image', 'image_lang'); - protected $fieldsRequired = array('id_product'); protected $fieldsValidate = array('id_product' => 'isUnsignedId', 'position' => 'isUnsignedInt', 'cover' => 'isBool'); protected $fieldsRequiredLang = array('legend'); diff --git a/classes/ObjectModel.php b/classes/ObjectModel.php index d05784989..8e43054a5 100644 --- a/classes/ObjectModel.php +++ b/classes/ObjectModel.php @@ -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 - * @deprecated + * @deprecated 1.5.0 */ protected $table; /** * @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; @@ -70,14 +70,14 @@ abstract class ObjectModelCore /** @var array Multilingual fields validity functions for admin panel forms */ protected $fieldsValidateLang = array(); - /** @var array tables */ + /** + * @deprecated 1.5.0 + */ protected $tables = array(); /** @var array tables */ protected $webserviceParameters = array(); - protected static $_cache = array(); - /** @var string path to image directory. Used for image deletion. */ protected $image_dir = null; @@ -155,17 +155,18 @@ abstract class ObjectModelCore if ($id) { // 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 * 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).')' : '') .' WHERE 1 AND a.`'.$this->identifier.'` = '.(int)$id. (($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) { $this->id = (int)$id; @@ -799,10 +800,10 @@ abstract class ObjectModelCore public function clearCache($all = false) { - if ($all AND isset(self::$_cache[$this->table])) - unset(self::$_cache[$this->table]); - elseif ($this->id AND isset(self::$_cache[$this->table][(int)$this->id])) - unset(self::$_cache[$this->table][(int)$this->id]); + if ($all) + Cache::clean('objectmodel_'.$this->table.'_*'); + else if ($this->id) + Cache::clean('objectmodel_'.$this->table.'_'.(int)$this->id.'_*'); } /** diff --git a/classes/Product.php b/classes/Product.php index d97919cac..e347e7c08 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -208,9 +208,6 @@ class ProductCore extends ObjectModel /** @var array cache stock data in getStock() method */ protected static $cacheStock = array(); - /** @var array tables */ - protected $tables = array ('product', 'product_lang'); - protected $fieldsRequired = array('price'); protected $fieldsSize = array('reference' => 32, 'supplier_reference' => 32, 'location' => 64, 'ean13' => 13, 'upc' => 12, 'unity' => 10); protected $fieldsValidate = array( diff --git a/classes/cache/Cache.php b/classes/cache/Cache.php index 9451f055b..07dd1a812 100755 --- a/classes/cache/Cache.php +++ b/classes/cache/Cache.php @@ -314,6 +314,16 @@ abstract class CacheCore 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)); } } diff --git a/classes/order/Order.php b/classes/order/Order.php index 8799816d5..8f4fa5d65 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -147,9 +147,6 @@ class OrderCore extends ObjectModel */ 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 $fieldsValidate = array( 'id_address_delivery' => 'isUnsignedId', diff --git a/classes/order/OrderCarrier.php b/classes/order/OrderCarrier.php index 70cb1f0dc..5c85c5106 100644 --- a/classes/order/OrderCarrier.php +++ b/classes/order/OrderCarrier.php @@ -55,8 +55,6 @@ class OrderCarrierCore extends ObjectModel /** @var string Object creation date */ public $date_add; - protected $tables = array ('order_carrier'); - protected $fieldsRequired = array ('id_order', 'id_carrier'); protected $fieldsValidate = array ( 'id_order_carrier' => 'isUnsignedId', diff --git a/classes/order/OrderCartRule.php b/classes/order/OrderCartRule.php index 016d567f8..a6768fa4e 100644 --- a/classes/order/OrderCartRule.php +++ b/classes/order/OrderCartRule.php @@ -42,8 +42,6 @@ class OrderCartRuleCore extends ObjectModel /** @var integer */ public $value; - protected $tables = array ('order_cart_rule'); - protected $fieldsRequired = array ('id_order', 'name', 'value'); protected $fieldsValidate = array ('id_order' => 'isUnsignedId', 'name' => 'isGenericName', 'value' => 'isInt'); diff --git a/classes/order/OrderDetail.php b/classes/order/OrderDetail.php index 0f6803c38..f711747cc 100644 --- a/classes/order/OrderDetail.php +++ b/classes/order/OrderDetail.php @@ -129,8 +129,6 @@ class OrderDetailCore extends ObjectModel /** @var int Id warehouse */ public $id_warehouse; - protected $tables = array('order_detail'); - protected $fieldsRequired = array( 'id_order', 'id_warehouse', diff --git a/classes/order/OrderHistory.php b/classes/order/OrderHistory.php index 7b76d36a9..f15698fa6 100644 --- a/classes/order/OrderHistory.php +++ b/classes/order/OrderHistory.php @@ -42,8 +42,6 @@ class OrderHistoryCore extends ObjectModel /** @var string Object last modification date */ public $date_upd; - protected $tables = array ('order_history'); - protected $fieldsRequired = array('id_order', 'id_order_state'); protected $fieldsValidate = array('id_order' => 'isUnsignedId', 'id_order_state' => 'isUnsignedId', 'id_employee' => 'isUnsignedId'); diff --git a/classes/order/OrderReturn.php b/classes/order/OrderReturn.php index 65e18ae68..2a5afce44 100644 --- a/classes/order/OrderReturn.php +++ b/classes/order/OrderReturn.php @@ -48,8 +48,6 @@ class OrderReturnCore extends ObjectModel /** @var string Object last modification date */ public $date_upd; - protected $tables = array ('order_return'); - protected $fieldsRequired = array ('id_customer', 'id_order'); protected $fieldsValidate = array('id_customer' => 'isUnsignedId', 'id_order' => 'isUnsignedId', 'question' => 'isMessage'); diff --git a/classes/order/OrderSlip.php b/classes/order/OrderSlip.php index bb116d7da..b0761f3db 100644 --- a/classes/order/OrderSlip.php +++ b/classes/order/OrderSlip.php @@ -57,8 +57,6 @@ class OrderSlipCore extends ObjectModel /** @var string Object last modification date */ public $date_upd; - protected $tables = array ('order_slip'); - protected $fieldsRequired = array ('id_customer', 'id_order', 'conversion_rate'); protected $fieldsValidate = array('id_customer' => 'isUnsignedId', 'id_order' => 'isUnsignedId', 'conversion_rate' => 'isFloat');