Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/kernel/db/dbitem.php
Show First 20 Lines • Show All 763 Lines • ▼ Show 20 Line(s) | |||||
// there was and sql error | // there was and sql error | ||||
$this->SetError($this->IDField, 'sql_error', '#' . $this->Conn->getErrorCode() . ': ' . $this->Conn->getErrorMsg()); | $this->SetError($this->IDField, 'sql_error', '#' . $this->Conn->getErrorCode() . ': ' . $this->Conn->getErrorMsg()); | ||||
return false; | return false; | ||||
} | } | ||||
$affected_rows = $this->Conn->getAffectedRows(); | $affected_rows = $this->Conn->getAffectedRows(); | ||||
if ( !$system_update && ($affected_rows > 0) ) { | if ( !$system_update && ($affected_rows > 0) ) { | ||||
$this->setModifiedFlag(ChangeLog::UPDATE); | $this->setModifiedFlag(ChangeLog::UPDATE, $update_fields); | ||||
} | } | ||||
$this->saveCustomFields(); | $this->saveCustomFields(); | ||||
$this->raiseEvent('OnAfterItemUpdate'); | $this->raiseEvent('OnAfterItemUpdate'); | ||||
// Preserve OriginalFieldValues during recursive Update() method calls. | // Preserve OriginalFieldValues during recursive Update() method calls. | ||||
$this->Loaded = true; | $this->Loaded = true; | ||||
▲ Show 20 Lines • Show All 399 Lines • ▼ Show 20 Line(s) | |||||
} | } | ||||
$this->setPendingActions($pending_actions, $new_id); | $this->setPendingActions($pending_actions, $new_id); | ||||
} | } | ||||
/** | /** | ||||
* Set's modification flag for main prefix of current prefix to true | * Set's modification flag for main prefix of current prefix to true | ||||
* | * | ||||
* @param int $mode | * @param integer $mode Mode. | ||||
* @access private | * @param array $update_fields Update fields. | ||||
* | |||||
* @return void | |||||
*/ | */ | ||||
public function setModifiedFlag($mode = null) | public function setModifiedFlag($mode = null, array $update_fields = null) | ||||
{ | { | ||||
$main_prefix = $this->Application->GetTopmostPrefix($this->Prefix); | $main_prefix = $this->Application->GetTopmostPrefix($this->Prefix); | ||||
$this->Application->StoreVar($main_prefix . '_modified', '1', true); // true for optional | $this->Application->StoreVar($main_prefix . '_modified', '1', true); // true for optional | ||||
if ($this->ShouldLogChanges(true)) { | if ( $this->ShouldLogChanges(true) ) { | ||||
$this->LogChanges($main_prefix, $mode); | $this->LogChanges($main_prefix, $mode, $update_fields); | ||||
if (!$this->IsTempTable()) { | if (!$this->IsTempTable()) { | ||||
/** @var kDBEventHandler $handler */ | /** @var kDBEventHandler $handler */ | ||||
$handler = $this->Application->recallObject($this->Prefix . '_EventHandler'); | $handler = $this->Application->recallObject($this->Prefix . '_EventHandler'); | ||||
$ses_var_name = $main_prefix . '_changes_' . $this->Application->GetTopmostWid($this->Prefix); | $ses_var_name = $main_prefix . '_changes_' . $this->Application->GetTopmostWid($this->Prefix); | ||||
$handler->SaveLoggedChanges($ses_var_name, $this->ShouldLogChanges()); | $handler->SaveLoggedChanges($ses_var_name, $this->ShouldLogChanges()); | ||||
} | } | ||||
Show All 11 Lines | |||||
if (!isset($log_changes)) { | if (!isset($log_changes)) { | ||||
// specific logging mode no forced -> use global logging settings | // specific logging mode no forced -> use global logging settings | ||||
$log_changes = $this->Application->getUnitOption($this->Prefix, 'LogChanges') || $this->Application->ConfigValue('UseChangeLog'); | $log_changes = $this->Application->getUnitOption($this->Prefix, 'LogChanges') || $this->Application->ConfigValue('UseChangeLog'); | ||||
} | } | ||||
return $log_changes && !$this->Application->getUnitOption($this->Prefix, 'ForceDontLogChanges'); | return $log_changes && !$this->Application->getUnitOption($this->Prefix, 'ForceDontLogChanges'); | ||||
} | } | ||||
protected function LogChanges($main_prefix, $mode) | protected function LogChanges($main_prefix, $mode, $update_fields = null) | ||||
{ | { | ||||
if ( !$mode ) { | if ( !$mode ) { | ||||
return ; | return ; | ||||
} | } | ||||
$ses_var_name = $main_prefix . '_changes_' . $this->Application->GetTopmostWid($this->Prefix); | $ses_var_name = $main_prefix . '_changes_' . $this->Application->GetTopmostWid($this->Prefix); | ||||
$changes = $this->Application->RecallVar($ses_var_name); | $changes = $this->Application->RecallVar($ses_var_name); | ||||
$changes = $changes ? unserialize($changes) : Array (); | $changes = $changes ? unserialize($changes) : Array (); | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
$master_id = $this->getParentId('auto', true); | $master_id = $this->getParentId('auto', true); | ||||
} | } | ||||
$fields_hash['MasterId'] = $master_id; | $fields_hash['MasterId'] = $master_id; | ||||
} | } | ||||
switch ( $mode ) { | switch ( $mode ) { | ||||
case ChangeLog::UPDATE: | case ChangeLog::UPDATE: | ||||
$to_save = array_merge($this->GetTitleField(), $this->GetChangedFields()); | $changed_fields = $this->GetChangedFields(); | ||||
if ( $update_fields ) { | |||||
$changed_fields = array_intersect_key( | |||||
$changed_fields, | |||||
array_combine($update_fields, $update_fields) | |||||
); | |||||
} | |||||
$to_save = array_merge($this->GetTitleField(), $changed_fields); | |||||
break; | break; | ||||
case ChangeLog::CREATE: | case ChangeLog::CREATE: | ||||
$to_save = $this->GetTitleField(); | $to_save = $this->GetTitleField(); | ||||
break; | break; | ||||
case ChangeLog::DELETE: | case ChangeLog::DELETE: | ||||
$to_save = array_merge($this->GetTitleField(), $this->GetRealFields()); | $to_save = array_merge($this->GetTitleField(), $this->GetRealFields()); | ||||
▲ Show 20 Lines • Show All 312 Lines • Show Last 20 Lines |