When you perform a restore of a course, which fully exhausts the character limit for the course name of 254 characters, the restore process will concat 'copy' together with a counter to the course name, as long as the course name already exists.
However, the length of the course name is never checked for sanity according to the database limit of 254 characters. Neither when the user can set the course name within the restore process, nor when in retore_dbops.class.php:1686 the function calculate_course_names actually calculates the name of the new course.
The result for the user is that a error message 'Error writing to database' is displayed, without helpful information about what just happened and why and how to fix it.
Steps to reproduce (from comments below):
- As a manager (or admin), create a backup of a course
- As a manager (or admin), restore the course backup as a new course (you need to be manager or admin for that)
- specify the name of the course, with something very long. I've used this : "A very long title of a marvelous Moodle course about possible bugs in latests versions with very long names of backup filenames (of course, this don't occure very often, but can occure, and it's really a bad thing). So, when it's more than 254 characters long, it generate an error."
- do the restore, and you'll see the error