You are here

function media_browser_plus_move_physical_folder in Media Browser Plus 7

Same name and namespace in other branches
  1. 7.3 includes/media_browser_plus.folders.inc \media_browser_plus_move_physical_folder()
  2. 7.2 media_browser_plus.module \media_browser_plus_move_physical_folder()

Cut-paste a directory with its children into a new filesystem location.

Parameters

$source string the current folder path:

$destination string the path we want the folder moved to:

3 calls to media_browser_plus_move_physical_folder()
media_browser_plus_folder_list_submit in includes/media_browser_plus.folders.inc
@todo Document what this function is does.
media_browser_plus_folder_save_folder in includes/media_browser_plus.folders.inc
@todo Document what this function is does.
media_browser_plus_media_settings_submit in ./media_browser_plus.module
Saves the entered settings.

File

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

Code

function media_browser_plus_move_physical_folder($source, $destination) {
  $destination = drupal_realpath($destination);
  $source = drupal_realpath($source);
  $jail = drupal_realpath(variable_get('file_default_scheme', 'public') . '://');

  // @todo Please avoid an error by checking the preconditions instead.
  $files = @scandir($source);
  if ($files && count($files) > 2) {
    $transfer = new FileTransferLocal($jail);
    $transfer
      ->copyDirectory($source, $destination);
    $transfer
      ->removeDirectory($source);
  }
  else {

    // The folder is empty so just delete and create the new one.
    drupal_rmdir($source);
    file_prepare_directory($destination, FILE_CREATE_DIRECTORY);
  }
}