mirror of
https://github.com/grocy/grocy.git
synced 2025-04-30 01:55:47 +00:00
Prevent non-number amounts for shopping list items on database level (closes #2657)
This commit is contained in:
parent
a177e2a185
commit
c8ac094bf4
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
### Shopping list
|
### Shopping list
|
||||||
|
|
||||||
- xxx
|
- Optimized that non-number amounts are now prevented on database level (was infamously a problem when using specific community contributed alternative clients)
|
||||||
|
|
||||||
### Recipes
|
### Recipes
|
||||||
|
|
||||||
|
35
migrations/0250.sql
Normal file
35
migrations/0250.sql
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
DROP TRIGGER shopping_list_qu_id_default;
|
||||||
|
|
||||||
|
CREATE TRIGGER shopping_list_defaults_INS AFTER INSERT ON shopping_list
|
||||||
|
BEGIN
|
||||||
|
UPDATE shopping_list
|
||||||
|
SET qu_id = (SELECT qu_id_purchase FROM products WHERE id = product_id)
|
||||||
|
WHERE IFNULL(qu_id, '') = ''
|
||||||
|
AND id = NEW.id;
|
||||||
|
|
||||||
|
UPDATE shopping_list
|
||||||
|
SET amount = 1
|
||||||
|
WHERE TYPEOF(amount) NOT IN ('integer', 'real')
|
||||||
|
AND id = NEW.id;
|
||||||
|
END;
|
||||||
|
|
||||||
|
CREATE TRIGGER shopping_list_defaults_UPD AFTER UPDATE ON shopping_list
|
||||||
|
BEGIN
|
||||||
|
UPDATE shopping_list
|
||||||
|
SET qu_id = (SELECT qu_id_purchase FROM products WHERE id = product_id)
|
||||||
|
WHERE IFNULL(qu_id, '') = ''
|
||||||
|
AND id = NEW.id;
|
||||||
|
|
||||||
|
UPDATE shopping_list
|
||||||
|
SET amount = 1
|
||||||
|
WHERE TYPEOF(amount) NOT IN ('integer', 'real')
|
||||||
|
AND id = NEW.id;
|
||||||
|
END;
|
||||||
|
|
||||||
|
UPDATE shopping_list
|
||||||
|
SET qu_id = (SELECT qu_id_purchase FROM products WHERE id = product_id)
|
||||||
|
WHERE IFNULL(qu_id, '') = '';
|
||||||
|
|
||||||
|
UPDATE shopping_list
|
||||||
|
SET amount = 1
|
||||||
|
WHERE TYPEOF(amount) NOT IN ('integer', 'real');
|
@ -264,11 +264,8 @@
|
|||||||
$productQuConversion = FindObjectInArrayByPropertyValue($productQuConversions, 'to_qu_id', $listItem->qu_id);
|
$productQuConversion = FindObjectInArrayByPropertyValue($productQuConversions, 'to_qu_id', $listItem->qu_id);
|
||||||
if ($productQuConversion)
|
if ($productQuConversion)
|
||||||
{
|
{
|
||||||
if (is_numeric($listItem->amount) && is_numeric($productQuConversion->factor)) // However people manage to have a non-number here, happened at least a trilion times for Grocy Mobile (iOS) users
|
|
||||||
{
|
|
||||||
$listItem->amount = $listItem->amount * $productQuConversion->factor;
|
$listItem->amount = $listItem->amount * $productQuConversion->factor;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(boolval($userSettings['shopping_list_round_up']))
|
if(boolval($userSettings['shopping_list_round_up']))
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user