diff --git a/CHANGELOG.txt b/CHANGELOG.txt index d418f6faa46b7734a704abfb74004a870d0fb039..0248d9ff7b188518c127db2376c7017e7e0388bb 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 a2a8f6809b869e9cc1f82f04a9914072a8c859da..4e09a7f94da5dad9afcf3b7179f3c5b41f3b8e2b 100644 --- a/plugins/sources/xml.inc +++ b/plugins/sources/xml.inc @@ -300,6 +300,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 */ @@ -337,6 +344,27 @@ class MigrateItemsXML extends MigrateItems { ' | item ID xpath = ' . $this->itemIDXpath; } + /** + * 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; } /**