You are here

protected function EntityShareMediasFileImport::importFile in Entity Share 7

Import the scald Atom.

Parameters

object $file: File object.

string $uuid: UUID of the file.

string $media_url: URL of the remote file.

Return value

int Scald atom id.

1 call to EntityShareMediasFileImport::importFile()
EntityShareMediasFileImport::fieldManagement in modules/entity_share_medias/modules/entity_share_medias_file/includes/entity_share_medias_file.import.inc
Manage field media reference content.

File

modules/entity_share_medias/modules/entity_share_medias_file/includes/entity_share_medias_file.import.inc, line 55
Class for handling scald Medias in RTE.

Class

EntityShareMediasFileImport
Class for file import.

Code

protected function importFile($file, $uuid, $media_url) {

  // Test if file already exists.
  $fid = $this
    ->getFileIdFromUuid($uuid);

  // Update the id with existing id if exists.
  if (isset($fid)) {
    $file->fid = $fid;
    $local_file = file_load($fid);
    $local_file_name = $local_file->filename;
  }
  else {

    // Empty the remote fid to create a local one.
    $file->fid = NULL;
  }

  // If the fileexists, get the media from the url if available.
  if (!empty($file->file_url)) {

    // Create the file if not exists or the filename is different.
    if (!isset($local_file_name) || isset($local_file_name) && $local_file_name != $file->filename) {
      $file = $this
        ->createFile($media_url, (object) $file);
    }
  }
  if (isset($file)) {
    if (!isset($fid)) {
      $fid = $file->fid;
    }

    // Update the file_usage table to keep the relation with the sid.
    $file_usage_list = file_usage_list($file);
    if (!isset($file_usage_list[$this->entity->entity_type]['file'])) {
      file_usage_add($file, 'file', $this->entity->entity_type, $fid);
    }
    $fid = $file->fid;
  }

  // Return the fid.
  return $fid;
}