I'm developing a question type plugin for moodle and ran into an issue that you might be able to help me out with.
The plugin has the feature that you can attach .pdf files which are opened on a different browser tab via a button. It is realized with (and other) this code snippet (in renderer.php):
$my_url= \moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
This works as intended as far as I'm not copying the course but after the backup and restore process the URL is not generated automatically and my file_storage is 0. Although the files are copied and I would just have to open the question settings and save it.
The files are also in the database. To my question:
Do you guys know whether it is possible to trigger the "URL" generation already in restore.class.php so that an user does not have to open and save it manually?
With best regards, Eduard
P.S. Maybe someone has an idea how to trigger question_type_renderer.php after the copy to save just everything that's in there at that moment.
------ Edit ------
I tried to add (and also the qtype_... without "booking_key_attachment")
public static function get_qtype_fileareas()
{
return array(
'booking_key_attachment' => 'qtype_..._booking_key_attachment');
}
But sadly I have still the issue.
I looked into phpadmin especially into mdl_files and the filearea (in my case booking_key_attachment) column is filled with the correct filearea name but no filename exists).
I'm saving the areas like this:
file_save_draft_area_files(
$question->booking_key_attachment,
$question->context->id,
'qtype_..._booking_line',
'booking_key_attachment',
$question->booking_key_attachment,
[
'subdirs' => 0,
'maxbytes' => 0,
'maxfiles' => 1
]
);
I also tried to use the function move_files() to use a new context ID.
Also I'm checking the var_dump of my $files (get_file_storage). Which has in the main course at least 1 entry but in the copied course 0.