/** * inspect update of one record (before update) * * @param Tinebase_Record_Interface $_record the update record * @param Tinebase_Record_Interface $_oldRecord the current persistent record * @return void */ protected function _inspectBeforeUpdate($_record, $_oldRecord) { // sanitize container_id if (is_array($_record->feast_calendar_id)) { $_record->feast_calendar_id = $_record->feast_calendar_id['id']; } $diff = $_record->diff($_oldRecord, array('created_by', 'creation_time', 'last_modified_by', 'last_modified_time', 'notes', 'end_date', 'seq', 'tags'))->diff; if (!empty($diff)) { if ($this->getFreeTimes($_record)->filter('type', 'vacation')->count() > 0) { throw new HumanResources_Exception_ContractNotEditable(); } } $this->_checkDates($_record); }
/** * inspect update of one record (before update) * * @param Tinebase_Record_Interface $_record the update record * @param Tinebase_Record_Interface $_oldRecord the current persistent record * @return void */ protected function _inspectBeforeUpdate($_record, $_oldRecord) { // sanitize container_id if (is_array($_record->feast_calendar_id)) { $_record->feast_calendar_id = $_record->feast_calendar_id['id']; } $diff = $_record->diff($_oldRecord, array('created_by', 'creation_time', 'last_modified_by', 'last_modified_time', 'notes', 'end_date', 'seq', 'tags', 'workingtime_json'))->diff; if (!empty($diff)) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Contract diff:" . print_r($diff, true)); } if ($this->getFreeTimes($_record)->filter('type', 'vacation')->count() > 0) { throw new HumanResources_Exception_ContractNotEditable(); } } $this->_checkDates($_record); }
/** * inspect update of system account * - only allow to update certain fields of system accounts * * @param Tinebase_Record_Interface $_record the update record * @param Tinebase_Record_Interface $_oldRecord the current persistent record * @return void */ protected function _beforeUpdateSystemAccount($_record, $_oldRecord) { // only allow to update some values for system accounts $allowedFields = array('name', 'signature', 'signature_position', 'has_children_support', 'delimiter', 'ns_personal', 'ns_other', 'ns_shared', 'last_modified_time', 'last_modified_by'); $diff = $_record->diff($_oldRecord); foreach ($diff as $key => $value) { if (!in_array($key, $allowedFields)) { // setting old value $_record->{$key} = $_oldRecord->{$key}; } } }
/** * computes changes of records and writes them to the logbook * * NOTE: expects last_modified_by and last_modified_time to be set * properly in the $_newRecord * * @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 RecordSet of Tinebase_Model_ModificationLog */ public function writeModLog($_newRecord, $_curRecord, $_model, $_backend, $_id) { $commonModLog = $this->_getCommonModlog($_model, $_backend, array('last_modified_time' => $_newRecord->last_modified_time, 'last_modified_by' => $_newRecord->last_modified_by, 'seq' => $_newRecord->has('seq') ? $_newRecord->seq : 0), $_id); $diffs = $_curRecord->diff($_newRecord)->diff; if (!empty($diffs) && Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Diffs: ' . print_r($diffs, TRUE)); } if (!empty($diffs) && Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' CurRecord: ' . print_r($_curRecord->toArray(), TRUE)); } if (!empty($diffs) && Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' NewRecord: ' . print_r($_newRecord->toArray(), TRUE)); } if (!empty($commonModLog) && Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Common modlog: ' . print_r($commonModLog->toArray(), TRUE)); } $modifications = new Tinebase_Record_RecordSet('Tinebase_Model_ModificationLog'); $this->_loopModifications($diffs, $commonModLog, $modifications, $_curRecord->toArray(), $_curRecord->getModlogOmitFields()); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Logged ' . count($modifications) . ' modifications.'); } return $modifications; }