0011974: uninitialize framework
authorPaul Mehrer <p.mehrer@metaways.de>
Thu, 19 May 2016 15:11:48 +0000 (17:11 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 28 Jun 2016 12:39:30 +0000 (14:39 +0200)
and added concrete implementation for Sales to
remove the scheduler job on uninstallation

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

Change-Id: I23dc4299c66c78e1e538141b8032469760aa29cc
Reviewed-on: http://gerrit.tine20.com/customers/3204
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Sales/Frontend/Cli.php
tine20/Sales/Scheduler/Task.php
tine20/Sales/Setup/Uninitialize.php [new file with mode: 0644]
tine20/Setup/Controller.php
tine20/Setup/Initialize.php
tine20/Setup/Uninitialize.php [new file with mode: 0644]
tine20/Tinebase/Application.php
tine20/Tinebase/Model/ApplicationFilter.php
tine20/Tinebase/Scheduler/Task.php

index 7b497d0..9c85c2c 100644 (file)
@@ -46,6 +46,11 @@ class Sales_Frontend_Cli extends Tinebase_Frontend_Cli_Abstract
      */
     public function create_auto_invoices($_opts)
     {
+        if (!Sales_Config::getInstance()->featureEnabled(Sales_Config::FEATURE_INVOICES_MODULE)) {
+            Tinebase_Core::getLogger()->crit(__METHOD__ . '::' . __LINE__ . ' create_auto_invoices ran allthoug feature ' . Sales_Config::FEATURE_INVOICES_MODULE . ' is disabled');
+            return false;
+        }
+
         $executionLifeTime = Tinebase_Core::setExecutionLifeTime(3600*8);
         
         $this->_addOutputLogWriter();
@@ -141,6 +146,11 @@ class Sales_Frontend_Cli extends Tinebase_Frontend_Cli_Abstract
      */
     public function transferContractsToOrderConfirmation()
     {
+        if (!Sales_Config::getInstance()->featureEnabled(Sales_Config::FEATURE_ORDERCONFIRMATIONS_MODULE)) {
+            Tinebase_Core::getLogger()->crit(__METHOD__ . '::' . __LINE__ . ' transferContractsToOrderConfirmation ran allthoug feature ' . Sales_Config::FEATURE_ORDERCONFIRMATIONS_MODULE . ' is disabled');
+            return false;
+        }
+
         $contractController = Sales_Controller_Contract::getInstance();
         $ocController = Sales_Controller_OrderConfirmation::getInstance();
         $rel = Tinebase_Relations::getInstance();
@@ -234,6 +244,11 @@ class Sales_Frontend_Cli extends Tinebase_Frontend_Cli_Abstract
     
     public function setLastAutobill()
     {
+        if (!Sales_Config::getInstance()->featureEnabled(Sales_Config::FEATURE_INVOICES_MODULE)) {
+            Tinebase_Core::getLogger()->crit(__METHOD__ . '::' . __LINE__ . ' setLastAutobill ran allthoug feature ' . Sales_Config::FEATURE_INVOICES_MODULE . ' is disabled');
+            return false;
+        }
+
         $cc = Sales_Controller_Contract::getInstance();
         $pc = Sales_Controller_ProductAggregate::getInstance();
         
@@ -277,6 +292,11 @@ class Sales_Frontend_Cli extends Tinebase_Frontend_Cli_Abstract
      */
     public function removeUnbilledAutoInvoices(Sales_Model_Contract $contract = NULL)
     {
+        if (!Sales_Config::getInstance()->featureEnabled(Sales_Config::FEATURE_INVOICES_MODULE)) {
+            Tinebase_Core::getLogger()->crit(__METHOD__ . '::' . __LINE__ . ' removeUnbilledAutoInvoices ran allthoug feature ' . Sales_Config::FEATURE_INVOICES_MODULE . ' is disabled');
+            return false;
+        }
+
         $c = Sales_Controller_Invoice::getInstance();
         
         $f = new Sales_Model_InvoiceFilter(array(
@@ -319,6 +339,11 @@ class Sales_Frontend_Cli extends Tinebase_Frontend_Cli_Abstract
      */
     public function transferBillingInformation()
     {
+        if (!Sales_Config::getInstance()->featureEnabled(Sales_Config::FEATURE_INVOICES_MODULE)) {
+            Tinebase_Core::getLogger()->crit(__METHOD__ . '::' . __LINE__ . ' transferBillingInformation ran allthoug feature ' . Sales_Config::FEATURE_INVOICES_MODULE . ' is disabled');
+            return false;
+        }
+
         Sales_Controller_Contract::getInstance()->transferBillingInformation();
     }
     
@@ -327,6 +352,11 @@ class Sales_Frontend_Cli extends Tinebase_Frontend_Cli_Abstract
      */
     public function updateBillingInformation()
     {
+        if (!Sales_Config::getInstance()->featureEnabled(Sales_Config::FEATURE_INVOICES_MODULE)) {
+            Tinebase_Core::getLogger()->crit(__METHOD__ . '::' . __LINE__ . ' updateBillingInformation ran allthoug feature ' . Sales_Config::FEATURE_INVOICES_MODULE . ' is disabled');
+            return false;
+        }
+
         Sales_Controller_Contract::getInstance()->transferBillingInformation(TRUE);
     }
     
@@ -335,6 +365,11 @@ class Sales_Frontend_Cli extends Tinebase_Frontend_Cli_Abstract
      */
     public function updateLastAutobillOfProductAggregates()
     {
+        if (!Sales_Config::getInstance()->featureEnabled(Sales_Config::FEATURE_INVOICES_MODULE)) {
+            Tinebase_Core::getLogger()->crit(__METHOD__ . '::' . __LINE__ . ' updateLastAutobillOfProductAggregates ran allthoug feature ' . Sales_Config::FEATURE_INVOICES_MODULE . ' is disabled');
+            return false;
+        }
+
         Sales_Controller_Contract::getInstance()->updateLastAutobillOfProductAggregates();
     }
 }
\ No newline at end of file
index 48031f7..55d6f0f 100644 (file)
@@ -34,4 +34,18 @@ class Sales_Scheduler_Task extends Tinebase_Scheduler_Task
         if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__
             . ' Saved task Sales_Controller_Product::updateProductLifespan in scheduler.');
     }
+
+    /**
+     * remove update product lifespan task from scheduler
+     *
+     * @param Zend_Scheduler $_scheduler
+     */
+    public static function removeUpdateProductLifespanTask(Zend_Scheduler $_scheduler)
+    {
+        $_scheduler->removeTask('Sales_Controller_Product::updateProductLifespan');
+        $_scheduler->saveTask();
+
+        if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__
+            . ' Removed task Sales_Controller_Product::updateProductLifespan from scheduler.');
+    }
 }
diff --git a/tine20/Sales/Setup/Uninitialize.php b/tine20/Sales/Setup/Uninitialize.php
new file mode 100644 (file)
index 0000000..e4713f9
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+/**
+ * Tine 2.0
+ *
+ * @package     Sales
+ * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
+ * @author      Paul Mehrer <p.mehrer@metaways.de>
+ * @copyright   Copyright (c) 2016 Metaways Infosystems GmbH (http://www.metaways.de)
+ *
+ */
+
+/**
+ * class for Tinebase initialization
+ *
+ * @package     Sales
+ */
+class Sales_Setup_Uninitialize extends Setup_Uninitialize
+{
+    /**
+     * uninit scheduler tasks
+     */
+    protected function _uninitializeSchedulerTasks()
+    {
+        $scheduler = Tinebase_Core::getScheduler();
+        Sales_Scheduler_Task::removeUpdateProductLifespanTask($scheduler);
+    }
+}
\ No newline at end of file
index 4a588e8..1173bf6 100644 (file)
@@ -1656,6 +1656,8 @@ class Setup_Controller
             Tinebase_Application::getInstance()->deleteApplication($_application);
         }
 
+        Setup_Uninitialize::uninitialize($_application);
+
         Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " Removed app: " . $_application->name);
     }
 
