Merge branch '2014.11' into 2014.11-develop
authorPhilipp Schüle <p.schuele@metaways.de>
Wed, 20 Apr 2016 10:21:03 +0000 (12:21 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 20 Apr 2016 10:21:03 +0000 (12:21 +0200)
1  2 
tine20/Tinebase/Backend/Sql/Abstract.php
tine20/Tinebase/FileSystem.php
tine20/Tinebase/WebDav/Collection/AbstractContainerTree.php

@@@ -303,8 -303,6 +303,8 @@@ abstract class Tinebase_Backend_Sql_Abs
      protected function _rawDataToRecord(array $_rawData)
      {
          $result = new $this->_modelName($_rawData, true);
 +
 +        $result->runConvertToRecord();
          
          $this->_explodeForeignValues($result);
          
          $getDeleted = !!$_filter && $_filter->getFilter('is_deleted');
          
          if ($_pagination === NULL) {
 -            $_pagination = new Tinebase_Model_Pagination(NULL, TRUE);
 +            $pagination = new Tinebase_Model_Pagination(NULL, TRUE);
 +        } else {
 +            // clone pagination to prevent accidental change of original object
 +            $pagination = clone($_pagination);
          }
          
          // legacy: $_cols param was $_onlyIds (boolean) ...
          }
          
          // (1) eventually get only ids or id/value pair
 -        list($colsToFetch, $getIdValuePair) = $this->_getColumnsToFetch($_cols, $_filter, $_pagination);
 +        list($colsToFetch, $getIdValuePair) = $this->_getColumnsToFetch($_cols, $_filter, $pagination);
  
          // check if we should do one or two queries
          $doSecondQuery = true;
          if ($_filter !== NULL) {
              $this->_addFilter($select, $_filter);
          }
 -        $this->_addSecondarySort($_pagination);
 -        $this->_appendForeignSort($_pagination, $select);
 -        $_pagination->appendPaginationSql($select);
 +        
 +        $this->_addSecondarySort($pagination);
 +        $this->_appendForeignSort($pagination, $select);
 +        $pagination->appendPaginationSql($select);
          
          Tinebase_Backend_Sql_Abstract::traitGroup($select);
          
          
          $select = $this->_getSelect($_cols, $getDeleted);
          $this->_addWhereIdIn($select, $ids);
 -        $_pagination->appendSort($select);
 +        $pagination->appendSort($select);
          
          $rows = $this->_fetch($select, self::FETCH_ALL);
          
       */
      protected function _recordToRawData($_record)
      {
 +        $_record->runConvertToData();
          $readOnlyFields = $_record->getReadOnlyFields();
          $raw = $_record->toArray(FALSE);
          foreach ($raw as $key => $value) {
          );
          
          $this->_db->update($this->_tablePrefix . $this->_tableName, $recordArray, $where);
-         
          // update custom fields
          if ($_record->has('customfields')) {
              Tinebase_CustomField::getInstance()->saveRecordCustomFields($_record);
@@@ -65,7 -65,7 +65,7 @@@ class Tinebase_FileSystem implements Ti
          $this->_fileObjectBackend  = new Tinebase_Tree_FileObject();
          $this->_treeNodeBackend    = new Tinebase_Tree_Node();
          
 -        if (! Setup_Controller::getInstance()->isFilesystemAvailable()) {
 +        if (! Tinebase_Core::isFilesystemAvailable()) {
              throw new Tinebase_Exception_Backend('No base path (filesdir) configured or path not writeable');
          }
          
          
          $modLog = Tinebase_Timemachine_ModificationLog::getInstance();
          $modLog->setRecordMetaData($updatedFileObject, 'update', $currentFileObject);
+         // quick hack for 2014.11 - will be resolved correctly in 2015.11-develop
+         if (isset($_SERVER['HTTP_X_OC_MTIME'])) {
+             $updatedFileObject->last_modified_time = new Tinebase_DateTime($_SERVER['HTTP_X_OC_MTIME']);
+             header('X-OC-MTime: accepted');
+             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG))
+                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " using X-OC-MTIME: {$updatedFileObject->last_modified_time->format(Tinebase_Record_Abstract::ISO8601LONG)} for {$updatedFileObject->id}");
+         }
          
          // sanitize file size, somehow filesize() seems to return empty strings on some systems
          if (empty($updatedFileObject->size)) {
              'contentytype'  => null,
          ));
          Tinebase_Timemachine_ModificationLog::setRecordMetaData($fileObject, 'create');
