diff --git a/admin-dev/tabs/AdminProducts.php b/admin-dev/tabs/AdminProducts.php index 6233abbf5..e3659e2c2 100644 --- a/admin-dev/tabs/AdminProducts.php +++ b/admin-dev/tabs/AdminProducts.php @@ -1232,6 +1232,7 @@ class AdminProducts extends AdminTab * Update product download * * @param object $product Product + * @return bool */ public function updateDownloadProduct($product) { @@ -1260,17 +1261,16 @@ class AdminProducts extends AdminTab return false; } - $download = new ProductDownload(Tools::getValue('virtual_product_id')); - $download->id_product = $product->id; - $download->display_filename = Tools::getValue('virtual_product_name'); - $download->physically_filename = Tools::getValue('virtual_product_filename') ? Tools::getValue('virtual_product_filename') : ProductDownload::getNewFilename(); - $download->date_deposit = date('Y-m-d H:i:s'); - $download->date_expiration = Tools::getValue('virtual_product_expiration_date') ? Tools::getValue('virtual_product_expiration_date').' 23:59:59' : ''; - $download->nb_days_accessible = Tools::getValue('virtual_product_nb_days'); - $download->nb_downloadable = Tools::getValue('virtual_product_nb_downloable'); - $download->active = 1; - if ($download->save()) - return true; + $productDownload = new ProductDownload(Tools::getValue('virtual_product_id')); + $productDownload->id_product = $product->id; + $productDownload->display_filename = Tools::getValue('virtual_product_name'); + $productDownload->physically_filename = Tools::getValue('virtual_product_filename') ? Tools::getValue('virtual_product_filename') : ProductDownload::getNewFilename(); + $productDownload->date_deposit = date('Y-m-d H:i:s'); + $productDownload->date_expiration = Tools::getValue('virtual_product_expiration_date') ? Tools::getValue('virtual_product_expiration_date').' 23:59:59' : ''; + $productDownload->nb_days_accessible = Tools::getValue('virtual_product_nb_days'); + $productDownload->nb_downloadable = Tools::getValue('virtual_product_nb_downloable'); + $productDownload->active = 1; + return $productDownload->save(); } else { diff --git a/classes/Alias.php b/classes/Alias.php index a0a166b9e..14a555d76 100644 --- a/classes/Alias.php +++ b/classes/Alias.php @@ -38,8 +38,6 @@ class AliasCore extends ObjectModel protected $table = 'alias'; protected $identifier = 'id_alias'; - protected static $feature_active = null; - function __construct($id = NULL, $alias = NULL, $search = NULL, $id_lang = NULL) { if ($id) @@ -73,6 +71,28 @@ class AliasCore extends ObjectModel } } + public function add($autodate = true, $nullValues = false) + { + if (parent::add($autodate, $nullValues)) + { + // Set cache of feature detachable to true + Configuration::updateGlobalValue('PS_ALIAS_FEATURE_ACTIVE', '1'); + return true; + } + return false; + } + + public function delete() + { + if (parent::delete()) + { + // Refresh cache of feature detachable + Configuration::updateGlobalValue('PS_ALIAS_FEATURE_ACTIVE', self::isCurrentlyUsed($this->table, true)); + return true; + } + return false; + } + public function getAliases() { if (!self::isFeatureActive()) @@ -104,12 +124,7 @@ class AliasCore extends ObjectModel */ public static function isFeatureActive() { - if (self::$feature_active === null) - self::$feature_active = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' - SELECT `id_alias` - FROM `'._DB_PREFIX_.'alias` - '); - return self::$feature_active; + return Configuration::get('PS_ALIAS_FEATURE_ACTIVE'); } } diff --git a/classes/Cart.php b/classes/Cart.php index 3d7054f77..cbf559c0a 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -444,12 +444,12 @@ class CartCore extends ObjectModel return array(); foreach ($result AS $row) { - if (isset($row['ecotax_attr']) AND $row['ecotax_attr'] > 0) + if (isset($row['ecotax_attr']) && $row['ecotax_attr'] > 0) $row['ecotax'] = (float)($row['ecotax_attr']); $row['stock_quantity'] = (int)($row['quantity']); // for compatibility with 1.2 themes $row['quantity'] = (int)($row['cart_quantity']); - if (isset($row['id_product_attribute']) AND (int)$row['id_product_attribute']) + if (isset($row['id_product_attribute']) && (int)$row['id_product_attribute'] && isset($row['weight_attribute'])) $row['weight'] = $row['weight_attribute']; if ($this->_taxCalculationMethod == PS_TAX_EXC) { diff --git a/classes/Combination.php b/classes/Combination.php index 25342f2bb..e669a2e39 100644 --- a/classes/Combination.php +++ b/classes/Combination.php @@ -191,16 +191,15 @@ class CombinationCore extends ObjectModel } /** - * This method is allow to know if a feature is in use + * This method is allow to know if a Combination entity is currently used * @since 1.5.0.1 + * @param $table + * @param $has_active_column * @return bool */ - public static function isCurrentlyUsed() + public static function isCurrentlyUsed($table = null, $has_active_column = false) { - return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' - SELECT `id_product_attribute` - FROM `'._DB_PREFIX_.'product_attribute` - '); + return parent::isCurrentlyUsed('product_attribute'); } } diff --git a/classes/Configuration.php b/classes/Configuration.php index 6e874e544..6174f3a4b 100644 --- a/classes/Configuration.php +++ b/classes/Configuration.php @@ -1,6 +1,6 @@ array(), ) ); - + public function getFields() { $this->validateFields(); @@ -87,7 +87,7 @@ class ConfigurationCore extends ObjectModel $this->validateFieldsLang(); return $this->getTranslationsFields(array('value')); } - + /** * Return ID a configuration key * @@ -104,7 +104,7 @@ class ConfigurationCore extends ObjectModel .Configuration::sqlRestriction($shopGroupID, $shopID); return (int)Db::getInstance()->getValue($sql); } - + /** * Load all configuration data */ @@ -132,7 +132,7 @@ class ConfigurationCore extends ObjectModel Configuration::set($row['name'], array($lang => $row['value']), (int)$row['id_group_shop'], (int)$row['id_shop']); } } - + /** * Get a single configuration value (in one language only) * @@ -146,7 +146,7 @@ class ConfigurationCore extends ObjectModel $langID = (int)$langID; if (!isset(self::$_CONF[$langID])) $langID = 0; - + // If conf if not initialized, try manual query if (!self::$_CONF) return Db::getInstance()->getValue('SELECT `value` FROM '._DB_PREFIX_.'configuration WHERE `name` = \''.pSQL($key).'\''); @@ -159,7 +159,7 @@ class ConfigurationCore extends ObjectModel return self::$_CONF[$langID]['global'][$key]; return false; } - + /** * Get a single configuration value (in multiple languages) * @@ -176,7 +176,7 @@ class ConfigurationCore extends ObjectModel $resultsArray[$language['id_lang']] = self::get($key, $language['id_lang'], $id_group_shop, $id_shop); return $resultsArray; } - + /** * Get several configuration values (in one language only) * @@ -200,7 +200,7 @@ class ConfigurationCore extends ObjectModel /** * Check if key exists in configuration - * + * * @param string $key * @param int $id_lang * @param int $shopGroupID @@ -216,7 +216,7 @@ class ConfigurationCore extends ObjectModel return isset(self::$_CONF[$langID]['group'][$shopGroupID]) && array_key_exists($key, self::$_CONF[$langID]['group'][$shopGroupID]); return isset(self::$_CONF[$langID]['global']) && array_key_exists($key, self::$_CONF[$langID]['global']); } - + /** * Set TEMPORARY a single configuration value (in one language only) * @@ -230,10 +230,10 @@ class ConfigurationCore extends ObjectModel if (!Validate::isConfigName($key)) die(Tools::displayError()); self::getShopFromContext($id_group_shop, $id_shop); - + if (!is_array($values)) $values = array($values); - + foreach ($values as $lang => $value) { if ($id_shop) @@ -242,12 +242,12 @@ class ConfigurationCore extends ObjectModel self::$_CONF[$lang]['group'][$id_group_shop][$key] = $value; else self::$_CONF[$lang]['global'][$key] = $value; - } + } } - + /** * Update configuration key for global context only - * + * * @param string $key * @param mixed $values * @param bool $html @@ -257,7 +257,7 @@ class ConfigurationCore extends ObjectModel { return Configuration::updateValue($key, $values, $html, 0, 0); } - + /** * Update configuration key and value into database (automatically insert if key does not exist) * @@ -268,7 +268,7 @@ class ConfigurationCore extends ObjectModel * @param int $shopID * @return boolean Update result */ - static public function updateValue($key, $values, $html = false, $shopGroupID = NULL, $shopID = NULL) + static public function updateValue($key, $values, $html = false, $shopGroupID = null, $shopID = null) { if (!Validate::isConfigName($key)) die(Tools::displayError()); @@ -337,10 +337,10 @@ class ConfigurationCore extends ObjectModel ), 'INSERT'); } } - + Configuration::set($key, $value, $shopGroupID, $shopID); } - + return $result; } @@ -362,7 +362,7 @@ class ConfigurationCore extends ObjectModel WHERE `name` = \''.pSQL($key).'\' )'; $result = Db::getInstance()->Execute($sql); - + $sql = 'DELETE FROM `'._DB_PREFIX_.'configuration` WHERE `name` = \''.pSQL($key).'\''; $result2 = Db::getInstance()->Execute($sql); @@ -384,15 +384,15 @@ class ConfigurationCore extends ObjectModel $sql = 'DELETE FROM '._DB_PREFIX_.'configuration WHERE id_configuration = '.$id; Db::getInstance()->Execute($sql); - + $sql = 'DELETE FROM '._DB_PREFIX_.'configuration_lang WHERE id_configuration = '.$id; Db::getInstance()->Execute($sql); } - + /** * Check if configuration var is defined in given context - * + * * @param string $key * @param int $langID * @param int $context @@ -408,7 +408,7 @@ class ConfigurationCore extends ObjectModel return true; return false; } - + public static function isOverridenByCurrentContext($key) { if (Configuration::isLangKey($key)) @@ -424,10 +424,10 @@ class ConfigurationCore extends ObjectModel $testContext = ((Context::shop() == Shop::CONTEXT_SHOP && Configuration::hasContext($key, null, Shop::CONTEXT_SHOP)) || (Context::shop() == Shop::CONTEXT_GROUP && Configuration::hasContext($key, null, Shop::CONTEXT_GROUP))) ? true : false; } - + return (Shop::isMultiShopActivated() && Context::shop() != Shop::CONTEXT_ALL && $testContext); } - + /** * Check if a key was loaded as multi lang * @@ -452,14 +452,14 @@ class ConfigurationCore extends ObjectModel $id_shop = $shopID; if (is_null($id_group_shop)) $id_group_shop = $shopGroupID; - + $id_shop = (int)$id_shop; $id_group_shop = (int)$id_group_shop; } - + /** - * Add SQL restriction on shops for configuration table - * + * Add SQL restriction on shops for configuration table + * * @param int $shopGroupID * @param int $shopID * @return string @@ -476,7 +476,7 @@ class ConfigurationCore extends ObjectModel /** * This method is override to allow TranslatedConfiguration entity - * + * * @param $sql_join * @param $sql_filter * @param $sql_sort @@ -488,7 +488,7 @@ class ConfigurationCore extends ObjectModel $query = ' SELECT DISTINCT main.`'.$this->identifier.'` FROM `'._DB_PREFIX_.$this->table.'` main '.$sql_join.' - WHERE id_configuration NOT IN + WHERE id_configuration NOT IN ( SELECT id_configuration FROM '._DB_PREFIX_.$this->table.'_lang ) '.$sql_filter.' diff --git a/classes/Customization.php b/classes/Customization.php index 9938af4ea..db2565853 100644 --- a/classes/Customization.php +++ b/classes/Customization.php @@ -27,8 +27,6 @@ class CustomizationCore { - protected static $feature_active = null; - public static function getReturnedCustomizations($id_order) { if (($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' @@ -105,12 +103,12 @@ class CustomizationCore { $quantity = array(); - $results = Db::getInstance()->executeS(' - SELECT `id_product`, `id_product_attribute`, SUM(`quantity`) AS quantity - FROM `'._DB_PREFIX_.'customization` - WHERE `id_cart` = '.(int)($id_cart).' - GROUP BY `id_cart`, `id_product`, `id_product_attribute`' - ); + $results = Db::getInstance()->ExecuteS(' + SELECT `id_product`, `id_product_attribute`, SUM(`quantity`) AS quantity + FROM `'._DB_PREFIX_.'customization` + WHERE `id_cart` = '.(int)$id_cart.' + GROUP BY `id_cart`, `id_product`, `id_product_attribute` + '); foreach($results as $row) $quantity[$row['id_product']][$row['product_attribute_id']] = $row['quantity']; @@ -125,13 +123,22 @@ class CustomizationCore */ public static function isFeatureActive() { - if (self::$feature_active === null) - self::$feature_active = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' - SELECT `id_customization_field` - FROM `'._DB_PREFIX_.'customization_field` - '); - return self::$feature_active; + return Configuration::get('PS_CUSTOMIZATION_FEATURE_ACTIVE'); } + /** + * This method is allow to know if a Customization entity is currently used + * @since 1.5.0.1 + * @param $table + * @param $has_active_column + * @return bool + */ + public static function isCurrentlyUsed() + { + return (bool)Db::getInstance()->getValue(' + SELECT `id_customization_field` + FROM `'._DB_PREFIX_.'customization_field` + '); + } } diff --git a/classes/Discount.php b/classes/Discount.php index ecf4273f2..37e591bbe 100644 --- a/classes/Discount.php +++ b/classes/Discount.php @@ -101,8 +101,6 @@ class DiscountCore extends ObjectModel protected $table = 'discount'; protected $identifier = 'id_discount'; - protected static $feature_active = null; - protected $webserviceParameters = array( 'fields' => array( 'id_discount_type' => array('sqlId' => 'id_discount_type', 'xlink_resource' => 'discount_types'), @@ -159,12 +157,15 @@ class DiscountCore extends ObjectModel public function add($autodate = true, $nullValues = false, $categories = null) { - $ret = NULL; if (parent::add($autodate, $nullValues)) - $ret = true; + { + $this->updateCategories($categories); - $this->updateCategories($categories); - return $ret; + // Set cache of feature detachable to true + Configuration::updateGlobalValue('PS_DISCOUNT_FEATURE_ACTIVE', '1'); + return true; + } + return false; } /* Categories initialization is different between add() and update() because the addition will set all categories if none are selected (compatibility with old modules) and update won't update categories if none are selected */ @@ -182,8 +183,12 @@ class DiscountCore extends ObjectModel { if (!parent::delete()) return false; - return (Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'cart_discount WHERE id_discount = '.(int)($this->id)) - AND Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'discount_category WHERE id_discount = '.(int)($this->id))); + + // Refresh cache of feature detachable + Configuration::updateGlobalValue('PS_DISCOUNT_FEATURE_ACTIVE', self::isCurrentlyUsed($this->table, true)); + + return (Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'cart_discount WHERE id_discount = '.(int)($this->id)) && + Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'discount_category WHERE id_discount = '.(int)($this->id))); } public function getTranslationsFieldsChild() @@ -579,12 +584,6 @@ class DiscountCore extends ObjectModel */ public static function isFeatureActive() { - if (self::$feature_active === null) - self::$feature_active = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' - SELECT `id_discount` - FROM `'._DB_PREFIX_.'discount` - WHERE `active` = 1 - '); - return self::$feature_active; + return Configuration::get('PS_DISCOUNT_FEATURE_ACTIVE'); } } \ No newline at end of file diff --git a/classes/Group.php b/classes/Group.php index 7e5712cc2..28fc4d659 100644 --- a/classes/Group.php +++ b/classes/Group.php @@ -59,7 +59,6 @@ class GroupCore extends ObjectModel protected static $_cacheReduction = array(); protected static $_groupPriceDisplayMethod = array(); - protected static $feature_active = null; protected $webserviceParameters = array(); @@ -150,7 +149,15 @@ class GroupCore extends ObjectModel public function add($autodate = true, $nullValues = false) { - return parent::add() && Category::setNewGroupForHome((int)($this->id)); + if (parent::add($autodate, $nullValues)) + { + Category::setNewGroupForHome((int)$this->id); + + // Set cache of feature detachable to true + Configuration::updateGlobalValue('PS_GROUP_FEATURE_ACTIVE', '1'); + return true; + } + return false; } public function delete() @@ -159,11 +166,15 @@ class GroupCore extends ObjectModel return false; if (parent::delete()) { - Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'customer_group` WHERE `id_group` = '.(int)($this->id)); - Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'category_group` WHERE `id_group` = '.(int)($this->id)); - Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'group_reduction` WHERE `id_group` = '.(int)($this->id)); - Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'product_group_reduction_cache` WHERE `id_group` = '.(int)($this->id)); - Discount::deleteByIdGroup((int)($this->id)); + Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'customer_group` WHERE `id_group` = '.(int)$this->id); + Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'category_group` WHERE `id_group` = '.(int)$this->id); + Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'group_reduction` WHERE `id_group` = '.(int)$this->id); + Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'product_group_reduction_cache` WHERE `id_group` = '.(int)$this->id); + Discount::deleteByIdGroup((int)$this->id); + + // Refresh cache of feature detachable + Configuration::updateGlobalValue('PS_GROUP_FEATURE_ACTIVE', self::isCurrentlyUsed()); + return true; } return false; @@ -176,12 +187,24 @@ class GroupCore extends ObjectModel */ public static function isFeatureActive() { - if (self::$feature_active === null) - self::$feature_active = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' - SELECT `id_group` - FROM `'._DB_PREFIX_.'group` - '); - return self::$feature_active; + return Configuration::get('PS_GROUP_FEATURE_ACTIVE'); + } + + /** + * This method is allow to know if a Discount entity is currently used + * @since 1.5.0.1 + * @param $table + * @param $has_active_column + * @return bool + */ + public static function isCurrentlyUsed($table = null, $has_active_column = false) + { + // We don't use the parent method, for specific clause reason (id_group != 1) + return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' + SELECT `id_group` + FROM `'._DB_PREFIX_.'group` + WHERE `id_group` != 1 + '); } } diff --git a/classes/ObjectModel.php b/classes/ObjectModel.php index a035eb099..006adad1e 100644 --- a/classes/ObjectModel.php +++ b/classes/ObjectModel.php @@ -905,4 +905,21 @@ abstract class ObjectModelCore return isset($row['id']); } + + /** + * This method is allow to know if a entity is currently used + * @since 1.5.0.1 + * @param string $table name of table linked to entity + * @param bool $has_active_column true if the table has an active column + * @return bool + */ + public static function isCurrentlyUsed($table, $has_active_column = false) + { + $query = new DbQuery(); + $query->select('`id_'.pSQL($table).'`'); + $query->from(pSQL($table)); + if ($has_active_column) + $query->where('`active` = 1'); + return (bool)Db::getInstance()->getValue($query); + } } diff --git a/classes/Pack.php b/classes/Pack.php index 4cb49cdcf..bb4c073dc 100644 --- a/classes/Pack.php +++ b/classes/Pack.php @@ -30,7 +30,6 @@ class PackCore extends Product protected static $cachePackItems = array(); protected static $cacheIsPack = array(); protected static $cacheIsPacked = array(); - protected static $feature_active = null; public static function isPack($id_product) { @@ -170,8 +169,9 @@ class PackCore extends Product public static function deleteItems($id_product) { - Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'product SET cache_is_pack = 0 WHERE id_product = '.(int)($id_product).' LIMIT 1'); - return Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'pack` WHERE `id_product_pack` = '.(int)($id_product)); + return Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'product SET cache_is_pack = 0 WHERE id_product = '.(int)($id_product).' LIMIT 1') && + Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'pack` WHERE `id_product_pack` = '.(int)($id_product)) && + Configuration::updateGlobalValue('PS_PACK_FEATURE_ACTIVE', self::isCurrentlyUsed()); } /** @@ -184,8 +184,9 @@ class PackCore extends Product */ public static function addItem($id_product, $id_item, $qty) { - Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'product SET cache_is_pack = 1 WHERE id_product = '.(int)($id_product).' LIMIT 1'); - return Db::getInstance()->AutoExecute(_DB_PREFIX_.'pack', array('id_product_pack' => (int)($id_product), 'id_product_item' => (int)($id_item), 'quantity' => (int)($qty)), 'INSERT'); + return Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'product SET cache_is_pack = 1 WHERE id_product = '.(int)($id_product).' LIMIT 1') && + Db::getInstance()->AutoExecute(_DB_PREFIX_.'pack', array('id_product_pack' => (int)($id_product), 'id_product_item' => (int)($id_item), 'quantity' => (int)($qty)), 'INSERT') && + Configuration::updateGlobalValue('PS_PACK_FEATURE_ACTIVE', '1'); } public static function duplicate($id_product_old, $id_product_new) @@ -204,12 +205,23 @@ class PackCore extends Product */ public static function isFeatureActive() { - if (self::$feature_active === null) - self::$feature_active = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' - SELECT `id_product_pack` - FROM `'._DB_PREFIX_.'pack` - '); - return self::$feature_active; + return Configuration::get('PS_PACK_FEATURE_ACTIVE'); + } + + /** + * This method is allow to know if a Pack entity is currently used + * @since 1.5.0.1 + * @param $table + * @param $has_active_column + * @return bool + */ + public static function isCurrentlyUsed($table = null, $has_active_column = false) + { + // We dont't use the parent method because the identifier isn't id_pack + return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' + SELECT `id_product_pack` + FROM `'._DB_PREFIX_.'pack` + '); } } diff --git a/classes/Product.php b/classes/Product.php index c311aef49..467a476f6 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -3049,22 +3049,35 @@ class ProductCore extends ObjectModel (!Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'customization_field` WHERE `id_product` = '.(int)($this->id).' AND `type` = '.Product::CUSTOMIZE_TEXTFIELD.' AND `id_customization_field` >= '.(int)($customizationFields[Product::CUSTOMIZE_TEXTFIELD][count($customizationFields[Product::CUSTOMIZE_TEXTFIELD]) - $extraText])) OR !Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'customization_field_lang` WHERE `id_customization_field` NOT IN (SELECT `id_customization_field` FROM `'._DB_PREFIX_.'customization_field`)'))) return false; + + // Refresh cache of feature detachable + Configuration::updateGlobalValue('PS_CUSTOMIZATION_FEATURE_ACTIVE', Customization::isCurrentlyUsed()); + return true; } protected function _createLabel(&$languages, $type) { - /* Label insertion */ - if (!Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'customization_field` (`id_product`, `type`, `required`) VALUES ('.(int)($this->id).', '.(int)($type).', 0)') OR !$id_customization_field = (int)(Db::getInstance()->Insert_ID())) + // Label insertion + if (!Db::getInstance()->Execute(' + INSERT INTO `'._DB_PREFIX_.'customization_field` (`id_product`, `type`, `required`) + VALUES ('.(int)$this->id.', '.(int)($type).', 0)') OR + !$id_customization_field = (int)(Db::getInstance()->Insert_ID())) return false; - /* Multilingual label name creation */ + // Multilingual label name creation $values = ''; foreach ($languages AS $language) $values .= '('.(int)($id_customization_field).', '.(int)($language['id_lang']).', \'\'), '; $values = rtrim($values, ', '); - if (!Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'customization_field_lang` (`id_customization_field`, `id_lang`, `name`) VALUES '.$values)) + if (!Db::getInstance()->Execute(' + INSERT INTO `'._DB_PREFIX_.'customization_field_lang` (`id_customization_field`, `id_lang`, `name`) + VALUES '.$values)) return false; + + // Set cache of feature detachable to true + Configuration::updateGlobalValue('PS_CUSTOMIZATION_FEATURE_ACTIVE', '1'); + return true; } diff --git a/classes/ProductDownload.php b/classes/ProductDownload.php index 369d4b2b9..6d187809a 100644 --- a/classes/ProductDownload.php +++ b/classes/ProductDownload.php @@ -80,20 +80,41 @@ class ProductDownloadCore extends ObjectModel protected $table = 'product_download'; protected $identifier = 'id_product_download'; - protected static $feature_active = null; - /** * Build a virtual product * * @param integer $id_product_download Existing productDownload id in order to load object (optional) */ - public function __construct($id_product_download = NULL) + public function __construct($id_product_download = null) { parent::__construct($id_product_download); // @TODO check if the file is present on hard drive } - public function delete($deleteFile=false) + public function add($autodate = true, $nullValues = false) + { + if (parent::add($autodate, $nullValues)) + { + // Set cache of feature detachable to true + if ($this->active) + Configuration::updateGlobalValue('PS_VIRTUAL_PROD_FEATURE_ACTIVE', '1'); + return true; + } + return false; + } + + public function update($nullValues = false) + { + if (parent::update($nullValues)) + { + // Refresh cache of feature detachable because the row can be deactive + Configuration::updateGlobalValue('PS_VIRTUAL_PROD_FEATURE_ACTIVE', self::isCurrentlyUsed($this->table, true)); + return true; + } + return false; + } + + public function delete($deleteFile = false) { if ($deleteFile) return $this->deleteFile(); @@ -118,7 +139,6 @@ class ProductDownloadCore extends ObjectModel return $fields; } - /** * Delete the file * @@ -280,14 +300,8 @@ class ProductDownloadCore extends ObjectModel */ public static function isFeatureActive() { - if (self::$feature_active === null) - self::$feature_active = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' - SELECT `id_product_download` - FROM `'._DB_PREFIX_.'product_download` - '); - return self::$feature_active; + return Configuration::get('PS_VIRTUAL_PROD_FEATURE_ACTIVE'); } - } diff --git a/classes/Scene.php b/classes/Scene.php index 2a8487d35..ad31b98be 100644 --- a/classes/Scene.php +++ b/classes/Scene.php @@ -88,7 +88,15 @@ class SceneCore extends ObjectModel return false; if (!$this->updateCategories()) return false; - return parent::update($nullValues); + + if (parent::update($nullValues)) + { + // Refresh cache of feature detachable + Configuration::updateGlobalValue('PS_SCENE_FEATURE_ACTIVE', self::isCurrentlyUsed($this->table, true)); + return true; + } + return false; + } public function add($autodate = true, $nullValues = false) @@ -98,7 +106,14 @@ class SceneCore extends ObjectModel if (!empty($this->categories)) $this->addCategories($this->categories); - return parent::add($autodate, $nullValues); + if (parent::add($autodate, $nullValues)) + { + // Put cache of feature detachable only if this new scene is active else we keep the old value + if ($this->active) + Configuration::updateGlobalValue('PS_SCENE_FEATURE_ACTIVE', '1'); + return true; + } + return false; } public function delete() @@ -106,7 +121,11 @@ class SceneCore extends ObjectModel $this->deleteZoneProducts(); $this->deleteCategories(); if (parent::delete()) - return $this->deleteImage(); + { + return $this->deleteImage() && + Configuration::updateGlobalValue('PS_SCENE_FEATURE_ACTIVE', self::isCurrentlyUsed($this->table, true)); + } + return false; } public function deleteImage() @@ -273,12 +292,7 @@ class SceneCore extends ObjectModel */ public static function isFeatureActive() { - if (self::$feature_active === null) - self::$feature_active = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' - SELECT `id_scene` - FROM `'._DB_PREFIX_.'scene` - '); - return self::$feature_active; + return Configuration::get('PS_SCENE_FEATURE_ACTIVE'); } } diff --git a/classes/SpecificPrice.php b/classes/SpecificPrice.php index 500c1926e..bfe030217 100644 --- a/classes/SpecificPrice.php +++ b/classes/SpecificPrice.php @@ -47,7 +47,6 @@ class SpecificPriceCore extends ObjectModel protected static $_specificPriceCache = array(); protected static $_cache_priorities = array(); - protected static $feature_active = null; public function getFields() { @@ -66,6 +65,28 @@ class SpecificPriceCore extends ObjectModel return $fields; } + public function add($autodate = true, $nullValues = false) + { + if (parent::add($autodate, $nullValues)) + { + // Set cache of feature detachable to true + Configuration::updateGlobalValue('PS_SPECIFIC_PRICE_FEATURE_ACTIVE', '1'); + return true; + } + return false; + } + + public function delete() + { + if (parent::delete()) + { + // Refresh cache of feature detachable + Configuration::updateGlobalValue('PS_SPECIFIC_PRICE_FEATURE_ACTIVE', self::isCurrentlyUsed($this->table)); + return true; + } + return false; + } + public static function getByProductId($id_product) { return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' @@ -82,7 +103,7 @@ class SpecificPriceCore extends ObjectModel WHERE `id_product` = '.(int)$id_product); } - // score generation for quantity discount + // score generation for quantity discount protected static function _getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group) { $select = '('; @@ -279,7 +300,13 @@ class SpecificPriceCore extends ObjectModel public static function deleteByProductId($id_product) { - return Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'specific_price` WHERE `id_product` = '.(int)$id_product); + if (Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'specific_price` WHERE `id_product` = '.(int)$id_product)) + { + // Refresh cache of feature detachable + Configuration::updateGlobalValue('PS_SPECIFIC_PRICE_FEATURE_ACTIVE', self::isCurrentlyUsed('specific_price')); + return true; + } + return false; } public function duplicate($id_product = false) @@ -296,12 +323,7 @@ class SpecificPriceCore extends ObjectModel */ public static function isFeatureActive() { - if (self::$feature_active === null) - self::$feature_active = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' - SELECT `id_specific_price` - FROM `'._DB_PREFIX_.'specific_price` - '); - return self::$feature_active; + return Configuration::get('PS_SPECIFIC_PRICE_FEATURE_ACTIVE'); } } diff --git a/install-dev/php/update_feature_detachable_cache.php b/install-dev/php/update_feature_detachable_cache.php new file mode 100644 index 000000000..5076cbf1a --- /dev/null +++ b/install-dev/php/update_feature_detachable_cache.php @@ -0,0 +1,38 @@ + +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision$ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +function update_feature_detachable_cache() +{ + Configuration::updateGlobalValue('PS_SPECIFIC_PRICE_FEATURE_ACTIVE', (int)SpecificPrice::isCurrentlyUsed('specific_price')); + Configuration::updateGlobalValue('PS_SCENE_FEATURE_ACTIVE', (int)Scene::isCurrentlyUsed('scene', true)); + Configuration::updateGlobalValue('PS_VIRTUAL_PROD_FEATURE_ACTIVE', (int)ProductDownload::isCurrentlyUsed('product_download', true)); + Configuration::updateGlobalValue('PS_CUSTOMIZATION_FEATURE_ACTIVE', (int)Customization::isCurrentlyUsed()); + Configuration::updateGlobalValue('PS_DISCOUNT_FEATURE_ACTIVE', (int)Discount::isCurrentlyUsed('discount', true)); + Configuration::updateGlobalValue('PS_GROUP_FEATURE_ACTIVE', (int)Group::isCurrentlyUsed()); + Configuration::updateGlobalValue('PS_PACK_FEATURE_ACTIVE', (int)Pack::isCurrentlyUsed()); + Configuration::updateGlobalValue('PS_ALIAS_FEATURE_ACTIVE', (int)Alias::isCurrentlyUsed('alias', true)); +} diff --git a/install-dev/sql/db_settings_lite.sql b/install-dev/sql/db_settings_lite.sql index b163564b2..f8474912e 100644 --- a/install-dev/sql/db_settings_lite.sql +++ b/install-dev/sql/db_settings_lite.sql @@ -225,7 +225,15 @@ INSERT INTO `PREFIX_configuration` (`id_configuration`, `name`, `value`, `date_a (137, 'PS_SHOW_NEW_CUSTOMERS', '1', NOW(), NOW()), (138, 'PS_SHOW_NEW_MESSAGES', '1', NOW(), NOW()), (139, 'PS_FEATURE_FEATURE_ACTIVE', '1', NOW(), NOW()), -(140, 'PS_COMBINATION_FEATURE_ACTIVE', '1', NOW(), NOW()); +(140, 'PS_COMBINATION_FEATURE_ACTIVE', '1', NOW(), NOW()), +(141, 'PS_SPECIFIC_PRICE_FEATURE_ACTIVE', '1', NOW(), NOW()), +(142, 'PS_SCENE_FEATURE_ACTIVE', '1', NOW(), NOW()), +(143, 'PS_VIRTUAL_PROD_FEATURE_ACTIVE', '0', NOW(), NOW()), +(144, 'PS_CUSTOMIZATION_FEATURE_ACTIVE', '0', NOW(), NOW()), +(145, 'PS_DISCOUNT_FEATURE_ACTIVE', '0', NOW(), NOW()), +(146, 'PS_GROUP_FEATURE_ACTIVE', '0', NOW(), NOW()), +(147, 'PS_PACK_FEATURE_ACTIVE', '0', NOW(), NOW()), +(148, 'PS_ALIAS_FEATURE_ACTIVE', '1', NOW(), NOW()); INSERT INTO `PREFIX_configuration_lang` (`id_configuration`, `id_lang`, `value`, `date_upd`) VALUES (36, 1, 'IN', NOW()),(36, 2, 'FA', NOW()),(36, 3, 'CU', NOW()),(36, 4, 'FA', NOW()),(36, 5, 'FA', NOW()), diff --git a/install-dev/sql/upgrade/1.5.0.1.sql b/install-dev/sql/upgrade/1.5.0.1.sql index 3074f795f..a3f089ae0 100644 --- a/install-dev/sql/upgrade/1.5.0.1.sql +++ b/install-dev/sql/upgrade/1.5.0.1.sql @@ -72,6 +72,8 @@ INSERT INTO `PREFIX_configuration` (`name`, `value`, `date_add`, `date_upd`) VAL ('PS_FEATURE_FEATURE_ACTIVE', '1', NOW(), NOW()), ('PS_COMBINATION_FEATURE_ACTIVE', '1', NOW(), NOW()); +/* PHP:update_feature_detachable_cache(); */; + ALTER TABLE `PREFIX_product` ADD `available_date` DATETIME NOT NULL AFTER `available_for_order`; ALTER TABLE `PREFIX_product_attribute` ADD `available_date` DATETIME NOT NULL; diff --git a/install-dev/xml/doUpgrade.php b/install-dev/xml/doUpgrade.php index 0dde70875..37c566f57 100644 --- a/install-dev/xml/doUpgrade.php +++ b/install-dev/xml/doUpgrade.php @@ -137,6 +137,8 @@ require_once(_PS_INSTALLER_PHP_UPGRADE_DIR_.'remove_tab.php'); require_once(_PS_INSTALLER_PHP_UPGRADE_DIR_.'update_order_detail_taxes.php'); +require_once(_PS_INSTALLER_PHP_UPGRADE_DIR_.'update_feature_detachable_cache.php'); + //old version detection global $oldversion, $logger; $oldversion = false;