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)
tine20/Tinebase/Backend/Sql/Abstract.php
tine20/Tinebase/FileSystem.php
tine20/Tinebase/Frontend/WebDAV/File.php
tine20/Tinebase/Frontend/WebDAV/Node.php
tine20/Tinebase/Server/WebDAV.php
tine20/Tinebase/WebDav/Collection/AbstractContainerTree.php

index e7ffb3e..4c04c62 100644 (file)
@@ -1248,7 +1248,7 @@ abstract class Tinebase_Backend_Sql_Abstract extends Tinebase_Backend_Abstract i
         );
         
         $this->_db->update($this->_tablePrefix . $this->_tableName, $recordArray, $where);
-        
+
         // update custom fields
         if ($_record->has('customfields')) {
             Tinebase_CustomField::getInstance()->saveRecordCustomFields($_record);
index 17e2498..3764afb 100644 (file)
@@ -371,6 +371,15 @@ class Tinebase_FileSystem implements Tinebase_Controller_Interface
         
         $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)) {
@@ -842,8 +851,19 @@ class Tinebase_FileSystem implements Tinebase_Controller_Interface
             '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(),
@@ -854,7 +874,7 @@ class Tinebase_FileSystem implements Tinebase_Controller_Interface
             ' ' . print_r($treeNode->toArray(), TRUE));
         
         $treeNode = $this->_treeNodeBackend->create($treeNode);
-        
+
         return $treeNode;
     }
     
@@ -1032,12 +1052,22 @@ class Tinebase_FileSystem implements Tinebase_Controller_Interface
     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);
index 260f5d2..6b23b9a 100644 (file)
@@ -79,9 +79,13 @@ class Tinebase_Frontend_WebDAV_File extends Tinebase_Frontend_WebDAV_Node implem
         if (is_resource($data)) {
             stream_copy_to_stream($data, $handle);
         }
-        
+
+        // save file object
         Tinebase_FileSystem::getInstance()->fclose($handle);
-        
+
+        // save node
+        Tinebase_FileSystem::getInstance()->update($this->_node);
+
         return $this->getETag();
     }
 }
index 20e4617..7658aee 100644 (file)
@@ -34,16 +34,18 @@ abstract class Tinebase_Frontend_WebDAV_Node implements Sabre\DAV\INode
     
     public function __construct($_path) 
     {
+        $this->_path      = $_path;
+
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) 
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' filesystem path: ' . $_path);
         
         try {
             $this->_node = Tinebase_FileSystem::getInstance()->stat($_path);
-        } catch (Tinebase_Exception_NotFound $tenf) {
+        } catch (Tinebase_Exception_NotFound $tenf) {}
+        
+        if (! $this->_node) {
             throw new Sabre\DAV\Exception\NotFound('Filesystem path: ' . $_path . ' not found');
         }
-        
-        $this->_path      = $_path;
     }
     
     public function getId()
index cdee29f..68b06cc 100644 (file)
@@ -72,6 +72,7 @@ class Tinebase_Server_WebDAV extends Tinebase_Server_Abstract implements Tinebas
         self::$_server = new \Sabre\DAV\Server(new Tinebase_WebDav_Root());
         
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
+            self::$_server->debugExceptions = true;
             $contentType = self::$_server->httpRequest->getHeader('Content-Type');
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " requestContentType: " . $contentType);
             
@@ -134,18 +135,24 @@ class Tinebase_Server_WebDAV extends Tinebase_Server_Abstract implements Tinebas
         self::$_server->addPlugin(new Tinebase_WebDav_Plugin_PrincipalSearch());
         self::$_server->addPlugin(new \Sabre\DAV\Browser\Plugin());
         self::$_server->addPlugin(new Tinebase_WebDav_Plugin_SyncToken());
-        
-        if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
+
+        $contentType = self::$_server->httpRequest->getHeader('Content-Type');
+        $logOutput = Tinebase_Core::isLogLevel(Zend_Log::DEBUG) && preg_match('/^text/', $contentType);
+
+        if ($logOutput) {
             ob_start();
         }
         
         self::$_server->exec();
         
-        if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
+        if ($logOutput) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " >>> *DAV response:\n" . ob_get_contents());
             ob_end_flush();
+        } else {
+
+            Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " <<< *DAV response\n -- BINARY DATA --");
         }
-        
+
         Tinebase_Controller::getInstance()->logout($this->_request->getServer('REMOTE_ADDR'));
     }
     
index 26284c2..b653169 100644 (file)
@@ -265,7 +265,10 @@ abstract class Tinebase_WebDav_Collection_AbstractContainerTree extends \Sabre\D
                 $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,
@@ -275,7 +278,10 @@ abstract class Tinebase_WebDav_Collection_AbstractContainerTree extends \Sabre\D
                     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
                             }