You are here

function media_browser_plus_move_file in Media Browser Plus 7.2

Same name and namespace in other branches
  1. 7.3 media_browser_plus.module \media_browser_plus_move_file()
  2. 7 media_browser_plus.module \media_browser_plus_move_file()

Moves and saves permanently a media file.

Every media file that is saved or updated,should pass through this to make sure the filesystem location is the same with the folder term.

Parameters

int $tid: The folder's term id.

object $media: The media object.

int $replace: Replace behavior when the destination file already exists.

5 calls to media_browser_plus_move_file()
media_browser_plus_change_folder in ./media_browser_plus.module
Called by the JS fronted (ajax) to change the folder of a media object.
media_browser_plus_edit_file_submit in ./media_browser_plus.module
Form submit handler for the media browser forms that edit media entities.
media_browser_plus_media_admin_folder_change_submit in includes/file_entity.admin.inc
Changes the folder of the submitted media items.
media_browser_plus_media_import_batch_import_files in ./media_browser_plus.module
Batch process with the ability to apply the field values to the items.
media_browser_plus_submit in ./media_browser_plus.module
Submit handler for the media browser forms that create new media entities.

File

./media_browser_plus.module, line 2090
Adds fields to the media browser forms for better UX

Code

function media_browser_plus_move_file($tid, $media, $replace = FILE_EXISTS_RENAME) {

  // Don't change the uri for media files with external source.
  if (strpos($media->uri, 'public') === FALSE && strpos($media->uri, 'private') === FALSE) {
    file_save($media);
  }
  else {

    // Media translation module does need this since it allows the creation of
    // file references which shouldn't move the referenced file itself when
    // moved. See http://drupal.org/node/1331818 for details.
    if (module_exists('media_translation') && media_translation_is_virtual_file($media->fid)) {
      file_save($media);
      return;
    }
    $folder = media_browser_plus_folder_load($tid);
    $path = media_browser_plus_construct_dir_path($folder);
    if (dirname($media->uri) !== $path) {
      file_prepare_directory($path, FILE_CREATE_DIRECTORY);
      file_move($media, $path, $replace);
    }
  }
}