We have legacy code on an XML migration that attempts to load the whole XML object to access some attributes.
This worked fine on Migrate 7.x-2.4, but since upgrading to 7.x-2.8 it breaks. I think it actually breaks at 7.x-2.6.

With 7.x-2.8, trying to load the whole xml object fails.
We're doing something like this:

$items_class = new MigrateItemsXML($items_url, $item_xpath, $item_ID_xpath);
$this->source = new MigrateSourceMultiItems($items_class, $fields, array('skip_count' => TRUE));
$xml = $items_class->xml();

In this case the $xml object is empty.

I've found a way to fix this but I'm not sure if this is the 'right' way or not so would like someone with more knowledge of this module to review this and let me know.

In xml.inc we have the following:

 public function &xml() {
    if (!empty($this->currentUrl)) {
      $this->currentXml = simplexml_load_file($this->currentUrl);
      if ($this->currentXml === FALSE) {
        Migration::displayMessage(t(
          'Loading of !currentUrl failed:',
          array('!currentUrl' => $this->currentUrl)
        ));
        foreach (libxml_get_errors() as $error) {
          Migration::displayMessage(self::parseLibXMLError($error));
        }
      }
      else {
        $this->registerNamespaces($this->currentXml);
      }
    }
    return $this->currentXml;
  }

This returns nothing in our case as $this->currentUrl is not defined.

In the MigrateItemsXML constructor there is no mention of $this->currentUrl, so I've added it like so:

if (!is_array($urls)) {
      $urls = array($urls);
    }
$this->urls = $urls;
$this->currentUrl = $urls[0];

I'll attach a patch with my one line change, as this does work in our case.

Is there another way to load the SimpleXML object to access attributes on parent items?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

finn.lewis created an issue. See original summary.

Finn Lewis’s picture

Title: Loading a simplexml object to parse whole xml broken since » Loading a simplexml object to parse whole xml object
FileSize
432 bytes