0012824: install from dump sets master replication id
authorPaul Mehrer <p.mehrer@metaways.de>
Fri, 17 Mar 2017 15:20:25 +0000 (16:20 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 21 Mar 2017 14:49:12 +0000 (15:49 +0100)
https://forge.tine20.org/view.php?id=12824

Change-Id: I420bd714eedc4b5611c687dc6f202396ac4d8fd5
Reviewed-on: http://gerrit.tine20.com/customers/4384
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/setup/Setup/ControllerTest.php
tests/setup/Setup/JsonTest.php
tests/setup/files/2017-02-27-11-42-25/tine20_files.tar.bz2 [deleted file]
tests/setup/files/2017-02-27-11-42-25/tine20_mysql.sql.bz2
tests/tine20/Tinebase/Timemachine/ModificationLogTest.php
tine20/Setup/Controller.php
tine20/Tinebase/Core.php
tine20/Tinebase/Group.php
tine20/Tinebase/Group/Abstract.php
tine20/Tinebase/Timemachine/ModificationLog.php

index 8115e39..c2b9f40 100644 (file)
@@ -279,7 +279,6 @@ class Setup_ControllerTest extends PHPUnit_Framework_TestCase
         $options = array(
             'backupDir' => dirname(__DIR__) . '/files/2017-02-27-11-42-25',
             'db' => 1,
         $options = array(
             'backupDir' => dirname(__DIR__) . '/files/2017-02-27-11-42-25',
             'db' => 1,
-            'files' => 1,
         );
         $result = $this->_uit->getInstance()->installFromDump($options);
         $this->assertTrue($result);
         );
         $result = $this->_uit->getInstance()->installFromDump($options);
         $this->assertTrue($result);
@@ -323,6 +322,8 @@ class Setup_ControllerTest extends PHPUnit_Framework_TestCase
     {
         $installedApplications = Tinebase_Application::getInstance()->getApplications(NULL, 'id');
         $this->_uit->uninstallApplications($installedApplications->name);
     {
         $installedApplications = Tinebase_Application::getInstance()->getApplications(NULL, 'id');
         $this->_uit->uninstallApplications($installedApplications->name);
+        Tinebase_Core::unsetTinebaseId();
+        Tinebase_Group::unsetInstance();
     }
     
     /**
     }
     
     /**
@@ -336,7 +337,10 @@ class Setup_ControllerTest extends PHPUnit_Framework_TestCase
         if (! $this->_uit) {
             throw new Setup_Exception('could not run test, Setup_Controller init failed');
         }
         if (! $this->_uit) {
             throw new Setup_Exception('could not run test, Setup_Controller init failed');
         }
-        
+
+        Tinebase_Core::unsetTinebaseId();
+        Tinebase_Group::unsetInstance();
+        Tinebase_Cache_PerRequest::getInstance()->reset();
         $installableApplications = $this->_uit->getInstallableApplications();
         $installableApplications = array_keys($installableApplications);
         $this->_uit->installApplications($installableApplications, $_options);
         $installableApplications = $this->_uit->getInstallableApplications();
         $installableApplications = array_keys($installableApplications);
         $this->_uit->installApplications($installableApplications, $_options);
index 9b9e50f..9679673 100644 (file)
@@ -295,6 +295,10 @@ class Setup_JsonTest extends PHPUnit_Framework_TestCase
         $installedApplications = $installedApplications->name;
 
         $this->_json->uninstallApplications($installedApplications);
         $installedApplications = $installedApplications->name;
 
         $this->_json->uninstallApplications($installedApplications);
+
+        Tinebase_Core::unsetTinebaseId();
+        Tinebase_Group::unsetInstance();
+        Tinebase_Cache_PerRequest::getInstance()->reset();
     }
     
     /**
     }
     
     /**
@@ -302,6 +306,10 @@ class Setup_JsonTest extends PHPUnit_Framework_TestCase
      */
     protected function _installAllApps()
     {
      */
     protected function _installAllApps()
     {
+        Tinebase_Core::unsetTinebaseId();
+        Tinebase_Group::unsetInstance();
+        Tinebase_Cache_PerRequest::getInstance()->reset();
+
         $installableApplications = Setup_Controller::getInstance()->getInstallableApplications();
         $installableApplications = array_keys($installableApplications);
         $testCredentials = Setup_TestServer::getInstance()->getTestCredentials();
         $installableApplications = Setup_Controller::getInstance()->getInstallableApplications();
         $installableApplications = array_keys($installableApplications);
         $testCredentials = Setup_TestServer::getInstance()->getTestCredentials();
diff --git a/tests/setup/files/2017-02-27-11-42-25/tine20_files.tar.bz2 b/tests/setup/files/2017-02-27-11-42-25/tine20_files.tar.bz2
deleted file mode 100644 (file)
index fd97d1c..0000000
Binary files a/tests/setup/files/2017-02-27-11-42-25/tine20_files.tar.bz2 and /dev/null differ
index 58f98cc..5c33de0 100644 (file)
Binary files a/tests/setup/files/2017-02-27-11-42-25/tine20_mysql.sql.bz2 and b/tests/setup/files/2017-02-27-11-42-25/tine20_mysql.sql.bz2 differ
index 2d0d404..07a8d52 100644 (file)
@@ -351,12 +351,7 @@ class Tinebase_Timemachine_ModificationLogTest extends PHPUnit_Framework_TestCas
 
     public function testGetReplicationModificationsByInstanceSeq()
     {
 
     public function testGetReplicationModificationsByInstanceSeq()
     {
-        $modifications = Tinebase_Timemachine_ModificationLog::getInstance()->getReplicationModificationsByInstanceSeq(-1, 10000);
-        if ($modifications->count() > 0) {
-            $instance_seq = $modifications->getLastRecord()->instance_seq;
-        } else {
-            $instance_seq = -1;
-        }
+        $instance_seq = Tinebase_Timemachine_ModificationLog::getInstance()->getMaxInstanceSeq();
 
         /** @var Tinebase_Acl_Roles $roleController */
         $roleController = Tinebase_Core::getApplicationInstance('Tinebase_Model_Role');
 
         /** @var Tinebase_Acl_Roles $roleController */
         $roleController = Tinebase_Core::getApplicationInstance('Tinebase_Model_Role');
@@ -432,12 +427,7 @@ class Tinebase_Timemachine_ModificationLogTest extends PHPUnit_Framework_TestCas
 
     public function testGroupReplication()
     {
 
     public function testGroupReplication()
     {
-        $modifications = Tinebase_Timemachine_ModificationLog::getInstance()->getReplicationModificationsByInstanceSeq(-1, 10000);
-        if ($modifications->count() > 0) {
-            $instance_seq = $modifications->getLastRecord()->instance_seq;
-        } else {
-            $instance_seq = -1;
-        }
+        $instance_seq = Tinebase_Timemachine_ModificationLog::getInstance()->getMaxInstanceSeq();
 
         $groupController = Tinebase_Group::getInstance();
 
 
         $groupController = Tinebase_Group::getInstance();
 
index 7e6895c..7377247 100644 (file)
@@ -1443,6 +1443,17 @@ class Setup_Controller
 
         $this->_replaceTinebaseidInDump($mysqlBackupFile);
         $this->restore($options);
 
         $this->_replaceTinebaseidInDump($mysqlBackupFile);
         $this->restore($options);
+
+        // set the replication master id
+        $tinebase = Tinebase_Application::getInstance()->getApplicationByName('Tinebase');
+        $state = $tinebase->state;
+        if (!is_array($state)) {
+            $state = array();
+        }
+        $state[Tinebase_Model_Application::STATE_REPLICATION_MASTER_ID] = Tinebase_Timemachine_ModificationLog::getInstance()->getMaxInstanceSeq();
+        $tinebase->state = $state;
+        Tinebase_Application::getInstance()->updateApplication($tinebase);
+
         $this->updateApplications();
 
         return true;
         $this->updateApplications();
 
         return true;
index f987ad7..ce4c504 100644 (file)
@@ -1798,4 +1798,11 @@ class Tinebase_Core
 
         return self::$appInstanceCache['TinebaseId'];
     }
 
         return self::$appInstanceCache['TinebaseId'];
     }
+
+    public static function unsetTinebaseId()
+    {
+        if (isset(self::$appInstanceCache['TinebaseId'])) {
+            unset(self::$appInstanceCache['TinebaseId']);
+        }
+    }
 }
 }
index c48d56d..36a7aee 100644 (file)
@@ -342,4 +342,9 @@ class Tinebase_Group
         Tinebase_Timemachine_ModificationLog::setRecordMetaData($userGroup, 'create');
         Tinebase_Group::getInstance()->addGroup($userGroup);
     }
         Tinebase_Timemachine_ModificationLog::setRecordMetaData($userGroup, 'create');
         Tinebase_Group::getInstance()->addGroup($userGroup);
     }
+
+    public static function unsetInstance()
+    {
+        self::$_instance = null;
+    }
 }
 }
