diff --git a/classes/contextinfo.php b/classes/contextinfo.php index 4f40b67..b15a989 100644 --- a/classes/contextinfo.php +++ b/classes/contextinfo.php @@ -110,7 +110,7 @@ class contextinfo { * @param int $contextid Context id * @return context The context */ - private static function context_by_id($contextid): \context { + public static function context_by_id($contextid): \context { if ($contextid <= 1) { $contextid = 1; } diff --git a/classes/studyplan.php b/classes/studyplan.php index a12e8f9..dbc3405 100644 --- a/classes/studyplan.php +++ b/classes/studyplan.php @@ -192,13 +192,18 @@ class studyplan { * @return \context */ public function context(): \context { + global $DB; if (!isset($this->context)) { try { - $this->context = contextinfo::by_id($this->r->context_id)->context; + $this->context = contextinfo::context_by_id($this->r->context_id); } catch (\dml_missing_record_exception $x) { - // Just throw it up again. catch is included here to make sure we know it throws this exception. - throw new \InvalidArgumentException( - "Context {$this->r->context_id} not available"); + /* The associated context cannot be found. + Probably the category was removed, but the studyplan was not. + Revert the studyplan back to the system context to avoid lost studyplans. + */ + $this->context = \context_system::instance(); + $this->r->context_id = $this->context->id; + $DB->update_record(self::TABLE, $this->r); } } return $this->context; diff --git a/db/services.php b/db/services.php index cf78b79..8d8748b 100644 --- a/db/services.php +++ b/db/services.php @@ -557,7 +557,7 @@ $functions = [ 'loginrequired' => true, ], 'local_treestudyplan_bulk_course_timing' => [ // Web service function name. - 'classname' => '\local_treestudyplan\utilityservice', // Class containing the external function. + 'classname' => '\local_treestudyplan\studyplanservice', // Class containing the external function. 'methodname' => 'bulk_course_timing', // External function name. 'description' => 'Change course start/end dates to match that of the studyplan period', 'type' => 'write', // Database rights of the web service function (read, write). diff --git a/version.php b/version.php index db0ffd6..9a0ceb1 100644 --- a/version.php +++ b/version.php @@ -22,7 +22,7 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'local_treestudyplan'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494). -$plugin->version = 2023121302; // YYYYMMDDHH (year, month, day, iteration). +$plugin->version = 2023121304; // YYYYMMDDHH (year, month, day, iteration). $plugin->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11). $plugin->release = "1.1.0";