You are here

public function MigrateItemsXML::getItem in Migrate 6.2

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

Implementors are expected to return an object representing a source item. Items are cached as an array of key=ID and value=stdclass object with attribute xml containing the xml SimpleXMLElement object of the item.

Parameters

mixed $id:

Return value

stdClass

Overrides MigrateItems::getItem

File

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

Class

MigrateItemsXML
Implementation of MigrateItems, for providing a list of IDs and for retrieving a parsed XML document given an ID from this list.

Code

public function getItem($id) {

  // Make sure we actually have an ID
  if (empty($id)) {
    return NULL;
  }
  $items = $this
    ->getAllItems();
  $item = $items[$id];
  if ($item) {
    return $item;
  }
  else {
    $migration = Migration::currentMigration();
    $message = t('Loading of item XML for ID !id failed:', array(
      '!id' => $id,
    ));
    foreach (libxml_get_errors() as $error) {
      $message .= "\n" . $error->message;
    }
    $migration
      ->getMap()
      ->saveMessage(array(
      $id,
    ), $message, MigrationBase::MESSAGE_ERROR);
    libxml_clear_errors();
    return NULL;
  }
}