Skip to content

Commit

Permalink
Merge branch 'MDL-59909-master' of git://github.com/damyon/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Oct 26, 2017
2 parents 7f91fb0 + a66de3c commit 1fc6423
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
5 changes: 4 additions & 1 deletion completion/classes/api.php
Expand Up @@ -59,7 +59,10 @@ public static function update_completion_date_event($cmid, $modulename, $instanc
if (is_object($instanceorid)) {
$instance = $instanceorid;
} else {
$instance = $DB->get_record($modulename, array('id' => $instanceorid), '*', MUST_EXIST);
$instance = $DB->get_record($modulename, array('id' => $instanceorid), '*', IGNORE_MISSING);
}
if (!$instance) {
return false;
}
$course = get_course($instance->course);

Expand Down
7 changes: 7 additions & 0 deletions completion/tests/api_test.php
Expand Up @@ -72,6 +72,13 @@ public function test_update_completion_date_event() {
$this->assertEquals(\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED, $event->eventtype);
$this->assertEquals($time, $event->timestart);
$this->assertEquals($time, $event->timesort);

require_once($CFG->dirroot . '/course/lib.php');
// Delete the module.
course_delete_module($assign->cmid);

// Check we don't get a failure when called on a deleted module.
\core_completion\api::update_completion_date_event($assign->cmid, 'assign', null, $time);
}

public function test_update_completion_date_event_update() {
Expand Down
9 changes: 6 additions & 3 deletions course/lib.php
Expand Up @@ -1404,7 +1404,9 @@ function course_module_update_calendar_events($modulename, $instance = null, $cm
if (!isset($cm)) {
$cm = get_coursemodule_from_instance($modulename, $instance->id, $instance->course);
}
course_module_calendar_event_update_process($instance, $cm);
if (!empty($cm)) {
course_module_calendar_event_update_process($instance, $cm);
}
return true;
}
return false;
Expand Down Expand Up @@ -1433,8 +1435,9 @@ function course_module_bulk_update_calendar_events($modulename, $courseid = 0) {
}

foreach ($instances as $instance) {
$cm = get_coursemodule_from_instance($modulename, $instance->id, $instance->course);
course_module_calendar_event_update_process($instance, $cm);
if ($cm = get_coursemodule_from_instance($modulename, $instance->id, $instance->course)) {
course_module_calendar_event_update_process($instance, $cm);
}
}
return true;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/classes/task/refresh_mod_calendar_events_task.php
Expand Up @@ -44,6 +44,10 @@ class refresh_mod_calendar_events_task extends adhoc_task {
* Run the task to refresh calendar events.
*/
public function execute() {
global $CFG;

require_once($CFG->dirroot . '/course/lib.php');

// Specific list of plugins that need to be refreshed. If not set, then all mod plugins will be refreshed.
$pluginstorefresh = null;
if (isset($this->get_custom_data()->plugins)) {
Expand Down

0 comments on commit 1fc6423

Please sign in to comment.