@@ -135,7 +135,7 @@ public function insert_response($responsedata) {
135
135
$ record ->question_id = $ this ->question ->id ;
136
136
$ record ->fileid = intval (clean_text ($ response ->answers [$ this ->question ->id ][0 ]->value ));
137
137
138
- // When saving the draft file, the itemid was the same as the draftfileid . This must now be
138
+ // When saving the draft file, the itemid was the same as the draftitemid . This must now be
139
139
// corrected to the primary key that is questionaire_response_file.id to have a correct reference.
140
140
$ recordid = $ DB ->insert_record (static ::response_table (), $ record );
141
141
if ($ recordid ) {
@@ -146,7 +146,7 @@ public function insert_response($responsedata) {
146
146
$ siblings = $ DB ->get_records ('files ' ,
147
147
['component ' => 'mod_questionnaire ' , 'itemid ' => $ olditem ->itemid ]);
148
148
foreach ($ siblings as $ sibling ) {
149
- if (!$ this -> fix_file_itemid ($ recordid , $ sibling )) {
149
+ if (!self :: fix_file_itemid ($ recordid , $ sibling )) {
150
150
return false ;
151
151
}
152
152
}
@@ -164,8 +164,11 @@ public function insert_response($responsedata) {
164
164
* @return bool
165
165
* @throws \dml_exception
166
166
*/
167
- protected function fix_file_itemid (int $ recordid , \stdClass $ filerecord ): bool {
167
+ public static function fix_file_itemid (int $ recordid , \stdClass $ filerecord ): bool {
168
168
global $ DB ;
169
+ if ((int )$ filerecord ->itemid === $ recordid ) {
170
+ return true ; // Reference is already good, nothing to do.
171
+ }
169
172
$ fs = get_file_storage ();
170
173
$ file = $ fs ->get_file_instance ($ filerecord );
171
174
$ newhash = $ fs ->get_pathname_hash ($ filerecord ->contextid , $ filerecord ->component ,
0 commit comments