Index: branches/5.1.x/core/kernel/db/dbitem.php =================================================================== diff -u -N -r12657 -r13086 --- branches/5.1.x/core/kernel/db/dbitem.php (.../dbitem.php) (revision 12657) +++ branches/5.1.x/core/kernel/db/dbitem.php (.../dbitem.php) (revision 13086) @@ -1,6 +1,6 @@ IDField => $this->ID); + if (!isset($keys_hash)) { + $keys_hash = Array ($this->IDField => $this->ID); + } $ret = ''; - foreach($keys_hash as $field => $value) - { + + foreach ($keys_hash as $field => $value) { if (!preg_match('/\./', $field)) { - $ret .= '(`'.$this->TableName.'`.'.$field.' = '.$this->Conn->qstr($value).') AND '; + $ret .= '(`' . $this->TableName . '`.' . $field . ' = ' . $this->Conn->qstr($value) . ') AND '; } else { - $ret .= '('.$field.' = '.$this->Conn->qstr($value).') AND '; + $ret .= '(' . $field . ' = ' . $this->Conn->qstr($value) . ') AND '; } } - return preg_replace('/(.*) AND $/', '\\1', $ret); + return substr($ret, 0, -5); } /** @@ -472,10 +481,6 @@ return false; } - if (!$this->raiseEvent('OnAfterItemValidate')) { - return false; - } - if (!$this->FieldValues) { // nothing to update return true; @@ -561,6 +566,9 @@ return true; } + // will apply any custom validation to the item + $this->raiseEvent('OnBeforeItemValidate'); + $global_res = true; foreach ($this->Fields as $field => $params) { $res = $this->ValidateField($field); @@ -577,6 +585,11 @@ $this->Application->Debugger->dumpVars($this->FieldErrors); } + if ($global_res) { + // no validation errors + $this->raiseEvent('OnAfterItemValidate'); + } + return $global_res; } @@ -822,10 +835,6 @@ return false; } - if (!$this->raiseEvent('OnAfterItemValidate')) { - return false; - } - if (is_int($force_id)) { $this->FieldValues[$this->IDField] = $force_id; } @@ -1081,7 +1090,7 @@ function setModifiedFlag($mode = null) { $main_prefix = $this->Application->GetTopmostPrefix($this->Prefix); - $this->Application->StoreVar($main_prefix.'_modified', '1', !$this->Application->IsAdmin()); + $this->Application->StoreVar($main_prefix.'_modified', '1', !$this->Application->isAdmin); if ($this->ShouldLogChanges()) { $this->LogChanges($main_prefix, $mode); @@ -1255,7 +1264,7 @@ function saveCustomFields() { - if (!$this->customFields) { + if (!$this->customFields || $this->inCloning) { return true; }