-
Improvement
-
Resolution: Deferred
-
Minor
-
None
-
4.0.2
This is not really a bug, it's more like a small issue which even does not affect Moodle itself. It affects plugin developers which try to make a plugin using Moodle core code.
There is a function here which chooses the right restorer for the question type being restored. This function has a static cache and as the comment in the function says this cache is here to mainly save instantiations of these qtype restorers. But... as described for example here, static function 'cache' is shared even among instances of the class. This is fine, when only one course is restored while running php script. But as a developer, when you want to restore multiple courses (which use questions) the restoration of a second course is unsuccessful because this cache is preserved, but some of the properties of the cache does not exist anymore.
I know, that this issue needs maybe more explanation. I'm not in the state of code that I can share. But there's a very simple fix to this problem. This function is only used at 2 places in Moodle and both of these places are responsible for restoration, which is a fairly long process, so a couple of more instantiations of a class could not add much time to restore a course. Another bonus is that we get rid of global stuff which is ugly and very hard to debug
So I propose not to use the cache at all and instantiate the class every time in this function.