/** * Renames the current working folder. * * @param string $newName new folder name * * @return array containing newName and newPath * * @throws AccessDeniedException * @throws AlreadyExistsException * @throws InvalidNameException */ public function rename($newName) { $disallowUnsafeCharacters = $this->app['config']->get('disallowUnsafeCharacters'); if (!Folder::isValidName($newName, $disallowUnsafeCharacters) || $this->backend->isHiddenFolder($newName)) { throw new InvalidNameException('Invalid folder name'); } $newBackendPath = dirname($this->getPath()) . '/' . $newName; if ($this->backend->has($newBackendPath)) { throw new AlreadyExistsException('File already exists'); } $newClientPath = Path::normalize(dirname($this->getClientCurrentFolder()) . '/' . $newName); if (!$this->getBackend()->rename($this->getPath(), $newBackendPath)) { throw new AccessDeniedException(); } /* @var OperationManager $currentRequestOperation */ $currentRequestOperation = $this->app['operation']; if ($currentRequestOperation->isAborted()) { // Don't continue in this case, no need to touch thumbs and cache entries return array('aborted' => true); } // Delete related thumbs path $this->thumbnailRepository->deleteThumbnails($this->resourceType, $this->getClientCurrentFolder()); $this->app['cache']->changePrefix(Path::combine($this->resourceType->getName(), $this->getClientCurrentFolder()), Path::combine($this->resourceType->getName(), $newClientPath)); return array('newName' => $newName, 'newPath' => $newClientPath, 'renamed' => 1); }
/** * Checks if directory contains subdirectories * * @param Backend $backend * @param ResourceType $resourceType * @param string $clientPath * @param Acl $acl * * @return bool */ public function containsDirectories(Backend $backend, ResourceType $resourceType, $clientPath, Acl $acl) { $location = rtrim($this->applyPathPrefix(Path::combine($resourceType->getDirectory(), $clientPath)), '/\\') . '/'; if (!is_dir($location) || false === ($fh = @opendir($location))) { return false; } $hasChildren = false; $resourceTypeName = $resourceType->getName(); $clientPath = rtrim($clientPath, '/\\') . '/'; while (false !== ($filename = readdir($fh))) { if ($filename == '.' || $filename == '..') { continue; } if (is_dir($location . $filename)) { if (!$acl->isAllowed($resourceTypeName, $clientPath . $filename, Permission::FOLDER_VIEW)) { continue; } if ($backend->isHiddenFolder($filename)) { continue; } $hasChildren = true; break; } } closedir($fh); return $hasChildren; }