You are here

protected function elFinderVolumeDrupal::_move in elFinder file manager 7.3

Same name and namespace in other branches
  1. 8.2 src/Controller/elFinderVolumeDrupal.php \elFinderVolumeDrupal::_move()
  2. 6.2 inc/elfinder.drupalfs.driver.inc \elFinderVolumeDrupal::_move()
  3. 7.2 inc/elfinder.drupalfs.driver.inc \elFinderVolumeDrupal::_move()

Move file into another parent dir. Return new file path or false.

Parameters

string $source source file path:

string $target target dir path:

string $name new name:

Return value

bool|string

File

inc/elfinder.drupalfs.driver.inc, line 145
elFinder driver for Drupal filesystem.

Class

elFinderVolumeDrupal
@file

Code

protected function _move($source, $targetDir, $name) {
  $target = $targetDir . DIRECTORY_SEPARATOR . (!empty($name) ? $name : basename($source));
  $is_dir = is_dir($source);

  // Maybe move this to rename().
  if (!is_dir($target) && !$this
    ->CheckExtension($this
    ->_drupalfileobject($target))) {
    return FALSE;
  }

  // Call the parent method;
  $results = parent::_move($source, $targetDir, $name);

  // Update Dupal's file_managed table.
  $srcuri = $this
    ->drupalpathtouri($source);
  $dsturi = $this
    ->drupalpathtouri($target);
  if ($is_dir) {

    // Renamed a folder. Update folder contents in file_managed table.
    db_update('file_managed')
      ->expression('uri', "REPLACE(uri, :search, :replace)", array(
      ':search' => $srcuri . '/',
      ':replace' => $dsturi . '/',
    ))
      ->condition('uri', $srcuri . '/%', 'LIKE')
      ->execute();
  }
  else {

    // Only renamed one file.
    db_update('file_managed')
      ->fields(array(
      'uri' => $dsturi,
      'filename' => $name,
    ))
      ->condition('uri', $srcuri)
      ->execute();
  }

  // Update any fields that point to this file.
  field_cache_clear();
  return $results;
}