Beispiel #1
0
 /**
  * @param IFile $file
  * @param bool $foldersFirst
  * @return int A negative value if the current file should be placed before $file,
  * zero (0) if they are equals, a positive value otherwise.
  */
 public function compareTo(IFile $file, $foldersFirst = false)
 {
     if ($foldersFirst) {
         $isDirThis = $this->isDirectory();
         $isDirFile = $file->isDirectory();
         if ($isDirThis && !$isDirFile) {
             return -1;
         } else {
             if ($isDirFile && !$isDirThis) {
                 return 1;
             }
         }
     }
     $urlParts = $file->getURLComponents();
     $urlParts['path'] = $file->getPathFromRoot();
     //needed to resolve the path (if relative)
     $absolutePathFile = AdvancedPathLib::buildURL($urlParts);
     $urlParts = $this->getURLComponents();
     $urlParts['path'] = $this->getPathFromRoot();
     //needed to resolve the path (if relative)
     $absolutePathThis = AdvancedPathLib::buildURL($urlParts);
     return utf8_strcasecmp($absolutePathThis, $absolutePathFile);
 }
Beispiel #2
0
 /**
  * @return bool TRUE if the file has been successfully moved, FALSE otherwise
  */
 public function moveTo(IFile $file)
 {
     if ($this->realFile === null) {
         throw new EyeUnsupportedOperationException(__METHOD__ . ' on ' . $this->path);
     }
     if ($this->isRoot()) {
         throw new EyeUnsupportedOperationException('Cannot move root folder ' . $this->path . '.');
     }
     //if the destination ($file) is a a directory AND: the source is not a directory OR is a directory with a different name
     if ($file->isDirectory() && (!$this->isDirectory() || $file->getName() != $this->getName())) {
         if ($file->getName() != '/' || $this->getName() != '/') {
             //we redirect the move operation to a file located within the destination directory ($file)
             return $this->moveTo($file->getChildFile($this->getName()));
         }
     }
     $this->checkReadPermission();
     $parentFile = $file->getParentFile();
     if ($parentFile instanceof ISecurableFile) {
         $parentFile->checkWritePermission();
     }
     if ($file->exists()) {
         $file->checkWritePermission();
     }
     try {
         $success = false;
         if ($file instanceof EyeosAbstractVirtualFile) {
             $success = $file->copyFromAndKeepOGP($this, true);
         } else {
             $success = $this->copyTo($file);
         }
         if ($success) {
             // Ensure the "listeners" property has been initialized *before* deleting the file
             $this->getAllFileListeners();
             // Delete file *without firing deletion event* (from outside, file has been moved, not deleted)
             if ($this->deleteImpl(true, false, false)) {
                 //notify listeners
                 $this->fireEvent('fileMoved', new FileEvent($this, $file));
                 return true;
             }
         }
     } catch (EyeException $e) {
         throw new EyeIOException('Cannot move ' . $this->path . ' to ' . $file->getPath() . '.', 0, $e);
     }
     throw new EyeIOException('Cannot move ' . $this->path . ' to ' . $file->getPath() . ' (Unknown error).');
 }
Beispiel #3
0
 /**
  * @return bool TRUE if the file has been successfully moved, FALSE otherwise
  * @throws EyeIOException
  */
 public function moveTo(IFile $file)
 {
     if (!$this->exists()) {
         throw new EyeFileNotFoundException($this->path . ' does not exist.');
     }
     if ($file->isDirectory()) {
         $target = $file->getChildFile($this->getName());
     } else {
         $target = $file;
     }
     if ($target->isFile()) {
         return false;
     }
     try {
         if ($target->copyFrom($this)) {
             $this->delete(true);
         }
     } catch (Exception $e) {
         throw new EyeIOException('Error occured during file move ' . $this->path . ' => ' . $file->getPath() . '.', 0, $e);
     }
     return true;
 }