You are here

class MigrateFileBlob in Migrate 7.2

Handle cases where we're handed a blob (i.e., the actual contents of a file, such as image data) to be stored as a real file in Drupal.

Hierarchy

Expanded class hierarchy of MigrateFileBlob

1 string reference to 'MigrateFileBlob'
WineFileBlobMigration::__construct in migrate_example/wine.inc
General initialization of a Migration object.

File

plugins/destinations/file.inc, line 483
Support for file entity as destination. Note that File Fields have their own destination in fields.inc

View source
class MigrateFileBlob extends MigrateFile {

  /**
   * The file contents we will be writing to a real file.
   *
   * @var
   */
  protected $fileContents;

  /**
   * Implementation of MigrateFile::copyFile().
   *
   * @param $destination
   *  Drupal destination path.
   *
   * @return bool
   *  TRUE if the file contents were successfully written, FALSE otherwise.
   */
  protected function copyFile($destination) {
    if (file_put_contents($destination, $this->fileContents)) {
      return TRUE;
    }
    else {
      $migration = Migration::currentMigration();
      $migration
        ->saveMessage(t('Failed to write blob data to %destination', array(
        '%destination' => $destination,
      )));
      return FALSE;
    }
  }

  /**
   * Implementation of MigrateFileInterface::processFile().
   *
   * @param $value
   *  The file contents to be saved as a file.
   * @param $owner
   *  User ID (uid) to be the owner of the file.
   *
   * @return object
   *  File entity being created or referenced.
   */
  public function processFile($value, $owner) {
    $this->fileContents = $value;
    $file = parent::processFile($value, $owner);
    return $file;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MigrateFile::$destinationDir protected property The destination directory within Drupal.
MigrateFile::$destinationFile protected property The filename relative to destinationDir to which to save the current file.
MigrateFile::fields public static function Implementation of MigrateFileInterface::fields(). Overrides MigrateFileBase::fields 1
MigrateFile::__construct public function Overrides MigrateFileBase::__construct 1
MigrateFileBase::$defaultFile protected property An optional file object to use as a default starting point for building the file entity.
MigrateFileBase::$fileReplace protected property How to handle destination filename collisions.
MigrateFileBase::$preserveFiles protected property Set to TRUE to prevent file deletion on rollback.
MigrateFileBase::createFileEntity protected function Setup a file entity object suitable for saving.
MigrateFileBase::FILE_EXISTS_REUSE constant Extension of the core FILE_EXISTS_* constants, offering an alternative to reuse the existing file if present as-is (core only offers the options of replacing it or renaming to avoid collision).
MigrateFileBase::markForPreservation protected function If asked to preserve files from deletion on rollback, add a file_usage entry.
MigrateFileBlob::$fileContents protected property The file contents we will be writing to a real file.
MigrateFileBlob::copyFile protected function Implementation of MigrateFile::copyFile(). Overrides MigrateFile::copyFile
MigrateFileBlob::processFile public function Implementation of MigrateFileInterface::processFile(). Overrides MigrateFile::processFile