Clean code using of oldcopy
This commit is contained in:
parent
35de9843d0
commit
f17f22755c
@ -3132,11 +3132,13 @@ class ContratLigne extends CommonObjectLine
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// $this->oldcopy should have been set by the caller of update (here properties were already modified)
|
||||||
|
if (empty($this->oldcopy)) {
|
||||||
|
$this->oldcopy = dol_clone($this);
|
||||||
|
}
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
$this->oldcopy = dol_clone($this);
|
|
||||||
|
|
||||||
// Update request
|
// Update request
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."contratdet SET";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."contratdet SET";
|
||||||
$sql .= " fk_contrat=".((int) $this->fk_contrat).",";
|
$sql .= " fk_contrat=".((int) $this->fk_contrat).",";
|
||||||
|
|||||||
@ -8918,11 +8918,12 @@ abstract class CommonObject
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to prepare a part of the query for insert.
|
* Function to prepare a part of the query for insert by returning an array with all properties of object.
|
||||||
* Note $this->${field} are set by the page that make the createCommon or the updateCommon.
|
|
||||||
* $this->${field} should be a clean value. The page can run
|
|
||||||
*
|
*
|
||||||
* @return array
|
* Note $this->${field} are set by the page that make the createCommon() or the updateCommon().
|
||||||
|
* $this->${field} should be a clean and string value (so date are formated for SQL insert).
|
||||||
|
*
|
||||||
|
* @return array Array with all values of each properties to update
|
||||||
*/
|
*/
|
||||||
protected function setSaveQuery()
|
protected function setSaveQuery()
|
||||||
{
|
{
|
||||||
@ -8950,7 +8951,7 @@ abstract class CommonObject
|
|||||||
}
|
}
|
||||||
} elseif ($this->isInt($info) || $this->isFloat($info)) {
|
} elseif ($this->isInt($info) || $this->isFloat($info)) {
|
||||||
if ($field == 'entity' && is_null($this->{$field})) {
|
if ($field == 'entity' && is_null($this->{$field})) {
|
||||||
$queryarray[$field] = $conf->entity;
|
$queryarray[$field] = ((int) $conf->entity);
|
||||||
} else {
|
} else {
|
||||||
// $this->{$field} may be null, '', 0, '0', 123, '123'
|
// $this->{$field} may be null, '', 0, '0', 123, '123'
|
||||||
if ((isset($this->{$field}) && $this->{$field} != '') || !empty($info['notnull'])) {
|
if ((isset($this->{$field}) && $this->{$field} != '') || !empty($info['notnull'])) {
|
||||||
@ -9378,6 +9379,11 @@ abstract class CommonObject
|
|||||||
|
|
||||||
$now = dol_now();
|
$now = dol_now();
|
||||||
|
|
||||||
|
// $this->oldcopy should have been set by the caller of update
|
||||||
|
//if (empty($this->oldcopy)) {
|
||||||
|
// $this->oldcopy = dol_clone($this);
|
||||||
|
//}
|
||||||
|
|
||||||
$fieldvalues = $this->setSaveQuery();
|
$fieldvalues = $this->setSaveQuery();
|
||||||
|
|
||||||
if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) {
|
if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) {
|
||||||
@ -9423,6 +9429,7 @@ abstract class CommonObject
|
|||||||
$sql = 'UPDATE '.$this->db->prefix().$this->table_element.' SET '.implode(', ', $tmp).' WHERE rowid='.((int) $this->id);
|
$sql = 'UPDATE '.$this->db->prefix().$this->table_element.' SET '.implode(', ', $tmp).' WHERE rowid='.((int) $this->id);
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
if (!$error) {
|
if (!$error) {
|
||||||
$res = $this->db->query($sql);
|
$res = $this->db->query($sql);
|
||||||
if (!$res) {
|
if (!$res) {
|
||||||
|
|||||||
@ -524,6 +524,8 @@ class Fichinter extends CommonObject
|
|||||||
|
|
||||||
dol_syslog(get_class($this)."::setDraft", LOG_DEBUG);
|
dol_syslog(get_class($this)."::setDraft", LOG_DEBUG);
|
||||||
|
|
||||||
|
$this->oldcopy = dol_clone($this);
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."fichinter";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."fichinter";
|
||||||
@ -532,10 +534,6 @@ class Fichinter extends CommonObject
|
|||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
if (!$error) {
|
|
||||||
$this->oldcopy = dol_clone($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$error) {
|
if (!$error) {
|
||||||
// Call trigger
|
// Call trigger
|
||||||
$result = $this->call_trigger('FICHINTER_UNVALIDATE', $user);
|
$result = $this->call_trigger('FICHINTER_UNVALIDATE', $user);
|
||||||
@ -1411,6 +1409,8 @@ class Fichinter extends CommonObject
|
|||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
|
$this->oldcopy = dol_clone($this);
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ref_client = ".(empty($ref_client) ? 'NULL' : "'".$this->db->escape($ref_client)."'");
|
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ref_client = ".(empty($ref_client) ? 'NULL' : "'".$this->db->escape($ref_client)."'");
|
||||||
$sql .= " WHERE rowid = ".((int) $this->id);
|
$sql .= " WHERE rowid = ".((int) $this->id);
|
||||||
|
|
||||||
@ -1422,7 +1422,6 @@ class Fichinter extends CommonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$error) {
|
if (!$error) {
|
||||||
$this->oldcopy = dol_clone($this);
|
|
||||||
$this->ref_client = $ref_client;
|
$this->ref_client = $ref_client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1050,6 +1050,7 @@ class Product extends CommonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($result >= 0) {
|
if ($result >= 0) {
|
||||||
|
// $this->oldcopy should have been set by the caller of update (here properties were already modified)
|
||||||
if (empty($this->oldcopy)) {
|
if (empty($this->oldcopy)) {
|
||||||
$this->oldcopy = dol_clone($this);
|
$this->oldcopy = dol_clone($this);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -384,9 +384,7 @@ class Productlot extends CommonObject
|
|||||||
$this->import_key = trim($this->import_key);
|
$this->import_key = trim($this->import_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check parameters
|
// $this->oldcopy should have been set by the caller of update (here properties were already modified)
|
||||||
// Put here code to add a control on parameters values
|
|
||||||
|
|
||||||
if (empty($this->oldcopy)) {
|
if (empty($this->oldcopy)) {
|
||||||
$this->oldcopy = dol_clone($this);
|
$this->oldcopy = dol_clone($this);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -262,6 +262,7 @@ class Dolresource extends CommonObject
|
|||||||
$this->country_id = 0;
|
$this->country_id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// $this->oldcopy should have been set by the caller of update (here properties were already modified)
|
||||||
if (empty($this->oldcopy)) {
|
if (empty($this->oldcopy)) {
|
||||||
$this->oldcopy = dol_clone($this);
|
$this->oldcopy = dol_clone($this);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -870,9 +870,10 @@ class Ticket extends CommonObject
|
|||||||
global $conf, $langs, $hookmanager;
|
global $conf, $langs, $hookmanager;
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
if (empty($notrigger)) {
|
// $this->oldcopy should have been set by the caller of update (here properties were already modified)
|
||||||
$this->oldcopy = dol_clone($this, 1);
|
//if (empty($this->oldcopy)) {
|
||||||
}
|
// $this->oldcopy = dol_clone($this);
|
||||||
|
//}
|
||||||
|
|
||||||
// Clean parameters
|
// Clean parameters
|
||||||
if (isset($this->ref)) {
|
if (isset($this->ref)) {
|
||||||
@ -1463,13 +1464,12 @@ class Ticket extends CommonObject
|
|||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
if ($this->statut != self::STATUS_CANCELED) { // no closed
|
if ($this->statut != self::STATUS_CANCELED) { // no closed
|
||||||
if (empty($notrigger)) {
|
$this->oldcopy = dol_clone($this);
|
||||||
$this->oldcopy = dol_clone($this, 1);
|
|
||||||
}
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."ticket";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."ticket";
|
||||||
$sql .= " SET fk_statut = ".Ticket::STATUS_READ.", date_read='".$this->db->idate(dol_now())."'";
|
$sql .= " SET fk_statut = ".Ticket::STATUS_READ.", date_read = '".$this->db->idate(dol_now())."'";
|
||||||
$sql .= " WHERE rowid = ".((int) $this->id);
|
$sql .= " WHERE rowid = ".((int) $this->id);
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::markAsRead");
|
dol_syslog(get_class($this)."::markAsRead");
|
||||||
@ -1518,10 +1518,11 @@ class Ticket extends CommonObject
|
|||||||
global $conf, $langs;
|
global $conf, $langs;
|
||||||
|
|
||||||
$error = 0;
|
$error = 0;
|
||||||
$this->db->begin();
|
|
||||||
|
|
||||||
$this->oldcopy = dol_clone($this);
|
$this->oldcopy = dol_clone($this);
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."ticket";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."ticket";
|
||||||
if ($id_assign_user > 0) {
|
if ($id_assign_user > 0) {
|
||||||
$sql .= " SET fk_user_assign=".((int) $id_assign_user).", fk_statut = ".Ticket::STATUS_ASSIGNED;
|
$sql .= " SET fk_user_assign=".((int) $id_assign_user).", fk_statut = ".Ticket::STATUS_ASSIGNED;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user