Permalink
Browse files

Merge branch 'MDL-58906-33' of git://github.com/ankitagarwal/moodle i…

…nto MOODLE_33_STABLE
  • Loading branch information...
dmonllao committed Jul 24, 2017
2 parents b82734e + 1839865 commit d413b817e8512540014ea20a4550e9aa2389524d
@@ -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));
}
@@ -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'));
@@ -2653,6 +2653,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;
@@ -5532,3 +5539,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);
}
}
@@ -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
*/
@@ -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) {
@@ -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);
}
}
}

0 comments on commit d413b81

Please sign in to comment.