diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index e3c3dff2b7c..bf05df918ce 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2089,10 +2089,6 @@ abstract class CommonObject $id_field = 'rowid'; } - $error = 0; - - $this->db->begin(); - // Special case if ($table == 'product' && $field == 'note_private') { $field = 'note'; @@ -2101,6 +2097,32 @@ abstract class CommonObject $fk_user_field = 'fk_user_mod'; } + if ($trigkey) { + $oldvalue = null; + + $sql = "SELECT " . $field; + $sql .= " FROM " . MAIN_DB_PREFIX . $table; + $sql .= " WHERE " . $id_field . " = " . ((int) $id); + + $resql = $this->db->query($sql); + if ($resql) { + if ($obj = $this->db->fetch_object($resql)) { + if ($format == 'date') { + $oldvalue = $this->db->jdate($obj->$field); + } else { + $oldvalue = $obj->$field; + } + } + } else { + $this->error = $this->db->lasterror(); + return -1; + } + } + + $error = 0; + + $this->db->begin(); + $sql = "UPDATE ".$this->db->prefix().$table." SET "; if ($format == 'text') { @@ -2133,6 +2155,11 @@ abstract class CommonObject } else { $result = $this->fetchCommon($id); } + $this->oldcopy = clone $this; + if (property_exists($this->oldcopy, $field)) { + $this->oldcopy->$field = $oldvalue; + } + if ($result >= 0) { $result = $this->call_trigger($trigkey, (!empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors }