mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 00:16:46 +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
1 changed files with 10 additions and 3 deletions
|
@ -73,9 +73,6 @@ class xmldb_file extends xmldb_object {
|
||||||
*/
|
*/
|
||||||
function validateXMLStructure() {
|
function validateXMLStructure() {
|
||||||
|
|
||||||
/// Let's capture errors
|
|
||||||
libxml_use_internal_errors(true);
|
|
||||||
|
|
||||||
/// Create and load XML file
|
/// Create and load XML file
|
||||||
$parser = new DOMDocument();
|
$parser = new DOMDocument();
|
||||||
$contents = file_get_contents($this->path);
|
$contents = file_get_contents($this->path);
|
||||||
|
@ -84,6 +81,13 @@ class xmldb_file extends xmldb_object {
|
||||||
$contents = preg_replace('|<STATEMENTS>.*</STATEMENTS>|s', '', $contents);
|
$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);
|
$parser->loadXML($contents);
|
||||||
/// Only validate if we have a schema
|
/// Only validate if we have a schema
|
||||||
if (!empty($this->schema) && file_exists($this->schema)) {
|
if (!empty($this->schema) && file_exists($this->schema)) {
|
||||||
|
@ -92,6 +96,9 @@ class xmldb_file extends xmldb_object {
|
||||||
/// Check for errors
|
/// Check for errors
|
||||||
$errors = libxml_get_errors();
|
$errors = libxml_get_errors();
|
||||||
|
|
||||||
|
// Stop capturing errors
|
||||||
|
libxml_use_internal_errors($olderrormode);
|
||||||
|
|
||||||
/// Prepare errors
|
/// Prepare errors
|
||||||
if (!empty($errors)) {
|
if (!empty($errors)) {
|
||||||
/// Create one structure to store errors
|
/// Create one structure to store errors
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue