You are here

protected function elFinderVolumeDrupal::remove in elFinder file manager 7.2

Same name and namespace in other branches
  1. 7.3 inc/elfinder.drupalfs.driver.inc \elFinderVolumeDrupal::remove()

Taken from elFinderVolumeDriver::remove().

Adds a message if the file is in use.

File

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

Class

elFinderVolumeDrupal
@file

Code

protected function remove($path, $force = false) {
  $stat = $this
    ->stat($path);
  if (empty($stat)) {
    return $this
      ->setError(elFinder::ERROR_RM, $path, elFinder::ERROR_FILE_NOT_FOUND);
  }
  $stat['realpath'] = $path;
  $this
    ->rmTmb($stat);
  $this
    ->clearcache();
  if (!$force && !empty($stat['locked'])) {
    return $this
      ->setError(elFinder::ERROR_LOCKED, $this
      ->path($stat['hash']));
  }
  if ($stat['mime'] == 'directory' && empty($stat['thash'])) {
    $ret = $this
      ->delTree($this
      ->convEncIn($path));
    $this
      ->convEncOut();
    if (!$ret) {
      return $this
        ->setError(elFinder::ERROR_RM, $this
        ->path($stat['hash']));
    }
  }
  else {
    $results = $this
      ->_unlink($this
      ->convEncIn($path));
    if (!$results) {
      return $this
        ->setError(elFinder::ERROR_RM, $this
        ->path($stat['hash']));
    }
    if (is_array($results)) {

      // File is in use and is being protected by Drupal. Fetch the first
      // entity where it's used.
      foreach ($results as $entity_type => $entity) {
        if (is_array($entity)) {
          foreach ($entity as $id => $count) {
            if ($entity_type == 'node' && is_integer($id)) {
              $node = node_load($id);
              if (!empty($node->title)) {
                return $this
                  ->setError(elFinder::ERROR_RM, $this
                  ->path($stat['hash']), '', t('File is used in @title', array(
                  '@title' => $node->title,
                )));
              }
            }
          }
        }
      }
      return $this
        ->setError(elFinder::ERROR_RM, $this
        ->path($stat['hash']), t('File is in use.'));
    }
    $this
      ->clearstatcache();
  }
  $this->removed[] = $stat;
  return true;
}