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
- class \MigrateFileBase implements MigrateFileInterface
- class \MigrateFile
- class \MigrateFileBlob
- class \MigrateFile
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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MigrateFile:: |
protected | property | The destination directory within Drupal. | |
MigrateFile:: |
protected | property | The filename relative to destinationDir to which to save the current file. | |
MigrateFile:: |
public static | function |
Implementation of MigrateFileInterface::fields(). Overrides MigrateFileBase:: |
1 |
MigrateFile:: |
public | function |
Overrides MigrateFileBase:: |
1 |
MigrateFileBase:: |
protected | property | An optional file object to use as a default starting point for building the file entity. | |
MigrateFileBase:: |
protected | property | How to handle destination filename collisions. | |
MigrateFileBase:: |
protected | property | Set to TRUE to prevent file deletion on rollback. | |
MigrateFileBase:: |
protected | function | Setup a file entity object suitable for saving. | |
MigrateFileBase:: |
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:: |
protected | function | If asked to preserve files from deletion on rollback, add a file_usage entry. | |
MigrateFileBlob:: |
protected | property | The file contents we will be writing to a real file. | |
MigrateFileBlob:: |
protected | function |
Implementation of MigrateFile::copyFile(). Overrides MigrateFile:: |
|
MigrateFileBlob:: |
public | function |
Implementation of MigrateFileInterface::processFile(). Overrides MigrateFile:: |