Merge branch '2013.10' into 2014.11
authorPhilipp Schüle <p.schuele@metaways.de>
Fri, 17 Apr 2015 17:45:53 +0000 (19:45 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Fri, 17 Apr 2015 17:45:53 +0000 (19:45 +0200)
Conflicts:
tine20/Tinebase/Container.php

Change-Id: I66fcb46d70614d0399cce54d011c9057deb36d47

1  2 
tests/tine20/TestCase.php
tests/tine20/Tinebase/ContainerTest.php
tine20/Tinebase/Backend/Sql/Abstract.php
tine20/Tinebase/Container.php
tine20/Tinebase/WebDav/PrincipalBackend.php

Simple merge
@@@ -413,10 -404,12 +407,12 @@@ class Tinebase_Container extends Tineba
              sort($grant);
          }
          
 -        $classCacheId = convertCacheId($accountId . $applicationId . implode('', (array)$grant) . (int)$onlyIds . (int)$ignoreACL);
 +        $classCacheId = Tinebase_Helper::convertCacheId($accountId . $applicationId . implode('', (array)$grant) . (int)$onlyIds . (int)$ignoreACL);
          
-         if (isset($this->_classCache[__FUNCTION__][$classCacheId])) {
-             return $this->_classCache[__FUNCTION__][$classCacheId];
+         try {
+             return $this->loadFromClassCache(__FUNCTION__, $classCacheId);
+         } catch (Tinebase_Exception_NotFound $tenf) {
+             // continue...
          }
          
          $select = $this->_getSelect($onlyIds ? 'id' : '*')
          $ownerId     = Tinebase_Model_User::convertUserIdToInt($_owner);
          $grant       = $_ignoreACL ? '*' : $_grant;
          $application = Tinebase_Application::getInstance()->getApplicationByName($meta['appName']);
+         
 -        $classCacheId = convertCacheId(
++        $classCacheId = Tinebase_Helper::convertCacheId(
+             $accountId .
+             $application->getId() .
+             ($meta['recordClass'] ? $meta['recordClass'] : null) .
+             $ownerId .
+             implode('', (array)$grant) .
+             (int)$_ignoreACL
+         );
+         
+         try {
+             return $this->loadFromClassCache(__FUNCTION__, $classCacheId);
+         } catch (Tinebase_Exception_NotFound $tenf) {
+             // continue...
+         }
+         
          $select = $this->_db->select()
              ->distinct()
              ->from(array('owner' => SQL_TABLE_PREFIX . 'container_acl'), array())
       * @return  Tinebase_Record_RecordSet set of Tinebase_Model_Container
       * @throws  Tinebase_Exception_NotFound
       */
 -    public function getSharedContainer($_accountId, $_application, $_grant, $_ignoreACL = FALSE)
 +    public function getSharedContainer($_accountId, $recordClass, $_grant, $_ignoreACL = FALSE)
      {
-         
 +        // legacy handling
 +        $meta = $this->_resolveRecordClassArgument($recordClass);
 +        $application = Tinebase_Application::getInstance()->getApplicationByName($meta['appName']);
 -        $application = Tinebase_Application::getInstance()->getApplicationByName($_application);
+         $accountId   = Tinebase_Model_User::convertUserIdToInt($_accountId);
          $grant       = $_ignoreACL ? '*' : $_grant;
          
 -        $classCacheId = convertCacheId(
++        $classCacheId = Tinebase_Helper::convertCacheId(
+             $accountId .
+             $application->getId() .
+             implode('', (array)$grant) .
+             (int)$_ignoreACL
+         );
+         
+         try {
+             return $this->loadFromClassCache(__FUNCTION__, $classCacheId);
+         } catch (Tinebase_Exception_NotFound $tenf) {
+             // continue...
+         }
+         
          $select = $this->_getSelect()
              ->distinct()
              ->join(array(
          $accountId   = Tinebase_Model_User::convertUserIdToInt($_accountId);
          $application = Tinebase_Application::getInstance()->getApplicationByName($_application);
          $grant       = $_ignoreACL ? '*' : $_grant;
-         
 -        $classCacheId = convertCacheId($accountId . $application->getId() . implode('', (array)$grant) .(int)$_ignoreACL);
++        $classCacheId = Tinebase_Helper::convertCacheId($accountId . $application->getId() . implode('', (array)$grant) .(int)$_ignoreACL);
+         try {
+             return $this->loadFromClassCache(__FUNCTION__, $classCacheId);
+         } catch (Tinebase_Exception_NotFound $tenf) {
+             // continue...
+         }
          // first grab all container ids ...
          $select = $this->_db->select()
              ->distinct()
       * @param   bool                                $_ignoreACL
       * @return  Tinebase_Record_RecordSet set of Tinebase_Model_Container
       */
 -    public function getOtherUsersContainer($_accountId, $_application, $_grant, $_ignoreACL = FALSE)
 +    public function getOtherUsersContainer($_accountId, $recordClass, $_grant, $_ignoreACL = FALSE)
      {
 -        $result = $this->_getOtherUsersContainerData($_accountId, $_application, $_grant, $_ignoreACL);
 -        
 +        // legacy handling
 +        $meta = $this->_resolveRecordClassArgument($recordClass);
-         
-         $containerData = $this->_getOtherUsersContainerData($_accountId, $meta['appName'], $_grant, $_ignoreACL);
-         $result = new Tinebase_Record_RecordSet('Tinebase_Model_Container', $containerData, TRUE);
-         
++        $result = $this->_getOtherUsersContainerData($_accountId, $meta['appName'], $_grant, $_ignoreACL);
++
          return $result;
      }
      
          $application = Tinebase_Application::getInstance()->getApplicationByName($_application);
          $grant       = $_ignoreACL ? '*' : $_grant;
          
 -        $classCacheId = convertCacheId(
++        $classCacheId = Tinebase_Helper::convertCacheId(
+             $accountId .
+             $application->getId() .
+             implode('', (array)$grant) .
+             (int)$_ignoreACL
+         );
+         
+         try {
+             return $this->loadFromClassCache(__FUNCTION__, $classCacheId);
+         } catch (Tinebase_Exception_NotFound $tenf) {
+             // continue...
+         }
+         
          $select = $this->_db->select()
              ->from(array('owner' => SQL_TABLE_PREFIX . 'container_acl'), array('account_id'))
              ->join(array(
          if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
              . ' account: ' . $accountId . ' / containerId: ' . $containerId . ' / grant:' . implode('/', (array)$_grant));
          
-         // always bring values in the same order for $classCacheId 
-         if (is_array($_grant)) {
-             sort($_grant);
-         }
-         
 -        $classCacheId = convertCacheId($accountId . $containerId);
 +        $classCacheId = Tinebase_Helper::convertCacheId($accountId . $containerId . implode('', (array)$_grant));
          
 +        if (isset($this->_classCache[__FUNCTION__][$classCacheId]) || array_key_exists($classCacheId, $this->_classCache[__FUNCTION__])) {
 +            return $this->_classCache[__FUNCTION__][$classCacheId];
 +        }
++
+         try {
+             $allGrants = $this->loadFromClassCache(__FUNCTION__, $classCacheId);
+         } catch (Tinebase_Exception_NotFound $tenf) {
+             // NOTE: some tests ask for already deleted container ;-)
+             $select = $this->_getSelect(array(), true)
+                 ->distinct()
+                 ->where("{$this->_db->quoteIdentifier('container.id')} = ?", $containerId)
+                 ->join(array(
+                     /* table  */ 'container_acl' => SQL_TABLE_PREFIX . 'container_acl'), 
+                     /* on     */ "{$this->_db->quoteIdentifier('container_acl.container_id')} = {$this->_db->quoteIdentifier('container.id')}",
+                     /* select */ array('container_acl.account_grant')
+                 );
+                 
+             $this->addGrantsSql($select, $accountId, '*');
+             
+             $stmt = $this->_db->query('/*' . __FUNCTION__ . '*/' . $select);
+             
+             $allGrants = $stmt->fetchAll(Zend_Db::FETCH_COLUMN);
+             $this->saveInClassCache(__FUNCTION__, $classCacheId, $allGrants);
+         }
          
-         // NOTE: some tests ask for already deleted container ;-)
-         $select = $this->_getSelect(self::IDCOL, true)
-             ->where("{$this->_db->quoteIdentifier('container.id')} = ?", $containerId)
-             ->join(array(
-                 /* table  */ 'container_acl' => SQL_TABLE_PREFIX . 'container_acl'), 
-                 /* on     */ "{$this->_db->quoteIdentifier('container_acl.container_id')} = {$this->_db->quoteIdentifier('container.id')}",
-                 /* select */ array()
-             );
-         
-         $this->addGrantsSql($select, $accountId, $_grant);
-         
-         $stmt = $this->_db->query($select);
-         
-         $grants = $stmt->fetchAll(Zend_Db::FETCH_COLUMN);
-         $result = ! empty($grants);
-         
-         $this->_classCache[__FUNCTION__][$classCacheId] = $result;
+         $matchingGrants = array_intersect((array)$_grant, $allGrants);
          
-         return $result;
+         return !!count($matchingGrants);
      }
      
      /**