/** * @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).'); }
/** * @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; }