Index: branches/5.1.x/core/kernel/db/dbitem.php =================================================================== diff -u -N -r13545 -r13750 --- branches/5.1.x/core/kernel/db/dbitem.php (.../dbitem.php) (revision 13545) +++ branches/5.1.x/core/kernel/db/dbitem.php (.../dbitem.php) (revision 13750) @@ -1,6 +1,6 @@ Conn->getAffectedRows(); - if (!$system_update && $affected == 1) { + $affected_rows = $this->Conn->getAffectedRows(); + + if (!$system_update && ($affected_rows > 0)) { $this->setModifiedFlag(clUPDATE); } $this->saveCustomFields(); - $this->raiseEvent('OnAfterItemUpdate'); + + if ($affected_rows > 0) { + $this->raiseEvent('OnAfterItemUpdate'); + } + + $this->OriginalFieldValues = $this->FieldValues; $this->Loaded = true; if ($this->mode != 't') { @@ -948,6 +954,8 @@ return false; } + $this->OriginalFieldValues = $this->FieldValues; + $insert_id = $this->Conn->getInsertID(); if ($insert_id == 0) { // insert into temp table (id is not auto-increment field) @@ -963,6 +971,12 @@ if ($this->mode != 't') { $this->Application->resetCounters($this->TableName); } + + if ($this->IsTempTable() && ($this->Application->GetTopmostPrefix($this->Prefix) != $this->Prefix)) { + // temp table + subitem = set negative id + $this->setTempID(); + } + $this->raiseEvent('OnAfterItemCreate'); $this->Loaded = true; @@ -1513,15 +1527,7 @@ $cdata->SetDBField($ml_formatter->LangFieldName('cust_'.$custom_id, $force_primary), $this->GetDBField('cust_'.$custom_name)); } - if ($cdata->isLoaded()) { - $ret = $cdata->Update(); - } - else { - $ret = $cdata->Create(); - if ($cdata->mode == 't') $cdata->setTempID(); - } - - return $ret; + return $cdata->isLoaded() ? $cdata->Update() : $cdata->Create(); } /**