diff --git a/admin/tool/langimport/classes/event/langpack_imported.php b/admin/tool/langimport/classes/event/langpack_imported.php index 59679296e2e..4dbedace40f 100644 --- a/admin/tool/langimport/classes/event/langpack_imported.php +++ b/admin/tool/langimport/classes/event/langpack_imported.php @@ -112,4 +112,9 @@ class langpack_imported extends \core\event\base { throw new \coding_exception('The \'langcode\' value must be set to a valid language code'); } } + + public static function get_other_mapping() { + // No mapping required for this event because this event is not backed up. + return false; + } } diff --git a/admin/tool/langimport/classes/event/langpack_removed.php b/admin/tool/langimport/classes/event/langpack_removed.php index e528da4afd5..772c1ca87e3 100644 --- a/admin/tool/langimport/classes/event/langpack_removed.php +++ b/admin/tool/langimport/classes/event/langpack_removed.php @@ -113,4 +113,9 @@ class langpack_removed extends \core\event\base { throw new \coding_exception('The \'langcode\' value must be set to a valid language code'); } } + + public static function get_other_mapping() { + // No mapping required for this event because this event is not backed up. + return false; + } } diff --git a/admin/tool/langimport/classes/event/langpack_updated.php b/admin/tool/langimport/classes/event/langpack_updated.php index b9d026aa9ee..c44e8fb18b3 100644 --- a/admin/tool/langimport/classes/event/langpack_updated.php +++ b/admin/tool/langimport/classes/event/langpack_updated.php @@ -112,4 +112,9 @@ class langpack_updated extends \core\event\base { throw new \coding_exception('The \'langcode\' value must be set to a valid language code'); } } + + public static function get_other_mapping() { + // No mapping required for this event because this event is not backed up. + return false; + } } diff --git a/admin/tool/log/backup/moodle2/backup_tool_log_logstore_subplugin.class.php b/admin/tool/log/backup/moodle2/backup_tool_log_logstore_subplugin.class.php new file mode 100644 index 00000000000..b86e92aca0e --- /dev/null +++ b/admin/tool/log/backup/moodle2/backup_tool_log_logstore_subplugin.class.php @@ -0,0 +1,37 @@ +. + +/** + * Backup support for tool_log logstore subplugins. + * + * @package tool_log + * @category backup + * @copyright 2015 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * Parent class of all the logstore subplugin implementations. + * + * Note: While this intermediate class is not strictly required and all the + * subplugin implementations can extend directly {@link backup_subplugin}, + * it is always recommended to have it, both for better testing and also + * for sharing code between all subplugins. + */ +abstract class backup_tool_log_logstore_subplugin extends backup_subplugin { +} diff --git a/admin/tool/log/backup/moodle2/restore_tool_log_logstore_subplugin.class.php b/admin/tool/log/backup/moodle2/restore_tool_log_logstore_subplugin.class.php new file mode 100644 index 00000000000..7901ef02f06 --- /dev/null +++ b/admin/tool/log/backup/moodle2/restore_tool_log_logstore_subplugin.class.php @@ -0,0 +1,150 @@ +. + +/** + * Restore support for tool_log logstore subplugins. + * + * @package tool_log + * @category backup + * @copyright 2015 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * Parent class of all the logstore subplugin implementations. + * + * Note: While this intermediate class is not strictly required and all the + * subplugin implementations can extend directly {@link restore_subplugin}, + * it is always recommended to have it, both for better testing and also + * for sharing code between all subplugins. + */ +abstract class restore_tool_log_logstore_subplugin extends restore_subplugin { + + /** + * Process log entries. + * + * This method proceeds to read, complete, remap and, finally, + * discard or save every log entry. + * + * @param array $data log entry. + * @return object|null $dataobject A data object with values for one or more fields in the record, + * or null if we are not going to process the log. + */ + protected function process_log($data) { + $data = (object) $data; + + // Complete the information that does not come from backup. + $contextid = $data->contextid; + if (!$data->contextid = $this->get_mappingid('context', $contextid)) { + $message = "Context id \"$contextid\" could not be mapped. Skipping log record."; + $this->log($message, backup::LOG_DEBUG); + return; + } + $context = context::instance_by_id($data->contextid, MUST_EXIST); + $data->contextlevel = $context->contextlevel; + $data->contextinstanceid = $context->instanceid; + $data->courseid = $this->task->get_courseid(); + + // Remap users. + $userid = $data->userid; + if (!$data->userid = $this->get_mappingid('user', $userid)) { + $message = "User id \"$userid\" could not be mapped. Skipping log record."; + $this->log($message, backup::LOG_DEBUG); + return; + } + if (!empty($data->relateduserid)) { // This is optional. + $relateduserid = $data->relateduserid; + if (!$data->relateduserid = $this->get_mappingid('user', $relateduserid)) { + $message = "Related user id \"$relateduserid\" could not be mapped. Skipping log record."; + $this->log($message, backup::LOG_DEBUG); + return; + } + } + if (!empty($data->realuserid)) { // This is optional. + $realuserid = $data->realuserid; + if (!$data->realuserid = $this->get_mappingid('user', $realuserid)) { + $message = "Real user id \"$realuserid\" could not be mapped. Skipping log record."; + $this->log($message, backup::LOG_DEBUG); + return; + } + } + + // Roll dates. + $data->timecreated = $this->apply_date_offset($data->timecreated); + + // Revert other to its original php way. + $data->other = unserialize(base64_decode($data->other)); + + // Arrived here, we have both 'objectid' and 'other' to be converted. This is the tricky part. + // Both are pointing to other records id, but the sources are not identified in the + // same way restore mappings work. So we need to delegate them to some resolver that + // will give us the correct restore mapping to be used. + if (!empty($data->objectid)) { + // Check if there is an available class for this event we can use to map this value. + $eventclass = $data->eventname; + if (class_exists($eventclass)) { + $mapping = $eventclass::get_objectid_mapping(); + if ($mapping) { + // 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->objectid = \core\event\base::NOT_MAPPED; + } else { + $data->objectid = $this->get_mappingid($mapping['restore'], $data->objectid); + } + } + } else { + $message = "Event class not found: \"$eventclass\". Skipping log record."; + $this->log($message, backup::LOG_DEBUG); + return; // No such class, can not restore. + } + } + if (!empty($data->other)) { + // 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]) && !empty($value)) { + // 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 { + $message = "Event class not found: \"$eventclass\". Skipping log record."; + $this->log($message, backup::LOG_DEBUG); + return; // No such class, can not restore. + } + } + + return $data; + } +} diff --git a/admin/tool/log/store/database/backup/moodle2/backup_logstore_database_nested_element.php b/admin/tool/log/store/database/backup/moodle2/backup_logstore_database_nested_element.php new file mode 100644 index 00000000000..cbcbad3175c --- /dev/null +++ b/admin/tool/log/store/database/backup/moodle2/backup_logstore_database_nested_element.php @@ -0,0 +1,98 @@ +. + +/** + * Backup implementation for the (tool_log) logstore_database nested element. + * + * @package logstore_database + * @category backup + * @copyright 2015 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * Custom subclass of backup_nested_element that iterates over an external DB connection. + * + * @package logstore_database + * @category backup + * @copyright 2015 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class backup_logstore_database_nested_element extends backup_nested_element { + + /** + * @var \moodle_database $sourcedb + */ + protected $sourcedb; + + /** + * Constructor - instantiates one backup_nested_element, specifying its basic info. + * + * @param string $name name of the element + * @param array $attributes attributes this element will handle (optional, defaults to null) + * @param array $finalelements this element will handle (optional, defaults to null) + */ + public function __construct($name, $attributes = null, $finalelements = null) { + global $DB; + + parent::__construct($name, $attributes, $finalelements); + $this->sourcedb = $DB; + } + + /** + * For sql or table datasources, this will iterate over the "external" DB connection + * stored in this class instead of the default $DB. All other cases use the parent default. + * @param object $processor the processor + */ + protected function get_iterator($processor) { + if ($this->get_source_table() !== null) { // It's one table, return recordset iterator. + return $this->get_source_db()->get_recordset( + $this->get_source_table(), + backup_structure_dbops::convert_params_to_values($this->procparams, $processor), + $this->get_source_table_sortby() + ); + + } else if ($this->get_source_sql() !== null) { // It's one sql, return recordset iterator. + return $this->get_source_db()->get_recordset_sql( + $this->get_source_sql(), + backup_structure_dbops::convert_params_to_values($this->procparams, $processor) + ); + } + + return parent::get_iterator($processor); + } + + /** + * Set the database we want to use. + * + * @param \moodle_database $db + */ + public function set_source_db($db) { + $this->sourcedb = $db; + } + + /** + * Get the database we want to use. + * + * @return \moodle_database $db + */ + public function get_source_db() { + return $this->sourcedb; + } + +} diff --git a/admin/tool/log/store/database/backup/moodle2/backup_logstore_database_subplugin.class.php b/admin/tool/log/store/database/backup/moodle2/backup_logstore_database_subplugin.class.php new file mode 100644 index 00000000000..0642078b08b --- /dev/null +++ b/admin/tool/log/store/database/backup/moodle2/backup_logstore_database_subplugin.class.php @@ -0,0 +1,65 @@ +. + +/** + * Backup implementation for the (tool_log) logstore_database subplugin. + * + * @package logstore_database + * @category backup + * @copyright 2015 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); +require_once('backup_logstore_database_nested_element.php'); + +class backup_logstore_database_subplugin extends backup_tool_log_logstore_subplugin { + + /** + * Returns the subplugin structure to attach to the 'logstore' XML element. + * + * @return backup_subplugin_element the subplugin structure to be attached. + */ + protected function define_logstore_subplugin_structure() { + $subplugin = $this->get_subplugin_element(); + $subpluginwrapper = new backup_nested_element($this->get_recommended_name()); + + // Create the custom (base64 encoded, xml safe) 'other' final element. + $otherelement = new base64_encode_final_element('other'); + + $subpluginlog = new backup_logstore_database_nested_element('logstore_database_log', array('id'), array( + 'eventname', 'component', 'action', 'target', 'objecttable', + 'objectid', 'crud', 'edulevel', 'contextid', 'userid', 'relateduserid', + 'anonymous', $otherelement, 'timecreated', 'ip', 'realuserid')); + + $subplugin->add_child($subpluginwrapper); + $subpluginwrapper->add_child($subpluginlog); + + // Get the details for the external database. + $manager = new \tool_log\log\manager(); + $store = new \logstore_database\log\store($manager); + $extdb = $store->get_extdb(); + + if (!$extdb) { + return false; + } + + $subpluginlog->set_source_db($extdb); + $subpluginlog->set_source_table($store->get_config_value('dbtable'), array('contextid' => backup::VAR_CONTEXTID)); + + return $subplugin; + } +} diff --git a/admin/tool/log/store/database/backup/moodle2/restore_logstore_database_subplugin.class.php b/admin/tool/log/store/database/backup/moodle2/restore_logstore_database_subplugin.class.php new file mode 100644 index 00000000000..9eca1bb813d --- /dev/null +++ b/admin/tool/log/store/database/backup/moodle2/restore_logstore_database_subplugin.class.php @@ -0,0 +1,102 @@ +. + +/** + * Restore implementation for the (tool_log) logstore_database subplugin. + * + * @package logstore_database + * @category backup + * @copyright 2015 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +class restore_logstore_database_subplugin extends restore_tool_log_logstore_subplugin { + + /** + * @var moodle_database the external database. + */ + private static $extdb = null; + + /** + * @var string the external database table name. + */ + private static $extdbtablename = null; + + /** + * The constructor for this logstore. + * + * @param string $subplugintype the subplugin type. + * @param string $subpluginname the subplugin name. + * @param restore_structure_step $step. + */ + public function __construct($subplugintype, $subpluginname, $step) { + // Check that the logstore is enabled before setting variables. + $enabledlogstores = explode(',', get_config('tool_log', 'enabled_stores')); + if (in_array('logstore_database', $enabledlogstores)) { + $manager = new \tool_log\log\manager(); + $store = new \logstore_database\log\store($manager); + self::$extdb = $store->get_extdb(); + self::$extdbtablename = $store->get_config_value('dbtable'); + } + + parent::__construct($subplugintype, $subpluginname, $step); + } + + /** + * Returns the subplugin structure to attach to the 'logstore' XML element. + * + * @return restore_path_element[] array of elements to be processed on restore. + */ + protected function define_logstore_subplugin_structure() { + // If the logstore is not enabled we don't add structures for it. + $enabledlogstores = explode(',', get_config('tool_log', 'enabled_stores')); + if (!in_array('logstore_database', $enabledlogstores)) { + return array(); // The logstore is not enabled, nothing to restore. + } + + $paths = array(); + + $elename = $this->get_namefor('log'); + $elepath = $this->get_pathfor('/logstore_database_log'); + $paths[] = new restore_path_element($elename, $elepath); + + return $paths; + } + + /** + * Process logstore_database_log entries. + * + * This method proceeds to read, complete, remap and, finally, + * discard or save every log entry. + * + * @param array() $data log entry. + * @return null if we are not restoring the log. + */ + public function process_logstore_database_log($data) { + // Do not bother processing if we can not add it to a database. + if (!self::$extdb || !self::$extdbtablename) { + return; + } + + $data = $this->process_log($data); + + if ($data) { + self::$extdb->insert_record(self::$extdbtablename, $data); + } + } +} diff --git a/admin/tool/log/store/database/classes/log/store.php b/admin/tool/log/store/database/classes/log/store.php index 0bbffb2950f..cddf3f99c4a 100644 --- a/admin/tool/log/store/database/classes/log/store.php +++ b/admin/tool/log/store/database/classes/log/store.php @@ -258,6 +258,30 @@ class store implements \tool_log\log\writer, \core\log\sql_reader { return $this->extdb->count_records_select($dbtable, $selectwhere, $params); } + /** + * Get a config value for the store. + * + * @param string $name Config name + * @param mixed $default default value + * @return mixed config value if set, else the default value. + */ + public function get_config_value($name, $default = null) { + return $this->get_config($name, $default); + } + + /** + * Get the external database object. + * + * @return \moodle_database $extdb + */ + public function get_extdb() { + if (!$this->init()) { + return false; + } + + return $this->extdb; + } + /** * Are the new events appearing in the reader? * diff --git a/admin/tool/log/store/standard/backup/moodle2/backup_logstore_standard_subplugin.class.php b/admin/tool/log/store/standard/backup/moodle2/backup_logstore_standard_subplugin.class.php new file mode 100644 index 00000000000..32db1b8f7da --- /dev/null +++ b/admin/tool/log/store/standard/backup/moodle2/backup_logstore_standard_subplugin.class.php @@ -0,0 +1,55 @@ +. + +/** + * Backup implementation for the (tool_log) logstore_standard subplugin. + * + * @package logstore_standard + * @category backup + * @copyright 2015 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +class backup_logstore_standard_subplugin extends backup_tool_log_logstore_subplugin { + + /** + * Returns the subplugin structure to attach to the 'logstore' XML element. + * + * @return backup_subplugin_element the subplugin structure to be attached. + */ + protected function define_logstore_subplugin_structure() { + + $subplugin = $this->get_subplugin_element(); + $subpluginwrapper = new backup_nested_element($this->get_recommended_name()); + + // Create the custom (base64 encoded, xml safe) 'other' final element. + $otherelement = new base64_encode_final_element('other'); + + $subpluginlog = new backup_nested_element('logstore_standard_log', array('id'), array( + 'eventname', 'component', 'action', 'target', 'objecttable', + 'objectid', 'crud', 'edulevel', 'contextid', 'userid', 'relateduserid', + 'anonymous', $otherelement, 'timecreated', 'ip', 'realuserid')); + + $subplugin->add_child($subpluginwrapper); + $subpluginwrapper->add_child($subpluginlog); + + $subpluginlog->set_source_table('logstore_standard_log', array('contextid' => backup::VAR_CONTEXTID)); + + return $subplugin; + } +} diff --git a/admin/tool/log/store/standard/backup/moodle2/restore_logstore_standard_subplugin.class.php b/admin/tool/log/store/standard/backup/moodle2/restore_logstore_standard_subplugin.class.php new file mode 100644 index 00000000000..ac041e46de2 --- /dev/null +++ b/admin/tool/log/store/standard/backup/moodle2/restore_logstore_standard_subplugin.class.php @@ -0,0 +1,69 @@ +. + +/** + * Restore implementation for the (tool_log) logstore_standard subplugin. + * + * @package logstore_standard + * @category backup + * @copyright 2015 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +class restore_logstore_standard_subplugin extends restore_tool_log_logstore_subplugin { + + /** + * Returns the subplugin structure to attach to the 'logstore' XML element. + * + * @return restore_path_element[] array of elements to be processed on restore. + */ + protected function define_logstore_subplugin_structure() { + + // If the logstore is not enabled we don't add structures for it. + $enabledlogstores = explode(',', get_config('tool_log', 'enabled_stores')); + if (!in_array('logstore_standard', $enabledlogstores)) { + return array(); // The logstore is not enabled, nothing to restore. + } + + $paths = array(); + + $elename = $this->get_namefor('log'); + $elepath = $this->get_pathfor('/logstore_standard_log'); + $paths[] = new restore_path_element($elename, $elepath); + + return $paths; + } + + /** + * Process logstore_standard_log entries. + * + * This method proceeds to read, complete, remap and, finally, + * discard or save every log entry. + * + * @param array() $data log entry. + */ + public function process_logstore_standard_log($data) { + global $DB; + + $data = $this->process_log($data); + + if ($data) { + $DB->insert_record('logstore_standard_log', $data); + } + } +} diff --git a/admin/tool/monitor/classes/event/rule_created.php b/admin/tool/monitor/classes/event/rule_created.php index 178445b46a3..18ee2e974f6 100644 --- a/admin/tool/monitor/classes/event/rule_created.php +++ b/admin/tool/monitor/classes/event/rule_created.php @@ -74,4 +74,9 @@ class rule_created extends \core\event\base { return new \moodle_url('/admin/tool/monitor/edit.php', array('ruleid' => $this->objectid, 'courseid' => $this->courseid)); } + + public static function get_objectid_mapping() { + // No mapping required for this event because event monitor rules are not backed up. + return array('db' => 'tool_monitor_rules', 'restore' => \core\event\base::NOT_MAPPED); + } } diff --git a/admin/tool/monitor/classes/event/rule_deleted.php b/admin/tool/monitor/classes/event/rule_deleted.php index 50e2d5b6628..e085c6c6f65 100644 --- a/admin/tool/monitor/classes/event/rule_deleted.php +++ b/admin/tool/monitor/classes/event/rule_deleted.php @@ -73,4 +73,9 @@ class rule_deleted extends \core\event\base { public function get_url() { return new \moodle_url('/admin/tool/monitor/managerules.php', array('courseid' => $this->courseid)); } + + public static function get_objectid_mapping() { + // No mapping required for this event because event monitor rules are not backed up. + return array('db' => 'tool_monitor_rules', 'restore' => \core\event\base::NOT_MAPPED); + } } diff --git a/admin/tool/monitor/classes/event/rule_updated.php b/admin/tool/monitor/classes/event/rule_updated.php index 8b262c4f49d..a886a82a3b9 100644 --- a/admin/tool/monitor/classes/event/rule_updated.php +++ b/admin/tool/monitor/classes/event/rule_updated.php @@ -74,4 +74,9 @@ class rule_updated extends \core\event\base { return new \moodle_url('/admin/tool/monitor/edit.php', array('ruleid' => $this->objectid, 'courseid' => $this->courseid)); } + + public static function get_objectid_mapping() { + // No mapping required for this event because event monitor rules are not backed up. + return array('db' => 'tool_monitor_rules', 'restore' => \core\event\base::NOT_MAPPED); + } } diff --git a/admin/tool/monitor/classes/event/subscription_created.php b/admin/tool/monitor/classes/event/subscription_created.php index e3d2b818da0..6da8626106a 100644 --- a/admin/tool/monitor/classes/event/subscription_created.php +++ b/admin/tool/monitor/classes/event/subscription_created.php @@ -64,4 +64,9 @@ class subscription_created extends \core\event\base { public function get_description() { return "The user with id '$this->userid' created the event monitor subscription with id '$this->objectid'."; } + + public static function get_objectid_mapping() { + // No mapping required for this event because event monitor subscriptions are not backed up. + return array('db' => 'tool_monitor_subscriptions', 'restore' => \core\event\base::NOT_MAPPED); + } } diff --git a/admin/tool/monitor/classes/event/subscription_criteria_met.php b/admin/tool/monitor/classes/event/subscription_criteria_met.php index 693bcf4049f..aa64be7c95f 100644 --- a/admin/tool/monitor/classes/event/subscription_criteria_met.php +++ b/admin/tool/monitor/classes/event/subscription_criteria_met.php @@ -83,4 +83,9 @@ class subscription_criteria_met extends \core\event\base { throw new \coding_exception('The \'subscriptionid\' value must be set in other.'); } } + + public static function get_other_mapping() { + // No mapping required for this event because event monitor subscriptions are not backed up. + return false; + } } diff --git a/admin/tool/monitor/classes/event/subscription_deleted.php b/admin/tool/monitor/classes/event/subscription_deleted.php index e4b2bc0b422..84970b334ff 100644 --- a/admin/tool/monitor/classes/event/subscription_deleted.php +++ b/admin/tool/monitor/classes/event/subscription_deleted.php @@ -64,4 +64,9 @@ class subscription_deleted extends \core\event\base { public function get_description() { return "The user with id '$this->userid' deleted the event monitor subscription with id '$this->objectid'."; } + + public static function get_objectid_mapping() { + // No mapping required for this event because event monitor subscriptions are not backed up. + return array('db' => 'tool_monitor_subscriptions', 'restore' => \core\event\base::NOT_MAPPED); + } } diff --git a/backup/moodle2/backup_activity_task.class.php b/backup/moodle2/backup_activity_task.class.php index 8eac1691d29..5c47f36e4dd 100644 --- a/backup/moodle2/backup_activity_task.class.php +++ b/backup/moodle2/backup_activity_task.class.php @@ -166,7 +166,10 @@ abstract class backup_activity_task extends backup_task { // Generate the logs file (conditionally) if ($this->get_setting_value('logs')) { + // Legacy logs. $this->add_step(new backup_activity_logs_structure_step('activity_logs', 'logs.xml')); + // New log stores. + $this->add_step(new backup_activity_logstores_structure_step('activity_logstores', 'logstores.xml')); } // Generate the calendar events file (conditionally) diff --git a/backup/moodle2/backup_course_task.class.php b/backup/moodle2/backup_course_task.class.php index c7b64b4c287..7ac637cbebe 100644 --- a/backup/moodle2/backup_course_task.class.php +++ b/backup/moodle2/backup_course_task.class.php @@ -121,7 +121,10 @@ class backup_course_task extends backup_task { // Generate the logs file (conditionally) if ($this->get_setting_value('logs')) { + // Legacy logs. $this->add_step(new backup_course_logs_structure_step('course_logs', 'logs.xml')); + // New log stores. + $this->add_step(new backup_course_logstores_structure_step('course_logstores', 'logstores.xml')); } // Generate the inforef file (must be after ALL steps gathering annotations of ANY type) diff --git a/backup/moodle2/backup_custom_fields.php b/backup/moodle2/backup_custom_fields.php index b5c32a5e84b..b2170984735 100644 --- a/backup/moodle2/backup_custom_fields.php +++ b/backup/moodle2/backup_custom_fields.php @@ -78,6 +78,25 @@ class mnethosturl_final_element extends backup_final_element { } } +/** + * Implementation of {@link backup_final_element} that provides base64 encoding. + * + * This final element transparently encodes with base64_encode() contents that + * normally are not safe for being stored in utf-8 xml files (binaries, serialized + * data...). + */ +class base64_encode_final_element extends backup_final_element { + + /** + * Set the value for the final element, encoding it as utf-8/xml safe base64. + * + * @param string $value Original value coming from backup step source, usually db. + */ + public function set_value($value) { + parent::set_value(base64_encode($value)); + } +} + /** * Implementation of backup_nested_element that provides special handling of files * diff --git a/backup/moodle2/backup_stepslib.php b/backup/moodle2/backup_stepslib.php index 89c75341c1c..436f19f36dd 100644 --- a/backup/moodle2/backup_stepslib.php +++ b/backup/moodle2/backup_stepslib.php @@ -91,64 +91,10 @@ class create_taskbasepath_directory extends backup_execution_step { /** * Abstract structure step, parent of all the activity structure steps. Used to wrap the - * activity structure definition within the main tag. Also provides - * subplugin support for activities (that must be properly declared) + * activity structure definition within the main tag. */ abstract class backup_activity_structure_step extends backup_structure_step { - /** - * Add subplugin structure to any element in the activity backup tree - * - * @param string $subplugintype type of subplugin as defined in activity db/subplugins.php - * @param backup_nested_element $element element in the activity backup tree that - * we are going to add subplugin information to - * @param bool $multiple to define if multiple subplugins can produce information - * for each instance of $element (true) or no (false) - * @return void - */ - protected function add_subplugin_structure($subplugintype, $element, $multiple) { - - global $CFG; - - // Check the requested subplugintype is a valid one - $subpluginsfile = $CFG->dirroot . '/mod/' . $this->task->get_modulename() . '/db/subplugins.php'; - if (!file_exists($subpluginsfile)) { - throw new backup_step_exception('activity_missing_subplugins_php_file', $this->task->get_modulename()); - } - include($subpluginsfile); - if (!array_key_exists($subplugintype, $subplugins)) { - throw new backup_step_exception('incorrect_subplugin_type', $subplugintype); - } - - // Arrived here, subplugin is correct, let's create the optigroup - $optigroupname = $subplugintype . '_' . $element->get_name() . '_subplugin'; - $optigroup = new backup_optigroup($optigroupname, null, $multiple); - $element->add_child($optigroup); // Add optigroup to stay connected since beginning - - // Get all the optigroup_elements, looking across all the subplugin dirs - $subpluginsdirs = core_component::get_plugin_list($subplugintype); - foreach ($subpluginsdirs as $name => $subpluginsdir) { - $classname = 'backup_' . $subplugintype . '_' . $name . '_subplugin'; - $backupfile = $subpluginsdir . '/backup/moodle2/' . $classname . '.class.php'; - if (file_exists($backupfile)) { - require_once($backupfile); - $backupsubplugin = new $classname($subplugintype, $name, $optigroup, $this); - // Add subplugin returned structure to optigroup - $backupsubplugin->define_subplugin_structure($element->get_name()); - } - } - } - - /** - * As far as activity backup steps are implementing backup_subplugin stuff, they need to - * have the parent task available for wrapping purposes (get course/context....) - * - * @return backup_activity_task - */ - public function get_task() { - return $this->task; - } - /** * Wraps any activity backup structure within the common 'activity' element * that will include common to all activities information like id, context... @@ -1539,6 +1485,36 @@ class backup_activity_logs_structure_step extends backup_structure_step { } } +/** + * Structure step in charge of constructing the logstores.xml file for the course logs. + * + * This backup step will backup the logs for all the enabled logstore subplugins supporting + * it, for logs belonging to the course level. + */ +class backup_course_logstores_structure_step extends backup_structure_step { + + protected function define_structure() { + + // Define the structure of logstores container. + $logstores = new backup_nested_element('logstores'); + $logstore = new backup_nested_element('logstore'); + $logstores->add_child($logstore); + + // Add the tool_log logstore subplugins information to the logstore element. + $this->add_subplugin_structure('logstore', $logstore, true, 'tool', 'log'); + + return $logstores; + } +} + +/** + * Structure step in charge of constructing the logstores.xml file for the activity logs. + * + * Note: Activity structure is completely equivalent to the course one, so just extend it. + */ +class backup_activity_logstores_structure_step extends backup_course_logstores_structure_step { +} + /** * structure in charge of constructing the inforef.xml file for all the items we want * to have referenced there (users, roles, files...) diff --git a/backup/moodle2/restore_activity_task.class.php b/backup/moodle2/restore_activity_task.class.php index 24a045687cf..116c8e2e432 100644 --- a/backup/moodle2/restore_activity_task.class.php +++ b/backup/moodle2/restore_activity_task.class.php @@ -173,7 +173,10 @@ abstract class restore_activity_task extends restore_task { // Logs (conditionally) if ($this->get_setting_value('logs')) { + // Legacy logs. $this->add_step(new restore_activity_logs_structure_step('activity_logs', 'logs.xml')); + // New log stores. + $this->add_step(new restore_activity_logstores_structure_step('activity_logstores', 'logstores.xml')); } // At the end, mark it as built diff --git a/backup/moodle2/restore_final_task.class.php b/backup/moodle2/restore_final_task.class.php index 124208a48aa..ff0ec6f1956 100644 --- a/backup/moodle2/restore_final_task.class.php +++ b/backup/moodle2/restore_final_task.class.php @@ -82,9 +82,12 @@ class restore_final_task extends restore_task { $this->add_step(new restore_decode_interlinks('decode_interlinks')); // Restore course logs (conditionally). They are restored here because we need all - // the activities to be already restored + // the activities to be already restored. if ($this->get_setting_value('logs')) { + // Legacy logs. $this->add_step(new restore_course_logs_structure_step('course_logs', 'course/logs.xml')); + // New log stores. + $this->add_step(new restore_course_logstores_structure_step('course_logstores', 'course/logstores.xml')); } // Review all the executed tasks having one after_restore method diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index 587015dc2dd..a41292dffdf 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -2997,6 +2997,75 @@ class restore_activity_logs_structure_step extends restore_course_logs_structure } } +/** + * Structure step in charge of restoring the logstores.xml file for the course logs. + * + * This restore step will rebuild the logs for all the enabled logstore subplugins supporting + * it, for logs belonging to the course level. + */ +class restore_course_logstores_structure_step extends restore_structure_step { + + /** + * Conditionally decide if this step should be executed. + * + * This function checks the following parameter: + * + * 1. the logstores.xml file exists + * + * @return bool true is safe to execute, false otherwise + */ + protected function execute_condition() { + + // Check it is included in the backup. + $fullpath = $this->task->get_taskbasepath(); + $fullpath = rtrim($fullpath, '/') . '/' . $this->filename; + if (!file_exists($fullpath)) { + // Not found, can't restore logstores.xml information. + return false; + } + + return true; + } + + /** + * Return the elements to be processed on restore of logstores. + * + * @return restore_path_element[] array of elements to be processed on restore. + */ + protected function define_structure() { + + $paths = array(); + + $logstore = new restore_path_element('logstore', '/logstores/logstore'); + $paths[] = $logstore; + + // Add logstore subplugin support to the 'logstore' element. + $this->add_subplugin_structure('logstore', $logstore, 'tool', 'log'); + + return array($logstore); + } + + /** + * Process the 'logstore' element, + * + * Note: This is empty by definition in backup, because stores do not share any + * data between them, so there is nothing to process here. + * + * @param array $data element data + */ + protected function process_logstore($data) { + return; + } +} + +/** + * Structure step in charge of restoring the logstores.xml file for the activity logs. + * + * Note: Activity structure is completely equivalent to the course one, so just extend it. + */ +class restore_activity_logstores_structure_step extends restore_course_logstores_structure_step { +} + /** * Defines the restore step for advanced grading methods attached to the activity module @@ -3782,48 +3851,11 @@ class restore_userscompletion_structure_step extends restore_structure_step { } /** - * Abstract structure step, parent of all the activity structure steps. Used to suuport - * the main tag and process it. Also provides subplugin support for - * activities. + * Abstract structure step, parent of all the activity structure steps. Used to support + * the main tag and process it. */ abstract class restore_activity_structure_step extends restore_structure_step { - protected function add_subplugin_structure($subplugintype, $element) { - - global $CFG; - - // Check the requested subplugintype is a valid one - $subpluginsfile = $CFG->dirroot . '/mod/' . $this->task->get_modulename() . '/db/subplugins.php'; - if (!file_exists($subpluginsfile)) { - throw new restore_step_exception('activity_missing_subplugins_php_file', $this->task->get_modulename()); - } - include($subpluginsfile); - if (!array_key_exists($subplugintype, $subplugins)) { - throw new restore_step_exception('incorrect_subplugin_type', $subplugintype); - } - // Get all the restore path elements, looking across all the subplugin dirs - $subpluginsdirs = core_component::get_plugin_list($subplugintype); - foreach ($subpluginsdirs as $name => $subpluginsdir) { - $classname = 'restore_' . $subplugintype . '_' . $name . '_subplugin'; - $restorefile = $subpluginsdir . '/backup/moodle2/' . $classname . '.class.php'; - if (file_exists($restorefile)) { - require_once($restorefile); - $restoresubplugin = new $classname($subplugintype, $name, $this); - // Add subplugin paths to the step - $this->prepare_pathelements($restoresubplugin->define_subplugin_structure($element)); - } - } - } - - /** - * As far as activity restore steps are implementing restore_subplugin stuff, they need to - * have the parent task available for wrapping purposes (get course/context....) - * @return restore_task - */ - public function get_task() { - return $this->task; - } - /** * Adds support for the 'activity' path that is common to all the activities * and will be processed globally here diff --git a/backup/moodle2/restore_subplugin.class.php b/backup/moodle2/restore_subplugin.class.php index bf21779f4fe..640968b88af 100644 --- a/backup/moodle2/restore_subplugin.class.php +++ b/backup/moodle2/restore_subplugin.class.php @@ -159,6 +159,13 @@ abstract class restore_subplugin { return $this->step->apply_date_offset($value); } + /** + * Call the log function from the step. + */ + public function log($message, $level, $a = null, $depth = null, $display = false) { + return $this->step->log($message, $level, $a, $depth, $display); + } + /** * Returns the value of one (task/plan) setting */ diff --git a/backup/util/dbops/backup_structure_dbops.class.php b/backup/util/dbops/backup_structure_dbops.class.php index 4ceb221defc..8ffc63e2efd 100644 --- a/backup/util/dbops/backup_structure_dbops.class.php +++ b/backup/util/dbops/backup_structure_dbops.class.php @@ -34,10 +34,12 @@ abstract class backup_structure_dbops extends backup_dbops { public static function get_iterator($element, $params, $processor) { global $DB; + // Check we are going to get_iterator for one backup_nested_element if (! $element instanceof backup_nested_element) { throw new base_element_struct_exception('backup_nested_element_expected'); } + // If var_array, table and sql are null, and element has no final elements it is one nested element without source // Just return one 1 element iterator without information if ($element->get_source_array() === null && $element->get_source_table() === null && @@ -58,7 +60,7 @@ abstract class backup_structure_dbops extends backup_dbops { } } - protected static function convert_params_to_values($params, $processor) { + public static function convert_params_to_values($params, $processor) { $newparams = array(); foreach ($params as $key => $param) { $newvalue = null; diff --git a/backup/util/plan/backup_structure_step.class.php b/backup/util/plan/backup_structure_step.class.php index 5ff5d086637..5d8cb557573 100644 --- a/backup/util/plan/backup_structure_step.class.php +++ b/backup/util/plan/backup_structure_step.class.php @@ -162,6 +162,83 @@ abstract class backup_structure_step extends backup_step { } } + /** + * Add subplugin structure for a given plugin to any element in the structure backup tree. + * + * This method allows the injection of subplugins (of a specified plugin) data to any + * element in any backup structure. + * + * NOTE: Initially subplugins were only available for activities (mod), so only the + * {@link backup_activity_structure_step} class had support for them, always + * looking for /mod/modulenanme subplugins. This new method is a generalization of the + * existing one for activities, supporting all subplugins injecting information everywhere. + * + * @param string $subplugintype type of subplugin as defined in plugin's db/subplugins.php. + * @param backup_nested_element $element element in the backup tree (anywhere) that + * we are going to add subplugin information to. + * @param bool $multiple to define if multiple subplugins can produce information + * for each instance of $element (true) or no (false). + * @param string $plugintype type of the plugin. + * @param string $pluginname name of the plugin. + * @return void + */ + protected function add_subplugin_structure($subplugintype, $element, $multiple, $plugintype = null, $pluginname = null) { + + // Verify if this is a BC call for an activity backup. See NOTE above for this special case. + if ($plugintype === null and $pluginname === null) { + $plugintype = 'mod'; + $pluginname = $this->task->get_modulename(); + // TODO: Once all the calls have been changed to add both not null plugintype and pluginname, add a debugging here. + } + + // Check the requested plugintype is a valid one. + if (!array_key_exists($plugintype, core_component::get_plugin_types())) { + throw new backup_step_exception('incorrect_plugin_type', $plugintype); + } + + // Check the requested pluginname, for the specified plugintype, is a valid one. + if (!array_key_exists($pluginname, core_component::get_plugin_list($plugintype))) { + throw new backup_step_exception('incorrect_plugin_name', array($plugintype, $pluginname)); + } + + // Check the requested subplugintype is a valid one. + $subpluginsfile = core_component::get_component_directory($plugintype . '_' . $pluginname) . '/db/subplugins.php'; + if (!file_exists($subpluginsfile)) { + throw new backup_step_exception('plugin_missing_subplugins_php_file', array($plugintype, $pluginname)); + } + include($subpluginsfile); + if (!array_key_exists($subplugintype, $subplugins)) { + throw new backup_step_exception('incorrect_subplugin_type', $subplugintype); + } + + // Arrived here, subplugin is correct, let's create the optigroup. + $optigroupname = $subplugintype . '_' . $element->get_name() . '_subplugin'; + $optigroup = new backup_optigroup($optigroupname, null, $multiple); + $element->add_child($optigroup); // Add optigroup to stay connected since beginning. + + // Every subplugin optionally can have a common/parent subplugin + // class for shared stuff. + $parentclass = 'backup_' . $plugintype . '_' . $pluginname . '_' . $subplugintype . '_subplugin'; + $parentfile = core_component::get_component_directory($plugintype . '_' . $pluginname) . + '/backup/moodle2/' . $parentclass . '.class.php'; + if (file_exists($parentfile)) { + require_once($parentfile); + } + + // Get all the optigroup_elements, looking over all the subplugin dirs. + $subpluginsdirs = core_component::get_plugin_list($subplugintype); + foreach ($subpluginsdirs as $name => $subpluginsdir) { + $classname = 'backup_' . $subplugintype . '_' . $name . '_subplugin'; + $backupfile = $subpluginsdir . '/backup/moodle2/' . $classname . '.class.php'; + if (file_exists($backupfile)) { + require_once($backupfile); + $backupsubplugin = new $classname($subplugintype, $name, $optigroup, $this); + // Add subplugin returned structure to optigroup. + $backupsubplugin->define_subplugin_structure($element->get_name()); + } + } + } + /** * To conditionally decide if one step will be executed or no * @@ -175,8 +252,9 @@ abstract class backup_structure_step extends backup_step { } /** - * Function that will return the structure to be processed by this backup_step. - * Must return one backup_nested_element + * Define the structure to be processed by this backup step. + * + * @return backup_nested_element */ abstract protected function define_structure(); } diff --git a/backup/util/plan/restore_structure_step.class.php b/backup/util/plan/restore_structure_step.class.php index 94e5ad66132..de7b0029c3a 100644 --- a/backup/util/plan/restore_structure_step.class.php +++ b/backup/util/plan/restore_structure_step.class.php @@ -294,6 +294,76 @@ abstract class restore_structure_step extends restore_step { } } + /** + * Add subplugin structure for a given plugin to any element in the structure restore tree + * + * This method allows the injection of subplugins (of a specific plugin) parsing and proccessing + * to any element in the restore structure. + * + * NOTE: Initially subplugins were only available for activities (mod), so only the + * {@link restore_activity_structure_step} class had support for them, always + * looking for /mod/modulenanme subplugins. This new method is a generalization of the + * existing one for activities, supporting all subplugins injecting information everywhere. + * + * @param string $subplugintype type of subplugin as defined in plugin's db/subplugins.php. + * @param restore_path_element $element element in the structure restore tree that + * we are going to add subplugin information to. + * @param string $plugintype type of the plugin. + * @param string $pluginname name of the plugin. + * @return void + */ + protected function add_subplugin_structure($subplugintype, $element, $plugintype = null, $pluginname = null) { + + // Verify if this is a BC call for an activity restore. See NOTE above for this special case. + if ($plugintype === null and $pluginname === null) { + $plugintype = 'mod'; + $pluginname = $this->task->get_modulename(); + // TODO: Once all the calls have been changed to add both not null plugintype and pluginname, add a debugging here. + } + + // Check the requested plugintype is a valid one. + if (!array_key_exists($plugintype, core_component::get_plugin_types())) { + throw new restore_step_exception('incorrect_plugin_type', $plugintype); + } + + // Check the requested pluginname, for the specified plugintype, is a valid one. + if (!array_key_exists($pluginname, core_component::get_plugin_list($plugintype))) { + throw new restore_step_exception('incorrect_plugin_name', array($plugintype, $pluginname)); + } + + // Check the requested subplugintype is a valid one. + $subpluginsfile = core_component::get_component_directory($plugintype . '_' . $pluginname) . '/db/subplugins.php'; + if (!file_exists($subpluginsfile)) { + throw new restore_step_exception('plugin_missing_subplugins_php_file', array($plugintype, $pluginname)); + } + include($subpluginsfile); + if (!array_key_exists($subplugintype, $subplugins)) { + throw new restore_step_exception('incorrect_subplugin_type', $subplugintype); + } + + // Every subplugin optionally can have a common/parent subplugin + // class for shared stuff. + $parentclass = 'restore_' . $plugintype . '_' . $pluginname . '_' . $subplugintype . '_subplugin'; + $parentfile = core_component::get_component_directory($plugintype . '_' . $pluginname) . + '/backup/moodle2/' . $parentclass . '.class.php'; + if (file_exists($parentfile)) { + require_once($parentfile); + } + + // Get all the restore path elements, looking across all the subplugin dirs. + $subpluginsdirs = core_component::get_plugin_list($subplugintype); + foreach ($subpluginsdirs as $name => $subpluginsdir) { + $classname = 'restore_' . $subplugintype . '_' . $name . '_subplugin'; + $restorefile = $subpluginsdir . '/backup/moodle2/' . $classname . '.class.php'; + if (file_exists($restorefile)) { + require_once($restorefile); + $restoresubplugin = new $classname($subplugintype, $name, $this); + // Add subplugin paths to the step. + $this->prepare_pathelements($restoresubplugin->define_subplugin_structure($element)); + } + } + } + /** * Launch all the after_execute methods present in all the processing objects * diff --git a/backup/util/plan/tests/fixtures/plan_fixtures.php b/backup/util/plan/tests/fixtures/plan_fixtures.php index 1283e7e5304..53f40906bd7 100644 --- a/backup/util/plan/tests/fixtures/plan_fixtures.php +++ b/backup/util/plan/tests/fixtures/plan_fixtures.php @@ -26,6 +26,7 @@ defined('MOODLE_INTERNAL') || die(); // Include all the needed stuff global $CFG; require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php'); +require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php'); /** @@ -61,6 +62,9 @@ class mock_backup_step extends backup_step { */ class mock_backup_task_basepath extends backup_task { + /** @var string name of the mod plugin (activity) being used in the tests */ + private $modulename; + public function build() { // Nothing to do } @@ -73,6 +77,39 @@ class mock_backup_task_basepath extends backup_task { global $CFG; return $CFG->tempdir . '/test'; } + + public function set_modulename($modulename) { + $this->modulename = $modulename; + } + + public function get_modulename() { + return $this->modulename; + } +} + +/** + * Instantiable class extending restore_task in order to mockup get_taskbasepath() + */ +class mock_restore_task_basepath extends restore_task { + + /** @var string name of the mod plugin (activity) being used in the tests */ + private $modulename; + + public function build() { + // Nothing to do. + } + + public function define_settings() { + // Nothing to do. + } + + public function set_modulename($modulename) { + $this->modulename = $modulename; + } + + public function get_modulename() { + return $this->modulename; + } } /** @@ -80,7 +117,7 @@ class mock_backup_task_basepath extends backup_task { */ class mock_backup_structure_step extends backup_structure_step { - protected function define_structure() { + public function define_structure() { // Create really simple structure (1 nested with 1 attr and 2 fields) $test = new backup_nested_element('test', @@ -91,6 +128,35 @@ class mock_backup_structure_step extends backup_structure_step { return $test; } + + public function add_plugin_structure($plugintype, $element, $multiple) { + parent::add_plugin_structure($plugintype, $element, $multiple); + } + + public function add_subplugin_structure($subplugintype, $element, $multiple, $plugintype = null, $pluginname = null) { + parent::add_subplugin_structure($subplugintype, $element, $multiple, $plugintype, $pluginname); + } +} + +class mock_restore_structure_step extends restore_structure_step { + public function define_structure() { + + // Create a really simple structure (1 element). + $test = new restore_path_element('test', '/tests/test'); + return array($test); + } + + public function add_plugin_structure($plugintype, $element) { + parent::add_plugin_structure($plugintype, $element); + } + + public function add_subplugin_structure($subplugintype, $element, $plugintype = null, $pluginname = null) { + parent::add_subplugin_structure($subplugintype, $element, $plugintype, $pluginname); + } + + public function get_pathelements() { + return $this->pathelements; + } } /** diff --git a/backup/util/plan/tests/step_test.php b/backup/util/plan/tests/step_test.php index 44afd8d74c1..826b349d990 100644 --- a/backup/util/plan/tests/step_test.php +++ b/backup/util/plan/tests/step_test.php @@ -134,6 +134,261 @@ class backup_step_testcase extends advanced_testcase { @remove_dir(dirname($file)); } + + /** + * Verify the add_plugin_structure() backup method behavior and created structures. + */ + public function test_backup_structure_step_add_plugin_structure() { + // Create mocked task, step and element. + $bt = new mock_backup_task_basepath('taskname'); + $bs = new mock_backup_structure_step('steptest', null, $bt); + $el = new backup_nested_element('question', array('id'), array('one', 'two', 'qtype')); + // Wrong plugintype. + try { + $bs->add_plugin_structure('fakeplugin', $el, true); + $this->assertTrue(false, 'base_step_exception expected'); + } catch (exception $e) { + $this->assertTrue($e instanceof backup_step_exception); + $this->assertEquals('incorrect_plugin_type', $e->errorcode); + } + // Correct plugintype qtype call (@ 'question' level). + $bs->add_plugin_structure('qtype', $el, false); + $ch = $el->get_children(); + $this->assertEquals(1, count($ch)); + $og = reset($ch); + $this->assertTrue($og instanceof backup_optigroup); + $ch = $og->get_children(); + $this->assertTrue(array_key_exists('optigroup_qtype_calculatedsimple_question', $ch)); + $this->assertTrue($ch['optigroup_qtype_calculatedsimple_question'] instanceof backup_plugin_element); + } + + /** + * Verify the add_subplugin_structure() backup method behavior and created structures. + */ + public function test_backup_structure_step_add_subplugin_structure() { + // Create mocked task, step and element. + $bt = new mock_backup_task_basepath('taskname'); + $bs = new mock_backup_structure_step('steptest', null, $bt); + $el = new backup_nested_element('workshop', array('id'), array('one', 'two', 'qtype')); + // Wrong plugin type. + try { + $bs->add_subplugin_structure('fakesubplugin', $el, true, 'fakeplugintype', 'fakepluginname'); + $this->assertTrue(false, 'base_step_exception expected'); + } catch (exception $e) { + $this->assertTrue($e instanceof backup_step_exception); + $this->assertEquals('incorrect_plugin_type', $e->errorcode); + } + // Wrong plugin type. + try { + $bs->add_subplugin_structure('fakesubplugin', $el, true, 'mod', 'fakepluginname'); + $this->assertTrue(false, 'base_step_exception expected'); + } catch (exception $e) { + $this->assertTrue($e instanceof backup_step_exception); + $this->assertEquals('incorrect_plugin_name', $e->errorcode); + } + // Wrong plugin not having subplugins. + try { + $bs->add_subplugin_structure('fakesubplugin', $el, true, 'mod', 'page'); + $this->assertTrue(false, 'base_step_exception expected'); + } catch (exception $e) { + $this->assertTrue($e instanceof backup_step_exception); + $this->assertEquals('plugin_missing_subplugins_php_file', $e->errorcode); + } + // Wrong BC (defaulting to mod and modulename) use not having subplugins. + try { + $bt->set_modulename('page'); + $bs->add_subplugin_structure('fakesubplugin', $el, true); + $this->assertTrue(false, 'base_step_exception expected'); + } catch (exception $e) { + $this->assertTrue($e instanceof backup_step_exception); + $this->assertEquals('plugin_missing_subplugins_php_file', $e->errorcode); + } + // Wrong subplugin type. + try { + $bs->add_subplugin_structure('fakesubplugin', $el, true, 'mod', 'workshop'); + $this->assertTrue(false, 'base_step_exception expected'); + } catch (exception $e) { + $this->assertTrue($e instanceof backup_step_exception); + $this->assertEquals('incorrect_subplugin_type', $e->errorcode); + } + // Wrong BC subplugin type. + try { + $bt->set_modulename('workshop'); + $bs->add_subplugin_structure('fakesubplugin', $el, true); + $this->assertTrue(false, 'base_step_exception expected'); + } catch (exception $e) { + $this->assertTrue($e instanceof backup_step_exception); + $this->assertEquals('incorrect_subplugin_type', $e->errorcode); + } + // Correct call to workshopform subplugin (@ 'workshop' level). + $bs->add_subplugin_structure('workshopform', $el, true, 'mod', 'workshop'); + $ch = $el->get_children(); + $this->assertEquals(1, count($ch)); + $og = reset($ch); + $this->assertTrue($og instanceof backup_optigroup); + $ch = $og->get_children(); + $this->assertTrue(array_key_exists('optigroup_workshopform_accumulative_workshop', $ch)); + $this->assertTrue($ch['optigroup_workshopform_accumulative_workshop'] instanceof backup_subplugin_element); + + // Correct BC call to workshopform subplugin (@ 'assessment' level). + $el = new backup_nested_element('assessment', array('id'), array('one', 'two', 'qtype')); + $bt->set_modulename('workshop'); + $bs->add_subplugin_structure('workshopform', $el, true); + $ch = $el->get_children(); + $this->assertEquals(1, count($ch)); + $og = reset($ch); + $this->assertTrue($og instanceof backup_optigroup); + $ch = $og->get_children(); + $this->assertTrue(array_key_exists('optigroup_workshopform_accumulative_assessment', $ch)); + $this->assertTrue($ch['optigroup_workshopform_accumulative_assessment'] instanceof backup_subplugin_element); + + // TODO: Add some test covering a non-mod subplugin once we have some implemented in core. + } + + /** + * Verify the add_plugin_structure() restore method behavior and created structures. + */ + public function test_restore_structure_step_add_plugin_structure() { + // Create mocked task, step and element. + $bt = new mock_restore_task_basepath('taskname'); + $bs = new mock_restore_structure_step('steptest', null, $bt); + $el = new restore_path_element('question', '/some/path/to/question'); + // Wrong plugintype. + try { + $bs->add_plugin_structure('fakeplugin', $el); + $this->assertTrue(false, 'base_step_exception expected'); + } catch (exception $e) { + $this->assertTrue($e instanceof restore_step_exception); + $this->assertEquals('incorrect_plugin_type', $e->errorcode); + } + // Correct plugintype qtype call (@ 'question' level). + $bs->add_plugin_structure('qtype', $el); + $patheles = $bs->get_pathelements(); + // Verify some well-known qtype plugin restore_path_elements have been added. + $keys = array( + '/some/path/to/question/plugin_qtype_calculated_question/answers/answer', + '/some/path/to/question/plugin_qtype_calculated_question/dataset_definitions/dataset_definition', + '/some/path/to/question/plugin_qtype_calculated_question/calculated_options/calculated_option', + '/some/path/to/question/plugin_qtype_essay_question/essay', + '/some/path/to/question/plugin_qtype_random_question', + '/some/path/to/question/plugin_qtype_truefalse_question/answers/answer'); + foreach ($keys as $key) { + // Verify the element exists. + $this->assertArrayHasKey($key, $patheles); + // Verify the element is a restore_path_element. + $this->assertTrue($patheles[$key] instanceof restore_path_element); + // Check it has a processing object. + $po = $patheles[$key]->get_processing_object(); + $this->assertTrue($po instanceof restore_plugin); + } + } + + /** + * Verify the add_subplugin_structure() restore method behavior and created structures. + */ + public function test_restore_structure_step_add_subplugin_structure() { + // Create mocked task, step and element. + $bt = new mock_restore_task_basepath('taskname'); + $bs = new mock_restore_structure_step('steptest', null, $bt); + $el = new restore_path_element('workshop', '/path/to/workshop'); + // Wrong plugin type. + try { + $bs->add_subplugin_structure('fakesubplugin', $el, 'fakeplugintype', 'fakepluginname'); + $this->assertTrue(false, 'base_step_exception expected'); + } catch (exception $e) { + $this->assertTrue($e instanceof restore_step_exception); + $this->assertEquals('incorrect_plugin_type', $e->errorcode); + } + // Wrong plugin type. + try { + $bs->add_subplugin_structure('fakesubplugin', $el, 'mod', 'fakepluginname'); + $this->assertTrue(false, 'base_step_exception expected'); + } catch (exception $e) { + $this->assertTrue($e instanceof restore_step_exception); + $this->assertEquals('incorrect_plugin_name', $e->errorcode); + } + // Wrong plugin not having subplugins. + try { + $bs->add_subplugin_structure('fakesubplugin', $el, 'mod', 'page'); + $this->assertTrue(false, 'base_step_exception expected'); + } catch (exception $e) { + $this->assertTrue($e instanceof restore_step_exception); + $this->assertEquals('plugin_missing_subplugins_php_file', $e->errorcode); + } + // Wrong BC (defaulting to mod and modulename) use not having subplugins. + try { + $bt->set_modulename('page'); + $bs->add_subplugin_structure('fakesubplugin', $el); + $this->assertTrue(false, 'base_step_exception expected'); + } catch (exception $e) { + $this->assertTrue($e instanceof restore_step_exception); + $this->assertEquals('plugin_missing_subplugins_php_file', $e->errorcode); + } + // Wrong subplugin type. + try { + $bs->add_subplugin_structure('fakesubplugin', $el, 'mod', 'workshop'); + $this->assertTrue(false, 'base_step_exception expected'); + } catch (exception $e) { + $this->assertTrue($e instanceof restore_step_exception); + $this->assertEquals('incorrect_subplugin_type', $e->errorcode); + } + // Wrong BC subplugin type. + try { + $bt->set_modulename('workshop'); + $bs->add_subplugin_structure('fakesubplugin', $el); + $this->assertTrue(false, 'base_step_exception expected'); + } catch (exception $e) { + $this->assertTrue($e instanceof restore_step_exception); + $this->assertEquals('incorrect_subplugin_type', $e->errorcode); + } + // Correct call to workshopform subplugin (@ 'workshop' level). + $bt = new mock_restore_task_basepath('taskname'); + $bs = new mock_restore_structure_step('steptest', null, $bt); + $el = new restore_path_element('workshop', '/path/to/workshop'); + $bs->add_subplugin_structure('workshopform', $el, 'mod', 'workshop'); + $patheles = $bs->get_pathelements(); + // Verify some well-known workshopform subplugin restore_path_elements have been added. + $keys = array( + '/path/to/workshop/subplugin_workshopform_accumulative_workshop/workshopform_accumulative_dimension', + '/path/to/workshop/subplugin_workshopform_comments_workshop/workshopform_comments_dimension', + '/path/to/workshop/subplugin_workshopform_numerrors_workshop/workshopform_numerrors_map', + '/path/to/workshop/subplugin_workshopform_rubric_workshop/workshopform_rubric_config'); + foreach ($keys as $key) { + // Verify the element exists. + $this->assertArrayHasKey($key, $patheles); + // Verify the element is a restore_path_element. + $this->assertTrue($patheles[$key] instanceof restore_path_element); + // Check it has a processing object. + $po = $patheles[$key]->get_processing_object(); + $this->assertTrue($po instanceof restore_subplugin); + } + + // Correct BC call to workshopform subplugin (@ 'assessment' level). + $bt = new mock_restore_task_basepath('taskname'); + $bs = new mock_restore_structure_step('steptest', null, $bt); + $el = new restore_path_element('assessment', '/a/assessment'); + $bt->set_modulename('workshop'); + $bs->add_subplugin_structure('workshopform', $el); + $patheles = $bs->get_pathelements(); + // Verify some well-known workshopform subplugin restore_path_elements have been added. + $keys = array( + '/a/assessment/subplugin_workshopform_accumulative_assessment/workshopform_accumulative_grade', + '/a/assessment/subplugin_workshopform_comments_assessment/workshopform_comments_grade', + '/a/assessment/subplugin_workshopform_numerrors_assessment/workshopform_numerrors_grade', + '/a/assessment/subplugin_workshopform_rubric_assessment/workshopform_rubric_grade'); + foreach ($keys as $key) { + // Verify the element exists. + $this->assertArrayHasKey($key, $patheles); + // Verify the element is a restore_path_element. + $this->assertTrue($patheles[$key] instanceof restore_path_element); + // Check it has a processing object. + $po = $patheles[$key]->get_processing_object(); + $this->assertTrue($po instanceof restore_subplugin); + } + + // TODO: Add some test covering a non-mod subplugin once we have some implemented in core. + } + /** * wrong base_step class tests */ diff --git a/lib/classes/event/assessable_uploaded.php b/lib/classes/event/assessable_uploaded.php index 6c1a50cee9a..39606525af1 100644 --- a/lib/classes/event/assessable_uploaded.php +++ b/lib/classes/event/assessable_uploaded.php @@ -77,4 +77,8 @@ abstract class assessable_uploaded extends base { } } + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/lib/classes/event/badge_awarded.php b/lib/classes/event/badge_awarded.php index 4c9e0215eb7..e7a3e39fd68 100644 --- a/lib/classes/event/badge_awarded.php +++ b/lib/classes/event/badge_awarded.php @@ -94,4 +94,15 @@ class badge_awarded extends base { throw new \coding_exception('The \'objectid\' must be set.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'badge', 'restore' => 'badge'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['badgeissuedid'] = array('db' => 'badge_issued', 'restore' => base::NOT_MAPPED); + + return $othermapped; + } } diff --git a/lib/classes/event/base.php b/lib/classes/event/base.php index 2ccec1d1fb3..88685a4e115 100644 --- a/lib/classes/event/base.php +++ b/lib/classes/event/base.php @@ -75,6 +75,11 @@ abstract class base implements \IteratorAggregate { */ const LEVEL_PARTICIPATING = 2; + /** + * The value used when an id can not be mapped during a restore. + */ + const NOT_MAPPED = -31337; + /** @var array event data */ protected $data; @@ -478,6 +483,79 @@ abstract class base implements \IteratorAggregate { return $event; } + /** + * This is used when restoring course logs where it is required that we + * map the objectid 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 an objectid this won't + * be called, so no debugging message will be displayed. + * + * Example of usage: + * + * return array('db' => 'assign_submissions', 'restore' => 'submission'); + * + * If the objectid can not be mapped during restore set the value to \core\event\base::NOT_MAPPED, example - + * + * return array('db' => 'some_table', 'restore' => \core\event\base::NOT_MAPPED); + * + * Note - it isn't necessary to specify the 'db' and 'restore' values in this case, so you can also use - + * + * return \core\event\base::NOT_MAPPED; + * + * The 'db' key refers to the database table and the 'restore' key refers to + * the name of the restore element the objectid is associated with. In many + * cases these will be the same. + * + * @return string the name of the restore mapping the objectid links to + */ + public static function get_objectid_mapping() { + debugging('In order to restore course logs accurately the event "' . get_called_class() . '" must define the + function get_objectid_mapping().', DEBUG_DEVELOPER); + + 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 "' . get_called_class() . '" 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. diff --git a/lib/classes/event/blog_association_created.php b/lib/classes/event/blog_association_created.php index 62ae7c9da98..3c30861aa03 100644 --- a/lib/classes/event/blog_association_created.php +++ b/lib/classes/event/blog_association_created.php @@ -125,4 +125,18 @@ class blog_association_created extends base { throw new \coding_exception('The \'subject\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + // Blogs are not included in backups, so no mapping required for restore. + return array('db' => 'blog_association', 'restore' => base::NOT_MAPPED); + } + + public static function get_other_mapping() { + // Blogs are not included in backups, so no mapping required for restore. + $othermapped = array(); + $othermapped['blogid'] = array('db' => 'post', 'restore' => base::NOT_MAPPED); + // The associateid field is varying (context->instanceid) so cannot be mapped. + + return $othermapped; + } } diff --git a/lib/classes/event/blog_comment_created.php b/lib/classes/event/blog_comment_created.php index 3c68de270f4..5de77d67fb2 100644 --- a/lib/classes/event/blog_comment_created.php +++ b/lib/classes/event/blog_comment_created.php @@ -52,4 +52,10 @@ class blog_comment_created extends comment_created { public function get_description() { return "The user with id '$this->userid' added the comment to the blog with id '{$this->other['itemid']}'."; } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['itemid'] = array('db' => 'post', 'restore' => base::NOT_MAPPED); + return $othermapped; + } } diff --git a/lib/classes/event/blog_comment_deleted.php b/lib/classes/event/blog_comment_deleted.php index adf5c092b94..63c808df48b 100644 --- a/lib/classes/event/blog_comment_deleted.php +++ b/lib/classes/event/blog_comment_deleted.php @@ -52,4 +52,10 @@ class blog_comment_deleted extends comment_deleted { public function get_description() { return "The user with id '$this->userid' deleted the comment for the blog with id '{$this->other['itemid']}'."; } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['itemid'] = array('db' => 'post', 'restore' => base::NOT_MAPPED); + return $othermapped; + } } diff --git a/lib/classes/event/blog_entries_viewed.php b/lib/classes/event/blog_entries_viewed.php index 632b892fcdb..e240ffbe1c1 100644 --- a/lib/classes/event/blog_entries_viewed.php +++ b/lib/classes/event/blog_entries_viewed.php @@ -106,4 +106,16 @@ class blog_entries_viewed extends base { $url = new \moodle_url('index.php', $params); return array (SITEID, 'blog', 'view', $url->out(), 'view blog entry'); } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['entryid'] = array('db' => 'post', 'restore' => base::NOT_MAPPED); + $othermapped['tagid'] = array('db' => 'tag', 'restore' => base::NOT_MAPPED); + $othermapped['userid'] = array('db' => 'user', 'restore' => 'user'); + $othermapped['modid'] = array('db' => 'course_modules', 'restore' => 'course_module'); + $othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group'); + $othermapped['courseid'] = array('db' => 'course', 'restore' => 'course'); + + return $othermapped; + } } diff --git a/lib/classes/event/blog_entry_created.php b/lib/classes/event/blog_entry_created.php index 1f39bed35b6..ff697ea9c6b 100644 --- a/lib/classes/event/blog_entry_created.php +++ b/lib/classes/event/blog_entry_created.php @@ -140,4 +140,9 @@ class blog_entry_created extends base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + // Blogs are not backed up, so no mapping required for restore. + return array('db' => 'post', 'restore' => base::NOT_MAPPED); + } } diff --git a/lib/classes/event/blog_entry_deleted.php b/lib/classes/event/blog_entry_deleted.php index 2321e42f51b..74a067e947a 100644 --- a/lib/classes/event/blog_entry_deleted.php +++ b/lib/classes/event/blog_entry_deleted.php @@ -131,4 +131,9 @@ class blog_entry_deleted extends base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + // Blogs are not backed up, so no need for mapping for restore. + return array('db' => 'post', 'restore' => base::NOT_MAPPED); + } } diff --git a/lib/classes/event/blog_entry_updated.php b/lib/classes/event/blog_entry_updated.php index 4b9237162e7..73959b6d8c0 100644 --- a/lib/classes/event/blog_entry_updated.php +++ b/lib/classes/event/blog_entry_updated.php @@ -138,5 +138,10 @@ class blog_entry_updated extends base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + // Blogs are not backed up, so no need for mapping for restore. + return array('db' => 'post', 'restore' => NOT_MAPPED); + } } diff --git a/lib/classes/event/calendar_event_created.php b/lib/classes/event/calendar_event_created.php index 98fa0f4c895..a98c238b922 100644 --- a/lib/classes/event/calendar_event_created.php +++ b/lib/classes/event/calendar_event_created.php @@ -111,4 +111,15 @@ class calendar_event_created extends base { throw new \coding_exception('The \'timestart\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'event', 'restore' => 'event'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['repeatid'] = array('db' => 'event', 'restore' => 'event'); + + return $othermapped; + } } diff --git a/lib/classes/event/calendar_event_deleted.php b/lib/classes/event/calendar_event_deleted.php index cdd013bf099..8cb09f64325 100644 --- a/lib/classes/event/calendar_event_deleted.php +++ b/lib/classes/event/calendar_event_deleted.php @@ -92,4 +92,15 @@ class calendar_event_deleted extends base { throw new \coding_exception('The \'timestart\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'event', 'restore' => 'event'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['repeatid'] = array('db' => 'event', 'restore' => 'event'); + + return $othermapped; + } } diff --git a/lib/classes/event/calendar_event_updated.php b/lib/classes/event/calendar_event_updated.php index 86971414725..1826f3d0a9f 100644 --- a/lib/classes/event/calendar_event_updated.php +++ b/lib/classes/event/calendar_event_updated.php @@ -110,4 +110,15 @@ class calendar_event_updated extends base { throw new \coding_exception('The \'timestart\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'event', 'restore' => 'event'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['repeatid'] = array('db' => 'event', 'restore' => 'event'); + + return $othermapped; + } } diff --git a/lib/classes/event/cohort_created.php b/lib/classes/event/cohort_created.php index 5451a7ab8fd..764245416ac 100644 --- a/lib/classes/event/cohort_created.php +++ b/lib/classes/event/cohort_created.php @@ -90,4 +90,9 @@ class cohort_created extends base { protected function get_legacy_eventdata() { return $this->get_record_snapshot('cohort', $this->objectid); } + + public static function get_objectid_mapping() { + // Cohorts are not included in backups, so no mapping is needed for restore. + return array('db' => 'cohort', 'restore' => base::NOT_MAPPED); + } } diff --git a/lib/classes/event/cohort_deleted.php b/lib/classes/event/cohort_deleted.php index c5f170cc876..37406cc752b 100644 --- a/lib/classes/event/cohort_deleted.php +++ b/lib/classes/event/cohort_deleted.php @@ -90,4 +90,9 @@ class cohort_deleted extends base { protected function get_legacy_eventdata() { return $this->get_record_snapshot('cohort', $this->objectid); } + + public static function get_objectid_mapping() { + // Cohorts are not included in backups, so no mapping is needed for restore. + return array('db' => 'cohort', 'restore' => base::NOT_MAPPED); + } } diff --git a/lib/classes/event/cohort_member_added.php b/lib/classes/event/cohort_member_added.php index 018d854ec1f..0390569ea14 100644 --- a/lib/classes/event/cohort_member_added.php +++ b/lib/classes/event/cohort_member_added.php @@ -108,4 +108,9 @@ class cohort_member_added extends base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + // Cohorts are not included in backups, so no mapping is needed for restore. + return array('db' => 'cohort', 'restore' => base::NOT_MAPPED); + } } diff --git a/lib/classes/event/cohort_member_removed.php b/lib/classes/event/cohort_member_removed.php index 25c902adf30..6152fa6233f 100644 --- a/lib/classes/event/cohort_member_removed.php +++ b/lib/classes/event/cohort_member_removed.php @@ -109,4 +109,9 @@ class cohort_member_removed extends base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + // Cohorts are not included in backups, so no mapping is needed for restore. + return array('db' => 'cohort', 'restore' => base::NOT_MAPPED); + } } diff --git a/lib/classes/event/cohort_updated.php b/lib/classes/event/cohort_updated.php index 83d05b5de9c..2ee6fe2f7ee 100644 --- a/lib/classes/event/cohort_updated.php +++ b/lib/classes/event/cohort_updated.php @@ -90,4 +90,9 @@ class cohort_updated extends base { protected function get_legacy_eventdata() { return $this->get_record_snapshot('cohort', $this->objectid); } + + public static function get_objectid_mapping() { + // Cohorts are not included in backups, so no mapping is needed for restore. + return array('db' => 'cohort', 'restore' => base::NOT_MAPPED); + } } diff --git a/lib/classes/event/comment_created.php b/lib/classes/event/comment_created.php index fa4befdb0c4..e754c0121ce 100644 --- a/lib/classes/event/comment_created.php +++ b/lib/classes/event/comment_created.php @@ -100,4 +100,15 @@ abstract class comment_created extends base { throw new \coding_exception('The \'itemid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'comments', 'restore' => 'comment'); + } + + public static function get_other_mapping() { + // We cannot map fields that do not have a 1:1 mapping. + $othermapped = array(); + $othermapped['itemid'] = base::NOT_MAPPED; + return $othermapped; + } } diff --git a/lib/classes/event/comment_deleted.php b/lib/classes/event/comment_deleted.php index 0dbdcab6741..2d66716e83c 100644 --- a/lib/classes/event/comment_deleted.php +++ b/lib/classes/event/comment_deleted.php @@ -100,4 +100,15 @@ abstract class comment_deleted extends base { throw new \coding_exception('The \'itemid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'comments', 'restore' => 'comment'); + } + + public static function get_other_mapping() { + // We cannot map fields that do not have a 1:1 mapping. + $othermapped = array(); + $othermapped['itemid'] = base::NOT_MAPPED; + return $othermapped; + } } diff --git a/lib/classes/event/content_viewed.php b/lib/classes/event/content_viewed.php index 18231bf91b8..a1680fa7fde 100644 --- a/lib/classes/event/content_viewed.php +++ b/lib/classes/event/content_viewed.php @@ -126,5 +126,9 @@ abstract class content_viewed extends base { throw new \coding_exception('The \'content\' value must be set in other.'); } } + + public static function get_other_mapping() { + return false; + } } diff --git a/lib/classes/event/course_category_created.php b/lib/classes/event/course_category_created.php index ff48d0a98ab..ceed8dea490 100644 --- a/lib/classes/event/course_category_created.php +++ b/lib/classes/event/course_category_created.php @@ -80,4 +80,9 @@ class course_category_created extends base { protected function get_legacy_logdata() { return array(SITEID, 'category', 'add', 'editcategory.php?id=' . $this->objectid, $this->objectid); } + + public static function get_objectid_mapping() { + // Categories are not backed up, so no need to map them on restore. + return array('db' => 'course_categories', 'restore' => base::NOT_MAPPED); + } } diff --git a/lib/classes/event/course_category_deleted.php b/lib/classes/event/course_category_deleted.php index 4d80eeea830..6de24131245 100644 --- a/lib/classes/event/course_category_deleted.php +++ b/lib/classes/event/course_category_deleted.php @@ -136,4 +136,13 @@ class course_category_deleted extends base { throw new \coding_exception('The \'name\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + // Categories are not backed up, so no need to map them on restore. + return array('db' => 'course_categories', 'restore' => base::NOT_MAPPED); + } + + public static function get_other_mapping() { + return false; + } } diff --git a/lib/classes/event/course_category_updated.php b/lib/classes/event/course_category_updated.php index d20d487e502..72a262fc66e 100644 --- a/lib/classes/event/course_category_updated.php +++ b/lib/classes/event/course_category_updated.php @@ -96,4 +96,9 @@ class course_category_updated extends base { return array(SITEID, 'category', 'update', 'editcategory.php?id=' . $this->objectid, $this->objectid); } + + public static function get_objectid_mapping() { + // Categories are not backed up, so no need to map them on restore. + return array('db' => 'course_categories', 'restore' => base::NOT_MAPPED); + } } diff --git a/lib/classes/event/course_completed.php b/lib/classes/event/course_completed.php index ed51fa97d3b..b01c626cb44 100644 --- a/lib/classes/event/course_completed.php +++ b/lib/classes/event/course_completed.php @@ -134,4 +134,15 @@ class course_completed extends base { throw new \coding_exception('The \'relateduserid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + // Sorry - there is no mapping available for completion records. + return array('db' => 'course_completions', 'restore' => base::NOT_MAPPED); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['relateduserid'] = array('db' => 'user', 'restore' => 'user'); + return $othermapped; + } } diff --git a/lib/classes/event/course_content_deleted.php b/lib/classes/event/course_content_deleted.php index dbea00d4d3a..c5207a85335 100644 --- a/lib/classes/event/course_content_deleted.php +++ b/lib/classes/event/course_content_deleted.php @@ -104,4 +104,12 @@ class course_content_deleted extends base { throw new \coding_exception('The \'options\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'course', 'restore' => 'course'); + } + + public static function get_other_mapping() { + return false; + } } diff --git a/lib/classes/event/course_created.php b/lib/classes/event/course_created.php index 699dcc15785..418a2c291c5 100644 --- a/lib/classes/event/course_created.php +++ b/lib/classes/event/course_created.php @@ -119,4 +119,13 @@ class course_created extends base { throw new \coding_exception('The \'fullname\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'course', 'restore' => 'course'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/lib/classes/event/course_deleted.php b/lib/classes/event/course_deleted.php index 19641ffef42..ea2734ae1ba 100644 --- a/lib/classes/event/course_deleted.php +++ b/lib/classes/event/course_deleted.php @@ -114,4 +114,13 @@ class course_deleted extends base { throw new \coding_exception('The \'fullname\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'course', 'restore' => 'course'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/lib/classes/event/course_module_completion_updated.php b/lib/classes/event/course_module_completion_updated.php index b5f2ff2c099..5142621612a 100644 --- a/lib/classes/event/course_module_completion_updated.php +++ b/lib/classes/event/course_module_completion_updated.php @@ -29,6 +29,12 @@ defined('MOODLE_INTERNAL') || die(); /** * Course module completion event class. * + * @property-read array $other { + * Extra information about event. + * + * - int relateduserid: (optional) the related user id. + * } + * * @package core * @since Moodle 2.6 * @copyright 2013 Rajesh Taneja @@ -107,4 +113,16 @@ class course_module_completion_updated extends base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + // Sorry mapping info is not available for course modules completion records. + return array('db' => 'course_modules_completion', 'restore' => base::NOT_MAPPED); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['relateduserid'] = array('db' => 'user', 'restore' => 'user'); + + return $othermapped; + } } diff --git a/lib/classes/event/course_module_created.php b/lib/classes/event/course_module_created.php index 244a1240da4..fba54873c78 100644 --- a/lib/classes/event/course_module_created.php +++ b/lib/classes/event/course_module_created.php @@ -165,5 +165,16 @@ class course_module_created extends base { throw new \coding_exception('The \'name\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'course_modules', 'restore' => 'course_module'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['instanceid'] = base::NOT_MAPPED; + + return $othermapped; + } } diff --git a/lib/classes/event/course_module_deleted.php b/lib/classes/event/course_module_deleted.php index 1bd888b3ec1..f2289ea7a28 100644 --- a/lib/classes/event/course_module_deleted.php +++ b/lib/classes/event/course_module_deleted.php @@ -119,5 +119,16 @@ class course_module_deleted extends base { throw new \coding_exception('The \'instanceid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'course_modules', 'restore' => 'course_module'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['instanceid'] = base::NOT_MAPPED; + + return $othermapped; + } } diff --git a/lib/classes/event/course_module_updated.php b/lib/classes/event/course_module_updated.php index b319df6cc1d..70f76e578e1 100644 --- a/lib/classes/event/course_module_updated.php +++ b/lib/classes/event/course_module_updated.php @@ -163,5 +163,16 @@ class course_module_updated extends base { )); return $event; } + + public static function get_objectid_mapping() { + return array('db' => 'course_modules', 'restore' => 'course_module'); + } + + public static function get_other_mapping() { + $othermapping = array(); + $othermapping['instanceid'] = base::NOT_MAPPED; + + return $othermapping; + } } diff --git a/lib/classes/event/course_reset_ended.php b/lib/classes/event/course_reset_ended.php index fcca9611e16..1ff0115d2e7 100644 --- a/lib/classes/event/course_reset_ended.php +++ b/lib/classes/event/course_reset_ended.php @@ -90,4 +90,9 @@ class course_reset_ended extends base { throw new \coding_exception('The \'reset_options\' value must be set in other.'); } } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/lib/classes/event/course_reset_started.php b/lib/classes/event/course_reset_started.php index 491aacc1d71..d65aadff329 100644 --- a/lib/classes/event/course_reset_started.php +++ b/lib/classes/event/course_reset_started.php @@ -90,4 +90,8 @@ class course_reset_started extends base { throw new \coding_exception('The \'reset_options\' value must be set in other.'); } } + + public static function get_other_mapping() { + return false; + } } diff --git a/lib/classes/event/course_restored.php b/lib/classes/event/course_restored.php index 1d5230c200c..3c41e12d2da 100644 --- a/lib/classes/event/course_restored.php +++ b/lib/classes/event/course_restored.php @@ -137,4 +137,13 @@ class course_restored extends base { throw new \coding_exception('The \'samesite\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'course', 'restore' => 'course'); + } + + public static function get_other_mapping() { + // No need to map anything. + return false; + } } diff --git a/lib/classes/event/course_section_updated.php b/lib/classes/event/course_section_updated.php index 0a458e6dc10..7bca3acc272 100644 --- a/lib/classes/event/course_section_updated.php +++ b/lib/classes/event/course_section_updated.php @@ -104,4 +104,13 @@ class course_section_updated extends base { throw new \coding_exception('The \'sectionnum\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'course_sections', 'restore' => 'course_section'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/lib/classes/event/course_updated.php b/lib/classes/event/course_updated.php index a49e9c2852e..fab46c534e9 100644 --- a/lib/classes/event/course_updated.php +++ b/lib/classes/event/course_updated.php @@ -117,4 +117,13 @@ class course_updated extends base { protected function get_legacy_logdata() { return $this->legacylogdata; } + + public static function get_objectid_mapping() { + return array('db' => 'course', 'restore' => 'course'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/lib/classes/event/course_user_report_viewed.php b/lib/classes/event/course_user_report_viewed.php index 1e55e562afb..45b5f279c8f 100644 --- a/lib/classes/event/course_user_report_viewed.php +++ b/lib/classes/event/course_user_report_viewed.php @@ -114,4 +114,9 @@ class course_user_report_viewed extends base { throw new \coding_exception('The \'mode\' value must be set in other.'); } } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/lib/classes/event/course_viewed.php b/lib/classes/event/course_viewed.php index a63e3cea8ff..4f4d9b38f7c 100644 --- a/lib/classes/event/course_viewed.php +++ b/lib/classes/event/course_viewed.php @@ -141,4 +141,9 @@ class course_viewed extends base { throw new \coding_exception('Context level must be CONTEXT_COURSE.'); } } + + public static function get_other_mapping() { + // No mapping required. + return false; + } } diff --git a/lib/classes/event/email_failed.php b/lib/classes/event/email_failed.php index 461f4581c93..e6fcbc9cfc8 100644 --- a/lib/classes/event/email_failed.php +++ b/lib/classes/event/email_failed.php @@ -30,6 +30,14 @@ defined('MOODLE_INTERNAL') || die(); /** * Email failed event class. * + * @property-read array $other { + * Extra information about event. + * + * - string subject: the message subject. + * - string message: the message text. + * - string errorinfo: the error info. + * } + * * @package core * @since Moodle 2.7 * @copyright 2013 Mark Nelson @@ -94,4 +102,8 @@ class email_failed extends base { throw new \coding_exception('The \'errorinfo\' value must be set in other.'); } } + + public static function get_other_mapping() { + return false; + } } diff --git a/lib/classes/event/enrol_instance_created.php b/lib/classes/event/enrol_instance_created.php index ba03ea4b0f7..cf0a16df36a 100644 --- a/lib/classes/event/enrol_instance_created.php +++ b/lib/classes/event/enrol_instance_created.php @@ -106,4 +106,13 @@ class enrol_instance_created extends base { throw new \coding_exception('The \'enrol\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'enrol', 'restore' => 'enrol'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/lib/classes/event/enrol_instance_deleted.php b/lib/classes/event/enrol_instance_deleted.php index 9c1bf95c7d6..0f1efb75b7e 100644 --- a/lib/classes/event/enrol_instance_deleted.php +++ b/lib/classes/event/enrol_instance_deleted.php @@ -107,4 +107,13 @@ class enrol_instance_deleted extends base { throw new \coding_exception('The \'enrol\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'enrol', 'restore' => 'enrol'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/lib/classes/event/enrol_instance_updated.php b/lib/classes/event/enrol_instance_updated.php index 98732d721d0..2ffcf26535f 100644 --- a/lib/classes/event/enrol_instance_updated.php +++ b/lib/classes/event/enrol_instance_updated.php @@ -107,4 +107,13 @@ class enrol_instance_updated extends base { throw new \coding_exception('The \'enrol\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'enrol', 'restore' => 'enrol'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/lib/classes/event/grade_deleted.php b/lib/classes/event/grade_deleted.php index ffb65439517..d66409de768 100644 --- a/lib/classes/event/grade_deleted.php +++ b/lib/classes/event/grade_deleted.php @@ -131,4 +131,15 @@ class grade_deleted extends base { throw new \coding_exception('The \'overridden\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'grade_grades', 'restore' => 'grade_grades'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['itemid'] = array('db' => 'grade_items', 'restore' => 'grade_item'); + + return $othermapped; + } } diff --git a/lib/classes/event/group_created.php b/lib/classes/event/group_created.php index 504ba3daedf..71421da72c8 100644 --- a/lib/classes/event/group_created.php +++ b/lib/classes/event/group_created.php @@ -90,4 +90,8 @@ class group_created extends base { $this->data['edulevel'] = self::LEVEL_OTHER; $this->data['objecttable'] = 'groups'; } + + public static function get_objectid_mapping() { + return array('db' => 'groups', 'restore' => 'group'); + } } diff --git a/lib/classes/event/group_deleted.php b/lib/classes/event/group_deleted.php index 22294d15e01..b574cb43abf 100644 --- a/lib/classes/event/group_deleted.php +++ b/lib/classes/event/group_deleted.php @@ -90,4 +90,8 @@ class group_deleted extends base { $this->data['edulevel'] = self::LEVEL_OTHER; $this->data['objecttable'] = 'groups'; } + + public static function get_objectid_mapping() { + return array('db' => 'groups', 'restore' => 'group'); + } } diff --git a/lib/classes/event/group_member_added.php b/lib/classes/event/group_member_added.php index 1da73bca3e2..51fdacdc288 100644 --- a/lib/classes/event/group_member_added.php +++ b/lib/classes/event/group_member_added.php @@ -125,4 +125,15 @@ class group_member_added extends base { throw new \coding_exception('The \'itemid\' value must be set in other, even if empty.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'groups', 'restore' => 'group'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['itemid'] = base::NOT_MAPPED; + + return $othermapped; + } } diff --git a/lib/classes/event/group_member_removed.php b/lib/classes/event/group_member_removed.php index 1acc7789fb5..938313c65c8 100644 --- a/lib/classes/event/group_member_removed.php +++ b/lib/classes/event/group_member_removed.php @@ -108,4 +108,9 @@ class group_member_removed extends base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'groups', 'restore' => 'group'); + } + } diff --git a/lib/classes/event/group_updated.php b/lib/classes/event/group_updated.php index 5882b5527a5..e56a5d99dd9 100644 --- a/lib/classes/event/group_updated.php +++ b/lib/classes/event/group_updated.php @@ -90,4 +90,8 @@ class group_updated extends base { $this->data['edulevel'] = self::LEVEL_OTHER; $this->data['objecttable'] = 'groups'; } + + public static function get_objectid_mapping() { + return array('db' => 'groups', 'restore' => 'group'); + } } diff --git a/lib/classes/event/grouping_created.php b/lib/classes/event/grouping_created.php index 7ab5f79bcde..eb58c0d9029 100644 --- a/lib/classes/event/grouping_created.php +++ b/lib/classes/event/grouping_created.php @@ -90,4 +90,8 @@ class grouping_created extends base { $this->data['edulevel'] = self::LEVEL_OTHER; $this->data['objecttable'] = 'groupings'; } + + public static function get_objectid_mapping() { + return array('db' => 'groupings', 'restore' => 'grouping'); + } } diff --git a/lib/classes/event/grouping_deleted.php b/lib/classes/event/grouping_deleted.php index 8a7235ad14b..ac1188ed60b 100644 --- a/lib/classes/event/grouping_deleted.php +++ b/lib/classes/event/grouping_deleted.php @@ -97,4 +97,8 @@ class grouping_deleted extends base { $this->data['edulevel'] = self::LEVEL_OTHER; $this->data['objecttable'] = 'groupings'; } + + public static function get_objectid_mapping() { + return array('db' => 'groupings', 'restore' => 'grouping'); + } } diff --git a/lib/classes/event/grouping_updated.php b/lib/classes/event/grouping_updated.php index 2917da77bff..1892198d7ae 100644 --- a/lib/classes/event/grouping_updated.php +++ b/lib/classes/event/grouping_updated.php @@ -90,4 +90,8 @@ class grouping_updated extends base { $this->data['edulevel'] = self::LEVEL_OTHER; $this->data['objecttable'] = 'groupings'; } + + public static function get_objectid_mapping() { + return array('db' => 'groupings', 'restore' => 'grouping'); + } } diff --git a/lib/classes/event/message_contact_added.php b/lib/classes/event/message_contact_added.php index 6240f6121a2..e2b48ea0f6f 100644 --- a/lib/classes/event/message_contact_added.php +++ b/lib/classes/event/message_contact_added.php @@ -94,4 +94,9 @@ class message_contact_added extends base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + // Messaging contacts are not backed up, so no need to map them on restore. + return array('db' => 'message_contacts', 'restore' => base::NOT_MAPPED); + } } diff --git a/lib/classes/event/message_contact_blocked.php b/lib/classes/event/message_contact_blocked.php index 959f3c4ed37..da9fc4cfa61 100644 --- a/lib/classes/event/message_contact_blocked.php +++ b/lib/classes/event/message_contact_blocked.php @@ -94,4 +94,9 @@ class message_contact_blocked extends base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + // Messaging contacts are not backed up, so no need to map them on restore. + return array('db' => 'message_contacts', 'restore' => base::NOT_MAPPED); + } } diff --git a/lib/classes/event/message_contact_removed.php b/lib/classes/event/message_contact_removed.php index c87f837da0d..60000d1b7d7 100644 --- a/lib/classes/event/message_contact_removed.php +++ b/lib/classes/event/message_contact_removed.php @@ -94,4 +94,9 @@ class message_contact_removed extends base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + // Messaging contacts are not backed up, so no need to map them on restore. + return array('db' => 'message_contacts', 'restore' => base::NOT_MAPPED); + } } diff --git a/lib/classes/event/message_contact_unblocked.php b/lib/classes/event/message_contact_unblocked.php index 48f5a07a70e..417a1a6c3cc 100644 --- a/lib/classes/event/message_contact_unblocked.php +++ b/lib/classes/event/message_contact_unblocked.php @@ -94,4 +94,9 @@ class message_contact_unblocked extends base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + // Messaging contacts are not backed up, so no need to map them on restore. + return array('db' => 'message_contacts', 'restore' => base::NOT_MAPPED); + } } diff --git a/lib/classes/event/message_deleted.php b/lib/classes/event/message_deleted.php index 5d3f71bc419..7d5087e1bc4 100644 --- a/lib/classes/event/message_deleted.php +++ b/lib/classes/event/message_deleted.php @@ -142,4 +142,14 @@ class message_deleted extends base { throw new \coding_exception('The \'useridto\' value must be set in other.'); } } + + public static function get_other_mapping() { + // Messages are not backed up, so no need to map them on restore. + $othermapped = array(); + // The messageid table varies so it cannot be mapped. + $othermapped['messageid'] = array('db' => base::NOT_MAPPED, 'restore' => base::NOT_MAPPED); + $othermapped['useridfrom'] = array('db' => 'user', 'restore' => base::NOT_MAPPED); + $othermapped['useridto'] = array('db' => 'user', 'restore' => base::NOT_MAPPED); + return $othermapped; + } } diff --git a/lib/classes/event/message_sent.php b/lib/classes/event/message_sent.php index 4f11edb63ca..0d58ddbea56 100644 --- a/lib/classes/event/message_sent.php +++ b/lib/classes/event/message_sent.php @@ -144,4 +144,17 @@ class message_sent extends base { throw new \coding_exception('The \'messageid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + // Messages are not backed up, so no need to map them. + return false; + } + + public static function get_other_mapping() { + // Messages are not backed up, so no need to map them on restore. + $othermapped = array(); + // The messages table could vary for older events - so cannot be mapped. + $othermapped['messageid'] = array('db' => base::NOT_MAPPED, 'restore' => base::NOT_MAPPED); + return $othermapped; + } } diff --git a/lib/classes/event/message_viewed.php b/lib/classes/event/message_viewed.php index d5eab52e2a5..8e129475114 100644 --- a/lib/classes/event/message_viewed.php +++ b/lib/classes/event/message_viewed.php @@ -95,4 +95,17 @@ class message_viewed extends base { throw new \coding_exception('The \'messageid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + // Messages are not backed up, so no need to map them. + return array('db' => 'message_read', 'restore' => base::NOT_MAPPED); + } + + public static function get_other_mapping() { + // Messages are not backed up, so no need to map them on restore. + $othermapped = array(); + // The messages table could vary for older events - so cannot be mapped. + $othermapped['messageid'] = array('db' => base::NOT_MAPPED, 'restore' => base::NOT_MAPPED); + return $othermapped; + } } diff --git a/lib/classes/event/mnet_access_control_created.php b/lib/classes/event/mnet_access_control_created.php index 1725ddd8222..69e47cc8367 100644 --- a/lib/classes/event/mnet_access_control_created.php +++ b/lib/classes/event/mnet_access_control_created.php @@ -113,4 +113,14 @@ class mnet_access_control_created extends base { throw new \coding_exception('The \'accessctrl\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + // Mnet info is not backed up, so no need to map on restore. + return array('db' => 'mnet_sso_access_control', 'restore' => base::NOT_MAPPED); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/lib/classes/event/mnet_access_control_updated.php b/lib/classes/event/mnet_access_control_updated.php index cc8b8752351..b2e93321fa8 100644 --- a/lib/classes/event/mnet_access_control_updated.php +++ b/lib/classes/event/mnet_access_control_updated.php @@ -113,4 +113,14 @@ class mnet_access_control_updated extends base { throw new \coding_exception('The \'accessctrl\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + // Mnet info is not backed up, so no need to map on restore. + return array('db' => 'mnet_sso_access_control', 'restore' => base::NOT_MAPPED); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/lib/classes/event/note_created.php b/lib/classes/event/note_created.php index e6720eb8353..dd75b755ee2 100644 --- a/lib/classes/event/note_created.php +++ b/lib/classes/event/note_created.php @@ -106,4 +106,14 @@ class note_created extends base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + // Notes are not backed up, so no need to map on restore. + return array('db' => 'post', 'restore' => base::NOT_MAPPED); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/lib/classes/event/note_deleted.php b/lib/classes/event/note_deleted.php index 0e127cad45f..772414a0635 100644 --- a/lib/classes/event/note_deleted.php +++ b/lib/classes/event/note_deleted.php @@ -96,4 +96,14 @@ class note_deleted extends base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + // Notes are not backed up, so no need to map on restore. + return array('db' => 'post', 'restore' => base::NOT_MAPPED); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/lib/classes/event/note_updated.php b/lib/classes/event/note_updated.php index 816816b6fcb..aa28dea53a7 100644 --- a/lib/classes/event/note_updated.php +++ b/lib/classes/event/note_updated.php @@ -106,4 +106,14 @@ class note_updated extends base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + // Notes are not backed up, so no need to map on restore. + return array('db' => 'post', 'restore' => base::NOT_MAPPED); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/lib/classes/event/question_category_created.php b/lib/classes/event/question_category_created.php index 99a06fbea5f..dd011eccb83 100644 --- a/lib/classes/event/question_category_created.php +++ b/lib/classes/event/question_category_created.php @@ -96,4 +96,8 @@ class question_category_created extends base { // This is not related to individual quiz at all. return null; } + + public static function get_objectid_mapping() { + return array('db' => 'question_categories', 'restore' => 'question_category'); + } } diff --git a/lib/classes/event/role_assigned.php b/lib/classes/event/role_assigned.php index 78682dad9e8..8396a8dffa4 100644 --- a/lib/classes/event/role_assigned.php +++ b/lib/classes/event/role_assigned.php @@ -131,4 +131,16 @@ class role_assigned extends base { throw new \coding_exception('The \'component\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'role', 'restore' => 'role'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['id'] = array('db' => 'role_assignments', 'restore' => base::NOT_MAPPED); + $othermapped['itemid'] = base::NOT_MAPPED; + + return $othermapped; + } } diff --git a/lib/classes/event/role_capabilities_updated.php b/lib/classes/event/role_capabilities_updated.php index 887c8e3a22d..e94e768cb4a 100644 --- a/lib/classes/event/role_capabilities_updated.php +++ b/lib/classes/event/role_capabilities_updated.php @@ -98,4 +98,8 @@ class role_capabilities_updated extends base { protected function get_legacy_logdata() { return $this->legacylogdata; } + + public static function get_objectid_mapping() { + return array('db' => 'role', 'restore' => 'role'); + } } diff --git a/lib/classes/event/role_deleted.php b/lib/classes/event/role_deleted.php index 9b5a2e2bd0f..b2586fb1fdd 100644 --- a/lib/classes/event/role_deleted.php +++ b/lib/classes/event/role_deleted.php @@ -102,4 +102,13 @@ class role_deleted extends base { throw new \coding_exception('The \'shortname\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'role', 'restore' => 'role'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/lib/classes/event/role_unassigned.php b/lib/classes/event/role_unassigned.php index bb788c2186d..2eb34e2548f 100644 --- a/lib/classes/event/role_unassigned.php +++ b/lib/classes/event/role_unassigned.php @@ -128,4 +128,16 @@ class role_unassigned extends base { throw new \coding_exception('The \'component\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'role', 'restore' => 'role'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['id'] = array('db' => 'role_assignments', 'restore' => base::NOT_MAPPED); + $othermapped['itemid'] = base::NOT_MAPPED; + + return $othermapped; + } } diff --git a/lib/classes/event/tag_added.php b/lib/classes/event/tag_added.php index 3c7558c5ce3..6316cc35012 100644 --- a/lib/classes/event/tag_added.php +++ b/lib/classes/event/tag_added.php @@ -117,4 +117,17 @@ class tag_added extends base { throw new \coding_exception('The \'tagrawname\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + // Tags cannot be mapped. + return array('db' => 'tag_instance', 'restore' => base::NOT_MAPPED); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['tagid'] = array('db' => 'tag', 'restore' => base::NOT_MAPPED); + $othermapped['itemid'] = base::NOT_MAPPED; + + return $othermapped; + } } diff --git a/lib/classes/event/tag_created.php b/lib/classes/event/tag_created.php index 858339e840d..e239b392a74 100644 --- a/lib/classes/event/tag_created.php +++ b/lib/classes/event/tag_created.php @@ -87,4 +87,13 @@ class tag_created extends base { throw new \coding_exception('The \'rawname\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + // Tags cannot be mapped. + return array('db' => 'tag', 'restore' => base::NOT_MAPPED); + } + + public static function get_other_mapping() { + return false; + } } diff --git a/lib/classes/event/tag_deleted.php b/lib/classes/event/tag_deleted.php index 2598087a149..60fc8a74b92 100644 --- a/lib/classes/event/tag_deleted.php +++ b/lib/classes/event/tag_deleted.php @@ -87,4 +87,13 @@ class tag_deleted extends base { throw new \coding_exception('The \'rawname\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + // Tags cannot be mapped. + return array('db' => 'tag', 'restore' => base::NOT_MAPPED); + } + + public static function get_other_mapping() { + return false; + } } diff --git a/lib/classes/event/tag_flagged.php b/lib/classes/event/tag_flagged.php index 4a675fbd5f1..2f7c26b3bef 100644 --- a/lib/classes/event/tag_flagged.php +++ b/lib/classes/event/tag_flagged.php @@ -96,4 +96,13 @@ class tag_flagged extends base { throw new \coding_exception('The \'rawname\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + // Tags cannot be mapped. + return array('db' => 'tag', 'restore' => base::NOT_MAPPED); + } + + public static function get_other_mapping() { + return false; + } } diff --git a/lib/classes/event/tag_removed.php b/lib/classes/event/tag_removed.php index fe0c1cfaa9e..04558aca24e 100644 --- a/lib/classes/event/tag_removed.php +++ b/lib/classes/event/tag_removed.php @@ -103,4 +103,18 @@ class tag_removed extends base { throw new \coding_exception('The \'tagrawname\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + // Tags cannot be mapped. + return array('db' => 'tag_instance', 'restore' => base::NOT_MAPPED); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['tagid'] = array('db' => 'tag', 'restore' => base::NOT_MAPPED); + $othermapped['itemid'] = base::NOT_MAPPED; + + return $othermapped; + } + } diff --git a/lib/classes/event/tag_unflagged.php b/lib/classes/event/tag_unflagged.php index f9e43782ff5..4b6f3dd252f 100644 --- a/lib/classes/event/tag_unflagged.php +++ b/lib/classes/event/tag_unflagged.php @@ -87,4 +87,14 @@ class tag_unflagged extends base { throw new \coding_exception('The \'rawname\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + // Tags cannot be mapped. + return array('db' => 'tag', 'restore' => base::NOT_MAPPED); + } + + public static function get_other_mapping() { + return false; + } + } diff --git a/lib/classes/event/tag_updated.php b/lib/classes/event/tag_updated.php index 6ec1853e5d4..fe6b4f75399 100644 --- a/lib/classes/event/tag_updated.php +++ b/lib/classes/event/tag_updated.php @@ -112,4 +112,14 @@ class tag_updated extends base { throw new \coding_exception('The \'rawname\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + // Tags cannot be mapped. + return array('db' => 'tag', 'restore' => base::NOT_MAPPED); + } + + public static function get_other_mapping() { + return false; + } + } diff --git a/lib/classes/event/user_created.php b/lib/classes/event/user_created.php index d6aa4391e8a..2fb3200de7f 100644 --- a/lib/classes/event/user_created.php +++ b/lib/classes/event/user_created.php @@ -133,4 +133,8 @@ class user_created extends base { $event = self::create($data); return $event; } + + public static function get_objectid_mapping() { + return array('db' => 'user', 'restore' => 'user'); + } } diff --git a/lib/classes/event/user_deleted.php b/lib/classes/event/user_deleted.php index 877ec5a46cd..fc3fb85f772 100644 --- a/lib/classes/event/user_deleted.php +++ b/lib/classes/event/user_deleted.php @@ -141,4 +141,15 @@ class user_deleted extends base { throw new \coding_exception('The \'mnethostid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'user', 'restore' => 'user'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['mnethostid'] = array('db' => 'mnet_host', 'restore' => base::NOT_MAPPED); + + return $othermapped; + } } diff --git a/lib/classes/event/user_enrolment_created.php b/lib/classes/event/user_enrolment_created.php index 7f84fbc0dd8..384015a20bb 100644 --- a/lib/classes/event/user_enrolment_created.php +++ b/lib/classes/event/user_enrolment_created.php @@ -125,4 +125,13 @@ class user_enrolment_created extends base { throw new \coding_exception('The \'enrol\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + // User enrolments table is not mappable. + return array('db' => 'user_enrolments', 'restore' => base::NOT_MAPPED); + } + + public static function get_other_mapping() { + return false; + } } diff --git a/lib/classes/event/user_enrolment_deleted.php b/lib/classes/event/user_enrolment_deleted.php index 59b60ecc191..d872ec266bd 100644 --- a/lib/classes/event/user_enrolment_deleted.php +++ b/lib/classes/event/user_enrolment_deleted.php @@ -124,4 +124,13 @@ class user_enrolment_deleted extends base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + // User enrolments table is not mappable. + return array('db' => 'user_enrolments', 'restore' => base::NOT_MAPPED); + } + + public static function get_other_mapping() { + return false; + } } diff --git a/lib/classes/event/user_enrolment_updated.php b/lib/classes/event/user_enrolment_updated.php index 9d9d2e87808..d7abe4c31fd 100644 --- a/lib/classes/event/user_enrolment_updated.php +++ b/lib/classes/event/user_enrolment_updated.php @@ -114,4 +114,13 @@ class user_enrolment_updated extends base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + // User enrolments table is not mappable. + return array('db' => 'user_enrolments', 'restore' => base::NOT_MAPPED); + } + + public static function get_other_mapping() { + return false; + } } diff --git a/lib/classes/event/user_graded.php b/lib/classes/event/user_graded.php index 479b4ddd36c..98a6a955589 100644 --- a/lib/classes/event/user_graded.php +++ b/lib/classes/event/user_graded.php @@ -156,4 +156,15 @@ class user_graded extends base { throw new \coding_exception('The \'itemid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'grade_grades', 'restore' => 'grade_grades'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['itemid'] = array('db' => 'grade_items', 'restore' => 'grade_item'); + + return $othermapped; + } } diff --git a/lib/classes/event/user_list_viewed.php b/lib/classes/event/user_list_viewed.php index 002fbfe2084..ff1fec00dcb 100644 --- a/lib/classes/event/user_list_viewed.php +++ b/lib/classes/event/user_list_viewed.php @@ -88,4 +88,12 @@ class user_list_viewed extends base { protected function get_legacy_logdata() { return array($this->courseid, 'user', 'view all', 'index.php?id=' . $this->courseid, ''); } + + public static function get_objectid_mapping() { + return array('db' => 'course', 'restore' => 'course'); + } + + public static function get_other_mapping() { + return false; + } } diff --git a/lib/classes/event/user_loggedin.php b/lib/classes/event/user_loggedin.php index 53e3b765093..e199d003116 100644 --- a/lib/classes/event/user_loggedin.php +++ b/lib/classes/event/user_loggedin.php @@ -113,4 +113,12 @@ class user_loggedin extends base { throw new \coding_exception('The \'username\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'user', 'restore' => 'user'); + } + + public static function get_other_mapping() { + return false; + } } diff --git a/lib/classes/event/user_loggedinas.php b/lib/classes/event/user_loggedinas.php index 494038fd001..64c1f61e50c 100644 --- a/lib/classes/event/user_loggedinas.php +++ b/lib/classes/event/user_loggedinas.php @@ -112,4 +112,12 @@ class user_loggedinas extends base { throw new \coding_exception('The \'loggedinasusername\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'user', 'restore' => 'user'); + } + + public static function get_other_mapping() { + return false; + } } diff --git a/lib/classes/event/user_loggedout.php b/lib/classes/event/user_loggedout.php index 7131a5a38f7..e3831a53687 100644 --- a/lib/classes/event/user_loggedout.php +++ b/lib/classes/event/user_loggedout.php @@ -105,4 +105,12 @@ class user_loggedout extends base { return array(SITEID, 'user', 'logout', 'view.php?id='.$this->objectid.'&course='.SITEID, $this->objectid, 0, $this->objectid); } + + public static function get_objectid_mapping() { + return array('db' => 'user', 'restore' => 'user'); + } + + public static function get_other_mapping() { + return false; + } } diff --git a/lib/classes/event/user_login_failed.php b/lib/classes/event/user_login_failed.php index 8c8d20a25bb..1214b49df04 100644 --- a/lib/classes/event/user_login_failed.php +++ b/lib/classes/event/user_login_failed.php @@ -113,4 +113,7 @@ class user_login_failed extends base { } } + public static function get_other_mapping() { + return false; + } } diff --git a/lib/classes/event/user_password_updated.php b/lib/classes/event/user_password_updated.php index ef7dbe8b538..72aa3232b21 100644 --- a/lib/classes/event/user_password_updated.php +++ b/lib/classes/event/user_password_updated.php @@ -130,4 +130,8 @@ class user_password_updated extends base { throw new \coding_exception('The \'forgottenreset\' value must be set in other.'); } } + + public static function get_other_mapping() { + return false; + } } diff --git a/lib/classes/event/user_profile_viewed.php b/lib/classes/event/user_profile_viewed.php index d2541955606..bd6bb690cea 100644 --- a/lib/classes/event/user_profile_viewed.php +++ b/lib/classes/event/user_profile_viewed.php @@ -111,4 +111,15 @@ class user_profile_viewed extends base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'user', 'restore' => 'user'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['courseid'] = array('db' => 'course', 'restore' => 'course'); + + return $othermapped; + } } diff --git a/lib/classes/event/user_updated.php b/lib/classes/event/user_updated.php index 1e5e27ab623..52827de4037 100644 --- a/lib/classes/event/user_updated.php +++ b/lib/classes/event/user_updated.php @@ -133,4 +133,8 @@ class user_updated extends base { $event = self::create($data); return $event; } + + public static function get_objectid_mapping() { + return array('db' => 'user', 'restore' => 'user'); + } } diff --git a/lib/classes/event/webservice_function_called.php b/lib/classes/event/webservice_function_called.php index b1bde22dbc3..95618487cfd 100644 --- a/lib/classes/event/webservice_function_called.php +++ b/lib/classes/event/webservice_function_called.php @@ -105,4 +105,8 @@ class webservice_function_called extends base { throw new \coding_exception('The \'function\' value must be set in other.'); } } + + public static function get_other_mapping() { + return false; + } } diff --git a/lib/classes/event/webservice_login_failed.php b/lib/classes/event/webservice_login_failed.php index e65e6e1bba6..d372de894b5 100644 --- a/lib/classes/event/webservice_login_failed.php +++ b/lib/classes/event/webservice_login_failed.php @@ -123,4 +123,8 @@ class webservice_login_failed extends base { throw new \coding_exception('The \'token\' value must not be set in other.'); } } + + public static function get_other_mapping() { + return false; + } } diff --git a/lib/classes/event/webservice_service_created.php b/lib/classes/event/webservice_service_created.php index 6a64a6ee1c0..c8943e262be 100644 --- a/lib/classes/event/webservice_service_created.php +++ b/lib/classes/event/webservice_service_created.php @@ -91,4 +91,13 @@ class webservice_service_created extends base { $this->data['edulevel'] = self::LEVEL_OTHER; $this->data['objecttable'] = 'external_services'; } + + public static function get_objectid_mapping() { + // Webservices are not included in the backups. + return array('db' => 'external_services', 'restore' => NOT_MAPPED); + } + + public static function get_other_mapping() { + return false; + } } diff --git a/lib/classes/event/webservice_service_deleted.php b/lib/classes/event/webservice_service_deleted.php index 120dc708a0a..c61c1be45e0 100644 --- a/lib/classes/event/webservice_service_deleted.php +++ b/lib/classes/event/webservice_service_deleted.php @@ -85,4 +85,10 @@ class webservice_service_deleted extends base { $this->data['edulevel'] = self::LEVEL_OTHER; $this->data['objecttable'] = 'external_services'; } + + public static function get_objectid_mapping() { + // Webservices are not included in backups. + return array('db' => 'external_services', 'restore' => base::NOT_MAPPED); + } + } diff --git a/lib/classes/event/webservice_service_updated.php b/lib/classes/event/webservice_service_updated.php index a84f4fc20b1..a0124f57d53 100644 --- a/lib/classes/event/webservice_service_updated.php +++ b/lib/classes/event/webservice_service_updated.php @@ -85,4 +85,10 @@ class webservice_service_updated extends base { $this->data['edulevel'] = self::LEVEL_OTHER; $this->data['objecttable'] = 'external_services'; } + + public static function get_objectid_mapping() { + // Webservices are not included in backups. + return array('db' => 'external_services', 'restore' => base::NOT_MAPPED); + } + } diff --git a/lib/classes/event/webservice_service_user_added.php b/lib/classes/event/webservice_service_user_added.php index 2d423782ec6..ca646446494 100644 --- a/lib/classes/event/webservice_service_user_added.php +++ b/lib/classes/event/webservice_service_user_added.php @@ -98,4 +98,10 @@ class webservice_service_user_added extends base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + // Webservices are not included in backups. + return array('db' => 'external_services', 'restore' => base::NOT_MAPPED); + } + } diff --git a/lib/classes/event/webservice_service_user_removed.php b/lib/classes/event/webservice_service_user_removed.php index 50ae27c472b..a812041aa0d 100644 --- a/lib/classes/event/webservice_service_user_removed.php +++ b/lib/classes/event/webservice_service_user_removed.php @@ -98,4 +98,10 @@ class webservice_service_user_removed extends base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + // Webservices are not included in backups. + return array('db' => 'external_services', 'restore' => base::NOT_MAPPED); + } + } diff --git a/lib/classes/event/webservice_token_created.php b/lib/classes/event/webservice_token_created.php index a816dbead50..8b8a9470b15 100644 --- a/lib/classes/event/webservice_token_created.php +++ b/lib/classes/event/webservice_token_created.php @@ -108,4 +108,13 @@ class webservice_token_created extends base { throw new \coding_exception('The \'auto\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + // Webservices are not included in backups. + return array('db' => 'external_tokens', 'restore' => base::NOT_MAPPED); + } + + public static function get_other_mapping() { + return false; + } } diff --git a/lib/classes/event/webservice_token_sent.php b/lib/classes/event/webservice_token_sent.php index f9d9f21c3e6..4f89d46d714 100644 --- a/lib/classes/event/webservice_token_sent.php +++ b/lib/classes/event/webservice_token_sent.php @@ -73,4 +73,9 @@ class webservice_token_sent extends base { $this->data['edulevel'] = self::LEVEL_OTHER; $this->data['objecttable'] = 'external_tokens'; } + + public static function get_objectid_mapping() { + // Webservices are not included in backups. + return array('db' => 'external_tokens', 'restore' => base::NOT_MAPPED); + } } diff --git a/mod/assign/classes/event/all_submissions_downloaded.php b/mod/assign/classes/event/all_submissions_downloaded.php index 541e40757bd..09b6c824112 100644 --- a/mod/assign/classes/event/all_submissions_downloaded.php +++ b/mod/assign/classes/event/all_submissions_downloaded.php @@ -115,4 +115,8 @@ class all_submissions_downloaded extends base { parent::validate_data(); } + + public static function get_objectid_mapping() { + return array('db' => 'assign', 'restore' => 'assign'); + } } diff --git a/mod/assign/classes/event/assessable_submitted.php b/mod/assign/classes/event/assessable_submitted.php index b1e16e51cab..c26375cd0f1 100644 --- a/mod/assign/classes/event/assessable_submitted.php +++ b/mod/assign/classes/event/assessable_submitted.php @@ -150,4 +150,13 @@ class assessable_submitted extends base { throw new \coding_exception('The \'submission_editable\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'assign_submission', 'restore' => 'submission'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/mod/assign/classes/event/batch_set_marker_allocation_viewed.php b/mod/assign/classes/event/batch_set_marker_allocation_viewed.php index 510549d22a9..9481b0cb950 100644 --- a/mod/assign/classes/event/batch_set_marker_allocation_viewed.php +++ b/mod/assign/classes/event/batch_set_marker_allocation_viewed.php @@ -123,4 +123,11 @@ class batch_set_marker_allocation_viewed extends base { throw new \coding_exception('The \'assignid\' value must be set in other.'); } } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign'); + + return $othermapped; + } } diff --git a/mod/assign/classes/event/batch_set_workflow_state_viewed.php b/mod/assign/classes/event/batch_set_workflow_state_viewed.php index b4b5c2511e8..b91c04537ea 100644 --- a/mod/assign/classes/event/batch_set_workflow_state_viewed.php +++ b/mod/assign/classes/event/batch_set_workflow_state_viewed.php @@ -123,4 +123,11 @@ class batch_set_workflow_state_viewed extends base { throw new \coding_exception('The \'assignid\' value must be set in other.'); } } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign'); + + return $othermapped; + } } diff --git a/mod/assign/classes/event/extension_granted.php b/mod/assign/classes/event/extension_granted.php index 3ed455830c0..51c4a9f7a5b 100644 --- a/mod/assign/classes/event/extension_granted.php +++ b/mod/assign/classes/event/extension_granted.php @@ -121,4 +121,8 @@ class extension_granted extends base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'assign', 'restore' => 'assign'); + } } diff --git a/mod/assign/classes/event/feedback_viewed.php b/mod/assign/classes/event/feedback_viewed.php index 37e0359ef6a..93d6aea615a 100644 --- a/mod/assign/classes/event/feedback_viewed.php +++ b/mod/assign/classes/event/feedback_viewed.php @@ -119,4 +119,15 @@ class feedback_viewed extends base { throw new \coding_exception('The \'assignid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'assign_grades', 'restore' => 'grade'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign'); + + return $othermapped; + } } diff --git a/mod/assign/classes/event/grading_form_viewed.php b/mod/assign/classes/event/grading_form_viewed.php index 6ee48c20365..dfa6b94bcc0 100644 --- a/mod/assign/classes/event/grading_form_viewed.php +++ b/mod/assign/classes/event/grading_form_viewed.php @@ -131,4 +131,11 @@ class grading_form_viewed extends base { throw new \coding_exception('The \'assignid\' value must be set in other.'); } } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign'); + + return $othermapped; + } } diff --git a/mod/assign/classes/event/grading_table_viewed.php b/mod/assign/classes/event/grading_table_viewed.php index e3bd463bc97..464e8b02c56 100644 --- a/mod/assign/classes/event/grading_table_viewed.php +++ b/mod/assign/classes/event/grading_table_viewed.php @@ -123,4 +123,11 @@ class grading_table_viewed extends base { throw new \coding_exception('The \'assignid\' value must be set in other.'); } } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign'); + + return $othermapped; + } } diff --git a/mod/assign/classes/event/identities_revealed.php b/mod/assign/classes/event/identities_revealed.php index 339a6f4ea3a..983ce4f0b69 100644 --- a/mod/assign/classes/event/identities_revealed.php +++ b/mod/assign/classes/event/identities_revealed.php @@ -115,4 +115,8 @@ class identities_revealed extends base { parent::validate_data(); } + + public static function get_objectid_mapping() { + return array('db' => 'assign', 'restore' => 'assign'); + } } diff --git a/mod/assign/classes/event/marker_updated.php b/mod/assign/classes/event/marker_updated.php index 64b50840e00..761afc29cb0 100644 --- a/mod/assign/classes/event/marker_updated.php +++ b/mod/assign/classes/event/marker_updated.php @@ -140,4 +140,15 @@ class marker_updated extends base { throw new \coding_exception('The \'markerid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'assign', 'restore' => 'assign'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['markerid'] = array('db' => 'user', 'restore' => 'user'); + + return $othermapped; + } } diff --git a/mod/assign/classes/event/reveal_identities_confirmation_page_viewed.php b/mod/assign/classes/event/reveal_identities_confirmation_page_viewed.php index 34913303588..922ec3b65c5 100644 --- a/mod/assign/classes/event/reveal_identities_confirmation_page_viewed.php +++ b/mod/assign/classes/event/reveal_identities_confirmation_page_viewed.php @@ -122,4 +122,11 @@ class reveal_identities_confirmation_page_viewed extends base { throw new \coding_exception('The \'assignid\' value must be set in other.'); } } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign'); + + return $othermapped; + } } diff --git a/mod/assign/classes/event/statement_accepted.php b/mod/assign/classes/event/statement_accepted.php index ec5d59cf36b..9212c9b3fa0 100644 --- a/mod/assign/classes/event/statement_accepted.php +++ b/mod/assign/classes/event/statement_accepted.php @@ -119,4 +119,8 @@ class statement_accepted extends base { parent::validate_data(); } + + public static function get_objectid_mapping() { + return array('db' => 'assign_submission', 'restore' => 'submission'); + } } diff --git a/mod/assign/classes/event/submission_confirmation_form_viewed.php b/mod/assign/classes/event/submission_confirmation_form_viewed.php index 833d2801b0a..727b811d3c5 100644 --- a/mod/assign/classes/event/submission_confirmation_form_viewed.php +++ b/mod/assign/classes/event/submission_confirmation_form_viewed.php @@ -123,4 +123,11 @@ class submission_confirmation_form_viewed extends base { throw new \coding_exception('The \'assignid\' value must be set in other.'); } } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign'); + + return $othermapped; + } } diff --git a/mod/assign/classes/event/submission_created.php b/mod/assign/classes/event/submission_created.php index c420ce38255..81fe71b3bc2 100644 --- a/mod/assign/classes/event/submission_created.php +++ b/mod/assign/classes/event/submission_created.php @@ -81,4 +81,12 @@ abstract class submission_created extends base { throw new \coding_exception('The \'submissionstatus\' value must be set in other.'); } } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['submissionid'] = array('db' => 'assign_submission', 'restore' => 'submission'); + $othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group'); + + return $othermapped; + } } diff --git a/mod/assign/classes/event/submission_duplicated.php b/mod/assign/classes/event/submission_duplicated.php index ac7875c2699..e2020b4fc6e 100644 --- a/mod/assign/classes/event/submission_duplicated.php +++ b/mod/assign/classes/event/submission_duplicated.php @@ -117,4 +117,8 @@ class submission_duplicated extends base { parent::validate_data(); } + + public static function get_objectid_mapping() { + return array('db' => 'assign_submission', 'restore' => 'submission'); + } } diff --git a/mod/assign/classes/event/submission_form_viewed.php b/mod/assign/classes/event/submission_form_viewed.php index bea0352a28e..fc2de8880e1 100644 --- a/mod/assign/classes/event/submission_form_viewed.php +++ b/mod/assign/classes/event/submission_form_viewed.php @@ -139,4 +139,11 @@ class submission_form_viewed extends base { throw new \coding_exception('The \'assignid\' value must be set in other.'); } } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign'); + + return $othermapped; + } } diff --git a/mod/assign/classes/event/submission_graded.php b/mod/assign/classes/event/submission_graded.php index 8e16305a0b7..a6b0853cf0a 100644 --- a/mod/assign/classes/event/submission_graded.php +++ b/mod/assign/classes/event/submission_graded.php @@ -123,4 +123,8 @@ class submission_graded extends base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'assign_grades', 'restore' => 'grade'); + } } diff --git a/mod/assign/classes/event/submission_locked.php b/mod/assign/classes/event/submission_locked.php index 3aaf9277e54..32d99a0cc67 100644 --- a/mod/assign/classes/event/submission_locked.php +++ b/mod/assign/classes/event/submission_locked.php @@ -123,4 +123,8 @@ class submission_locked extends base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'assign', 'restore' => 'assign'); + } } diff --git a/mod/assign/classes/event/submission_status_updated.php b/mod/assign/classes/event/submission_status_updated.php index 5609e169add..16297169795 100644 --- a/mod/assign/classes/event/submission_status_updated.php +++ b/mod/assign/classes/event/submission_status_updated.php @@ -121,4 +121,13 @@ class submission_status_updated extends base { throw new \coding_exception('The \'newstatus\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'assign_submission', 'restore' => 'submission'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/mod/assign/classes/event/submission_status_viewed.php b/mod/assign/classes/event/submission_status_viewed.php index 898042d04c6..532cd150898 100644 --- a/mod/assign/classes/event/submission_status_viewed.php +++ b/mod/assign/classes/event/submission_status_viewed.php @@ -124,4 +124,11 @@ class submission_status_viewed extends base { throw new \coding_exception('The \'assignid\' value must be set in other.'); } } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign'); + + return $othermapped; + } } diff --git a/mod/assign/classes/event/submission_unlocked.php b/mod/assign/classes/event/submission_unlocked.php index c4610686453..eba152a1943 100644 --- a/mod/assign/classes/event/submission_unlocked.php +++ b/mod/assign/classes/event/submission_unlocked.php @@ -123,4 +123,8 @@ class submission_unlocked extends base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'assign', 'restore' => 'assign'); + } } diff --git a/mod/assign/classes/event/submission_updated.php b/mod/assign/classes/event/submission_updated.php index deb2e13feb4..2e38625e445 100644 --- a/mod/assign/classes/event/submission_updated.php +++ b/mod/assign/classes/event/submission_updated.php @@ -81,4 +81,12 @@ abstract class submission_updated extends base { throw new \coding_exception('The \'submissionstatus\' value must be set in other.'); } } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['submissionid'] = array('db' => 'assign_submission', 'restore' => 'submission'); + $othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group'); + + return $othermapped; + } } diff --git a/mod/assign/classes/event/submission_viewed.php b/mod/assign/classes/event/submission_viewed.php index e0956ab10c8..4793786c23f 100644 --- a/mod/assign/classes/event/submission_viewed.php +++ b/mod/assign/classes/event/submission_viewed.php @@ -119,4 +119,15 @@ class submission_viewed extends base { throw new \coding_exception('The \'assignid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'assign_submission', 'restore' => 'submission'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign'); + + return $othermapped; + } } diff --git a/mod/assign/classes/event/workflow_state_updated.php b/mod/assign/classes/event/workflow_state_updated.php index cfba9dbb1e8..5928f537159 100644 --- a/mod/assign/classes/event/workflow_state_updated.php +++ b/mod/assign/classes/event/workflow_state_updated.php @@ -138,4 +138,13 @@ class workflow_state_updated extends base { throw new \coding_exception('The \'newstate\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'assign', 'restore' => 'assign'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/mod/assign/submission/file/classes/event/assessable_uploaded.php b/mod/assign/submission/file/classes/event/assessable_uploaded.php index 3c60a8da222..06f7fdbc539 100644 --- a/mod/assign/submission/file/classes/event/assessable_uploaded.php +++ b/mod/assign/submission/file/classes/event/assessable_uploaded.php @@ -120,4 +120,7 @@ class assessable_uploaded extends \core\event\assessable_uploaded { $this->data['objecttable'] = 'assign_submission'; } + public static function get_objectid_mapping() { + return array('db' => 'assign_submission', 'restore' => 'submission'); + } } diff --git a/mod/assign/submission/file/classes/event/submission_created.php b/mod/assign/submission/file/classes/event/submission_created.php index a788a119ff4..fe8fc66dc9d 100644 --- a/mod/assign/submission/file/classes/event/submission_created.php +++ b/mod/assign/submission/file/classes/event/submission_created.php @@ -80,4 +80,9 @@ class submission_created extends \mod_assign\event\submission_created { throw new \coding_exception('The \'filesubmissioncount\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + // No mapping available for 'assignsubmission_file'. + return array('db' => 'assignsubmission_file', 'restore' => \core\event\base::NOT_MAPPED); + } } diff --git a/mod/assign/submission/file/classes/event/submission_updated.php b/mod/assign/submission/file/classes/event/submission_updated.php index 65e8b542607..8e1dec63ee9 100644 --- a/mod/assign/submission/file/classes/event/submission_updated.php +++ b/mod/assign/submission/file/classes/event/submission_updated.php @@ -80,4 +80,9 @@ class submission_updated extends \mod_assign\event\submission_updated { throw new \coding_exception('The \'filesubmissioncount\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + // No mapping available for 'assignsubmission_file'. + return array('db' => 'assignsubmission_file', 'restore' => \core\event\base::NOT_MAPPED); + } } diff --git a/mod/assign/submission/onlinetext/classes/event/assessable_uploaded.php b/mod/assign/submission/onlinetext/classes/event/assessable_uploaded.php index aae666be45b..d1ef0766f2c 100644 --- a/mod/assign/submission/onlinetext/classes/event/assessable_uploaded.php +++ b/mod/assign/submission/onlinetext/classes/event/assessable_uploaded.php @@ -107,4 +107,8 @@ class assessable_uploaded extends \core\event\assessable_uploaded { parent::init(); $this->data['objecttable'] = 'assign_submission'; } + + public static function get_objectid_mapping() { + return array('db' => 'assign_submission', 'restore' => 'submission'); + } } diff --git a/mod/assign/submission/onlinetext/classes/event/submission_created.php b/mod/assign/submission/onlinetext/classes/event/submission_created.php index f730d32db1a..2a2b930b438 100644 --- a/mod/assign/submission/onlinetext/classes/event/submission_created.php +++ b/mod/assign/submission/onlinetext/classes/event/submission_created.php @@ -47,7 +47,7 @@ class submission_created extends \mod_assign\event\submission_created { */ protected function init() { parent::init(); - $this->data['objecttable'] = 'assignsubmission_file'; + $this->data['objecttable'] = 'assignsubmission_onlinetext'; } /** @@ -80,4 +80,9 @@ class submission_created extends \mod_assign\event\submission_created { throw new \coding_exception('The \'onlinetextwordcount\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + // No mapping available for 'assignsubmission_onlinetext'. + return array('db' => 'assignsubmission_onlinetext', 'restore' => \core\event\base::NOT_MAPPED); + } } diff --git a/mod/assign/submission/onlinetext/classes/event/submission_updated.php b/mod/assign/submission/onlinetext/classes/event/submission_updated.php index 356d3a66514..8edad4c4a49 100644 --- a/mod/assign/submission/onlinetext/classes/event/submission_updated.php +++ b/mod/assign/submission/onlinetext/classes/event/submission_updated.php @@ -47,7 +47,7 @@ class submission_updated extends \mod_assign\event\submission_updated { */ protected function init() { parent::init(); - $this->data['objecttable'] = 'assignsubmission_file'; + $this->data['objecttable'] = 'assignsubmission_onlinetext'; } /** @@ -80,4 +80,9 @@ class submission_updated extends \mod_assign\event\submission_updated { throw new \coding_exception('The \'onlinetextwordcount\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + // No mapping available for 'assignsubmission_onlinetext'. + return array('db' => 'assignsubmission_onlinetext', 'restore' => \core\event\base::NOT_MAPPED); + } } diff --git a/mod/book/classes/event/chapter_created.php b/mod/book/classes/event/chapter_created.php index 0fd344c572d..0adef111a40 100644 --- a/mod/book/classes/event/chapter_created.php +++ b/mod/book/classes/event/chapter_created.php @@ -108,4 +108,7 @@ class chapter_created extends \core\event\base { $this->data['objecttable'] = 'book_chapters'; } + public static function get_objectid_mapping() { + return array('db' => 'book_chapters', 'restore' => 'book_chapter'); + } } diff --git a/mod/book/classes/event/chapter_deleted.php b/mod/book/classes/event/chapter_deleted.php index b53a9d0264d..c58c04ae96c 100644 --- a/mod/book/classes/event/chapter_deleted.php +++ b/mod/book/classes/event/chapter_deleted.php @@ -104,4 +104,8 @@ class chapter_deleted extends \core\event\base { $this->data['edulevel'] = self::LEVEL_TEACHING; $this->data['objecttable'] = 'book_chapters'; } + + public static function get_objectid_mapping() { + return array('db' => 'book_chapters', 'restore' => 'book_chapter'); + } } diff --git a/mod/book/classes/event/chapter_updated.php b/mod/book/classes/event/chapter_updated.php index c577e4efce4..7f8580c82a0 100644 --- a/mod/book/classes/event/chapter_updated.php +++ b/mod/book/classes/event/chapter_updated.php @@ -108,4 +108,7 @@ class chapter_updated extends \core\event\base { $this->data['objecttable'] = 'book_chapters'; } + public static function get_objectid_mapping() { + return array('db' => 'book_chapters', 'restore' => 'book_chapter'); + } } diff --git a/mod/book/classes/event/chapter_viewed.php b/mod/book/classes/event/chapter_viewed.php index 6d5bb0056a0..7a0fc782418 100644 --- a/mod/book/classes/event/chapter_viewed.php +++ b/mod/book/classes/event/chapter_viewed.php @@ -104,4 +104,8 @@ class chapter_viewed extends \core\event\base { $this->data['edulevel'] = self::LEVEL_PARTICIPATING; $this->data['objecttable'] = 'book_chapters'; } + + public static function get_objectid_mapping() { + return array('db' => 'book_chapters', 'restore' => 'book_chapter'); + } } diff --git a/mod/book/classes/event/course_module_viewed.php b/mod/book/classes/event/course_module_viewed.php index d24eceb3575..f6ecdb9ee3b 100644 --- a/mod/book/classes/event/course_module_viewed.php +++ b/mod/book/classes/event/course_module_viewed.php @@ -64,4 +64,8 @@ class course_module_viewed extends \core\event\course_module_viewed { $this->data['edulevel'] = self::LEVEL_PARTICIPATING; $this->data['objecttable'] = 'book'; } + + public static function get_objectid_mapping() { + return array('db' => 'book', 'restore' => 'book'); + } } diff --git a/mod/book/tool/exportimscp/classes/event/book_exported.php b/mod/book/tool/exportimscp/classes/event/book_exported.php index 08d5a442596..08b63fdac50 100644 --- a/mod/book/tool/exportimscp/classes/event/book_exported.php +++ b/mod/book/tool/exportimscp/classes/event/book_exported.php @@ -102,4 +102,7 @@ class book_exported extends \core\event\base { $this->data['objecttable'] = 'book'; } + public static function get_objectid_mapping() { + return array('db' => 'book', 'restore' => 'book'); + } } diff --git a/mod/book/tool/print/classes/event/book_printed.php b/mod/book/tool/print/classes/event/book_printed.php index ef11cbd410f..62d91b184df 100644 --- a/mod/book/tool/print/classes/event/book_printed.php +++ b/mod/book/tool/print/classes/event/book_printed.php @@ -102,4 +102,7 @@ class book_printed extends \core\event\base { $this->data['objecttable'] = 'book'; } + public static function get_objectid_mapping() { + return array('db' => 'book', 'restore' => 'book'); + } } diff --git a/mod/book/tool/print/classes/event/chapter_printed.php b/mod/book/tool/print/classes/event/chapter_printed.php index 8f83074c74c..c0c3b7ade77 100644 --- a/mod/book/tool/print/classes/event/chapter_printed.php +++ b/mod/book/tool/print/classes/event/chapter_printed.php @@ -102,7 +102,10 @@ class chapter_printed extends \core\event\base { protected function init() { $this->data['crud'] = 'r'; $this->data['edulevel'] = self::LEVEL_PARTICIPATING; - $this->data['objecttable'] = 'book'; + $this->data['objecttable'] = 'book_chapters'; } + public static function get_objectid_mapping() { + return array('db' => 'book_chapters', 'restore' => 'book_chapter'); + } } diff --git a/mod/chat/classes/event/course_module_viewed.php b/mod/chat/classes/event/course_module_viewed.php index 21fc8f8bac7..854699262a5 100644 --- a/mod/chat/classes/event/course_module_viewed.php +++ b/mod/chat/classes/event/course_module_viewed.php @@ -40,4 +40,8 @@ class course_module_viewed extends \core\event\course_module_viewed { $this->data['edulevel'] = self::LEVEL_PARTICIPATING; $this->data['objecttable'] = 'chat'; } + + public static function get_objectid_mapping() { + return array('db' => 'chat', 'restore' => 'chat'); + } } diff --git a/mod/chat/classes/event/message_sent.php b/mod/chat/classes/event/message_sent.php index 5b14c348423..8397bb50905 100644 --- a/mod/chat/classes/event/message_sent.php +++ b/mod/chat/classes/event/message_sent.php @@ -97,4 +97,8 @@ class message_sent extends \core\event\base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'chat_messages', 'restore' => 'chat_message'); + } } diff --git a/mod/chat/classes/event/sessions_viewed.php b/mod/chat/classes/event/sessions_viewed.php index 8b369bfec52..b2ec0c4431b 100644 --- a/mod/chat/classes/event/sessions_viewed.php +++ b/mod/chat/classes/event/sessions_viewed.php @@ -107,4 +107,12 @@ class sessions_viewed extends \core\event\base { } } + public static function get_objectid_mapping() { + return array('db' => 'chat', 'restore' => 'chat'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/mod/choice/classes/event/answer_submitted.php b/mod/choice/classes/event/answer_submitted.php index 323bdc52510..baa6817b44f 100644 --- a/mod/choice/classes/event/answer_submitted.php +++ b/mod/choice/classes/event/answer_submitted.php @@ -93,6 +93,10 @@ class answer_submitted extends \core\event\base { * @return void */ protected function init() { + // The objecttable here is wrong. We are submitting an answer, not a choice activity. + // This also makes the description misleading as it states we made a choice with id + // '$this->objectid' which just refers to the 'choice' table. The trigger for + // this event should be triggered after we insert to the 'choice_answers' table. $this->data['crud'] = 'c'; $this->data['edulevel'] = self::LEVEL_PARTICIPATING; $this->data['objecttable'] = 'choice'; @@ -111,4 +115,22 @@ class answer_submitted extends \core\event\base { throw new \coding_exception('The \'choiceid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'choice', 'restore' => 'choice'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['choiceid'] = array('db' => 'choice', 'restore' => 'choice'); + + // The 'optionid' is being passed as an array, so we can't map it. The event is + // triggered each time a choice is answered, where it may be possible to select + // multiple choices, so the value is converted to an array, which is then passed + // to the event. Ideally this event should be triggered every time we insert to the + // 'choice_answers' table so this will only be an int. + $othermapped['optionid'] = \core\event\base::NOT_MAPPED; + + return $othermapped; + } } diff --git a/mod/choice/classes/event/answer_updated.php b/mod/choice/classes/event/answer_updated.php index 3f205b89383..e6ab08a87d4 100644 --- a/mod/choice/classes/event/answer_updated.php +++ b/mod/choice/classes/event/answer_updated.php @@ -93,6 +93,10 @@ class answer_updated extends \core\event\base { * @return void */ protected function init() { + // The objecttable here is wrong. We are updating an answer, not a choice activity. + // This also makes the description misleading as it states we made a choice with id + // '$this->objectid' which just refers to the 'choice' table. The trigger for + // this event should be triggered after we update the 'choice_answers' table. $this->data['crud'] = 'u'; $this->data['edulevel'] = self::LEVEL_PARTICIPATING; $this->data['objecttable'] = 'choice'; @@ -111,4 +115,22 @@ class answer_updated extends \core\event\base { throw new \coding_exception('The \'choiceid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'choice', 'restore' => 'choice'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['choiceid'] = array('db' => 'choice', 'restore' => 'choice'); + + // The 'optionid' is being passed as an array, so we can't map it. The event is + // triggered each time a choice is answered, where it may be possible to select + // multiple choices, so the value is converted to an array, which is then passed + // to the event. Ideally this event should be triggered every time we update the + // 'choice_answers' table so this will only be an int. + $othermapped['optionid'] = \core\event\base::NOT_MAPPED; + + return $othermapped; + } } diff --git a/mod/choice/classes/event/course_module_viewed.php b/mod/choice/classes/event/course_module_viewed.php index 5069a89e583..7ccad4911d6 100644 --- a/mod/choice/classes/event/course_module_viewed.php +++ b/mod/choice/classes/event/course_module_viewed.php @@ -43,4 +43,8 @@ class course_module_viewed extends \core\event\course_module_viewed { $this->data['edulevel'] = self::LEVEL_PARTICIPATING; $this->data['objecttable'] = 'choice'; } + + public static function get_objectid_mapping() { + return array('db' => 'choice', 'restore' => 'choice'); + } } diff --git a/mod/choice/classes/event/report_viewed.php b/mod/choice/classes/event/report_viewed.php index 4611427728f..3e3f97d9194 100644 --- a/mod/choice/classes/event/report_viewed.php +++ b/mod/choice/classes/event/report_viewed.php @@ -28,6 +28,12 @@ defined('MOODLE_INTERNAL') || die(); /** * The mod_choice report viewed event class. * + * @property-read array $other { + * Extra information about the event. + * + * - string content: (optional) The content we are viewing. + * } + * * @package mod_choice * @since Moodle 2.6 * @copyright 2013 Adrian Greeve @@ -80,4 +86,13 @@ class report_viewed extends \core\event\base { $url = new \moodle_url('report.php', array('id' => $this->contextinstanceid)); return array($this->courseid, 'choice', 'report', $url->out(), $this->objectid, $this->contextinstanceid); } + + public static function get_objectid_mapping() { + return array('db' => 'choice', 'restore' => 'choice'); + } + + public static function get_other_mapping() { + // No need to map the 'content' value. + return false; + } } diff --git a/mod/data/classes/event/course_module_viewed.php b/mod/data/classes/event/course_module_viewed.php index a3feffaa032..46cbca9df28 100644 --- a/mod/data/classes/event/course_module_viewed.php +++ b/mod/data/classes/event/course_module_viewed.php @@ -47,4 +47,8 @@ class course_module_viewed extends \core\event\course_module_viewed { $this->data['crud'] = 'r'; $this->data['edulevel'] = self::LEVEL_PARTICIPATING; } + + public static function get_objectid_mapping() { + return array('db' => 'data', 'restore' => 'data'); + } } diff --git a/mod/data/classes/event/field_created.php b/mod/data/classes/event/field_created.php index 20847246aa1..dc1bb0e0ec6 100644 --- a/mod/data/classes/event/field_created.php +++ b/mod/data/classes/event/field_created.php @@ -110,4 +110,15 @@ class field_created extends \core\event\base { throw new \coding_exception('The \'dataid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'data_fields', 'restore' => 'data_field'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['dataid'] = array('db' => 'data', 'restore' => 'data'); + + return $othermapped; + } } diff --git a/mod/data/classes/event/field_deleted.php b/mod/data/classes/event/field_deleted.php index ff597eb2cf9..4a6b4af135f 100644 --- a/mod/data/classes/event/field_deleted.php +++ b/mod/data/classes/event/field_deleted.php @@ -109,4 +109,15 @@ class field_deleted extends \core\event\base { throw new \coding_exception('The \'dataid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'data_fields', 'restore' => 'data_field'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['dataid'] = array('db' => 'data', 'restore' => 'data'); + + return $othermapped; + } } diff --git a/mod/data/classes/event/field_updated.php b/mod/data/classes/event/field_updated.php index 416dad0715c..0f35080a514 100644 --- a/mod/data/classes/event/field_updated.php +++ b/mod/data/classes/event/field_updated.php @@ -109,4 +109,15 @@ class field_updated extends \core\event\base { throw new \coding_exception('The \'dataid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'data_fields', 'restore' => 'data_field'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['dataid'] = array('db' => 'data', 'restore' => 'data'); + + return $othermapped; + } } diff --git a/mod/data/classes/event/record_created.php b/mod/data/classes/event/record_created.php index f90465d3276..d0c15af0cbf 100644 --- a/mod/data/classes/event/record_created.php +++ b/mod/data/classes/event/record_created.php @@ -104,4 +104,15 @@ class record_created extends \core\event\base { throw new \coding_exception('The \'dataid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'data_records', 'restore' => 'data_record'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['dataid'] = array('db' => 'data', 'restore' => 'data'); + + return $othermapped; + } } diff --git a/mod/data/classes/event/record_deleted.php b/mod/data/classes/event/record_deleted.php index cbaafd9a1ba..58356ad926f 100644 --- a/mod/data/classes/event/record_deleted.php +++ b/mod/data/classes/event/record_deleted.php @@ -104,4 +104,15 @@ class record_deleted extends \core\event\base { throw new \coding_exception('The \'dataid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'data_records', 'restore' => 'data_record'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['dataid'] = array('db' => 'data', 'restore' => 'data'); + + return $othermapped; + } } diff --git a/mod/data/classes/event/record_updated.php b/mod/data/classes/event/record_updated.php index baa6ed5c46b..b053d12df3d 100644 --- a/mod/data/classes/event/record_updated.php +++ b/mod/data/classes/event/record_updated.php @@ -104,4 +104,15 @@ class record_updated extends \core\event\base { throw new \coding_exception('The \'dataid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'data_records', 'restore' => 'data_record'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['dataid'] = array('db' => 'data', 'restore' => 'data'); + + return $othermapped; + } } diff --git a/mod/data/classes/event/template_updated.php b/mod/data/classes/event/template_updated.php index 78211b3cc5b..e484e51da11 100644 --- a/mod/data/classes/event/template_updated.php +++ b/mod/data/classes/event/template_updated.php @@ -104,4 +104,11 @@ class template_updated extends \core\event\base { throw new \coding_exception('The \'dataid\' value must be set in other.'); } } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['dataid'] = array('db' => 'data', 'restore' => 'data'); + + return $othermapped; + } } diff --git a/mod/data/classes/event/template_viewed.php b/mod/data/classes/event/template_viewed.php index a9a385e94ff..00f921749ee 100644 --- a/mod/data/classes/event/template_viewed.php +++ b/mod/data/classes/event/template_viewed.php @@ -103,4 +103,11 @@ class template_viewed extends \core\event\base { throw new \coding_exception('The \'dataid\' value must be set in other.'); } } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['dataid'] = array('db' => 'data', 'restore' => 'data'); + + return $othermapped; + } } diff --git a/mod/feedback/classes/event/course_module_viewed.php b/mod/feedback/classes/event/course_module_viewed.php index ad9585bc061..056a20d620b 100644 --- a/mod/feedback/classes/event/course_module_viewed.php +++ b/mod/feedback/classes/event/course_module_viewed.php @@ -98,5 +98,14 @@ class course_module_viewed extends \core\event\course_module_viewed { throw new \coding_exception('The \'anonymous\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'feedback', 'restore' => 'feedback'); + } + + public static function get_other_mapping() { + // No need to map the 'anonymous' flag. + return false; + } } diff --git a/mod/feedback/classes/event/response_deleted.php b/mod/feedback/classes/event/response_deleted.php index 00a1105a722..b5d583cd7b0 100644 --- a/mod/feedback/classes/event/response_deleted.php +++ b/mod/feedback/classes/event/response_deleted.php @@ -126,5 +126,17 @@ class response_deleted extends \core\event\base { throw new \coding_exception('The \'instanceid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'feedback_completed', 'restore' => 'feedback_completed'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['cmid'] = array('db' => 'course_modules', 'restore' => 'course_module'); + $othermapped['instanceid'] = array('db' => 'feedback', 'restore' => 'feedback'); + + return $othermapped; + } } diff --git a/mod/feedback/classes/event/response_submitted.php b/mod/feedback/classes/event/response_submitted.php index acd1dcc7fea..b9a6fa39d26 100644 --- a/mod/feedback/classes/event/response_submitted.php +++ b/mod/feedback/classes/event/response_submitted.php @@ -148,5 +148,17 @@ class response_submitted extends \core\event\base { throw new \coding_exception('The \'instanceid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'feedback_completed', 'restore' => 'feedback_completed'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['cmid'] = array('db' => 'course_modules', 'restore' => 'course_module'); + $othermapped['instanceid'] = array('db' => 'feedback', 'restore' => 'feedback'); + + return $othermapped; + } } diff --git a/mod/folder/classes/event/course_module_viewed.php b/mod/folder/classes/event/course_module_viewed.php index 475c72fcd7e..e39fff9c873 100644 --- a/mod/folder/classes/event/course_module_viewed.php +++ b/mod/folder/classes/event/course_module_viewed.php @@ -44,4 +44,8 @@ class course_module_viewed extends \core\event\course_module_viewed { $this->data['edulevel'] = self::LEVEL_PARTICIPATING; $this->data['objecttable'] = 'folder'; } + + public static function get_objectid_mapping() { + return array('db' => 'folder', 'restore' => 'folder'); + } } diff --git a/mod/folder/classes/event/folder_updated.php b/mod/folder/classes/event/folder_updated.php index 2b744f45ef8..d3a20e84361 100644 --- a/mod/folder/classes/event/folder_updated.php +++ b/mod/folder/classes/event/folder_updated.php @@ -81,4 +81,8 @@ class folder_updated extends \core\event\base { return array($this->courseid, 'folder', 'edit', 'edit.php?id=' . $this->contextinstanceid, $this->objectid, $this->contextinstanceid); } + + public static function get_objectid_mapping() { + return array('db' => 'folder', 'restore' => 'folder'); + } } diff --git a/mod/forum/backup/moodle2/restore_forum_stepslib.php b/mod/forum/backup/moodle2/restore_forum_stepslib.php index f76a7c4adcd..4eb0bc31813 100644 --- a/mod/forum/backup/moodle2/restore_forum_stepslib.php +++ b/mod/forum/backup/moodle2/restore_forum_stepslib.php @@ -149,6 +149,8 @@ class restore_forum_activity_structure_step extends restore_activity_structure_s $data->userid = $this->get_mappingid('user', $data->userid); $newitemid = $DB->insert_record('forum_subscriptions', $data); + $this->set_mapping('forum_subscription', $oldid, $newitemid, true); + } protected function process_forum_discussion_sub($data) { @@ -162,6 +164,7 @@ class restore_forum_activity_structure_step extends restore_activity_structure_s $data->userid = $this->get_mappingid('user', $data->userid); $newitemid = $DB->insert_record('forum_discussion_subs', $data); + $this->set_mapping('forum_discussion_sub', $oldid, $newitemid, true); } protected function process_forum_digest($data) { diff --git a/mod/forum/classes/event/assessable_uploaded.php b/mod/forum/classes/event/assessable_uploaded.php index b5d9c0b05de..93f37bdbbcd 100644 --- a/mod/forum/classes/event/assessable_uploaded.php +++ b/mod/forum/classes/event/assessable_uploaded.php @@ -126,4 +126,15 @@ class assessable_uploaded extends \core\event\assessable_uploaded { throw new \coding_exception('The \'triggeredfrom\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'forum_posts', 'restore' => 'forum_post'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['discussionid'] = array('db' => 'forum_discussions', 'restore' => 'forum_discussion'); + + return $othermapped; + } } diff --git a/mod/forum/classes/event/course_module_viewed.php b/mod/forum/classes/event/course_module_viewed.php index 8621898cc83..a4c2f033dbc 100644 --- a/mod/forum/classes/event/course_module_viewed.php +++ b/mod/forum/classes/event/course_module_viewed.php @@ -66,5 +66,8 @@ class course_module_viewed extends \core\event\course_module_viewed { $this->objectid, $this->contextinstanceid); } + public static function get_objectid_mapping() { + return array('db' => 'forum', 'restore' => 'forum'); + } } diff --git a/mod/forum/classes/event/course_searched.php b/mod/forum/classes/event/course_searched.php index c9f6f0db1f2..40ab3dc88b0 100644 --- a/mod/forum/classes/event/course_searched.php +++ b/mod/forum/classes/event/course_searched.php @@ -111,5 +111,8 @@ class course_searched extends \core\event\base { } } + public static function get_other_mapping() { + return false; + } } diff --git a/mod/forum/classes/event/discussion_created.php b/mod/forum/classes/event/discussion_created.php index e974753b8d5..ad5e372ba03 100644 --- a/mod/forum/classes/event/discussion_created.php +++ b/mod/forum/classes/event/discussion_created.php @@ -109,4 +109,15 @@ class discussion_created extends \core\event\base { throw new \coding_exception('Context level must be CONTEXT_MODULE.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'forum_discussions', 'restore' => 'forum_discussion'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['forumid'] = array('db' => 'forum', 'restore' => 'forum'); + + return $othermapped; + } } diff --git a/mod/forum/classes/event/discussion_deleted.php b/mod/forum/classes/event/discussion_deleted.php index 813f37bda73..6bd2d2ffa14 100644 --- a/mod/forum/classes/event/discussion_deleted.php +++ b/mod/forum/classes/event/discussion_deleted.php @@ -107,5 +107,16 @@ class discussion_deleted extends \core\event\base { throw new \coding_exception('Context level must be CONTEXT_MODULE.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'forum_discussions', 'restore' => 'forum_discussion'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['forumid'] = array('db' => 'forum', 'restore' => 'forum'); + + return $othermapped; + } } diff --git a/mod/forum/classes/event/discussion_moved.php b/mod/forum/classes/event/discussion_moved.php index 4d2382ea3d9..c0aaa1b93ca 100644 --- a/mod/forum/classes/event/discussion_moved.php +++ b/mod/forum/classes/event/discussion_moved.php @@ -111,4 +111,16 @@ class discussion_moved extends \core\event\base { throw new \coding_exception('Context level must be CONTEXT_MODULE.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'forum_discussions', 'restore' => 'forum_discussion'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['fromforumid'] = array('db' => 'forum', 'restore' => 'forum'); + $othermapped['toforumid'] = array('db' => 'forum', 'restore' => 'forum'); + + return $othermapped; + } } diff --git a/mod/forum/classes/event/discussion_subscription_created.php b/mod/forum/classes/event/discussion_subscription_created.php index d430292fc6b..da452509909 100644 --- a/mod/forum/classes/event/discussion_subscription_created.php +++ b/mod/forum/classes/event/discussion_subscription_created.php @@ -109,4 +109,16 @@ class discussion_subscription_created extends \core\event\base { throw new \coding_exception('Context level must be CONTEXT_MODULE.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'forum_discussion_subs', 'restore' => 'forum_discussion_sub'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['forumid'] = array('db' => 'forum', 'restore' => 'forum'); + $othermapped['discussion'] = array('db' => 'forum_discussions', 'restore' => 'forum_discussion'); + + return $othermapped; + } } diff --git a/mod/forum/classes/event/discussion_subscription_deleted.php b/mod/forum/classes/event/discussion_subscription_deleted.php index 7a773912eba..68533966306 100644 --- a/mod/forum/classes/event/discussion_subscription_deleted.php +++ b/mod/forum/classes/event/discussion_subscription_deleted.php @@ -109,4 +109,16 @@ class discussion_subscription_deleted extends \core\event\base { throw new \coding_exception('Context level must be CONTEXT_MODULE.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'forum_discussion_subs', 'restore' => 'forum_discussion_sub'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['forumid'] = array('db' => 'forum', 'restore' => 'forum'); + $othermapped['discussion'] = array('db' => 'forum_discussions', 'restore' => 'forum_discussion'); + + return $othermapped; + } } diff --git a/mod/forum/classes/event/discussion_updated.php b/mod/forum/classes/event/discussion_updated.php index c0c78148157..001a8a679b5 100644 --- a/mod/forum/classes/event/discussion_updated.php +++ b/mod/forum/classes/event/discussion_updated.php @@ -97,4 +97,15 @@ class discussion_updated extends \core\event\base { throw new \coding_exception('Context level must be CONTEXT_MODULE.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'forum_discussions', 'restore' => 'forum_discussion'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['forumid'] = array('db' => 'forum', 'restore' => 'forum'); + + return $othermapped; + } } diff --git a/mod/forum/classes/event/discussion_viewed.php b/mod/forum/classes/event/discussion_viewed.php index 3986531a69a..e99290e0cb0 100644 --- a/mod/forum/classes/event/discussion_viewed.php +++ b/mod/forum/classes/event/discussion_viewed.php @@ -99,5 +99,8 @@ class discussion_viewed extends \core\event\base { } } + public static function get_objectid_mapping() { + return array('db' => 'forum_discussions', 'restore' => 'forum_discussion'); + } } diff --git a/mod/forum/classes/event/post_created.php b/mod/forum/classes/event/post_created.php index 91f1554a8e3..ea170e569ae 100644 --- a/mod/forum/classes/event/post_created.php +++ b/mod/forum/classes/event/post_created.php @@ -128,4 +128,16 @@ class post_created extends \core\event\base { throw new \coding_exception('Context level must be CONTEXT_MODULE.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'forum_posts', 'restore' => 'forum_post'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['forumid'] = array('db' => 'forum', 'restore' => 'forum'); + $othermapped['discussionid'] = array('db' => 'forum_discussions', 'restore' => 'forum_discussion'); + + return $othermapped; + } } diff --git a/mod/forum/classes/event/post_deleted.php b/mod/forum/classes/event/post_deleted.php index 311d89979d5..91d2f4c12db 100644 --- a/mod/forum/classes/event/post_deleted.php +++ b/mod/forum/classes/event/post_deleted.php @@ -127,4 +127,16 @@ class post_deleted extends \core\event\base { throw new \coding_exception('Context level must be CONTEXT_MODULE.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'forum_posts', 'restore' => 'forum_post'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['forumid'] = array('db' => 'forum', 'restore' => 'forum'); + $othermapped['discussionid'] = array('db' => 'forum_discussions', 'restore' => 'forum_discussion'); + + return $othermapped; + } } diff --git a/mod/forum/classes/event/post_updated.php b/mod/forum/classes/event/post_updated.php index eff30eb4505..2ab41ff3a16 100644 --- a/mod/forum/classes/event/post_updated.php +++ b/mod/forum/classes/event/post_updated.php @@ -128,4 +128,16 @@ class post_updated extends \core\event\base { throw new \coding_exception('Context level must be CONTEXT_MODULE.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'forum_posts', 'restore' => 'forum_post'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['forumid'] = array('db' => 'forum', 'restore' => 'forum'); + $othermapped['discussionid'] = array('db' => 'forum_discussions', 'restore' => 'forum_discussion'); + + return $othermapped; + } } diff --git a/mod/forum/classes/event/readtracking_disabled.php b/mod/forum/classes/event/readtracking_disabled.php index 44b005ece8b..3e35ff3cc9b 100644 --- a/mod/forum/classes/event/readtracking_disabled.php +++ b/mod/forum/classes/event/readtracking_disabled.php @@ -110,4 +110,11 @@ class readtracking_disabled extends \core\event\base { throw new \coding_exception('Context level must be CONTEXT_MODULE.'); } } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['forumid'] = array('db' => 'forum', 'restore' => 'forum'); + + return $othermapped; + } } diff --git a/mod/forum/classes/event/readtracking_enabled.php b/mod/forum/classes/event/readtracking_enabled.php index 07de971dd3e..c2dcc40c87e 100644 --- a/mod/forum/classes/event/readtracking_enabled.php +++ b/mod/forum/classes/event/readtracking_enabled.php @@ -110,4 +110,11 @@ class readtracking_enabled extends \core\event\base { throw new \coding_exception('Context level must be CONTEXT_MODULE.'); } } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['forumid'] = array('db' => 'forum', 'restore' => 'forum'); + + return $othermapped; + } } diff --git a/mod/forum/classes/event/subscribers_viewed.php b/mod/forum/classes/event/subscribers_viewed.php index b7b6139b7fd..deec581902c 100644 --- a/mod/forum/classes/event/subscribers_viewed.php +++ b/mod/forum/classes/event/subscribers_viewed.php @@ -108,5 +108,11 @@ class subscribers_viewed extends \core\event\base { } } + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['forumid'] = array('db' => 'forum', 'restore' => 'forum'); + + return $othermapped; + } } diff --git a/mod/forum/classes/event/subscription_created.php b/mod/forum/classes/event/subscription_created.php index 9d099669b61..c3531aafd9a 100644 --- a/mod/forum/classes/event/subscription_created.php +++ b/mod/forum/classes/event/subscription_created.php @@ -111,4 +111,15 @@ class subscription_created extends \core\event\base { throw new \coding_exception('Context level must be CONTEXT_MODULE.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'forum_subscriptions', 'restore' => 'forum_subscription'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['forumid'] = array('db' => 'forum', 'restore' => 'forum'); + + return $othermapped; + } } diff --git a/mod/forum/classes/event/subscription_deleted.php b/mod/forum/classes/event/subscription_deleted.php index 97892b0a8d5..129e9b2e6c3 100644 --- a/mod/forum/classes/event/subscription_deleted.php +++ b/mod/forum/classes/event/subscription_deleted.php @@ -111,4 +111,15 @@ class subscription_deleted extends \core\event\base { throw new \coding_exception('Context level must be CONTEXT_MODULE.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'forum_subscriptions', 'restore' => 'forum_subscription'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['forumid'] = array('db' => 'forum', 'restore' => 'forum'); + + return $othermapped; + } } diff --git a/mod/forum/classes/event/user_report_viewed.php b/mod/forum/classes/event/user_report_viewed.php index a03fe6152ce..1fdc5c96f0b 100644 --- a/mod/forum/classes/event/user_report_viewed.php +++ b/mod/forum/classes/event/user_report_viewed.php @@ -128,5 +128,8 @@ class user_report_viewed extends \core\event\base { } } + public static function get_other_mapping() { + return false; + } } diff --git a/mod/glossary/classes/event/category_created.php b/mod/glossary/classes/event/category_created.php index cc289e3b9cc..56a644612c5 100644 --- a/mod/glossary/classes/event/category_created.php +++ b/mod/glossary/classes/event/category_created.php @@ -96,5 +96,9 @@ class category_created extends \core\event\base { throw new \coding_exception('Context level must be CONTEXT_MODULE.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'glossary_categories', 'restore' => 'glossary_category'); + } } diff --git a/mod/glossary/classes/event/category_deleted.php b/mod/glossary/classes/event/category_deleted.php index 620c71c2cb7..3b25a4699b9 100644 --- a/mod/glossary/classes/event/category_deleted.php +++ b/mod/glossary/classes/event/category_deleted.php @@ -96,5 +96,9 @@ class category_deleted extends \core\event\base { throw new \coding_exception('Context level must be CONTEXT_MODULE.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'glossary_categories', 'restore' => 'glossary_category'); + } } diff --git a/mod/glossary/classes/event/category_updated.php b/mod/glossary/classes/event/category_updated.php index fa9f0457b94..887123d48ed 100644 --- a/mod/glossary/classes/event/category_updated.php +++ b/mod/glossary/classes/event/category_updated.php @@ -96,5 +96,9 @@ class category_updated extends \core\event\base { throw new \coding_exception('Context level must be CONTEXT_MODULE.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'glossary_categories', 'restore' => 'glossary_category'); + } } diff --git a/mod/glossary/classes/event/course_module_viewed.php b/mod/glossary/classes/event/course_module_viewed.php index 32e459035a8..33680aa5da6 100644 --- a/mod/glossary/classes/event/course_module_viewed.php +++ b/mod/glossary/classes/event/course_module_viewed.php @@ -28,6 +28,12 @@ defined('MOODLE_INTERNAL') || die(); /** * The mod_glossary course module viewed event class. * + * @property-read array $other { + * Extra information about event. + * + * - string mode: (optional) + * } + * * @package mod_glossary * @since Moodle 2.7 * @copyright 2014 Marina Glancy @@ -68,4 +74,13 @@ class course_module_viewed extends \core\event\course_module_viewed { 'view.php?id=' . $this->contextinstanceid . '&tab=-1', $this->objectid, $this->contextinstanceid); } + + public static function get_objectid_mapping() { + return array('db' => 'glossary', 'restore' => 'glossary'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/mod/glossary/classes/event/entry_approved.php b/mod/glossary/classes/event/entry_approved.php index 6e690e82a45..38bae26cf49 100644 --- a/mod/glossary/classes/event/entry_approved.php +++ b/mod/glossary/classes/event/entry_approved.php @@ -98,5 +98,9 @@ class entry_approved extends \core\event\base { throw new \coding_exception('Context level must be CONTEXT_MODULE.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'glossary_entries', 'restore' => 'glossary_entry'); + } } diff --git a/mod/glossary/classes/event/entry_created.php b/mod/glossary/classes/event/entry_created.php index 98387f8ec0a..fba39d75a19 100644 --- a/mod/glossary/classes/event/entry_created.php +++ b/mod/glossary/classes/event/entry_created.php @@ -104,5 +104,14 @@ class entry_created extends \core\event\base { throw new \coding_exception('Context level must be CONTEXT_MODULE.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'glossary_entries', 'restore' => 'glossary_entry'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/mod/glossary/classes/event/entry_deleted.php b/mod/glossary/classes/event/entry_deleted.php index f116600a8be..7721668d17b 100644 --- a/mod/glossary/classes/event/entry_deleted.php +++ b/mod/glossary/classes/event/entry_deleted.php @@ -118,5 +118,14 @@ class entry_deleted extends \core\event\base { throw new \coding_exception('Context level must be CONTEXT_MODULE.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'glossary_entries', 'restore' => 'glossary_entry'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/mod/glossary/classes/event/entry_disapproved.php b/mod/glossary/classes/event/entry_disapproved.php index 8a74289c336..faa47213d2a 100644 --- a/mod/glossary/classes/event/entry_disapproved.php +++ b/mod/glossary/classes/event/entry_disapproved.php @@ -98,5 +98,9 @@ class entry_disapproved extends \core\event\base { throw new \coding_exception('Context level must be CONTEXT_MODULE.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'glossary_entries', 'restore' => 'glossary_entry'); + } } diff --git a/mod/glossary/classes/event/entry_updated.php b/mod/glossary/classes/event/entry_updated.php index ea831fd59f8..88c10de469c 100644 --- a/mod/glossary/classes/event/entry_updated.php +++ b/mod/glossary/classes/event/entry_updated.php @@ -104,5 +104,14 @@ class entry_updated extends \core\event\base { throw new \coding_exception('Context level must be CONTEXT_MODULE.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'glossary_entries', 'restore' => 'glossary_entry'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/mod/glossary/classes/event/entry_viewed.php b/mod/glossary/classes/event/entry_viewed.php index fbaba29a276..f04695568a5 100644 --- a/mod/glossary/classes/event/entry_viewed.php +++ b/mod/glossary/classes/event/entry_viewed.php @@ -98,5 +98,9 @@ class entry_viewed extends \core\event\base { throw new \coding_exception('Context level must be CONTEXT_MODULE.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'glossary_entries', 'restore' => 'glossary_entry'); + } } diff --git a/mod/imscp/classes/event/course_module_viewed.php b/mod/imscp/classes/event/course_module_viewed.php index 5a1681ffbc1..71acd68d5ba 100644 --- a/mod/imscp/classes/event/course_module_viewed.php +++ b/mod/imscp/classes/event/course_module_viewed.php @@ -45,4 +45,8 @@ class course_module_viewed extends \core\event\course_module_viewed { $this->data['crud'] = 'r'; $this->data['edulevel'] = self::LEVEL_PARTICIPATING; } + + public static function get_objectid_mapping() { + return array('db' => 'imscp', 'restore' => 'imscp'); + } } diff --git a/mod/lesson/classes/event/content_page_viewed.php b/mod/lesson/classes/event/content_page_viewed.php index 90875cfa66e..d98bdbf6de5 100644 --- a/mod/lesson/classes/event/content_page_viewed.php +++ b/mod/lesson/classes/event/content_page_viewed.php @@ -86,4 +86,8 @@ class content_page_viewed extends \core\event\base { throw new \coding_exception('Context level must be CONTEXT_MODULE.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'lesson_pages', 'restore' => 'lesson_page'); + } } diff --git a/mod/lesson/classes/event/course_module_viewed.php b/mod/lesson/classes/event/course_module_viewed.php index 8b7992bdea7..3244e754ee2 100644 --- a/mod/lesson/classes/event/course_module_viewed.php +++ b/mod/lesson/classes/event/course_module_viewed.php @@ -45,4 +45,8 @@ class course_module_viewed extends \core\event\course_module_viewed { $this->data['crud'] = 'r'; $this->data['edulevel'] = self::LEVEL_PARTICIPATING; } + + public static function get_objectid_mapping() { + return array('db' => 'lesson', 'restore' => 'lesson'); + } } diff --git a/mod/lesson/classes/event/essay_assessed.php b/mod/lesson/classes/event/essay_assessed.php index f3117d15db6..92079ac4e89 100644 --- a/mod/lesson/classes/event/essay_assessed.php +++ b/mod/lesson/classes/event/essay_assessed.php @@ -111,4 +111,16 @@ class essay_assessed extends \core\event\base { throw new \coding_exception('The \'attemptid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'lesson_grades', 'restore' => 'lesson_grade'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['lessonid'] = array('db' => 'lesson', 'restore' => 'lesson'); + $othermapped['attemptid'] = array('db' => 'lesson_attempts', 'restore' => 'lesson_attept'); + + return $othermapped; + } } diff --git a/mod/lesson/classes/event/essay_attempt_viewed.php b/mod/lesson/classes/event/essay_attempt_viewed.php index 5e179228624..1af109f0bd9 100644 --- a/mod/lesson/classes/event/essay_attempt_viewed.php +++ b/mod/lesson/classes/event/essay_attempt_viewed.php @@ -97,4 +97,8 @@ class essay_attempt_viewed extends \core\event\base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'lesson_attempts', 'restore' => 'lesson_attempt'); + } } diff --git a/mod/lesson/classes/event/group_override_created.php b/mod/lesson/classes/event/group_override_created.php index 1edc21bbb37..fff0e617019 100644 --- a/mod/lesson/classes/event/group_override_created.php +++ b/mod/lesson/classes/event/group_override_created.php @@ -97,4 +97,16 @@ class group_override_created extends \core\event\base { throw new \coding_exception('The \'groupid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'lesson_overrides', 'restore' => 'lesson_override'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['lessonid'] = array('db' => 'lesson', 'restore' => 'lesson'); + $othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group'); + + return $othermapped; + } } diff --git a/mod/lesson/classes/event/group_override_deleted.php b/mod/lesson/classes/event/group_override_deleted.php index 16700850afa..49ba8569d79 100644 --- a/mod/lesson/classes/event/group_override_deleted.php +++ b/mod/lesson/classes/event/group_override_deleted.php @@ -96,4 +96,16 @@ class group_override_deleted extends \core\event\base { throw new \coding_exception('The \'groupid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'lesson_overrides', 'restore' => 'lesson_override'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['lessonid'] = array('db' => 'lesson', 'restore' => 'lesson'); + $othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group'); + + return $othermapped; + } } diff --git a/mod/lesson/classes/event/group_override_updated.php b/mod/lesson/classes/event/group_override_updated.php index 7096cd11b42..a5fd6ca138a 100644 --- a/mod/lesson/classes/event/group_override_updated.php +++ b/mod/lesson/classes/event/group_override_updated.php @@ -96,4 +96,16 @@ class group_override_updated extends \core\event\base { throw new \coding_exception('The \'groupid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'lesson_overrides', 'restore' => 'lesson_override'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['lessonid'] = array('db' => 'lesson', 'restore' => 'lesson'); + $othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group'); + + return $othermapped; + } } diff --git a/mod/lesson/classes/event/highscore_added.php b/mod/lesson/classes/event/highscore_added.php index e5d9513f97f..25d61bebc94 100644 --- a/mod/lesson/classes/event/highscore_added.php +++ b/mod/lesson/classes/event/highscore_added.php @@ -111,4 +111,14 @@ class highscore_added extends \core\event\base { throw new \coding_exception('The \'nickname\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + // The 'highscore' functionality was removed from core. + return false; + } + + public static function get_other_mapping() { + // The 'highscore' functionality was removed from core. + return false; + } } diff --git a/mod/lesson/classes/event/highscores_viewed.php b/mod/lesson/classes/event/highscores_viewed.php index 614ef0900c8..91fa720cd22 100644 --- a/mod/lesson/classes/event/highscores_viewed.php +++ b/mod/lesson/classes/event/highscores_viewed.php @@ -87,4 +87,14 @@ class highscores_viewed extends \core\event\base { return array($this->courseid, 'lesson', 'view highscores', 'highscores.php?id=' . $this->contextinstanceid, $lesson->name, $this->contextinstanceid); } + + public static function get_objectid_mapping() { + // The 'highscore' functionality was removed from core. + return false; + } + + public static function get_other_mapping() { + // The 'highscore' functionality was removed from core. + return false; + } } diff --git a/mod/lesson/classes/event/lesson_ended.php b/mod/lesson/classes/event/lesson_ended.php index aea1c2f55dd..e090a789f86 100644 --- a/mod/lesson/classes/event/lesson_ended.php +++ b/mod/lesson/classes/event/lesson_ended.php @@ -82,4 +82,8 @@ class lesson_ended extends \core\event\base { return array($this->courseid, 'lesson', 'end', 'view.php?id=' . $this->contextinstanceid, $this->objectid, $this->contextinstanceid); } + + public static function get_objectid_mapping() { + return array('db' => 'lesson', 'restore' => 'lesson'); + } } diff --git a/mod/lesson/classes/event/lesson_restarted.php b/mod/lesson/classes/event/lesson_restarted.php index c2c8b6750ff..7870e43d77a 100644 --- a/mod/lesson/classes/event/lesson_restarted.php +++ b/mod/lesson/classes/event/lesson_restarted.php @@ -72,4 +72,8 @@ class lesson_restarted extends \core\event\base { return "The user with id '$this->userid' abandoned their previous incomplete attempt ". "and started a new attempt on the lesson with course module id '$this->contextinstanceid'."; } + + public static function get_objectid_mapping() { + return array('db' => 'lesson', 'restore' => 'lesson'); + } } diff --git a/mod/lesson/classes/event/lesson_resumed.php b/mod/lesson/classes/event/lesson_resumed.php index 30638f46095..89abc44bb7f 100644 --- a/mod/lesson/classes/event/lesson_resumed.php +++ b/mod/lesson/classes/event/lesson_resumed.php @@ -72,4 +72,8 @@ class lesson_resumed extends \core\event\base { return "The user with id '$this->userid' resumed their previous incomplete attempt on". " the lesson with course module id '$this->contextinstanceid'."; } + + public static function get_objectid_mapping() { + return array('db' => 'lesson', 'restore' => 'lesson'); + } } diff --git a/mod/lesson/classes/event/lesson_started.php b/mod/lesson/classes/event/lesson_started.php index d35b37230de..204d0ce7798 100644 --- a/mod/lesson/classes/event/lesson_started.php +++ b/mod/lesson/classes/event/lesson_started.php @@ -81,4 +81,8 @@ class lesson_started extends \core\event\base { return array($this->courseid, 'lesson', 'start', 'view.php?id=' . $this->contextinstanceid, $this->objectid, $this->contextinstanceid); } + + public static function get_objectid_mapping() { + return array('db' => 'lesson', 'restore' => 'lesson'); + } } diff --git a/mod/lesson/classes/event/page_created.php b/mod/lesson/classes/event/page_created.php index de3c1f94cd9..f2dc4e1b287 100644 --- a/mod/lesson/classes/event/page_created.php +++ b/mod/lesson/classes/event/page_created.php @@ -30,9 +30,9 @@ defined('MOODLE_INTERNAL') || die(); * The mod_lesson page_created event class. * * @property-read array $other { - * Extra information about event. + * Extra information about event. * - * - string pagetype: the name of the pagetype as defined in the individual page class + * - string pagetype: the name of the pagetype as defined in the individual page class * } * * @package mod_lesson @@ -95,4 +95,13 @@ class page_created extends \core\event\base { throw new \coding_exception('The \'pagetype\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'lesson_pages', 'restore' => 'lesson_page'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } \ No newline at end of file diff --git a/mod/lesson/classes/event/page_deleted.php b/mod/lesson/classes/event/page_deleted.php index a4342a30b02..037e3dc49cd 100644 --- a/mod/lesson/classes/event/page_deleted.php +++ b/mod/lesson/classes/event/page_deleted.php @@ -30,9 +30,9 @@ defined('MOODLE_INTERNAL') || die(); * The mod_lesson page_deleted event class. * * @property-read array $other { - * Extra information about event. + * Extra information about event. * - * - string pagetype: the name of the pagetype as defined in the individual page class + * - string pagetype: the name of the pagetype as defined in the individual page class * } * * @package mod_lesson @@ -95,4 +95,13 @@ class page_deleted extends \core\event\base { throw new \coding_exception('The \'pagetype\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'lesson_pages', 'restore' => 'lesson_page'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } \ No newline at end of file diff --git a/mod/lesson/classes/event/page_moved.php b/mod/lesson/classes/event/page_moved.php index 91ce667111b..5f4b254517c 100644 --- a/mod/lesson/classes/event/page_moved.php +++ b/mod/lesson/classes/event/page_moved.php @@ -30,11 +30,11 @@ defined('MOODLE_INTERNAL') || die(); * The mod_lesson page_moved event class. * * @property-read array $other { - * Extra information about event. + * Extra information about event. * - * - string pagetype: the name of the pagetype as defined in the individual page class - * - int prevpageid: the id of the previous lesson page - * - int nextpageid: the id of the next lesson page + * - string pagetype: the name of the pagetype as defined in the individual page class + * - int prevpageid: the id of the previous lesson page + * - int nextpageid: the id of the next lesson page * } * * @package mod_lesson @@ -105,4 +105,16 @@ class page_moved extends \core\event\base { throw new \coding_exception('The \'nextpageid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'lesson_pages', 'restore' => 'lesson_page'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['prevpageid'] = array('db' => 'lesson_pages', 'restore' => 'lesson_page'); + $othermapped['nextpageid'] = array('db' => 'lesson_pages', 'restore' => 'lesson_page'); + + return $othermapped; + } } diff --git a/mod/lesson/classes/event/page_updated.php b/mod/lesson/classes/event/page_updated.php index 55065f18fa0..2f11224741d 100644 --- a/mod/lesson/classes/event/page_updated.php +++ b/mod/lesson/classes/event/page_updated.php @@ -28,10 +28,11 @@ defined('MOODLE_INTERNAL') || die(); /** * The mod_lesson page_updated event class. - * @property-read array $other { - * Extra information about event. * - * - string pagetype: the name of the pagetype as defined in the individual page class + * @property-read array $other { + * Extra information about event. + * + * - string pagetype: the name of the pagetype as defined in the individual page class * } * * @package mod_lesson @@ -113,4 +114,13 @@ class page_updated extends \core\event\base { throw new \coding_exception('The \'pagetype\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'lesson_pages', 'restore' => 'lesson_page'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } \ No newline at end of file diff --git a/mod/lesson/classes/event/question_answered.php b/mod/lesson/classes/event/question_answered.php index 5f1b5fef95b..ef037ae3489 100644 --- a/mod/lesson/classes/event/question_answered.php +++ b/mod/lesson/classes/event/question_answered.php @@ -30,9 +30,9 @@ defined('MOODLE_INTERNAL') || die(); * The mod_lesson question answered event class. * * @property-read array $other { - * Extra information about event. + * Extra information about event. * - * - string pagetype: the name of the pagetype as defined in the individual page class + * - string pagetype: the name of the pagetype as defined in the individual page class * } * * @package mod_lesson @@ -95,4 +95,13 @@ class question_answered extends \core\event\base { throw new \coding_exception('The \'pagetype\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'lesson_pages', 'restore' => 'lesson_page'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/mod/lesson/classes/event/question_viewed.php b/mod/lesson/classes/event/question_viewed.php index a6d82a699ba..a72aa4612a6 100644 --- a/mod/lesson/classes/event/question_viewed.php +++ b/mod/lesson/classes/event/question_viewed.php @@ -30,9 +30,9 @@ defined('MOODLE_INTERNAL') || die(); * The mod_lesson question viewed event class. * * @property-read array $other { - * Extra information about event. + * Extra information about event. * - * - string pagetype: the name of the pagetype as defined in the individual page class + * - string pagetype: the name of the pagetype as defined in the individual page class * } * * @package mod_lesson @@ -95,4 +95,13 @@ class question_viewed extends \core\event\base { throw new \coding_exception('The \'pagetype\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'lesson_pages', 'restore' => 'lesson_page'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/mod/lesson/classes/event/user_override_created.php b/mod/lesson/classes/event/user_override_created.php index 9e47d57cb92..6d6cae6c3c2 100644 --- a/mod/lesson/classes/event/user_override_created.php +++ b/mod/lesson/classes/event/user_override_created.php @@ -95,4 +95,15 @@ class user_override_created extends \core\event\base { throw new \coding_exception('The \'lessonid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'lesson_overrides', 'restore' => 'lesson_override'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['lessonid'] = array('db' => 'lesson', 'restore' => 'lesson'); + + return $othermapped; + } } diff --git a/mod/lesson/classes/event/user_override_deleted.php b/mod/lesson/classes/event/user_override_deleted.php index 6fc90aac5d3..1c77ea6c050 100644 --- a/mod/lesson/classes/event/user_override_deleted.php +++ b/mod/lesson/classes/event/user_override_deleted.php @@ -95,4 +95,15 @@ class user_override_deleted extends \core\event\base { throw new \coding_exception('The \'lessonid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'lesson_overrides', 'restore' => 'lesson_override'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['lessonid'] = array('db' => 'lesson', 'restore' => 'lesson'); + + return $othermapped; + } } diff --git a/mod/lesson/classes/event/user_override_updated.php b/mod/lesson/classes/event/user_override_updated.php index 4c30e4bb85a..b845df5c52e 100644 --- a/mod/lesson/classes/event/user_override_updated.php +++ b/mod/lesson/classes/event/user_override_updated.php @@ -96,4 +96,15 @@ class user_override_updated extends \core\event\base { throw new \coding_exception('The \'lessonid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'lesson_overrides', 'restore' => 'lesson_override'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['lessonid'] = array('db' => 'lesson', 'restore' => 'lesson'); + + return $othermapped; + } } diff --git a/mod/lti/classes/event/course_module_viewed.php b/mod/lti/classes/event/course_module_viewed.php index a42d007ec41..6cb886d1fd9 100644 --- a/mod/lti/classes/event/course_module_viewed.php +++ b/mod/lti/classes/event/course_module_viewed.php @@ -44,4 +44,8 @@ class course_module_viewed extends \core\event\course_module_viewed { $this->data['crud'] = 'r'; $this->data['edulevel'] = self::LEVEL_PARTICIPATING; } + + public static function get_objectid_mapping() { + return array('db' => 'lti', 'restore' => 'lti'); + } } diff --git a/mod/page/classes/event/course_module_viewed.php b/mod/page/classes/event/course_module_viewed.php index c61cbe374af..d0086629462 100644 --- a/mod/page/classes/event/course_module_viewed.php +++ b/mod/page/classes/event/course_module_viewed.php @@ -43,5 +43,9 @@ class course_module_viewed extends \core\event\course_module_viewed { $this->data['edulevel'] = self::LEVEL_PARTICIPATING; $this->data['objecttable'] = 'page'; } + + public static function get_objectid_mapping() { + return array('db' => 'page', 'restore' => 'page'); + } } diff --git a/mod/quiz/classes/event/attempt_abandoned.php b/mod/quiz/classes/event/attempt_abandoned.php index 08e56076388..5960954557b 100644 --- a/mod/quiz/classes/event/attempt_abandoned.php +++ b/mod/quiz/classes/event/attempt_abandoned.php @@ -126,4 +126,16 @@ class attempt_abandoned extends \core\event\base { throw new \coding_exception('The \'submitterid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'quiz_attempts', 'restore' => 'quiz_attempt'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['submitterid'] = array('db' => 'user', 'restore' => 'user'); + $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + + return $othermapped; + } } diff --git a/mod/quiz/classes/event/attempt_becameoverdue.php b/mod/quiz/classes/event/attempt_becameoverdue.php index 5318048ea12..549e839c326 100644 --- a/mod/quiz/classes/event/attempt_becameoverdue.php +++ b/mod/quiz/classes/event/attempt_becameoverdue.php @@ -128,4 +128,16 @@ class attempt_becameoverdue extends \core\event\base { throw new \coding_exception('The \'submitterid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'quiz_attempts', 'restore' => 'quiz_attempt'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['submitterid'] = array('db' => 'user', 'restore' => 'user'); + $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + + return $othermapped; + } } diff --git a/mod/quiz/classes/event/attempt_deleted.php b/mod/quiz/classes/event/attempt_deleted.php index b0dbfc482de..0662f397304 100644 --- a/mod/quiz/classes/event/attempt_deleted.php +++ b/mod/quiz/classes/event/attempt_deleted.php @@ -28,6 +28,12 @@ defined('MOODLE_INTERNAL') || die(); /** * The mod_quiz attempt deleted event class. * + * @property-read array $other { + * Extra information about event. + * + * - int quizid: the id of the quiz. + * } + * * @package mod_quiz * @since Moodle 2.7 * @copyright 2014 Mark Nelson @@ -99,4 +105,15 @@ class attempt_deleted extends \core\event\base { throw new \coding_exception('The \'quizid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'quiz_attempts', 'restore' => 'quiz_attempt'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + + return $othermapped; + } } diff --git a/mod/quiz/classes/event/attempt_preview_started.php b/mod/quiz/classes/event/attempt_preview_started.php index cbea2372568..7b00db28e9b 100644 --- a/mod/quiz/classes/event/attempt_preview_started.php +++ b/mod/quiz/classes/event/attempt_preview_started.php @@ -106,4 +106,15 @@ class attempt_preview_started extends \core\event\base { throw new \coding_exception('The \'quizid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'quiz_attempts', 'restore' => 'quiz_attempt'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + + return $othermapped; + } } diff --git a/mod/quiz/classes/event/attempt_reviewed.php b/mod/quiz/classes/event/attempt_reviewed.php index 989f7880eeb..fbfdd8dc62a 100644 --- a/mod/quiz/classes/event/attempt_reviewed.php +++ b/mod/quiz/classes/event/attempt_reviewed.php @@ -105,4 +105,15 @@ class attempt_reviewed extends \core\event\base { throw new \coding_exception('The \'quizid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'quiz_attempts', 'restore' => 'quiz_attempt'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + + return $othermapped; + } } diff --git a/mod/quiz/classes/event/attempt_started.php b/mod/quiz/classes/event/attempt_started.php index 149b56a5714..f5e70162a74 100644 --- a/mod/quiz/classes/event/attempt_started.php +++ b/mod/quiz/classes/event/attempt_started.php @@ -27,6 +27,12 @@ defined('MOODLE_INTERNAL') || die(); /** * The mod_quiz attempt started event class. * + * @property-read array $other { + * Extra information about event. + * + * - int quizid: (optional) the id of the quiz. + * } + * * @package mod_quiz * @since Moodle 2.6 * @copyright 2013 Adrian Greeve @@ -125,4 +131,15 @@ class attempt_started extends \core\event\base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'quiz_attempts', 'restore' => 'quiz_attempt'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + + return $othermapped; + } } diff --git a/mod/quiz/classes/event/attempt_submitted.php b/mod/quiz/classes/event/attempt_submitted.php index b64a967b345..efa5302c007 100644 --- a/mod/quiz/classes/event/attempt_submitted.php +++ b/mod/quiz/classes/event/attempt_submitted.php @@ -126,4 +126,16 @@ class attempt_submitted extends \core\event\base { throw new \coding_exception('The \'submitterid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'quiz_attempts', 'restore' => 'quiz_attempt'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['submitterid'] = array('db' => 'user', 'restore' => 'user'); + $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + + return $othermapped; + } } diff --git a/mod/quiz/classes/event/attempt_summary_viewed.php b/mod/quiz/classes/event/attempt_summary_viewed.php index 6b480cf7d89..385e2b356d3 100644 --- a/mod/quiz/classes/event/attempt_summary_viewed.php +++ b/mod/quiz/classes/event/attempt_summary_viewed.php @@ -108,4 +108,15 @@ class attempt_summary_viewed extends \core\event\base { throw new \coding_exception('The \'quizid\' must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'quiz_attempts', 'restore' => 'quiz_attempt'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + + return $othermapped; + } } diff --git a/mod/quiz/classes/event/attempt_viewed.php b/mod/quiz/classes/event/attempt_viewed.php index edde520f7b1..f08739936c3 100644 --- a/mod/quiz/classes/event/attempt_viewed.php +++ b/mod/quiz/classes/event/attempt_viewed.php @@ -106,4 +106,15 @@ class attempt_viewed extends \core\event\base { throw new \coding_exception('The \'quizid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'quiz_attempts', 'restore' => 'quiz_attempt'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + + return $othermapped; + } } diff --git a/mod/quiz/classes/event/course_module_viewed.php b/mod/quiz/classes/event/course_module_viewed.php index f1977873fa6..dbdf0fc8621 100644 --- a/mod/quiz/classes/event/course_module_viewed.php +++ b/mod/quiz/classes/event/course_module_viewed.php @@ -46,4 +46,8 @@ class course_module_viewed extends \core\event\course_module_viewed { $this->data['edulevel'] = self::LEVEL_PARTICIPATING; $this->data['objecttable'] = 'quiz'; } + + public static function get_objectid_mapping() { + return array('db' => 'quiz', 'restore' => 'quiz'); + } } diff --git a/mod/quiz/classes/event/edit_page_viewed.php b/mod/quiz/classes/event/edit_page_viewed.php index 7f1473aa3c9..80247260376 100644 --- a/mod/quiz/classes/event/edit_page_viewed.php +++ b/mod/quiz/classes/event/edit_page_viewed.php @@ -101,4 +101,11 @@ class edit_page_viewed extends \core\event\base { throw new \coding_exception('The \'quizid\' value must be set in other.'); } } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + + return $othermapped; + } } diff --git a/mod/quiz/classes/event/group_override_created.php b/mod/quiz/classes/event/group_override_created.php index 0f5025ce72d..2d21b8dd132 100644 --- a/mod/quiz/classes/event/group_override_created.php +++ b/mod/quiz/classes/event/group_override_created.php @@ -97,4 +97,16 @@ class group_override_created extends \core\event\base { throw new \coding_exception('The \'groupid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'quiz_overrides', 'restore' => 'quiz_override'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + $othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group'); + + return $othermapped; + } } diff --git a/mod/quiz/classes/event/group_override_deleted.php b/mod/quiz/classes/event/group_override_deleted.php index 7814b79bd56..9fe90c15b5d 100644 --- a/mod/quiz/classes/event/group_override_deleted.php +++ b/mod/quiz/classes/event/group_override_deleted.php @@ -106,4 +106,16 @@ class group_override_deleted extends \core\event\base { throw new \coding_exception('The \'groupid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'quiz_overrides', 'restore' => 'quiz_override'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + $othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group'); + + return $othermapped; + } } diff --git a/mod/quiz/classes/event/group_override_updated.php b/mod/quiz/classes/event/group_override_updated.php index 711147e5893..5476b019e61 100644 --- a/mod/quiz/classes/event/group_override_updated.php +++ b/mod/quiz/classes/event/group_override_updated.php @@ -106,4 +106,16 @@ class group_override_updated extends \core\event\base { throw new \coding_exception('The \'groupid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'quiz_overrides', 'restore' => 'quiz_override'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + $othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group'); + + return $othermapped; + } } diff --git a/mod/quiz/classes/event/question_manually_graded.php b/mod/quiz/classes/event/question_manually_graded.php index 70d7bb915d1..a77912ee3ed 100644 --- a/mod/quiz/classes/event/question_manually_graded.php +++ b/mod/quiz/classes/event/question_manually_graded.php @@ -111,6 +111,17 @@ class question_manually_graded extends \core\event\base { if (!isset($this->other['slot'])) { throw new \coding_exception('The \'slot\' value must be set in other.'); } + } + public static function get_objectid_mapping() { + return array('db' => 'question', 'restore' => 'question'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + $othermapped['attemptid'] = array('db' => 'quiz_attempts', 'restore' => 'quiz_attempt'); + + return $othermapped; } } diff --git a/mod/quiz/classes/event/report_viewed.php b/mod/quiz/classes/event/report_viewed.php index 12e5d519131..de23f9df4a3 100644 --- a/mod/quiz/classes/event/report_viewed.php +++ b/mod/quiz/classes/event/report_viewed.php @@ -109,4 +109,11 @@ class report_viewed extends \core\event\base { throw new \coding_exception('The \'reportname\' value must be set in other.'); } } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + + return $othermapped; + } } diff --git a/mod/quiz/classes/event/user_override_created.php b/mod/quiz/classes/event/user_override_created.php index c1f5a663101..e8cbfd0411b 100644 --- a/mod/quiz/classes/event/user_override_created.php +++ b/mod/quiz/classes/event/user_override_created.php @@ -95,4 +95,15 @@ class user_override_created extends \core\event\base { throw new \coding_exception('The \'quizid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'quiz_overrides', 'restore' => 'quiz_override'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + + return $othermapped; + } } diff --git a/mod/quiz/classes/event/user_override_deleted.php b/mod/quiz/classes/event/user_override_deleted.php index 59b1ac52233..f851189292f 100644 --- a/mod/quiz/classes/event/user_override_deleted.php +++ b/mod/quiz/classes/event/user_override_deleted.php @@ -105,4 +105,15 @@ class user_override_deleted extends \core\event\base { throw new \coding_exception('The \'quizid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'quiz_overrides', 'restore' => 'quiz_override'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + + return $othermapped; + } } diff --git a/mod/quiz/classes/event/user_override_updated.php b/mod/quiz/classes/event/user_override_updated.php index 8f3cfc83d3d..2b902a28949 100644 --- a/mod/quiz/classes/event/user_override_updated.php +++ b/mod/quiz/classes/event/user_override_updated.php @@ -106,4 +106,15 @@ class user_override_updated extends \core\event\base { throw new \coding_exception('The \'quizid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'quiz_overrides', 'restore' => 'quiz_override'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + + return $othermapped; + } } diff --git a/mod/resource/classes/event/course_module_viewed.php b/mod/resource/classes/event/course_module_viewed.php index 880a0ae5b30..8d4b43df285 100644 --- a/mod/resource/classes/event/course_module_viewed.php +++ b/mod/resource/classes/event/course_module_viewed.php @@ -46,4 +46,8 @@ class course_module_viewed extends \core\event\course_module_viewed { $this->data['crud'] = 'r'; $this->data['edulevel'] = self::LEVEL_PARTICIPATING; } + + public static function get_objectid_mapping() { + return array('db' => 'resource', 'restore' => 'resource'); + } } diff --git a/mod/scorm/classes/event/attempt_deleted.php b/mod/scorm/classes/event/attempt_deleted.php index 3e465639c3c..2a0a1274ee5 100644 --- a/mod/scorm/classes/event/attempt_deleted.php +++ b/mod/scorm/classes/event/attempt_deleted.php @@ -100,4 +100,9 @@ class attempt_deleted extends \core\event\base { throw new \coding_exception('The \'attemptid\' must be set in other.'); } } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/mod/scorm/classes/event/course_module_viewed.php b/mod/scorm/classes/event/course_module_viewed.php index e598045b489..a81e411a571 100644 --- a/mod/scorm/classes/event/course_module_viewed.php +++ b/mod/scorm/classes/event/course_module_viewed.php @@ -53,5 +53,9 @@ class course_module_viewed extends \core\event\course_module_viewed { return array($this->courseid, 'scorm', 'pre-view', 'view.php?id=' . $this->contextinstanceid, $this->objectid, $this->contextinstanceid); } + + public static function get_objectid_mapping() { + return array('db' => 'scorm', 'restore' => 'scorm'); + } } diff --git a/mod/scorm/classes/event/interactions_viewed.php b/mod/scorm/classes/event/interactions_viewed.php index 91dcc8e1419..ad3f41be844 100644 --- a/mod/scorm/classes/event/interactions_viewed.php +++ b/mod/scorm/classes/event/interactions_viewed.php @@ -115,4 +115,11 @@ class interactions_viewed extends \core\event\base { throw new \coding_exception('The \'instanceid\' must be set in other.'); } } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['instanceid'] = array('db' => 'scorm', 'restore' => 'scorm'); + + return $othermapped; + } } diff --git a/mod/scorm/classes/event/report_viewed.php b/mod/scorm/classes/event/report_viewed.php index edd61f3f3d5..e86e9466050 100644 --- a/mod/scorm/classes/event/report_viewed.php +++ b/mod/scorm/classes/event/report_viewed.php @@ -105,4 +105,11 @@ class report_viewed extends \core\event\base { throw new \coding_exception('The \'mode\' value must be set in other.'); } } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['scormid'] = array('db' => 'scorm', 'restore' => 'scorm'); + + return $othermapped; + } } diff --git a/mod/scorm/classes/event/sco_launched.php b/mod/scorm/classes/event/sco_launched.php index 62c0de877e7..06b66d2bb67 100644 --- a/mod/scorm/classes/event/sco_launched.php +++ b/mod/scorm/classes/event/sco_launched.php @@ -102,4 +102,15 @@ class sco_launched extends \core\event\base { throw new \coding_exception('The \'loadedcontent\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'scorm_scoes', 'restore' => 'scorm_sco'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['instanceid'] = array('db' => 'scorm', 'restore' => 'scorm'); + + return $othermapped; + } } diff --git a/mod/scorm/classes/event/tracks_viewed.php b/mod/scorm/classes/event/tracks_viewed.php index d76812ddb50..25364c3f741 100644 --- a/mod/scorm/classes/event/tracks_viewed.php +++ b/mod/scorm/classes/event/tracks_viewed.php @@ -118,4 +118,12 @@ class tracks_viewed extends \core\event\base { throw new \coding_exception('The \'scoid\' value must be set in other.'); } } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['instanceid'] = array('db' => 'scorm', 'restore' => 'scorm'); + $othermapped['scoid'] = array('db' => 'scorm_scoes', 'restore' => 'scorm_scoe'); + + return $othermapped; + } } diff --git a/mod/scorm/classes/event/user_report_viewed.php b/mod/scorm/classes/event/user_report_viewed.php index b91ad5582b1..6cec96852fb 100644 --- a/mod/scorm/classes/event/user_report_viewed.php +++ b/mod/scorm/classes/event/user_report_viewed.php @@ -112,4 +112,11 @@ class user_report_viewed extends \core\event\base { throw new \coding_exception('The \'instanceid\' value must be set in other.'); } } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['instanceid'] = array('db' => 'scorm', 'restore' => 'scorm'); + + return $othermapped; + } } diff --git a/mod/survey/classes/event/course_module_viewed.php b/mod/survey/classes/event/course_module_viewed.php index c8cf62a4ce1..6fcb582e3df 100644 --- a/mod/survey/classes/event/course_module_viewed.php +++ b/mod/survey/classes/event/course_module_viewed.php @@ -29,6 +29,12 @@ defined('MOODLE_INTERNAL') || die(); /** * The mod_survery course module viewed event. * + * @property-read array $other { + * Extra information about the event. + * + * - string viewed: what was viewed + * } + * * @package mod_survey * @since Moodle 2.7 * @copyright 2014 Rajesh Taneja @@ -67,4 +73,13 @@ class course_module_viewed extends \core\event\course_module_viewed { throw new \coding_exception('Other must contain the key viewed.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'survey', 'restore' => 'survey'); + } + + public static function get_other_mapping() { + // No need to map 'viewed'. + return false; + } } diff --git a/mod/survey/classes/event/report_downloaded.php b/mod/survey/classes/event/report_downloaded.php index 9ca6f11d63a..62f9f92e3b2 100644 --- a/mod/survey/classes/event/report_downloaded.php +++ b/mod/survey/classes/event/report_downloaded.php @@ -104,4 +104,15 @@ class report_downloaded extends \core\event\base { throw new \coding_exception('The \'type\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'survey', 'restore' => 'survey'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group'); + + return $othermapped; + } } diff --git a/mod/survey/classes/event/report_viewed.php b/mod/survey/classes/event/report_viewed.php index 1055c0896d4..a9a44b4b036 100644 --- a/mod/survey/classes/event/report_viewed.php +++ b/mod/survey/classes/event/report_viewed.php @@ -93,4 +93,15 @@ class report_viewed extends \core\event\base { return array($this->courseid, "survey", "view report", "report.php?id=" . $this->contextinstanceid, $this->objectid, $this->contextinstanceid); } + + public static function get_objectid_mapping() { + return array('db' => 'survey', 'restore' => 'survey'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group'); + + return $othermapped; + } } diff --git a/mod/survey/classes/event/response_submitted.php b/mod/survey/classes/event/response_submitted.php index ab4234e3326..9d748f422dc 100644 --- a/mod/survey/classes/event/response_submitted.php +++ b/mod/survey/classes/event/response_submitted.php @@ -99,4 +99,11 @@ class response_submitted extends \core\event\base { throw new \coding_exception('The \'surveyid\' value must be set in other.'); } } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['surveyid'] = array('db' => 'survey', 'restore' => 'survey'); + + return $othermapped; + } } diff --git a/mod/url/classes/event/course_module_viewed.php b/mod/url/classes/event/course_module_viewed.php index 2f86aa46622..e0342b1bfa8 100644 --- a/mod/url/classes/event/course_module_viewed.php +++ b/mod/url/classes/event/course_module_viewed.php @@ -46,4 +46,8 @@ class course_module_viewed extends \core\event\course_module_viewed { $this->data['crud'] = 'r'; $this->data['edulevel'] = self::LEVEL_PARTICIPATING; } + + public static function get_objectid_mapping() { + return array('db' => 'url', 'restore' => 'url'); + } } diff --git a/mod/wiki/classes/event/comments_viewed.php b/mod/wiki/classes/event/comments_viewed.php index 952637944d8..9d18302bd3c 100644 --- a/mod/wiki/classes/event/comments_viewed.php +++ b/mod/wiki/classes/event/comments_viewed.php @@ -73,4 +73,8 @@ class comments_viewed extends \core\event\comments_viewed { public function get_url() { return new \moodle_url('/mod/wiki/comments.php', array('pageid' => $this->objectid)); } + + public static function get_objectid_mapping() { + return array('db' => 'wiki_pages', 'restore' => 'wiki_page'); + } } diff --git a/mod/wiki/classes/event/course_module_viewed.php b/mod/wiki/classes/event/course_module_viewed.php index 52a86603433..9e16d637230 100644 --- a/mod/wiki/classes/event/course_module_viewed.php +++ b/mod/wiki/classes/event/course_module_viewed.php @@ -45,4 +45,8 @@ class course_module_viewed extends \core\event\course_module_viewed { $this->data['edulevel'] = self::LEVEL_PARTICIPATING; $this->data['objecttable'] = 'wiki'; } + + public static function get_objectid_mapping() { + return array('db' => 'wiki', 'restore' => 'wiki'); + } } diff --git a/mod/wiki/classes/event/page_created.php b/mod/wiki/classes/event/page_created.php index 734b07808d5..9b97a94e750 100644 --- a/mod/wiki/classes/event/page_created.php +++ b/mod/wiki/classes/event/page_created.php @@ -82,4 +82,8 @@ class page_created extends \core\event\base { public function get_url() { return new \moodle_url('/mod/wiki/view.php', array('pageid' => $this->objectid)); } + + public static function get_objectid_mapping() { + return array('db' => 'wiki_pages', 'restore' => 'wiki_page'); + } } diff --git a/mod/wiki/classes/event/page_deleted.php b/mod/wiki/classes/event/page_deleted.php index de69394208e..52eed433370 100644 --- a/mod/wiki/classes/event/page_deleted.php +++ b/mod/wiki/classes/event/page_deleted.php @@ -88,4 +88,15 @@ class page_deleted extends \core\event\base { public function get_url() { return new \moodle_url('/mod/wiki/admin.php', array('pageid' => $this->objectid)); } + + public static function get_objectid_mapping() { + return array('db' => 'wiki_pages', 'restore' => 'wiki_page'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['subwikiid'] = array('db' => 'wiki_subwikis', 'restore' => 'wiki_subwiki'); + + return $othermapped; + } } diff --git a/mod/wiki/classes/event/page_diff_viewed.php b/mod/wiki/classes/event/page_diff_viewed.php index 4c0007c0faf..8d43c1352b0 100644 --- a/mod/wiki/classes/event/page_diff_viewed.php +++ b/mod/wiki/classes/event/page_diff_viewed.php @@ -110,4 +110,13 @@ class page_diff_viewed extends \core\event\base { throw new \coding_exception('The \'compare\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'wiki_pages', 'restore' => 'wiki_page'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/mod/wiki/classes/event/page_history_viewed.php b/mod/wiki/classes/event/page_history_viewed.php index 8ace0becd5e..52af74d77e5 100644 --- a/mod/wiki/classes/event/page_history_viewed.php +++ b/mod/wiki/classes/event/page_history_viewed.php @@ -82,4 +82,8 @@ class page_history_viewed extends \core\event\base { public function get_url() { return new \moodle_url('/mod/wiki/history.php', array('pageid' => $this->objectid)); } + + public static function get_objectid_mapping() { + return array('db' => 'wiki_pages', 'restore' => 'wiki_page'); + } } diff --git a/mod/wiki/classes/event/page_locks_deleted.php b/mod/wiki/classes/event/page_locks_deleted.php index 991c8e42464..cf81976b27d 100644 --- a/mod/wiki/classes/event/page_locks_deleted.php +++ b/mod/wiki/classes/event/page_locks_deleted.php @@ -31,7 +31,7 @@ defined('MOODLE_INTERNAL') || die(); * @property-read array $other { * Extra information about event. * - * - int section: (optional) section id. + * - string section: (optional) section name. * } * * @package mod_wiki @@ -88,4 +88,13 @@ class page_locks_deleted extends \core\event\base { public function get_url() { return new \moodle_url('/mod/wiki/view.php', array('pageid' => $this->objectid)); } + + public static function get_objectid_mapping() { + return array('db' => 'wiki_pages', 'restore' => 'wiki_page'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/mod/wiki/classes/event/page_map_viewed.php b/mod/wiki/classes/event/page_map_viewed.php index f10f7e4b93a..a668badefb9 100644 --- a/mod/wiki/classes/event/page_map_viewed.php +++ b/mod/wiki/classes/event/page_map_viewed.php @@ -101,4 +101,13 @@ class page_map_viewed extends \core\event\base { throw new \coding_exception('The \'option\' value must be set in other, even if 0.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'wiki_pages', 'restore' => 'wiki_page'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/mod/wiki/classes/event/page_updated.php b/mod/wiki/classes/event/page_updated.php index ab792b4ad93..7075535c21f 100644 --- a/mod/wiki/classes/event/page_updated.php +++ b/mod/wiki/classes/event/page_updated.php @@ -88,4 +88,13 @@ class page_updated extends \core\event\base { public function get_url() { return new \moodle_url('/mod/wiki/view.php', array('pageid' => $this->objectid)); } + + public static function get_objectid_mapping() { + return array('db' => 'wiki_pages', 'restore' => 'wiki_page'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/mod/wiki/classes/event/page_version_deleted.php b/mod/wiki/classes/event/page_version_deleted.php index 2fcf2dfd942..ef0f7bfbd6f 100644 --- a/mod/wiki/classes/event/page_version_deleted.php +++ b/mod/wiki/classes/event/page_version_deleted.php @@ -101,4 +101,15 @@ class page_version_deleted extends \core\event\base { throw new \coding_exception('The \'pageid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'wiki_versions', 'restore' => 'wiki_version'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['pageid'] = array('db' => 'wiki_pages', 'restore' => 'wiki_page'); + + return $othermapped; + } } diff --git a/mod/wiki/classes/event/page_version_restored.php b/mod/wiki/classes/event/page_version_restored.php index ddef9726aa3..3a10c0f8978 100644 --- a/mod/wiki/classes/event/page_version_restored.php +++ b/mod/wiki/classes/event/page_version_restored.php @@ -102,4 +102,15 @@ class page_version_restored extends \core\event\base { throw new \coding_exception('The pageid needs to be set in $other'); } } + + public static function get_objectid_mapping() { + return array('db' => 'wiki_versions', 'restore' => 'wiki_version'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['pageid'] = array('db' => 'wiki_pages', 'restore' => 'wiki_page'); + + return $othermapped; + } } diff --git a/mod/wiki/classes/event/page_version_viewed.php b/mod/wiki/classes/event/page_version_viewed.php index 6a4e49d8b59..aed8a7c84f7 100644 --- a/mod/wiki/classes/event/page_version_viewed.php +++ b/mod/wiki/classes/event/page_version_viewed.php @@ -103,4 +103,15 @@ class page_version_viewed extends \core\event\base { throw new \coding_exception('The versionid need to be set in $other'); } } + + public static function get_objectid_mapping() { + return array('db' => 'wiki_pages', 'restore' => 'wiki_page'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['versionid'] = array('db' => 'wiki_versions', 'restore' => 'wiki_version'); + + return $othermapped; + } } diff --git a/mod/wiki/classes/event/page_viewed.php b/mod/wiki/classes/event/page_viewed.php index 8d10d2dc132..357663281c8 100644 --- a/mod/wiki/classes/event/page_viewed.php +++ b/mod/wiki/classes/event/page_viewed.php @@ -28,6 +28,15 @@ defined('MOODLE_INTERNAL') || die(); /** * The mod_wiki page viewed event class. * + * @property-read array $other { + * Extra information about the event. + * + * - string title: (optional) the wiki title + * - int wid: (optional) the wiki id + * - int group: (optional) the group id + * - string groupanduser: (optional) the groupid-userid + * } + * * @package mod_wiki * @since Moodle 2.7 * @copyright 2013 Rajesh Taneja @@ -102,4 +111,16 @@ class page_viewed extends \core\event\base { return new \moodle_url('/mod/wiki/view.php', array('pageid' => $this->objectid)); } } + + public static function get_objectid_mapping() { + return array('db' => 'wiki_pages', 'restore' => 'wiki_page'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['wid'] = array('db' => 'wiki', 'restore' => 'wiki'); + $othermapped['group'] = array('db' => 'groups', 'restore' => 'group'); + + return $othermapped; + } } diff --git a/mod/workshop/backup/moodle2/restore_workshop_stepslib.php b/mod/workshop/backup/moodle2/restore_workshop_stepslib.php index 4ca2b2c8f82..a3680da5ccd 100644 --- a/mod/workshop/backup/moodle2/restore_workshop_stepslib.php +++ b/mod/workshop/backup/moodle2/restore_workshop_stepslib.php @@ -204,6 +204,7 @@ class restore_workshop_activity_structure_step extends restore_activity_structur $data->timegraded = $this->apply_date_offset($data->timegraded); $newitemid = $DB->insert_record('workshop_aggregations', $data); + $this->set_mapping('workshop_aggregation', $oldid, $newitemid, true); } protected function after_execute() { diff --git a/mod/workshop/classes/event/assessable_uploaded.php b/mod/workshop/classes/event/assessable_uploaded.php index 861f92de9ed..34e1a1a0f6e 100644 --- a/mod/workshop/classes/event/assessable_uploaded.php +++ b/mod/workshop/classes/event/assessable_uploaded.php @@ -128,4 +128,8 @@ class assessable_uploaded extends \core\event\assessable_uploaded { public function set_legacy_logdata($legacylogdata) { $this->legacylogdata = $legacylogdata; } + + public static function get_objectid_mapping() { + return array('db' => 'workshop_submissions', 'restore' => 'workshop_submission'); + } } diff --git a/mod/workshop/classes/event/assessment_evaluated.php b/mod/workshop/classes/event/assessment_evaluated.php index a865b738239..2392a6822c1 100644 --- a/mod/workshop/classes/event/assessment_evaluated.php +++ b/mod/workshop/classes/event/assessment_evaluated.php @@ -80,4 +80,13 @@ class assessment_evaluated extends \core\event\base { public function get_url() { return new \moodle_url('/mod/workshop/view.php', array('id' => $this->contextinstanceid)); } + + public static function get_objectid_mapping() { + return array('db' => 'workshop_aggregations', 'restore' => 'workshop_aggregation'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/mod/workshop/classes/event/assessment_evaluations_reset.php b/mod/workshop/classes/event/assessment_evaluations_reset.php index 68145df942d..e9ea908f36a 100644 --- a/mod/workshop/classes/event/assessment_evaluations_reset.php +++ b/mod/workshop/classes/event/assessment_evaluations_reset.php @@ -103,4 +103,11 @@ class assessment_evaluations_reset extends \core\event\base { throw new \coding_exception('The \'workshopid\' value must be set in other.'); } } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['workshopid'] = array('db' => 'workshop', 'restore' => 'workshop'); + + return $othermapped; + } } diff --git a/mod/workshop/classes/event/assessment_reevaluated.php b/mod/workshop/classes/event/assessment_reevaluated.php index 1e401c473f2..8e4f8a39746 100644 --- a/mod/workshop/classes/event/assessment_reevaluated.php +++ b/mod/workshop/classes/event/assessment_reevaluated.php @@ -90,4 +90,13 @@ class assessment_reevaluated extends \core\event\base { public function get_url() { return new \moodle_url('/mod/workshop/view.php', array('id' => $this->contextinstanceid)); } + + public static function get_objectid_mapping() { + return array('db' => 'workshop_aggregations', 'restore' => 'workshop_aggregation'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/mod/workshop/classes/event/assessments_reset.php b/mod/workshop/classes/event/assessments_reset.php index 2e1a32b6c4c..8d7d2a083d9 100644 --- a/mod/workshop/classes/event/assessments_reset.php +++ b/mod/workshop/classes/event/assessments_reset.php @@ -102,4 +102,11 @@ class assessments_reset extends \core\event\base { throw new \coding_exception('The \'workshopid\' value must be set in other.'); } } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['workshopid'] = array('db' => 'workshop', 'restore' => 'workshop'); + + return $othermapped; + } } diff --git a/mod/workshop/classes/event/course_module_viewed.php b/mod/workshop/classes/event/course_module_viewed.php index 00e184bfb1d..794384c4150 100644 --- a/mod/workshop/classes/event/course_module_viewed.php +++ b/mod/workshop/classes/event/course_module_viewed.php @@ -71,4 +71,8 @@ class course_module_viewed extends \core\event\course_module_viewed { $workshop = new \workshop($workshop, $cm, $course); return (object)array('workshop' => $workshop, 'user' => $USER); } + + public static function get_objectid_mapping() { + return array('db' => 'workshop', 'restore' => 'workshop'); + } } diff --git a/mod/workshop/classes/event/phase_switched.php b/mod/workshop/classes/event/phase_switched.php index faefe75e920..16281932354 100644 --- a/mod/workshop/classes/event/phase_switched.php +++ b/mod/workshop/classes/event/phase_switched.php @@ -103,4 +103,13 @@ class phase_switched extends \core\event\base { throw new \coding_exception('The \'workshopphase\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'workshop', 'restore' => 'workshop'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/mod/workshop/classes/event/submission_assessed.php b/mod/workshop/classes/event/submission_assessed.php index 94dda7002a4..e2c9e3943d2 100644 --- a/mod/workshop/classes/event/submission_assessed.php +++ b/mod/workshop/classes/event/submission_assessed.php @@ -108,4 +108,16 @@ class submission_assessed extends \core\event\base { throw new \coding_exception('The \'submissionid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'workshop_assessments', 'restore' => 'workshop_assessment'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['submissionid'] = array('db' => 'workshop_submissions', 'restore' => 'workshop_submission'); + $othermapped['workshopid'] = array('db' => 'workshop', 'restore' => 'workshop'); + + return $othermapped; + } } diff --git a/mod/workshop/classes/event/submission_created.php b/mod/workshop/classes/event/submission_created.php index 928eb566631..3503f5265b9 100644 --- a/mod/workshop/classes/event/submission_created.php +++ b/mod/workshop/classes/event/submission_created.php @@ -88,4 +88,13 @@ class submission_created extends \core\event\base { 'submission.php?cmid=' . $this->contextinstanceid . '&id=' . $this->objectid, $this->objectid, $this->contextinstanceid); } + + public static function get_objectid_mapping() { + return array('db' => 'workshop_submissions', 'restore' => 'workshop_submission'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/mod/workshop/classes/event/submission_reassessed.php b/mod/workshop/classes/event/submission_reassessed.php index 30b5967b10f..1c55c9678a6 100644 --- a/mod/workshop/classes/event/submission_reassessed.php +++ b/mod/workshop/classes/event/submission_reassessed.php @@ -109,4 +109,16 @@ class submission_reassessed extends \core\event\base { throw new \coding_exception('The \'submissionid\' value must be set in other.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'workshop_assessments', 'restore' => 'workshop_assessment'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['submissionid'] = array('db' => 'workshop_submissions', 'restore' => 'workshop_submission'); + $othermapped['workshopid'] = array('db' => 'workshop', 'restore' => 'workshop'); + + return $othermapped; + } } diff --git a/mod/workshop/classes/event/submission_updated.php b/mod/workshop/classes/event/submission_updated.php index cb727fb4e21..b23ee777b0a 100644 --- a/mod/workshop/classes/event/submission_updated.php +++ b/mod/workshop/classes/event/submission_updated.php @@ -88,4 +88,13 @@ class submission_updated extends \core\event\base { 'submission.php?cmid=' . $this->contextinstanceid . '&id=' . $this->objectid, $this->objectid, $this->contextinstanceid); } + + public static function get_objectid_mapping() { + return array('db' => 'workshop_submissions', 'restore' => 'workshop_submission'); + } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/mod/workshop/classes/event/submission_viewed.php b/mod/workshop/classes/event/submission_viewed.php index eac6caee2f1..c6ae693a5c1 100644 --- a/mod/workshop/classes/event/submission_viewed.php +++ b/mod/workshop/classes/event/submission_viewed.php @@ -102,4 +102,15 @@ class submission_viewed extends \core\event\base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_objectid_mapping() { + return array('db' => 'workshop_submissions', 'restore' => 'workshop_submission'); + } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['workshopid'] = array('db' => 'workshop', 'restore' => 'workshop'); + + return $othermapped; + } } diff --git a/report/log/classes/event/report_viewed.php b/report/log/classes/event/report_viewed.php index d8ef4b46ec9..eaf24ab0654 100644 --- a/report/log/classes/event/report_viewed.php +++ b/report/log/classes/event/report_viewed.php @@ -123,4 +123,12 @@ class report_viewed extends \core\event\base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_other_mapping() { + $othermapped = array(); + $othermapped['modid'] = array('db' => 'course_modules', 'restore' => 'course_module'); + $othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group'); + + return $othermapped; + } } diff --git a/report/log/classes/event/user_report_viewed.php b/report/log/classes/event/user_report_viewed.php index d553306d0f4..46672d00d54 100644 --- a/report/log/classes/event/user_report_viewed.php +++ b/report/log/classes/event/user_report_viewed.php @@ -105,4 +105,9 @@ class user_report_viewed extends \core\event\base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/report/outline/classes/event/activity_report_viewed.php b/report/outline/classes/event/activity_report_viewed.php index 507e8135965..09df8365a53 100644 --- a/report/outline/classes/event/activity_report_viewed.php +++ b/report/outline/classes/event/activity_report_viewed.php @@ -80,4 +80,5 @@ class activity_report_viewed extends \core\event\base { public function get_url() { return new \moodle_url('/report/outline/index.php', array('course' => $this->courseid)); } + } diff --git a/report/outline/classes/event/report_viewed.php b/report/outline/classes/event/report_viewed.php index d9397bd2bbd..45277b9bea7 100644 --- a/report/outline/classes/event/report_viewed.php +++ b/report/outline/classes/event/report_viewed.php @@ -105,4 +105,10 @@ class report_viewed extends \core\event\base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } + } diff --git a/report/participation/classes/event/report_viewed.php b/report/participation/classes/event/report_viewed.php index d5b9d8b5159..8a4d8aea4f1 100644 --- a/report/participation/classes/event/report_viewed.php +++ b/report/participation/classes/event/report_viewed.php @@ -120,6 +120,19 @@ class report_viewed extends \core\event\base { if (!isset($this->other['action'])) { throw new \coding_exception('The \'action\' value must be set in other.'); } + + } + + public static function get_other_mapping() { + $othermapped = array(); + // This is a badly named variable - it represents "cm->id" not "cm->instance". + $othermapped['instanceid'] = array('db' => 'course_modules', 'restore' => 'course_module'); + + $othermapped['roleid'] = array('db' => 'role', 'restore' => 'role'); + $othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group'); + + return $othermapped; + } } diff --git a/report/questioninstances/classes/event/report_viewed.php b/report/questioninstances/classes/event/report_viewed.php index 5e79da8f724..36e3f6520e2 100644 --- a/report/questioninstances/classes/event/report_viewed.php +++ b/report/questioninstances/classes/event/report_viewed.php @@ -100,5 +100,10 @@ class report_viewed extends \core\event\base { throw new \coding_exception('The \'requestedqtype\' value must be set in other.'); } } + + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/report/stats/classes/event/report_viewed.php b/report/stats/classes/event/report_viewed.php index e485a79808f..35803d00dac 100644 --- a/report/stats/classes/event/report_viewed.php +++ b/report/stats/classes/event/report_viewed.php @@ -114,5 +114,10 @@ class report_viewed extends \core\event\base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + + public static function get_other_mapping() { + // Nothing to map. + return array(); + } }