This issue is ready for peer review.
I have added two separate commits:
1) To fix this issue, as I have discussed with you, we will change the status of the question to draft when we disapprove of a question in StudentQuiz.
2) To update the legacy data.
classes/local/studentquiz_question.php - change_state_visibility - the huge if statement here is not very readable. A better way to do this, both for simplicity of code and self-documentation is: Have an array like [self::STATE_DISAPPROVED => question_version_status::QUESTION_STATUS_DRAFT] which defines the logic ...
Then ... well, the change_state_visibility method is not even very helpful. Why is this a separate function? I would expect the work of udpating the state of the question in the question bank to be part of the funciotn that updates the studentquiz_question state, so it is impossible for the two things to get out-of-synch. Right, we have a huge chunk of duplciate logic between changestate.php and change_question_state in externallib.php That should be fixed.
And, the fact that both those places end up calling change_state_visibility twice in quick succession really shows this code is not well designed.
classes/question/bank/studentquiz_bank_view.php build_query - "qv.status <> '$state'", we shoudl be usign a placeholder to insert the value into the SQL.
ensure_studentquiz_question_status_is_always_ready - the coment here says "Make sure questions created/edited in StudentQuiz is always ready." but that is now incorrect.
Upgrade code:
If you are only doing a single $DB->execute, you don't need a transactoin.
The SQL is unnecessarily complicated. No need to have {question} and {question_versions} in the subquery (unless I am wrong). Just do UPDATE {question_versions} SET status = 'draft' WHERE questionbankentryid IN (...)
Then, there is no need to have two levels on nested subqueries.
Hi @timhunt ,
This issue is ready for peer review. I have added two separate commits: 1) To fix this issue, as I have discussed with you, we will change the status of the question to draft when we disapprove of a question in StudentQuiz. 2) To update the legacy data.