From 8c24c0e489ef95d81d3247f5450a2268992371c7 Mon Sep 17 00:00:00 2001 From: Dave Miller Date: Fri, 23 Aug 2024 08:07:05 +0100 Subject: [PATCH] Fix 'Invalid database query parameter value' exception when restoring course with 'Any cohort' restriction (#17) --- CHANGES.md | 4 ++++ classes/condition.php | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 8d2e71e..c894c9c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,10 @@ moodle-availability_cohort Changes ------- +### Unreleased + +* 2024-08-23 - Bugfix: Fix 'Invalid database query parameter value' exception when restoring course with 'Any cohort' restriction, thanks to mi-dave. + ### v4.3-r2 * 2024-08-11 - Add section for scheduled tasks to README diff --git a/classes/condition.php b/classes/condition.php index 031984c..0b370a6 100644 --- a/classes/condition.php +++ b/classes/condition.php @@ -212,7 +212,7 @@ public function include_after_restore($restoreid, $courseid, \base_logger $logge if ($DB->record_exists('cohort', ['id' => $this->cohortid]) && cohort_get_cohort($this->cohortid, \context_course::instance($courseid))) { $returnvalue = true; - } else if ($this->cohortid == 0 && !empty(cohort_get_cohorts(\context_course::instance($courseid)))) { + } else if ($this->cohortid == 0 && !empty(cohort_get_cohorts(\context_course::instance($courseid)->id))) { // The setting was set to any cohort and cohorts have not been deleted in the meantime. // Import the activity with the condition. $returnvalue = true; @@ -223,7 +223,7 @@ public function include_after_restore($restoreid, $courseid, \base_logger $logge } else { // We are not on the same instance. // We have to check if the setting was set to any cohort and cohorts exist on the new instance. - if ($this->cohortid == 0 && !empty(cohort_get_cohorts(\context_course::instance($courseid)))) { + if ($this->cohortid == 0 && !empty(cohort_get_cohorts(\context_course::instance($courseid)->id))) { $returnvalue = true; } else { // Availability was not set to any cohort, so do not include.