openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 810d463f305d149165fb84287bc30e4b26022971
parent ace80dc82ca26d60eb8703a1efed0d0bb0f9e90f
Author: Jan Dankert <devnull@localhost>
Date:   Thu, 25 Oct 2012 21:48:11 +0200

Wenn ein Objekt nicht gefunden wird, eine ObjectNotFoundException werfen.

Diffstat:
action/Action.class.php | 19++++---------------
action/FileAction.class.php | 23++---------------------
action/FolderAction.class.php | 42++++--------------------------------------
action/GroupAction.class.php | 18++++--------------
action/GrouplistAction.class.php | 1-
action/LanguageAction.class.php | 7++-----
action/LinkAction.class.php | 12++----------
action/ModelAction.class.php | 7++-----
action/PageAction.class.php | 14+++-----------
action/ProjectAction.class.php | 9++-------
action/ProjectlistAction.class.php | 1-
action/TemplateAction.class.php | 13+++----------
action/UserAction.class.php | 14+++-----------
action/UserlistAction.class.php | 1-
dispatcher.php | 22++++++++++++++++++++--
model/Folder.class.php | 2+-
model/Object.class.php | 19++-----------------
model/Project.class.php | 3+++
18 files changed, 57 insertions(+), 170 deletions(-)

diff --git a/action/Action.class.php b/action/Action.class.php @@ -34,6 +34,8 @@ define('OR_FILTER_NUMBER' ,'123' ); define('OR_FILTER_RAW' ,'raw' ); define('OR_FILTER_ALL' ,'all' ); +class ObjectNotFoundException extends Exception {} + /** * Eltern-Klasse fuer alle Actions. * @@ -319,6 +321,8 @@ class Action $status = OR_NOTICE_ERROR; $this->templateVars['notice_status'] = $status; + $this->templateVars['status' ] = $status; + $this->templateVars['success' ] = ($status==OR_NOTICE_ERROR?'false':'true'); if ( $status == OR_NOTICE_OK && isset($_COOKIE['or_ignore_ok_notices'])) return; @@ -552,21 +556,6 @@ class Action /** - * Stellt klar, dass ein Administrator angemeldet sein muss. - */ - protected function requireAdmin() - { - if ( ! $this->userIsAdmin() ) - { - Logger::warn('User has no administration privileges'); - Http::notAuthorized( lang('SESSION_EXPIRED'),'administration privileges required' ); - $do->templateVars['error'] = 'administration privileges required'; - exit; - } - } - - - /** * Ermitteln des Benutzerobjektes aus der Session * @return User */ diff --git a/action/FileAction.class.php b/action/FileAction.class.php @@ -38,27 +38,8 @@ class FileAction extends ObjectAction */ function FileAction() { - if ( $this->getRequestId() != 0 ) - { - $this->file = new File( $this->getRequestId() ); - $this->file->load(); - Session::setObject( $this->file ); - } - else - { - $this->file = Session::getObject(); - } - - $folder = new Folder( $this->file->parentid ); - $folder->filenames = false; - $folder->load(); - $path = array(); - foreach( $folder->parentObjectNames(true,true) as $id=>$name ) - { - $path[] = array('key'=>'','name'=>$name,'title'=>$name,'url'=>Html::url('folder','show',$id),'type'=>'folder'); - } - $path[] = array('key'=>'','name'=>$this->file->name,'title'=>$this->file->description,'xurl'=>Html::url('file','show',$this->file->id),'type'=>'file'); - $this->setTemplateVar('path',$path); + $this->file = new File( $this->getRequestId() ); + $this->file->load(); } diff --git a/action/FolderAction.class.php b/action/FolderAction.class.php @@ -28,32 +28,13 @@ class FolderAction extends ObjectAction { public $security = SECURITY_USER; - var $defaultSubAction = 'show'; - var $folder; + private $folder; function FolderAction() { - if ( $this->getRequestId() != 0 ) - { - $this->folder = new Folder( $this->getRequestId() ); - $this->folder->load(); - Session::setObject( $this->folder ); - - $history = Session::get('history'); - if ( !is_array($history) ) - $history = array(); - unset($history[$this->getRequestId()]); - if ( count($history) > 20 ) - array_shift($history); - $history[ $this->getRequestId() ] = $this->getRequestId(); - Session::set('history',$history); - } - else - { - $this->folder = Session::getObject(); - } + $this->folder = new Folder( $this->getRequestId() ); + $this->folder->load(); - // Datum letzte Aenderung an Browser uebertragen //$this->lastModified( $this->folder->lastchangeDate ); } @@ -366,21 +347,6 @@ class FolderAction extends ObjectAction /** - * Abspeichern der Ordner-Eigenschaften. Ist der Schalter "delete" gesetzt, wird - * der Ordner stattdessen gel?scht. - */ - function delete() - { - if ( $this->getRequestVar('delete') != '' ) - { - // Ordner l?schen - $this->folder->delete(); - $this->addNotice($this->folder->getType(),$this->folder->name,lang('DELETED'),'ok'); - } - } - - - /** * Reihenfolge von Objekten aendern. */ function orderPost() @@ -928,7 +894,7 @@ class FolderAction extends ObjectAction * * @return Integer maximale Dateigroesse in Bytes */ - function maxFileSize() + private function maxFileSize() { global $conf; diff --git a/action/GroupAction.class.php b/action/GroupAction.class.php @@ -33,24 +33,14 @@ class GroupAction extends Action { public $security = SECURITY_ADMIN; - var $group; - var $defaultSubAction = 'edit'; + private $group; function GroupAction() { - if ( !$this->userIsAdmin() ) - die('you are not an admin'); - - if ( $this->getRequestId() != 0 ) - { - $this->group = new Group( $this->getRequestId() ); - $this->group->load(); - $this->setTemplateVar( 'groupid',$this->group->groupid ); - } - - - $this->requireAdmin(); + $this->group = new Group( $this->getRequestId() ); + $this->group->load(); + $this->setTemplateVar( 'groupid',$this->group->groupid ); } diff --git a/action/GrouplistAction.class.php b/action/GrouplistAction.class.php @@ -35,7 +35,6 @@ class GrouplistAction extends Action function GrouplistAction() { - $this->requireAdmin(); } diff --git a/action/LanguageAction.class.php b/action/LanguageAction.class.php @@ -81,11 +81,8 @@ class LanguageAction extends Action */ function LanguageAction() { - if ( $this->getRequestId() != 0 ) - { - $this->language = new Language( $this->getRequestId() ); - $this->language->load(); - } + $this->language = new Language( $this->getRequestId() ); + $this->language->load(); $this->project = Session::getProject(); } diff --git a/action/LinkAction.class.php b/action/LinkAction.class.php @@ -71,16 +71,8 @@ class LinkAction extends ObjectAction */ function LinkAction() { - if ( $this->getRequestId() != 0 ) - { - $this->link = new Link( $this->getRequestId() ); - $this->link->load(); - Session::setObject( $this->link ); - } - else - { - $this->link = Session::getObject(); - } + $this->link = new Link( $this->getRequestId() ); + $this->link->load(); } diff --git a/action/ModelAction.class.php b/action/ModelAction.class.php @@ -69,11 +69,8 @@ class ModelAction extends Action function ModelAction() { - if ( $this->getRequestId() != 0 ) - { - $this->model = new Model( $this->getRequestId() ); - $this->model->load(); - } + $this->model = new Model( $this->getRequestId() ); + $this->model->load(); $this->project = Session::getProject(); } diff --git a/action/PageAction.class.php b/action/PageAction.class.php @@ -37,22 +37,14 @@ class PageAction extends ObjectAction function PageAction() { - if ( $this->getRequestId() != 0 ) - { - $this->page = new Page( $this->getRequestId() ); - $this->page->load(); - Session::setObject( $this->page ); - } - else - { - $this->page = Session::getObject(); - } + $this->page = new Page( $this->getRequestId() ); + $this->page->load(); // Hier kann leider nicht das Datum der letzten Änderung verwendet werden, // da sich die Seite auch danach ändern kann, z.B. durch Includes anderer // Seiten oder Änderung einer Vorlage oder Änderung des Dateinamens einer // verlinkten Datei. - $this->lastModified( time() ); + //$this->lastModified( time() ); } diff --git a/action/ProjectAction.class.php b/action/ProjectAction.class.php @@ -33,13 +33,8 @@ class ProjectAction extends Action function ProjectAction() { - if ( $this->getRequestId()!=0 ) - { - $this->project = new Project( $this->getRequestId() ); - $this->project->load(); - } - - $this->requireAdmin(); + $this->project = new Project( $this->getRequestId() ); + $this->project->load(); } diff --git a/action/ProjectlistAction.class.php b/action/ProjectlistAction.class.php @@ -29,7 +29,6 @@ class ProjectlistAction extends Action function ProjectlistAction() { - $this->requireAdmin(); } diff --git a/action/TemplateAction.class.php b/action/TemplateAction.class.php @@ -34,16 +34,9 @@ class TemplateAction extends Action function TemplateAction() { - if ( $this->getRequestId() != 0 ) - { - $this->template = new Template( $this->getRequestId() ); - $this->template->load(); - $this->setTemplateVar( 'templateid',$this->template->templateid ); - } - else - { - $this->defaultSubAction = 'listing'; - } + $this->template = new Template( $this->getRequestId() ); + $this->template->load(); + $this->setTemplateVar( 'templateid',$this->template->templateid ); if ( intval($this->getRequestVar('elementid')) != 0 ) { diff --git a/action/UserAction.class.php b/action/UserAction.class.php @@ -36,17 +36,9 @@ class UserAction extends Action function UserAction() { - if ( !$this->userIsAdmin() ) - die('you are not an admin'); - - if ( $this->getRequestId() != 0 ) - { - $this->user = new User( $this->getRequestId() ); - $this->user->load(); - $this->setTemplateVar('userid',$this->user->userid); - } - - $this->requireAdmin(); + $this->user = new User( $this->getRequestId() ); + $this->user->load(); + $this->setTemplateVar('userid',$this->user->userid); } diff --git a/action/UserlistAction.class.php b/action/UserlistAction.class.php @@ -32,7 +32,6 @@ class UserlistAction extends Action function UserlistAction() { - $this->requireAdmin(); } diff --git a/dispatcher.php b/dispatcher.php @@ -165,7 +165,18 @@ $actionClassName = ucfirst($action).'Action'; require_once( OR_ACTIONCLASSES_DIR.'/'.$actionClassName.'.class.php' ); // Erzeugen der Action-Klasse -$do = new $actionClassName; +try +{ + $do = new $actionClassName; +} +catch( ObjectNotFoundException $e ) +{ + Http::sendStatus(404,"Object not found","The requested object was not found." ); +} +catch( Exception $e ) +{ + Http::serverError($e->getMessage(),$e->getTraceAsString() ); +} $do->actionClassName = $actionClassName; $do->actionName = $action; @@ -216,7 +227,14 @@ if ( ! method_exists($do,$subactionMethodName) ) Http::sendStatus(404,"Method not found","Method '".$subactionMethodName."' does not exist in this context" ); // Jetzt wird die Aktion aus der Actionklasse aufgerufen. -$do->$subactionMethodName(); +try +{ + $do->$subactionMethodName(); +} +catch( ObjectNotFoundException $e ) +{ + Http::sendStatus(404,"Object not found","The requested object was not found." ); +} $do->forward(); diff --git a/model/Folder.class.php b/model/Folder.class.php @@ -107,7 +107,7 @@ class Folder extends Object } - function load() + public function load() { // $db = db_connection(); // diff --git a/model/Object.class.php b/model/Object.class.php @@ -493,24 +493,9 @@ SQL $row = $db->getRow($sql); if (count($row) == 0) - { - $project = Session::getProject(); + throw new ObjectNotFoundException('object '.$this->objectid.' not found'); - $this->name = lang('unknown'); - $this->parentid = $project->getRootObjectId(); - $this->projectid = $project->projectid; - $this->filename = ""; - $this->orderid = 0; - $this->isRoot = false; - $this->createDate = 0; - $this->lastchangeDate = 0; - $this->createUser = new User(); - $this->lastchangeUser = new User(); - } - else - $this->setDatabaseRow( $row ); - - + $this->setDatabaseRow( $row ); } diff --git a/model/Project.class.php b/model/Project.class.php @@ -187,6 +187,9 @@ class Project $row = $db->getRow( $sql ); + if ( empty($row) ) + throw new ObjectNotFoundException('project '.$this->projectid.' not found'); + $this->name = $row['name' ]; $this->target_dir = $row['target_dir' ]; $this->ftp_url = $row['ftp_url' ];