Skip to content

Commit

Permalink
lifecycletrigger_categories: Don't fail if category doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
justusdieckmann committed Feb 21, 2024
1 parent a0e676f commit 2b54804
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 5 additions & 4 deletions classes/local/backup/restore_lifecycle_workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion trigger/categories/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 2b54804

Please sign in to comment.