Merge branch '2014.11-develop' into 2015.11 2015.07.6
authorPhilipp Schüle <p.schuele@metaways.de>
Thu, 19 Nov 2015 09:29:13 +0000 (10:29 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 19 Nov 2015 09:29:13 +0000 (10:29 +0100)
Conflicts:
tine20/Tinebase/Container.php

Change-Id: I0c58c2b1653cd247102c793f53125cbaabf5583c

1  2 
tine20/Calendar/Convert/Event/VCalendar/Factory.php
tine20/Tinebase/Container.php

@@@ -24,7 -24,6 +24,7 @@@ class Calendar_Convert_Event_VCalendar_
      const CLIENT_THUNDERBIRD = 'thunderbird';
      const CLIENT_EMCLIENT    = 'emclient';
      const CLIENT_TINE        = 'tine';
 +    const CLIENT_DAVDROID    = 'davdroid';
      
      /**
       * cache parsed user-agent strings
                  return new Calendar_Convert_Event_VCalendar_EMClient($_version);
                  break;
  
 +            case Calendar_Convert_Event_VCalendar_Factory::CLIENT_DAVDROID:
 +                return new Calendar_Convert_Event_VCalendar_DavDroid($_version);
 +                break;
 +
              case Calendar_Convert_Event_VCalendar_Factory::CLIENT_TINE:
                  return new Calendar_Convert_Event_VCalendar_Tine($_version);
          }
              $backend = Calendar_Convert_Event_VCalendar_Factory::CLIENT_TINE;
              $version = $matches['version'];
  
 +        // DavDroid
 +        } elseif (preg_match(Calendar_Convert_Event_VCalendar_DavDroid::HEADER_MATCH, $_userAgent, $matches)) {
 +            $backend = Calendar_Convert_Event_VCalendar_Factory::CLIENT_TINE;
 +            $version = $matches['version'];
  
          } else {
              $backend = Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC;
          
          return array($backend, $version);
      }
+     /**
+      * parse useragent and return backend and version
+      *
+      * @return array
+      */
+     static public function supportsSyncToken($_userAgent)
+     {
+         list($backend, $version) = self::parseUserAgent($_userAgent);
+         switch($backend)
+         {
+             case self::CLIENT_MACOSX:
+                 if (version_compare($version, '10.9', '>='))
+                     return true;
+                 break;
+         }
+         return false;
+     }
  }
@@@ -109,7 -109,7 +109,7 @@@ class Tinebase_Container extends Tineba
       * 
       * @todo move this to constructor when this no longer extends Tinebase_Backend_Sql_Abstract
       */
