summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Ryan2012-02-04 22:47:23 (GMT)
committer Mike Ryan2012-02-04 22:47:23 (GMT)
commit934ff09a4ea19c4a6f5616cb21f8b2fb33b9ea20 (patch)
treebef6191f55793c4f75b8399ef77c0e28be48913f
parentfe509b25aa9d438c2413213834e915977cff95fc (diff)
Issue #1419086 by mikeryan: Better error handling in MigrateXMLReader::next()
-rw-r--r--CHANGELOG.txt1
-rw-r--r--plugins/sources/xml.inc35
2 files changed, 22 insertions, 14 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index dc7004c..9de2e53 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -34,6 +34,7 @@ Features and enhancements
- #1254398 - Prevent accidental emailing during migration.
Bug fixes
+- #1419086 - Better error handling in MigrateXMLReader::next().
- #1422114 - ID list array must be imploded for queries.
- #1372204 - Fix loss of pictures when updating users.
- #1364034 - Add cache_key option to sources, for disambiguation.
diff --git a/plugins/sources/xml.inc b/plugins/sources/xml.inc
index f6e6c83..41ddf77 100644
--- a/plugins/sources/xml.inc
+++ b/plugins/sources/xml.inc
@@ -679,6 +679,10 @@ class MigrateXMLReader implements Iterator {
$this->url = $xml_url;
$this->elementQuery = $element_query;
$this->idQuery = $id_query;
+
+ // Suppress errors during parsing, so we can pick them up after
+ libxml_use_internal_errors(TRUE);
+
// Parse the element query. First capture group is the element path, second
// (if present) is the attribute.
preg_match_all('|^/([^\[]+)(.*)$|', $element_query, $matches);
@@ -738,24 +742,27 @@ class MigrateXMLReader implements Iterator {
// it into SimpleXML.
// Despite appearances, this is almost twice as fast as
// simplexml_load_string($this->readOuterXML());
- try {
- $node = $this->reader->expand();
+ $node = $this->reader->expand();
+ if ($node) {
+ $dom = new DOMDocument();
+ $node = $dom->importNode($node, TRUE);
+ $dom->appendChild($node);
+ $this->currentElement = simplexml_import_dom($node);
+ $idnode = $this->currentElement->xpath($this->idQuery);
+ $this->currentId = (string)reset($idnode);
+ break;
}
- catch (Exception $e) {
+ else {
foreach (libxml_get_errors() as $error) {
- Migration::displayMessage(MigrateItemsXML::parseLibXMLError($error));
+ $error_string = MigrateItemsXML::parseLibXMLError($error);
+ if ($migration = Migration::currentMigration()) {
+ $migration->saveMessage($error_string);
+ }
+ else {
+ Migration::displayMessage($error_string);
+ }
}
- throw new MigrateException(t('Failed to load node from !url:',
- array('!url' => $this->url)));
- continue;
}
- $dom = new DOMDocument();
- $node = $dom->importNode($node, TRUE);
- $dom->appendChild($node);
- $this->currentElement = simplexml_import_dom($node);
- $idnode = $this->currentElement->xpath($this->idQuery);
- $this->currentId = (string)reset($idnode);
- break;
}
}
}