You are here

public function MigrateItemXML::getItem in Migrate 6.2

Same name and namespace in other branches
  1. 7.2 plugins/sources/xml.inc \MigrateItemXML::getItem()

Implementors are expected to return an object representing a source item.

Parameters

mixed $id:

Return value

stdClass

Overrides MigrateItem::getItem

File

plugins/sources/xml.inc, line 134
Support for migration from XML sources.

Class

MigrateItemXML
Implementation of MigrateItem, for retrieving a parsed XML document given an ID provided by a MigrateList class.

Code

public function getItem($id) {

  // Make sure we actually have an ID
  if (empty($id)) {
    return NULL;
  }
  $item_url = $this
    ->constructItemUrl($id);

  // And make sure we actually got a URL to fetch
  if (empty($item_url)) {
    return NULL;
  }

  // Get the XML object at the specified URL;
  $xml = $this
    ->loadXmlUrl($item_url);
  if ($xml !== FALSE) {
    $return = new stdclass();
    $return->xml = $xml;
    return $return;
  }
  else {
    $migration = Migration::currentMigration();
    $message = t('Loading of !objecturl failed:', array(
      '!objecturl' => $item_url,
    ));
    foreach (libxml_get_errors() as $error) {
      $message .= "\n" . $error->message;
    }
    $migration
      ->getMap()
      ->saveMessage(array(
      $id,
    ), $message, MigrationBase::MESSAGE_ERROR);
    libxml_clear_errors();
    return NULL;
  }
}