0012836: Replication - email notifications for errors
authorPaul Mehrer <p.mehrer@metaways.de>
Mon, 20 Mar 2017 15:46:29 +0000 (16:46 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 21 Mar 2017 12:49:27 +0000 (13:49 +0100)
* added configurable notification list to email to in case of replication
errors
* cli introduced to increase master replication id

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

Change-Id: I2d9561a41043937757f9d4543ae2e259445ad49b
Reviewed-on: http://gerrit.tine20.com/customers/4391
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Tinebase/Config.php
tine20/Tinebase/Frontend/Cli.php
tine20/Tinebase/Timemachine/ModificationLog.php

index 7de4101..83c63d0 100644 (file)
@@ -471,6 +471,11 @@ class Tinebase_Config extends Tinebase_Config_Abstract
     const MASTER_PASSWORD = 'masterPassword';
 
     /**
+     * @var string
+     */
+    const ERROR_NOTIFICATION_LIST = 'errorNotificationList';
+
+    /**
      * (non-PHPdoc)
      * @see tine20/Tinebase/Config/Definition::$_properties
      */
@@ -652,14 +657,17 @@ class Tinebase_Config extends Tinebase_Config_Abstract
             'setByAdminModule'      => FALSE,
             'setBySetupModule'      => TRUE,
             'content'               => array(
-                self::MASTER_URL            => array(
-                    'type'                      => Tinebase_Config::TYPE_STRING,
+                self::MASTER_URL                => array(
+                    'type'                          => Tinebase_Config::TYPE_STRING,
                 ),
-                self::MASTER_USERNAME       => array(
-                    'type'                      => Tinebase_Config::TYPE_STRING,
+                self::MASTER_USERNAME           => array(
+                    'type'                          => Tinebase_Config::TYPE_STRING,
                 ),
-                self::MASTER_PASSWORD       => array(
-                    'type'                      => Tinebase_Config::TYPE_STRING,
+                self::MASTER_PASSWORD           => array(
+                    'type'                          => Tinebase_Config::TYPE_STRING,
+                ),
+                self::ERROR_NOTIFICATION_LIST   => array(
+                    'type'                          => Tinebase_Config::TYPE_ARRAY,
                 )
             )
         ),
index 96626d4..cfdf7d2 100644 (file)
@@ -36,6 +36,21 @@ class Tinebase_Frontend_Cli extends Tinebase_Frontend_Cli_Abstract
      * @param Zend_Console_Getopt $_opts
      * @return boolean success
      */
+    public function increaseReplicationMasterId($opts)
+    {
+        if (!$this->_checkAdminRight()) {
+            return -1;
+        }
+
+        Tinebase_Timemachine_ModificationLog::getInstance()->increaseReplicationMasterId();
+
+        return true;
+    }
+
+    /**
+     * @param Zend_Console_Getopt $_opts
+     * @return boolean success
+     */
     public function readModifictionLogFromMaster($opts)
     {
         if (!$this->_checkAdminRight()) {
@@ -43,6 +58,8 @@ class Tinebase_Frontend_Cli extends Tinebase_Frontend_Cli_Abstract
         }
 
         Tinebase_Timemachine_ModificationLog::getInstance()->readModificationLogFromMaster();
+
+        return true;
     }
 
     /**
index a232b4e..755b5aa 100644 (file)
@@ -1298,6 +1298,21 @@ class Tinebase_Timemachine_ModificationLog implements Tinebase_Controller_Interf
 
                 $transactionManager->rollBack();
 
+                // notify configured email addresses about replication failure
+                $config = Tinebase_Config::getInstance()->get(Tinebase_Config::REPLICATION_SLAVE);
+                if ($config && is_array($config->{Tinebase_Config::ERROR_NOTIFICATION_LIST}) &&
+                        count($config->{Tinebase_Config::ERROR_NOTIFICATION_LIST}) > 0) {
+
+                    $recipients = array();
+                    foreach($config->{Tinebase_Config::ERROR_NOTIFICATION_LIST} as $recipient) {
+                        $recipients[] = new Addressbook_Model_Contact(array('email' => $recipient), true);
+                    }
+
+                    $plain = $e->getMessage() . PHP_EOL . PHP_EOL . $e->getTraceAsString();
+
+                    Tinebase_Notification::getInstance()->send(Tinebase_Core::getUser(), $recipients, 'replication client error', $plain);
+                }
+
                 // must not happen, continuing pointless!
                 return false;
             }
@@ -1307,4 +1322,26 @@ class Tinebase_Timemachine_ModificationLog implements Tinebase_Controller_Interf
 
         return true;
     }
+
+    /**
+     * @param int $count
+     */
+    public function increaseReplicationMasterId($count = 1)
+    {
+        $applicationController = Tinebase_Application::getInstance();
+        $tinebase = $applicationController->getApplicationByName('Tinebase');
+
+        $state = $tinebase->state;
+        if (!is_array($state)) {
+            $state = array();
+        }
+        if (!isset($state[Tinebase_Model_Application::STATE_REPLICATION_MASTER_ID])) {
+            $state[Tinebase_Model_Application::STATE_REPLICATION_MASTER_ID] = 0;
+        }
+
+        $state[Tinebase_Model_Application::STATE_REPLICATION_MASTER_ID] += intval($count);
+        $tinebase->state = $state;
+
+        $applicationController->updateApplication($tinebase);
+    }
 }