+         // quick hack for 2014.11 - will be resolved correctly in 2015.11-develop
+         if (isset($_SERVER['HTTP_X_OC_MTIME'])) {
+             $fileObject->creation_time = new Tinebase_DateTime($_SERVER['HTTP_X_OC_MTIME']);
+             $fileObject->last_modified_time = new Tinebase_DateTime($_SERVER['HTTP_X_OC_MTIME']);
+             header('X-OC-MTime: accepted');
+             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG))
+                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " using X-OC-MTIME: {$fileObject->last_modified_time->format(Tinebase_Record_Abstract::ISO8601LONG)} for {$name}");
+         }
          $fileObject = $this->_fileObjectBackend->create($fileObject);
-         
          $treeNode = new Tinebase_Model_Tree_Node(array(
              'name'          => $name,
              'object_id'     => $fileObject->getId(),
              ' ' . print_r($treeNode->toArray(), TRUE));
          
          $treeNode = $this->_treeNodeBackend->create($treeNode);
-         
          return $treeNode;
      }
      
              $nodeId = $nodeId->getArrayOfIds();
              $operator = 'in';
          } else {
 -            $nodeId = $_nodeId;
              $operator = 'equals';
          }
          
      public function update(Tinebase_Model_Tree_Node $_node)
      {
          $currentNodeObject = $this->get($_node->getId());
+         $fileObject = $this->_fileObjectBackend->get($currentNodeObject->object_id);
          Tinebase_Timemachine_ModificationLog::setRecordMetaData($_node, 'update', $currentNodeObject);
-         
+         Tinebase_Timemachine_ModificationLog::setRecordMetaData($fileObject, 'update', $fileObject);
+         // quick hack for 2014.11 - will be resolved correctly in 2015.11-develop
+         if (isset($_SERVER['HTTP_X_OC_MTIME'])) {
+             $fileObject->last_modified_time = new Tinebase_DateTime($_SERVER['HTTP_X_OC_MTIME']);
+             header('X-OC-MTime: accepted');
+             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG))
+                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " using X-OC-MTIME: {$fileObject->last_modified_time->format(Tinebase_Record_Abstract::ISO8601LONG)} for {$_node->name}");
+         }
          // update file object
-         $fileObject = $this->_fileObjectBackend->get($currentNodeObject->object_id);
          $fileObject->description = $_node->description;
-         
          $this->_updateFileObject($fileObject, $_node->hash);
          
          return $this->_treeNodeBackend->update($_node);
@@@ -245,6 -245,8 +245,6 @@@ abstract class Tinebase_WebDav_Collecti
              
                  break;
          }
 -    
 -        
      }
      
      /**
                  $children[] = $this->getChild(Tinebase_Model_Container::TYPE_SHARED);
                  
                  if ($this->_hasPersonalFolders) {
-                     $children[] = $this->getChild($this->_useIdAsName ? Tinebase_Core::getUser()->contact_id : Tinebase_Core::getUser()->accountDisplayName);
+                     $children[] = $this->getChild(
+                         $this->_useIdAsName ? Tinebase_Core::getUser()->contact_id :
+                         Addressbook_Controller_Contact::getInstance()->get(Tinebase_Core::getUser()->contact_id)->n_fileas
+                     );
                      
                      $otherUsers = Tinebase_Container::getInstance()->getOtherUsers(Tinebase_Core::getUser(), $this->_getApplicationName(), array(
                          Tinebase_Model_Grants::GRANT_READ,
                      foreach ($otherUsers as $user) {
                          if ($user->contact_id && $user->visibility === Tinebase_Model_User::VISIBILITY_DISPLAYED) {
                              try {
-                                 $children[] = $this->getChild($this->_useIdAsName ? $user->contact_id : $user->accountDisplayName);
+                                 $folderId = $this->_useIdAsName ? $user->contact_id :
+                                     Addressbook_Controller_Contact::getInstance()->get($user->contact_id)->n_fileas;
+                                 $children[] = $this->getChild($folderId);
                              } catch (\Sabre\DAV\Exception\NotFound $sdavenf) {
                                  // ignore contacts not found
                              }
                  
                  foreach ($containers as $container) {
                      try {
 -                        $children[] = $this->getChild($container);
 +                        $children[] = $this->getChild($this->_useIdAsName ? $container->getId() : $container->name);
                      } catch (\Sabre\DAV\Exception\NotFound $sdavenf) {
                          // ignore containers not found
                      }