Skip to content

Commit

Permalink
MDL-20636 Fix 2 essay issues. Wrong file area name and broken backup/…
Browse files Browse the repository at this point in the history
…restore.
  • Loading branch information
timhunt committed May 5, 2011
1 parent 9e06daf commit 3b3d5e7
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,32 @@ protected function define_question_plugin_structure() {
// connect the visible container ASAP
$plugin->add_child($pluginwrapper);

// This qtype uses standard question_answers, add them here
// to the tree before any other information that will use them
$this->add_question_question_answers($pluginwrapper);

// Now create the qtype own structures
// No own structures!
$essay = new backup_nested_element('essay', array('id'), array(
'responseformat', 'responsefieldlines', 'attachments',
'graderinfo', 'graderinfoformat'));

// Now the own qtype tree
$pluginwrapper->add_child($essay);

// set source to populate the data
$essay->set_source_table('qtype_essay_options',
array('questionid' => backup::VAR_PARENTID));

// don't need to annotate ids nor files

return $plugin;
}

/**
* Returns one array with filearea => mappingname elements for the qtype
*
* Used by {@link get_components_and_fileareas} to know about all the qtype
* files to be processed both in backup and restore.
*/
public static function get_qtype_fileareas() {
return array(
'graderinfo' => 'question_created',
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,39 @@ class restore_qtype_essay_plugin extends restore_qtype_plugin {
* Returns the paths to be handled by the plugin at question level
*/
protected function define_question_plugin_structure() {
return array(
new restore_path_element('essay', $this->get_pathfor('/essay'))
);
}

$paths = array();
/**
* Process the qtype/essay element
*/
public function process_essay($data) {
global $DB;

// This qtype uses question_answers, add them
// Crazy we use answers to store feedback!
$this->add_question_question_answers($paths);
$data = (object)$data;
$oldid = $data->id;

// Add own qtype stuff
// essay qtype has not own structures (but the question_answers use above)
// Detect if the question is created or mapped
$questioncreated = $this->get_mappingid('question_created',
$this->get_old_parentid('question')) ? true : false;

return $paths; // And we return the interesting paths
// If the question has been created by restore, we need to create its
// qtype_essay too
if ($questioncreated) {
$data->questionid = $this->get_new_parentid('question');
$newitemid = $DB->insert_record('qtype_essay_options', $data);
$this->set_mapping('qtype_essay', $oldid, $newitemid);
}
}

/**
* Return the contents of this qtype to be processed by the links decoder
*/
public static function define_decode_contents() {
return array(
new restore_decode_content('qtype_essay_options', 'graderinfo', 'qtype_essay'),
);
}
}
9 changes: 6 additions & 3 deletions question/type/essay/questiontype.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function is_manual_graded() {
}

public function response_file_areas() {
return array('attachments', 'answers');
return array('attachments', 'answer');
}

public function get_question_options($question) {
Expand Down Expand Up @@ -118,11 +118,14 @@ public function attachment_options() {

public function move_files($questionid, $oldcontextid, $newcontextid) {
parent::move_files($questionid, $oldcontextid, $newcontextid);
$this->move_files_in_answers($questionid, $oldcontextid, $newcontextid);
$fs = get_file_storage();
$fs->move_area_files_to_new_context($oldcontextid,
$newcontextid, 'qtype_essay', 'graderinfo', $questionid);
}

protected function delete_files($questionid, $contextid) {
parent::delete_files($questionid, $contextid);
$this->delete_files_in_answers($questionid, $contextid);
$fs = get_file_storage();
$fs->delete_area_files($contextid, 'qtype_essay', 'graderinfo', $questionid);
}
}

0 comments on commit 3b3d5e7

Please sign in to comment.