예제 #1
0
 /**
  * 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);
 }
예제 #2
0
 /**
  * Deletes all thumbnails under the given path defined by the resource type,
  * path and file name.
  *
  * @param ResourceType $resourceType
  * @param string       $path
  * @param string       $fileName
  *
  * @return bool `true` if deleted successfully
  */
 public function deleteThumbnails(ResourceType $resourceType, $path, $fileName = null)
 {
     $path = Path::combine($this->getThumbnailsPath(), $resourceType->getName(), $path, $fileName);
     if ($this->thumbsBackend->has($path)) {
         return $this->thumbsBackend->deleteDir($path);
     }
     return false;
 }
예제 #3
0
 /**
  * Deletes value under given key  from cache
  *
  * @param string $key
  *
  * @return bool true if successful
  */
 public function delete($key)
 {
     $cachePath = $this->createCachePath($key);
     if (!$this->backend->has($cachePath)) {
         return false;
     }
     $this->backend->delete($cachePath);
     $dirs = explode('/', dirname($cachePath));
     do {
         $dirPath = implode('/', $dirs);
         $contents = $this->backend->listContents($dirPath);
         if (!empty($contents)) {
             break;
         }
         $this->backend->deleteDir($dirPath);
         array_pop($dirs);
     } while (!empty($dirs));
 }
 /**
  * Checks if resized image already exists
  *
  * @return bool
  */
 public function exists()
 {
     return $this->backend->has($this->getFilePath());
 }
예제 #5
0
 /**
  * Renames current file by adding number to file name.
  *
  * Renaming is done by adding number in parenthesis until file name doesn't
  * collide with any other file existing in target backend/path.
  * For example, if target backend path contains file named foo.txt
  * and current file name is foo.txt, this method will change current file
  * name to foo(1).txt.
  *
  * @param Backend $backend target backend
  * @param string  $path    target backend relative path
  *
  * @return bool true if file was renamed
  */
 public function autorename(Backend $backend = null, $path = '')
 {
     $filePath = Path::combine($path, $this->fileName);
     if (!$backend->has($filePath)) {
         return false;
     }
     $pieces = explode('.', $this->fileName);
     $basename = array_shift($pieces);
     $extension = implode('.', $pieces);
     $i = 0;
     while (true) {
         $i++;
         $this->fileName = "{$basename}({$i}).{$extension}";
         $filePath = Path::combine($path, $this->fileName);
         if (!$backend->has($filePath)) {
             break;
         }
     }
     return true;
 }