Skip to content

Commit

Permalink
Merge branch 'hotfix/escape-queries'
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannu Pölönen committed Dec 21, 2016
2 parents 4ac32c9 + f50038e commit 5e25cda
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 40 deletions.
4 changes: 2 additions & 2 deletions classes/helpers/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public function exists($name, $lang_id = null, $id_shop_group = null, $id_shop =
*/
public function purge()
{
$config_table = _DB_PREFIX_ . 'configuration';
$config_lang_table = $config_table . '_lang';
$config_table = pSQL(_DB_PREFIX_ . 'configuration');
$config_lang_table = pSQL($config_table . '_lang');

Db::getInstance()->execute(
'DELETE `' . $config_lang_table . '` FROM `' . $config_lang_table . '`
Expand Down
17 changes: 9 additions & 8 deletions classes/helpers/customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class NostoTaggingHelperCustomer
*/
public static function getCustomerLinkTableName()
{
return _DB_PREFIX_.self::TABLE_NAME_CUSTOMER_LINK;
return pSQL(_DB_PREFIX_.self::TABLE_NAME_CUSTOMER_LINK);
}

/**
Expand Down Expand Up @@ -171,9 +171,9 @@ public function getNostoId(Order $order)
public function getCustomerReference(Customer $customer)
{
$sql = sprintf(
'SELECT `customer_reference` FROM `%s` WHERE `id_customer` = \'%s\'',
'SELECT `customer_reference` FROM `%s` WHERE `id_customer` = \'%d\'',
self::getCustomerReferenceTableName(),
$customer->id
(int)$customer->id
);

return Db::getInstance()->getValue($sql);
Expand All @@ -191,15 +191,16 @@ public function saveCustomerReference(Customer $customer, $reference)
{
$table = self::getCustomerReferenceTableName();
$customer_reference = pSQL($reference);
$customer_id = (int)$customer->id;
$data = array(
'id_customer' => $customer->id,
'id_customer' => $customer_id,
'customer_reference' => $customer_reference
);
$existing_id = Db::getInstance()->getRow(
sprintf(
'SELECT id_customer FROM `%s` WHERE id_customer = \'%s\'',
'SELECT id_customer FROM `%s` WHERE id_customer = \'%d\'',
$table,
$customer->id
$customer_id
)
);
if (empty($existing_id)) {
Expand All @@ -211,8 +212,8 @@ public function saveCustomerReference(Customer $customer, $reference)
} else {
unset($data['id_customer']);
$where = sprintf(
'id_customer=\'%s\'',
$customer->id
'id_customer=\'%d\'',
$customer_id
);
if (_PS_VERSION_ >= '1.5') {
return Db::getInstance()->update($table, $data, $where, 0, false, true, false);
Expand Down
2 changes: 1 addition & 1 deletion classes/helpers/url.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function getPreviewUrlCategory($id_category = null, $id_lang = null)
// Find a category that is active, not the root category and has a parent category.
$sql = '
SELECT `id_category`
FROM `'._DB_PREFIX_.'category`
FROM `'.pSQL(_DB_PREFIX_).'category`
WHERE `active` = 1
AND `id_parent` > 0
';
Expand Down
54 changes: 27 additions & 27 deletions classes/models/order.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ protected function getProductAttributeCombinationsById($product, $id_product_att
return $product->getAttributeCombinationsById($id_product_attribute, $id_lang);
}

return Db::getInstance()->ExecuteS(
return Db::getInstance()->executeS(
'SELECT
pa.*,
ag.`id_attribute_group`,
Expand All @@ -460,32 +460,32 @@ protected function getProductAttributeCombinationsById($product, $id_product_att
al.`name` attribute_name,
a.`id_attribute`,
pa.`unit_price_impact`
FROM
`'._DB_PREFIX_.'product_attribute` pa
LEFT JOIN
`'._DB_PREFIX_.'product_attribute_combination` pac
ON pac.`id_product_attribute` = pa.`id_product_attribute`
LEFT JOIN
`'._DB_PREFIX_.'attribute` a ON a.`id_attribute` = pac.`id_attribute`
LEFT JOIN
`'._DB_PREFIX_.'attribute_group` ag
ON ag.`id_attribute_group` = a.`id_attribute_group`
LEFT JOIN
`'._DB_PREFIX_.'attribute_lang` al
ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)($id_lang).')
LEFT JOIN
`'._DB_PREFIX_.'attribute_group_lang` agl
ON (
ag.`id_attribute_group` = agl.`id_attribute_group`
AND agl.`id_lang` = '.(int)($id_lang).'
)
WHERE
pa.`id_product` = '.(int)($product->id).'
AND
pa.`id_product_attribute` = '.(int)$id_product_attribute.'
GROUP BY
pa.`id_product_attribute`, ag.`id_attribute_group`
ORDER BY pa.`id_product_attribute`'
FROM
`'._DB_PREFIX_.'product_attribute` pa
LEFT JOIN
`'._DB_PREFIX_.'product_attribute_combination` pac
ON pac.`id_product_attribute` = pa.`id_product_attribute`
LEFT JOIN
`'._DB_PREFIX_.'attribute` a ON a.`id_attribute` = pac.`id_attribute`
LEFT JOIN
`'._DB_PREFIX_.'attribute_group` ag
ON ag.`id_attribute_group` = a.`id_attribute_group`
LEFT JOIN
`'._DB_PREFIX_.'attribute_lang` al
ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)($id_lang).')
LEFT JOIN
`'._DB_PREFIX_.'attribute_group_lang` agl
ON (
ag.`id_attribute_group` = agl.`id_attribute_group`
AND agl.`id_lang` = '.(int)($id_lang).'
)
WHERE
pa.`id_product` = '.(int)($product->id).'
AND
pa.`id_product_attribute` = '.(int)$id_product_attribute.'
GROUP BY
pa.`id_product_attribute`, ag.`id_attribute_group`
ORDER BY pa.`id_product_attribute`'
);
}
}
3 changes: 2 additions & 1 deletion controllers/front/order.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected function getOrderIds()
LIMIT %d
OFFSET %d
',
_DB_PREFIX_,
pSQL(_DB_PREFIX_),
$where,
$this->limit,
$this->offset
Expand All @@ -109,6 +109,7 @@ protected function getOrderIds()
foreach ($rows as $row) {
$order_ids[] = (int)$row['id_order'];
}

return $order_ids;
}
}
3 changes: 2 additions & 1 deletion controllers/front/product.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected function getProductIds()
LIMIT %d
OFFSET %d
',
_DB_PREFIX_,
pSQL(_DB_PREFIX_),
$this->limit,
$this->offset
);
Expand All @@ -90,6 +90,7 @@ protected function getProductIds()
foreach ($rows as $row) {
$product_ids[] = (int)$row['id_product'];
}

return $product_ids;
}
}

0 comments on commit 5e25cda

Please sign in to comment.