This commit is contained in:
dMetzger
2012-08-31 12:16:15 +00:00
parent 75710639d0
commit f5bcab7459
5 changed files with 29 additions and 29 deletions
+2 -2
View File
@@ -103,9 +103,9 @@ class Autoload
{ {
// request a non Core Class load the associated Core class if exists // request a non Core Class load the associated Core class if exists
if (isset($this->index[$classname.'Core'])) if (isset($this->index[$classname.'Core']))
require($this->root_dir.$this->index[$classname.'Core']); require_once($this->root_dir.$this->index[$classname.'Core']);
if (isset($this->index[$classname])) if (isset($this->index[$classname]))
require($this->root_dir.$this->index[$classname]); require_once($this->root_dir.$this->index[$classname]);
} }
} }
// Call directly ProductCore, ShopCore class // Call directly ProductCore, ShopCore class
+3 -6
View File
@@ -1350,8 +1350,6 @@ class ProductCore extends ObjectModel
WHERE `id_product` = '.(int)$this->id.' WHERE `id_product` = '.(int)$this->id.'
), \'0\') ), \'0\')
WHERE `id_product` = '.(int)$this->id); WHERE `id_product` = '.(int)$this->id);
} }
/** /**
* Delete product attributes * Delete product attributes
@@ -4931,11 +4929,10 @@ class ProductCore extends ObjectModel
public function hasAttributesInOtherShops() public function hasAttributesInOtherShops()
{ {
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT COUNT(*) SELECT pa.id_product_attribute
FROM `'._DB_PREFIX_.'product_attribute` pa FROM `'._DB_PREFIX_.'product_attribute` pa
LEFT JOIN `'._DB_PREFIX_.'product_attribute_shop` pas LEFT JOIN `'._DB_PREFIX_.'product_attribute_shop` pas ON (pa.`id_product_attribute` = pas.`id_product_attribute`)
ON (pa.`id_product_attribute` = pas.`id_product_attribute`)
WHERE pa.`id_product` = '.(int)$this->id WHERE pa.`id_product` = '.(int)$this->id
); );
} }
+11 -11
View File
@@ -492,15 +492,15 @@ class StockAvailableCore extends ObjectModel
* *
* @param int $id_product * @param int $id_product
* @param int $id_product_attribute Optional * @param int $id_product_attribute Optional
* @param int $id_shop Optional * @param mixed $id_shop shop id or shop object Optional
*/ */
public static function removeProductFromStockAvailable($id_product, $id_product_attribute = null, $id_shop = null) public static function removeProductFromStockAvailable($id_product, $id_product_attribute = null, $shop = null)
{ {
return Db::getInstance()->execute(' return Db::getInstance()->execute('
DELETE FROM '._DB_PREFIX_.'stock_available DELETE FROM '._DB_PREFIX_.'stock_available
WHERE id_product = '.(int)$id_product. WHERE id_product = '.(int)$id_product.
($id_product_attribute ? ' AND id_product_attribute = '.(int)$id_product_attribute : ''). ($id_product_attribute ? ' AND id_product_attribute = '.(int)$id_product_attribute : '').
StockAvailable::addSqlShopRestriction(null, $id_shop) StockAvailable::addSqlShopRestriction(null, $shop)
); );
} }
@@ -585,7 +585,7 @@ class StockAvailableCore extends ObjectModel
* *
* @return mixed the DbQuery object or the sql restriction string * @return mixed the DbQuery object or the sql restriction string
*/ */
public static function addSqlShopRestriction(DbQuery $sql = null, $id_shop = null, $alias = null) public static function addSqlShopRestriction(DbQuery $sql = null, $shop = null, $alias = null)
{ {
$context = Context::getContext(); $context = Context::getContext();
@@ -594,19 +594,19 @@ class StockAvailableCore extends ObjectModel
// if there is no $id_shop, gets the context one // if there is no $id_shop, gets the context one
// get shop group too // get shop group too
if ($id_shop === null) if ($shop === null)
{ {
if (Shop::getContext() == Shop::CONTEXT_GROUP) if (Shop::getContext() == Shop::CONTEXT_GROUP)
$shop_group = Shop::getContextShopGroup(); $shop_group = Shop::getContextShopGroup();
else else
{
$shop_group = $context->shop->getGroup(); $shop_group = $context->shop->getGroup();
$id_shop = $context->shop->id; $shop = $context->shop;
}
} }
elseif (is_object($shop))
$shop_group = $shop->getGroup();
else else
{ {
$shop = new Shop($id_shop); $shop = new Shop($shop);
$shop_group = $shop->getGroup(); $shop_group = $shop->getGroup();
} }
@@ -627,9 +627,9 @@ class StockAvailableCore extends ObjectModel
else else
{ {
if (is_object($sql)) if (is_object($sql))
$sql->where(pSQL($alias).'id_shop = '.(int)$id_shop); $sql->where(pSQL($alias).'id_shop = '.(int)$shop->id);
else else
$sql = ' AND '.pSQL($alias).'id_shop = '.(int)$id_shop.' '; $sql = ' AND '.pSQL($alias).'id_shop = '.(int)$shop->id.' ';
} }
return $sql; return $sql;
@@ -114,7 +114,7 @@ class AdminAttributeGeneratorControllerCore extends AdminController
{ {
$attributes = Product::getProductAttributesIds($this->product->id); $attributes = Product::getProductAttributesIds($this->product->id);
foreach ($attributes as $attribute) foreach ($attributes as $attribute)
StockAvailable::removeProductFromStockAvailable($this->product->id, $attribute['id_product_attribute'], $this->context->shop->id); StockAvailable::removeProductFromStockAvailable($this->product->id, $attribute['id_product_attribute'], $this->context->shop);
} }
$this->product->deleteProductAttributes(); $this->product->deleteProductAttributes();
+12 -9
View File
@@ -389,15 +389,18 @@ abstract class Controller extends ControllerCore
foreach ($queries as $data) foreach ($queries as $data)
{ {
echo $hr.'<b '.$this->getTimeColor($data['time'] * 1000).'>'.round($data['time'] * 1000, 3).' ms</b> '.$data['query'].'<br />in '.$data['file'].':'.$data['line'].'<br />'; echo $hr.'<b '.$this->getTimeColor($data['time'] * 1000).'>'.round($data['time'] * 1000, 3).' ms</b> '.$data['query'].'<br />in '.$data['file'].':'.$data['line'].'<br />';
$explain = Db::getInstance()->executeS('explain '.$data['query']); if (preg_match('/^\s*select\s+/i', $data['query']))
if (stristr($explain[0]['Extra'], 'filesort')) {
echo '<b '.$this->getTimeColor($data['time'] * 1000).'>USING FILESORT</b> - '; $explain = Db::getInstance()->executeS('explain '.$data['query']);
$browsed_rows = 1; if (stristr($explain[0]['Extra'], 'filesort'))
foreach ($explain as $row) echo '<b '.$this->getTimeColor($data['time'] * 1000).'>USING FILESORT</b> - ';
$browsed_rows *= $row['rows']; $browsed_rows = 1;
echo $this->displayRowsBrowsed($browsed_rows); foreach ($explain as $row)
if (stristr($data['query'], 'group by') && !preg_match('/(avg|count|min|max|group_concat|sum)\s*\(/i', $data['query'])) $browsed_rows *= $row['rows'];
echo '<br /><b>Useless GROUP BY need to be removed</b>'; echo $this->displayRowsBrowsed($browsed_rows);
if (stristr($data['query'], 'group by') && !preg_match('/(avg|count|min|max|group_concat|sum)\s*\(/i', $data['query']))
echo '<br /><b>Useless GROUP BY need to be removed</b>';
}
} }
echo '</div> echo '</div>
<div class="rte" style="text-align:left;padding:8px"> <div class="rte" style="text-align:left;padding:8px">