You are here

public function MigrateItemFile::getItem in Migrate 6.2

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

Return an object representing a file or piece thereof.

Parameters

$id: The file id, which is the file URI.

Return value

object The item object for migration.

Overrides MigrateItem::getItem

File

plugins/sources/files.inc, line 206
Support for migration from files sources.

Class

MigrateItemFile
Implementation of MigrateItem, for retrieving a file from the file system based on source directory and an ID provided by a MigrateList class.

Code

public function getItem($id) {
  $pieces = explode(MIGRATE_CHUNK_SEPARATOR, $id);
  $item_uri = $this->baseDir . $pieces[0];
  $chunk = $pieces[1];

  // Get the file data at the specified URI
  $data = $this
    ->loadFile($item_uri);
  if (is_string($data)) {
    $this->parser
      ->setContent($data);
    $return = new stdClass();
    $return->filedata = $this->parser
      ->getChunk($chunk);
    return $return;
  }
  else {
    if ($data === TRUE) {
      $return = new stdClass();
      return $return;
    }
    else {
      $migration = Migration::currentMigration();
      $message = t('Loading of !objecturi failed:', array(
        '!objecturi' => $item_uri,
      ));
      $migration
        ->getMap()
        ->saveMessage(array(
        $id,
      ), $message, MigrationBase::MESSAGE_ERROR);
      return NULL;
    }
  }
}