Ejemplo n.º 1
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;
     }
 }
Ejemplo n.º 2
0
 /**
  * set publishedBy user
  * helper method for publish and unpublish
  *  
  * @param User $user
  */
 private function setPublishedBy($user)
 {
     // was a user specified?
     if ($user) {
         $this->publishedBy = $user;
     } else {
         if ($user = User::getSessionUser()) {
             $this->publishedBy = $user;
         } else {
             $this->publishedBy = NULL;
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * fallback method for authenticating single menu entry access on observe_table/observe_row level
  * positive authentication if auth_parameter contains a table name found in the admins table access setting
  *
  * @param MenuEntry $e
  * @return boolean
  */
 protected function authenticateMenuEntry(MenuEntry $e)
 {
     $p = $e->getAuthParameters();
     if (empty($p)) {
         return FALSE;
     }
     $admin = User::getSessionUser();
     if (!$admin) {
         return FALSE;
     }
     $tables = preg_split('/\\s*,\\s*/', trim($p));
     return !array_intersect($tables, $admin->getTableAccess());
 }
Ejemplo n.º 4
0
 /**
  * check whether authentication level required by route is met by user
  *
  * @param Route $route
  * @param User $user
  * @return boolean
  */
 private static function authenticateRoute(Route $route, User $user = NULL)
 {
     $auth = $route->getAuth();
     if (!is_null($auth)) {
         if (is_null($user) && !($user = User::getSessionUser())) {
             return FALSE;
         }
         if (!$user->isAuthenticated()) {
             return FALSE;
         }
         // UserAbstract::AUTH_OBSERVE_TABLE and UserAbstract::AUTH_OBSERVE_ROW are handled by controller
         return $auth >= $user->getPrivilegeLevel();
     }
     return TRUE;
 }