From ba66edd0740c1dc5daafd029f70e7e39086d1646 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Sun, 8 Mar 2015 19:38:44 +0100 Subject: [PATCH 01/16] MDL-46455 backup: Extend support for subplugins to any plugin. In order to implement the backup and restore of log stores, that are created as subplugins of the tool_log plugin , we need to extend subplugins support from activities to virtually any plugin. Basically that implies moving the add_subplugin_structure() method from its current, restricted, activity level to general backup_structure_step. This commit implements the change in backup, covered with tests verifying old, bc behavior and also new, general one. --- backup/moodle2/backup_stepslib.php | 56 +-------- .../util/plan/backup_structure_step.class.php | 82 ++++++++++++- .../plan/tests/fixtures/plan_fixtures.php | 21 +++- backup/util/plan/tests/step_test.php | 111 ++++++++++++++++++ 4 files changed, 212 insertions(+), 58 deletions(-) diff --git a/backup/moodle2/backup_stepslib.php b/backup/moodle2/backup_stepslib.php index 89c75341c1c..4246b927fc9 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... 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/tests/fixtures/plan_fixtures.php b/backup/util/plan/tests/fixtures/plan_fixtures.php index 1283e7e5304..a2775d2984e 100644 --- a/backup/util/plan/tests/fixtures/plan_fixtures.php +++ b/backup/util/plan/tests/fixtures/plan_fixtures.php @@ -61,6 +61,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 +76,14 @@ 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; + } } /** @@ -80,7 +91,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 +102,14 @@ 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); + } } /** diff --git a/backup/util/plan/tests/step_test.php b/backup/util/plan/tests/step_test.php index 44afd8d74c1..7a47c319428 100644 --- a/backup/util/plan/tests/step_test.php +++ b/backup/util/plan/tests/step_test.php @@ -134,6 +134,117 @@ 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. + } + /** * wrong base_step class tests */ From 6a45e6b169b63c0f11545a4268e294bb27c1d47a Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Mon, 16 Mar 2015 03:08:44 +0100 Subject: [PATCH 02/16] MDL-46455 restore: Extend support for subplugins to any plugin. In order to implement the backup and restore of log stores, that are created as subplugins of the tool_log plugin , we need to extend subplugins support from activities to virtually any plugin. Basically that implies moving the add_subplugin_structure() method from its current, restricted, activity level to general restore_structure_step. This commit implements the change in restore, covered with tests verifying old, bc behavior and also new, general one. --- backup/moodle2/restore_stepslib.php | 41 +---- .../plan/restore_structure_step.class.php | 70 +++++++++ .../plan/tests/fixtures/plan_fixtures.php | 47 ++++++ backup/util/plan/tests/step_test.php | 144 ++++++++++++++++++ 4 files changed, 263 insertions(+), 39 deletions(-) diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index 587015dc2dd..6cabaabeac3 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -3782,48 +3782,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/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 a2775d2984e..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'); /** @@ -86,6 +87,31 @@ class mock_backup_task_basepath extends backup_task { } } +/** + * 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; + } +} + /** * Instantiable class extending backup_structure_step in order to be able to perform tests */ @@ -112,6 +138,27 @@ class mock_backup_structure_step extends backup_structure_step { } } +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; + } +} + /** * Instantiable class extending activity_backup_setting to be added to task and perform tests */ diff --git a/backup/util/plan/tests/step_test.php b/backup/util/plan/tests/step_test.php index 7a47c319428..826b349d990 100644 --- a/backup/util/plan/tests/step_test.php +++ b/backup/util/plan/tests/step_test.php @@ -245,6 +245,150 @@ class backup_step_testcase extends advanced_testcase { // 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 */ From 73c2a354202c7f280bf06d0aacc8db7930a002ff Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Sun, 29 Mar 2015 16:53:07 +0200 Subject: [PATCH 03/16] MDL-46455 backup: Implement backup of standard logstore Using standard subplugin support, this commit implements the backup of logstore subplugins in general and the standard logstore in particular. Notes: - Uses a custom final element (base64_encode_final_element) to support the storage of serialized 'other' information in logs. - Organization: Instead of directly extending backup_subplugin, every logstore extends backup_tool_log_logstore_subplugin just in case any shared code is needed in the future. - Implements both course and activity logs, sharing the structure completely (both are based in contextid to pick the target information, from database or whatever other logstores use). --- ...ckup_tool_log_logstore_subplugin.class.php | 37 +++++++++++++ ...ckup_logstore_standard_subplugin.class.php | 55 +++++++++++++++++++ backup/moodle2/backup_activity_task.class.php | 3 + backup/moodle2/backup_course_task.class.php | 3 + backup/moodle2/backup_custom_fields.php | 19 +++++++ backup/moodle2/backup_stepslib.php | 30 ++++++++++ 6 files changed, 147 insertions(+) create mode 100644 admin/tool/log/backup/moodle2/backup_tool_log_logstore_subplugin.class.php create mode 100644 admin/tool/log/store/standard/backup/moodle2/backup_logstore_standard_subplugin.class.php 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/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/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 4246b927fc9..436f19f36dd 100644 --- a/backup/moodle2/backup_stepslib.php +++ b/backup/moodle2/backup_stepslib.php @@ -1485,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...) From ea6c56437a9f081e15152bec0ba655b577d5b449 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Mon, 30 Mar 2015 01:19:01 +0200 Subject: [PATCH 04/16] MDL-46455 restore: Implement restore of standard logstore Using standard subplugin support, this commits implements the restore of logstore subplugins in general and the standard logstore is particular. Notes: - TODO: Decide about these 2 pending issues: 1) Some logs are already created (events fired) by the restore process itself. Every time an API is used and it fires events... corresponding (and actual!) logs are created. We need to prevent restore to duplicate them (or, alternatively, stop firing events when restore is happening). 2) There are 2 pieces of information in the logs that, right now, can not be restored, because the process does not know enough to be able to remap that information to its new counterparts. We are talking about objectid and other columns. So we need to specify, in some way understandable by restore, to which existing mappings they correspond to. --- ...tore_tool_log_logstore_subplugin.class.php | 37 ++++++ ...tore_logstore_standard_subplugin.class.php | 115 ++++++++++++++++++ .../moodle2/restore_activity_task.class.php | 3 + backup/moodle2/restore_final_task.class.php | 5 +- backup/moodle2/restore_stepslib.php | 69 +++++++++++ 5 files changed, 228 insertions(+), 1 deletion(-) create mode 100644 admin/tool/log/backup/moodle2/restore_tool_log_logstore_subplugin.class.php create mode 100644 admin/tool/log/store/standard/backup/moodle2/restore_logstore_standard_subplugin.class.php 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..2b6ec5450b0 --- /dev/null +++ b/admin/tool/log/backup/moodle2/restore_tool_log_logstore_subplugin.class.php @@ -0,0 +1,37 @@ +. + +/** + * 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 { +} 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..8457a900aac --- /dev/null +++ b/admin/tool/log/store/standard/backup/moodle2/restore_logstore_standard_subplugin.class.php @@ -0,0 +1,115 @@ +. + +/** + * 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 = (object)$data; + + // Complete the information that does not come from backup. + if (! $data->contextid = $this->get_mappingid('context', $data->contextid)) { + // Something went really wrong, cannot find the context this log belongs to. + 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. + if (! $data->userid = $this->get_mappingid('user', $data->userid)) { + // Something went really wrong, cannot find the user this log belongs to. + return; + } + if (!empty($data->relateduserid)) { // This is optional. + if (! $data->relateduserid = $this->get_mappingid('user', $data->relateduserid)) { + // Something went really wrong, cannot find the relateduserid this log is about. + return; + } + } + if (!empty($data->realuserid)) { // This is optional. + if (! $data->realuserid = $this->get_mappingid('user', $data->realuserid)) { + // Something went really wrong, cannot find the realuserid this log is logged in as. + 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)) { + // TODO: Call to the resolver. + return; + } + if (!empty($data->other)) { + // TODO: Call to the resolver. + return; + } + + // Arrived here, everything is now ready to be added to database, let's proceed. + $DB->insert_record('logstore_standard_log', $data); + } +} 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 6cabaabeac3..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 From bcfa51ca41b9945d81a2f1d9112c9383db31eea2 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Fri, 18 Sep 2015 16:00:08 -0700 Subject: [PATCH 05/16] MDL-46455 logstore_database: added backup/restore support --- ...tore_tool_log_logstore_subplugin.class.php | 63 +++++++++++ ...ckup_logstore_database_subplugin.class.php | 64 +++++++++++ ...tore_logstore_database_subplugin.class.php | 102 ++++++++++++++++++ .../log/store/database/classes/log/store.php | 24 +++++ ...tore_logstore_standard_subplugin.class.php | 52 +-------- .../dbops/backup_structure_dbops.class.php | 6 +- .../structure/backup_nested_element.class.php | 26 +++++ 7 files changed, 285 insertions(+), 52 deletions(-) create mode 100644 admin/tool/log/store/database/backup/moodle2/backup_logstore_database_subplugin.class.php create mode 100644 admin/tool/log/store/database/backup/moodle2/restore_logstore_database_subplugin.class.php 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 index 2b6ec5450b0..5a9e0b921bf 100644 --- 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 @@ -34,4 +34,67 @@ defined('MOODLE_INTERNAL') || die(); * 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. + if (!$data->contextid = $this->get_mappingid('context', $data->contextid)) { + // Something went really wrong, cannot find the context this log belongs to. + 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. + if (!$data->userid = $this->get_mappingid('user', $data->userid)) { + // Something went really wrong, cannot find the user this log belongs to. + return; + } + if (!empty($data->relateduserid)) { // This is optional. + if (!$data->relateduserid = $this->get_mappingid('user', $data->relateduserid)) { + // Something went really wrong, cannot find the relateduserid this log is about. + return; + } + } + if (!empty($data->realuserid)) { // This is optional. + if (!$data->realuserid = $this->get_mappingid('user', $data->realuserid)) { + // Something went really wrong, cannot find the realuserid this log is logged in as. + 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)) { + // TODO: Call to the resolver. + return; + } + if (!empty($data->other)) { + // TODO: Call to the resolver. + return; + } + + return $data; + } } 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..8b0dae4bcbb --- /dev/null +++ b/admin/tool/log/store/database/backup/moodle2/backup_logstore_database_subplugin.class.php @@ -0,0 +1,64 @@ +. + +/** + * 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(); + +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_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/restore_logstore_standard_subplugin.class.php b/admin/tool/log/store/standard/backup/moodle2/restore_logstore_standard_subplugin.class.php index 8457a900aac..ac041e46de2 100644 --- 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 @@ -60,56 +60,10 @@ class restore_logstore_standard_subplugin extends restore_tool_log_logstore_subp public function process_logstore_standard_log($data) { global $DB; - $data = (object)$data; + $data = $this->process_log($data); - // Complete the information that does not come from backup. - if (! $data->contextid = $this->get_mappingid('context', $data->contextid)) { - // Something went really wrong, cannot find the context this log belongs to. - return; + if ($data) { + $DB->insert_record('logstore_standard_log', $data); } - $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. - if (! $data->userid = $this->get_mappingid('user', $data->userid)) { - // Something went really wrong, cannot find the user this log belongs to. - return; - } - if (!empty($data->relateduserid)) { // This is optional. - if (! $data->relateduserid = $this->get_mappingid('user', $data->relateduserid)) { - // Something went really wrong, cannot find the relateduserid this log is about. - return; - } - } - if (!empty($data->realuserid)) { // This is optional. - if (! $data->realuserid = $this->get_mappingid('user', $data->realuserid)) { - // Something went really wrong, cannot find the realuserid this log is logged in as. - 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)) { - // TODO: Call to the resolver. - return; - } - if (!empty($data->other)) { - // TODO: Call to the resolver. - return; - } - - // Arrived here, everything is now ready to be added to database, let's proceed. - $DB->insert_record('logstore_standard_log', $data); } } diff --git a/backup/util/dbops/backup_structure_dbops.class.php b/backup/util/dbops/backup_structure_dbops.class.php index 4ceb221defc..b3767d5b4d2 100644 --- a/backup/util/dbops/backup_structure_dbops.class.php +++ b/backup/util/dbops/backup_structure_dbops.class.php @@ -33,11 +33,11 @@ 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 && @@ -48,10 +48,10 @@ abstract class backup_structure_dbops extends backup_dbops { return new backup_array_iterator($element->get_source_array()); } else if ($element->get_source_table() !== null) { // It's one table, return recordset iterator - return $DB->get_recordset($element->get_source_table(), self::convert_params_to_values($params, $processor), $element->get_source_table_sortby()); + return $element->get_source_db()->get_recordset($element->get_source_table(), self::convert_params_to_values($params, $processor), $element->get_source_table_sortby()); } else if ($element->get_source_sql() !== null) { // It's one sql, return recordset iterator - return $DB->get_recordset_sql($element->get_source_sql(), self::convert_params_to_values($params, $processor)); + return $element->get_source_db()->get_recordset_sql($element->get_source_sql(), self::convert_params_to_values($params, $processor)); } else { // No sources, supress completely, using null iterator return new backup_null_iterator(); diff --git a/backup/util/structure/backup_nested_element.class.php b/backup/util/structure/backup_nested_element.class.php index 32abd9ac19d..68606b13041 100644 --- a/backup/util/structure/backup_nested_element.class.php +++ b/backup/util/structure/backup_nested_element.class.php @@ -41,6 +41,11 @@ class backup_nested_element extends base_nested_element implements processable { protected $results; // Logs the results we encounter during the process. protected $logs; // Some log messages that could be retrieved later. + /** + * @var \moodle_database $dbtouse + */ + protected $dbtouse; + /** * Constructor - instantiates one backup_nested_element, specifying its basic info. * @@ -49,6 +54,8 @@ class backup_nested_element extends base_nested_element implements processable { * @param array $final_elements this element will handle (optional, defaults to null) */ public function __construct($name, $attributes = null, $final_elements = null) { + global $DB; + parent::__construct($name, $attributes, $final_elements); $this->var_array = null; $this->table = null; @@ -61,6 +68,7 @@ class backup_nested_element extends base_nested_element implements processable { $this->counter = 0; $this->results = array(); $this->logs = array(); + $this->dbtouse = $DB; } /** @@ -193,6 +201,15 @@ class backup_nested_element extends base_nested_element implements processable { $this->var_array = $arr; } + /** + * Set the database we want to use. + * + * @param \moodle_database $db + */ + public function set_source_db($db) { + $this->dbtouse = $db; + } + public function set_source_table($table, $params, $sortby = null) { if (!is_array($params)) { // Check we are passing array throw new base_element_struct_exception('setsourcerequiresarrayofparams'); @@ -260,6 +277,15 @@ class backup_nested_element extends base_nested_element implements processable { return $this->var_array; } + /** + * Get the database we want to use. + * + * @return \moodle_database $db + */ + public function get_source_db() { + return $this->dbtouse; + } + public function get_source_table() { return $this->table; } From 51311962c41ab6122c0aa8887bc1d2cf18160ef2 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Mon, 21 Sep 2015 13:39:51 +0800 Subject: [PATCH 06/16] MDL-46455 backup: Keep external database logstore code self-contained. General backup/restore does not need to handle external data sources natively - so any changes needed to achieve this should be contained to the plugin that needs it. --- ...ackup_logstore_database_nested_element.php | 98 +++++++++++++++++++ ...ckup_logstore_database_subplugin.class.php | 3 +- .../dbops/backup_structure_dbops.class.php | 8 +- .../structure/backup_nested_element.class.php | 26 ----- 4 files changed, 105 insertions(+), 30 deletions(-) create mode 100644 admin/tool/log/store/database/backup/moodle2/backup_logstore_database_nested_element.php 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 index 8b0dae4bcbb..0642078b08b 100644 --- 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 @@ -24,6 +24,7 @@ */ defined('MOODLE_INTERNAL') || die(); +require_once('backup_logstore_database_nested_element.php'); class backup_logstore_database_subplugin extends backup_tool_log_logstore_subplugin { @@ -39,7 +40,7 @@ class backup_logstore_database_subplugin extends backup_tool_log_logstore_subplu // Create the custom (base64 encoded, xml safe) 'other' final element. $otherelement = new base64_encode_final_element('other'); - $subpluginlog = new backup_nested_element('logstore_database_log', array('id'), array( + $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')); diff --git a/backup/util/dbops/backup_structure_dbops.class.php b/backup/util/dbops/backup_structure_dbops.class.php index b3767d5b4d2..8ffc63e2efd 100644 --- a/backup/util/dbops/backup_structure_dbops.class.php +++ b/backup/util/dbops/backup_structure_dbops.class.php @@ -33,6 +33,8 @@ 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'); @@ -48,17 +50,17 @@ abstract class backup_structure_dbops extends backup_dbops { return new backup_array_iterator($element->get_source_array()); } else if ($element->get_source_table() !== null) { // It's one table, return recordset iterator - return $element->get_source_db()->get_recordset($element->get_source_table(), self::convert_params_to_values($params, $processor), $element->get_source_table_sortby()); + return $DB->get_recordset($element->get_source_table(), self::convert_params_to_values($params, $processor), $element->get_source_table_sortby()); } else if ($element->get_source_sql() !== null) { // It's one sql, return recordset iterator - return $element->get_source_db()->get_recordset_sql($element->get_source_sql(), self::convert_params_to_values($params, $processor)); + return $DB->get_recordset_sql($element->get_source_sql(), self::convert_params_to_values($params, $processor)); } else { // No sources, supress completely, using null iterator return new backup_null_iterator(); } } - 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/structure/backup_nested_element.class.php b/backup/util/structure/backup_nested_element.class.php index 68606b13041..32abd9ac19d 100644 --- a/backup/util/structure/backup_nested_element.class.php +++ b/backup/util/structure/backup_nested_element.class.php @@ -41,11 +41,6 @@ class backup_nested_element extends base_nested_element implements processable { protected $results; // Logs the results we encounter during the process. protected $logs; // Some log messages that could be retrieved later. - /** - * @var \moodle_database $dbtouse - */ - protected $dbtouse; - /** * Constructor - instantiates one backup_nested_element, specifying its basic info. * @@ -54,8 +49,6 @@ class backup_nested_element extends base_nested_element implements processable { * @param array $final_elements this element will handle (optional, defaults to null) */ public function __construct($name, $attributes = null, $final_elements = null) { - global $DB; - parent::__construct($name, $attributes, $final_elements); $this->var_array = null; $this->table = null; @@ -68,7 +61,6 @@ class backup_nested_element extends base_nested_element implements processable { $this->counter = 0; $this->results = array(); $this->logs = array(); - $this->dbtouse = $DB; } /** @@ -201,15 +193,6 @@ class backup_nested_element extends base_nested_element implements processable { $this->var_array = $arr; } - /** - * Set the database we want to use. - * - * @param \moodle_database $db - */ - public function set_source_db($db) { - $this->dbtouse = $db; - } - public function set_source_table($table, $params, $sortby = null) { if (!is_array($params)) { // Check we are passing array throw new base_element_struct_exception('setsourcerequiresarrayofparams'); @@ -277,15 +260,6 @@ class backup_nested_element extends base_nested_element implements processable { return $this->var_array; } - /** - * Get the database we want to use. - * - * @return \moodle_database $db - */ - public function get_source_db() { - return $this->dbtouse; - } - public function get_source_table() { return $this->table; } From 6920d3904c49c85106445ec377a23c8a62c99ade Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 21 Sep 2015 16:43:44 -0700 Subject: [PATCH 07/16] MDL-46455 restore: added restore support for the 'objectid' in events --- ...tore_tool_log_logstore_subplugin.class.php | 18 ++++++++- lib/classes/event/base.php | 39 +++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) 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 index 5a9e0b921bf..348b71ac2ab 100644 --- 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 @@ -87,8 +87,22 @@ abstract class restore_tool_log_logstore_subplugin extends restore_subplugin { // 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)) { - // TODO: Call to the resolver. - return; + // Check if there is an available class for this event we can use to map this value. + $eventclass = $data->eventname; + if (class_exists($eventclass)) { + $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 { + return; // No such class, can not restore. + } } if (!empty($data->other)) { // TODO: Call to the resolver. diff --git a/lib/classes/event/base.php b/lib/classes/event/base.php index 2ccec1d1fb3..298b88cb178 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,40 @@ 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 must define the + function get_objectid_mapping().', DEBUG_DEVELOPER); + + return false; + } + /** * Get static information about an event. * This is used in reports and is not for general use. From 901a7ff7f2c9228e395c01f276ffeff410b25a47 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 22 Sep 2015 16:25:19 -0700 Subject: [PATCH 08/16] MDL-46455 restore: added restore support for 'other' in events --- ...tore_tool_log_logstore_subplugin.class.php | 28 ++++++++++++- lib/classes/event/base.php | 39 +++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) 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 index 348b71ac2ab..c25693f58c3 100644 --- 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 @@ -105,8 +105,32 @@ abstract class restore_tool_log_logstore_subplugin extends restore_subplugin { } } if (!empty($data->other)) { - // TODO: Call to the resolver. - return; + // Check if there is an available class for this event we can use to map this value. + $eventclass = $data->eventname; + if (class_exists($eventclass)) { + $othermapping = $eventclass::get_other_mapping(); + if ($othermapping) { + // Go through the data we have. + foreach ($data->other as $key => $value) { + // Check if there is a corresponding key we can use to map to. + if (isset($othermapping[$key])) { + // Ok, let's map this. + $mapping = $othermapping[$key]; + // Check if it can not be mapped. + if ((is_int($mapping) && $mapping === \core\event\base::NOT_MAPPED) || + ($mapping['restore'] === \core\event\base::NOT_MAPPED)) { + $data->other[$key] = \core\event\base::NOT_MAPPED; + } else { + $data->other[$key] = $this->get_mappingid($mapping['restore'], $value); + } + } + } + } + // Now we want to serialize it so we can store it in the DB. + $data->other = serialize($data->other); + } else { + return; // No such class, can not restore. + } } return $data; diff --git a/lib/classes/event/base.php b/lib/classes/event/base.php index 298b88cb178..ee2be4041c5 100644 --- a/lib/classes/event/base.php +++ b/lib/classes/event/base.php @@ -517,6 +517,45 @@ abstract class base implements \IteratorAggregate { return false; } + /** + * This is used when restoring course logs where it is required that we + * map the information in 'other' to it's new value in the new course. + * + * Does nothing in the base class except display a debugging message warning + * the user that the event does not contain the required functionality to + * map this information. For events that do not store any other information this + * won't be called, so no debugging message will be displayed. + * + * Example of usage: + * + * $othermapped = array(); + * $othermapped['discussionid'] = array('db' => 'forum_discussions', 'restore' => 'forum_discussion'); + * $othermapped['forumid'] = array('db' => 'forum', 'restore' => 'forum'); + * return $othermapped; + * + * If an id can not be mapped during restore we set it to \core\event\base::NOT_MAPPED, example - + * + * $othermapped = array(); + * $othermapped['someid'] = array('db' => 'some_table', 'restore' => \core\event\base::NOT_MAPPED); + * return $othermapped; + * + * Note - it isn't necessary to specify the 'db' and 'restore' values in this case, so you can also use - + * + * $othermapped = array(); + * $othermapped['someid'] = \core\event\base::NOT_MAPPED; + * return $othermapped; + * + * The 'db' key refers to the database table and the 'restore' key refers to + * the name of the restore element the other value is associated with. In many + * cases these will be the same. + * + * @return array an array of other values and their corresponding mapping + */ + public static function get_other_mapping() { + debugging('In order to restore course logs accurately the event must define the + function get_other_mapping().', DEBUG_DEVELOPER); + } + /** * Get static information about an event. * This is used in reports and is not for general use. From ef15eae433d2e3baef3cf32d6533ab24d51a8226 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 24 Sep 2015 17:03:41 -0700 Subject: [PATCH 09/16] MDL-46455 mod_*: added additional mapping to be used by events --- mod/forum/backup/moodle2/restore_forum_stepslib.php | 3 +++ mod/workshop/backup/moodle2/restore_workshop_stepslib.php | 1 + 2 files changed, 4 insertions(+) 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/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() { From 0bfafc5ba06d9d88aea35f03c4dc4ad3c7444e0e Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 24 Sep 2015 17:02:57 -0700 Subject: [PATCH 10/16] MDL-46455 mod_*: added restore mapping to events --- .../event/all_submissions_downloaded.php | 4 ++++ .../classes/event/assessable_submitted.php | 9 ++++++++ .../batch_set_marker_allocation_viewed.php | 7 ++++++ .../event/batch_set_workflow_state_viewed.php | 7 ++++++ .../classes/event/extension_granted.php | 4 ++++ mod/assign/classes/event/feedback_viewed.php | 11 ++++++++++ .../classes/event/grading_form_viewed.php | 7 ++++++ .../classes/event/grading_table_viewed.php | 7 ++++++ .../classes/event/identities_revealed.php | 4 ++++ mod/assign/classes/event/marker_updated.php | 11 ++++++++++ ...al_identities_confirmation_page_viewed.php | 7 ++++++ .../classes/event/statement_accepted.php | 4 ++++ .../submission_confirmation_form_viewed.php | 7 ++++++ .../classes/event/submission_created.php | 8 +++++++ .../classes/event/submission_duplicated.php | 4 ++++ .../classes/event/submission_form_viewed.php | 7 ++++++ .../classes/event/submission_graded.php | 4 ++++ .../classes/event/submission_locked.php | 4 ++++ .../event/submission_status_updated.php | 9 ++++++++ .../event/submission_status_viewed.php | 7 ++++++ .../classes/event/submission_unlocked.php | 4 ++++ .../classes/event/submission_updated.php | 8 +++++++ .../classes/event/submission_viewed.php | 11 ++++++++++ .../classes/event/workflow_state_updated.php | 9 ++++++++ .../classes/event/assessable_uploaded.php | 3 +++ .../file/classes/event/submission_created.php | 5 +++++ .../file/classes/event/submission_updated.php | 5 +++++ .../classes/event/assessable_uploaded.php | 4 ++++ .../classes/event/submission_created.php | 7 +++++- .../classes/event/submission_updated.php | 7 +++++- mod/book/classes/event/chapter_created.php | 3 +++ mod/book/classes/event/chapter_deleted.php | 4 ++++ mod/book/classes/event/chapter_updated.php | 3 +++ mod/book/classes/event/chapter_viewed.php | 4 ++++ .../classes/event/course_module_viewed.php | 4 ++++ .../classes/event/book_exported.php | 3 +++ .../tool/print/classes/event/book_printed.php | 3 +++ .../print/classes/event/chapter_printed.php | 5 ++++- .../classes/event/course_module_viewed.php | 4 ++++ mod/chat/classes/event/message_sent.php | 4 ++++ mod/chat/classes/event/sessions_viewed.php | 8 +++++++ mod/choice/classes/event/answer_submitted.php | 22 +++++++++++++++++++ mod/choice/classes/event/answer_updated.php | 22 +++++++++++++++++++ .../classes/event/course_module_viewed.php | 4 ++++ mod/choice/classes/event/report_viewed.php | 4 ++++ .../classes/event/course_module_viewed.php | 4 ++++ mod/data/classes/event/field_created.php | 11 ++++++++++ mod/data/classes/event/field_deleted.php | 11 ++++++++++ mod/data/classes/event/field_updated.php | 11 ++++++++++ mod/data/classes/event/record_created.php | 11 ++++++++++ mod/data/classes/event/record_deleted.php | 11 ++++++++++ mod/data/classes/event/record_updated.php | 11 ++++++++++ mod/data/classes/event/template_updated.php | 7 ++++++ mod/data/classes/event/template_viewed.php | 7 ++++++ .../classes/event/course_module_viewed.php | 4 ++++ .../classes/event/response_deleted.php | 12 ++++++++++ .../classes/event/response_submitted.php | 12 ++++++++++ .../classes/event/course_module_viewed.php | 4 ++++ mod/folder/classes/event/folder_updated.php | 4 ++++ .../classes/event/assessable_uploaded.php | 11 ++++++++++ .../classes/event/course_module_viewed.php | 3 +++ mod/forum/classes/event/course_searched.php | 3 +++ .../classes/event/discussion_created.php | 11 ++++++++++ .../classes/event/discussion_deleted.php | 11 ++++++++++ mod/forum/classes/event/discussion_moved.php | 12 ++++++++++ .../event/discussion_subscription_created.php | 12 ++++++++++ .../event/discussion_subscription_deleted.php | 12 ++++++++++ .../classes/event/discussion_updated.php | 11 ++++++++++ mod/forum/classes/event/discussion_viewed.php | 3 +++ mod/forum/classes/event/post_created.php | 12 ++++++++++ mod/forum/classes/event/post_deleted.php | 12 ++++++++++ mod/forum/classes/event/post_updated.php | 12 ++++++++++ .../classes/event/readtracking_disabled.php | 7 ++++++ .../classes/event/readtracking_enabled.php | 7 ++++++ .../classes/event/subscribers_viewed.php | 6 +++++ .../classes/event/subscription_created.php | 11 ++++++++++ .../classes/event/subscription_deleted.php | 11 ++++++++++ .../classes/event/user_report_viewed.php | 3 +++ .../classes/event/category_created.php | 4 ++++ .../classes/event/category_deleted.php | 4 ++++ .../classes/event/category_updated.php | 4 ++++ .../classes/event/course_module_viewed.php | 15 +++++++++++++ mod/glossary/classes/event/entry_approved.php | 4 ++++ mod/glossary/classes/event/entry_created.php | 9 ++++++++ mod/glossary/classes/event/entry_deleted.php | 9 ++++++++ .../classes/event/entry_disapproved.php | 4 ++++ mod/glossary/classes/event/entry_updated.php | 9 ++++++++ mod/glossary/classes/event/entry_viewed.php | 4 ++++ .../classes/event/course_module_viewed.php | 4 ++++ .../classes/event/content_page_viewed.php | 4 ++++ .../classes/event/course_module_viewed.php | 4 ++++ mod/lesson/classes/event/essay_assessed.php | 12 ++++++++++ .../classes/event/essay_attempt_viewed.php | 4 ++++ .../classes/event/group_override_created.php | 12 ++++++++++ .../classes/event/group_override_deleted.php | 12 ++++++++++ .../classes/event/group_override_updated.php | 12 ++++++++++ mod/lesson/classes/event/highscore_added.php | 10 +++++++++ .../classes/event/highscores_viewed.php | 10 +++++++++ mod/lesson/classes/event/lesson_ended.php | 4 ++++ mod/lesson/classes/event/lesson_restarted.php | 4 ++++ mod/lesson/classes/event/lesson_resumed.php | 4 ++++ mod/lesson/classes/event/lesson_started.php | 4 ++++ mod/lesson/classes/event/page_created.php | 13 +++++++++-- mod/lesson/classes/event/page_deleted.php | 13 +++++++++-- mod/lesson/classes/event/page_moved.php | 20 +++++++++++++---- mod/lesson/classes/event/page_updated.php | 16 +++++++++++--- .../classes/event/question_answered.php | 13 +++++++++-- mod/lesson/classes/event/question_viewed.php | 13 +++++++++-- .../classes/event/user_override_created.php | 11 ++++++++++ .../classes/event/user_override_deleted.php | 11 ++++++++++ .../classes/event/user_override_updated.php | 11 ++++++++++ .../classes/event/course_module_viewed.php | 4 ++++ .../classes/event/course_module_viewed.php | 4 ++++ mod/quiz/classes/event/attempt_abandoned.php | 12 ++++++++++ .../classes/event/attempt_becameoverdue.php | 12 ++++++++++ mod/quiz/classes/event/attempt_deleted.php | 17 ++++++++++++++ .../classes/event/attempt_preview_started.php | 11 ++++++++++ mod/quiz/classes/event/attempt_reviewed.php | 11 ++++++++++ mod/quiz/classes/event/attempt_started.php | 17 ++++++++++++++ mod/quiz/classes/event/attempt_submitted.php | 12 ++++++++++ .../classes/event/attempt_summary_viewed.php | 11 ++++++++++ mod/quiz/classes/event/attempt_viewed.php | 11 ++++++++++ .../classes/event/course_module_viewed.php | 4 ++++ mod/quiz/classes/event/edit_page_viewed.php | 7 ++++++ .../classes/event/group_override_created.php | 12 ++++++++++ .../classes/event/group_override_deleted.php | 12 ++++++++++ .../classes/event/group_override_updated.php | 12 ++++++++++ .../event/question_manually_graded.php | 11 ++++++++++ mod/quiz/classes/event/report_viewed.php | 7 ++++++ .../classes/event/user_override_created.php | 11 ++++++++++ .../classes/event/user_override_deleted.php | 11 ++++++++++ .../classes/event/user_override_updated.php | 11 ++++++++++ .../classes/event/course_module_viewed.php | 4 ++++ mod/scorm/classes/event/attempt_deleted.php | 5 +++++ .../classes/event/course_module_viewed.php | 4 ++++ .../classes/event/interactions_viewed.php | 7 ++++++ mod/scorm/classes/event/report_viewed.php | 7 ++++++ mod/scorm/classes/event/sco_launched.php | 11 ++++++++++ mod/scorm/classes/event/tracks_viewed.php | 8 +++++++ .../classes/event/user_report_viewed.php | 7 ++++++ .../classes/event/course_module_viewed.php | 4 ++++ .../classes/event/report_downloaded.php | 11 ++++++++++ mod/survey/classes/event/report_viewed.php | 11 ++++++++++ .../classes/event/response_submitted.php | 7 ++++++ .../classes/event/course_module_viewed.php | 4 ++++ mod/wiki/classes/event/comments_viewed.php | 4 ++++ .../classes/event/course_module_viewed.php | 4 ++++ mod/wiki/classes/event/page_created.php | 4 ++++ mod/wiki/classes/event/page_deleted.php | 11 ++++++++++ mod/wiki/classes/event/page_diff_viewed.php | 9 ++++++++ .../classes/event/page_history_viewed.php | 4 ++++ mod/wiki/classes/event/page_locks_deleted.php | 11 +++++++++- mod/wiki/classes/event/page_map_viewed.php | 9 ++++++++ mod/wiki/classes/event/page_updated.php | 9 ++++++++ .../classes/event/page_version_deleted.php | 11 ++++++++++ .../classes/event/page_version_restored.php | 11 ++++++++++ .../classes/event/page_version_viewed.php | 11 ++++++++++ mod/wiki/classes/event/page_viewed.php | 4 ++++ .../classes/event/assessable_uploaded.php | 4 ++++ .../classes/event/assessment_evaluated.php | 9 ++++++++ .../event/assessment_evaluations_reset.php | 7 ++++++ .../classes/event/assessment_reevaluated.php | 9 ++++++++ .../classes/event/assessments_reset.php | 7 ++++++ .../classes/event/course_module_viewed.php | 4 ++++ mod/workshop/classes/event/phase_switched.php | 9 ++++++++ .../classes/event/submission_assessed.php | 12 ++++++++++ .../classes/event/submission_created.php | 9 ++++++++ .../classes/event/submission_reassessed.php | 12 ++++++++++ .../classes/event/submission_updated.php | 9 ++++++++ .../classes/event/submission_viewed.php | 11 ++++++++++ 170 files changed, 1364 insertions(+), 19 deletions(-) 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..d71d1f3710f 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 false; + } } diff --git a/mod/assign/submission/file/classes/event/submission_updated.php b/mod/assign/submission/file/classes/event/submission_updated.php index 65e8b542607..bf184759ae1 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 false; + } } 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..0108c1f0717 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 false; + } } diff --git a/mod/assign/submission/onlinetext/classes/event/submission_updated.php b/mod/assign/submission/onlinetext/classes/event/submission_updated.php index 356d3a66514..8f95aa2d5cb 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 false; + } } 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..41aec7b3110 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'] = array('db' => 'choice_options', 'restore' => 'choice_option'); + + return $othermapped; + } } diff --git a/mod/choice/classes/event/answer_updated.php b/mod/choice/classes/event/answer_updated.php index 3f205b89383..4fb8c4c11b6 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'] = array('db' => 'choice_options', 'restore' => 'choice_option'); + + 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..213ffa0882a 100644 --- a/mod/choice/classes/event/report_viewed.php +++ b/mod/choice/classes/event/report_viewed.php @@ -80,4 +80,8 @@ 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'); + } } 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..81b7fdc3818 100644 --- a/mod/feedback/classes/event/course_module_viewed.php +++ b/mod/feedback/classes/event/course_module_viewed.php @@ -98,5 +98,9 @@ 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'); + } } 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/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..ddd22fff69f 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() { + // Can't map the 'attemptid' value. + 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..5f27140e90c 100644 --- a/mod/survey/classes/event/course_module_viewed.php +++ b/mod/survey/classes/event/course_module_viewed.php @@ -67,4 +67,8 @@ 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'); + } } 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..af3b46e31d7 100644 --- a/mod/wiki/classes/event/page_viewed.php +++ b/mod/wiki/classes/event/page_viewed.php @@ -102,4 +102,8 @@ 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'); + } } 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; + } } From 0817451470f2288948d6ff561319fae7e9daab2c Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Wed, 23 Sep 2015 16:00:33 +0800 Subject: [PATCH 11/16] MDL-46455 events: Add mapping info to events This commit covers all events outside of /mod/. It adds mapping info for restoring events, or the default implementation which returns false if mapping is not required. --- admin/tool/monitor/classes/event/rule_created.php | 5 +++++ admin/tool/monitor/classes/event/rule_deleted.php | 5 +++++ admin/tool/monitor/classes/event/rule_updated.php | 5 +++++ .../monitor/classes/event/subscription_created.php | 5 +++++ .../classes/event/subscription_criteria_met.php | 5 +++++ .../monitor/classes/event/subscription_deleted.php | 5 +++++ lib/classes/event/assessable_uploaded.php | 4 ++++ lib/classes/event/badge_awarded.php | 4 ++++ lib/classes/event/blog_association_created.php | 10 ++++++++++ lib/classes/event/blog_comment_created.php | 10 ++++++++++ lib/classes/event/blog_comment_deleted.php | 10 ++++++++++ lib/classes/event/blog_entries_viewed.php | 10 ++++++++++ lib/classes/event/blog_entry_created.php | 5 +++++ lib/classes/event/blog_entry_deleted.php | 5 +++++ lib/classes/event/blog_entry_updated.php | 5 +++++ lib/classes/event/calendar_event_created.php | 11 +++++++++++ lib/classes/event/calendar_event_deleted.php | 11 +++++++++++ lib/classes/event/calendar_event_updated.php | 11 +++++++++++ lib/classes/event/cohort_created.php | 5 +++++ lib/classes/event/cohort_deleted.php | 5 +++++ lib/classes/event/cohort_member_added.php | 5 +++++ lib/classes/event/cohort_member_removed.php | 5 +++++ lib/classes/event/cohort_updated.php | 5 +++++ lib/classes/event/comment_created.php | 9 +++++++++ lib/classes/event/comment_deleted.php | 9 +++++++++ lib/classes/event/content_viewed.php | 4 ++++ lib/classes/event/course_category_created.php | 5 +++++ lib/classes/event/course_category_deleted.php | 5 +++++ lib/classes/event/course_category_updated.php | 5 +++++ lib/classes/event/course_completed.php | 11 +++++++++++ lib/classes/event/course_content_deleted.php | 4 ++++ lib/classes/event/course_created.php | 4 ++++ lib/classes/event/course_deleted.php | 4 ++++ .../event/course_module_completion_updated.php | 5 +++++ lib/classes/event/course_module_created.php | 8 ++++++++ lib/classes/event/course_module_deleted.php | 4 ++++ lib/classes/event/course_module_updated.php | 8 ++++++++ lib/classes/event/course_reset_ended.php | 5 +++++ lib/classes/event/course_reset_started.php | 4 ++++ lib/classes/event/course_restored.php | 4 ++++ lib/classes/event/course_section_updated.php | 4 ++++ lib/classes/event/course_updated.php | 4 ++++ lib/classes/event/course_viewed.php | 5 +++++ lib/classes/event/email_failed.php | 4 ++++ lib/classes/event/grade_deleted.php | 4 ++++ lib/classes/event/group_created.php | 4 ++++ lib/classes/event/group_deleted.php | 4 ++++ lib/classes/event/group_member_added.php | 9 +++++++++ lib/classes/event/group_member_removed.php | 5 +++++ lib/classes/event/group_updated.php | 4 ++++ lib/classes/event/grouping_created.php | 4 ++++ lib/classes/event/grouping_deleted.php | 4 ++++ lib/classes/event/grouping_updated.php | 4 ++++ lib/classes/event/message_contact_added.php | 5 +++++ lib/classes/event/message_contact_blocked.php | 5 +++++ lib/classes/event/message_contact_removed.php | 5 +++++ lib/classes/event/message_contact_unblocked.php | 5 +++++ lib/classes/event/message_deleted.php | 5 +++++ lib/classes/event/message_sent.php | 10 ++++++++++ lib/classes/event/message_viewed.php | 10 ++++++++++ lib/classes/event/mnet_access_control_created.php | 10 ++++++++++ lib/classes/event/mnet_access_control_updated.php | 10 ++++++++++ lib/classes/event/note_created.php | 10 ++++++++++ lib/classes/event/note_deleted.php | 10 ++++++++++ lib/classes/event/note_updated.php | 10 ++++++++++ lib/classes/event/notes_viewed.php | 10 ++++++++++ lib/classes/event/question_category_created.php | 4 ++++ lib/classes/event/role_assigned.php | 9 +++++++++ lib/classes/event/role_capabilities_updated.php | 4 ++++ lib/classes/event/role_deleted.php | 4 ++++ lib/classes/event/role_unassigned.php | 8 ++++++++ lib/classes/event/tag_added.php | 10 ++++++++++ lib/classes/event/tag_created.php | 9 +++++++++ lib/classes/event/tag_deleted.php | 9 +++++++++ lib/classes/event/tag_flagged.php | 9 +++++++++ lib/classes/event/tag_removed.php | 10 ++++++++++ lib/classes/event/tag_unflagged.php | 10 ++++++++++ lib/classes/event/tag_updated.php | 10 ++++++++++ lib/classes/event/user_created.php | 4 ++++ lib/classes/event/user_deleted.php | 8 ++++++++ lib/classes/event/user_enrolment_created.php | 9 +++++++++ lib/classes/event/user_enrolment_deleted.php | 9 +++++++++ lib/classes/event/user_enrolment_updated.php | 9 +++++++++ lib/classes/event/user_graded.php | 11 +++++++++++ lib/classes/event/user_list_viewed.php | 8 ++++++++ lib/classes/event/user_loggedin.php | 8 ++++++++ lib/classes/event/user_loggedinas.php | 8 ++++++++ lib/classes/event/user_loggedout.php | 8 ++++++++ lib/classes/event/user_login_failed.php | 3 +++ lib/classes/event/user_password_updated.php | 4 ++++ lib/classes/event/user_profile_viewed.php | 11 +++++++++++ lib/classes/event/user_updated.php | 4 ++++ lib/classes/event/webservice_function_called.php | 4 ++++ lib/classes/event/webservice_login_failed.php | 4 ++++ lib/classes/event/webservice_service_created.php | 9 +++++++++ lib/classes/event/webservice_service_deleted.php | 6 ++++++ lib/classes/event/webservice_service_updated.php | 6 ++++++ lib/classes/event/webservice_service_user_added.php | 6 ++++++ .../event/webservice_service_user_removed.php | 6 ++++++ lib/classes/event/webservice_token_created.php | 9 +++++++++ lib/classes/event/webservice_token_sent.php | 5 +++++ report/log/classes/event/report_viewed.php | 8 ++++++++ report/log/classes/event/user_report_viewed.php | 1 + .../classes/event/activity_report_viewed.php | 1 + report/outline/classes/event/report_viewed.php | 6 ++++++ .../participation/classes/event/report_viewed.php | 13 +++++++++++++ .../classes/event/report_viewed.php | 5 +++++ 107 files changed, 702 insertions(+) diff --git a/admin/tool/monitor/classes/event/rule_created.php b/admin/tool/monitor/classes/event/rule_created.php index 178445b46a3..afc42e892e0 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 false; + } } diff --git a/admin/tool/monitor/classes/event/rule_deleted.php b/admin/tool/monitor/classes/event/rule_deleted.php index 50e2d5b6628..45b46cb294f 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 false; + } } diff --git a/admin/tool/monitor/classes/event/rule_updated.php b/admin/tool/monitor/classes/event/rule_updated.php index 8b262c4f49d..63b247cc1b1 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 false; + } } diff --git a/admin/tool/monitor/classes/event/subscription_created.php b/admin/tool/monitor/classes/event/subscription_created.php index e3d2b818da0..3ae76742543 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 false; + } } 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..fc646902b8c 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 false; + } } 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..4520d6d3dc4 100644 --- a/lib/classes/event/badge_awarded.php +++ b/lib/classes/event/badge_awarded.php @@ -94,4 +94,8 @@ 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'); + } } diff --git a/lib/classes/event/blog_association_created.php b/lib/classes/event/blog_association_created.php index 62ae7c9da98..e22322d8b95 100644 --- a/lib/classes/event/blog_association_created.php +++ b/lib/classes/event/blog_association_created.php @@ -125,4 +125,14 @@ 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. + return false; + } + + public static function get_other_mapping() { + // Blogs are not included in backups, so no mapping required. + return false; + } } diff --git a/lib/classes/event/blog_comment_created.php b/lib/classes/event/blog_comment_created.php index 3c68de270f4..c7889901567 100644 --- a/lib/classes/event/blog_comment_created.php +++ b/lib/classes/event/blog_comment_created.php @@ -52,4 +52,14 @@ 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_objectid_mapping() { + // Blogs are not included in backups, so no mapping required. + return false; + } + + public static function get_other_mapping() { + // Blogs are not included in backups, so no mapping required. + return false; + } } diff --git a/lib/classes/event/blog_comment_deleted.php b/lib/classes/event/blog_comment_deleted.php index adf5c092b94..a058c82586d 100644 --- a/lib/classes/event/blog_comment_deleted.php +++ b/lib/classes/event/blog_comment_deleted.php @@ -52,4 +52,14 @@ 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_objectid_mapping() { + // Blogs are not included in backups, so no mapping required. + return false; + } + + public static function get_other_mapping() { + // Blogs are not included in backups, so no mapping required. + return false; + } } diff --git a/lib/classes/event/blog_entries_viewed.php b/lib/classes/event/blog_entries_viewed.php index 632b892fcdb..05d61819ff5 100644 --- a/lib/classes/event/blog_entries_viewed.php +++ b/lib/classes/event/blog_entries_viewed.php @@ -106,4 +106,14 @@ 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['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..479d86039b2 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. + return false; + } } diff --git a/lib/classes/event/blog_entry_deleted.php b/lib/classes/event/blog_entry_deleted.php index 2321e42f51b..7282b5e89f9 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. + return false; + } } diff --git a/lib/classes/event/blog_entry_updated.php b/lib/classes/event/blog_entry_updated.php index 4b9237162e7..6081f76f635 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. + return false; + } } 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..3fcc3cbf865 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. + return false; + } } diff --git a/lib/classes/event/cohort_deleted.php b/lib/classes/event/cohort_deleted.php index c5f170cc876..a785d9c4528 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. + return false; + } } diff --git a/lib/classes/event/cohort_member_added.php b/lib/classes/event/cohort_member_added.php index 018d854ec1f..ccd8cf51b57 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. + return false; + } } diff --git a/lib/classes/event/cohort_member_removed.php b/lib/classes/event/cohort_member_removed.php index 25c902adf30..b94d4b49f06 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. + return false; + } } diff --git a/lib/classes/event/cohort_updated.php b/lib/classes/event/cohort_updated.php index 83d05b5de9c..53bc15cc3c2 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. + return false; + } } diff --git a/lib/classes/event/comment_created.php b/lib/classes/event/comment_created.php index fa4befdb0c4..e37e3ff63f3 100644 --- a/lib/classes/event/comment_created.php +++ b/lib/classes/event/comment_created.php @@ -100,4 +100,13 @@ 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' => 'comment', 'restore' => 'comment'); + } + + public static function get_other_mapping() { + // We cannot map fields that do not have a 1:1 mapping. + return false; + } } diff --git a/lib/classes/event/comment_deleted.php b/lib/classes/event/comment_deleted.php index 0dbdcab6741..145eb44a8e9 100644 --- a/lib/classes/event/comment_deleted.php +++ b/lib/classes/event/comment_deleted.php @@ -100,4 +100,13 @@ 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' => 'comment', 'restore' => 'comment'); + } + + public static function get_other_mapping() { + // We cannot map fields that do not have a 1:1 mapping. + return false; + } } 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..a710887af4d 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. + return false; + } } diff --git a/lib/classes/event/course_category_deleted.php b/lib/classes/event/course_category_deleted.php index 4d80eeea830..45df1cb111d 100644 --- a/lib/classes/event/course_category_deleted.php +++ b/lib/classes/event/course_category_deleted.php @@ -136,4 +136,9 @@ 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. + return false; + } } diff --git a/lib/classes/event/course_category_updated.php b/lib/classes/event/course_category_updated.php index d20d487e502..e2a8e375be4 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. + return false; + } } diff --git a/lib/classes/event/course_completed.php b/lib/classes/event/course_completed.php index ed51fa97d3b..8eddac21880 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 false; + } + + 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..21ad2b5370a 100644 --- a/lib/classes/event/course_content_deleted.php +++ b/lib/classes/event/course_content_deleted.php @@ -104,4 +104,8 @@ 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'); + } } diff --git a/lib/classes/event/course_created.php b/lib/classes/event/course_created.php index 699dcc15785..fcb1ec65d9f 100644 --- a/lib/classes/event/course_created.php +++ b/lib/classes/event/course_created.php @@ -119,4 +119,8 @@ 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'); + } } diff --git a/lib/classes/event/course_deleted.php b/lib/classes/event/course_deleted.php index 19641ffef42..661a2384712 100644 --- a/lib/classes/event/course_deleted.php +++ b/lib/classes/event/course_deleted.php @@ -114,4 +114,8 @@ 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'); + } } diff --git a/lib/classes/event/course_module_completion_updated.php b/lib/classes/event/course_module_completion_updated.php index b5f2ff2c099..60e2ae7c901 100644 --- a/lib/classes/event/course_module_completion_updated.php +++ b/lib/classes/event/course_module_completion_updated.php @@ -107,4 +107,9 @@ 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 false; + } } diff --git a/lib/classes/event/course_module_created.php b/lib/classes/event/course_module_created.php index 244a1240da4..b8e13317dee 100644 --- a/lib/classes/event/course_module_created.php +++ b/lib/classes/event/course_module_created.php @@ -165,5 +165,13 @@ 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() { + return false; + } } diff --git a/lib/classes/event/course_module_deleted.php b/lib/classes/event/course_module_deleted.php index 1bd888b3ec1..bad9fe2eda6 100644 --- a/lib/classes/event/course_module_deleted.php +++ b/lib/classes/event/course_module_deleted.php @@ -119,5 +119,9 @@ 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'); + } } diff --git a/lib/classes/event/course_module_updated.php b/lib/classes/event/course_module_updated.php index b319df6cc1d..79ed096193c 100644 --- a/lib/classes/event/course_module_updated.php +++ b/lib/classes/event/course_module_updated.php @@ -163,5 +163,13 @@ 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() { + return false; + } } 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..34c1c555b87 100644 --- a/lib/classes/event/course_restored.php +++ b/lib/classes/event/course_restored.php @@ -137,4 +137,8 @@ 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'); + } } diff --git a/lib/classes/event/course_section_updated.php b/lib/classes/event/course_section_updated.php index 0a458e6dc10..610012e47ad 100644 --- a/lib/classes/event/course_section_updated.php +++ b/lib/classes/event/course_section_updated.php @@ -104,4 +104,8 @@ 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'); + } } diff --git a/lib/classes/event/course_updated.php b/lib/classes/event/course_updated.php index a49e9c2852e..c272e653cf4 100644 --- a/lib/classes/event/course_updated.php +++ b/lib/classes/event/course_updated.php @@ -117,4 +117,8 @@ 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'); + } } 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..1834ef635a4 100644 --- a/lib/classes/event/email_failed.php +++ b/lib/classes/event/email_failed.php @@ -94,4 +94,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/grade_deleted.php b/lib/classes/event/grade_deleted.php index ffb65439517..b82b98d736d 100644 --- a/lib/classes/event/grade_deleted.php +++ b/lib/classes/event/grade_deleted.php @@ -131,4 +131,8 @@ 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'); + } } 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..2718a0725fe 100644 --- a/lib/classes/event/group_member_added.php +++ b/lib/classes/event/group_member_added.php @@ -125,4 +125,13 @@ 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() { + // Nothing to map. + return false; + } } 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..916f82783d2 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. + return false; + } } diff --git a/lib/classes/event/message_contact_blocked.php b/lib/classes/event/message_contact_blocked.php index 959f3c4ed37..43ec640786c 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. + return false; + } } diff --git a/lib/classes/event/message_contact_removed.php b/lib/classes/event/message_contact_removed.php index c87f837da0d..59979e2cc6a 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. + return false; + } } diff --git a/lib/classes/event/message_contact_unblocked.php b/lib/classes/event/message_contact_unblocked.php index 48f5a07a70e..75d58917ef9 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. + return false; + } } diff --git a/lib/classes/event/message_deleted.php b/lib/classes/event/message_deleted.php index 5d3f71bc419..6ccf2e0d65f 100644 --- a/lib/classes/event/message_deleted.php +++ b/lib/classes/event/message_deleted.php @@ -142,4 +142,9 @@ 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. + return false; + } } diff --git a/lib/classes/event/message_sent.php b/lib/classes/event/message_sent.php index 4f11edb63ca..297c6ad8cc8 100644 --- a/lib/classes/event/message_sent.php +++ b/lib/classes/event/message_sent.php @@ -144,4 +144,14 @@ 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. + return false; + } } diff --git a/lib/classes/event/message_viewed.php b/lib/classes/event/message_viewed.php index d5eab52e2a5..a5c815a71cc 100644 --- a/lib/classes/event/message_viewed.php +++ b/lib/classes/event/message_viewed.php @@ -95,4 +95,14 @@ 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 false; + } + + public static function get_other_mapping() { + // Messages are not backed up, so no need to map them. + return false; + } } diff --git a/lib/classes/event/mnet_access_control_created.php b/lib/classes/event/mnet_access_control_created.php index 1725ddd8222..56fdb7f15eb 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. + return false; + } + + public static function get_other_mapping() { + // Mnet info is not backed up, so no need 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..a9737d07707 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. + return false; + } + + public static function get_other_mapping() { + // Mnet info is not backed up, so no need to map. + return false; + } } diff --git a/lib/classes/event/note_created.php b/lib/classes/event/note_created.php index e6720eb8353..aa407d1e490 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. + return false; + } + + public static function get_other_mapping() { + // Notes are not backed up, so no need to map. + return false; + } } diff --git a/lib/classes/event/note_deleted.php b/lib/classes/event/note_deleted.php index 0e127cad45f..cce5fb8f4f0 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. + return false; + } + + public static function get_other_mapping() { + // Notes are not backed up, so no need to map. + return false; + } } diff --git a/lib/classes/event/note_updated.php b/lib/classes/event/note_updated.php index 816816b6fcb..8744e066a75 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. + return false; + } + + public static function get_other_mapping() { + // Notes are not backed up, so no need to map. + return false; + } } diff --git a/lib/classes/event/notes_viewed.php b/lib/classes/event/notes_viewed.php index ccbbc5d2148..1e38e6d3f7c 100644 --- a/lib/classes/event/notes_viewed.php +++ b/lib/classes/event/notes_viewed.php @@ -86,4 +86,14 @@ class notes_viewed extends base { return array($this->courseid, 'notes', 'view', 'index.php?course=' . $this->courseid.'&user=' . $this->relateduserid, 'view notes'); } + + public static function get_objectid_mapping() { + // Notes are not backed up, so no need to map. + return false; + } + + public static function get_other_mapping() { + // Notes are not backed up, so no need 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..098ff753255 100644 --- a/lib/classes/event/role_assigned.php +++ b/lib/classes/event/role_assigned.php @@ -131,4 +131,13 @@ 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() { + // Nothing mappable. + return false; + } } 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..2c75a8cf696 100644 --- a/lib/classes/event/role_deleted.php +++ b/lib/classes/event/role_deleted.php @@ -102,4 +102,8 @@ 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'); + } } diff --git a/lib/classes/event/role_unassigned.php b/lib/classes/event/role_unassigned.php index bb788c2186d..810c2f49f76 100644 --- a/lib/classes/event/role_unassigned.php +++ b/lib/classes/event/role_unassigned.php @@ -128,4 +128,12 @@ 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() { + return false; + } } diff --git a/lib/classes/event/tag_added.php b/lib/classes/event/tag_added.php index 3c7558c5ce3..be93b086b84 100644 --- a/lib/classes/event/tag_added.php +++ b/lib/classes/event/tag_added.php @@ -117,4 +117,14 @@ 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 by id. + return false; + } + + public static function get_other_mapping() { + return false; + } + } diff --git a/lib/classes/event/tag_created.php b/lib/classes/event/tag_created.php index 858339e840d..e49588a8f4e 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 by id. + return false; + } + + 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..d1c8f2fbdc5 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 by id. + return false; + } + + 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..6ab16e57d5f 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 by id. + return false; + } + + 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..1b6b6c56f46 100644 --- a/lib/classes/event/tag_removed.php +++ b/lib/classes/event/tag_removed.php @@ -103,4 +103,14 @@ 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 false; + } + + public static function get_other_mapping() { + return false; + } + } diff --git a/lib/classes/event/tag_unflagged.php b/lib/classes/event/tag_unflagged.php index f9e43782ff5..fc8cb4db8cc 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 false; + } + + 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..817baeaf9b0 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 false; + } + + 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..418f72a0b5f 100644 --- a/lib/classes/event/user_deleted.php +++ b/lib/classes/event/user_deleted.php @@ -141,4 +141,12 @@ 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() { + return false; + } } diff --git a/lib/classes/event/user_enrolment_created.php b/lib/classes/event/user_enrolment_created.php index 7f84fbc0dd8..17d720cb4c0 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 false; + } + + 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..0c4f5026547 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 false; + } + + 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..1219d19cd6f 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 false; + } + + 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..b17ea6fc155 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 false; + } + + 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..a10c094665d 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 false; + } + } diff --git a/lib/classes/event/webservice_service_updated.php b/lib/classes/event/webservice_service_updated.php index a84f4fc20b1..c078f92cafe 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 false; + } + } diff --git a/lib/classes/event/webservice_service_user_added.php b/lib/classes/event/webservice_service_user_added.php index 2d423782ec6..662a2aa0f9d 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 false; + } + } diff --git a/lib/classes/event/webservice_service_user_removed.php b/lib/classes/event/webservice_service_user_removed.php index 50ae27c472b..9488fdda9fd 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 false; + } + } diff --git a/lib/classes/event/webservice_token_created.php b/lib/classes/event/webservice_token_created.php index a816dbead50..a3f375847a3 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 false; + } + + 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..527036c50a1 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 false; + } } 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..8ac4302a873 100644 --- a/report/log/classes/event/user_report_viewed.php +++ b/report/log/classes/event/user_report_viewed.php @@ -105,4 +105,5 @@ class user_report_viewed extends \core\event\base { throw new \coding_exception('The \'relateduserid\' must be set.'); } } + } 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..820ab9f6a6c 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 array(); + } + } 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..682f2fdbb36 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 array(); + } } From 63b5a5faadade405665b2e553734bd825487067c Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Thu, 24 Sep 2015 14:27:24 +0800 Subject: [PATCH 12/16] MDL-46455 event: Make the debugging messages print the event class. Because they are in the base class, it was impossible to find which event triggered the debugging. --- lib/classes/event/base.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/classes/event/base.php b/lib/classes/event/base.php index ee2be4041c5..88685a4e115 100644 --- a/lib/classes/event/base.php +++ b/lib/classes/event/base.php @@ -511,7 +511,7 @@ abstract class base implements \IteratorAggregate { * @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 must define the + debugging('In order to restore course logs accurately the event "' . get_called_class() . '" must define the function get_objectid_mapping().', DEBUG_DEVELOPER); return false; @@ -552,7 +552,7 @@ abstract class base implements \IteratorAggregate { * @return array an array of other values and their corresponding mapping */ public static function get_other_mapping() { - debugging('In order to restore course logs accurately the event must define the + debugging('In order to restore course logs accurately the event "' . get_called_class() . '" must define the function get_other_mapping().', DEBUG_DEVELOPER); } From e17b739995010b3f559dc693baa952a275047a77 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Thu, 24 Sep 2015 14:32:39 +0800 Subject: [PATCH 13/16] MDL-46455 logstores: Do not try and map empty fields on restore. --- .../moodle2/restore_tool_log_logstore_subplugin.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index c25693f58c3..85e7d439a57 100644 --- 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 @@ -113,7 +113,7 @@ abstract class restore_tool_log_logstore_subplugin extends restore_subplugin { // 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])) { + if (isset($othermapping[$key]) && !empty($value)) { // Ok, let's map this. $mapping = $othermapping[$key]; // Check if it can not be mapped. From 3d0fff3a8372e5c6e11abb362f910a36e4337dbd Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Thu, 24 Sep 2015 15:03:26 +0800 Subject: [PATCH 14/16] MDL-46455 restore: Add debug messages when log records cannot be mapped --- ...tore_tool_log_logstore_subplugin.class.php | 28 +++++++++++++------ backup/moodle2/restore_subplugin.class.php | 7 +++++ 2 files changed, 27 insertions(+), 8 deletions(-) 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 index 85e7d439a57..7901ef02f06 100644 --- 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 @@ -49,8 +49,10 @@ abstract class restore_tool_log_logstore_subplugin extends restore_subplugin { $data = (object) $data; // Complete the information that does not come from backup. - if (!$data->contextid = $this->get_mappingid('context', $data->contextid)) { - // Something went really wrong, cannot find the context this log belongs to. + $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); @@ -59,19 +61,25 @@ abstract class restore_tool_log_logstore_subplugin extends restore_subplugin { $data->courseid = $this->task->get_courseid(); // Remap users. - if (!$data->userid = $this->get_mappingid('user', $data->userid)) { - // Something went really wrong, cannot find the user this log belongs to. + $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. - if (!$data->relateduserid = $this->get_mappingid('user', $data->relateduserid)) { - // Something went really wrong, cannot find the relateduserid this log is about. + $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. - if (!$data->realuserid = $this->get_mappingid('user', $data->realuserid)) { - // Something went really wrong, cannot find the realuserid this log is logged in as. + $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; } } @@ -101,6 +109,8 @@ abstract class restore_tool_log_logstore_subplugin extends restore_subplugin { } } } else { + $message = "Event class not found: \"$eventclass\". Skipping log record."; + $this->log($message, backup::LOG_DEBUG); return; // No such class, can not restore. } } @@ -129,6 +139,8 @@ abstract class restore_tool_log_logstore_subplugin extends restore_subplugin { // 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. } } 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 */ From 607021c14bdd15ac5f48688e7e37466375e878ca Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 6 Oct 2015 16:44:18 -0700 Subject: [PATCH 15/16] MDL-46455 events: added more mapping Also fixed a few bugs. --- .../classes/event/langpack_imported.php | 5 +++++ .../classes/event/langpack_removed.php | 5 +++++ .../classes/event/langpack_updated.php | 5 +++++ lib/classes/event/badge_awarded.php | 7 +++++++ lib/classes/event/blog_entries_viewed.php | 2 ++ lib/classes/event/comment_created.php | 6 ++++-- lib/classes/event/comment_deleted.php | 6 ++++-- lib/classes/event/course_category_deleted.php | 5 +++++ lib/classes/event/course_completed.php | 2 +- lib/classes/event/course_created.php | 5 +++++ lib/classes/event/course_deleted.php | 5 +++++ .../event/course_module_completion_updated.php | 15 ++++++++++++++- lib/classes/event/course_module_created.php | 5 ++++- lib/classes/event/course_module_deleted.php | 7 +++++++ lib/classes/event/course_module_updated.php | 5 ++++- lib/classes/event/course_restored.php | 5 +++++ lib/classes/event/course_section_updated.php | 5 +++++ lib/classes/event/course_updated.php | 5 +++++ lib/classes/event/course_user_report_viewed.php | 5 +++++ lib/classes/event/email_failed.php | 8 ++++++++ lib/classes/event/enrol_instance_created.php | 9 +++++++++ lib/classes/event/enrol_instance_deleted.php | 9 +++++++++ lib/classes/event/enrol_instance_updated.php | 9 +++++++++ lib/classes/event/grade_deleted.php | 7 +++++++ lib/classes/event/group_member_added.php | 6 ++++-- lib/classes/event/notes_viewed.php | 10 ---------- lib/classes/event/role_assigned.php | 7 +++++-- lib/classes/event/role_deleted.php | 5 +++++ lib/classes/event/role_unassigned.php | 6 +++++- lib/classes/event/tag_added.php | 11 +++++++---- lib/classes/event/tag_created.php | 4 ++-- lib/classes/event/tag_deleted.php | 4 ++-- lib/classes/event/tag_flagged.php | 4 ++-- lib/classes/event/tag_removed.php | 8 ++++++-- lib/classes/event/tag_unflagged.php | 2 +- lib/classes/event/tag_updated.php | 2 +- lib/classes/event/user_enrolment_created.php | 2 +- lib/classes/event/user_enrolment_deleted.php | 2 +- lib/classes/event/user_enrolment_updated.php | 2 +- .../file/classes/event/submission_created.php | 2 +- .../file/classes/event/submission_updated.php | 2 +- .../classes/event/submission_created.php | 2 +- .../classes/event/submission_updated.php | 2 +- mod/choice/classes/event/answer_submitted.php | 2 +- mod/choice/classes/event/answer_updated.php | 2 +- mod/choice/classes/event/report_viewed.php | 11 +++++++++++ .../classes/event/course_module_viewed.php | 5 +++++ mod/scorm/classes/event/attempt_deleted.php | 2 +- .../classes/event/course_module_viewed.php | 11 +++++++++++ mod/wiki/classes/event/page_viewed.php | 17 +++++++++++++++++ report/log/classes/event/user_report_viewed.php | 4 ++++ report/outline/classes/event/report_viewed.php | 2 +- .../classes/event/report_viewed.php | 2 +- report/stats/classes/event/report_viewed.php | 5 +++++ 54 files changed, 244 insertions(+), 49 deletions(-) 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/lib/classes/event/badge_awarded.php b/lib/classes/event/badge_awarded.php index 4520d6d3dc4..e7a3e39fd68 100644 --- a/lib/classes/event/badge_awarded.php +++ b/lib/classes/event/badge_awarded.php @@ -98,4 +98,11 @@ class badge_awarded extends base { 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/blog_entries_viewed.php b/lib/classes/event/blog_entries_viewed.php index 05d61819ff5..e240ffbe1c1 100644 --- a/lib/classes/event/blog_entries_viewed.php +++ b/lib/classes/event/blog_entries_viewed.php @@ -109,6 +109,8 @@ class blog_entries_viewed extends base { 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'); diff --git a/lib/classes/event/comment_created.php b/lib/classes/event/comment_created.php index e37e3ff63f3..e754c0121ce 100644 --- a/lib/classes/event/comment_created.php +++ b/lib/classes/event/comment_created.php @@ -102,11 +102,13 @@ abstract class comment_created extends base { } public static function get_objectid_mapping() { - return array('db' => 'comment', 'restore' => 'comment'); + return array('db' => 'comments', 'restore' => 'comment'); } public static function get_other_mapping() { // We cannot map fields that do not have a 1:1 mapping. - return false; + $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 145eb44a8e9..2d66716e83c 100644 --- a/lib/classes/event/comment_deleted.php +++ b/lib/classes/event/comment_deleted.php @@ -102,11 +102,13 @@ abstract class comment_deleted extends base { } public static function get_objectid_mapping() { - return array('db' => 'comment', 'restore' => 'comment'); + return array('db' => 'comments', 'restore' => 'comment'); } public static function get_other_mapping() { // We cannot map fields that do not have a 1:1 mapping. - return false; + $othermapped = array(); + $othermapped['itemid'] = base::NOT_MAPPED; + return $othermapped; } } diff --git a/lib/classes/event/course_category_deleted.php b/lib/classes/event/course_category_deleted.php index 45df1cb111d..95d8313005a 100644 --- a/lib/classes/event/course_category_deleted.php +++ b/lib/classes/event/course_category_deleted.php @@ -141,4 +141,9 @@ class course_category_deleted extends base { // Categories are not backed up, so no need to map them. return false; } + + public static function get_other_mapping() { + // Categories are not backed up, so no need to map them. + return false; + } } diff --git a/lib/classes/event/course_completed.php b/lib/classes/event/course_completed.php index 8eddac21880..b01c626cb44 100644 --- a/lib/classes/event/course_completed.php +++ b/lib/classes/event/course_completed.php @@ -137,7 +137,7 @@ class course_completed extends base { public static function get_objectid_mapping() { // Sorry - there is no mapping available for completion records. - return false; + return array('db' => 'course_completions', 'restore' => base::NOT_MAPPED); } public static function get_other_mapping() { diff --git a/lib/classes/event/course_created.php b/lib/classes/event/course_created.php index fcb1ec65d9f..418a2c291c5 100644 --- a/lib/classes/event/course_created.php +++ b/lib/classes/event/course_created.php @@ -123,4 +123,9 @@ class course_created extends base { 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 661a2384712..ea2734ae1ba 100644 --- a/lib/classes/event/course_deleted.php +++ b/lib/classes/event/course_deleted.php @@ -118,4 +118,9 @@ class course_deleted extends base { 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 60e2ae7c901..2faf575b664 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 @@ -110,6 +116,13 @@ class course_module_completion_updated extends base { public static function get_objectid_mapping() { // Sorry mapping info is not available for course modules completion records. - return false; + return array('db' => 'course_modules_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_module_created.php b/lib/classes/event/course_module_created.php index b8e13317dee..fba54873c78 100644 --- a/lib/classes/event/course_module_created.php +++ b/lib/classes/event/course_module_created.php @@ -171,7 +171,10 @@ class course_module_created extends base { } public static function get_other_mapping() { - return false; + $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 bad9fe2eda6..f2289ea7a28 100644 --- a/lib/classes/event/course_module_deleted.php +++ b/lib/classes/event/course_module_deleted.php @@ -123,5 +123,12 @@ class course_module_deleted extends base { 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 79ed096193c..70f76e578e1 100644 --- a/lib/classes/event/course_module_updated.php +++ b/lib/classes/event/course_module_updated.php @@ -169,7 +169,10 @@ class course_module_updated extends base { } public static function get_other_mapping() { - return false; + $othermapping = array(); + $othermapping['instanceid'] = base::NOT_MAPPED; + + return $othermapping; } } diff --git a/lib/classes/event/course_restored.php b/lib/classes/event/course_restored.php index 34c1c555b87..3c41e12d2da 100644 --- a/lib/classes/event/course_restored.php +++ b/lib/classes/event/course_restored.php @@ -141,4 +141,9 @@ class course_restored extends base { 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 610012e47ad..7bca3acc272 100644 --- a/lib/classes/event/course_section_updated.php +++ b/lib/classes/event/course_section_updated.php @@ -108,4 +108,9 @@ class course_section_updated extends base { 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 c272e653cf4..fab46c534e9 100644 --- a/lib/classes/event/course_updated.php +++ b/lib/classes/event/course_updated.php @@ -121,4 +121,9 @@ class course_updated extends base { 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/email_failed.php b/lib/classes/event/email_failed.php index 1834ef635a4..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 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 b82b98d736d..d66409de768 100644 --- a/lib/classes/event/grade_deleted.php +++ b/lib/classes/event/grade_deleted.php @@ -135,4 +135,11 @@ class grade_deleted extends base { 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_member_added.php b/lib/classes/event/group_member_added.php index 2718a0725fe..51fdacdc288 100644 --- a/lib/classes/event/group_member_added.php +++ b/lib/classes/event/group_member_added.php @@ -131,7 +131,9 @@ class group_member_added extends base { } public static function get_other_mapping() { - // Nothing to map. - return false; + $othermapped = array(); + $othermapped['itemid'] = base::NOT_MAPPED; + + return $othermapped; } } diff --git a/lib/classes/event/notes_viewed.php b/lib/classes/event/notes_viewed.php index 1e38e6d3f7c..ccbbc5d2148 100644 --- a/lib/classes/event/notes_viewed.php +++ b/lib/classes/event/notes_viewed.php @@ -86,14 +86,4 @@ class notes_viewed extends base { return array($this->courseid, 'notes', 'view', 'index.php?course=' . $this->courseid.'&user=' . $this->relateduserid, 'view notes'); } - - public static function get_objectid_mapping() { - // Notes are not backed up, so no need to map. - return false; - } - - public static function get_other_mapping() { - // Notes are not backed up, so no need to map. - return false; - } } diff --git a/lib/classes/event/role_assigned.php b/lib/classes/event/role_assigned.php index 098ff753255..8396a8dffa4 100644 --- a/lib/classes/event/role_assigned.php +++ b/lib/classes/event/role_assigned.php @@ -137,7 +137,10 @@ class role_assigned extends base { } public static function get_other_mapping() { - // Nothing mappable. - return false; + $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_deleted.php b/lib/classes/event/role_deleted.php index 2c75a8cf696..b2586fb1fdd 100644 --- a/lib/classes/event/role_deleted.php +++ b/lib/classes/event/role_deleted.php @@ -106,4 +106,9 @@ class role_deleted extends base { 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 810c2f49f76..2eb34e2548f 100644 --- a/lib/classes/event/role_unassigned.php +++ b/lib/classes/event/role_unassigned.php @@ -134,6 +134,10 @@ class role_unassigned extends base { } public static function get_other_mapping() { - return false; + $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 be93b086b84..6316cc35012 100644 --- a/lib/classes/event/tag_added.php +++ b/lib/classes/event/tag_added.php @@ -119,12 +119,15 @@ class tag_added extends base { } public static function get_objectid_mapping() { - // Tags cannot be mapped by id. - return false; + // Tags cannot be mapped. + return array('db' => 'tag_instance', 'restore' => base::NOT_MAPPED); } public static function get_other_mapping() { - return false; - } + $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 e49588a8f4e..e239b392a74 100644 --- a/lib/classes/event/tag_created.php +++ b/lib/classes/event/tag_created.php @@ -89,8 +89,8 @@ class tag_created extends base { } public static function get_objectid_mapping() { - // Tags cannot be mapped by id. - return false; + // Tags cannot be mapped. + return array('db' => 'tag', 'restore' => base::NOT_MAPPED); } public static function get_other_mapping() { diff --git a/lib/classes/event/tag_deleted.php b/lib/classes/event/tag_deleted.php index d1c8f2fbdc5..60fc8a74b92 100644 --- a/lib/classes/event/tag_deleted.php +++ b/lib/classes/event/tag_deleted.php @@ -89,8 +89,8 @@ class tag_deleted extends base { } public static function get_objectid_mapping() { - // Tags cannot be mapped by id. - return false; + // Tags cannot be mapped. + return array('db' => 'tag', 'restore' => base::NOT_MAPPED); } public static function get_other_mapping() { diff --git a/lib/classes/event/tag_flagged.php b/lib/classes/event/tag_flagged.php index 6ab16e57d5f..2f7c26b3bef 100644 --- a/lib/classes/event/tag_flagged.php +++ b/lib/classes/event/tag_flagged.php @@ -98,8 +98,8 @@ class tag_flagged extends base { } public static function get_objectid_mapping() { - // Tags cannot be mapped by id. - return false; + // Tags cannot be mapped. + return array('db' => 'tag', 'restore' => base::NOT_MAPPED); } public static function get_other_mapping() { diff --git a/lib/classes/event/tag_removed.php b/lib/classes/event/tag_removed.php index 1b6b6c56f46..04558aca24e 100644 --- a/lib/classes/event/tag_removed.php +++ b/lib/classes/event/tag_removed.php @@ -106,11 +106,15 @@ class tag_removed extends base { public static function get_objectid_mapping() { // Tags cannot be mapped. - return false; + return array('db' => 'tag_instance', 'restore' => base::NOT_MAPPED); } public static function get_other_mapping() { - return false; + $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 fc8cb4db8cc..4b6f3dd252f 100644 --- a/lib/classes/event/tag_unflagged.php +++ b/lib/classes/event/tag_unflagged.php @@ -90,7 +90,7 @@ class tag_unflagged extends base { public static function get_objectid_mapping() { // Tags cannot be mapped. - return false; + return array('db' => 'tag', 'restore' => base::NOT_MAPPED); } public static function get_other_mapping() { diff --git a/lib/classes/event/tag_updated.php b/lib/classes/event/tag_updated.php index 817baeaf9b0..fe6b4f75399 100644 --- a/lib/classes/event/tag_updated.php +++ b/lib/classes/event/tag_updated.php @@ -115,7 +115,7 @@ class tag_updated extends base { public static function get_objectid_mapping() { // Tags cannot be mapped. - return false; + return array('db' => 'tag', 'restore' => base::NOT_MAPPED); } public static function get_other_mapping() { diff --git a/lib/classes/event/user_enrolment_created.php b/lib/classes/event/user_enrolment_created.php index 17d720cb4c0..384015a20bb 100644 --- a/lib/classes/event/user_enrolment_created.php +++ b/lib/classes/event/user_enrolment_created.php @@ -128,7 +128,7 @@ class user_enrolment_created extends base { public static function get_objectid_mapping() { // User enrolments table is not mappable. - return false; + return array('db' => 'user_enrolments', 'restore' => base::NOT_MAPPED); } public static function get_other_mapping() { diff --git a/lib/classes/event/user_enrolment_deleted.php b/lib/classes/event/user_enrolment_deleted.php index 0c4f5026547..d872ec266bd 100644 --- a/lib/classes/event/user_enrolment_deleted.php +++ b/lib/classes/event/user_enrolment_deleted.php @@ -127,7 +127,7 @@ class user_enrolment_deleted extends base { public static function get_objectid_mapping() { // User enrolments table is not mappable. - return false; + return array('db' => 'user_enrolments', 'restore' => base::NOT_MAPPED); } public static function get_other_mapping() { diff --git a/lib/classes/event/user_enrolment_updated.php b/lib/classes/event/user_enrolment_updated.php index 1219d19cd6f..d7abe4c31fd 100644 --- a/lib/classes/event/user_enrolment_updated.php +++ b/lib/classes/event/user_enrolment_updated.php @@ -117,7 +117,7 @@ class user_enrolment_updated extends base { public static function get_objectid_mapping() { // User enrolments table is not mappable. - return false; + return array('db' => 'user_enrolments', 'restore' => base::NOT_MAPPED); } public static function get_other_mapping() { diff --git a/mod/assign/submission/file/classes/event/submission_created.php b/mod/assign/submission/file/classes/event/submission_created.php index d71d1f3710f..fe8fc66dc9d 100644 --- a/mod/assign/submission/file/classes/event/submission_created.php +++ b/mod/assign/submission/file/classes/event/submission_created.php @@ -83,6 +83,6 @@ class submission_created extends \mod_assign\event\submission_created { public static function get_objectid_mapping() { // No mapping available for 'assignsubmission_file'. - return false; + 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 bf184759ae1..8e1dec63ee9 100644 --- a/mod/assign/submission/file/classes/event/submission_updated.php +++ b/mod/assign/submission/file/classes/event/submission_updated.php @@ -83,6 +83,6 @@ class submission_updated extends \mod_assign\event\submission_updated { public static function get_objectid_mapping() { // No mapping available for 'assignsubmission_file'. - return false; + return array('db' => 'assignsubmission_file', 'restore' => \core\event\base::NOT_MAPPED); } } diff --git a/mod/assign/submission/onlinetext/classes/event/submission_created.php b/mod/assign/submission/onlinetext/classes/event/submission_created.php index 0108c1f0717..2a2b930b438 100644 --- a/mod/assign/submission/onlinetext/classes/event/submission_created.php +++ b/mod/assign/submission/onlinetext/classes/event/submission_created.php @@ -83,6 +83,6 @@ class submission_created extends \mod_assign\event\submission_created { public static function get_objectid_mapping() { // No mapping available for 'assignsubmission_onlinetext'. - return false; + 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 8f95aa2d5cb..8edad4c4a49 100644 --- a/mod/assign/submission/onlinetext/classes/event/submission_updated.php +++ b/mod/assign/submission/onlinetext/classes/event/submission_updated.php @@ -83,6 +83,6 @@ class submission_updated extends \mod_assign\event\submission_updated { public static function get_objectid_mapping() { // No mapping available for 'assignsubmission_onlinetext'. - return false; + return array('db' => 'assignsubmission_onlinetext', 'restore' => \core\event\base::NOT_MAPPED); } } diff --git a/mod/choice/classes/event/answer_submitted.php b/mod/choice/classes/event/answer_submitted.php index 41aec7b3110..baa6817b44f 100644 --- a/mod/choice/classes/event/answer_submitted.php +++ b/mod/choice/classes/event/answer_submitted.php @@ -129,7 +129,7 @@ class answer_submitted extends \core\event\base { // 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'] = array('db' => 'choice_options', 'restore' => 'choice_option'); + $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 4fb8c4c11b6..e6ab08a87d4 100644 --- a/mod/choice/classes/event/answer_updated.php +++ b/mod/choice/classes/event/answer_updated.php @@ -129,7 +129,7 @@ class answer_updated extends \core\event\base { // 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'] = array('db' => 'choice_options', 'restore' => 'choice_option'); + $othermapped['optionid'] = \core\event\base::NOT_MAPPED; return $othermapped; } diff --git a/mod/choice/classes/event/report_viewed.php b/mod/choice/classes/event/report_viewed.php index 213ffa0882a..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 @@ -84,4 +90,9 @@ class report_viewed extends \core\event\base { 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/feedback/classes/event/course_module_viewed.php b/mod/feedback/classes/event/course_module_viewed.php index 81b7fdc3818..056a20d620b 100644 --- a/mod/feedback/classes/event/course_module_viewed.php +++ b/mod/feedback/classes/event/course_module_viewed.php @@ -102,5 +102,10 @@ class course_module_viewed extends \core\event\course_module_viewed { 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/scorm/classes/event/attempt_deleted.php b/mod/scorm/classes/event/attempt_deleted.php index ddd22fff69f..2a0a1274ee5 100644 --- a/mod/scorm/classes/event/attempt_deleted.php +++ b/mod/scorm/classes/event/attempt_deleted.php @@ -102,7 +102,7 @@ class attempt_deleted extends \core\event\base { } public static function get_other_mapping() { - // Can't map the 'attemptid' value. + // Nothing to map. return false; } } diff --git a/mod/survey/classes/event/course_module_viewed.php b/mod/survey/classes/event/course_module_viewed.php index 5f27140e90c..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 @@ -71,4 +77,9 @@ class course_module_viewed extends \core\event\course_module_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/wiki/classes/event/page_viewed.php b/mod/wiki/classes/event/page_viewed.php index af3b46e31d7..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 @@ -106,4 +115,12 @@ class page_viewed extends \core\event\base { 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/report/log/classes/event/user_report_viewed.php b/report/log/classes/event/user_report_viewed.php index 8ac4302a873..46672d00d54 100644 --- a/report/log/classes/event/user_report_viewed.php +++ b/report/log/classes/event/user_report_viewed.php @@ -106,4 +106,8 @@ class user_report_viewed extends \core\event\base { } } + public static function get_other_mapping() { + // Nothing to map. + return false; + } } diff --git a/report/outline/classes/event/report_viewed.php b/report/outline/classes/event/report_viewed.php index 820ab9f6a6c..45277b9bea7 100644 --- a/report/outline/classes/event/report_viewed.php +++ b/report/outline/classes/event/report_viewed.php @@ -108,7 +108,7 @@ class report_viewed extends \core\event\base { public static function get_other_mapping() { // Nothing to map. - return array(); + return false; } } diff --git a/report/questioninstances/classes/event/report_viewed.php b/report/questioninstances/classes/event/report_viewed.php index 682f2fdbb36..36e3f6520e2 100644 --- a/report/questioninstances/classes/event/report_viewed.php +++ b/report/questioninstances/classes/event/report_viewed.php @@ -103,7 +103,7 @@ class report_viewed extends \core\event\base { public static function get_other_mapping() { // Nothing to map. - return array(); + 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(); + } } From ac82a9a8b4c73f8e7ee734d1563bcf851f3c66e6 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Mon, 12 Oct 2015 16:23:39 +0800 Subject: [PATCH 16/16] MDL-46455 Events: Add db mapping info even if not part of backup We can return db mapping info even for objects that are not included in backup/restore and it may be useful in future (no use in core yet). --- admin/tool/monitor/classes/event/rule_created.php | 2 +- admin/tool/monitor/classes/event/rule_deleted.php | 2 +- admin/tool/monitor/classes/event/rule_updated.php | 2 +- .../monitor/classes/event/subscription_created.php | 2 +- .../monitor/classes/event/subscription_deleted.php | 2 +- lib/classes/event/blog_association_created.php | 12 ++++++++---- lib/classes/event/blog_comment_created.php | 10 +++------- lib/classes/event/blog_comment_deleted.php | 10 +++------- lib/classes/event/blog_entry_created.php | 4 ++-- lib/classes/event/blog_entry_deleted.php | 4 ++-- lib/classes/event/blog_entry_updated.php | 4 ++-- lib/classes/event/cohort_created.php | 4 ++-- lib/classes/event/cohort_deleted.php | 4 ++-- lib/classes/event/cohort_member_added.php | 4 ++-- lib/classes/event/cohort_member_removed.php | 4 ++-- lib/classes/event/cohort_updated.php | 4 ++-- lib/classes/event/course_category_created.php | 4 ++-- lib/classes/event/course_category_deleted.php | 5 ++--- lib/classes/event/course_category_updated.php | 4 ++-- lib/classes/event/course_content_deleted.php | 4 ++++ .../event/course_module_completion_updated.php | 2 +- lib/classes/event/message_contact_added.php | 4 ++-- lib/classes/event/message_contact_blocked.php | 4 ++-- lib/classes/event/message_contact_removed.php | 4 ++-- lib/classes/event/message_contact_unblocked.php | 4 ++-- lib/classes/event/message_deleted.php | 9 +++++++-- lib/classes/event/message_sent.php | 7 +++++-- lib/classes/event/message_viewed.php | 9 ++++++--- lib/classes/event/mnet_access_control_created.php | 6 +++--- lib/classes/event/mnet_access_control_updated.php | 6 +++--- lib/classes/event/note_created.php | 6 +++--- lib/classes/event/note_deleted.php | 6 +++--- lib/classes/event/note_updated.php | 6 +++--- lib/classes/event/user_deleted.php | 5 ++++- lib/classes/event/webservice_service_created.php | 2 +- lib/classes/event/webservice_service_deleted.php | 2 +- lib/classes/event/webservice_service_updated.php | 2 +- lib/classes/event/webservice_service_user_added.php | 2 +- .../event/webservice_service_user_removed.php | 2 +- lib/classes/event/webservice_token_created.php | 2 +- lib/classes/event/webservice_token_sent.php | 2 +- 41 files changed, 98 insertions(+), 85 deletions(-) diff --git a/admin/tool/monitor/classes/event/rule_created.php b/admin/tool/monitor/classes/event/rule_created.php index afc42e892e0..18ee2e974f6 100644 --- a/admin/tool/monitor/classes/event/rule_created.php +++ b/admin/tool/monitor/classes/event/rule_created.php @@ -77,6 +77,6 @@ class rule_created extends \core\event\base { public static function get_objectid_mapping() { // No mapping required for this event because event monitor rules are not backed up. - return false; + 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 45b46cb294f..e085c6c6f65 100644 --- a/admin/tool/monitor/classes/event/rule_deleted.php +++ b/admin/tool/monitor/classes/event/rule_deleted.php @@ -76,6 +76,6 @@ class rule_deleted extends \core\event\base { public static function get_objectid_mapping() { // No mapping required for this event because event monitor rules are not backed up. - return false; + 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 63b247cc1b1..a886a82a3b9 100644 --- a/admin/tool/monitor/classes/event/rule_updated.php +++ b/admin/tool/monitor/classes/event/rule_updated.php @@ -77,6 +77,6 @@ class rule_updated extends \core\event\base { public static function get_objectid_mapping() { // No mapping required for this event because event monitor rules are not backed up. - return false; + 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 3ae76742543..6da8626106a 100644 --- a/admin/tool/monitor/classes/event/subscription_created.php +++ b/admin/tool/monitor/classes/event/subscription_created.php @@ -67,6 +67,6 @@ class subscription_created extends \core\event\base { public static function get_objectid_mapping() { // No mapping required for this event because event monitor subscriptions are not backed up. - return false; + return array('db' => 'tool_monitor_subscriptions', 'restore' => \core\event\base::NOT_MAPPED); } } diff --git a/admin/tool/monitor/classes/event/subscription_deleted.php b/admin/tool/monitor/classes/event/subscription_deleted.php index fc646902b8c..84970b334ff 100644 --- a/admin/tool/monitor/classes/event/subscription_deleted.php +++ b/admin/tool/monitor/classes/event/subscription_deleted.php @@ -67,6 +67,6 @@ class subscription_deleted extends \core\event\base { public static function get_objectid_mapping() { // No mapping required for this event because event monitor subscriptions are not backed up. - return false; + return array('db' => 'tool_monitor_subscriptions', 'restore' => \core\event\base::NOT_MAPPED); } } diff --git a/lib/classes/event/blog_association_created.php b/lib/classes/event/blog_association_created.php index e22322d8b95..3c30861aa03 100644 --- a/lib/classes/event/blog_association_created.php +++ b/lib/classes/event/blog_association_created.php @@ -127,12 +127,16 @@ class blog_association_created extends base { } public static function get_objectid_mapping() { - // Blogs are not included in backups, so no mapping required. - return false; + // 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. - return false; + // 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 c7889901567..5de77d67fb2 100644 --- a/lib/classes/event/blog_comment_created.php +++ b/lib/classes/event/blog_comment_created.php @@ -53,13 +53,9 @@ class blog_comment_created extends comment_created { return "The user with id '$this->userid' added the comment to the blog with id '{$this->other['itemid']}'."; } - public static function get_objectid_mapping() { - // Blogs are not included in backups, so no mapping required. - return false; - } - public static function get_other_mapping() { - // Blogs are not included in backups, so no mapping required. - return false; + $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 a058c82586d..63c808df48b 100644 --- a/lib/classes/event/blog_comment_deleted.php +++ b/lib/classes/event/blog_comment_deleted.php @@ -53,13 +53,9 @@ class blog_comment_deleted extends comment_deleted { return "The user with id '$this->userid' deleted the comment for the blog with id '{$this->other['itemid']}'."; } - public static function get_objectid_mapping() { - // Blogs are not included in backups, so no mapping required. - return false; - } - public static function get_other_mapping() { - // Blogs are not included in backups, so no mapping required. - return false; + $othermapped = array(); + $othermapped['itemid'] = array('db' => 'post', 'restore' => base::NOT_MAPPED); + return $othermapped; } } diff --git a/lib/classes/event/blog_entry_created.php b/lib/classes/event/blog_entry_created.php index 479d86039b2..ff697ea9c6b 100644 --- a/lib/classes/event/blog_entry_created.php +++ b/lib/classes/event/blog_entry_created.php @@ -142,7 +142,7 @@ class blog_entry_created extends base { } public static function get_objectid_mapping() { - // Blogs are not backed up, so no mapping required. - return false; + // 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 7282b5e89f9..74a067e947a 100644 --- a/lib/classes/event/blog_entry_deleted.php +++ b/lib/classes/event/blog_entry_deleted.php @@ -133,7 +133,7 @@ class blog_entry_deleted extends base { } public static function get_objectid_mapping() { - // Blogs are not backed up, so no need for mapping. - return false; + // 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 6081f76f635..73959b6d8c0 100644 --- a/lib/classes/event/blog_entry_updated.php +++ b/lib/classes/event/blog_entry_updated.php @@ -140,8 +140,8 @@ class blog_entry_updated extends base { } public static function get_objectid_mapping() { - // Blogs are not backed up, so no need for mapping. - return false; + // 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/cohort_created.php b/lib/classes/event/cohort_created.php index 3fcc3cbf865..764245416ac 100644 --- a/lib/classes/event/cohort_created.php +++ b/lib/classes/event/cohort_created.php @@ -92,7 +92,7 @@ class cohort_created extends base { } public static function get_objectid_mapping() { - // Cohorts are not included in backups, so no mapping is needed. - return false; + // 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 a785d9c4528..37406cc752b 100644 --- a/lib/classes/event/cohort_deleted.php +++ b/lib/classes/event/cohort_deleted.php @@ -92,7 +92,7 @@ class cohort_deleted extends base { } public static function get_objectid_mapping() { - // Cohorts are not included in backups, so no mapping is needed. - return false; + // 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 ccd8cf51b57..0390569ea14 100644 --- a/lib/classes/event/cohort_member_added.php +++ b/lib/classes/event/cohort_member_added.php @@ -110,7 +110,7 @@ class cohort_member_added extends base { } public static function get_objectid_mapping() { - // Cohorts are not included in backups, so no mapping is needed. - return false; + // 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 b94d4b49f06..6152fa6233f 100644 --- a/lib/classes/event/cohort_member_removed.php +++ b/lib/classes/event/cohort_member_removed.php @@ -111,7 +111,7 @@ class cohort_member_removed extends base { } public static function get_objectid_mapping() { - // Cohorts are not included in backups, so no mapping is needed. - return false; + // 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 53bc15cc3c2..2ee6fe2f7ee 100644 --- a/lib/classes/event/cohort_updated.php +++ b/lib/classes/event/cohort_updated.php @@ -92,7 +92,7 @@ class cohort_updated extends base { } public static function get_objectid_mapping() { - // Cohorts are not included in backups, so no mapping is needed. - return false; + // 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/course_category_created.php b/lib/classes/event/course_category_created.php index a710887af4d..ceed8dea490 100644 --- a/lib/classes/event/course_category_created.php +++ b/lib/classes/event/course_category_created.php @@ -82,7 +82,7 @@ class course_category_created extends base { } public static function get_objectid_mapping() { - // Categories are not backed up, so no need to map them. - return false; + // 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 95d8313005a..6de24131245 100644 --- a/lib/classes/event/course_category_deleted.php +++ b/lib/classes/event/course_category_deleted.php @@ -138,12 +138,11 @@ class course_category_deleted extends base { } public static function get_objectid_mapping() { - // Categories are not backed up, so no need to map them. - return false; + // 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() { - // Categories are not backed up, so no need to map them. return false; } } diff --git a/lib/classes/event/course_category_updated.php b/lib/classes/event/course_category_updated.php index e2a8e375be4..72a262fc66e 100644 --- a/lib/classes/event/course_category_updated.php +++ b/lib/classes/event/course_category_updated.php @@ -98,7 +98,7 @@ class course_category_updated extends base { } public static function get_objectid_mapping() { - // Categories are not backed up, so no need to map them. - return false; + // 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_content_deleted.php b/lib/classes/event/course_content_deleted.php index 21ad2b5370a..c5207a85335 100644 --- a/lib/classes/event/course_content_deleted.php +++ b/lib/classes/event/course_content_deleted.php @@ -108,4 +108,8 @@ class course_content_deleted extends base { 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_module_completion_updated.php b/lib/classes/event/course_module_completion_updated.php index 2faf575b664..5142621612a 100644 --- a/lib/classes/event/course_module_completion_updated.php +++ b/lib/classes/event/course_module_completion_updated.php @@ -116,7 +116,7 @@ class course_module_completion_updated extends base { public static function get_objectid_mapping() { // Sorry mapping info is not available for course modules completion records. - return array('db' => 'course_modules_completions', 'restore' => base::NOT_MAPPED); + return array('db' => 'course_modules_completion', 'restore' => base::NOT_MAPPED); } public static function get_other_mapping() { diff --git a/lib/classes/event/message_contact_added.php b/lib/classes/event/message_contact_added.php index 916f82783d2..e2b48ea0f6f 100644 --- a/lib/classes/event/message_contact_added.php +++ b/lib/classes/event/message_contact_added.php @@ -96,7 +96,7 @@ class message_contact_added extends base { } public static function get_objectid_mapping() { - // Messaging contacts are not backed up, so no need to map them. - return false; + // 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 43ec640786c..da9fc4cfa61 100644 --- a/lib/classes/event/message_contact_blocked.php +++ b/lib/classes/event/message_contact_blocked.php @@ -96,7 +96,7 @@ class message_contact_blocked extends base { } public static function get_objectid_mapping() { - // Messaging contacts are not backed up, so no need to map them. - return false; + // 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 59979e2cc6a..60000d1b7d7 100644 --- a/lib/classes/event/message_contact_removed.php +++ b/lib/classes/event/message_contact_removed.php @@ -96,7 +96,7 @@ class message_contact_removed extends base { } public static function get_objectid_mapping() { - // Messaging contacts are not backed up, so no need to map them. - return false; + // 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 75d58917ef9..417a1a6c3cc 100644 --- a/lib/classes/event/message_contact_unblocked.php +++ b/lib/classes/event/message_contact_unblocked.php @@ -96,7 +96,7 @@ class message_contact_unblocked extends base { } public static function get_objectid_mapping() { - // Messaging contacts are not backed up, so no need to map them. - return false; + // 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 6ccf2e0d65f..7d5087e1bc4 100644 --- a/lib/classes/event/message_deleted.php +++ b/lib/classes/event/message_deleted.php @@ -144,7 +144,12 @@ class message_deleted extends base { } public static function get_other_mapping() { - // Messages are not backed up, so no need to map them. - return false; + // 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 297c6ad8cc8..0d58ddbea56 100644 --- a/lib/classes/event/message_sent.php +++ b/lib/classes/event/message_sent.php @@ -151,7 +151,10 @@ class message_sent extends base { } public static function get_other_mapping() { - // Messages are not backed up, so no need to map them. - return false; + // 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 a5c815a71cc..8e129475114 100644 --- a/lib/classes/event/message_viewed.php +++ b/lib/classes/event/message_viewed.php @@ -98,11 +98,14 @@ class message_viewed extends base { public static function get_objectid_mapping() { // Messages are not backed up, so no need to map them. - return false; + 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. - return false; + // 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 56fdb7f15eb..69e47cc8367 100644 --- a/lib/classes/event/mnet_access_control_created.php +++ b/lib/classes/event/mnet_access_control_created.php @@ -115,12 +115,12 @@ class mnet_access_control_created extends base { } public static function get_objectid_mapping() { - // Mnet info is not backed up, so no need to map. - return false; + // 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() { - // Mnet info is not backed up, so no need to map. + // 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 a9737d07707..b2e93321fa8 100644 --- a/lib/classes/event/mnet_access_control_updated.php +++ b/lib/classes/event/mnet_access_control_updated.php @@ -115,12 +115,12 @@ class mnet_access_control_updated extends base { } public static function get_objectid_mapping() { - // Mnet info is not backed up, so no need to map. - return false; + // 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() { - // Mnet info is not backed up, so no need to map. + // Nothing to map. return false; } } diff --git a/lib/classes/event/note_created.php b/lib/classes/event/note_created.php index aa407d1e490..dd75b755ee2 100644 --- a/lib/classes/event/note_created.php +++ b/lib/classes/event/note_created.php @@ -108,12 +108,12 @@ class note_created extends base { } public static function get_objectid_mapping() { - // Notes are not backed up, so no need to map. - return false; + // 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() { - // Notes are not backed up, so no need to map. + // Nothing to map. return false; } } diff --git a/lib/classes/event/note_deleted.php b/lib/classes/event/note_deleted.php index cce5fb8f4f0..772414a0635 100644 --- a/lib/classes/event/note_deleted.php +++ b/lib/classes/event/note_deleted.php @@ -98,12 +98,12 @@ class note_deleted extends base { } public static function get_objectid_mapping() { - // Notes are not backed up, so no need to map. - return false; + // 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() { - // Notes are not backed up, so no need to map. + // Nothing to map. return false; } } diff --git a/lib/classes/event/note_updated.php b/lib/classes/event/note_updated.php index 8744e066a75..aa28dea53a7 100644 --- a/lib/classes/event/note_updated.php +++ b/lib/classes/event/note_updated.php @@ -108,12 +108,12 @@ class note_updated extends base { } public static function get_objectid_mapping() { - // Notes are not backed up, so no need to map. - return false; + // 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() { - // Notes are not backed up, so no need to map. + // Nothing to map. return false; } } diff --git a/lib/classes/event/user_deleted.php b/lib/classes/event/user_deleted.php index 418f72a0b5f..fc3fb85f772 100644 --- a/lib/classes/event/user_deleted.php +++ b/lib/classes/event/user_deleted.php @@ -147,6 +147,9 @@ class user_deleted extends base { } public static function get_other_mapping() { - return false; + $othermapped = array(); + $othermapped['mnethostid'] = array('db' => 'mnet_host', 'restore' => base::NOT_MAPPED); + + return $othermapped; } } diff --git a/lib/classes/event/webservice_service_created.php b/lib/classes/event/webservice_service_created.php index b17ea6fc155..c8943e262be 100644 --- a/lib/classes/event/webservice_service_created.php +++ b/lib/classes/event/webservice_service_created.php @@ -94,7 +94,7 @@ class webservice_service_created extends base { public static function get_objectid_mapping() { // Webservices are not included in the backups. - return false; + return array('db' => 'external_services', 'restore' => NOT_MAPPED); } public static function get_other_mapping() { diff --git a/lib/classes/event/webservice_service_deleted.php b/lib/classes/event/webservice_service_deleted.php index a10c094665d..c61c1be45e0 100644 --- a/lib/classes/event/webservice_service_deleted.php +++ b/lib/classes/event/webservice_service_deleted.php @@ -88,7 +88,7 @@ class webservice_service_deleted extends base { public static function get_objectid_mapping() { // Webservices are not included in backups. - return false; + 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 c078f92cafe..a0124f57d53 100644 --- a/lib/classes/event/webservice_service_updated.php +++ b/lib/classes/event/webservice_service_updated.php @@ -88,7 +88,7 @@ class webservice_service_updated extends base { public static function get_objectid_mapping() { // Webservices are not included in backups. - return false; + 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 662a2aa0f9d..ca646446494 100644 --- a/lib/classes/event/webservice_service_user_added.php +++ b/lib/classes/event/webservice_service_user_added.php @@ -101,7 +101,7 @@ class webservice_service_user_added extends base { public static function get_objectid_mapping() { // Webservices are not included in backups. - return false; + 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 9488fdda9fd..a812041aa0d 100644 --- a/lib/classes/event/webservice_service_user_removed.php +++ b/lib/classes/event/webservice_service_user_removed.php @@ -101,7 +101,7 @@ class webservice_service_user_removed extends base { public static function get_objectid_mapping() { // Webservices are not included in backups. - return false; + 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 a3f375847a3..8b8a9470b15 100644 --- a/lib/classes/event/webservice_token_created.php +++ b/lib/classes/event/webservice_token_created.php @@ -111,7 +111,7 @@ class webservice_token_created extends base { public static function get_objectid_mapping() { // Webservices are not included in backups. - return false; + return array('db' => 'external_tokens', 'restore' => base::NOT_MAPPED); } public static function get_other_mapping() { diff --git a/lib/classes/event/webservice_token_sent.php b/lib/classes/event/webservice_token_sent.php index 527036c50a1..4f89d46d714 100644 --- a/lib/classes/event/webservice_token_sent.php +++ b/lib/classes/event/webservice_token_sent.php @@ -76,6 +76,6 @@ class webservice_token_sent extends base { public static function get_objectid_mapping() { // Webservices are not included in backups. - return false; + return array('db' => 'external_tokens', 'restore' => base::NOT_MAPPED); } }