error/restore_unknown_restore_type when duplicating any kind of entry in every course

error/restore_unknown_restore_type when duplicating any kind of entry in every course

by Werner Schöller -
Number of replies: 8

Since last week I have a strange problem (Moodle 4.4.6). When duplicating any kind of entry in a course i get:

grafik.png

I did run some server package upgrades, but nothing major except for upgrading MariaDB 10.6.21 -> 10.11.11. Mariadb-upgrade completed without any errors. I upgraded to Moodle 4.4.7 today, the error remains.

I don´t have any other issues (i am aware of yet) with my moodle instance. 

Any ideas? 

Thanks!

Average of ratings: -
In reply to Werner Schöller

Re: error/restore_unknown_restore_type when duplicating any kind of entry in every course

by William Lu -
Picture of Particularly helpful Moodlers
Moving to the General Help Forum...
In reply to William Lu

Re: error/restore_unknown_restore_type when duplicating any kind of entry in every course

by Werner Schöller -
It is a Moodle bug introduced with PCRE 10.45.

When switching to PCRE 10.45 you will get errors like that in your webserver error-log:
AH01071: Got error '} or \\o{} or \\N{U+} at offset 3 in /var/www/moodle/backup/util/xml/xml_writer.class.php on line 263; PHP message: PHP Warning: preg_replace(): Compilation failed: digits missing after \\x or in \\x{} or \\o{}

https://github.com/PCRE2Project/pcre2/blob/pcre2-10.45/NEWS

* (Minor pattern syntax change) Parsing of the \x escape is stricter, and is
no longer parsed as an escape for the NUL character if not followed by '{' or
a hexadecimal digit. Use \x00 instead.

Since I am running on Gentoo, i am using PCRE 10.45 already with PHP 8.2.x.

If you change \x- -> \x0- in the REGEX code everything works again.

My colleague will open a bug and create a patch.
In reply to Werner Schöller

Re: error/restore_unknown_restore_type when duplicating any kind of entry in every course

by Werner Schöller -
In reply to Werner Schöller

Re: error/restore_unknown_restore_type when duplicating any kind of entry in every course

by JHON EDINSON RANGEL ARDILA -
Picture of Plugin developers

Hello

Thanks for your report.

I have the same error in moodle. Temporal solution, in /backup/util/xml/xml_writer.class.php, the function xml_safe_utf8:

 protected function xml_safe_utf8($content) {
        $content = preg_replace('/[\x-\x8\xb-\xc\xe-\x1f\x7f]/is', '', $content ?? ''); // clean CTRL chars.
        $content = preg_replace("/\r\n|\r/", "\n", $content); // Normalize line&return=>line
        return fix_utf8($content);
    }

Replace content function for this:

protected function xml_safe_utf8($content) {
$content = preg_replace('/[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F]/s', '', $content ?? '');
$content = preg_replace("/\r\n|\r/", "\n", $content);
return fix_utf8($content);
}
In reply to Werner Schöller

Re: error/restore_unknown_restore_type when duplicating any kind of entry in every course

by iddqd sakh -

In my case, it didn’t help—or rather, it only helped partially. Today a teacher accidentally deleted course items and reported that restoring from the Recycle Bin doesn’t work. I stumbled on this bug and upgraded to 4.5.4 from 4.5.2. I deleted a course item and successfully restored it, BUT items deleted before the update still return “error/restore_unknown_restore_type.”
I’m running Gentoo with PHP 8.2.28 (PCRE 10.45 2025-02-05).
Do you think upgrading to 5 will help, or will it make things worse? The deleted items are very important to the user.

Thanks, everyone.

In reply to iddqd sakh

Re: error/restore_unknown_restore_type when duplicating any kind of entry in every course

by Ken Task -
Picture of Particularly helpful Moodlers

If you've not changed settings for recyclebin, whatever was deleted a backup (.mbz file) is made and stored for the duration settings in recyclebin setup.

Suggest checking the course where the deletion was made and see if in the course menu there is a link to the recyclebin.

Also suggest changing the setting for the recyclebin link in course menu to display all the time.

And ... this plugin might help:

https://moodle.org/plugins/report_allbackups

'SoS'. Ken

In reply to Ken Task

Re: error/restore_unknown_restore_type when duplicating any kind of entry in every course

by iddqd sakh -
Thanks for the answer. I just now realized that I am writing in a topic where there is an error like mine, but the context is different, I have a problem with restoring items from the cart, and Topicstarter has an error when duplicating any type of entry. Yes, I have already retrieved the deleted item files from filesdir by finding their hashes in the database, but even from the console I cannot restore them. Tomorrow I'll deploy test Moodle 5 and try to restore it.
In reply to iddqd sakh

Re: error/restore_unknown_restore_type when duplicating any kind of entry in every course

by iddqd sakh -
Unfortunately, the recycle bin files created in the moodle version with this bug cannot be restored because the xml files have no values. sadness.