allow to define supported SQL adapter in email plugin
authorLars Kneschke <l.kneschke@metaways.de>
Tue, 3 Mar 2015 17:27:57 +0000 (18:27 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 4 Mar 2015 13:36:42 +0000 (14:36 +0100)
Change-Id: I57dac10ba43acce987e15699d7b037b68edc311a
Reviewed-on: http://gerrit.tine20.com/customers/1706
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Lars Kneschke <l.kneschke@metaways.de>
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Tinebase/EmailUser.php
tine20/Tinebase/EmailUser/Imap/Dbmail.php
tine20/Tinebase/EmailUser/Imap/Dovecot.php
tine20/Tinebase/EmailUser/Smtp/Postfix.php
tine20/Tinebase/User/Plugin/Abstract.php

index ff6bb45..46d2074 100644 (file)
@@ -5,7 +5,7 @@
  * @package     Tinebase
  * @subpackage  User
  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
- * @copyright   Copyright (c) 2009-2012 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2009-2015 Metaways Infosystems GmbH (http://www.metaways.de)
  * @author      Philipp Schüle <p.schuele@metaways.de>
  * 
  * @todo        think about splitting email user model in two (imap + smtp)
@@ -27,7 +27,7 @@ class Tinebase_EmailUser
      * @staticvar string
      */
     const DBMAIL    = 'Dbmail';
-
+    
     /**
      * Dovecot imap backend const
      * 
@@ -36,19 +36,33 @@ class Tinebase_EmailUser
     const DOVECOT_IMAP    = 'Dovecot_imap';
     
     /**
+     * Dovecot imap combined backend const
+     * 
+     * @staticvar string
+     */
+    const DOVECOT_IMAP_COMBINED    = 'Dovecot_imap_combined';
+    
+    /**
      * postfix backend const
      * 
      * @staticvar string
      */
     const POSTFIX    = 'Postfix';
-
+    
+    /**
+     * postfix backend const
+     * 
+     * @staticvar string
+     */
+    const POSTFIX_COMBINED    = 'Postfix_combined';
+    
     /**
      * imap ldap backend const
      * 
      * @staticvar string
      */
     const LDAP_IMAP      = 'Ldap_imap';
-
+    
     /**
      * smtp ldap backend const
      * 
@@ -69,7 +83,7 @@ class Tinebase_EmailUser
      * @staticvar string
      */
     const LDAP_SMTP_QMAIL      = 'Ldapsmtpqmail';
-
+    
     /**
      * cyrus backend const
      * 
@@ -156,6 +170,12 @@ class Tinebase_EmailUser
                 }
                 break;
                 
+            case self::POSTFIX_COMBINED:
+                if (!isset(self::$_backends[$_type])) {
+                    self::$_backends[$_type] = new Tinebase_EmailUser_Smtp_PostfixCombined();
+                }
+                break;
+                
             case self::LDAP_SMTP:
                 if (!isset(self::$_backends[$_type])) {
                     self::$_backends[$_type] = new Tinebase_EmailUser_Smtp_LdapDbmailSchema();
@@ -173,13 +193,19 @@ class Tinebase_EmailUser
                     self::$_backends[$_type] = new Tinebase_EmailUser_Smtp_LdapQmailSchema();
                 }
                 break;
-            
+                
             case self::DOVECOT_IMAP:
                 if (!isset(self::$_backends[$_type])) {
                     self::$_backends[$_type] = new Tinebase_EmailUser_Imap_Dovecot();
                 }
                 break;
                 
+            case self::DOVECOT_IMAP_COMBINED:
+                if (!isset(self::$_backends[$_type])) {
+                    self::$_backends[$_type] = new Tinebase_EmailUser_Imap_DovecotCombined();
+                }
+                break;
+                
             default:
                 throw new Tinebase_Exception_InvalidArgument("Backend type $_type not implemented.");
         }
@@ -230,7 +256,7 @@ class Tinebase_EmailUser
                     break;
             }
         }
-
+        
         if (empty($result)) {
             throw new Tinebase_Exception_NotFound("Config for type $_configType / $backend not found.");
         }
index 2d85934..688646c 100644 (file)
@@ -51,7 +51,8 @@ class Tinebase_EmailUser_Imap_Dbmail extends Tinebase_User_Plugin_Abstract
         'userTable'    => 'users',
         'emailScheme'  => 'md5',
         'mailboxTable' => 'mailboxes',
-        'emailGID'     => null
+        'emailGID'     => null,
+        'adapter'      => Tinebase_Core::PDO_MYSQL
     );
 
     /**
index 30bc798..cafbf97 100644 (file)
@@ -198,6 +198,7 @@ class Tinebase_EmailUser_Imap_Dovecot extends Tinebase_EmailUser_Sql
         'emailGID'          => 'vmail',
         'emailScheme'       => 'SSHA256',
         'domain'            => null,
+        'adapter'           => Tinebase_Core::PDO_MYSQL
     );
     
     /**
index 24740f5..05fdc47 100644 (file)
@@ -106,7 +106,8 @@ class Tinebase_EmailUser_Smtp_Postfix extends Tinebase_EmailUser_Sql
         'destinationTable'  => 'destinations',
         'emailScheme'       => 'ssha256',
         'domain'            => null,
-        'alloweddomains'    => array()
+        'alloweddomains'    => array(),
+        'adapter'           => Tinebase_Core::PDO_MYSQL
     );
 
     /**
index aad9402..bbb9304 100644 (file)
@@ -18,7 +18,7 @@
 abstract class Tinebase_User_Plugin_Abstract implements Tinebase_User_Plugin_SqlInterface
 {
     /**
-    * @var Zend_Db_Adapter
+    * @var Zend_Db_Adapter_Abstract
     */
     protected $_db = NULL;
     
@@ -88,29 +88,28 @@ abstract class Tinebase_User_Plugin_Abstract implements Tinebase_User_Plugin_Sql
      * set database
      * 
      * @param array $_config
-     * 
-     * @todo allow other db backends than mysql
      */
     protected function _getDb($_config)
     {
         $tine20DbConfig = Tinebase_Core::getDb()->getConfig();
+        $tine20DbConfig['adapter'] = str_replace('Tinebase_Backend_Sql_Adapter_', '', get_class(Tinebase_Core::getDb()));
         
-        if ($this->_config['host'] == $tine20DbConfig['host'] && 
-            $this->_config['dbname'] == $tine20DbConfig['dbname'] &&
-            $this->_config['username'] == $tine20DbConfig['username'] &&
-            Tinebase_Core::getDb() instanceof Zend_Db_Adapter_Pdo_Mysql
+        if ($this->_config['adapter']  == $tine20DbConfig['adapter'] &&
+            $this->_config['host']     == $tine20DbConfig['host'] && 
+            $this->_config['dbname']   == $tine20DbConfig['dbname'] &&
+            $this->_config['username'] == $tine20DbConfig['username']
         ) {
             $this->_db = Tinebase_Core::getDb();
         } else {
-            $dbConfig = array_intersect_key($_config, array_flip(array('host', 'dbname', 'username', 'password', 'prefix', 'port')));
-            $this->_db = Tinebase_Core::createAndConfigureDbAdapter($dbConfig, 'Pdo_Mysql');
+            $dbConfig = array_intersect_key($_config, array_flip(array('adapter', 'host', 'dbname', 'username', 'password', 'port')));
+            $this->_db = Tinebase_Core::createAndConfigureDbAdapter($dbConfig);
         }
     }
     
     /**
      * get database object
      * 
-     * @return Zend_Db_Adapter
+     * @return Zend_Db_Adapter_Abstract
      */
     public function getDb()
     {