[*] Classes : improve performances of "Feature detachable" feature

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8754 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
aFolletete
2011-09-24 15:03:21 +00:00
parent cfca41b012
commit 78f6a4e20a
18 changed files with 334 additions and 149 deletions
+11 -11
View File
@@ -1232,6 +1232,7 @@ class AdminProducts extends AdminTab
* Update product download * Update product download
* *
* @param object $product Product * @param object $product Product
* @return bool
*/ */
public function updateDownloadProduct($product) public function updateDownloadProduct($product)
{ {
@@ -1260,17 +1261,16 @@ class AdminProducts extends AdminTab
return false; return false;
} }
$download = new ProductDownload(Tools::getValue('virtual_product_id')); $productDownload = new ProductDownload(Tools::getValue('virtual_product_id'));
$download->id_product = $product->id; $productDownload->id_product = $product->id;
$download->display_filename = Tools::getValue('virtual_product_name'); $productDownload->display_filename = Tools::getValue('virtual_product_name');
$download->physically_filename = Tools::getValue('virtual_product_filename') ? Tools::getValue('virtual_product_filename') : ProductDownload::getNewFilename(); $productDownload->physically_filename = Tools::getValue('virtual_product_filename') ? Tools::getValue('virtual_product_filename') : ProductDownload::getNewFilename();
$download->date_deposit = date('Y-m-d H:i:s'); $productDownload->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' : ''; $productDownload->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'); $productDownload->nb_days_accessible = Tools::getValue('virtual_product_nb_days');
$download->nb_downloadable = Tools::getValue('virtual_product_nb_downloable'); $productDownload->nb_downloadable = Tools::getValue('virtual_product_nb_downloable');
$download->active = 1; $productDownload->active = 1;
if ($download->save()) return $productDownload->save();
return true;
} }
else else
{ {
+23 -8
View File
@@ -38,8 +38,6 @@ class AliasCore extends ObjectModel
protected $table = 'alias'; protected $table = 'alias';
protected $identifier = 'id_alias'; protected $identifier = 'id_alias';
protected static $feature_active = null;
function __construct($id = NULL, $alias = NULL, $search = NULL, $id_lang = NULL) function __construct($id = NULL, $alias = NULL, $search = NULL, $id_lang = NULL)
{ {
if ($id) 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() public function getAliases()
{ {
if (!self::isFeatureActive()) if (!self::isFeatureActive())
@@ -104,12 +124,7 @@ class AliasCore extends ObjectModel
*/ */
public static function isFeatureActive() public static function isFeatureActive()
{ {
if (self::$feature_active === null) return Configuration::get('PS_ALIAS_FEATURE_ACTIVE');
self::$feature_active = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT `id_alias`
FROM `'._DB_PREFIX_.'alias`
');
return self::$feature_active;
} }
} }
+2 -2
View File
@@ -444,12 +444,12 @@ class CartCore extends ObjectModel
return array(); return array();
foreach ($result AS $row) 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['ecotax'] = (float)($row['ecotax_attr']);
$row['stock_quantity'] = (int)($row['quantity']); $row['stock_quantity'] = (int)($row['quantity']);
// for compatibility with 1.2 themes // for compatibility with 1.2 themes
$row['quantity'] = (int)($row['cart_quantity']); $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']; $row['weight'] = $row['weight_attribute'];
if ($this->_taxCalculationMethod == PS_TAX_EXC) if ($this->_taxCalculationMethod == PS_TAX_EXC)
{ {
+5 -6
View File
@@ -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 * @since 1.5.0.1
* @param $table
* @param $has_active_column
* @return bool * @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(' return parent::isCurrentlyUsed('product_attribute');
SELECT `id_product_attribute`
FROM `'._DB_PREFIX_.'product_attribute`
');
} }
} }
+34 -34
View File
@@ -1,6 +1,6 @@
<?php <?php
/* /*
* 2007-2011 PrestaShop * 2007-2011 PrestaShop
* *
* NOTICE OF LICENSE * NOTICE OF LICENSE
* *
@@ -31,7 +31,7 @@ class ConfigurationCore extends ObjectModel
/** @var string Key */ /** @var string Key */
public $name; public $name;
public $id_group_shop; public $id_group_shop;
public $id_shop; public $id_shop;
@@ -53,7 +53,7 @@ class ConfigurationCore extends ObjectModel
/** @var array Configuration cache */ /** @var array Configuration cache */
protected static $_CONF; protected static $_CONF;
/** @var array Vars types */ /** @var array Vars types */
protected static $types = array(); protected static $types = array();
@@ -62,7 +62,7 @@ class ConfigurationCore extends ObjectModel
'value' => array(), 'value' => array(),
) )
); );
public function getFields() public function getFields()
{ {
$this->validateFields(); $this->validateFields();
@@ -87,7 +87,7 @@ class ConfigurationCore extends ObjectModel
$this->validateFieldsLang(); $this->validateFieldsLang();
return $this->getTranslationsFields(array('value')); return $this->getTranslationsFields(array('value'));
} }
/** /**
* Return ID a configuration key * Return ID a configuration key
* *
@@ -104,7 +104,7 @@ class ConfigurationCore extends ObjectModel
.Configuration::sqlRestriction($shopGroupID, $shopID); .Configuration::sqlRestriction($shopGroupID, $shopID);
return (int)Db::getInstance()->getValue($sql); return (int)Db::getInstance()->getValue($sql);
} }
/** /**
* Load all configuration data * 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']); 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) * Get a single configuration value (in one language only)
* *
@@ -146,7 +146,7 @@ class ConfigurationCore extends ObjectModel
$langID = (int)$langID; $langID = (int)$langID;
if (!isset(self::$_CONF[$langID])) if (!isset(self::$_CONF[$langID]))
$langID = 0; $langID = 0;
// If conf if not initialized, try manual query // If conf if not initialized, try manual query
if (!self::$_CONF) if (!self::$_CONF)
return Db::getInstance()->getValue('SELECT `value` FROM '._DB_PREFIX_.'configuration WHERE `name` = \''.pSQL($key).'\''); 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 self::$_CONF[$langID]['global'][$key];
return false; return false;
} }
/** /**
* Get a single configuration value (in multiple languages) * 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); $resultsArray[$language['id_lang']] = self::get($key, $language['id_lang'], $id_group_shop, $id_shop);
return $resultsArray; return $resultsArray;
} }
/** /**
* Get several configuration values (in one language only) * Get several configuration values (in one language only)
* *
@@ -200,7 +200,7 @@ class ConfigurationCore extends ObjectModel
/** /**
* Check if key exists in configuration * Check if key exists in configuration
* *
* @param string $key * @param string $key
* @param int $id_lang * @param int $id_lang
* @param int $shopGroupID * @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]['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']); return isset(self::$_CONF[$langID]['global']) && array_key_exists($key, self::$_CONF[$langID]['global']);
} }
/** /**
* Set TEMPORARY a single configuration value (in one language only) * Set TEMPORARY a single configuration value (in one language only)
* *
@@ -230,10 +230,10 @@ class ConfigurationCore extends ObjectModel
if (!Validate::isConfigName($key)) if (!Validate::isConfigName($key))
die(Tools::displayError()); die(Tools::displayError());
self::getShopFromContext($id_group_shop, $id_shop); self::getShopFromContext($id_group_shop, $id_shop);
if (!is_array($values)) if (!is_array($values))
$values = array($values); $values = array($values);
foreach ($values as $lang => $value) foreach ($values as $lang => $value)
{ {
if ($id_shop) if ($id_shop)
@@ -242,12 +242,12 @@ class ConfigurationCore extends ObjectModel
self::$_CONF[$lang]['group'][$id_group_shop][$key] = $value; self::$_CONF[$lang]['group'][$id_group_shop][$key] = $value;
else else
self::$_CONF[$lang]['global'][$key] = $value; self::$_CONF[$lang]['global'][$key] = $value;
} }
} }
/** /**
* Update configuration key for global context only * Update configuration key for global context only
* *
* @param string $key * @param string $key
* @param mixed $values * @param mixed $values
* @param bool $html * @param bool $html
@@ -257,7 +257,7 @@ class ConfigurationCore extends ObjectModel
{ {
return Configuration::updateValue($key, $values, $html, 0, 0); return Configuration::updateValue($key, $values, $html, 0, 0);
} }
/** /**
* Update configuration key and value into database (automatically insert if key does not exist) * 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 * @param int $shopID
* @return boolean Update result * @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)) if (!Validate::isConfigName($key))
die(Tools::displayError()); die(Tools::displayError());
@@ -337,10 +337,10 @@ class ConfigurationCore extends ObjectModel
), 'INSERT'); ), 'INSERT');
} }
} }
Configuration::set($key, $value, $shopGroupID, $shopID); Configuration::set($key, $value, $shopGroupID, $shopID);
} }
return $result; return $result;
} }
@@ -362,7 +362,7 @@ class ConfigurationCore extends ObjectModel
WHERE `name` = \''.pSQL($key).'\' WHERE `name` = \''.pSQL($key).'\'
)'; )';
$result = Db::getInstance()->Execute($sql); $result = Db::getInstance()->Execute($sql);
$sql = 'DELETE FROM `'._DB_PREFIX_.'configuration` $sql = 'DELETE FROM `'._DB_PREFIX_.'configuration`
WHERE `name` = \''.pSQL($key).'\''; WHERE `name` = \''.pSQL($key).'\'';
$result2 = Db::getInstance()->Execute($sql); $result2 = Db::getInstance()->Execute($sql);
@@ -384,15 +384,15 @@ class ConfigurationCore extends ObjectModel
$sql = 'DELETE FROM '._DB_PREFIX_.'configuration $sql = 'DELETE FROM '._DB_PREFIX_.'configuration
WHERE id_configuration = '.$id; WHERE id_configuration = '.$id;
Db::getInstance()->Execute($sql); Db::getInstance()->Execute($sql);
$sql = 'DELETE FROM '._DB_PREFIX_.'configuration_lang $sql = 'DELETE FROM '._DB_PREFIX_.'configuration_lang
WHERE id_configuration = '.$id; WHERE id_configuration = '.$id;
Db::getInstance()->Execute($sql); Db::getInstance()->Execute($sql);
} }
/** /**
* Check if configuration var is defined in given context * Check if configuration var is defined in given context
* *
* @param string $key * @param string $key
* @param int $langID * @param int $langID
* @param int $context * @param int $context
@@ -408,7 +408,7 @@ class ConfigurationCore extends ObjectModel
return true; return true;
return false; return false;
} }
public static function isOverridenByCurrentContext($key) public static function isOverridenByCurrentContext($key)
{ {
if (Configuration::isLangKey($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)) $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; || (Context::shop() == Shop::CONTEXT_GROUP && Configuration::hasContext($key, null, Shop::CONTEXT_GROUP))) ? true : false;
} }
return (Shop::isMultiShopActivated() && Context::shop() != Shop::CONTEXT_ALL && $testContext); return (Shop::isMultiShopActivated() && Context::shop() != Shop::CONTEXT_ALL && $testContext);
} }
/** /**
* Check if a key was loaded as multi lang * Check if a key was loaded as multi lang
* *
@@ -452,14 +452,14 @@ class ConfigurationCore extends ObjectModel
$id_shop = $shopID; $id_shop = $shopID;
if (is_null($id_group_shop)) if (is_null($id_group_shop))
$id_group_shop = $shopGroupID; $id_group_shop = $shopGroupID;
$id_shop = (int)$id_shop; $id_shop = (int)$id_shop;
$id_group_shop = (int)$id_group_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 $shopGroupID
* @param int $shopID * @param int $shopID
* @return string * @return string
@@ -476,7 +476,7 @@ class ConfigurationCore extends ObjectModel
/** /**
* This method is override to allow TranslatedConfiguration entity * This method is override to allow TranslatedConfiguration entity
* *
* @param $sql_join * @param $sql_join
* @param $sql_filter * @param $sql_filter
* @param $sql_sort * @param $sql_sort
@@ -488,7 +488,7 @@ class ConfigurationCore extends ObjectModel
$query = ' $query = '
SELECT DISTINCT main.`'.$this->identifier.'` FROM `'._DB_PREFIX_.$this->table.'` main SELECT DISTINCT main.`'.$this->identifier.'` FROM `'._DB_PREFIX_.$this->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->table.'_lang
) '.$sql_filter.' ) '.$sql_filter.'
+21 -14
View File
@@ -27,8 +27,6 @@
class CustomizationCore class CustomizationCore
{ {
protected static $feature_active = null;
public static function getReturnedCustomizations($id_order) public static function getReturnedCustomizations($id_order)
{ {
if (($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' if (($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
@@ -105,12 +103,12 @@ class CustomizationCore
{ {
$quantity = array(); $quantity = array();
$results = Db::getInstance()->executeS(' $results = Db::getInstance()->ExecuteS('
SELECT `id_product`, `id_product_attribute`, SUM(`quantity`) AS quantity SELECT `id_product`, `id_product_attribute`, SUM(`quantity`) AS quantity
FROM `'._DB_PREFIX_.'customization` FROM `'._DB_PREFIX_.'customization`
WHERE `id_cart` = '.(int)($id_cart).' WHERE `id_cart` = '.(int)$id_cart.'
GROUP BY `id_cart`, `id_product`, `id_product_attribute`' GROUP BY `id_cart`, `id_product`, `id_product_attribute`
); ');
foreach($results as $row) foreach($results as $row)
$quantity[$row['id_product']][$row['product_attribute_id']] = $row['quantity']; $quantity[$row['id_product']][$row['product_attribute_id']] = $row['quantity'];
@@ -125,13 +123,22 @@ class CustomizationCore
*/ */
public static function isFeatureActive() public static function isFeatureActive()
{ {
if (self::$feature_active === null) return Configuration::get('PS_CUSTOMIZATION_FEATURE_ACTIVE');
self::$feature_active = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT `id_customization_field`
FROM `'._DB_PREFIX_.'customization_field`
');
return self::$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`
');
}
} }
+14 -15
View File
@@ -101,8 +101,6 @@ class DiscountCore extends ObjectModel
protected $table = 'discount'; protected $table = 'discount';
protected $identifier = 'id_discount'; protected $identifier = 'id_discount';
protected static $feature_active = null;
protected $webserviceParameters = array( protected $webserviceParameters = array(
'fields' => array( 'fields' => array(
'id_discount_type' => array('sqlId' => 'id_discount_type', 'xlink_resource' => 'discount_types'), '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) public function add($autodate = true, $nullValues = false, $categories = null)
{ {
$ret = NULL;
if (parent::add($autodate, $nullValues)) if (parent::add($autodate, $nullValues))
$ret = true; {
$this->updateCategories($categories);
$this->updateCategories($categories); // Set cache of feature detachable to true
return $ret; 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 */ /* 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()) if (!parent::delete())
return false; 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() public function getTranslationsFieldsChild()
@@ -579,12 +584,6 @@ class DiscountCore extends ObjectModel
*/ */
public static function isFeatureActive() public static function isFeatureActive()
{ {
if (self::$feature_active === null) return Configuration::get('PS_DISCOUNT_FEATURE_ACTIVE');
self::$feature_active = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT `id_discount`
FROM `'._DB_PREFIX_.'discount`
WHERE `active` = 1
');
return self::$feature_active;
} }
} }
+36 -13
View File
@@ -59,7 +59,6 @@ class GroupCore extends ObjectModel
protected static $_cacheReduction = array(); protected static $_cacheReduction = array();
protected static $_groupPriceDisplayMethod = array(); protected static $_groupPriceDisplayMethod = array();
protected static $feature_active = null;
protected $webserviceParameters = array(); protected $webserviceParameters = array();
@@ -150,7 +149,15 @@ class GroupCore extends ObjectModel
public function add($autodate = true, $nullValues = false) 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() public function delete()
@@ -159,11 +166,15 @@ class GroupCore extends ObjectModel
return false; return false;
if (parent::delete()) 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_.'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_.'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_.'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)); Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'product_group_reduction_cache` WHERE `id_group` = '.(int)$this->id);
Discount::deleteByIdGroup((int)($this->id)); Discount::deleteByIdGroup((int)$this->id);
// Refresh cache of feature detachable
Configuration::updateGlobalValue('PS_GROUP_FEATURE_ACTIVE', self::isCurrentlyUsed());
return true; return true;
} }
return false; return false;
@@ -176,12 +187,24 @@ class GroupCore extends ObjectModel
*/ */
public static function isFeatureActive() public static function isFeatureActive()
{ {
if (self::$feature_active === null) return Configuration::get('PS_GROUP_FEATURE_ACTIVE');
self::$feature_active = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' }
SELECT `id_group`
FROM `'._DB_PREFIX_.'group` /**
'); * This method is allow to know if a Discount entity is currently used
return self::$feature_active; * @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
');
} }
} }
+17
View File
@@ -905,4 +905,21 @@ abstract class ObjectModelCore
return isset($row['id']); 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);
}
} }
+23 -11
View File
@@ -30,7 +30,6 @@ class PackCore extends Product
protected static $cachePackItems = array(); protected static $cachePackItems = array();
protected static $cacheIsPack = array(); protected static $cacheIsPack = array();
protected static $cacheIsPacked = array(); protected static $cacheIsPacked = array();
protected static $feature_active = null;
public static function isPack($id_product) public static function isPack($id_product)
{ {
@@ -170,8 +169,9 @@ class PackCore extends Product
public static function deleteItems($id_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('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)); 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) 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()->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'); 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) public static function duplicate($id_product_old, $id_product_new)
@@ -204,12 +205,23 @@ class PackCore extends Product
*/ */
public static function isFeatureActive() public static function isFeatureActive()
{ {
if (self::$feature_active === null) return Configuration::get('PS_PACK_FEATURE_ACTIVE');
self::$feature_active = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' }
SELECT `id_product_pack`
FROM `'._DB_PREFIX_.'pack` /**
'); * This method is allow to know if a Pack entity is currently used
return self::$feature_active; * @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`
');
} }
} }
+17 -4
View File
@@ -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])) (!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`)'))) 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; return false;
// Refresh cache of feature detachable
Configuration::updateGlobalValue('PS_CUSTOMIZATION_FEATURE_ACTIVE', Customization::isCurrentlyUsed());
return true; return true;
} }
protected function _createLabel(&$languages, $type) protected function _createLabel(&$languages, $type)
{ {
/* Label insertion */ // 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())) 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; return false;
/* Multilingual label name creation */ // Multilingual label name creation
$values = ''; $values = '';
foreach ($languages AS $language) foreach ($languages AS $language)
$values .= '('.(int)($id_customization_field).', '.(int)($language['id_lang']).', \'\'), '; $values .= '('.(int)($id_customization_field).', '.(int)($language['id_lang']).', \'\'), ';
$values = rtrim($values, ', '); $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; return false;
// Set cache of feature detachable to true
Configuration::updateGlobalValue('PS_CUSTOMIZATION_FEATURE_ACTIVE', '1');
return true; return true;
} }
+26 -12
View File
@@ -80,20 +80,41 @@ class ProductDownloadCore extends ObjectModel
protected $table = 'product_download'; protected $table = 'product_download';
protected $identifier = 'id_product_download'; protected $identifier = 'id_product_download';
protected static $feature_active = null;
/** /**
* Build a virtual product * Build a virtual product
* *
* @param integer $id_product_download Existing productDownload id in order to load object (optional) * @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); parent::__construct($id_product_download);
// @TODO check if the file is present on hard drive // @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) if ($deleteFile)
return $this->deleteFile(); return $this->deleteFile();
@@ -118,7 +139,6 @@ class ProductDownloadCore extends ObjectModel
return $fields; return $fields;
} }
/** /**
* Delete the file * Delete the file
* *
@@ -280,14 +300,8 @@ class ProductDownloadCore extends ObjectModel
*/ */
public static function isFeatureActive() public static function isFeatureActive()
{ {
if (self::$feature_active === null) return Configuration::get('PS_VIRTUAL_PROD_FEATURE_ACTIVE');
self::$feature_active = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT `id_product_download`
FROM `'._DB_PREFIX_.'product_download`
');
return self::$feature_active;
} }
} }
+23 -9
View File
@@ -88,7 +88,15 @@ class SceneCore extends ObjectModel
return false; return false;
if (!$this->updateCategories()) if (!$this->updateCategories())
return false; 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) public function add($autodate = true, $nullValues = false)
@@ -98,7 +106,14 @@ class SceneCore extends ObjectModel
if (!empty($this->categories)) if (!empty($this->categories))
$this->addCategories($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() public function delete()
@@ -106,7 +121,11 @@ class SceneCore extends ObjectModel
$this->deleteZoneProducts(); $this->deleteZoneProducts();
$this->deleteCategories(); $this->deleteCategories();
if (parent::delete()) 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() public function deleteImage()
@@ -273,12 +292,7 @@ class SceneCore extends ObjectModel
*/ */
public static function isFeatureActive() public static function isFeatureActive()
{ {
if (self::$feature_active === null) return Configuration::get('PS_SCENE_FEATURE_ACTIVE');
self::$feature_active = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT `id_scene`
FROM `'._DB_PREFIX_.'scene`
');
return self::$feature_active;
} }
} }
+31 -9
View File
@@ -47,7 +47,6 @@ class SpecificPriceCore extends ObjectModel
protected static $_specificPriceCache = array(); protected static $_specificPriceCache = array();
protected static $_cache_priorities = array(); protected static $_cache_priorities = array();
protected static $feature_active = null;
public function getFields() public function getFields()
{ {
@@ -66,6 +65,28 @@ class SpecificPriceCore extends ObjectModel
return $fields; 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) public static function getByProductId($id_product)
{ {
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
@@ -82,7 +103,7 @@ class SpecificPriceCore extends ObjectModel
WHERE `id_product` = '.(int)$id_product); 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) protected static function _getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group)
{ {
$select = '('; $select = '(';
@@ -279,7 +300,13 @@ class SpecificPriceCore extends ObjectModel
public static function deleteByProductId($id_product) 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) public function duplicate($id_product = false)
@@ -296,12 +323,7 @@ class SpecificPriceCore extends ObjectModel
*/ */
public static function isFeatureActive() public static function isFeatureActive()
{ {
if (self::$feature_active === null) return Configuration::get('PS_SPECIFIC_PRICE_FEATURE_ACTIVE');
self::$feature_active = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT `id_specific_price`
FROM `'._DB_PREFIX_.'specific_price`
');
return self::$feature_active;
} }
} }
@@ -0,0 +1,38 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @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));
}
+9 -1
View File
@@ -225,7 +225,15 @@ INSERT INTO `PREFIX_configuration` (`id_configuration`, `name`, `value`, `date_a
(137, 'PS_SHOW_NEW_CUSTOMERS', '1', NOW(), NOW()), (137, 'PS_SHOW_NEW_CUSTOMERS', '1', NOW(), NOW()),
(138, 'PS_SHOW_NEW_MESSAGES', '1', NOW(), NOW()), (138, 'PS_SHOW_NEW_MESSAGES', '1', NOW(), NOW()),
(139, 'PS_FEATURE_FEATURE_ACTIVE', '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 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()), (36, 1, 'IN', NOW()),(36, 2, 'FA', NOW()),(36, 3, 'CU', NOW()),(36, 4, 'FA', NOW()),(36, 5, 'FA', NOW()),
+2
View File
@@ -72,6 +72,8 @@ INSERT INTO `PREFIX_configuration` (`name`, `value`, `date_add`, `date_upd`) VAL
('PS_FEATURE_FEATURE_ACTIVE', '1', NOW(), NOW()), ('PS_FEATURE_FEATURE_ACTIVE', '1', NOW(), NOW()),
('PS_COMBINATION_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` ADD `available_date` DATETIME NOT NULL AFTER `available_for_order`;
ALTER TABLE `PREFIX_product_attribute` ADD `available_date` DATETIME NOT NULL; ALTER TABLE `PREFIX_product_attribute` ADD `available_date` DATETIME NOT NULL;
+2
View File
@@ -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_order_detail_taxes.php');
require_once(_PS_INSTALLER_PHP_UPGRADE_DIR_.'update_feature_detachable_cache.php');
//old version detection //old version detection
global $oldversion, $logger; global $oldversion, $logger;
$oldversion = false; $oldversion = false;