Prevent non-number amounts for shopping list items on database level (closes #2657)

This commit is contained in:
Bernd Bestel 2025-01-30 19:42:56 +01:00
parent a177e2a185
commit c8ac094bf4
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
3 changed files with 36 additions and 4 deletions

View File

@ -16,7 +16,7 @@
### 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

35
migrations/0250.sql Normal file
View 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');

View File

@ -264,11 +264,8 @@
$productQuConversion = FindObjectInArrayByPropertyValue($productQuConversions, 'to_qu_id', $listItem->qu_id);
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;
}
}
if(boolval($userSettings['shopping_list_round_up']))
{