summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordaspeter2011-10-02 19:53:23 (GMT)
committer Mike Ryan2011-10-02 19:53:23 (GMT)
commitf00a2ba1c98f73a537eb7a7408723c5856a0d713 (patch)
treed383e1813da457e82d3aec2cb756cc7a03e6e256
parentf0799315f4a5846d718c020b7d70bc3ada173385 (diff)
Issue #1290706 by das-peter: Centralize loading of XML
-rw-r--r--CHANGELOG.txt1
-rw-r--r--plugins/sources/xml.inc54
2 files changed, 34 insertions, 21 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index d418f6f..0248d9f 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -3,6 +3,7 @@ Next release
============
Features and enhancements
+- #1290706 - Centralize loading of XML.
- #1254398 - Prevent accidental emailing during migration.
Bug fixes
diff --git a/plugins/sources/xml.inc b/plugins/sources/xml.inc
index a2a8f68..4e09a7f 100644
--- a/plugins/sources/xml.inc
+++ b/plugins/sources/xml.inc
@@ -301,6 +301,13 @@ class MigrateItemsXML extends MigrateItems {
protected $xmlUrl;
/**
+ * Stores the loaded XML document.
+ *
+ * @var SimpleXMLElement
+ */
+ protected $xml = FALSE;
+
+ /**
* xpath identifying the element used for each item
*/
protected $itemXpath;
@@ -338,6 +345,27 @@ class MigrateItemsXML extends MigrateItems {
}
/**
+ * Load and return the xml from the defined xmlUrl.
+ * @return SimpleXMLElement
+ */
+ public function &xml() {
+ if (!$this->xml && !empty($this->xmlUrl)) {
+ $this->xml = simplexml_load_file($this->xmlUrl);
+ if (!$this->xml) {
+ $migration = Migration::currentMigration();
+ $migration->showMessage(t(
+ 'Loading of !xmlUrl failed:',
+ array('!xmlUrl' => $this->xmlUrl)
+ ));
+ foreach (libxml_get_errors() as $error) {
+ $migration->showMessage($error);
+ }
+ }
+ }
+ return $this->xml;
+ }
+
+ /**
* Load the XML at the given URL, and return an array of the IDs found
* within it.
*
@@ -345,20 +373,12 @@ class MigrateItemsXML extends MigrateItems {
*/
public function getIdList() {
migrate_instrument_start("Retrieve $this->xmlUrl");
- $xml = simplexml_load_file($this->xmlUrl);
+ $xml = $this->xml();
migrate_instrument_stop("Retrieve $this->xmlUrl");
if ($xml) {
return $this->getIDsFromXML($xml);
}
- else {
- $migration = Migration::currentMigration();
- $migration->showMessage(t('Loading of !xmlUrl failed:',
- array('!xmlUrl' => $this->xmlUrl)));
- foreach (libxml_get_errors() as $error) {
- $migration->showMessage($error);
- }
- return NULL;
- }
+ return NULL;
}
/**
@@ -405,7 +425,7 @@ class MigrateItemsXML extends MigrateItems {
*/
public function computeCount() {
$count = 0;
- $xml = simplexml_load_file($this->xmlUrl);
+ $xml = $this->xml();
if ($xml) {
$ids = $this->getIDsFromXML($xml, TRUE);
$count = count($ids);
@@ -420,19 +440,11 @@ class MigrateItemsXML extends MigrateItems {
* @return array
*/
public function getAllItems() {
- $xml = simplexml_load_file($this->xmlUrl);
+ $xml = $this->xml();
if ($xml) {
return $this->getItemsFromXML($xml);
}
- else {
- $migration = Migration::currentMigration();
- $migration->showMessage(t('Loading of !xmlUrl failed:',
- array('!xmlUrl' => $this->xmlUrl)));
- foreach (libxml_get_errors() as $error) {
- $migration->showMessage($error);
- }
- return NULL;
- }
+ return NULL;
}
/**