示例#1
0
 /**
  * @return bool TRUE if the file has been successfully renamed, FALSE otherwise
  */
 public function renameTo($newName)
 {
     if ($this->realFile === null) {
         throw new EyeUnsupportedOperationException(__METHOD__ . ' on ' . $this->path);
     }
     if (!$this->exists()) {
         throw new EyeFileNotFoundException($this->path . ' does not exist.');
     }
     if ($this->isRoot()) {
         throw new EyeUnsupportedOperationException('Cannot rename the root folder.');
     }
     $oldName = $this->getName();
     $oldPath = $this->getAbsolutePath();
     $this->getParentFile()->checkWritePermission();
     $newFile = FSI::getFile(dirname($oldPath) . '/' . $newName);
     $newFile->checkWritePermission();
     try {
         if ($this->realFile->renameTo($newName)) {
             //change internal name in URL
             $urlParts = $this->getURLComponents();
             $dirname = dirname($urlParts['path']);
             $urlParts['path'] = $dirname . '/' . $newName;
             $this->path = AdvancedPathLib::buildUrl($urlParts);
             //Update URL components cache
             $this->urlParts = $urlParts;
             //update metadata
             MetaManager::getInstance()->updateMeta($this, array('oldName' => $oldName));
             $oldFile = FSI::getFile($oldPath);
             //notify listeners
             $this->fireEvent('fileRenamed', new FileEvent($oldFile, $this));
             return true;
         }
     } catch (EyeFileNotFoundException $e) {
         throw new EyeFileNotFoundException($this->path . ' does not exist.', 0, $e);
     } catch (EyeException $e) {
         throw new EyeIOException('Unable to rename file ' . $this->path . '.', 0, $e);
     }
     throw new EyeIOException('Unable to rename file ' . $this->path . '.');
 }