Fixed meal plan did not load when a containing recipe was deleted (closes #361)

This commit is contained in:
Bernd Bestel 2019-09-21 09:18:40 +02:00
parent ab44566890
commit 327c1f4fb3
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
4 changed files with 24 additions and 2 deletions

View File

@ -47,6 +47,7 @@
- New option "price factor" per recipe ingredient (defaults to `1`) - the resulting costs of the recipe ingredient will be multiplied by that factor
- Use this for example for spices in combination with "Only check if a single unit is in stock" to not take the full price of a pack of pepper into account for a recipe
- The search field on the recipe overview page now also searches for product names of recipe ingredients (means it's possible to search an recipe by a product name)
- Fixed a problem where the meal plan did not load when a recipe, which was already added to a the meal plan, was deleted
### Chores improvements
- Chores can now be assigned to users

View File

@ -135,12 +135,19 @@ class RecipesController extends BaseController
$events = array();
foreach($this->Database->meal_plan() as $mealPlanEntry)
{
$recipe = FindObjectInArrayByPropertyValue($recipes, 'id', $mealPlanEntry['recipe_id']);
$title = '';
if ($recipe !== null)
{
$title = $recipe->name;
}
$events[] = array(
'id' => $mealPlanEntry['id'],
'title' => FindObjectInArrayByPropertyValue($recipes, 'id', $mealPlanEntry['recipe_id'])->name,
'title' => $title,
'start' => $mealPlanEntry['day'],
'date_format' => 'date',
'recipe' => json_encode(FindObjectInArrayByPropertyValue($recipes, 'id', $mealPlanEntry['recipe_id'])),
'recipe' => json_encode($recipe),
'mealPlanEntry' => json_encode($mealPlanEntry)
);
}

9
migrations/0089.sql Normal file
View File

@ -0,0 +1,9 @@
CREATE TRIGGER remove_recipe_from_meal_plans AFTER DELETE ON recipes
BEGIN
DELETE FROM meal_plan
WHERE recipe_id = OLD.id;
END;
-- Delete all recipes from the meal plan which doesn't exist anymore
DELETE FROM meal_plan
WHERE recipe_id NOT IN (SELECT id FROM recipes);

View File

@ -59,6 +59,11 @@ var calendar = $("#calendar").fullCalendar({
"eventRender": function(event, element)
{
var recipe = JSON.parse(event.recipe);
if (recipe === null || recipe === undefined)
{
return false;
}
var mealPlanEntry = JSON.parse(event.mealPlanEntry);
var resolvedRecipe = FindObjectInArrayByPropertyValue(recipesResolved, "recipe_id", recipe.id);