function media_browser_plus_move_file in Media Browser Plus 7
Same name and namespace in other branches
- 7.3 media_browser_plus.module \media_browser_plus_move_file()
- 7.2 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
$tid the folder's term id.:
$media the media object.:
$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 ./
media_browser_plus.module - Changes the folder of the submitted media items.
- media_browser_plus_media_import_batch_import_files in ./
media_browser_plus.module - Batch process that only differs in 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 2220 - Adds fields to the media browser forms for better UX
Code
function media_browser_plus_move_file($tid, $media, $replace = FILE_EXISTS_RENAME) {
// Dont 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);
file_prepare_directory($path, FILE_CREATE_DIRECTORY);
$destination = $path . '/' . $media->filename;
file_move($media, $destination, $replace);
}
}