From 153cd38c78d2ef9dcd8ae00b59f8ee83c8faf4dd Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 27 Jan 2022 10:57:20 +0100 Subject: [PATCH] FIX uniformize and fix code --- htdocs/core/class/commonobject.class.php | 8 ++-- htdocs/core/class/html.formmail.class.php | 2 +- htdocs/core/class/infobox.class.php | 46 +++++++++++------------ htdocs/core/class/link.class.php | 12 +++--- htdocs/core/class/translate.class.php | 6 +-- 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index d2e1227ba75..962ad8450b1 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -536,7 +536,7 @@ abstract class CommonObject global $db, $conf; $sql = "SELECT rowid, ref, ref_ext"; - $sql .= " FROM ".$this->db->prefix().$element; + $sql .= " FROM ".$db->prefix().$element; $sql .= " WHERE entity IN (".getEntity($element).")"; if ($id > 0) { @@ -4105,7 +4105,7 @@ abstract class CommonObject global $db; - $sql = "SELECT ".$field_select." FROM ".$this->db->prefix().$table_element." WHERE ".$field_where." = ".((int) $fk_object_where); + $sql = "SELECT ".$field_select." FROM ".$db->prefix().$table_element." WHERE ".$field_where." = ".((int) $fk_object_where); $resql = $db->query($sql); $TRes = array(); @@ -4134,7 +4134,7 @@ abstract class CommonObject global $db; - $sql = "DELETE FROM ".$this->db->prefix().$table_element." WHERE ".$field_where." = ".((int) $fk_object_where); + $sql = "DELETE FROM ".$db->prefix().$table_element." WHERE ".$field_where." = ".((int) $fk_object_where); $resql = $db->query($sql); if (empty($resql)) { @@ -8052,7 +8052,7 @@ abstract class CommonObject public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors = 0) { foreach ($tables as $table) { - $sql = 'UPDATE '.$this->db->prefix().$table.' SET fk_soc = '.((int) $dest_id).' WHERE fk_soc = '.((int) $origin_id); + $sql = 'UPDATE '.$db->prefix().$table.' SET fk_soc = '.((int) $dest_id).' WHERE fk_soc = '.((int) $origin_id); if (!$db->query($sql)) { if ($ignoreerrors) { diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 7207ef336c0..d002ff47850 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -1279,7 +1279,7 @@ class FormMail extends Form } $sql = "SELECT rowid, module, label, type_template, topic, joinfiles, content, content_lines, lang"; - $sql .= " FROM ".$this->db->prefix().'c_email_templates'; + $sql .= " FROM ".$db->prefix().'c_email_templates'; $sql .= " WHERE (type_template='".$db->escape($type_template)."' OR type_template='all')"; $sql .= " AND entity IN (".getEntity('c_email_templates').")"; $sql .= " AND (private = 0 OR fk_user = ".((int) $user->id).")"; // Get all public or private owned diff --git a/htdocs/core/class/infobox.class.php b/htdocs/core/class/infobox.class.php index 47fcc81c4aa..9254e0b0f64 100644 --- a/htdocs/core/class/infobox.class.php +++ b/htdocs/core/class/infobox.class.php @@ -83,7 +83,7 @@ class InfoBox /** * Return array of boxes qualified for area and user * - * @param DoliDB $dbs Database handler + * @param DoliDB $db Database handler * @param string $mode 'available' or 'activated' * @param int $zone Name or area (-1 for all, 0 for Homepage, 1 for Accountancy, 2 for xxx, ...) * @param User|null $user Object user to filter @@ -91,7 +91,7 @@ class InfoBox * @param int $includehidden Include also hidden boxes * @return array Array of boxes */ - public static function listBoxes($dbs, $mode, $zone, $user = null, $excludelist = array(), $includehidden = 1) + public static function listBoxes($db, $mode, $zone, $user = null, $excludelist = array(), $includehidden = 1) { global $conf; @@ -100,7 +100,7 @@ class InfoBox if ($mode == 'activated') { // activated $sql = "SELECT b.rowid, b.position, b.box_order, b.fk_user,"; $sql .= " d.rowid as box_id, d.file, d.note, d.tms"; - $sql .= " FROM ".$this->db->prefix()."boxes as b, ".$this->db->prefix()."boxes_def as d"; + $sql .= " FROM ".$db->prefix()."boxes as b, ".$db->prefix()."boxes_def as d"; $sql .= " WHERE b.box_id = d.rowid"; $sql .= " AND b.entity IN (0,".$conf->entity.")"; if ($zone >= 0) { @@ -119,12 +119,12 @@ class InfoBox } dol_syslog(get_class()."::listBoxes get default box list for mode=".$mode." userid=".(is_object($user) ? $user->id : '')."", LOG_DEBUG); - $resql = $dbs->query($sql); + $resql = $db->query($sql); if ($resql) { - $num = $dbs->num_rows($resql); + $num = $db->num_rows($resql); $j = 0; while ($j < $num) { - $obj = $dbs->fetch_object($resql); + $obj = $db->fetch_object($resql); if (!in_array($obj->box_id, $excludelist)) { $regs = array(); @@ -144,7 +144,7 @@ class InfoBox // Goal is to avoid making a "new" done for each boxes returned by select. dol_include_once($relsourcefile); if (class_exists($boxname)) { - $box = new $boxname($dbs, $obj->note); // Constructor may set properties like box->enabled. obj->note is note into box def, not user params. + $box = new $boxname($db, $obj->note); // Constructor may set properties like box->enabled. obj->note is note into box def, not user params. //$box=new stdClass(); // box properties @@ -204,8 +204,8 @@ class InfoBox $j++; } } else { - dol_syslog($dbs->lasterror(), LOG_ERR); - return array('error'=>$dbs->lasterror()); + dol_syslog($db->lasterror(), LOG_ERR); + return array('error'=>$db->lasterror()); } return $boxes; @@ -215,13 +215,13 @@ class InfoBox /** * Save order of boxes for area and user * - * @param DoliDB $dbs Database handler + * @param DoliDB $db Database handler * @param int $zone Name of area (0 for Homepage, ...) * @param string $boxorder List of boxes with correct order 'A:123,456,...-B:789,321...' * @param int $userid Id of user * @return int <0 if KO, 0=Nothing done, > 0 if OK */ - public static function saveboxorder($dbs, $zone, $boxorder, $userid = 0) + public static function saveboxorder($db, $zone, $boxorder, $userid = 0) { global $conf; @@ -235,29 +235,29 @@ class InfoBox return 0; } - $user = new User($dbs); + $user = new User($db); $user->id = $userid; - $dbs->begin(); + $db->begin(); // Save parameters to say user has a dedicated setup $tab = array(); $confuserzone = 'MAIN_BOXES_'.$zone; $tab[$confuserzone] = 1; - if (dol_set_user_param($dbs, $conf, $user, $tab) < 0) { - $error = $dbs->lasterror(); - $dbs->rollback(); + if (dol_set_user_param($db, $conf, $user, $tab) < 0) { + $error = $db->lasterror(); + $db->rollback(); return -3; } // Delete all lines - $sql = "DELETE FROM ".$this->db->prefix()."boxes"; + $sql = "DELETE FROM ".$db->prefix()."boxes"; $sql .= " WHERE entity = ".$conf->entity; $sql .= " AND fk_user = ".((int) $userid); $sql .= " AND position = ".((int) $zone); dol_syslog(get_class()."::saveboxorder", LOG_DEBUG); - $result = $dbs->query($sql); + $result = $db->query($sql); if ($result) { $colonnes = explode('-', $boxorder); foreach ($colonnes as $collist) { @@ -274,17 +274,17 @@ class InfoBox $i++; $ii = sprintf('%02d', $i); - $sql = "INSERT INTO ".$this->db->prefix()."boxes"; + $sql = "INSERT INTO ".$db->prefix()."boxes"; $sql .= "(box_id, position, box_order, fk_user, entity)"; $sql .= " values ("; $sql .= " ".((int) $id).","; $sql .= " ".((int) $zone).","; - $sql .= " '".$dbs->escape($colonne.$ii)."',"; + $sql .= " '".$db->escape($colonne.$ii)."',"; $sql .= " ".((int) $userid).","; $sql .= " ".((int) $conf->entity); $sql .= ")"; - $result = $dbs->query($sql); + $result = $db->query($sql); if ($result < 0) { $error++; break; @@ -297,10 +297,10 @@ class InfoBox } if ($error) { - $dbs->rollback(); + $db->rollback(); return -2; } else { - $dbs->commit(); + $db->commit(); return 1; } } diff --git a/htdocs/core/class/link.class.php b/htdocs/core/class/link.class.php index bf6b771b4a5..bad71deee90 100644 --- a/htdocs/core/class/link.class.php +++ b/htdocs/core/class/link.class.php @@ -274,24 +274,24 @@ class Link extends CommonObject /** * Return nb of links * - * @param DoliDb $dbs Database handler + * @param DoliDb $db Database handler * @param string $objecttype Type of the associated object in dolibarr * @param int $objectid Id of the associated object in dolibarr * @return int Nb of links, -1 if error **/ - public static function count($dbs, $objecttype, $objectid) + public static function count($db, $objecttype, $objectid) { global $conf; - $sql = "SELECT COUNT(rowid) as nb FROM ".$this->db->prefix()."links"; - $sql .= " WHERE objecttype = '".$dbs->escape($objecttype)."' AND objectid = ".((int) $objectid); + $sql = "SELECT COUNT(rowid) as nb FROM ".$db->prefix()."links"; + $sql .= " WHERE objecttype = '".$db->escape($objecttype)."' AND objectid = ".((int) $objectid); if ($conf->entity != 0) { $sql .= " AND entity = ".$conf->entity; } - $resql = $dbs->query($sql); + $resql = $db->query($sql); if ($resql) { - $obj = $dbs->fetch_object($resql); + $obj = $db->fetch_object($resql); if ($obj) { return $obj->nb; } diff --git a/htdocs/core/class/translate.class.php b/htdocs/core/class/translate.class.php index c5f3ceba580..8be6f77251c 100644 --- a/htdocs/core/class/translate.class.php +++ b/htdocs/core/class/translate.class.php @@ -480,7 +480,7 @@ class Translate if (!$found && !empty($conf->global->MAIN_ENABLE_OVERWRITE_TRANSLATION)) { // Overwrite translation with database read - $sql = "SELECT transkey, transvalue FROM ".$this->db->prefix()."overwrite_trans where lang='".$db->escape($this->defaultlang)."' OR lang IS NULL"; + $sql = "SELECT transkey, transvalue FROM ".$db->prefix()."overwrite_trans where lang='".$db->escape($this->defaultlang)."' OR lang IS NULL"; $sql .= " AND entity IN (0, ".getEntity('overwrite_trans').")"; $sql .= $db->order("lang", "DESC"); $resql = $db->query($sql); @@ -980,7 +980,7 @@ class Translate // Not found in loaded language file nor in cache. So we will take the label into database. $sql = "SELECT ".$fieldlabel." as label"; - $sql .= " FROM ".$this->db->prefix().$tablename; + $sql .= " FROM ".$db->prefix().$tablename; $sql .= " WHERE ".$fieldkey." = '".$db->escape($keyforselect ? $keyforselect : $key)."'"; if ($filteronentity) { $sql .= " AND entity IN (".getEntity($tablename).')'; @@ -1067,7 +1067,7 @@ class Translate } $sql = "SELECT code_iso, label, unicode"; - $sql .= " FROM ".$this->db->prefix()."c_currencies"; + $sql .= " FROM ".$db->prefix()."c_currencies"; $sql .= " WHERE active = 1"; if (!empty($currency_code)) { $sql .= " AND code_iso = '".$db->escape($currency_code)."'";