mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
MDL-57455 mod_data: performance improvement for tags backup/restore
This commit is contained in:
parent
a783cf701c
commit
5623d18784
@ -47,8 +47,8 @@ class backup_data_activity_structure_step extends backup_activity_structure_step
|
||||
'assessed', 'assesstimestart', 'assesstimefinish', 'defaultsort',
|
||||
'defaultsortdir', 'editany', 'notification', 'timemodified', 'config', 'completionentries'));
|
||||
|
||||
$tags = new backup_nested_element('tags');
|
||||
$tag = new backup_nested_element('tag', array('id'), array('name', 'rawname'));
|
||||
$tags = new backup_nested_element('recordstags');
|
||||
$tag = new backup_nested_element('tag', array('id'), array('itemid', 'rawname'));
|
||||
|
||||
$fields = new backup_nested_element('fields');
|
||||
|
||||
@ -87,7 +87,7 @@ class backup_data_activity_structure_step extends backup_activity_structure_step
|
||||
$record->add_child($ratings);
|
||||
$ratings->add_child($rating);
|
||||
|
||||
$record->add_child($tags);
|
||||
$data->add_child($tags);
|
||||
$tags->add_child($tag);
|
||||
|
||||
// Define sources
|
||||
@ -110,16 +110,18 @@ class backup_data_activity_structure_step extends backup_activity_structure_step
|
||||
'component' => backup_helper::is_sqlparam('mod_data'),
|
||||
'ratingarea' => backup_helper::is_sqlparam('entry')));
|
||||
$rating->set_source_alias('rating', 'value');
|
||||
$tag->set_source_sql('SELECT t.id, t.name, t.rawname
|
||||
FROM {tag} t
|
||||
JOIN {tag_instance} ti
|
||||
ON ti.tagid = t.id
|
||||
WHERE ti.itemtype = ?
|
||||
AND ti.component = ?
|
||||
AND ti.itemid = ?', array(
|
||||
backup_helper::is_sqlparam('data_records'),
|
||||
backup_helper::is_sqlparam('mod_data'),
|
||||
backup::VAR_PARENTID));
|
||||
if (core_tag_tag::is_enabled('mod_data', 'data_records')) {
|
||||
$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.contextid = ?', array(
|
||||
backup_helper::is_sqlparam('data_records'),
|
||||
backup_helper::is_sqlparam('mod_data'),
|
||||
backup::VAR_CONTEXTID));
|
||||
}
|
||||
}
|
||||
|
||||
// Define id annotations
|
||||
|
@ -42,7 +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');
|
||||
$paths[] = new restore_path_element('data_record_tag', '/activity/data/recordstags/tag');
|
||||
}
|
||||
|
||||
// Return the paths wrapped into standard activity structure
|
||||
@ -127,16 +127,19 @@ class restore_data_activity_structure_step extends restore_activity_structure_st
|
||||
*
|
||||
* @param stdClass $data Tag
|
||||
*/
|
||||
protected function process_data_tag($data) {
|
||||
protected function process_data_record_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');
|
||||
if (!$itemid = $this->get_mappingid('data_record', $data->itemid)) {
|
||||
// Some orphaned tag, we could not find the data record for it - ignore.
|
||||
return;
|
||||
}
|
||||
|
||||
$tag = $data->rawname;
|
||||
$context = context_module::instance($this->task->get_moduleid());
|
||||
core_tag_tag::add_item_tag('mod_data', 'data_records', $itemid, $context, $tag);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user