diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php index 0f153f57e01..c1ff111b9c4 100644 --- a/htdocs/adherents/card.php +++ b/htdocs/adherents/card.php @@ -217,7 +217,7 @@ if (empty($reshook)) { if ($result > 0) { // Creation user $nuser = new User($db); - $tmpuser = dol_clone($object); + $tmpuser = dol_clone($object, 2); if (GETPOST('internalorexternal', 'aZ09') == 'internal') { $tmpuser->fk_soc = 0; } diff --git a/htdocs/adherents/list.php b/htdocs/adherents/list.php index 68e52e148a7..f70433f2c9d 100644 --- a/htdocs/adherents/list.php +++ b/htdocs/adherents/list.php @@ -315,9 +315,9 @@ if (empty($reshook)) { foreach ($toselect as $idtoclose) { $tmpmember->fetch($idtoclose); - if (!empty($tmpmember->fk_soc)) { + if (!empty($tmpmember->socid)) { $nuser = new User($db); - $tmpuser = dol_clone($tmpmember); + $tmpuser = dol_clone($tmpmember, 2); $result = $nuser->create_from_member($tmpuser, $tmpmember->login); diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index f13654b0a31..a383630cd67 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -222,7 +222,7 @@ if (empty($reshook)) { if (!($socid > 0)) { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('IdThirdParty')), null, 'errors'); } else { - $objectutil = dol_clone($object, 1); // To avoid to denaturate loaded object when setting some properties for clone. We use native clone to keep this->db valid. + $objectutil = dol_clone($object, 1); // We use a clone to avoid to denaturate loaded object when setting some properties for clone. We use native clone to keep this->db valid. '@phan-var-force Facture $objectutil'; $objectutil->date = dol_mktime(12, 0, 0, GETPOSTINT('newdatemonth'), GETPOSTINT('newdateday'), GETPOSTINT('newdateyear')); diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 23890c825c7..85e217d58c2 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -719,7 +719,7 @@ if (empty($reshook)) { } $objectline->fetch_optionals(); - $objectline->oldcopy = dol_clone($objectline); + $objectline->oldcopy = dol_clone($objectline, 2); } $db->begin(); diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 1b4d4261a8a..3234107fd0f 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -1425,7 +1425,7 @@ class Contrat extends CommonObject } //if (isset($this->extraparams)) $this->extraparams=trim($this->extraparams); - // $this->oldcopy should have been set by the caller of update + // $this->oldcopy must have been set by the caller of update // Update request $sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET"; @@ -3543,7 +3543,8 @@ 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); + dol_syslog("this->oldcopy should have been set by the caller of update (here properties were already modified)", LOG_WARNING); + $this->oldcopy = dol_clone($this, 2); } $this->db->begin(); diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 1cf74e70817..54779d16536 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -1595,16 +1595,17 @@ if (!$error && ($massaction == 'approveleave' || ($action == 'approveleave' && $ foreach ($toselect as $toselectid) { $result = $objecttmp->fetch($toselectid); if ($result > 0) { - if ($objecttmp->statut != Holiday::STATUS_VALIDATED) { + if ($objecttmp->status != Holiday::STATUS_VALIDATED) { setEventMessages($langs->trans('StatusOfRefMustBe', $objecttmp->ref, $langs->transnoentitiesnoconv('Validated')), null, 'warnings'); continue; } if ($user->id == $objecttmp->fk_validator) { - $objecttmp->oldcopy = dol_clone($objecttmp); + $objecttmp->oldcopy = dol_clone($objecttmp, 2); $objecttmp->date_valid = dol_now(); $objecttmp->fk_user_valid = $user->id; - $objecttmp->statut = Holiday::STATUS_APPROVED; + $objecttmp->status = Holiday::STATUS_APPROVED; + $objecttmp->statut = $objecttmp->status; // deprecated $verif = $objecttmp->approve($user); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 003f3989651..921d483106c 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -10060,7 +10060,8 @@ abstract class CommonObject // $this->oldcopy should have been set by the caller of update //if (empty($this->oldcopy)) { - // $this->oldcopy = dol_clone($this); + // dol_syslog("this->oldcopy should have been set by the caller of update (here properties were already modified)", LOG_WARNING); + // $this->oldcopy = dol_clone($this, 2); //} $fieldvalues = $this->setSaveQuery(); diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index df1073ecd30..def0ae45bc2 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1407,7 +1407,7 @@ function dol_get_object_properties($obj, $properties = []) /** * Create a clone of instance of object (new instance with same value for each properties) - * With native = 0: Property that are reference are different memory area in the new object (full isolation clone). This means $this->db of new object may not be valid. + * With native = 0: Property that are references are different memory area in the new object (full isolation clone). This means $this->object of new object may not be valid (except this->db that is voluntarly kept). * With native = 1: Use PHP clone. Property that are reference are same pointer. This means $this->db of new object is still valid but point to same this->db than original object. * With native = 2: Property that are reference are different memory area in the new object (full isolation clone). Only scalar and array values are cloned. This means method are not availables and $this->db of new object is not valid. * diff --git a/htdocs/core/modules/export/export_excel2007.modules.php b/htdocs/core/modules/export/export_excel2007.modules.php index 23dd1e5b71b..d154965fde7 100644 --- a/htdocs/core/modules/export/export_excel2007.modules.php +++ b/htdocs/core/modules/export/export_excel2007.modules.php @@ -194,7 +194,7 @@ class ExportExcel2007 extends ModeleExports public function open_file($file, $outputlangs) { // phpcs:enable - global $user, $conf, $langs; + global $user, $langs; dol_syslog(get_class($this)."::open_file file=".$file); $this->file = $file; @@ -326,7 +326,8 @@ class ExportExcel2007 extends ModeleExports if (empty($alias)) { dol_print_error(null, 'Bad value for field with code='.$code.'. Try to redefine export.'); } - $newvalue = $objp->$alias; + + $newvalue = property_exists($objp, $alias) ? $objp->$alias : ''; $newvalue = $this->excel_clean($newvalue); $typefield = isset($array_types[$code]) ? $array_types[$code] : ''; diff --git a/htdocs/cron/card.php b/htdocs/cron/card.php index 15c6b847166..9535232386f 100644 --- a/htdocs/cron/card.php +++ b/htdocs/cron/card.php @@ -230,7 +230,7 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd) { if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) { setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors'); } else { - $objectutil = dol_clone($object, 1); // To avoid to denaturate loaded object when setting some properties for clone or if createFromClone modifies the object. We use native clone to keep this->db valid. + $objectutil = dol_clone($object, 1); // We clone to avoid to denaturate loaded object when setting some properties for clone or if createFromClone modifies the object. We use the native clone to keep this->db valid. $result = $objectutil->createFromClone($user, (($object->id > 0) ? $object->id : $id)); if (is_object($result) || $result > 0) { diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php index 0b6d2aaaef9..cf8435ef599 100644 --- a/htdocs/holiday/class/holiday.class.php +++ b/htdocs/holiday/class/holiday.class.php @@ -451,8 +451,8 @@ class Holiday extends CommonObject $this->date_debut_gmt = $this->db->jdate($obj->date_debut, 1); $this->date_fin_gmt = $this->db->jdate($obj->date_fin, 1); $this->halfday = $obj->halfday; - $this->statut = $obj->status; $this->status = $obj->status; + $this->statut = $obj->status; // deprecated $this->fk_validator = $obj->fk_validator; $this->date_valid = $this->db->jdate($obj->date_valid); $this->fk_user_valid = $obj->fk_user_valid; @@ -880,7 +880,6 @@ class Holiday extends CommonObject */ public function approve($user = null, $notrigger = 0) { - global $conf, $langs; $error = 0; $checkBalance = getDictionaryValue('c_holiday_types', 'block_if_negative', $this->fk_type); @@ -896,9 +895,7 @@ class Holiday extends CommonObject // Update request $sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET"; - $sql .= " description= '".$this->db->escape($this->description)."',"; - if (!empty($this->date_debut)) { $sql .= " date_debut = '".$this->db->idate($this->date_debut)."',"; } else { diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index a6997438c02..68279242c2d 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -1839,11 +1839,11 @@ class User extends CommonObject public function create_from_member($member, $login = '') { // phpcs:enable - global $conf, $user, $langs; + global $user; // Set properties on new user $this->admin = 0; - $this->civility_code = $member->civility_id; + $this->civility_code = $member->civility_code; $this->lastname = $member->lastname; $this->firstname = $member->firstname; $this->gender = $member->gender;