diff --git a/changelog/52_UNRELEASED_2019-xx-xx.md b/changelog/52_UNRELEASED_2019-xx-xx.md index 72ddb548..45dfc54e 100644 --- a/changelog/52_UNRELEASED_2019-xx-xx.md +++ b/changelog/52_UNRELEASED_2019-xx-xx.md @@ -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 diff --git a/controllers/RecipesController.php b/controllers/RecipesController.php index 29228814..8f6cd3da 100644 --- a/controllers/RecipesController.php +++ b/controllers/RecipesController.php @@ -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) ); } diff --git a/migrations/0089.sql b/migrations/0089.sql new file mode 100644 index 00000000..5d3625f6 --- /dev/null +++ b/migrations/0089.sql @@ -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); diff --git a/public/viewjs/mealplan.js b/public/viewjs/mealplan.js index bb78a02c..327bcd61 100644 --- a/public/viewjs/mealplan.js +++ b/public/viewjs/mealplan.js @@ -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);