diff --git a/mod/book/backup/moodle2/backup_book_stepslib.php b/mod/book/backup/moodle2/backup_book_stepslib.php index a87cad677fa..3c18bd76f75 100644 --- a/mod/book/backup/moodle2/backup_book_stepslib.php +++ b/mod/book/backup/moodle2/backup_book_stepslib.php @@ -43,8 +43,8 @@ class backup_book_activity_structure_step extends backup_activity_structure_step 'pagenum', 'subchapter', 'title', 'content', 'contentformat', 'hidden', 'timemcreated', 'timemodified', 'importsrc')); - $tags = new backup_nested_element('tags'); - $tag = new backup_nested_element('tag', array('id'), array('name', 'rawname')); + $tags = new backup_nested_element('chaptertags'); + $tag = new backup_nested_element('tag', array('id'), array('itemid', 'rawname')); $book->add_child($chapters); $chapters->add_child($chapter); @@ -57,20 +57,20 @@ class backup_book_activity_structure_step extends backup_activity_structure_step $book->annotate_files('mod_book', 'intro', null); // This file area hasn't itemid $chapter->annotate_files('mod_book', 'chapter', 'id'); - $chapter->add_child($tags); + $book->add_child($tags); $tags->add_child($tag); // All these source definitions only happen if we are including user info. - if ($userinfo) { - $tag->set_source_sql('SELECT t.id, t.name, t.rawname + if ($userinfo && core_tag_tag::is_enabled('mod_book', 'book_chapters')) { + $tag->set_source_sql('SELECT t.id, ti.itemid, t.rawname FROM {tag} t JOIN {tag_instance} ti ON ti.tagid = t.id WHERE ti.itemtype = ? AND ti.component = ? - AND ti.itemid = ?', array( + AND ti.contextid = ?', array( backup_helper::is_sqlparam('book_chapters'), backup_helper::is_sqlparam('mod_book'), - backup::VAR_PARENTID)); + backup::VAR_CONTEXTID)); } // Return the root element (book), wrapped into standard activity structure diff --git a/mod/book/backup/moodle2/restore_book_stepslib.php b/mod/book/backup/moodle2/restore_book_stepslib.php index 59757c19dd3..951488c077a 100644 --- a/mod/book/backup/moodle2/restore_book_stepslib.php +++ b/mod/book/backup/moodle2/restore_book_stepslib.php @@ -37,7 +37,7 @@ class restore_book_activity_structure_step extends restore_activity_structure_st $paths[] = new restore_path_element('book_chapter', '/activity/book/chapters/chapter'); if ($userinfo) { - $paths[] = new restore_path_element('book_tag', '/activity/book/chapters/chapter/tags/tag'); + $paths[] = new restore_path_element('book_chapter_tag', '/activity/book/chaptertags/tag'); } // Return the paths wrapped into standard activity structure @@ -76,7 +76,7 @@ class restore_book_activity_structure_step extends restore_activity_structure_st $this->set_mapping('book_chapter', $oldid, $newitemid, true); } - protected function process_book_tag($data) { + protected function process_book_chapter_tag($data) { $data = (object)$data; if (!core_tag_tag::is_enabled('mod_book', 'book_chapters')) { // Tags disabled in server, nothing to process. @@ -84,7 +84,10 @@ class restore_book_activity_structure_step extends restore_activity_structure_st } $tag = $data->rawname; - $itemid = $this->get_new_parentid('book_chapter'); + + if (!$itemid = $this->get_mappingid('book_chapter', $data->itemid)) { + return; + } $context = context_module::instance($this->task->get_moduleid()); core_tag_tag::add_item_tag('mod_book', 'book_chapters', $itemid, $context, $tag);