mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
xmldb MDL-24979 Made xmldb (a) not hide libxml errors permanently, (b) not incorrectly report previous errors with a later, working file
This commit is contained in:
parent
bfb82da3e4
commit
d854dff9ef
@ -73,9 +73,6 @@ class xmldb_file extends xmldb_object {
|
||||
*/
|
||||
function validateXMLStructure() {
|
||||
|
||||
/// Let's capture errors
|
||||
libxml_use_internal_errors(true);
|
||||
|
||||
/// Create and load XML file
|
||||
$parser = new DOMDocument();
|
||||
$contents = file_get_contents($this->path);
|
||||
@ -84,6 +81,13 @@ class xmldb_file extends xmldb_object {
|
||||
$contents = preg_replace('|<STATEMENTS>.*</STATEMENTS>|s', '', $contents);
|
||||
}
|
||||
|
||||
// Let's capture errors
|
||||
$olderrormode = libxml_use_internal_errors(true);
|
||||
|
||||
// Clear XML error flag so that we don't incorrectly report failure
|
||||
// when a previous xml parse failed
|
||||
libxml_clear_errors();
|
||||
|
||||
$parser->loadXML($contents);
|
||||
/// Only validate if we have a schema
|
||||
if (!empty($this->schema) && file_exists($this->schema)) {
|
||||
@ -92,6 +96,9 @@ class xmldb_file extends xmldb_object {
|
||||
/// Check for errors
|
||||
$errors = libxml_get_errors();
|
||||
|
||||
// Stop capturing errors
|
||||
libxml_use_internal_errors($olderrormode);
|
||||
|
||||
/// Prepare errors
|
||||
if (!empty($errors)) {
|
||||
/// Create one structure to store errors
|
||||
|
Loading…
x
Reference in New Issue
Block a user