MDL-46455 restore: added restore support for 'other' in events
This commit is contained in:
@@ -105,8 +105,32 @@ abstract class restore_tool_log_logstore_subplugin extends restore_subplugin {
|
||||
}
|
||||
}
|
||||
if (!empty($data->other)) {
|
||||
// TODO: Call to the resolver.
|
||||
return;
|
||||
// Check if there is an available class for this event we can use to map this value.
|
||||
$eventclass = $data->eventname;
|
||||
if (class_exists($eventclass)) {
|
||||
$othermapping = $eventclass::get_other_mapping();
|
||||
if ($othermapping) {
|
||||
// Go through the data we have.
|
||||
foreach ($data->other as $key => $value) {
|
||||
// Check if there is a corresponding key we can use to map to.
|
||||
if (isset($othermapping[$key])) {
|
||||
// Ok, let's map this.
|
||||
$mapping = $othermapping[$key];
|
||||
// Check if it can not be mapped.
|
||||
if ((is_int($mapping) && $mapping === \core\event\base::NOT_MAPPED) ||
|
||||
($mapping['restore'] === \core\event\base::NOT_MAPPED)) {
|
||||
$data->other[$key] = \core\event\base::NOT_MAPPED;
|
||||
} else {
|
||||
$data->other[$key] = $this->get_mappingid($mapping['restore'], $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Now we want to serialize it so we can store it in the DB.
|
||||
$data->other = serialize($data->other);
|
||||
} else {
|
||||
return; // No such class, can not restore.
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
@@ -517,6 +517,45 @@ abstract class base implements \IteratorAggregate {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used when restoring course logs where it is required that we
|
||||
* map the information in 'other' to it's new value in the new course.
|
||||
*
|
||||
* Does nothing in the base class except display a debugging message warning
|
||||
* the user that the event does not contain the required functionality to
|
||||
* map this information. For events that do not store any other information this
|
||||
* won't be called, so no debugging message will be displayed.
|
||||
*
|
||||
* Example of usage:
|
||||
*
|
||||
* $othermapped = array();
|
||||
* $othermapped['discussionid'] = array('db' => 'forum_discussions', 'restore' => 'forum_discussion');
|
||||
* $othermapped['forumid'] = array('db' => 'forum', 'restore' => 'forum');
|
||||
* return $othermapped;
|
||||
*
|
||||
* If an id can not be mapped during restore we set it to \core\event\base::NOT_MAPPED, example -
|
||||
*
|
||||
* $othermapped = array();
|
||||
* $othermapped['someid'] = array('db' => 'some_table', 'restore' => \core\event\base::NOT_MAPPED);
|
||||
* return $othermapped;
|
||||
*
|
||||
* Note - it isn't necessary to specify the 'db' and 'restore' values in this case, so you can also use -
|
||||
*
|
||||
* $othermapped = array();
|
||||
* $othermapped['someid'] = \core\event\base::NOT_MAPPED;
|
||||
* return $othermapped;
|
||||
*
|
||||
* The 'db' key refers to the database table and the 'restore' key refers to
|
||||
* the name of the restore element the other value is associated with. In many
|
||||
* cases these will be the same.
|
||||
*
|
||||
* @return array an array of other values and their corresponding mapping
|
||||
*/
|
||||
public static function get_other_mapping() {
|
||||
debugging('In order to restore course logs accurately the event must define the
|
||||
function get_other_mapping().', DEBUG_DEVELOPER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get static information about an event.
|
||||
* This is used in reports and is not for general use.
|
||||
|
||||
Reference in New Issue
Block a user