Index: branches/5.1.x/core/kernel/db/db_event_handler.php =================================================================== diff -u -r13159 -r13161 --- branches/5.1.x/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 13159) +++ branches/5.1.x/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 13161) @@ -1,6 +1,6 @@ getObject(); + /* @var $object kDBItem */ + $id = $this->getPassedID($event); if ($object->isLoaded() && !is_array($id) && ($object->GetID() == $id)) { @@ -1511,9 +1513,13 @@ { $this->setTempWindowID($event); $ids = $this->StoreSelectedIDs($event); + $var_name = $event->getPrefixSpecial().'_file_pending_actions'.$this->Application->GetVar('m_wid'); $this->Application->RemoveVar($var_name); + $changes_var_name = $this->Prefix . '_changes_' . $this->Application->GetTopmostWid($this->Prefix); + $this->Application->RemoveVar($changes_var_name); + $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); /* @var $temp kTempTablesHandler */ @@ -1563,10 +1569,12 @@ $this->StoreSelectedIDs($event, $live_ids); } - $this->SaveLoggedChanges($changes_var_name); + $object =& $event->getObject(); + /* @var $object kDBItem */ + + $this->SaveLoggedChanges($changes_var_name, $object->ShouldLogChanges()); } else { - $this->Application->RemoveVar($changes_var_name); $event->status = erFAIL; } @@ -1580,40 +1588,43 @@ } } - function SaveLoggedChanges($changes_var_name) + function SaveLoggedChanges($changes_var_name, $save = true) { - $ses_log_id = $this->Application->RecallVar('_SessionLogId_'); - if (!$ses_log_id) { - return ; - } - + // 1. get changes, that were made $changes = $this->Application->RecallVar($changes_var_name); $changes = $changes ? unserialize($changes) : Array (); + $this->Application->RemoveVar($changes_var_name); + if (!$changes) { + // no changes, skip processing return ; } + // save changes to database + $sesion_log_id = $this->Application->RecallVar('_SessionLogId_'); + + if (!$save || !$sesion_log_id) { + // saving changes to database disabled OR related session log missing + return ; + } + $add_fields = Array ( 'PortalUserId' => $this->Application->RecallVar('user_id'), - 'SessionLogId' => $ses_log_id, + 'SessionLogId' => $sesion_log_id, ); - $changelog_table = $this->Application->getUnitOption('change-log', 'TableName'); - $sessionlog_table = $this->Application->getUnitOption('session-log', 'TableName'); + $change_log_table = $this->Application->getUnitOption('change-log', 'TableName'); foreach ($changes as $rec) { - $this->Conn->doInsert(array_merge($rec, $add_fields), $changelog_table); + $this->Conn->doInsert(array_merge($rec, $add_fields), $change_log_table); } - $sql = 'UPDATE '.$sessionlog_table.' - SET AffectedItems = AffectedItems + '.count($changes).' - WHERE SessionLogId = '.$ses_log_id; + $sql = 'UPDATE ' . $this->Application->getUnitOption('session-log', 'TableName') . ' + SET AffectedItems = AffectedItems + ' . count($changes) . ' + WHERE SessionLogId = ' . $sesion_log_id; $this->Conn->Query($sql); - - $this->Application->RemoveVar($changes_var_name); } - /** * Cancels edit * Removes all temp tables and clears selected ids @@ -1628,6 +1639,9 @@ $this->clearSelectedIDs($event); $event->redirect_params = Array('opener'=>'u'); $this->Application->RemoveVar($event->getPrefixSpecial().'_modified'); + + $changes_var_name = $this->Prefix . '_changes_' . $this->Application->GetTopmostWid($this->Prefix); + $this->Application->RemoveVar($changes_var_name); } @@ -1782,6 +1796,9 @@ $this->Application->SetVar($event->getPrefixSpecial().'_id', 0); $this->Application->SetVar($event->getPrefixSpecial().'_PreCreate', 1); + $changes_var_name = $this->Prefix . '_changes_' . $this->Application->GetTopmostWid($this->Prefix); + $this->Application->RemoveVar($changes_var_name); + $event->redirect = false; }