Esempio n. 1
0
 /**
  * @param boolean $recursive
  * @param boolean $onlyContents In the case of a directory, only delete the files it contains if TRUE
  * or the entire directory otherwise
  * @param boolean $fireEvent
  * @return bool TRUE if the file has been successfully deleted, FALSE otherwise
  */
 protected function deleteImpl($recursive = false, $onlyContents = false, $fireEvent = true)
 {
     if ($this->realFile === null) {
         throw new EyeUnsupportedOperationException(__METHOD__ . ' on ' . $this->path);
     }
     if ($this->isRoot()) {
         throw new EyeIOException('Cannot delete the root folder.');
     }
     $this->checkDeletePermission();
     $success = true;
     try {
         if ($this->isDirectory()) {
             //FIXME: the permissions of each child are not checked using this way
             $meta = $this->getMeta();
             $success = $this->realFile->delete($recursive, $onlyContents);
             MetaManager::getInstance()->deleteMeta($this);
             if ($onlyContents) {
                 $this->setMeta($meta);
             }
         } else {
             if ($fireEvent) {
                 // Ensure the "listeners" property has been initialized *before* deleting the file
                 $this->getAllFileListeners();
             }
             $this->realFile->delete();
             //notify listeners
             if ($fireEvent) {
                 $this->fireEvent('fileDeleted', new FileEvent($this));
             }
             $this->deleteMeta();
         }
     } catch (EyeFileNotFoundException $e) {
         throw new EyeFileNotFoundException($this->path . ' does not exist.', 0, $e);
     } catch (EyeIOException $e) {
         throw new EyeIOException('Cannot delete ' . $this->path . '.', 0, $e);
     }
     if ($success) {
         if ($fireEvent) {
             //notify listeners on the parent directory
             $this->getParentFile()->fireEvent('fileDeleted', new FileEvent($this));
         }
     }
     return $success;
 }