With a recent migration to Moodle 3.7.1 we were not able to restore a course due to a dml exception when processing a quiz activity with some multianswer questions that did not map the answers correctly, returning an array of empty strings that were then imploded, producing at the end one unique string of separators (i.e. ',,,,,,,,,,,,').
Since we use a Postgres database, the following error raised (with several references on the tracker but still showing up for our scenario):
We also successfully restored the same backup on demo.moodle.net, it worked since there's a Mysql DB on use.
The actual behavior details are:
Class: restore_qtype_multianswer_pluginMethod: after_execute_question
Since the call to the method get_mappingid('question', $question) might return an empty string (answers were not created because they were lacking on the backup's 'questions.xml' file):
The variable $sequence might return ',,,,,,,,,'
Thus, the following line produced the dlm error (Postgres):
Performing the array_unique on $sequencearr will ensure it gets reduced to one empty value, therefore the imploded $sequence will not end being a string containing only commas.
We found this procedure is a fail-safe that works for Mysql/MariaDB and Postgres.
Can someone validate it please?