Clean code: No more fetch to clone

This commit is contained in:
Laurent Destailleur 2022-08-11 23:59:25 +02:00
parent 0f3ed254fd
commit 9bc6c41ca7
14 changed files with 19 additions and 25 deletions

View File

@ -278,7 +278,7 @@ if (empty($reshook)) {
} }
// Create new object // Create new object
if ($result > 0 && !$error) { if ($result > 0 && !$error) {
$object->oldcopy = clone $object; $object->oldcopy = dol_clone($object);
// Change values // Change values
$object->civility_id = trim(GETPOST("civility_id", 'alphanohtml')); $object->civility_id = trim(GETPOST("civility_id", 'alphanohtml'));

View File

@ -170,7 +170,8 @@ if ($action == 'add' && $user->rights->adherent->configurer) {
if ($action == 'update' && $user->rights->adherent->configurer) { if ($action == 'update' && $user->rights->adherent->configurer) {
$object->fetch($rowid); $object->fetch($rowid);
$object->oldcopy = clone $object; $object->oldcopy = dol_clone($object);
$object->label= trim($label); $object->label= trim($label);
$object->morphy = trim($morphy); $object->morphy = trim($morphy);
$object->status = (int) $status; $object->status = (int) $status;

View File

@ -677,7 +677,7 @@ if (empty($reshook) && $action == 'update') {
$object->fetch($id); $object->fetch($id);
$object->fetch_optionals(); $object->fetch_optionals();
$object->fetch_userassigned(); $object->fetch_userassigned();
$object->oldcopy = clone $object; $object->oldcopy = dol_clone($object);
// Clean parameters // Clean parameters
if ($fulldayevent) { if ($fulldayevent) {
@ -927,7 +927,7 @@ if (empty($reshook) && $action == 'confirm_delete' && GETPOST("confirm") == 'yes
$object->fetch($id); $object->fetch($id);
$object->fetch_optionals(); $object->fetch_optionals();
$object->fetch_userassigned(); $object->fetch_userassigned();
$object->oldcopy = clone $object; $object->oldcopy = dol_clone($object);
if ($user->rights->agenda->myactions->delete if ($user->rights->agenda->myactions->delete
|| $user->rights->agenda->allactions->delete) { || $user->rights->agenda->allactions->delete) {

View File

@ -212,7 +212,7 @@ if (GETPOST("viewperuser", 'alpha') || $mode == 'show_peruser') {
$event->fetch($actionid); $event->fetch($actionid);
$event->fetch_optionals(); $event->fetch_optionals();
$event->fetch_userassigned(); $event->fetch_userassigned();
$event->oldcopy = clone $event; $event->oldcopy = dol_clone($event);
$result = $event->delete(); $result = $event->delete();
} }

View File

@ -189,7 +189,7 @@ if ($action == 'delete_action' && $user->rights->agenda->delete) {
$event->fetch($actionid); $event->fetch($actionid);
$event->fetch_optionals(); $event->fetch_optionals();
$event->fetch_userassigned(); $event->fetch_userassigned();
$event->oldcopy = clone $event; $event->oldcopy = dol_clone($event);
$result = $event->delete(); $result = $event->delete();
} }

View File

@ -196,7 +196,7 @@ if ($action == 'delete_action' && $user->rights->agenda->delete) {
$event->fetch($actionid); $event->fetch($actionid);
$event->fetch_optionals(); $event->fetch_optionals();
$event->fetch_userassigned(); $event->fetch_userassigned();
$event->oldcopy = clone $event; $event->oldcopy = dol_clone($event);
$result = $event->delete(); $result = $event->delete();
} }

View File

@ -60,7 +60,7 @@ if ($action == 'update' && !GETPOST("cancel") && $user->rights->societe->contact
$result = $object->update_perso($id, $user); $result = $object->update_perso($id, $user);
if ($result > 0) { if ($result > 0) {
$object->oldcopy = clone $object; $object->oldcopy = dol_clone($object);
// Logo/Photo save // Logo/Photo save
$dir = $conf->societe->dir_output.'/contact/'.get_exdir($object->id, 0, 0, 1, $object, 'contact').'/photos'; $dir = $conf->societe->dir_output.'/contact/'.get_exdir($object->id, 0, 0, 1, $object, 'contact').'/photos';

View File

@ -3135,8 +3135,7 @@ class ContratLigne extends CommonObjectLine
$this->db->begin(); $this->db->begin();
$this->oldcopy = new ContratLigne($this->db); $this->oldcopy = dol_clone($this);
$this->oldcopy->fetch($this->id);
// Update request // Update request
$sql = "UPDATE ".MAIN_DB_PREFIX."contratdet SET"; $sql = "UPDATE ".MAIN_DB_PREFIX."contratdet SET";

View File

@ -71,19 +71,19 @@ class Comment extends CommonObject
public $fk_user_modif; public $fk_user_modif;
/** /**
* @var int Entity * @var int Entity
*/ */
public $entity; public $entity;
/** /**
* @var string import key * @var string Import key
*/ */
public $import_key; public $import_key;
public $comments = array(); public $comments = array();
/** /**
* @var Comment Object oldcopy * @var Comment Object oldcopy
*/ */
public $oldcopy; public $oldcopy;

View File

@ -533,7 +533,7 @@ class Fichinter extends CommonObject
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) { if ($resql) {
if (!$error) { if (!$error) {
$this->oldcopy = clone $this; $this->oldcopy = dol_clone($this);
} }
if (!$error) { if (!$error) {
@ -1422,7 +1422,7 @@ class Fichinter extends CommonObject
} }
if (!$error) { if (!$error) {
$this->oldcopy = clone $this; $this->oldcopy = dol_clone($this);
$this->ref_client = $ref_client; $this->ref_client = $ref_client;
} }

View File

@ -1051,9 +1051,7 @@ class Product extends CommonObject
if ($result >= 0) { if ($result >= 0) {
if (empty($this->oldcopy)) { if (empty($this->oldcopy)) {
$org = new self($this->db); $this->oldcopy = dol_clone($this);
$org->fetch($this->id);
$this->oldcopy = $org;
} }
// Test if batch management is activated on existing product // Test if batch management is activated on existing product

View File

@ -388,9 +388,7 @@ class Productlot extends CommonObject
// Put here code to add a control on parameters values // Put here code to add a control on parameters values
if (empty($this->oldcopy)) { if (empty($this->oldcopy)) {
$org = new self($this->db); $this->oldcopy = dol_clone($this);
$org->fetch($this->id);
$this->oldcopy = $org;
} }
// Update request // Update request

View File

@ -263,9 +263,7 @@ class Dolresource extends CommonObject
} }
if (empty($this->oldcopy)) { if (empty($this->oldcopy)) {
$org = new self($this->db); $this->oldcopy = dol_clone($this);
$org->fetch($this->id);
$this->oldcopy = $org;
} }
// Update request // Update request

View File

@ -149,7 +149,7 @@ if ($action == 'update' && !$cancel && $permissiontoaddbankaccount) {
{ {
$objectuser->fetch($id); $objectuser->fetch($id);
$objectuser->oldcopy = clone $objectuser; $objectuser->oldcopy = dol_clone($objectuser);
$db->begin(); $db->begin();