public function MigrateExtrasFileYoutube::processFile in Migrate Extras 7.2
Implementation of MigrateFileInterface::processFiles().
Parameters
$value: The URI or local filespec of a file to be imported.
$owner: User ID (uid) to be the owner of the file.
Return value
object The file entity being created or referenced.
Overrides MigrateFileInterface::processFile
File
- ./
media.inc, line 111
Class
- MigrateExtrasFileYoutube
- Class for creating Youtube file entities.
Code
public function processFile($value, $owner) {
// Convert the Youtube URI into a local stream wrapper.
if (class_exists('MediaInternetYouTubeHandler')) {
$handler = new MediaInternetYouTubeHandler($value);
$destination = $handler
->parse($value);
$file = file_uri_to_object($destination, TRUE);
}
elseif (class_exists('MediaInternetOEmbedHandler')) {
$handler = new MediaInternetOEmbedHandler($value);
$file = $handler
->getFileObject();
}
else {
MigrationBase::displayMessage(t('Could not find a handler for YouTube videos'));
return FALSE;
}
// Create a file entity object for this Youtube reference, and see if we
// can get the video title.
if (empty($file->fid) && ($info = $handler
->getOEmbed())) {
$file->filename = truncate_utf8($info['title'], 255);
}
$file = file_save($file);
if (is_object($file)) {
return $file;
}
else {
return FALSE;
}
}