Separating checkModules() and checkPermissions() in AbstractAction
authorDaniel Rudolf <rudolf@eifel-online.com>
Wed, 30 Jan 2013 18:10:02 +0000 (19:10 +0100)
committerDaniel Rudolf <rudolf@eifel-online.com>
Wed, 30 Jan 2013 18:10:02 +0000 (19:10 +0100)
Actually nothing was changed, just separating the code into own methods to make them overridable, just like in AbstractPage.

wcfsetup/install/files/lib/action/AbstractAction.class.php
wcfsetup/install/files/lib/action/IAction.class.php

index fc25fc30314317a6d6eab82b6f1696ac115b1958..db400b154129179004842c666594536527052499 100644 (file)
@@ -58,25 +58,47 @@ abstract class AbstractAction implements IAction {
        }
        
        /**
-        * @see wcf\action\IAction::execute()
+        * @see wcf\action\IAction::checkModules()
         */
-       public function execute() {
-               // check if active user is logged in
-               if ($this->loginRequired && !WCF::getUser()->userID) {
-                       throw new PermissionDeniedException();
-               }
+       public function checkModules() {
+               // call checkModules event
+               EventHandler::getInstance()->fireAction($this, 'checkModules');
                
                // check modules
-               if (!empty($this->neededModules)) {
-                       foreach ($this->neededModules as $module) {
-                               if (!defined($module) || !constant($module)) throw new IllegalLinkException();
+               foreach ($this->neededModules as $module) {
+                       if (!defined($module) || !constant($module)) {
+                               throw new IllegalLinkException();
                        }
                }
+       }
+       
+       /**
+        * @see wcf\action\IAction::checkPermissions()
+        */
+       public function checkPermissions() {
+               // call checkPermissions event
+               EventHandler::getInstance()->fireAction($this, 'checkPermissions');
                
                // check permission
                if (!empty($this->neededPermissions)) {
                        WCF::getSession()->checkPermissions($this->neededPermissions);
                }
+       }
+       
+       /**
+        * @see wcf\action\IAction::execute()
+        */
+       public function execute() {
+               // check if active user is logged in
+               if ($this->loginRequired && !WCF::getUser()->userID) {
+                       throw new PermissionDeniedException();
+               }
+               
+               // check modules
+               $this->checkModules();
+               
+               // check permissions
+               $this->checkPermissions();
                
                // call execute event
                EventHandler::getInstance()->fireAction($this, 'execute');
index b3b2b57c029fb9a72a7e4f49ddb7ae3f2698a21b..4d6e9aa1d30693cac749acd0ab00fe5ca21a3453 100644 (file)
@@ -23,6 +23,16 @@ interface IAction {
         */
        public function readParameters();
        
+       /**
+        * Checks the modules of this action.
+        */
+       public function checkModules();
+       
+       /**
+        * Checks the permissions of this action.
+        */
+       public function checkPermissions();
+       
        /**
         * Executes this action.
         */