From 2b548044ac8106bf871b657511e54feaa34de067 Mon Sep 17 00:00:00 2001 From: Justus Dieckmann Date: Wed, 21 Feb 2024 12:34:28 +0100 Subject: [PATCH] lifecycletrigger_categories: Don't fail if category doesn't exist --- classes/local/backup/restore_lifecycle_workflow.php | 9 +++++---- trigger/categories/lib.php | 5 ++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/classes/local/backup/restore_lifecycle_workflow.php b/classes/local/backup/restore_lifecycle_workflow.php index ceb22fe8..5a74df3d 100644 --- a/classes/local/backup/restore_lifecycle_workflow.php +++ b/classes/local/backup/restore_lifecycle_workflow.php @@ -77,11 +77,13 @@ public function execute() { // If the workflow could be loaded continue with the subplugins. if ($this->workflow) { $this->load_subplugins(); - $this->check_subplugin_validity(); // Validate the subplugin data. if (empty($this->errors) && $this->all_subplugins_installed()) { - // If all loaded data is valid, the new workflow and the steps can be stored in the database. - $this->persist(); + $this->check_subplugin_validity(); + if (empty($this->errors)) { + // If all loaded data is valid, the new workflow and the steps can be stored in the database. + $this->persist(); + } } } return $this->errors; @@ -103,7 +105,6 @@ private function load_workflow() { $this->workflow->timeactive = null; $this->workflow->timedeactive = null; $this->workflow->sortindex = null; - workflow_manager::insert_or_update($this->workflow); } /** diff --git a/trigger/categories/lib.php b/trigger/categories/lib.php index 97ed716f..7ca38d58 100644 --- a/trigger/categories/lib.php +++ b/trigger/categories/lib.php @@ -76,6 +76,9 @@ public function get_course_recordset_where($triggerid) { $allcategories = []; foreach ($categories as $category) { array_push($allcategories, $category); + if (!isset($categoryobjects[$category]) || !$categoryobjects[$category]) { + continue; + } $children = $categoryobjects[$category]->get_all_children_ids(); $allcategories = array_merge($allcategories, $children); } @@ -139,7 +142,7 @@ public function ensure_validity(array $settings): array { // Use core_course_category for moodle 3.6 and higher. $categoryobjects = \core_course_category::get_many($categories); foreach ($categories as $category) { - if (!isset($categoryobjects[$category])) { + if (!isset($categoryobjects[$category]) || !$categoryobjects[$category]) { $errors[] = get_string('category_does_not_exist', 'lifecycletrigger_categories', $category); } }