index 0fdda96..0b38d60 100644 (file)
@@ -80,7 +80,7 @@ class Setup_Initialize
         $methods = $reflectionClass->getMethods();
         foreach ($methods as $method) {
             $methodName = $method->name;
-            if (preg_match('/^_initialize.+/', $methodName)) {
+            if (strpos($methodName, '_initialize') === 0 && $methodName !== '_initialize') {
                 Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Calling init function ' . get_class($this) . '::' . $methodName);
                 
                 $this->$methodName($_application, $_options);
diff --git a/tine20/Setup/Uninitialize.php b/tine20/Setup/Uninitialize.php
new file mode 100644 (file)
index 0000000..30942c0
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+/**
+ * Tine 2.0
+ *
+ * @package     Setup
+ * @subpackage  Uninitialize
+ * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
+ * @author      Paul Mehrer <p.mehrer@metaways.de>
+ * @copyright   Copyright (c) 2016 Metaways Infosystems GmbH (http://www.metaways.de)
+ */
+
+/**
+ * Class to handle application uninitialization
+ *
+ * @package     Setup
+ * @subpackage  Uninitialize
+ */
+class Setup_Uninitialize
+{
+    /**
+     * Call {@see _uninitialize} on an instance of the concrete Setup_Uninitialize class for the given {@param $_application}
+     *
+     * @param Tinebase_Model_Application $_application
+     * @param array | optional $_options
+     * @return void
+     */
+    public static function uninitialize(Tinebase_Model_Application $_application, $_options = null)
+    {
+        $applicationName = $_application->name;
+        $classname = "{$applicationName}_Setup_Uninitialize";
+        if (true !== class_exists($classname)) {
+            return;
+        }
+        $instance = new $classname;
+
+        Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Initializing application: ' . $applicationName);
+
+        $instance->_uninitialize($_application, $_options);
+    }
+
+    /**
+     * uninitialize application
+     *
+     * @param Tinebase_Model_Application $_application
+     * @param array | optional $_options
+     * @return void
+     */
+    protected function _uninitialize(Tinebase_Model_Application $_application, $_options = null)
+    {
+        $reflectionClass = new ReflectionClass($this);
+        $methods = $reflectionClass->getMethods();
+        foreach ($methods as $method) {
+            $methodName = $method->name;
+            if (strpos($methodName, '_uninitialize') === 0 && $methodName !== '_uninitialize') {
+                Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Calling uninit function ' . get_class($this) . '::' . $methodName);
+
+                $this->$methodName($_application, $_options);
+            }
+        }
+    }
+}
\ No newline at end of file
index 11261a3..92e0799 100644 (file)
@@ -99,7 +99,7 @@ class Tinebase_Application
     public function getApplicationById($_applicationId)
     {
         $applicationId = Tinebase_Model_Application::convertApplicationIdToInt($_applicationId);
-        
+
         $application = $this->getApplications()->getById($applicationId);
         
         if (!$application) {
@@ -124,7 +124,7 @@ class Tinebase_Application
         if(empty($_applicationName) || ! is_string($_applicationName)) {
             throw new Tinebase_Exception_InvalidArgument('$_applicationName can not be empty / has to be string.');
         }
-        
+
         $application = $this->getApplications()->find('name', $_applicationName);
         
         if (!$application) {
index f7b9eae..6db8667 100644 (file)
@@ -39,6 +39,7 @@ class Tinebase_Model_ApplicationFilter extends Tinebase_Model_Filter_FilterGroup
      * @var array filter model fieldName => definition
      */
     protected $_filterModel = array(
+        'id'    => array('filter' => 'Tinebase_Model_Filter_Id'),
         'query' => array('filter' => 'Tinebase_Model_Filter_Query', 'options' => array('fields' => array('name'))),
         'name'  => array('filter' => 'Tinebase_Model_Filter_Text')
     );
index 1782346..e44e444 100644 (file)
@@ -272,7 +272,16 @@ class Tinebase_Scheduler_Task extends Zend_Scheduler_Task
                 . ' Running request: ' . $request->getControllerName() . '::' . $request->getActionName());
             
             try {
-                $controller = Tinebase_Controller_Abstract::getController($request->getControllerName());
+                $controllerName = $request->getControllerName();
+                list($appName) = explode('_', $controllerName);
+
+                if (true !== Tinebase_Application::getInstance()->isInstalled($appName)) {
+                    if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__
+                        . ' Application ' . $appName . ' is not installed for scheduler job');
+                    return false;
+                }
+
+                $controller = Tinebase_Controller_Abstract::getController($controllerName);
             } catch (Exception $e) {
                 if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ 
                     . ' Could not get controller for scheduler job: ' . $e->getMessage());