(Perhaps this could be moved to the quiz forum.)
I think the answer to this is No, but ...
Conceptually, the way question import works is
- The import format parses the file, and creates a data structure in Memory which is the same as you gets when the user clicks save on the editing form for that question type.
- Then we use the standard function to save that data into the question bank database tables.
Unfortunately, the real code is old and crufty, so it does not work exactly like that. There are some slight differences in the two data-structures, and we don't entirely use the standard save_question method. Instead, question/format.php does some work of its own https://github.com/moodle/moodle/blob/a149d6a177f58aa031c60d6e1b4c0d9f8f2ced22/question/format.php#L397 and only later calls the standard save_question_options to do the rest.
If it did not work like that, then it would be as simple as setting $question->id in your import format, and then the standard code would do an update, not an insert, of the question.
Except that, while it would be simple, it would be extremely dangerous, because people could easily overwrite any question in the question bank. So, if this was made possible, you would need to do various checks:
- Check that the question from the import file is at least the same type as the one we are about to overwrite (and possibly some other sanity checks, e.g. in the same category.)
- Check that the current user has permission to edit any questions that are due to be overwritten.
- Have an extra are-you-sure warning step in the import process, that confirms to you which questions if any would be overwritten if you proceeded with this import.
But, if it was implemented well, I would not object to adding a change like this to Moodle core. But I doubt I will have time to do this myself. I will peer review if anyone else implements it.