Exemple #1
0
 /**
  * update file object with hash file info
  * 
  * @param string $_id
  * @param string $_hash
  * @param string $_hashFile
  * @return Tinebase_Model_Tree_FileObject
  */
 protected function _updateFileObject($_id, $_hash, $_hashFile)
 {
     $currentFileObject = $this->_fileObjectBackend->get($_id);
     $updatedFileObject = clone $currentFileObject;
     $updatedFileObject->hash = $_hash;
     $updatedFileObject->size = filesize($_hashFile);
     if (version_compare(PHP_VERSION, '5.3.0', '>=') && function_exists('finfo_open')) {
         $finfo = finfo_open(FILEINFO_MIME_TYPE);
         $mimeType = finfo_file($finfo, $_hashFile);
         if ($mimeType !== false) {
             $updatedFileObject->contenttype = $mimeType;
         }
         finfo_close($finfo);
     } else {
         if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
             Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' finfo_open() is not available: Could not get file information.');
         }
     }
     $modLog = Tinebase_Timemachine_ModificationLog::getInstance();
     $modLog->setRecordMetaData($updatedFileObject, 'update', $currentFileObject);
     // sanitize file size, somehow filesize() seems to return empty strings on some systems
     if (empty($updatedFileObject->size)) {
         $updatedFileObject->size = 0;
     }
     return $this->_fileObjectBackend->update($updatedFileObject);
 }
 /**
  * update file object with hash file info
  * 
  * @param string $_id
  * @param string $_hash
  * @param string $_hashFile
  * @return Tinebase_Model_Tree_FileObject
  */
 protected function _updateFileObject($_id, $_hash, $_hashFile = null)
 {
     $currentFileObject = $_id instanceof Tinebase_Record_Abstract ? $_id : $this->_fileObjectBackend->get($_id);
     $_hashFile = $_hashFile ?: $this->_basePath . '/' . substr($_hash, 0, 3) . '/' . substr($_hash, 3);
     $updatedFileObject = clone $currentFileObject;
     $updatedFileObject->hash = $_hash;
     $updatedFileObject->size = filesize($_hashFile);
     if (version_compare(PHP_VERSION, '5.3.0', '>=') && function_exists('finfo_open')) {
         $finfo = finfo_open(FILEINFO_MIME_TYPE);
         $mimeType = finfo_file($finfo, $_hashFile);
         if ($mimeType !== false) {
             $updatedFileObject->contenttype = $mimeType;
         }
         finfo_close($finfo);
     } else {
         if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
             Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' finfo_open() is not available: Could not get file information.');
         }
     }
     $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']);
         Tinebase_Server_WebDAV::getResponse()->setHeader('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)) {
         $updatedFileObject->size = 0;
     }
     return $this->_fileObjectBackend->update($updatedFileObject);
 }