/** * merges changes made to local storage on concurrent updates into the new record * * @param Tinebase_Record_Interface $_newRecord record from user data * @param Tinebase_Record_Interface $_curRecord record from storage * @param string $_model * @param string $_backend * @param string $_id * @return Tinebase_Record_RecordSet with resolved concurrent updates (Tinebase_Model_ModificationLog records) * @throws Tinebase_Timemachine_Exception_ConcurrencyConflict * * @deprecated this should be removed when all records have seq(uence) */ public function manageConcurrentUpdatesByTimestamp(Tinebase_Record_Interface $_newRecord, Tinebase_Record_Interface $_curRecord, $_model, $_backend, $_id) { if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Calling deprecated method. Model ' . $_model . ' should get a seq property.'); } list($appName, $i, $modelName) = explode('_', $_model); $resolved = new Tinebase_Record_RecordSet('Tinebase_Model_ModificationLog'); // handle concurrent updates on unmodified records if (!$_newRecord->last_modified_time instanceof DateTime) { if ($_curRecord->creation_time instanceof DateTime) { $_newRecord->last_modified_time = clone $_curRecord->creation_time; } else { Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Something went wrong! No creation_time was set in current record: ' . print_r($_curRecord->toArray(), TRUE)); return $resolved; } } if ($_curRecord->last_modified_time instanceof DateTime && !$_curRecord->last_modified_time->equals($_newRecord->last_modified_time)) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " concurrent updates: current record last updated '" . $_curRecord->last_modified_time . "' where record to be updated was last updated '" . $_newRecord->last_modified_time . "'"); } $loggedMods = $this->getModifications($appName, $_id, $_model, $_backend, $_newRecord->last_modified_time, $_curRecord->last_modified_time); // effective modifications made to the record after current user got his record $diffs = $this->computeDiff($loggedMods); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " during the concurrent update, the following changes have been made: " . print_r($diffs->toArray(), true)); } // we loop over the diffs! -> changes over fields which have no diff in storage are not in the loop! foreach ($diffs as $diff) { $newUserValue = isset($_newRecord[$diff->modified_attribute]) ? Tinebase_Helper::normalizeLineBreaks($_newRecord[$diff->modified_attribute]) : NULL; if (isset($_newRecord[$diff->modified_attribute]) && $newUserValue == Tinebase_Helper::normalizeLineBreaks($diff->new_value)) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " User updated to same value for field '" . $diff->modified_attribute . "', nothing to do."); } $resolved->addRecord($diff); } elseif (!isset($_newRecord[$diff->modified_attribute]) || $newUserValue == Tinebase_Helper::normalizeLineBreaks($diff->old_value)) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Merge current value into update data, as it was not changed in update request."); } $_newRecord[$diff->modified_attribute] = $diff->new_value; $resolved->addRecord($diff); } else { Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . " Non resolvable conflict for field '" . $diff->modified_attribute . "'!"); throw new Tinebase_Timemachine_Exception_ConcurrencyConflict('concurrency conflict!'); } } } return $resolved; }