-     protected function _getContentBackend()
+     public function getContentBackend()
      {
          if ($this->_contentBackend === NULL) {
              $this->_contentBackend  = new Tinebase_Backend_Sql(array(
      {
          $_container->isValid(TRUE);
          
 -        if($_ignoreAcl !== TRUE) {
 -            switch($_container->type) {
 +        if ($_ignoreAcl !== TRUE) {
 +            switch ($_container->type) {
                  case Tinebase_Model_Container::TYPE_PERSONAL:
                      // is the user allowed to create personal container?
                      break;
          $rows = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
          
          $result = new Tinebase_Record_RecordSet('Tinebase_Model_Container', $rows, TRUE);
 +        
          return $result;
      }
      
              sort($grant);
          }
          
 -        $classCacheId = Tinebase_Helper::convertCacheId($accountId . $applicationId . implode('', (array)$grant) . (int)$onlyIds . (int)$ignoreACL);
 +        $classCacheId = $accountId . $applicationId . implode('', (array)$grant) . (int)$onlyIds . (int)$ignoreACL;
          
          try {
              return $this->loadFromClassCache(__FUNCTION__, $classCacheId);
      {
          $containerId = Tinebase_Model_Container::convertContainerIdToInt($_containerId);
          
 -        $classCacheId = $containerId . 'd' . (int)$_getDeleted;
 -        $cacheId      = 'getContainerById' . $classCacheId;
 +        $cacheId = $containerId . 'd' . (int)$_getDeleted;
          
          try {
 -            return $this->loadFromClassCache(__FUNCTION__, $classCacheId);
 +            return $this->loadFromClassCache(__FUNCTION__, $cacheId, Tinebase_Cache_PerRequest::VISIBILITY_SHARED);
          } catch (Tinebase_Exception_NotFound $tenf) {
              // continue...
          }
          
 -        // load from cache
 -        $cache = Tinebase_Core::getCache();
 -        $result = $cache->load($cacheId);
 -
 -        if ($result === FALSE) {
 -            $result = $this->get($containerId, $_getDeleted);
 -            $cache->save($result, $cacheId, array('container'));
 -        }
 +        $result = $this->get($containerId, $_getDeleted);
          
 -        $this->saveInClassCache(__FUNCTION__, $classCacheId, $result);
 +        $this->saveInClassCache(__FUNCTION__, $cacheId, $result, Tinebase_Cache_PerRequest::VISIBILITY_SHARED);
          
          return $result;
      }
          $grant       = $_ignoreACL ? '*' : $_grant;
          $application = Tinebase_Application::getInstance()->getApplicationByName($meta['appName']);
          
 -        $classCacheId = Tinebase_Helper::convertCacheId(
 -            $accountId .
 -            $application->getId() .
 -            ($meta['recordClass'] ? $meta['recordClass'] : null) .
 -            $ownerId .
 -            implode('', (array)$grant) .
 -            (int)$_ignoreACL
 -        );
 +        $classCacheId = $accountId .
 +                        $application->getId() .
 +                        ($meta['recordClass'] ? $meta['recordClass'] : null) .
 +                        $ownerId .
 +                        implode('', (array)$grant) .
 +                        (int)$_ignoreACL;
          
          try {
              return $this->loadFromClassCache(__FUNCTION__, $classCacheId);
              (int)$_ignoreACL .
              (int)$_andGrants
          );
 -        
 +
          try {
              return $this->loadFromClassCache(__FUNCTION__, $classCacheId);
          } catch (Tinebase_Exception_NotFound $tenf) {
          $this->saveInClassCache(__FUNCTION__, $classCacheId, $containers);
          
          Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ 
 -            . ' Found ' . count($containers) . ' shared container(s) in application ' . $application->name
 -            . ' with grant(s): ' . implode(',', (array)$grant));
 +            . ' Found ' . count($containers) . ' shared container(s) in application ' . $application->name);
          
          return $containers;
      }
          $application = Tinebase_Application::getInstance()->getApplicationByName($_application);
          $grant       = $_ignoreACL ? '*' : $_grant;
          
 -        $classCacheId = Tinebase_Helper::convertCacheId(
 -            $accountId .
 -            $application->getId() .
 -            implode('', (array)$grant) .
 -            (int)$_ignoreACL
 -        );
 +        $classCacheId = $accountId .
 +                        $application->getId() .
 +                        implode('', (array)$grant) .
 +                        (int)$_ignoreACL;
          
          try {
              return $this->loadFromClassCache(__FUNCTION__, $classCacheId);
          if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
              . ' account: ' . $accountId . ' / containerId: ' . $containerId . ' / grant:' . implode('/', (array)$_grant));
          
 -        $classCacheId = Tinebase_Helper::convertCacheId($accountId . $containerId . implode('', (array)$_grant));
 -
 +        $classCacheId = $accountId . $containerId . implode('', (array)$_grant);
 +        
          try {
              $allGrants = $this->loadFromClassCache(__FUNCTION__, $classCacheId);
          } catch (Tinebase_Exception_NotFound $tenf) {
          $containerId        = Tinebase_Model_Container::convertContainerIdToInt($_containerId);
          $container          = ($_containerId instanceof Tinebase_Model_Container) ? $_containerId : $this->getContainerById($_containerId);
          
 -        $cacheKey = Tinebase_Helper::convertCacheId('getGrantsOfAccount' . $containerId . $accountId . $container->seq);
 -        $cache = Tinebase_Core::getCache();
 -        $grants = $cache->load($cacheKey);
 -        if ($grants === FALSE) {
 -            $select = $this->_getAclSelectByContainerId($containerId)
 -                ->group('container_acl.account_grant');
 -            
 -            $this->addGrantsSql($select, $accountId, '*');
 -            
 -            Tinebase_Backend_Sql_Abstract::traitGroup($select);
 -            
 -            $stmt = $this->_db->query('/*' . __FUNCTION__ . '*/' . $select);
 -            $rows = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
 -            $grants = $this->_getGrantsFromArray($rows, $accountId, $_grantModel);
 +        $classCacheId = $accountId . $containerId . $container->seq . $_grantModel;
 +        
 +        try {
 +            return $this->loadFromClassCache(__FUNCTION__, $classCacheId, Tinebase_Cache_PerRequest::VISIBILITY_SHARED);
 +        } catch (Tinebase_Exception_NotFound $tenf) {
              
 -            $cache->save($grants, $cacheKey, array('container'), self::ACL_CACHE_TIMEOUT);
          }
          
 +        $select = $this->_getAclSelectByContainerId($containerId)
 +            ->group('container_acl.account_grant');
 +        
 +        $this->addGrantsSql($select, $accountId, '*');
 +        
 +        Tinebase_Backend_Sql_Abstract::traitGroup($select);
 +        
 +        $stmt = $this->_db->query('/*' . __FUNCTION__ . '*/' . $select);
 +        
 +        $rows = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
 +        
 +        $grants = $this->_getGrantsFromArray($rows, $accountId, $_grantModel);
 +        
 +        $this->saveInClassCache(__FUNCTION__, $classCacheId, $grants, Tinebase_Cache_PerRequest::VISIBILITY_SHARED, self::ACL_CACHE_TIMEOUT);
 +        
          return $grants;
      }
      
                  ));
                  if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ 
                      . ' Creating "' . $action . '" action content history record for record id ' . $recordId);
-                 $this->_getContentBackend()->create($contentRecord);
+                 $this->getContentBackend()->create($contentRecord);
              }
              
              Tinebase_TransactionManager::getInstance()->commitTransaction($transactionId);
       */
      public function getContentHistory($containerId, $lastContentSeq = 0)
      {
 -        $containerId = Tinebase_Model_Container::convertContainerIdToInt($containerId);
          $filter = new Tinebase_Model_ContainerContentFilter(array(
 -            array('field' => 'container_id', 'operator' => 'equals',  'value' => $containerId),
 +            array('field' => 'container_id', 'operator' => 'equals',  'value' => Tinebase_Model_Container::convertContainerIdToInt($containerId)),
              array('field' => 'content_seq',  'operator' => 'greater', 'value' => $lastContentSeq),
          ));
          $pagination = new Tinebase_Model_Pagination(array(
              'sort' => 'content_seq'
          ));
-         
-         $result = $this->_getContentBackend()->search($filter, $pagination);
-         
+         $result = $this->getContentBackend()->search($filter, $pagination);
          return $result;
      }