0011410: remove relations + modlog if app is uninstalled
authorPaul Mehrer <p.mehrer@metaways.de>
Thu, 22 Oct 2015 12:48:00 +0000 (14:48 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 28 Oct 2015 13:10:57 +0000 (14:10 +0100)
added Tinebase_Relations::removeAppliction
added Tinebase_Timemachine_ModificationLog::removeApplication

used both methods in Setup_Controller::_uninstallApplication

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

Change-Id: Ie6f9644173b83925b8800c2781adb5f908ae37f8
Reviewed-on: http://gerrit.tine20.com/customers/2304
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Setup/Controller.php
tine20/Tinebase/Relation/Backend/Sql.php
tine20/Tinebase/Relations.php
tine20/Tinebase/Timemachine/ModificationLog.php

index cbf0d2d..a44f0dd 100644 (file)
@@ -1412,7 +1412,7 @@ class Setup_Controller
             $this->_backend->setForeignKeyChecks(0);
             foreach ($installedApps as $app) {
                 if ($app->name != 'Tinebase') {
-                    $this->_uninstallApplication($app);
+                    $this->_uninstallApplication($app, true);
                 } else {
                     $tinebase = $app;
                 }
@@ -1536,7 +1536,7 @@ class Setup_Controller
      * @param Tinebase_Model_Application $_application
      * @throws Setup_Exception
      */
-    protected function _uninstallApplication(Tinebase_Model_Application $_application)
+    protected function _uninstallApplication(Tinebase_Model_Application $_application, $uninstallAll = false)
     {
         if ($this->_backend === null) {
             throw new Setup_Exception('No setup backend available');
@@ -1617,12 +1617,19 @@ class Setup_Controller
         }
         
         if ($_application->name != 'Tinebase') {
-            // delete containers, config options and other data for app
-            Tinebase_Application::getInstance()->removeApplicationData($_application);
+            if (!$uninstallAll) {
+                Tinebase_Relations::getInstance()->removeApplication($_application->name);
+
+                Tinebase_Timemachine_ModificationLog::getInstance()->removeApplication($_application);
+
+                // delete containers, config options and other data for app
+                Tinebase_Application::getInstance()->removeApplicationData($_application);
+            }
             
             // remove application from table of installed applications
             Tinebase_Application::getInstance()->deleteApplication($_application);
         }
+
         Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " Removed app: " . $_application->name);
     }
 
index 592010e..d95bd11 100644 (file)
@@ -473,4 +473,25 @@ class Tinebase_Relation_Backend_Sql extends Tinebase_Backend_Sql_Abstract
     
         return $result;
     }
+
+    /**
+     * remove all relations for application
+     *
+     * @param string $applicationName
+     *
+     * @return void
+     */
+    public function removeApplication($applicationName)
+    {
+        $tableName = $this->_db->quoteIdentifier(SQL_TABLE_PREFIX . 'relations');
+
+        $select = $this->_db->select()->from($tableName)->columns('rel_id')
+            ->where($this->_db->quoteIdentifier('own_model') . ' LIKE ?', $applicationName . '_%');
+
+        $relation_ids = $this->_db->fetchCol($select);
+
+        if (is_array($relation_ids) && count($relation_ids) > 0) {
+            $this->_db->delete($tableName, $this->_db->quoteInto($this->_db->quoteIdentifier('rel_id') . ' IN (?)', $relation_ids));
+        }
+    }
 }
index 403760f..f88604d 100644 (file)
@@ -612,4 +612,16 @@ class Tinebase_Relations
         
         return $this->_backend->transferRelations($sourceId, $destinationId, $model);
     }
+
+    /**
+     * remove all relations for application
+     *
+     * @param string $applicationName
+     *
+     * @return void
+     */
+    public function removeApplication($applicationName)
+    {
+        $this->_backend->removeApplication($applicationName);
+    }
 }
index adece39..92ef101 100644 (file)
@@ -869,4 +869,16 @@ class Tinebase_Timemachine_ModificationLog
 
         return array($currentAccountId, $currentTime);
     }
+
+    /**
+     * removes modlog entries for that application
+     *
+     * @param Tinebase_Model_Application $applicationName
+     *
+     * @return void
+     */
+    public function removeApplication(Tinebase_Model_Application $_application)
+    {
+        $this->_backend->deleteByProperty($_application->getId(), 'application_id');
+    }
 }