make sure owner_id column is added
authorPhilipp Schüle <p.schuele@metaways.de>
Mon, 29 May 2017 07:40:15 +0000 (09:40 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 31 May 2017 10:12:11 +0000 (12:12 +0200)
... somehow the owner_id update script could
 be skipped in certain situations

Change-Id: Ib46086a1c1af4b2449e85f669cb3ab742086e0be
Reviewed-on: http://gerrit.tine20.com/customers/4767
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Tinebase/Setup/Update/Release9.php
tine20/Tinebase/Setup/setup.xml

index 0279650..01c434b 100644 (file)
@@ -5,7 +5,7 @@
  * @package     Tinebase
  * @subpackage  Setup
  * @license     http://www.gnu.org/licenses/agpl.html AGPL3
- * @copyright   Copyright (c) 2015 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2015-2017 Metaways Infosystems GmbH (http://www.metaways.de)
  * @author      Philipp Schüle <p.schuele@metaways.de>
  */
 class Tinebase_Setup_Update_Release9 extends Setup_Update_Abstract
@@ -65,33 +65,39 @@ class Tinebase_Setup_Update_Release9 extends Setup_Update_Abstract
      */
     public function update_4()
     {
-        if ($this->getTableVersion('container') < 10) {
-            $declaration = new Setup_Backend_Schema_Field_Xml(
+        $this->_addOwnerIdColumn();
+        $this->setTableVersion('container', 10);
+        $this->setApplicationVersion('Tinebase', '9.5');
+    }
+
+    protected function _addOwnerIdColumn()
+    {
+        if ($this->_backend->columnExists('owner_id', 'container')) {
+            return;
+        }
+
+        $declaration = new Setup_Backend_Schema_Field_Xml(
             '<field>
-                <name>owner_id</name>
-                <type>text</type>
-                <length>40</length>
-                <notnull>false</notnull>
-            </field>
-            ');
-            $this->_backend->addCol('container', $declaration);
+            <name>owner_id</name>
+            <type>text</type>
+            <length>40</length>
+            <notnull>false</notnull>
+        </field>
+        ');
+        $this->_backend->addCol('container', $declaration);
 
-            $declaration = new Setup_Backend_Schema_Index_Xml('
-                <index>
+        $declaration = new Setup_Backend_Schema_Index_Xml('
+            <index>
+                <name>owner_id</name>
+                <field>
                     <name>owner_id</name>
-                    <field>
-                        <name>owner_id</name>
-                    </field>
-                </index>
-            ');
+                </field>
+            </index>
+        ');
 
-            $this->_backend->addIndex('container', $declaration);
-            $this->setTableVersion('container', 10);
-        }
+        $this->_backend->addIndex('container', $declaration);
 
         Tinebase_Container::getInstance()->setContainerOwners();
-
-        $this->setApplicationVersion('Tinebase', '9.5');
     }
 
     /**
@@ -291,4 +297,15 @@ class Tinebase_Setup_Update_Release9 extends Setup_Update_Abstract
         $this->setTableVersion('import', '2');
         $this->setApplicationVersion('Tinebase', '9.10');
     }
+
+    /**
+     * update to 9.11
+     *
+     * adds owner_id column if still missing
+     */
+    public function update_10()
+    {
+        $this->_addOwnerIdColumn();
+        $this->setApplicationVersion('Tinebase', '9.11');
+    }
 }
index 80cd9f8..8624e73 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <application>
     <name>Tinebase</name>
-    <version>9.10</version>
+    <version>9.11</version>
     <tables>
         <table>
             <name>applications</name>