0011764: allow to create apps without controllers
authorPhilipp Schüle <p.schuele@metaways.de>
Mon, 27 Jun 2016 15:56:17 +0000 (17:56 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 27 Jun 2016 16:31:15 +0000 (18:31 +0200)
* skip initialize during installation if no Initialize class is found
* adds generic application controller that is used if no
 custom app controller is found

 https://forge.tine20.org/view.php?id=11764

Change-Id: I8a1a662137f73058d94d7f7b4beca06560e418ce
Reviewed-on: http://gerrit.tine20.com/customers/3281
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Setup/Controller.php
tine20/Setup/Initialize.php
tine20/Tinebase/Application/Controller.php [new file with mode: 0755]
tine20/Tinebase/Core.php

index 95fb44b..4a588e8 100644 (file)
@@ -447,7 +447,8 @@ class Setup_Controller
         $setupXML = $this->_baseDir . ucfirst($_applicationName) . '/Setup/setup.xml';
 
         if (!file_exists($setupXML)) {
-            throw new Setup_Exception_NotFound(ucfirst($_applicationName) . '/Setup/setup.xml not found. If application got renamed or deleted, re-run setup.php.');
+            throw new Setup_Exception_NotFound(ucfirst($_applicationName)
+                . '/Setup/setup.xml not found. If application got renamed or deleted, re-run setup.php.');
         }
         
         $xml = simplexml_load_file($setupXML);
@@ -1373,9 +1374,10 @@ class Setup_Controller
         
         // get xml and sort apps first
         $applications = array();
-        foreach($_applications as $applicationName) {
+        foreach ($_applications as $applicationName) {
             if ($this->isInstalled($applicationName)) {
-                if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " skipping installation of application {$applicationName} because it is already installed");
+                if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
+                    . " skipping installation of application {$applicationName} because it is already installed");
             } else {
                 $applications[$applicationName] = $this->getSetupXml($applicationName);
             }
index 41367f3..0fdda96 100644 (file)
@@ -37,11 +37,17 @@ class Setup_Initialize
     {
         $applicationName = $_application->name;
         $classname = "{$applicationName}_Setup_Initialize";
-        $instance = new $classname;
-        
-        Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Initializing application: ' . $applicationName);
-        
-        $instance->_initialize($_application, $_options);
+
+        if (class_exists($classname)) {
+            $instance = new $classname;
+
+            Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Initializing application: ' . $applicationName);
+
+            $instance->_initialize($_application, $_options);
+        } else {
+            Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Skipping init of application: '
+                . $applicationName . '. Class ' . $classname . ' not found.');
+        }
     }
     
     /**
diff --git a/tine20/Tinebase/Application/Controller.php b/tine20/Tinebase/Application/Controller.php
new file mode 100755 (executable)
index 0000000..77a2679
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+/**
+ * Tine 2.0
+ *
+ * @package     Tinebase
+ * @subpackage  Controller
+ * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
+ * @author      Philipp Schüle <p.schuele@metaways.de>
+ * @copyright   Copyright (c) 2007-2016 Metaways Infosystems GmbH (http://www.metaways.de)
+ * 
+ */
+
+/**
+ * generic controller for applications
+ *
+ * @package     Tinebase
+ * @subpackage  Controller
+ */
+class Tinebase_Application_Controller extends Tinebase_Controller_Abstract
+{
+    /**
+     * Tinebase_Controller_Abstract constructor.
+     *
+     * @param string $applicationName
+     */
+    public function __construct($applicationName)
+    {
+        $this->_applicationName = $applicationName;
+    }
+
+    /**
+     * Instance of Controller Object.
+     */
+    public static function getInstance()
+    {
+        throw new Tinebase_Exception('Use the constructor');
+    }
+}
index 0003915..ac27b2a 100644 (file)
@@ -386,7 +386,10 @@ class Tinebase_Core
                 $controllerName = $controllerNameModel;
             }
         } else if (! class_exists($controllerName)) {
-            throw new Tinebase_Exception_NotFound('No Application Controller found (checked class ' . $controllerName . ')!');
+            if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__
+                . ' Use generic application controller');
+
+            $controller = new Tinebase_Application_Controller($appName);
         }
         
         if (! $_ignoreACL && is_object(Tinebase_Core::getUser()) && ! Tinebase_Core::getUser()->hasRight($appName, Tinebase_Acl_Rights_Abstract::RUN)) {
@@ -394,12 +397,14 @@ class Tinebase_Core
                 . ' User ' . Tinebase_Core::getUser()->accountDisplayName . '/' . Tinebase_Core::getUser()->getId() . ' has no right to access ' . $appName);
             throw new Tinebase_Exception_AccessDenied('No right to access application ' . $appName);
         }
-        
-        if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ 
-            . ' Getting instance of ' . $controllerName);
-        
-        $controller = call_user_func(array($controllerName, 'getInstance'));
-        self::$appInstanceCache[$cacheKey] = $controller;
+
+        if (! isset($controller)) {
+            if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__
+                . ' Getting instance of ' . $controllerName);
+
+            $controller = call_user_func(array($controllerName, 'getInstance'));
+            self::$appInstanceCache[$cacheKey] = $controller;
+        }
         
         return $controller;
     }