MDL-57457 mod_book: performance improvement for tags backup/restore

This commit is contained in:
Andrew Hancox 2017-04-19 09:38:31 +01:00 committed by Marina Glancy
parent 0178314682
commit 4282634fcd
2 changed files with 13 additions and 10 deletions

View File

@ -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

View File

@ -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);