Merge branch 'wip-MDL-34220-m24' of git://github.com/samhemelryk/moodle

This commit is contained in:
Dan Poltawski 2012-07-16 11:11:36 +08:00
commit 30a3059e79
2 changed files with 40 additions and 16 deletions

View file

@ -323,7 +323,7 @@ class backup_module_structure_step extends backup_structure_step {
$availability = new backup_nested_element('availability', array('id'), array(
'sourcecmid', 'requiredcompletion', 'gradeitemid', 'grademin', 'grademax'));
$availabilityfield = new backup_nested_element('availability_field', array('id'), array(
'userfield', 'customfieldid', 'operator', 'value'));
'userfield', 'customfield', 'customfieldtype', 'operator', 'value'));
// attach format plugin structure to $module element, only one allowed
$this->add_plugin_structure('format', $module, false);
@ -346,7 +346,11 @@ class backup_module_structure_step extends backup_structure_step {
WHERE cm.id = ?', array(backup::VAR_MODID));
$availability->set_source_table('course_modules_availability', array('coursemoduleid' => backup::VAR_MODID));
$availabilityfield->set_source_table('course_modules_avail_fields', array('coursemoduleid' => backup::VAR_MODID));
$availabilityfield->set_source_sql('
SELECT cmaf.*, uif.shortname AS customfield, uif.datatype AS customfieldtype
FROM {course_modules_avail_fields} cmaf
LEFT JOIN {user_info_field} uif ON uif.id = cmaf.customfieldid
WHERE cmaf.coursemoduleid = ?', array(backup::VAR_MODID));
// Define annotations
$module->annotate_ids('grouping', 'groupingid');
@ -377,14 +381,18 @@ class backup_section_structure_step extends backup_structure_step {
$avail = new backup_nested_element('availability', array('id'), array(
'sourcecmid', 'requiredcompletion', 'gradeitemid', 'grademin', 'grademax'));
$availfield = new backup_nested_element('availability_field', array('id'), array(
'userfield', 'customfieldid', 'operator', 'value'));
'userfield', 'operator', 'value', 'customfield', 'customfieldtype'));
$section->add_child($avail);
$section->add_child($availfield);
// Define sources
$section->set_source_table('course_sections', array('id' => backup::VAR_SECTIONID));
$avail->set_source_table('course_sections_availability', array('coursesectionid' => backup::VAR_SECTIONID));
$availfield->set_source_table('course_sections_avail_fields', array('coursesectionid' => backup::VAR_SECTIONID));
$availfield->set_source_sql('
SELECT csaf.*, uif.shortname AS customfield, uif.datatype AS customfieldtype
FROM {course_sections_avail_fields} csaf
LEFT JOIN {user_info_field} uif ON uif.id = csaf.customfieldid
WHERE csaf.coursesectionid = ?', array(backup::VAR_SECTIONID));
// Aliases
$section->set_source_alias('section', 'number');

View file

@ -1139,18 +1139,26 @@ class restore_section_structure_step extends restore_structure_step {
$data = (object)$data;
// Mark it is as passed by default
$passed = true;
// Ok, if it is a profile field we need to check it exists
if (!is_null($data->customfieldid)) {
if (!$DB->record_exists('user_info_field', array('id' => $data->customfieldid))) {
$passed = false;
}
$customfieldid = null;
// If a customfield has been used in order to pass we must be able to match an existing
// customfield by name (data->customfield) and type (data->customfieldtype)
if (is_null($data->customfield) xor is_null($data->customfieldtype)) {
// xor is sort of uncommon. If either customfield is null or customfieldtype is null BUT not both.
// If one is null but the other isn't something clearly went wrong and we'll skip this condition.
$passed = false;
} else if (!is_null($data->customfield)) {
$params = array('shortname' => $data->customfield, 'datatype' => $data->customfieldtype);
$customfieldid = $DB->get_field('user_info_field', 'id', $params);
$passed = ($customfieldid !== false);
}
if ($passed) {
// Create the object to insert into the database
$availfield = new stdClass();
$availfield->coursesectionid = $this->task->get_sectionid();
$availfield->userfield = $data->userfield;
$availfield->customfieldid = $data->customfieldid;
$availfield->customfieldid = $customfieldid;
$availfield->operator = $data->operator;
$availfield->value = $data->value;
$DB->insert_record('course_sections_avail_fields', $availfield);
@ -2637,18 +2645,26 @@ class restore_module_structure_step extends restore_structure_step {
$data = (object)$data;
// Mark it is as passed by default
$passed = true;
// Ok, if it is a profile field we need to check it exists
if (!is_null($data->customfieldid)) {
if (!$DB->record_exists('user_info_field', array('id' => $data->customfieldid))) {
$passed = false;
}
$customfieldid = null;
// If a customfield has been used in order to pass we must be able to match an existing
// customfield by name (data->customfield) and type (data->customfieldtype)
if (!empty($data->customfield) xor !empty($data->customfieldtype)) {
// xor is sort of uncommon. If either customfield is null or customfieldtype is null BUT not both.
// If one is null but the other isn't something clearly went wrong and we'll skip this condition.
$passed = false;
} else if (!empty($data->customfield)) {
$params = array('shortname' => $data->customfield, 'datatype' => $data->customfieldtype);
$customfieldid = $DB->get_field('user_info_field', 'id', $params);
$passed = ($customfieldid !== false);
}
if ($passed) {
// Create the object to insert into the database
$availfield = new stdClass();
$availfield->coursemoduleid = $this->task->get_moduleid(); // Lets add the availability cmid
$availfield->userfield = $data->userfield;
$availfield->customfieldid = $data->customfieldid;
$availfield->customfieldid = $customfieldid;
$availfield->operator = $data->operator;
$availfield->value = $data->value;
// Insert into the database