Skip to content

Commit

Permalink
MDL-58906 restore: Call action event refresh task during restore
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitagarwal committed Jul 24, 2017
1 parent 229ae61 commit a4af31d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
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
19 changes: 19 additions & 0 deletions backup/moodle2/restore_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -5553,3 +5553,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);
}
}
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 a4af31d

Please sign in to comment.