[*] Classes: Db->execute() now return always a boolean. Use Db->query() instead.
This commit is contained in:
+1
-1
@@ -243,7 +243,7 @@ class BackupCore
|
||||
|
||||
if (!in_array($schema[0]['Table'], $ignore_insert_table))
|
||||
{
|
||||
$data = Db::getInstance()->executeS('SELECT * FROM `' . $schema[0]['Table'] . '`', false);
|
||||
$data = Db::getInstance()->query('SELECT * FROM `' . $schema[0]['Table'] . '`', false);
|
||||
$sizeof = DB::getInstance()->NumRows();
|
||||
$lines = explode("\n", $schema[0]['Create Table']);
|
||||
|
||||
|
||||
@@ -260,12 +260,12 @@ class CartRuleCore extends ObjectModel
|
||||
return array();
|
||||
|
||||
$productRules = array();
|
||||
$result = Db::getInstance()->ExecuteS('
|
||||
$results = Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
FROM '._DB_PREFIX_.'cart_rule_product_rule pr
|
||||
LEFT JOIN '._DB_PREFIX_.'cart_rule_product_rule_value prv ON pr.id_product_rule = prv.id_product_rule
|
||||
WHERE pr.id_cart_rule = '.(int)$this->id, false);
|
||||
while ($row = Db::getInstance()->nextRow($result))
|
||||
foreach ($results as $row)
|
||||
{
|
||||
if (!isset($productRules[$row['id_product_rule']]))
|
||||
$productRules[$row['id_product_rule']] = array('quantity' => $row['quantity'], 'type' => $row['type'], 'values' => array());
|
||||
|
||||
+23
-21
@@ -62,18 +62,18 @@ class GroupReductionCore extends ObjectModel
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$resource = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
$products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
SELECT p.`id_product`
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
WHERE p.`id_category_default` = '.(int)$this->id_category
|
||||
, false);
|
||||
);
|
||||
|
||||
while ($row = Db::getInstance()->nextRow($resource))
|
||||
{
|
||||
$query = 'DELETE FROM `'._DB_PREFIX_.'product_group_reduction_cache` WHERE `id_product` = '.(int)$row['id_product'];
|
||||
if (Db::getInstance()->execute($query) === false)
|
||||
return false;
|
||||
}
|
||||
$ids = array();
|
||||
foreach ($products as $row)
|
||||
$ids[] = $row['id_product'];
|
||||
|
||||
if ($ids)
|
||||
Db::getInstance()->delete(_DB_PREFIX_.'product_group_reduction_cache', 'id_product IN ('.implode(', ', $ids).')');
|
||||
return (parent::delete());
|
||||
}
|
||||
|
||||
@@ -84,15 +84,15 @@ class GroupReductionCore extends ObjectModel
|
||||
|
||||
protected function _setCache()
|
||||
{
|
||||
$resource = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
$products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
SELECT p.`id_product`
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
WHERE p.`id_category_default` = '.(int)$this->id_category
|
||||
, false);
|
||||
);
|
||||
|
||||
$query = 'INSERT INTO `'._DB_PREFIX_.'product_group_reduction_cache` (`id_product`, `id_group`, `reduction`) VALUES ';
|
||||
$updated = false;
|
||||
while ($row = Db::getInstance()->nextRow($resource))
|
||||
foreach ($products as $row)
|
||||
{
|
||||
$query .= '('.(int)$row['id_product'].', '.(int)$this->id_group.', '.(float)$this->reduction.'), ';
|
||||
$updated = true;
|
||||
@@ -105,21 +105,23 @@ class GroupReductionCore extends ObjectModel
|
||||
|
||||
protected function _updateCache()
|
||||
{
|
||||
$resource = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
$products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
SELECT p.`id_product`
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
WHERE p.`id_category_default` = '.(int)$this->id_category
|
||||
, false);
|
||||
|
||||
while ($row = Db::getInstance()->nextRow($resource))
|
||||
{
|
||||
$query = 'UPDATE `'._DB_PREFIX_.'product_group_reduction_cache`
|
||||
SET `reduction` = '.(float)$this->reduction.'
|
||||
WHERE `id_product` = '.(int)$row['id_product'].' AND `id_group` = '.(int)$this->id_group;
|
||||
if (Db::getInstance()->execute($query) === false)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
$ids = array();
|
||||
foreach ($products as $product)
|
||||
$ids[] = $product['id_product'];
|
||||
|
||||
$result = true;
|
||||
if ($ids)
|
||||
$result &= Db::getInstance()->autoExecute(_DB_PREFIX_.'product_group_reduction_cache', array(
|
||||
'reduction' => (float)$this->reduction,
|
||||
), 'UPDATE', 'id_product IN('.implode(', ', $ids).') AND id_group = '.(int)$this->id_group);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getGroupReductions($id_group, $id_lang)
|
||||
|
||||
+3
-3
@@ -220,11 +220,11 @@ class HookCore extends ObjectModel
|
||||
$sql .= '
|
||||
GROUP BY hm.id_hook, hm.id_module
|
||||
ORDER BY hm.`position`';
|
||||
$result = $db->executeS($sql, false);
|
||||
$results = $db->executeS($sql);
|
||||
self::$_hookModulesCache = array();
|
||||
|
||||
if ($result)
|
||||
while ($row = $db->nextRow())
|
||||
if ($results)
|
||||
foreach ($results as $row)
|
||||
{
|
||||
$row['hook'] = strtolower($row['hook']);
|
||||
if (!isset(self::$_hookModulesCache[$row['hook']]))
|
||||
|
||||
+3
-4
@@ -3226,16 +3226,15 @@ class ProductCore extends ObjectModel
|
||||
$sql = 'SELECT `display_filename`, `filename`, `date_add`, `date_expiration`, `nb_days_accessible`, `nb_downloadable`, `active`, `is_shareable`
|
||||
FROM `'._DB_PREFIX_.'product_download`
|
||||
WHERE `id_product` = '.(int)$id_product_old;
|
||||
$resource = Db::getInstance()->execute($sql);
|
||||
|
||||
if (!Db::getInstance()->NumRows())
|
||||
$results = Db::getInstance()->executeS($sql);
|
||||
if (!$results)
|
||||
return true;
|
||||
|
||||
$query = 'INSERT INTO `'._DB_PREFIX_.'product_download`
|
||||
(`id_product`, `display_filename`, `filename`, `date_add`, `date_expiration`, `nb_days_accessible`, `nb_downloadable`, `active`, `is_shareable`)
|
||||
VALUES';
|
||||
|
||||
while ($row = Db::getInstance()->nextRow($resource))
|
||||
foreach ($results as $row)
|
||||
$query .= ' ('.(int)$id_product_new.', \''.pSQL($row['display_filename']).'\', \''.pSQL($row['filename']).
|
||||
'\', \''.pSQL($row['date_add']).'\', \''.pSQL($row['date_expiration']).'\', '.(int)$row['nb_days_accessible'].
|
||||
', '.(int)$row['nb_downloadable'].', '.(int)$row['active'].'), '.(int)$row['is_shareable'].'),';
|
||||
|
||||
+7
-9
@@ -219,16 +219,15 @@ class SearchCore
|
||||
SELECT id_group FROM '._DB_PREFIX_.'customer_group
|
||||
WHERE id_customer = '.(int)$id_customer.'
|
||||
)');
|
||||
$result = $db->executeS($sql, false);
|
||||
$results = $db->executeS($sql);
|
||||
|
||||
$eligibleProducts = array();
|
||||
while ($row = $db->nextRow($result))
|
||||
foreach ($results as $row)
|
||||
$eligibleProducts[] = $row['id_product'];
|
||||
foreach ($intersectArray as $query)
|
||||
{
|
||||
$result = $db->executeS($query, false);
|
||||
$eligibleProducts2 = array();
|
||||
while ($row = $db->nextRow($result))
|
||||
foreach ($db->executeS($query) as $row)
|
||||
$eligibleProducts2[] = $row['id_product'];
|
||||
|
||||
$eligibleProducts = array_intersect($eligibleProducts, $eligibleProducts2);
|
||||
@@ -418,19 +417,18 @@ class SearchCore
|
||||
'features' => Configuration::get('PS_SEARCH_WEIGHT_FEATURE')
|
||||
);
|
||||
|
||||
// Those are kind of global variables required to save the processed data in the database every X occurences, in order to avoid overloading MySQL
|
||||
// Those are kind of global variables required to save the processed data in the database every X occurrences, in order to avoid overloading MySQL
|
||||
$countWords = 0;
|
||||
$countProducts = 0;
|
||||
$queryArray3 = array();
|
||||
$productsArray = array();
|
||||
|
||||
// Every indexed words are cached into a PHP array
|
||||
$wordIdsByWord = array();
|
||||
$wordIds = Db::getInstance()->executeS('
|
||||
SELECT id_word, word, id_lang, id_shop
|
||||
FROM '._DB_PREFIX_.'search_word', false);
|
||||
SELECT id_word, word, id_lang, id_shop
|
||||
FROM '._DB_PREFIX_.'search_word');
|
||||
$wordIdsByWord = array();
|
||||
while ($wordId = $db->nextRow($wordIds))
|
||||
foreach ($wordIds as $wordId)
|
||||
{
|
||||
if (!isset($wordIdsByWord[$wordId['id_shop']][$wordId['id_lang']]))
|
||||
$wordIdsByWord[$wordId['id_shop']][$wordId['id_lang']] = array();
|
||||
|
||||
@@ -286,7 +286,7 @@ class SpecificPriceCore extends ObjectModel
|
||||
if (!self::isFeatureActive())
|
||||
return array();
|
||||
|
||||
$resource = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
$results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
SELECT `id_product`
|
||||
FROM `'._DB_PREFIX_.'specific_price`
|
||||
WHERE `id_shop` IN(0, '.(int)$id_shop.') AND
|
||||
@@ -301,9 +301,9 @@ class SpecificPriceCore extends ObjectModel
|
||||
)
|
||||
AND
|
||||
`reduction` > 0
|
||||
', false);
|
||||
');
|
||||
$ids_product = array();
|
||||
while ($row = DB::getInstance()->nextRow($resource))
|
||||
foreach ($results as $row)
|
||||
$ids_product[] = (int)$row['id_product'];
|
||||
return $ids_product;
|
||||
}
|
||||
|
||||
+11
-11
@@ -362,14 +362,14 @@ abstract class DbCore
|
||||
* @param bool $use_cache Use cache or not
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($table, $where = false, $limit = false, $use_cache = 1)
|
||||
public function delete($table, $where = false, $limit = false, $use_cache = true)
|
||||
{
|
||||
$this->result = false;
|
||||
$sql = 'DELETE FROM `'.bqSQL($table).'`'.($where ? ' WHERE '.$where : '').($limit ? ' LIMIT '.(int)$limit : '');
|
||||
$res = $this->query($sql);
|
||||
if ($use_cache && $this->is_cache_enabled)
|
||||
Cache::getInstance()->deleteQuery($sql);
|
||||
return $res;
|
||||
return (bool)$res;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -377,30 +377,30 @@ abstract class DbCore
|
||||
*
|
||||
* @param string $sql
|
||||
* @param bool $use_cache
|
||||
* @return mixed
|
||||
* @return bool
|
||||
*/
|
||||
public function execute($sql, $use_cache = 1)
|
||||
public function execute($sql, $use_cache = true)
|
||||
{
|
||||
$sql = (string)$sql;
|
||||
$this->result = $this->query($sql);
|
||||
if ($use_cache && $this->is_cache_enabled)
|
||||
Cache::getInstance()->deleteQuery($sql);
|
||||
return $this->result;
|
||||
return (bool)$this->result;
|
||||
}
|
||||
|
||||
/**
|
||||
* ExecuteS return the result of $sql as array
|
||||
*
|
||||
* @param string $sql query to execute
|
||||
* @param boolean $array return an array instead of a mysql_result object
|
||||
* @param boolean $array return an array instead of a mysql_result object (deprecated since 1.5.0, use query method instead)
|
||||
* @param int $use_cache if query has been already executed, use its result
|
||||
* @return array or result object
|
||||
*/
|
||||
public function executeS($sql, $array = true, $use_cache = 1)
|
||||
public function executeS($sql, $array = true, $use_cache = true)
|
||||
{
|
||||
$sql = (string)$sql;
|
||||
|
||||
// This methode must be used only with queries which display results
|
||||
// This method must be used only with queries which display results
|
||||
if (!preg_match('#^\s*(select|show|explain|describe)\s#i', $sql))
|
||||
{
|
||||
if (defined('_PS_MODE_DEV_') && _PS_MODE_DEV_)
|
||||
@@ -441,7 +441,7 @@ abstract class DbCore
|
||||
* @param int $use_cache find it in cache first
|
||||
* @return array associative array of (field=>value)
|
||||
*/
|
||||
public function getRow($sql, $use_cache = 1)
|
||||
public function getRow($sql, $use_cache = true)
|
||||
{
|
||||
$sql = (string)$sql;
|
||||
$sql .= ' LIMIT 1';
|
||||
@@ -471,7 +471,7 @@ abstract class DbCore
|
||||
* @param int $use_cache
|
||||
* @return void
|
||||
*/
|
||||
public function getValue($sql, $use_cache = 1)
|
||||
public function getValue($sql, $use_cache = true)
|
||||
{
|
||||
$sql = (string)$sql;
|
||||
if (!$result = $this->getRow($sql, $use_cache))
|
||||
@@ -504,7 +504,7 @@ abstract class DbCore
|
||||
* @param string $sql
|
||||
* @param bool $use_cache
|
||||
*/
|
||||
protected function q($sql, $use_cache = 1)
|
||||
protected function q($sql, $use_cache = true)
|
||||
{
|
||||
global $webservice_call;
|
||||
|
||||
|
||||
@@ -294,7 +294,7 @@ class StockManagerCore implements StockManagerInterface
|
||||
if ($left_quantity_to_check <= 0)
|
||||
continue;
|
||||
|
||||
$resource = Db::getInstance(_PS_USE_SQL_SLAVE_)->execute('
|
||||
$resource = Db::getInstance(_PS_USE_SQL_SLAVE_)->query('
|
||||
SELECT sm.`id_stock_mvt`, sm.`date_add`, sm.`physical_quantity`,
|
||||
IF ((sm2.`physical_quantity` is null), sm.`physical_quantity`, (sm.`physical_quantity` - SUM(sm2.`physical_quantity`))) as qty
|
||||
FROM `'._DB_PREFIX_.'stock_mvt` sm
|
||||
|
||||
Reference in New Issue
Block a user