Stray files appearing in Support Files

Stray files appearing in Support Files

por Richard Lobb -
Número de respuestas: 0

I have a question for Tim (or anyone else who might have experienced the problem), relating to a confusing but fortunately extremely rare issue.

On a small handful of occasions in the last few years we've found questions that have acquired additional files in their Support Files section. This seems to occur when we saving the question after editing it. In the most recent occasion on which we have some data, there were NINE stray files! All were images from the text of other CodeRunner questions. The teacher to whom this occurred didn't think they even had all those other questions (the ones that were the apparent source of the stray image files) open at the time, but isn't sure. However, he is quite confident (as am I, from earlier occasions) that this wasn't an inadvertent drag-and-drop event or similar user UI error. You can only drag and drop into the filemanager when that section of the editing form is open, and it wasn't open at the time. Also - you don't make such slips nine times in one editing session!

As an example, there was a question with the following HTML in the question text:

<img class="img-fluid atto_image_button_text-bottom" src="https://quiz2024.csse.canterbury.ac.nz/draftfile.php/830/user/draft/884732361/_2021su2cosc122exam1.png" alt="Reload page and contact staff if you can't see the graph" width="567" height="451">

Somehow, that image file has been picked up by the filemanager element for the Support Files of the prototype that was being edited.

Looking through the CodeRunner source, I thought this pickup must have occurred within the following code (simplified) from within edit_coderunner_form.php:

$draftid = file_get_submitted_draft_itemid('datafiles');
$options = $this->fileoptions;
$options['subdirs'] = false;

file_prepare_draft_area(
    $draftid,
    $this->context->id,
    'qtype_coderunner',
    'datafile',
    empty($question->id) ? null : (int) $question->id,
    $options
);
$question->datafiles = $draftid;
 

BUT ... I've looked through the Moodle source code for file_prepare_draft_area and it searches the DB for all files belonging to the component 'qtype_coderunner', marked as 'datafile' and belonging to the given question id (which could be null, though in the example quoted above the teacher was editing an existing question, so it shouldn't have been null). I don't see how this could possibly pull in all those image files embedded in other questions!

So I'm probably looking in the wrong place :-(

Suggestions, anyone?