Skip to content

Commit

Permalink
update existing files.itemid to questionnaire_response_file.id
Browse files Browse the repository at this point in the history
  • Loading branch information
srobotta authored and lucaboesch committed Apr 4, 2024
1 parent 79f2b73 commit 2439d76
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions classes/responsetype/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function insert_response($responsedata) {
$record->question_id = $this->question->id;
$record->fileid = intval(clean_text($response->answers[$this->question->id][0]->value));

// When saving the draft file, the itemid was the same as the draftfileid. This must now be
// When saving the draft file, the itemid was the same as the draftitemid. This must now be
// corrected to the primary key that is questionaire_response_file.id to have a correct reference.
$recordid = $DB->insert_record(static::response_table(), $record);
if ($recordid) {
Expand All @@ -146,7 +146,7 @@ public function insert_response($responsedata) {
$siblings = $DB->get_records('files',
['component' => 'mod_questionnaire', 'itemid' => $olditem->itemid]);
foreach ($siblings as $sibling) {
if (!$this->fix_file_itemid($recordid, $sibling)) {
if (!self::fix_file_itemid($recordid, $sibling)) {
return false;
}
}
Expand All @@ -164,8 +164,11 @@ public function insert_response($responsedata) {
* @return bool
* @throws \dml_exception
*/
protected function fix_file_itemid(int $recordid, \stdClass $filerecord): bool {
public static function fix_file_itemid(int $recordid, \stdClass $filerecord): bool {
global $DB;
if ((int)$filerecord->itemid === $recordid) {
return true; // Reference is already good, nothing to do.
}
$fs = get_file_storage();
$file = $fs->get_file_instance($filerecord);
$newhash = $fs->get_pathname_hash($filerecord->contextid, $filerecord->component,
Expand Down

0 comments on commit 2439d76

Please sign in to comment.