From f5bcab745971d6add0db979ba7b238edf34c0f20 Mon Sep 17 00:00:00 2001 From: dMetzger Date: Fri, 31 Aug 2012 12:16:15 +0000 Subject: [PATCH] // Opti --- classes/Autoload.php | 4 ++-- classes/Product.php | 9 +++----- classes/stock/StockAvailable.php | 22 +++++++++---------- .../AdminAttributeGeneratorController.php | 2 +- tools/profiling/Controller.php | 21 ++++++++++-------- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/classes/Autoload.php b/classes/Autoload.php index 5e1e379a8..9e2a23673 100644 --- a/classes/Autoload.php +++ b/classes/Autoload.php @@ -103,9 +103,9 @@ class Autoload { // request a non Core Class load the associated Core class if exists 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])) - require($this->root_dir.$this->index[$classname]); + require_once($this->root_dir.$this->index[$classname]); } } // Call directly ProductCore, ShopCore class diff --git a/classes/Product.php b/classes/Product.php index ee553c026..61b4eeb1d 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -1350,8 +1350,6 @@ class ProductCore extends ObjectModel WHERE `id_product` = '.(int)$this->id.' ), \'0\') WHERE `id_product` = '.(int)$this->id); - - } /** * Delete product attributes @@ -4931,11 +4929,10 @@ class ProductCore extends ObjectModel public function hasAttributesInOtherShops() { - return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' - SELECT COUNT(*) + return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' + SELECT pa.id_product_attribute FROM `'._DB_PREFIX_.'product_attribute` pa - LEFT JOIN `'._DB_PREFIX_.'product_attribute_shop` pas - ON (pa.`id_product_attribute` = pas.`id_product_attribute`) + LEFT JOIN `'._DB_PREFIX_.'product_attribute_shop` pas ON (pa.`id_product_attribute` = pas.`id_product_attribute`) WHERE pa.`id_product` = '.(int)$this->id ); } diff --git a/classes/stock/StockAvailable.php b/classes/stock/StockAvailable.php index 52a1db104..95ac0622c 100644 --- a/classes/stock/StockAvailable.php +++ b/classes/stock/StockAvailable.php @@ -492,15 +492,15 @@ class StockAvailableCore extends ObjectModel * * @param int $id_product * @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(' DELETE FROM '._DB_PREFIX_.'stock_available WHERE id_product = '.(int)$id_product. ($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 */ - 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(); @@ -594,19 +594,19 @@ class StockAvailableCore extends ObjectModel // if there is no $id_shop, gets the context one // get shop group too - if ($id_shop === null) + if ($shop === null) { if (Shop::getContext() == Shop::CONTEXT_GROUP) $shop_group = Shop::getContextShopGroup(); else - { $shop_group = $context->shop->getGroup(); - $id_shop = $context->shop->id; - } + $shop = $context->shop; } + elseif (is_object($shop)) + $shop_group = $shop->getGroup(); else { - $shop = new Shop($id_shop); + $shop = new Shop($shop); $shop_group = $shop->getGroup(); } @@ -627,9 +627,9 @@ class StockAvailableCore extends ObjectModel else { if (is_object($sql)) - $sql->where(pSQL($alias).'id_shop = '.(int)$id_shop); + $sql->where(pSQL($alias).'id_shop = '.(int)$shop->id); else - $sql = ' AND '.pSQL($alias).'id_shop = '.(int)$id_shop.' '; + $sql = ' AND '.pSQL($alias).'id_shop = '.(int)$shop->id.' '; } return $sql; diff --git a/controllers/admin/AdminAttributeGeneratorController.php b/controllers/admin/AdminAttributeGeneratorController.php index 3a1d2fd69..0dae7e109 100644 --- a/controllers/admin/AdminAttributeGeneratorController.php +++ b/controllers/admin/AdminAttributeGeneratorController.php @@ -114,7 +114,7 @@ class AdminAttributeGeneratorControllerCore extends AdminController { $attributes = Product::getProductAttributesIds($this->product->id); 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(); diff --git a/tools/profiling/Controller.php b/tools/profiling/Controller.php index 3d17329fa..9dd524e00 100644 --- a/tools/profiling/Controller.php +++ b/tools/profiling/Controller.php @@ -389,15 +389,18 @@ abstract class Controller extends ControllerCore foreach ($queries as $data) { echo $hr.'getTimeColor($data['time'] * 1000).'>'.round($data['time'] * 1000, 3).' ms '.$data['query'].'
in '.$data['file'].':'.$data['line'].'
'; - $explain = Db::getInstance()->executeS('explain '.$data['query']); - if (stristr($explain[0]['Extra'], 'filesort')) - echo 'getTimeColor($data['time'] * 1000).'>USING FILESORT - '; - $browsed_rows = 1; - foreach ($explain as $row) - $browsed_rows *= $row['rows']; - 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 '
Useless GROUP BY need to be removed'; + if (preg_match('/^\s*select\s+/i', $data['query'])) + { + $explain = Db::getInstance()->executeS('explain '.$data['query']); + if (stristr($explain[0]['Extra'], 'filesort')) + echo 'getTimeColor($data['time'] * 1000).'>USING FILESORT - '; + $browsed_rows = 1; + foreach ($explain as $row) + $browsed_rows *= $row['rows']; + 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 '
Useless GROUP BY need to be removed'; + } } echo '