11784 support ownclouds X-OC-MTime header
authorCornelius Weiß <c.weiss@metaways.de>
Fri, 15 Apr 2016 12:40:57 +0000 (14:40 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 19 Apr 2016 15:30:04 +0000 (17:30 +0200)
NOTE:
* this is a hack as good solution would change too much
* automated test not possible due to headers already send problem
* see 0011786: support ctime/mtime as file properties

Change-Id: I33940c09533c5d13d2e0e242a3f9f2608d74b504
Reviewed-on: http://gerrit.tine20.com/customers/3051
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Tinebase/Backend/Sql/Abstract.php
tine20/Tinebase/FileSystem.php
tine20/Tinebase/Frontend/WebDAV/File.php

index 92f8c8e..83f105b 100644 (file)
@@ -1241,7 +1241,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 43aea8e..96c140d 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;
     }
     
@@ -1033,12 +1053,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();
     }
 }