Tinebase_Model_Filter_GrantsFilterGroup - fix recursive join issue
authorPaul Mehrer <p.mehrer@metaways.de>
Tue, 8 Aug 2017 11:29:40 +0000 (13:29 +0200)
committerPaul Mehrer <p.mehrer@metaways.de>
Tue, 8 Aug 2017 12:43:39 +0000 (14:43 +0200)
recursively used this filter fails in the inner execution as the outer one
already did a join and used the same table alias as the inner execution
wanted to use. Table alias is uniquely generated now.

Change-Id: I2bbe56f4c8826fa0039773b55ad2ffe8508ea253
Reviewed-on: http://gerrit.tine20.com/customers/5419
Tested-by: Jenkins CI (http://ci.tine20.com/) <tine20-jenkins@metaways.de>
Reviewed-by: Paul Mehrer <p.mehrer@metaways.de>
Tested-by: Paul Mehrer <p.mehrer@metaways.de>
tine20/Tinebase/Model/Filter/GrantsFilterGroup.php
tine20/Tinebase/Model/Tree/Node/Filter.php

index ea143ac..920c330 100644 (file)
@@ -22,6 +22,11 @@ class Tinebase_Model_Filter_GrantsFilterGroup extends Tinebase_Model_Filter_Filt
     protected $_aclTableName = null;
 
     /**
+     * @var string the alias for the acl table name
+     */
+    protected $_joinedTableAlias = null;
+
+    /**
      * @var string acl record column for join with acl table
      */
     protected $_aclIdColumn = 'id';
@@ -97,14 +102,15 @@ class Tinebase_Model_Filter_GrantsFilterGroup extends Tinebase_Model_Filter_Filt
             $user = isset($this->_options['user']) ? $this->_options['user'] : Tinebase_Core::getUser();
         }
 
+        $this->_joinedTableAlias = uniqid($this->_aclTableName);
         $db = $backend->getAdapter();
         $select->join(array(
-            /* table  */ $this->_aclTableName => SQL_TABLE_PREFIX . $this->_aclTableName), 
-            /* on     */ "{$db->quoteIdentifier($this->_aclTableName . '.record_id')} = {$db->quoteIdentifier($backend->getTableName() . '.' . $this->_aclIdColumn)}",
+            /* table  */ $this->_joinedTableAlias => SQL_TABLE_PREFIX . $this->_aclTableName),
+            /* on     */ "{$db->quoteIdentifier($this->_joinedTableAlias . '.record_id')} = {$db->quoteIdentifier($backend->getTableName() . '.' . $this->_aclIdColumn)}",
             /* select */ array()
         );
         
-        Tinebase_Container::addGrantsSql($select, $user, $this->_requiredGrants, $this->_aclTableName);
+        Tinebase_Container::addGrantsSql($select, $user, $this->_requiredGrants, $this->_joinedTableAlias);
         
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ 
             . ' $select after appending grants sql: ' . $select);
index e0e94c6..8c3dd1b 100644 (file)
@@ -153,12 +153,13 @@ class Tinebase_Model_Tree_Node_Filter extends Tinebase_Model_Filter_GrantsFilter
 
         if (!$this->_ignorePinProtection && !Tinebase_Auth_SecondFactor_Abstract::hasValidSecondFactor()) {
             $db = $backend->getAdapter();
+            $uniqueId = uniqid('pinProtected');
             $select->joinLeft(array(
-                /* table  */ 'pinProtected' => SQL_TABLE_PREFIX . $backend->getTableName()),
-                /* on     */ "{$db->quoteIdentifier('pinProtected.id')} = {$db->quoteIdentifier($backend->getTableName() . '.' . $this->_aclIdColumn)}",
+                /* table  */ $uniqueId => SQL_TABLE_PREFIX . $backend->getTableName()),
+                /* on     */ "{$db->quoteIdentifier($uniqueId . '.id')} = {$db->quoteIdentifier($backend->getTableName() . '.' . $this->_aclIdColumn)}",
                 /* select */ array()
             );
-            $select->where("{$db->quoteIdentifier('pinProtected.pin_protected')} = 0 OR {$db->quoteIdentifier('pinProtected.pin_protected')} IS NULL");
+            $select->where("{$db->quoteIdentifier($uniqueId . '.pin_protected')} = 0 OR {$db->quoteIdentifier($uniqueId . '.pin_protected')} IS NULL");
         }
 
         // TODO do something when acl_node = NULL?