There was a big proliferation and reuse of $pdf variable that was making the code hard to read/review. This commit does change nothing but makes it more readable. Also adds a couple of Close() calls, not strictly needed because they don't have opened files. But think it makes really clearer the scope of every variable. And, for sure it frees some resources. That cannot be bad.
The upgrade step was changing any site that had the setting 'defaulthomepage' set to HOMEPAGE_SITE to HOMEPAGE_MY. We can not make the assumption that users want this setting changed.
Before this patch if a user who is not logged in to Moodle accesses the enrol/index.php page directly they were redirected to the Moodle front page after login, rather than back to a page that would allow them to self enrol, if it is enabled on the course. This change will cause a user who directly accesses the page to be redirected back to it after they have logged in, unless the course has guest access enabled. Thanks to Marina Glancy for suggesting the use of get_referer()
When a pdf object is instantiated and any file is loaded with set_pdf() or load_pdf(), the files remain open until the pdf is saved with pdf_save() or outputted with Output().. In that cases is needed to perform an explicit Close() in order to free resources, parsers and, ultimately, fclose() the files. Note that only the uses detected in the editpdf unit tests have been fixed. I'd recommend to analyse every instance of the tcpdf libs. Also, there was one incorrecly reused pdf instance in then generate_combined_pdf_for_attempt() method. Apparently it was not leading to problems, but better use a separate instance (#246).
Get rid of the gc_collect_cycles() that only was hiding incorrectly left open files. This must be fixed in code when possible. And pdf libs allow us to do so. Note that a lot of gc_collect_cycles() were added in MDL-47675, I'd recommend to take a look to all them, being replaced by fixes in code when possible.
can_finish_during_the_attempt was returning the wrong result for random questions for behaviours like deferred feedback.