Index: branches/5.1.x/core/kernel/db/db_event_handler.php =================================================================== diff -u -r13161 -r13168 --- branches/5.1.x/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 13161) +++ branches/5.1.x/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 13168) @@ -1,6 +1,6 @@ Application->SetVar($event->getPrefixSpecial() . '_selected_ids', implode(',', $resulting_ids)); - $this->Application->LinkVar($event->getPrefixSpecial() . '_selected_ids', $session_name); + $this->Application->LinkVar($event->getPrefixSpecial() . '_selected_ids', $session_name, '', true); $this->Application->SetVar($event->getPrefixSpecial() . '_id', $resulting_ids[0]); return $resulting_ids; @@ -1600,6 +1600,44 @@ return ; } + // TODO: 2. optimize change log records (replace multiple changes to same record with one change record) + + $to_increment = Array (); + + // 3. collect serials to reset based on foreign keys + foreach ($changes as $index => $rec) { + if (array_key_exists('DependentFields', $rec)) { + + foreach ($rec['DependentFields'] as $field_name => $field_value) { + // will be "ci|ItemResourceId:345" + $to_increment[] = $rec['Prefix'] . '|' . $field_name . ':' . $field_value; + } + + unset($changes[$index]['DependentFields']); + } + + unset($changes[$index]['ParentId'], $changes[$index]['ParentPrefix']); + } + + // 4. collect serials to reset based on changed ids + foreach ($changes as $change) { + $to_increment[] = $change['MasterPrefix'] . '|' . $change['MasterId']; + + if ($change['MasterPrefix'] != $change['Prefix']) { + $to_increment[] = $change['Prefix'] . '|' . $change['ItemId']; + } + } + + // 5. reset serials collected before + $to_increment = array_unique($to_increment); + $this->Application->incrementCacheSerial($this->Prefix); + + foreach ($to_increment as $to_increment_mixed) { + list ($to_increment_prefix, $to_increment_id) = explode('|', $to_increment_mixed, 2); + + $this->Application->incrementCacheSerial($to_increment_prefix, $to_increment_id); + } + // save changes to database $sesion_log_id = $this->Application->RecallVar('_SessionLogId_'); @@ -1619,10 +1657,14 @@ $this->Conn->doInsert(array_merge($rec, $add_fields), $change_log_table); } + $this->Application->incrementCacheSerial('change-log'); + $sql = 'UPDATE ' . $this->Application->getUnitOption('session-log', 'TableName') . ' SET AffectedItems = AffectedItems + ' . count($changes) . ' WHERE SessionLogId = ' . $sesion_log_id; $this->Conn->Query($sql); + + $this->Application->incrementCacheSerial('session-log'); } /**