Example #1
0
 /**
  * deletes both filesystem file and metafile and removes instance from lookup array
  * filesystem file will be kept when $keepFilesystemFile is TRUE
  *
  * @param boolean $keepFilesystemFile
  *
  * @throws Exception
  */
 public function delete($keepFilesystemFile = FALSE)
 {
     FileEvent::create(FileEvent::BEFORE_METAFILE_DELETE, $this)->trigger();
     if (Application::getInstance()->getDb()->deleteRecord('files', $this->id)) {
         unset(self::$instancesById[$this->id]);
         unset(self::$instancesByPath[$this->filesystemFile->getPath()]);
         if (!$keepFilesystemFile) {
             $this->filesystemFile->delete();
         }
     } else {
         throw new MetaFileException("Delete of metafile '{$this->filesystemFile->getPath()}' failed.");
     }
 }
Example #2
0
 /**
  * creates a meta file based on filesystem file
  * @return MetaFile
  * @throws FilesystemFileException
  */
 public function createMetaFile()
 {
     $db = Application::getInstance()->getDb();
     if (count($db->doPreparedQuery("\n\t\t\tSELECT\n\t\t\t\tf.filesID\n\t\t\tFROM\n\t\t\t\tfiles f\n\t\t\t\tINNER JOIN folders fo ON fo.foldersID = f.foldersID\n\t\t\tWHERE\n\t\t\t\tf.File  COLLATE utf8_bin = ? AND\n\t\t\t\tfo.Path COLLATE utf8_bin = ?\n\t\t\tLIMIT 1", array($this->filename, $this->folder->getRelativePath())))) {
         throw new FilesystemFileException("Metafile '{$this->filename}' in '{$this->folder->getRelativePath()}' already exists.", FilesystemFileException::METAFILE_ALREADY_EXISTS);
     }
     $mf = $this->folder->createMetaFolder();
     $user = User::getSessionUser();
     if (!($filesID = $db->insertRecord('files', array('foldersID' => $mf->getId(), 'File' => $this->filename, 'Mimetype' => $this->getMimetype(), 'createdBy' => is_null($user) ? NULL : $user->getAdminId())))) {
         throw new FilesystemFileException("Could not create metafile for '{$this->filename}'.", FilesystemFileException::METAFILE_CREATION_FAILED);
     } else {
         $mf = MetaFile::getInstance(NULL, $filesID);
         FileEvent::create(FileEvent::AFTER_METAFILE_CREATE, $this)->trigger();
         return $mf;
     }
 }