Hello,
We've been migrating courses from an old moodle 2.7.2+ (Build 2014-10-28) to a new (latest version 3.11.4 (Build 2021-11-08).
We come across one course that fails to import. An exception occurs when performing a select query in the database. When I run the query myself directly it works fine and returns a result as expected.
The error suggests that the database wasn't available (but it is!) and the problem is repeatable.
Here is the php_error.log entry:
[25-Nov-2021 13:15:02 Europe/London] Default exception handler: Error reading from database Debug: MySQL server has gone away
SELECT bc.itemid
FROM mdl_backup_controllers bc, mdl_course c
WHERE bc.operation = 'restore'
AND bc.type = 'course'
AND bc.itemid = c.id
AND bc.itemid = ? LIMIT 0, 1
[array (
0 => 28,
)]
Error code: dmlreadexception
* line 486 of \lib\dml\moodle_database.php: dml_read_exception thrown
* line 1212 of \lib\dml\mysqli_native_moodle_database.php: call to moodle_database->query_end()
* line 2002 of \lib\dml\moodle_database.php: call to mysqli_native_moodle_database->get_recordset_sql()
* line 252 of \backup\util\ui\restore_ui.class.php: call to moodle_database->record_exists_sql()
* line 231 of \backup\util\ui\restore_ui.class.php: call to restore_ui->is_temporary_course_created()
* line 152 of \backup\restore.php: call to restore_ui->cleanup()
[25-Nov-2021 13:15:02 Europe/London] Exception ignored in shutdown function tool_log\log\manager::dispose: Error reading from database [25-Nov-2021 13:15:02 Europe/London] Potential coding error - existing temptables found when disposing database. Must be dropped! [25-Nov-2021 13:15:02 Europe/London] PHP Fatal error: Uncaught ddl_change_structure_exception: DDL sql execution error in E:\public_html\moodle\lib\dml\moodle_database.php:492
Stack trace:
#0 E:\public_html\moodle\lib\dml\mysqli_native_moodle_database.php(1098): moodle_database->query_end()
#1 E:\public_html\moodle\lib\ddl\database_manager.php(77): mysqli_native_moodle_database->change_database_structure()
#2 E:\public_html\moodle\lib\ddl\database_manager.php(332): database_manager->execute_sql_arr()
#3 E:\public_html\moodle\lib\dml\moodle_temptables.php(140): database_manager->drop_table()
#4 E:\public_html\moodle\lib\dml\moodle_database.php(405): moodle_temptables->dispose()
#5 E:\public_html\moodle\lib\dml\mysqli_native_moodle_database.php(622): moodle_database->dispose()
#6 E:\public_html\moodle\lib\dml\moodle_database.php(160): mysqli_native_moodle_database->dispose()
#7 [internal function]: moodle_database->__destruct()
#8 {main}
thrown in E:\public_html\moodle\lib\dml\moodle_database.php on line 492
Running the SQL query with 28 as a parameter returns the value 28.
The message "Potential coding error - existing temptables found when disposing database. Must be dropped!"halfway down suggests to me that there is some DDL (database Schema changes etc.) going on that might be causing the problem.
I'm not sure how to get past it. Any suggestions would be great.