Skip to content

Commit

Permalink
Merge branch 'MDL-58906-master' of git://github.com/ankitagarwal/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonllao committed Jul 24, 2017
2 parents 13b7c4f + 65f15cd commit 53565d4
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
13 changes: 11 additions & 2 deletions backup/moodle2/backup_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -878,13 +878,22 @@ protected function define_structure() {
$calendar_items_params = array('courseid'=>backup::VAR_COURSEID);
$event->set_source_sql($calendar_items_sql, $calendar_items_params);
} else if ($this->name == 'activity_calendar') {
$params = array('instance' => backup::VAR_ACTIVITYID, 'modulename' => backup::VAR_MODNAME);
// We don't backup action events.
$params = array('instance' => backup::VAR_ACTIVITYID, 'modulename' => backup::VAR_MODNAME,
'type' => array('sqlparam' => CALENDAR_EVENT_TYPE_ACTION));
// If we don't want to include the userinfo in the backup then setting the courseid
// will filter out all of the user override events (which have a course id of zero).
$coursewhere = "";
if (!$this->get_setting_value('userinfo')) {
$params['courseid'] = backup::VAR_COURSEID;
$coursewhere = " AND courseid = :courseid";
}
$event->set_source_table('event', $params);
$calendarsql = "SELECT * FROM {event}
WHERE instance = :instance
AND type <> :type
AND modulename = :modulename";
$calendarsql = $calendarsql . $coursewhere;
$event->set_source_sql($calendarsql, $params);
} else {
$event->set_source_table('event', array('courseid' => backup::VAR_COURSEID, 'instance' => backup::VAR_ACTIVITYID, 'modulename' => backup::VAR_MODNAME));
}
Expand Down
5 changes: 5 additions & 0 deletions backup/moodle2/restore_final_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ public function build() {
// during backup/restore.
$this->add_step(new restore_update_availability('update_availability'));

// Refresh action events conditionally.
if ($this->get_setting_value('activities')) {
$this->add_step(new restore_calendar_action_events('restoring_action_events'));
}

// Decode all the interlinks
$this->add_step(new restore_decode_interlinks('decode_interlinks'));

Expand Down
26 changes: 26 additions & 0 deletions backup/moodle2/restore_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2659,6 +2659,13 @@ public function process_calendarevents($data) {
$data = (object)$data;
$oldid = $data->id;
$restorefiles = true; // We'll restore the files

// If this is a new action event, it will automatically be populated by the adhoc task.
// Nothing to do here.
if (isset($data->type) && $data->type == CALENDAR_EVENT_TYPE_ACTION) {
return;
}

// User overrides for activities are identified by having a courseid of zero with
// both a modulename and instance value set.
$isuseroverride = !$data->courseid && $data->modulename && $data->instance;
Expand Down Expand Up @@ -5553,3 +5560,22 @@ protected function process_completion_defaults($data) {
$this->set_mapping('course_completion_defaults', $oldid, $newid);
}
}
/**
* Restore action events.
*
* @package core_backup
* @copyright 2017 onwards Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restore_calendar_action_events extends restore_execution_step {
/**
* What to do when this step is executed.
*/
protected function define_execution() {
// We just queue the task here rather trying to recreate everything manually.
// The task will automatically populate all data.
$task = new \core\task\refresh_mod_calendar_events_task();
$task->set_custom_data(array('courseid' => $this->get_courseid()));
\core\task\manager::queue_adhoc_task($task);
}
}
2 changes: 1 addition & 1 deletion completion/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class api {
*
* @param int $cmid The course module id
* @param string $modulename The name of the module (eg. assign, quiz)
* @param stdClass|int $instanceorid The instance object or ID.
* @param \stdClass|int $instanceorid The instance object or ID.
* @param int|null $completionexpectedtime The time completion is expected, null if not set
* @return bool
*/
Expand Down
9 changes: 8 additions & 1 deletion lib/classes/task/refresh_mod_calendar_events_task.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public function execute() {
$pluginstorefresh = $this->get_custom_data()->plugins;
}

// Is course id set?
if (isset($this->get_custom_data()->courseid)) {
$courseid = $this->get_custom_data()->courseid;
} else {
$courseid = 0;
}

$pluginmanager = core_plugin_manager::instance();
$modplugins = $pluginmanager->get_plugins_of_type('mod');
foreach ($modplugins as $plugin) {
Expand All @@ -61,7 +68,7 @@ public function execute() {
// Check if the plugin implements *_refresh_events() and call it when it does.
if (component_callback_exists('mod_' . $plugin->name, 'refresh_events')) {
mtrace('Refreshing events for ' . $plugin->name);
component_callback('mod_' . $plugin->name, 'refresh_events');
course_module_bulk_update_calendar_events($plugin->name, $courseid);
}
}
}
Expand Down

0 comments on commit 53565d4

Please sign in to comment.