You are here

class MigrateExtrasFileYoutube in Migrate Extras 7.2

Class for creating Youtube file entities.

Hierarchy

Expanded class hierarchy of MigrateExtrasFileYoutube

1 string reference to 'MigrateExtrasFileYoutube'
MigrateExampleMediaVideoMigration::__construct in migrate_extras_examples/migrate_extras_media/migrate_extras_media.migrate.inc
General initialization of a Migration object.

File

./media.inc, line 91

View source
class MigrateExtrasFileYoutube implements MigrateFileInterface {

  /**
   * Implementation of MigrateFileInterface::fields().
   *
   * @return array
   */
  public static function fields() {
    return array();
  }

  /**
   * Implementation of MigrateFileInterface::processFiles().
   *
   * @param $value
   *  The URI or local filespec of a file to be imported.
   * @param $owner
   *  User ID (uid) to be the owner of the file.
   * @return object
   *  The file entity being created or referenced.
   */
  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;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MigrateExtrasFileYoutube::fields public static function Implementation of MigrateFileInterface::fields(). Overrides MigrateFileInterface::fields
MigrateExtrasFileYoutube::processFile public function Implementation of MigrateFileInterface::processFiles(). Overrides MigrateFileInterface::processFile