MDL-57455 mod_data: Implement tagging
[moodle.git] / mod / data / backup / moodle2 / restore_data_stepslib.php
index 7ac138b..c7bd911 100644 (file)
@@ -42,6 +42,7 @@ class restore_data_activity_structure_step extends restore_activity_structure_st
             $paths[] = new restore_path_element('data_record', '/activity/data/records/record');
             $paths[] = new restore_path_element('data_content', '/activity/data/records/record/contents/content');
             $paths[] = new restore_path_element('data_rating', '/activity/data/records/record/ratings/rating');
+            $paths[] = new restore_path_element('data_tag', '/activity/data/records/record/tags/tag');
         }
 
         // Return the paths wrapped into standard activity structure
@@ -121,6 +122,25 @@ class restore_data_activity_structure_step extends restore_activity_structure_st
         $this->set_mapping('data_content', $oldid, $newitemid, true); // files by this itemname
     }
 
+    /**
+     * Add tags to restored records.
+     *
+     * @param stdClass $data Tag
+     */
+    protected function process_data_tag($data) {
+        $data = (object)$data;
+
+        if (!core_tag_tag::is_enabled('mod_data', 'data_records')) { // Tags disabled in server, nothing to process.
+            return;
+        }
+
+        $tag = $data->rawname;
+        $itemid = $this->get_new_parentid('data_record');
+
+        $context = context_module::instance($this->task->get_moduleid());
+        core_tag_tag::add_item_tag('mod_data', 'data_records', $itemid, $context, $tag);
+    }
+
     protected function process_data_rating($data) {
         global $DB;