index dd6fd95..7731b62 100644 (file)
@@ -5,7 +5,7 @@
  * @package     Tinebase
  * @subpackage  Group
  * @license     http://www.gnu.org/licenses/agpl.html AGPL3
  * @package     Tinebase
  * @subpackage  Group
  * @license     http://www.gnu.org/licenses/agpl.html AGPL3
- * @copyright   Copyright (c) 2008-2014 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2008-2017 Metaways Infosystems GmbH (http://www.metaways.de)
  * @author      Lars Kneschke <l.kneschke@metaways.de>
  * 
  * @todo        add search count function
  * @author      Lars Kneschke <l.kneschke@metaways.de>
  * 
  * @todo        add search count function
@@ -91,7 +91,7 @@ abstract class Tinebase_Group_Abstract
      * create a new group
      *
      * @param string $_groupName
      * create a new group
      *
      * @param string $_groupName
-     * @return unknown
+     * @return Tinebase_Model_Group
      */
     abstract public function addGroup(Tinebase_Model_Group $_group);
     
      */
     abstract public function addGroup(Tinebase_Model_Group $_group);
     
index 755b5aa..72b0885 100644 (file)
@@ -339,6 +339,26 @@ class Tinebase_Timemachine_ModificationLog implements Tinebase_Controller_Interf
 
         return $this->_backend->search($filter, $paging);
     }
 
         return $this->_backend->search($filter, $paging);
     }
+
+    /**
+     * @return int
+     */
+    public function getMaxInstanceSeq()
+    {
+        $db = $this->_table->getAdapter();
+        $select = $db->select()
+            ->from($this->_tablename, new Zend_Db_Expr('MAX(' . $db->quoteIdentifier('instance_seq') . ')'))
+            ->where($db->quoteInto($db->quoteIdentifier('instance_id') . ' = ?', Tinebase_Core::getTinebaseId()));
+
+        $stmt = $db->query($select);
+        $resultArray = $stmt->fetchAll(Zend_Db::FETCH_NUM);
+
+        if (count($resultArray) === 0) {
+            return 0;
+        }
+
+        return intval($resultArray[0][0]);
+    }
     
     /**
      * Computes effective difference from a set of modifications
     
     /**
      * Computes effective difference from a set of modifications