Fixed lost context bug
This commit is contained in:
parent
4ca2c875ef
commit
32bab2de5e
|
@ -110,7 +110,7 @@ class contextinfo {
|
||||||
* @param int $contextid Context id
|
* @param int $contextid Context id
|
||||||
* @return context The context
|
* @return context The context
|
||||||
*/
|
*/
|
||||||
private static function context_by_id($contextid): \context {
|
public static function context_by_id($contextid): \context {
|
||||||
if ($contextid <= 1) {
|
if ($contextid <= 1) {
|
||||||
$contextid = 1;
|
$contextid = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,13 +192,18 @@ class studyplan {
|
||||||
* @return \context
|
* @return \context
|
||||||
*/
|
*/
|
||||||
public function context(): \context {
|
public function context(): \context {
|
||||||
|
global $DB;
|
||||||
if (!isset($this->context)) {
|
if (!isset($this->context)) {
|
||||||
try {
|
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) {
|
} catch (\dml_missing_record_exception $x) {
|
||||||
// Just throw it up again. catch is included here to make sure we know it throws this exception.
|
/* The associated context cannot be found.
|
||||||
throw new \InvalidArgumentException(
|
Probably the category was removed, but the studyplan was not.
|
||||||
"Context {$this->r->context_id} not available");
|
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;
|
return $this->context;
|
||||||
|
|
|
@ -557,7 +557,7 @@ $functions = [
|
||||||
'loginrequired' => true,
|
'loginrequired' => true,
|
||||||
],
|
],
|
||||||
'local_treestudyplan_bulk_course_timing' => [ // Web service function name.
|
'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.
|
'methodname' => 'bulk_course_timing', // External function name.
|
||||||
'description' => 'Change course start/end dates to match that of the studyplan period',
|
'description' => 'Change course start/end dates to match that of the studyplan period',
|
||||||
'type' => 'write', // Database rights of the web service function (read, write).
|
'type' => 'write', // Database rights of the web service function (read, write).
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
$plugin->component = 'local_treestudyplan'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494).
|
$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->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11).
|
||||||
|
|
||||||
$plugin->release = "1.1.0";
|
$plugin->release = "1.1.0";
|
||||||
|
|
Loading…
Reference in New Issue
Block a user