From bdf5f29dcc985e3469bf2c20c434c7038ae7fde4 Mon Sep 17 00:00:00 2001 From: Maximilien Valenzano Date: Fri, 26 Jan 2024 10:55:27 +0100 Subject: [PATCH 001/114] new: separation of expense report from salary accounting code --- htdocs/accountancy/admin/defaultaccounts.php | 4 ++++ htdocs/accountancy/journal/bankjournal.php | 15 ++++++++++----- .../accountancy/journal/expensereportsjournal.php | 12 ++++++------ htdocs/langs/en_US/accountancy.lang | 1 + 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/htdocs/accountancy/admin/defaultaccounts.php b/htdocs/accountancy/admin/defaultaccounts.php index 982448cebdd..79a4b2f8835 100644 --- a/htdocs/accountancy/admin/defaultaccounts.php +++ b/htdocs/accountancy/admin/defaultaccounts.php @@ -51,6 +51,10 @@ $list_account_main = array( 'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT', ); +if (isModEnabled('expensereport')) { + $list_account_main[] = 'ACCOUNTING_ACCOUNT_EXPENSEREPORT'; +} + $list_account = array(); $list_account[] = '---Product---'; diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index 9e6b39a9b00..d716ad9f3a0 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -221,6 +221,7 @@ if ($result) { $account_supplier = getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER', 'NotDefined'); // NotDefined is a reserved word $account_customer = getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER', 'NotDefined'); // NotDefined is a reserved word $account_employee = getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT', 'NotDefined'); // NotDefined is a reserved word + $account_expensereport = getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT', 'NotDefined'); // NotDefined is a reserved word $account_pay_vat = getDolGlobalString('ACCOUNTING_VAT_PAY_ACCOUNT', 'NotDefined'); // NotDefined is a reserved word $account_pay_donation = getDolGlobalString('DONATION_ACCOUNTINGACCOUNT', 'NotDefined'); // NotDefined is a reserved word $account_pay_subscription = getDolGlobalString('ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT', 'NotDefined'); // NotDefined is a reserved word @@ -625,6 +626,9 @@ if (!$error && $action == 'writebookkeeping') { $accountingaccountpayment = new AccountingAccount($db); $accountingaccountpayment->fetch(null, getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT'), true); + $accountingaccountexpensereport = new AccountingAccount($db); + $accountingaccountexpensereport->fetch(null, $conf->global->ACCOUNTING_ACCOUNT_EXPENSEREPORT, true); + $accountingaccountsuspense = new AccountingAccount($db); $accountingaccountsuspense->fetch(null, getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE'), true); @@ -757,8 +761,8 @@ if (!$error && $action == 'writebookkeeping') { } elseif ($tabtype[$key] == 'payment_expensereport') { $bookkeeping->subledger_account = $tabuser[$key]['accountancy_code']; $bookkeeping->subledger_label = $tabuser[$key]['name']; - $bookkeeping->numero_compte = getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT'); - $bookkeeping->label_compte = $accountingaccountpayment->label; + $bookkeeping->numero_compte = getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT'); + $bookkeeping->label_compte = $accountingaccountexpensereport->label; } elseif ($tabtype[$key] == 'payment_salary') { $bookkeeping->subledger_account = $tabuser[$key]['accountancy_code']; $bookkeeping->subledger_label = $tabuser[$key]['name']; @@ -1013,7 +1017,7 @@ if ($action == 'exportcsv') { // ISO and not UTF8 ! } elseif ($tabtype[$key] == 'payment') { print '"'.getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER').'"'.$sep; } elseif ($tabtype[$key] == 'payment_expensereport') { - print '"'.getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT').'"'.$sep; + print '"'.getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT').'"'.$sep; } elseif ($tabtype[$key] == 'payment_salary') { print '"'.getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT').'"'.$sep; } else { @@ -1135,7 +1139,8 @@ if (empty($action) || $action == 'view') { // Button to write into Ledger if (getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER') == "" || getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER') == '-1' || getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER') == "" || getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER') == '-1' - || getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT') == "" || getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT') == '-1') { + || getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT') == "" || getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT') == '-1' + || getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSERERPORT') == "" || getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSERERPORT') == '-1') { print($desc ? '' : '
').'
'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone"); $desc = ' : '.$langs->trans("AccountancyAreaDescMisc", 4, '{link}'); $desc = str_replace('{link}', ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'', $desc); @@ -1294,7 +1299,7 @@ if (empty($action) || $action == 'view') { $account_ledger = getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER'); } if ($tabtype[$key] == 'payment_expensereport') { - $account_ledger = getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT'); + $account_ledger = getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT'); } if ($tabtype[$key] == 'payment_salary') { $account_ledger = getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT'); diff --git a/htdocs/accountancy/journal/expensereportsjournal.php b/htdocs/accountancy/journal/expensereportsjournal.php index 881070ad6fd..077f8f755b1 100644 --- a/htdocs/accountancy/journal/expensereportsjournal.php +++ b/htdocs/accountancy/journal/expensereportsjournal.php @@ -162,7 +162,7 @@ if ($result) { $num = $db->num_rows($result); // Variables - $account_salary = getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT', 'NotDefined'); + $account_salary = getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT', 'NotDefined'); $account_vat = getDolGlobalString('ACCOUNTING_VAT_BUY_ACCOUNT', 'NotDefined'); $i = 0; @@ -247,7 +247,7 @@ if ($action == 'writebookkeeping' && !$error) { $error = 0; $accountingaccountexpense = new AccountingAccount($db); - $accountingaccountexpense->fetch(null, getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT'), true); + $accountingaccountexpense->fetch(null, getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT'), true); foreach ($taber as $key => $val) { // Loop on each expense report $errorforline = 0; @@ -279,7 +279,7 @@ if ($action == 'writebookkeeping' && !$error) { $bookkeeping->subledger_account = $tabuser[$key]['user_accountancy_code']; $bookkeeping->subledger_label = $tabuser[$key]['name']; - $bookkeeping->numero_compte = getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT'); + $bookkeeping->numero_compte = getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT'); $bookkeeping->label_compte = $accountingaccountexpense->label; $bookkeeping->label_operation = $tabuser[$key]['name']; @@ -590,7 +590,7 @@ if (empty($action) || $action == 'view') { } // Button to write into Ledger - if (!getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT') || getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT') == '-1') { + if (!getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT') || getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT') == '-1') { print '
'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone"); $desc = ' : '.$langs->trans("AccountancyAreaDescMisc", 4, '{link}'); $desc = str_replace('{link}', ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'', $desc); @@ -602,7 +602,7 @@ if (empty($action) || $action == 'view') { if (getDolGlobalString('ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping == 'notyet') { print ''; } - if (!getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT') || getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT') == '-1') { + if (!getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT') || getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT') == '-1') { print ''; } else { if ($in_bookkeeping == 'notyet') { @@ -726,7 +726,7 @@ if (empty($action) || $action == 'view') { print "".$expensereportstatic->getNomUrl(1).""; // Account print ""; - $accountoshow = length_accountg(getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT')); + $accountoshow = length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT')); if (($accountoshow == "") || $accountoshow == 'NotDefined') { print ''.$langs->trans("MainAccountForUsersNotDefined").''; } else { diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index cee9b17d6c0..d8b67a715cd 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -178,6 +178,7 @@ ACCOUNTING_SELL_JOURNAL=Sales journal - sales and returns ACCOUNTING_PURCHASE_JOURNAL=Purchase journal - purchase and returns ACCOUNTING_BANK_JOURNAL=Cash journal - receipts and disbursements ACCOUNTING_EXPENSEREPORT_JOURNAL=Expense report journal +ACCOUNTING_ACCOUNT_EXPENSEREPORT=Default accounting account for "expense reports" ACCOUNTING_MISCELLANEOUS_JOURNAL=General journal ACCOUNTING_HAS_NEW_JOURNAL=Has new Journal ACCOUNTING_INVENTORY_JOURNAL=Inventory journal From b2baacccb40b0e920745df27a088b5ae770b3b95 Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Tue, 19 Mar 2024 14:58:05 +0100 Subject: [PATCH 002/114] update credentials --- .../fournisseur.commande.dispatch.class.php | 719 +---------------- .../class/receptionlinebatch.class.php | 754 ++++++++++++++++++ 2 files changed, 757 insertions(+), 716 deletions(-) create mode 100644 htdocs/reception/class/receptionlinebatch.class.php diff --git a/htdocs/fourn/class/fournisseur.commande.dispatch.class.php b/htdocs/fourn/class/fournisseur.commande.dispatch.class.php index 911ddd01eef..c74114febea 100644 --- a/htdocs/fourn/class/fournisseur.commande.dispatch.class.php +++ b/htdocs/fourn/class/fournisseur.commande.dispatch.class.php @@ -2,6 +2,7 @@ /* Copyright (C) 2015 Laurent Destailleur * Copyright (C) 2014 Juanjo Menent * Copyright (C) 2024 Frédéric France + * Copyright (C) 2024 Christophe Battarel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,730 +26,16 @@ */ // Put here all includes required by your class file -require_once DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php"; -require_once DOL_DOCUMENT_ROOT."/reception/class/reception.class.php"; +require_once DOL_DOCUMENT_ROOT."/reception/class/receptionlinebatch.class.php"; /** * Class to manage table commandefournisseurdispatch */ -class CommandeFournisseurDispatch extends CommonObjectLine +class CommandeFournisseurDispatch extends ReceptionLineBatch { - /** - * @var DoliDB Database handler. - */ - public $db; - - /** - * @var string Error code (or message) - */ - public $error; - - /** - * @var string[] Error codes (or messages) - */ - public $errors = array(); - /** * @var string ID to identify managed object */ public $element = 'commandefournisseurdispatch'; - - /** - * @var string Name of table without prefix where object is stored - */ - public $table_element = 'receptiondet_batch'; //!< Name of table without prefix where object is stored - public $lines = array(); - - /** - * @var int ID - */ - public $id; - - /** - * @var int ID - */ - public $fk_commande; - - /** - * @var int ID - */ - public $fk_product; - - /** - * @var int ID. Should be named fk_origin_line ? - */ - public $fk_commandefourndet; - - public $fk_reception; - - - public $qty; - public $qty_asked; - - public $libelle; - public $label; - public $desc; - public $tva_tx; - public $vat_src_code; - public $ref_supplier; - - /** - * @var int ID - */ - public $fk_entrepot; - - /** - * @var int User ID - */ - public $fk_user; - - public $datec = ''; - public $comment; - - /** - * @var int Status - */ - public $status; - - public $batch; - public $eatby = ''; - public $sellby = ''; - public $cost_price = 0; - - - - - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - public function __construct($db) - { - $this->db = $db; - - // List of language codes for status - $this->labelStatus[0] = 'Received'; - $this->labelStatus[1] = 'Verified'; - $this->labelStatus[2] = 'Denied'; - $this->labelStatusShort[0] = 'Received'; - $this->labelStatusShort[1] = 'Verified'; - $this->labelStatusShort[2] = 'Denied'; - } - - - /** - * Create object into database - * - * @param User $user User that creates - * @param int $notrigger 0=launch triggers after, 1=disable triggers - * @return int Return integer <0 if KO, Id of created object if OK - */ - public function create($user, $notrigger = 0) - { - global $conf, $langs, $hookmanager; - $error = 0; - - // Clean parameters - - if (isset($this->fk_commande)) { - $this->fk_commande = (int) $this->fk_commande; - } - if (isset($this->fk_product)) { - $this->fk_product = (int) $this->fk_product; - } - if (isset($this->fk_commandefourndet)) { - $this->fk_commandefourndet = (int) $this->fk_commandefourndet; - } - if (isset($this->qty)) { - $this->qty = trim($this->qty); - } - if (isset($this->fk_entrepot)) { - $this->fk_entrepot = (int) $this->fk_entrepot; - } - if (isset($this->fk_user)) { - $this->fk_user = (int) $this->fk_user; - } - if (isset($this->comment)) { - $this->comment = trim($this->comment); - } - if (isset($this->status)) { - $this->status = (int) $this->status; - } - if (isset($this->batch)) { - $this->batch = trim($this->batch); - } - if (empty($this->datec)) { - $this->datec = dol_now(); - } - - - // Check parameters - // Put here code to add control on parameters values - - // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."("; - $sql .= "fk_commande,"; - $sql .= "fk_product,"; - $sql .= "fk_commandefourndet,"; - $sql .= "qty,"; - $sql .= "fk_entrepot,"; - $sql .= "fk_user,"; - $sql .= "datec,"; - $sql .= "comment,"; - $sql .= "status,"; - $sql .= "batch,"; - $sql .= "eatby,"; - $sql .= "sellby,"; - $sql .= "fk_reception,"; - $sql .= "cost_price"; - - - $sql .= ") VALUES ("; - $sql .= " ".(!isset($this->fk_commande) ? 'NULL' : "'".$this->db->escape($this->fk_commande)."'").","; - $sql .= " ".(!isset($this->fk_product) ? 'NULL' : "'".$this->db->escape($this->fk_product)."'").","; - $sql .= " ".(!isset($this->fk_commandefourndet) ? 'NULL' : "'".$this->db->escape($this->fk_commandefourndet)."'").","; - $sql .= " ".(!isset($this->qty) ? 'NULL' : "'".$this->db->escape($this->qty)."'").","; - $sql .= " ".(!isset($this->fk_entrepot) ? 'NULL' : "'".$this->db->escape($this->fk_entrepot)."'").","; - $sql .= " ".(!isset($this->fk_user) ? 'NULL' : "'".$this->db->escape($this->fk_user)."'").","; - $sql .= " ".(!isset($this->datec) || dol_strlen($this->datec) == 0 ? 'NULL' : "'".$this->db->idate($this->datec)."'").","; - $sql .= " ".(!isset($this->comment) ? 'NULL' : "'".$this->db->escape($this->comment)."'").","; - $sql .= " ".(!isset($this->status) ? 'NULL' : "'".$this->db->escape($this->status)."'").","; - $sql .= " ".(!isset($this->batch) ? 'NULL' : "'".$this->db->escape($this->batch)."'").","; - $sql .= " ".(!isset($this->eatby) || dol_strlen($this->eatby) == 0 ? 'NULL' : "'".$this->db->idate($this->eatby)."'").","; - $sql .= " ".(!isset($this->sellby) || dol_strlen($this->sellby) == 0 ? 'NULL' : "'".$this->db->idate($this->sellby)."'").","; - $sql .= " ".(!isset($this->fk_reception) ? 'NULL' : "'".$this->db->escape($this->fk_reception)."'").","; - $sql .= " ".(!isset($this->cost_price) ? '0' : "'".$this->db->escape($this->cost_price)."'"); - $sql .= ")"; - - $this->db->begin(); - - dol_syslog(__METHOD__, LOG_DEBUG); - $resql = $this->db->query($sql); - if (!$resql) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } - - if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); - - if (!$notrigger) { - // Call triggers - $result = $this->call_trigger('LINERECEPTION_CREATE', $user); - if ($result < 0) { - $error++; - } - // End call triggers - } - } - - // Create extrafields - if (!$error) { - $result = $this->insertExtraFields(); - if ($result < 0) { - $error++; - } - } - - // Commit or rollback - if ($error) { - foreach ($this->errors as $errmsg) { - dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); - $this->error .= ($this->error ? ', '.$errmsg : $errmsg); - } - $this->db->rollback(); - return -1 * $error; - } else { - $this->db->commit(); - return $this->id; - } - } - - - /** - * Load object in memory from the database - * - * @param int $id Id object - * @param string $ref Ref - * @return int Return integer <0 if KO, >0 if OK - */ - public function fetch($id, $ref = '') - { - global $langs; - $sql = "SELECT"; - $sql .= " t.rowid,"; - - $sql .= " t.fk_commande,"; - $sql .= " t.fk_product,"; - $sql .= " t.fk_commandefourndet,"; - $sql .= " t.qty,"; - $sql .= " t.fk_entrepot,"; - $sql .= " t.fk_user,"; - $sql .= " t.datec,"; - $sql .= " t.comment,"; - $sql .= " t.status,"; - $sql .= " t.tms,"; - $sql .= " t.batch,"; - $sql .= " t.eatby,"; - $sql .= " t.sellby,"; - $sql .= " t.fk_reception"; - - - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t"; - if ($ref) { - $sql .= " WHERE t.ref = '".$this->db->escape($ref)."'"; - } else { - $sql .= " WHERE t.rowid = ".((int) $id); - } - - dol_syslog(get_class($this)."::fetch"); - $resql = $this->db->query($sql); - if ($resql) { - if ($this->db->num_rows($resql)) { - $obj = $this->db->fetch_object($resql); - - $this->id = $obj->rowid; - - $this->fk_commande = $obj->fk_commande; - $this->fk_product = $obj->fk_product; - $this->fk_commandefourndet = $obj->fk_commandefourndet; - $this->qty = $obj->qty; - $this->fk_entrepot = $obj->fk_entrepot; - $this->fk_user = $obj->fk_user; - $this->datec = $this->db->jdate($obj->datec); - $this->comment = $obj->comment; - $this->status = $obj->status; - $this->tms = $this->db->jdate($obj->tms); - $this->batch = $obj->batch; - $this->eatby = $this->db->jdate($obj->eatby); - $this->sellby = $this->db->jdate($obj->sellby); - $this->fk_reception = $obj->fk_reception; - - $this->fetch_optionals(); - } - $this->db->free($resql); - - return 1; - } else { - $this->error = "Error ".$this->db->lasterror(); - return -1; - } - } - - - /** - * Update object into database - * - * @param User $user User that modifies - * @param int $notrigger 0=launch triggers after, 1=disable triggers - * @return int Return integer <0 if KO, >0 if OK - */ - public function update($user, $notrigger = 0) - { - $error = 0; - - // Clean parameters - - if (isset($this->fk_commande)) { - $this->fk_commande = (int) $this->fk_commande; - } - if (isset($this->fk_product)) { - $this->fk_product = (int) $this->fk_product; - } - if (isset($this->fk_commandefourndet)) { - $this->fk_commandefourndet = (int) $this->fk_commandefourndet; - } - if (isset($this->qty)) { - $this->qty = trim($this->qty); - } - if (isset($this->fk_entrepot)) { - $this->fk_entrepot = (int) $this->fk_entrepot; - } - if (isset($this->fk_user)) { - $this->fk_user = (int) $this->fk_user; - } - if (isset($this->comment)) { - $this->comment = trim($this->comment); - } - if (isset($this->status)) { - $this->status = (int) $this->status; - } - if (isset($this->batch)) { - $this->batch = trim($this->batch); - } - - - - // Check parameters - // Put here code to add a control on parameters values - - // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; - $sql .= " fk_commande=".(isset($this->fk_commande) ? $this->fk_commande : "null").","; - $sql .= " fk_product=".(isset($this->fk_product) ? $this->fk_product : "null").","; - $sql .= " fk_commandefourndet=".(isset($this->fk_commandefourndet) ? $this->fk_commandefourndet : "null").","; - $sql .= " qty=".(isset($this->qty) ? $this->qty : "null").","; - $sql .= " fk_entrepot=".(isset($this->fk_entrepot) ? $this->fk_entrepot : "null").","; - $sql .= " fk_user=".(isset($this->fk_user) ? $this->fk_user : "null").","; - $sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').","; - $sql .= " comment=".(isset($this->comment) ? "'".$this->db->escape($this->comment)."'" : "null").","; - $sql .= " status=".(isset($this->status) ? $this->status : "null").","; - $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; - $sql .= " batch=".(isset($this->batch) ? "'".$this->db->escape($this->batch)."'" : "null").","; - $sql .= " eatby=".(dol_strlen($this->eatby) != 0 ? "'".$this->db->idate($this->eatby)."'" : 'null').","; - $sql .= " sellby=".(dol_strlen($this->sellby) != 0 ? "'".$this->db->idate($this->sellby)."'" : 'null'); - $sql .= " WHERE rowid=".((int) $this->id); - - $this->db->begin(); - - dol_syslog(__METHOD__); - $resql = $this->db->query($sql); - if (!$resql) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } - - if (!$error) { - if (!$error) { - if (empty($this->id) && !empty($this->rowid)) { - $this->id = $this->rowid; - } - $result = $this->insertExtraFields(); - if ($result < 0) { - $error++; - } - } - - if (!$notrigger) { - // Call triggers - $result = $this->call_trigger('LINERECEPTION_MODIFY', $user); - if ($result < 0) { - $error++; - } - // End call triggers - } - } - - // Commit or rollback - if ($error) { - foreach ($this->errors as $errmsg) { - dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); - $this->error .= ($this->error ? ', '.$errmsg : $errmsg); - } - $this->db->rollback(); - return -1 * $error; - } else { - $this->db->commit(); - return 1; - } - } - - - /** - * Delete object in database - * - * @param User $user User that deletes - * @param int $notrigger 0=launch triggers after, 1=disable triggers - * @return int Return integer <0 if KO, >0 if OK - */ - public function delete($user, $notrigger = 0) - { - $error = 0; - - $this->db->begin(); - - if (!$error) { - if (!$notrigger) { - // Call triggers - $result = $this->call_trigger('LINERECEPTION_DELETE', $user); - if ($result < 0) { - $error++; - } - // End call triggers - } - } - - // Remove extrafields - if (!$error) { - $result = $this->deleteExtraFields(); - if ($result < 0) { - $error++; - dol_syslog(get_class($this)."::delete error deleteExtraFields ".$this->error, LOG_ERR); - } - } - - if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; - $sql .= " WHERE rowid=".((int) $this->id); - - dol_syslog(__METHOD__); - $resql = $this->db->query($sql); - if (!$resql) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } - } - - // Commit or rollback - if ($error) { - foreach ($this->errors as $errmsg) { - dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); - $this->error .= ($this->error ? ', '.$errmsg : $errmsg); - } - $this->db->rollback(); - return -1 * $error; - } else { - $this->db->commit(); - return 1; - } - } - - - /** - * Load an object from its id and create a new one in database - * - * @param User $user User making the clone - * @param int $fromid Id of object to clone - * @return int New id of clone - */ - public function createFromClone(User $user, $fromid) - { - $error = 0; - - $object = new CommandeFournisseurDispatch($this->db); - - $this->db->begin(); - - // Load source object - $object->fetch($fromid); - $object->id = 0; - $object->statut = 0; - - // Clear fields - // ... - - // Create clone - $object->context['createfromclone'] = 'createfromclone'; - $result = $object->create($user); - - // Other options - if ($result < 0) { - $this->error = $object->error; - $error++; - } - - if (!$error) { - } - - unset($object->context['createfromclone']); - - // End - if (!$error) { - $this->db->commit(); - return $object->id; - } else { - $this->db->rollback(); - return -1; - } - } - - - - /** - * Return label of the status of object - * - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto - * @return string Label - */ - public function getLibStatut($mode = 0) - { - return $this->LibStatut($this->status, $mode); - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Return label of a status - * - * @param int $status Id status - * @param int $mode 0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto - * @return string Label of status - */ - public function LibStatut($status, $mode = 0) - { - // phpcs:enable - global $langs; - $langs->load('orders'); - - if ($mode == 0) { - return $langs->trans($this->labelStatus[$status]); - } elseif ($mode == 1) { - return $langs->trans($this->labelStatusShort[$status]); - } elseif ($mode == 2) { - return $langs->trans($this->labelStatus[$status]); - } elseif ($mode == 3) { - if ($status == 0) { - return img_picto($langs->trans($this->labelStatus[$status]), 'statut0'); - } elseif ($status == 1) { - return img_picto($langs->trans($this->labelStatus[$status]), 'statut4'); - } elseif ($status == 2) { - return img_picto($langs->trans($this->labelStatus[$status]), 'statut8'); - } - } elseif ($mode == 4) { - if ($status == 0) { - return img_picto($langs->trans($this->labelStatus[$status]), 'statut0').' '.$langs->trans($this->labelStatus[$status]); - } elseif ($status == 1) { - return img_picto($langs->trans($this->labelStatus[$status]), 'statut4').' '.$langs->trans($this->labelStatus[$status]); - } elseif ($status == 2) { - return img_picto($langs->trans($this->labelStatus[$status]), 'statut8').' '.$langs->trans($this->labelStatus[$status]); - } - } elseif ($mode == 5) { - if ($status == 0) { - return ''.$langs->trans($this->labelStatusShort[$status]).' '.img_picto($langs->trans($this->labelStatus[$status]), 'statut0'); - } elseif ($status == 1) { - return ''.$langs->trans($this->labelStatusShort[$status]).' '.img_picto($langs->trans($this->labelStatus[$status]), 'statut4'); - } elseif ($status == 2) { - return ''.$langs->trans($this->labelStatusShort[$status]).' '.img_picto($langs->trans($this->labelStatus[$status]), 'statut8'); - } - } - return ""; - } - - - /** - * Initialise object with example values - * Id must be 0 if object instance is a specimen - * - * @return int - */ - public function initAsSpecimen() - { - $this->id = 0; - - $this->fk_commande = 0; - $this->fk_product = 0; - $this->fk_commandefourndet = 0; - $this->qty = ''; - $this->fk_entrepot = 0; - $this->fk_user = 0; - $this->datec = ''; - $this->comment = ''; - $this->status = 0; - $this->tms = dol_now(); - $this->batch = ''; - $this->eatby = ''; - $this->sellby = ''; - - return 1; - } - - /** - * Load object in memory from the database - * - * @param string $sortorder Sort Order - * @param string $sortfield Sort field - * @param int $limit limit - * @param int $offset offset limit - * @param string|array $filter filter array - * @param string $filtermode filter mode (AND or OR) - * @return int Return integer <0 if KO, >0 if OK - */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') - { - dol_syslog(__METHOD__, LOG_DEBUG); - - $sql = "SELECT"; - $sql .= " t.rowid,"; - $sql .= " t.fk_commande,"; - $sql .= " t.fk_product,"; - $sql .= " t.fk_commandefourndet,"; - $sql .= " t.qty,"; - $sql .= " t.fk_entrepot,"; - $sql .= " t.fk_user,"; - $sql .= " t.datec,"; - $sql .= " t.comment,"; - $sql .= " t.status,"; - $sql .= " t.tms,"; - $sql .= " t.batch,"; - $sql .= " t.eatby,"; - $sql .= " t.sellby"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t"; - - // Manage filter - if (is_array($filter)) { - $sqlwhere = array(); - if (count($filter) > 0) { - foreach ($filter as $key => $value) { - if ($key == 't.comment') { - $sqlwhere [] = $this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'"; - } elseif ($key == 't.datec' || $key == 't.tms' || $key == 't.eatby' || $key == 't.sellby' || $key == 't.batch') { - $sqlwhere [] = $this->db->sanitize($key)." = '".$this->db->escape($value)."'"; - } elseif ($key == 'qty') { - $sqlwhere [] = $this->db->sanitize($key)." = ".((float) $value); - } else { - $sqlwhere [] = $this->db->sanitize($key)." = ".((int) $value); - } - } - } - if (count($sqlwhere) > 0) { - $sql .= ' WHERE '.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere); - } - - $filter = ''; - } - - // Manage filter - $errormessage = ''; - $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage); - if ($errormessage) { - $this->errors[] = $errormessage; - dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); - return -1; - } - - if (!empty($sortfield)) { - $sql .= $this->db->order($sortfield, $sortorder); - } - if (!empty($limit)) { - $sql .= $this->db->plimit($limit, $offset); - } - $this->lines = array(); - - $resql = $this->db->query($sql); - if ($resql) { - $num = $this->db->num_rows($resql); - - while ($obj = $this->db->fetch_object($resql)) { - $line = new self($this->db); - - $line->id = $obj->rowid; - - $line->fk_commande = $obj->fk_commande; - $line->fk_product = $obj->fk_product; - $line->fk_commandefourndet = $obj->fk_commandefourndet; - $line->qty = $obj->qty; - $line->fk_entrepot = $obj->fk_entrepot; - $line->fk_user = $obj->fk_user; - $line->datec = $this->db->jdate($obj->datec); - $line->comment = $obj->comment; - $line->status = $obj->status; - $line->tms = $this->db->jdate($obj->tms); - $line->batch = $obj->batch; - $line->eatby = $this->db->jdate($obj->eatby); - $line->sellby = $this->db->jdate($obj->sellby); - $line->fetch_optionals(); - - $this->lines[$line->id] = $line; - } - $this->db->free($resql); - - return $num; - } else { - $this->errors[] = 'Error '.$this->db->lasterror(); - dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); - - return -1; - } - } } diff --git a/htdocs/reception/class/receptionlinebatch.class.php b/htdocs/reception/class/receptionlinebatch.class.php new file mode 100644 index 00000000000..9b02cef2bc9 --- /dev/null +++ b/htdocs/reception/class/receptionlinebatch.class.php @@ -0,0 +1,754 @@ + + * Copyright (C) 2014 Juanjo Menent + * Copyright (C) 2024 Frédéric France + * Copyright (C) 2024 Christophe Battarel + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/fourn/class/fournisseur.commande.dispatch.class.php + * \ingroup fournisseur stock + * \brief This file is an example for a CRUD class file (Create/Read/Update/Delete) + * Initially built by build_class_from_table on 2015-02-24 10:38 + */ + +// Put here all includes required by your class file +require_once DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php"; +require_once DOL_DOCUMENT_ROOT."/reception/class/reception.class.php"; + + +/** + * Class to manage table commandefournisseurdispatch + */ +class ReceptionLineBatch extends CommonObjectLine +{ + /** + * @var DoliDB Database handler. + */ + public $db; + + /** + * @var string Error code (or message) + */ + public $error; + + /** + * @var string[] Error codes (or messages) + */ + public $errors = array(); + + /** + * @var string ID to identify managed object + */ + public $element = 'receptionlinebatch'; + + /** + * @var string Name of table without prefix where object is stored + */ + public $table_element = 'receptiondet_batch'; //!< Name of table without prefix where object is stored + public $lines = array(); + + /** + * @var int ID + */ + public $id; + + /** + * @var int ID + */ + public $fk_commande; + + /** + * @var int ID + */ + public $fk_product; + + /** + * @var int ID. Should be named fk_origin_line ? + */ + public $fk_commandefourndet; + + public $fk_reception; + + + public $qty; + public $qty_asked; + + public $libelle; + public $label; + public $desc; + public $tva_tx; + public $vat_src_code; + public $ref_supplier; + + /** + * @var int ID + */ + public $fk_entrepot; + + /** + * @var int User ID + */ + public $fk_user; + + public $datec = ''; + public $comment; + + /** + * @var int Status + */ + public $status; + + public $batch; + public $eatby = ''; + public $sellby = ''; + public $cost_price = 0; + + + + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + $this->db = $db; + + // List of language codes for status + $this->labelStatus[0] = 'Received'; + $this->labelStatus[1] = 'Verified'; + $this->labelStatus[2] = 'Denied'; + $this->labelStatusShort[0] = 'Received'; + $this->labelStatusShort[1] = 'Verified'; + $this->labelStatusShort[2] = 'Denied'; + } + + + /** + * Create object into database + * + * @param User $user User that creates + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int Return integer <0 if KO, Id of created object if OK + */ + public function create($user, $notrigger = 0) + { + global $conf, $langs, $hookmanager; + $error = 0; + + // Clean parameters + + if (isset($this->fk_commande)) { + $this->fk_commande = (int) $this->fk_commande; + } + if (isset($this->fk_product)) { + $this->fk_product = (int) $this->fk_product; + } + if (isset($this->fk_commandefourndet)) { + $this->fk_commandefourndet = (int) $this->fk_commandefourndet; + } + if (isset($this->qty)) { + $this->qty = trim($this->qty); + } + if (isset($this->fk_entrepot)) { + $this->fk_entrepot = (int) $this->fk_entrepot; + } + if (isset($this->fk_user)) { + $this->fk_user = (int) $this->fk_user; + } + if (isset($this->comment)) { + $this->comment = trim($this->comment); + } + if (isset($this->status)) { + $this->status = (int) $this->status; + } + if (isset($this->batch)) { + $this->batch = trim($this->batch); + } + if (empty($this->datec)) { + $this->datec = dol_now(); + } + + + // Check parameters + // Put here code to add control on parameters values + + // Insert request + $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."("; + $sql .= "fk_commande,"; + $sql .= "fk_product,"; + $sql .= "fk_commandefourndet,"; + $sql .= "qty,"; + $sql .= "fk_entrepot,"; + $sql .= "fk_user,"; + $sql .= "datec,"; + $sql .= "comment,"; + $sql .= "status,"; + $sql .= "batch,"; + $sql .= "eatby,"; + $sql .= "sellby,"; + $sql .= "fk_reception,"; + $sql .= "cost_price"; + + + $sql .= ") VALUES ("; + $sql .= " ".(!isset($this->fk_commande) ? 'NULL' : "'".$this->db->escape($this->fk_commande)."'").","; + $sql .= " ".(!isset($this->fk_product) ? 'NULL' : "'".$this->db->escape($this->fk_product)."'").","; + $sql .= " ".(!isset($this->fk_commandefourndet) ? 'NULL' : "'".$this->db->escape($this->fk_commandefourndet)."'").","; + $sql .= " ".(!isset($this->qty) ? 'NULL' : "'".$this->db->escape($this->qty)."'").","; + $sql .= " ".(!isset($this->fk_entrepot) ? 'NULL' : "'".$this->db->escape($this->fk_entrepot)."'").","; + $sql .= " ".(!isset($this->fk_user) ? 'NULL' : "'".$this->db->escape($this->fk_user)."'").","; + $sql .= " ".(!isset($this->datec) || dol_strlen($this->datec) == 0 ? 'NULL' : "'".$this->db->idate($this->datec)."'").","; + $sql .= " ".(!isset($this->comment) ? 'NULL' : "'".$this->db->escape($this->comment)."'").","; + $sql .= " ".(!isset($this->status) ? 'NULL' : "'".$this->db->escape($this->status)."'").","; + $sql .= " ".(!isset($this->batch) ? 'NULL' : "'".$this->db->escape($this->batch)."'").","; + $sql .= " ".(!isset($this->eatby) || dol_strlen($this->eatby) == 0 ? 'NULL' : "'".$this->db->idate($this->eatby)."'").","; + $sql .= " ".(!isset($this->sellby) || dol_strlen($this->sellby) == 0 ? 'NULL' : "'".$this->db->idate($this->sellby)."'").","; + $sql .= " ".(!isset($this->fk_reception) ? 'NULL' : "'".$this->db->escape($this->fk_reception)."'").","; + $sql .= " ".(!isset($this->cost_price) ? '0' : "'".$this->db->escape($this->cost_price)."'"); + $sql .= ")"; + + $this->db->begin(); + + dol_syslog(__METHOD__, LOG_DEBUG); + $resql = $this->db->query($sql); + if (!$resql) { + $error++; + $this->errors[] = "Error ".$this->db->lasterror(); + } + + if (!$error) { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + + if (!$notrigger) { + // Call triggers + $result = $this->call_trigger('LINERECEPTION_CREATE', $user); + if ($result < 0) { + $error++; + } + // End call triggers + } + } + + // Create extrafields + if (!$error) { + $result = $this->insertExtraFields(); + if ($result < 0) { + $error++; + } + } + + // Commit or rollback + if ($error) { + foreach ($this->errors as $errmsg) { + dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); + } + $this->db->rollback(); + return -1 * $error; + } else { + $this->db->commit(); + return $this->id; + } + } + + + /** + * Load object in memory from the database + * + * @param int $id Id object + * @param string $ref Ref + * @return int Return integer <0 if KO, >0 if OK + */ + public function fetch($id, $ref = '') + { + global $langs; + $sql = "SELECT"; + $sql .= " t.rowid,"; + + $sql .= " t.fk_commande,"; + $sql .= " t.fk_product,"; + $sql .= " t.fk_commandefourndet,"; + $sql .= " t.qty,"; + $sql .= " t.fk_entrepot,"; + $sql .= " t.fk_user,"; + $sql .= " t.datec,"; + $sql .= " t.comment,"; + $sql .= " t.status,"; + $sql .= " t.tms,"; + $sql .= " t.batch,"; + $sql .= " t.eatby,"; + $sql .= " t.sellby,"; + $sql .= " t.fk_reception"; + + + $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t"; + if ($ref) { + $sql .= " WHERE t.ref = '".$this->db->escape($ref)."'"; + } else { + $sql .= " WHERE t.rowid = ".((int) $id); + } + + dol_syslog(get_class($this)."::fetch"); + $resql = $this->db->query($sql); + if ($resql) { + if ($this->db->num_rows($resql)) { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + + $this->fk_commande = $obj->fk_commande; + $this->fk_product = $obj->fk_product; + $this->fk_commandefourndet = $obj->fk_commandefourndet; + $this->qty = $obj->qty; + $this->fk_entrepot = $obj->fk_entrepot; + $this->fk_user = $obj->fk_user; + $this->datec = $this->db->jdate($obj->datec); + $this->comment = $obj->comment; + $this->status = $obj->status; + $this->tms = $this->db->jdate($obj->tms); + $this->batch = $obj->batch; + $this->eatby = $this->db->jdate($obj->eatby); + $this->sellby = $this->db->jdate($obj->sellby); + $this->fk_reception = $obj->fk_reception; + + $this->fetch_optionals(); + } + $this->db->free($resql); + + return 1; + } else { + $this->error = "Error ".$this->db->lasterror(); + return -1; + } + } + + + /** + * Update object into database + * + * @param User $user User that modifies + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int Return integer <0 if KO, >0 if OK + */ + public function update($user, $notrigger = 0) + { + $error = 0; + + // Clean parameters + + if (isset($this->fk_commande)) { + $this->fk_commande = (int) $this->fk_commande; + } + if (isset($this->fk_product)) { + $this->fk_product = (int) $this->fk_product; + } + if (isset($this->fk_commandefourndet)) { + $this->fk_commandefourndet = (int) $this->fk_commandefourndet; + } + if (isset($this->qty)) { + $this->qty = trim($this->qty); + } + if (isset($this->fk_entrepot)) { + $this->fk_entrepot = (int) $this->fk_entrepot; + } + if (isset($this->fk_user)) { + $this->fk_user = (int) $this->fk_user; + } + if (isset($this->comment)) { + $this->comment = trim($this->comment); + } + if (isset($this->status)) { + $this->status = (int) $this->status; + } + if (isset($this->batch)) { + $this->batch = trim($this->batch); + } + + + + // Check parameters + // Put here code to add a control on parameters values + + // Update request + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; + $sql .= " fk_commande=".(isset($this->fk_commande) ? $this->fk_commande : "null").","; + $sql .= " fk_product=".(isset($this->fk_product) ? $this->fk_product : "null").","; + $sql .= " fk_commandefourndet=".(isset($this->fk_commandefourndet) ? $this->fk_commandefourndet : "null").","; + $sql .= " qty=".(isset($this->qty) ? $this->qty : "null").","; + $sql .= " fk_entrepot=".(isset($this->fk_entrepot) ? $this->fk_entrepot : "null").","; + $sql .= " fk_user=".(isset($this->fk_user) ? $this->fk_user : "null").","; + $sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').","; + $sql .= " comment=".(isset($this->comment) ? "'".$this->db->escape($this->comment)."'" : "null").","; + $sql .= " status=".(isset($this->status) ? $this->status : "null").","; + $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; + $sql .= " batch=".(isset($this->batch) ? "'".$this->db->escape($this->batch)."'" : "null").","; + $sql .= " eatby=".(dol_strlen($this->eatby) != 0 ? "'".$this->db->idate($this->eatby)."'" : 'null').","; + $sql .= " sellby=".(dol_strlen($this->sellby) != 0 ? "'".$this->db->idate($this->sellby)."'" : 'null'); + $sql .= " WHERE rowid=".((int) $this->id); + + $this->db->begin(); + + dol_syslog(__METHOD__); + $resql = $this->db->query($sql); + if (!$resql) { + $error++; + $this->errors[] = "Error ".$this->db->lasterror(); + } + + if (!$error) { + if (!$error) { + if (empty($this->id) && !empty($this->rowid)) { + $this->id = $this->rowid; + } + $result = $this->insertExtraFields(); + if ($result < 0) { + $error++; + } + } + + if (!$notrigger) { + // Call triggers + $result = $this->call_trigger('LINERECEPTION_MODIFY', $user); + if ($result < 0) { + $error++; + } + // End call triggers + } + } + + // Commit or rollback + if ($error) { + foreach ($this->errors as $errmsg) { + dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); + } + $this->db->rollback(); + return -1 * $error; + } else { + $this->db->commit(); + return 1; + } + } + + + /** + * Delete object in database + * + * @param User $user User that deletes + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int Return integer <0 if KO, >0 if OK + */ + public function delete($user, $notrigger = 0) + { + $error = 0; + + $this->db->begin(); + + if (!$error) { + if (!$notrigger) { + // Call triggers + $result = $this->call_trigger('LINERECEPTION_DELETE', $user); + if ($result < 0) { + $error++; + } + // End call triggers + } + } + + // Remove extrafields + if (!$error) { + $result = $this->deleteExtraFields(); + if ($result < 0) { + $error++; + dol_syslog(get_class($this)."::delete error deleteExtraFields ".$this->error, LOG_ERR); + } + } + + if (!$error) { + $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " WHERE rowid=".((int) $this->id); + + dol_syslog(__METHOD__); + $resql = $this->db->query($sql); + if (!$resql) { + $error++; + $this->errors[] = "Error ".$this->db->lasterror(); + } + } + + // Commit or rollback + if ($error) { + foreach ($this->errors as $errmsg) { + dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); + } + $this->db->rollback(); + return -1 * $error; + } else { + $this->db->commit(); + return 1; + } + } + + + /** + * Load an object from its id and create a new one in database + * + * @param User $user User making the clone + * @param int $fromid Id of object to clone + * @return int New id of clone + */ + public function createFromClone(User $user, $fromid) + { + $error = 0; + + $object = new CommandeFournisseurDispatch($this->db); + + $this->db->begin(); + + // Load source object + $object->fetch($fromid); + $object->id = 0; + $object->statut = 0; + + // Clear fields + // ... + + // Create clone + $object->context['createfromclone'] = 'createfromclone'; + $result = $object->create($user); + + // Other options + if ($result < 0) { + $this->error = $object->error; + $error++; + } + + if (!$error) { + } + + unset($object->context['createfromclone']); + + // End + if (!$error) { + $this->db->commit(); + return $object->id; + } else { + $this->db->rollback(); + return -1; + } + } + + + + /** + * Return label of the status of object + * + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto + * @return string Label + */ + public function getLibStatut($mode = 0) + { + return $this->LibStatut($this->status, $mode); + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Return label of a status + * + * @param int $status Id status + * @param int $mode 0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto + * @return string Label of status + */ + public function LibStatut($status, $mode = 0) + { + // phpcs:enable + global $langs; + $langs->load('orders'); + + if ($mode == 0) { + return $langs->trans($this->labelStatus[$status]); + } elseif ($mode == 1) { + return $langs->trans($this->labelStatusShort[$status]); + } elseif ($mode == 2) { + return $langs->trans($this->labelStatus[$status]); + } elseif ($mode == 3) { + if ($status == 0) { + return img_picto($langs->trans($this->labelStatus[$status]), 'statut0'); + } elseif ($status == 1) { + return img_picto($langs->trans($this->labelStatus[$status]), 'statut4'); + } elseif ($status == 2) { + return img_picto($langs->trans($this->labelStatus[$status]), 'statut8'); + } + } elseif ($mode == 4) { + if ($status == 0) { + return img_picto($langs->trans($this->labelStatus[$status]), 'statut0').' '.$langs->trans($this->labelStatus[$status]); + } elseif ($status == 1) { + return img_picto($langs->trans($this->labelStatus[$status]), 'statut4').' '.$langs->trans($this->labelStatus[$status]); + } elseif ($status == 2) { + return img_picto($langs->trans($this->labelStatus[$status]), 'statut8').' '.$langs->trans($this->labelStatus[$status]); + } + } elseif ($mode == 5) { + if ($status == 0) { + return ''.$langs->trans($this->labelStatusShort[$status]).' '.img_picto($langs->trans($this->labelStatus[$status]), 'statut0'); + } elseif ($status == 1) { + return ''.$langs->trans($this->labelStatusShort[$status]).' '.img_picto($langs->trans($this->labelStatus[$status]), 'statut4'); + } elseif ($status == 2) { + return ''.$langs->trans($this->labelStatusShort[$status]).' '.img_picto($langs->trans($this->labelStatus[$status]), 'statut8'); + } + } + return ""; + } + + + /** + * Initialise object with example values + * Id must be 0 if object instance is a specimen + * + * @return int + */ + public function initAsSpecimen() + { + $this->id = 0; + + $this->fk_commande = 0; + $this->fk_product = 0; + $this->fk_commandefourndet = 0; + $this->qty = ''; + $this->fk_entrepot = 0; + $this->fk_user = 0; + $this->datec = ''; + $this->comment = ''; + $this->status = 0; + $this->tms = dol_now(); + $this->batch = ''; + $this->eatby = ''; + $this->sellby = ''; + + return 1; + } + + /** + * Load object in memory from the database + * + * @param string $sortorder Sort Order + * @param string $sortfield Sort field + * @param int $limit limit + * @param int $offset offset limit + * @param string|array $filter filter array + * @param string $filtermode filter mode (AND or OR) + * @return int Return integer <0 if KO, >0 if OK + */ + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + { + dol_syslog(__METHOD__, LOG_DEBUG); + + $sql = "SELECT"; + $sql .= " t.rowid,"; + $sql .= " t.fk_commande,"; + $sql .= " t.fk_product,"; + $sql .= " t.fk_commandefourndet,"; + $sql .= " t.qty,"; + $sql .= " t.fk_entrepot,"; + $sql .= " t.fk_user,"; + $sql .= " t.datec,"; + $sql .= " t.comment,"; + $sql .= " t.status,"; + $sql .= " t.tms,"; + $sql .= " t.batch,"; + $sql .= " t.eatby,"; + $sql .= " t.sellby"; + $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t"; + + // Manage filter + if (is_array($filter)) { + $sqlwhere = array(); + if (count($filter) > 0) { + foreach ($filter as $key => $value) { + if ($key == 't.comment') { + $sqlwhere [] = $this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'"; + } elseif ($key == 't.datec' || $key == 't.tms' || $key == 't.eatby' || $key == 't.sellby' || $key == 't.batch') { + $sqlwhere [] = $this->db->sanitize($key)." = '".$this->db->escape($value)."'"; + } elseif ($key == 'qty') { + $sqlwhere [] = $this->db->sanitize($key)." = ".((float) $value); + } else { + $sqlwhere [] = $this->db->sanitize($key)." = ".((int) $value); + } + } + } + if (count($sqlwhere) > 0) { + $sql .= ' WHERE '.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere); + } + + $filter = ''; + } + + // Manage filter + $errormessage = ''; + $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage); + if ($errormessage) { + $this->errors[] = $errormessage; + dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); + return -1; + } + + if (!empty($sortfield)) { + $sql .= $this->db->order($sortfield, $sortorder); + } + if (!empty($limit)) { + $sql .= $this->db->plimit($limit, $offset); + } + $this->lines = array(); + + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + + while ($obj = $this->db->fetch_object($resql)) { + $line = new self($this->db); + + $line->id = $obj->rowid; + + $line->fk_commande = $obj->fk_commande; + $line->fk_product = $obj->fk_product; + $line->fk_commandefourndet = $obj->fk_commandefourndet; + $line->qty = $obj->qty; + $line->fk_entrepot = $obj->fk_entrepot; + $line->fk_user = $obj->fk_user; + $line->datec = $this->db->jdate($obj->datec); + $line->comment = $obj->comment; + $line->status = $obj->status; + $line->tms = $this->db->jdate($obj->tms); + $line->batch = $obj->batch; + $line->eatby = $this->db->jdate($obj->eatby); + $line->sellby = $this->db->jdate($obj->sellby); + $line->fetch_optionals(); + + $this->lines[$line->id] = $line; + } + $this->db->free($resql); + + return $num; + } else { + $this->errors[] = 'Error '.$this->db->lasterror(); + dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); + + return -1; + } + } +} From f94d282c17ba9536d4ca94efce079a7ba8e490e6 Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Tue, 19 Mar 2024 15:24:08 +0100 Subject: [PATCH 003/114] renam fk_commande and fk_commandefourdet --- .../fournisseur.commande.dispatch.class.php | 53 ++++++++++++++++++ .../install/mysql/migration/19.0.0-20.0.0.sql | 3 + .../class/receptionlinebatch.class.php | 56 +++++++++---------- 3 files changed, 84 insertions(+), 28 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.commande.dispatch.class.php b/htdocs/fourn/class/fournisseur.commande.dispatch.class.php index c74114febea..23edeb6aa4b 100644 --- a/htdocs/fourn/class/fournisseur.commande.dispatch.class.php +++ b/htdocs/fourn/class/fournisseur.commande.dispatch.class.php @@ -38,4 +38,57 @@ class CommandeFournisseurDispatch extends ReceptionLineBatch * @var string ID to identify managed object */ public $element = 'commandefournisseurdispatch'; + /** + * @var int ID + */ + public $fk_commande; + /** + * @var int ID + */ + public $fk_commandefourndet; + + /** + * Create object into database + * + * @param User $user User that creates + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int Return integer <0 if KO, Id of created object if OK + */ + public function create($user, $notrigger = 0) + { + $this->fk_element = $this->fk_commande; + $this->fk_elementdet = $this->fk_commandefourndet; + return parent::create($user, $notrigger); + } + + /** + * Load object in memory from the database + * + * @param int $id Id object + * @param string $ref Ref + * @return int Return integer <0 if KO, >0 if OK + */ + public function fetch($id, $ref = '') + { + $ret = parent::fetch($id, $ref); + if ($ret > 0) { + $this->fk_commande = $this->fk_element; + $this->fk_commandefourndet = $this->fk_elementdet; + } + return $ret; + } + + /** + * Update object into database + * + * @param User $user User that modifies + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int Return integer <0 if KO, >0 if OK + */ + public function update($user, $notrigger = 0) + { + $this->fk_element = $this->fk_commande; + $this->fk_elementdet = $this->fk_commandefourndet; + return parent::update($user, $notrigger); + } } diff --git a/htdocs/install/mysql/migration/19.0.0-20.0.0.sql b/htdocs/install/mysql/migration/19.0.0-20.0.0.sql index 491b563a502..68d2694aeb7 100644 --- a/htdocs/install/mysql/migration/19.0.0-20.0.0.sql +++ b/htdocs/install/mysql/migration/19.0.0-20.0.0.sql @@ -280,3 +280,6 @@ ALTER TABLE llx_ticket ADD UNIQUE INDEX uk_ticket_barcode_barcode_type (barcode, ALTER TABLE llx_ticket ADD CONSTRAINT llx_ticket_fk_product_barcode_type FOREIGN KEY (fk_barcode_type) REFERENCES llx_c_barcode_type (rowid); ALTER TABLE llx_societe ADD COLUMN fk_parent integer NULL; + +ALTER TABLE llx_receptiondet_batch RENAME COLUMN fk_commande TO fk_element; +ALTER TABLE llx_receptiondet_batch RENAME COLUMN fk_commandefourndet TO fk_elementdet; diff --git a/htdocs/reception/class/receptionlinebatch.class.php b/htdocs/reception/class/receptionlinebatch.class.php index 9b02cef2bc9..81f93a32f37 100644 --- a/htdocs/reception/class/receptionlinebatch.class.php +++ b/htdocs/reception/class/receptionlinebatch.class.php @@ -68,7 +68,7 @@ class ReceptionLineBatch extends CommonObjectLine /** * @var int ID */ - public $fk_commande; + public $fk_element; /** * @var int ID @@ -76,9 +76,9 @@ class ReceptionLineBatch extends CommonObjectLine public $fk_product; /** - * @var int ID. Should be named fk_origin_line ? + * @var int ID */ - public $fk_commandefourndet; + public $fk_elementdet; public $fk_reception; @@ -152,14 +152,14 @@ class ReceptionLineBatch extends CommonObjectLine // Clean parameters - if (isset($this->fk_commande)) { - $this->fk_commande = (int) $this->fk_commande; + if (isset($this->fk_element)) { + $this->fk_element = (int) $this->fk_element; } if (isset($this->fk_product)) { $this->fk_product = (int) $this->fk_product; } - if (isset($this->fk_commandefourndet)) { - $this->fk_commandefourndet = (int) $this->fk_commandefourndet; + if (isset($this->fk_elementdet)) { + $this->fk_elementdet = (int) $this->fk_elementdet; } if (isset($this->qty)) { $this->qty = trim($this->qty); @@ -189,9 +189,9 @@ class ReceptionLineBatch extends CommonObjectLine // Insert request $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."("; - $sql .= "fk_commande,"; + $sql .= "fk_element,"; $sql .= "fk_product,"; - $sql .= "fk_commandefourndet,"; + $sql .= "fk_elementdet,"; $sql .= "qty,"; $sql .= "fk_entrepot,"; $sql .= "fk_user,"; @@ -206,9 +206,9 @@ class ReceptionLineBatch extends CommonObjectLine $sql .= ") VALUES ("; - $sql .= " ".(!isset($this->fk_commande) ? 'NULL' : "'".$this->db->escape($this->fk_commande)."'").","; + $sql .= " ".(!isset($this->fk_element) ? 'NULL' : "'".$this->db->escape($this->fk_element)."'").","; $sql .= " ".(!isset($this->fk_product) ? 'NULL' : "'".$this->db->escape($this->fk_product)."'").","; - $sql .= " ".(!isset($this->fk_commandefourndet) ? 'NULL' : "'".$this->db->escape($this->fk_commandefourndet)."'").","; + $sql .= " ".(!isset($this->fk_elementdet) ? 'NULL' : "'".$this->db->escape($this->fk_elementdet)."'").","; $sql .= " ".(!isset($this->qty) ? 'NULL' : "'".$this->db->escape($this->qty)."'").","; $sql .= " ".(!isset($this->fk_entrepot) ? 'NULL' : "'".$this->db->escape($this->fk_entrepot)."'").","; $sql .= " ".(!isset($this->fk_user) ? 'NULL' : "'".$this->db->escape($this->fk_user)."'").","; @@ -280,9 +280,9 @@ class ReceptionLineBatch extends CommonObjectLine $sql = "SELECT"; $sql .= " t.rowid,"; - $sql .= " t.fk_commande,"; + $sql .= " t.fk_element,"; $sql .= " t.fk_product,"; - $sql .= " t.fk_commandefourndet,"; + $sql .= " t.fk_elementdet,"; $sql .= " t.qty,"; $sql .= " t.fk_entrepot,"; $sql .= " t.fk_user,"; @@ -311,9 +311,9 @@ class ReceptionLineBatch extends CommonObjectLine $this->id = $obj->rowid; - $this->fk_commande = $obj->fk_commande; + $this->fk_element = $obj->fk_element; $this->fk_product = $obj->fk_product; - $this->fk_commandefourndet = $obj->fk_commandefourndet; + $this->fk_elementdet = $obj->fk_elementdet; $this->qty = $obj->qty; $this->fk_entrepot = $obj->fk_entrepot; $this->fk_user = $obj->fk_user; @@ -351,14 +351,14 @@ class ReceptionLineBatch extends CommonObjectLine // Clean parameters - if (isset($this->fk_commande)) { - $this->fk_commande = (int) $this->fk_commande; + if (isset($this->fk_element)) { + $this->fk_element = (int) $this->fk_element; } if (isset($this->fk_product)) { $this->fk_product = (int) $this->fk_product; } - if (isset($this->fk_commandefourndet)) { - $this->fk_commandefourndet = (int) $this->fk_commandefourndet; + if (isset($this->fk_elementdet)) { + $this->fk_elementdet = (int) $this->fk_elementdet; } if (isset($this->qty)) { $this->qty = trim($this->qty); @@ -386,9 +386,9 @@ class ReceptionLineBatch extends CommonObjectLine // Update request $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; - $sql .= " fk_commande=".(isset($this->fk_commande) ? $this->fk_commande : "null").","; + $sql .= " fk_element=".(isset($this->fk_element) ? $this->fk_element : "null").","; $sql .= " fk_product=".(isset($this->fk_product) ? $this->fk_product : "null").","; - $sql .= " fk_commandefourndet=".(isset($this->fk_commandefourndet) ? $this->fk_commandefourndet : "null").","; + $sql .= " fk_elementdet=".(isset($this->fk_elementdet) ? $this->fk_elementdet : "null").","; $sql .= " qty=".(isset($this->qty) ? $this->qty : "null").","; $sql .= " fk_entrepot=".(isset($this->fk_entrepot) ? $this->fk_entrepot : "null").","; $sql .= " fk_user=".(isset($this->fk_user) ? $this->fk_user : "null").","; @@ -517,7 +517,7 @@ class ReceptionLineBatch extends CommonObjectLine { $error = 0; - $object = new CommandeFournisseurDispatch($this->db); + $object = new ReceptionLineBatch($this->db); $this->db->begin(); @@ -626,9 +626,9 @@ class ReceptionLineBatch extends CommonObjectLine { $this->id = 0; - $this->fk_commande = 0; + $this->fk_element = 0; $this->fk_product = 0; - $this->fk_commandefourndet = 0; + $this->fk_elementdet = 0; $this->qty = ''; $this->fk_entrepot = 0; $this->fk_user = 0; @@ -660,9 +660,9 @@ class ReceptionLineBatch extends CommonObjectLine $sql = "SELECT"; $sql .= " t.rowid,"; - $sql .= " t.fk_commande,"; + $sql .= " t.fk_element,"; $sql .= " t.fk_product,"; - $sql .= " t.fk_commandefourndet,"; + $sql .= " t.fk_elementdet,"; $sql .= " t.qty,"; $sql .= " t.fk_entrepot,"; $sql .= " t.fk_user,"; @@ -724,9 +724,9 @@ class ReceptionLineBatch extends CommonObjectLine $line->id = $obj->rowid; - $line->fk_commande = $obj->fk_commande; + $line->fk_element = $obj->fk_element; $line->fk_product = $obj->fk_product; - $line->fk_commandefourndet = $obj->fk_commandefourndet; + $line->fk_elementdet = $obj->fk_elementdet; $line->qty = $obj->qty; $line->fk_entrepot = $obj->fk_entrepot; $line->fk_user = $obj->fk_user; From 815a2e231ff766cb1c6b75ca7e576909fd93e4af Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Tue, 19 Mar 2024 15:31:22 +0100 Subject: [PATCH 004/114] fix mysql old version rename --- htdocs/install/mysql/migration/19.0.0-20.0.0.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/install/mysql/migration/19.0.0-20.0.0.sql b/htdocs/install/mysql/migration/19.0.0-20.0.0.sql index 68d2694aeb7..61d01e6fe20 100644 --- a/htdocs/install/mysql/migration/19.0.0-20.0.0.sql +++ b/htdocs/install/mysql/migration/19.0.0-20.0.0.sql @@ -281,5 +281,5 @@ ALTER TABLE llx_ticket ADD CONSTRAINT llx_ticket_fk_product_barcode_type FOREIGN ALTER TABLE llx_societe ADD COLUMN fk_parent integer NULL; -ALTER TABLE llx_receptiondet_batch RENAME COLUMN fk_commande TO fk_element; -ALTER TABLE llx_receptiondet_batch RENAME COLUMN fk_commandefourndet TO fk_elementdet; +ALTER TABLE llx_receptiondet_batch CHANGE COLUMN fk_commande fk_element integer; +ALTER TABLE llx_receptiondet_batch CHANGE COLUMN fk_commandefourndet fk_elementdet integer; From 446b574de5e9d5fa01ee3c95f230260236e3c0f3 Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Tue, 19 Mar 2024 15:49:42 +0100 Subject: [PATCH 005/114] renaming of columns impact db access --- htdocs/core/modules/modReception.class.php | 2 +- htdocs/expedition/dispatch.php | 4 -- .../class/fournisseur.commande.class.php | 8 +-- htdocs/fourn/commande/dispatch.php | 4 +- htdocs/install/mysql/migration/repair.sql | 56 +++++++++---------- .../tables/llx_receptiondet_batch.key.sql | 2 +- .../mysql/tables/llx_receptiondet_batch.sql | 4 +- htdocs/install/repair.php | 8 +-- .../product/stock/class/productlot.class.php | 2 +- .../stock/stats/commande_fournisseur.php | 2 +- htdocs/reception/card.php | 2 +- htdocs/reception/class/reception.class.php | 10 ++-- htdocs/reception/dispatch.php | 4 +- 13 files changed, 52 insertions(+), 56 deletions(-) diff --git a/htdocs/core/modules/modReception.class.php b/htdocs/core/modules/modReception.class.php index 71dc0b9623f..860181935e1 100644 --- a/htdocs/core/modules/modReception.class.php +++ b/htdocs/core/modules/modReception.class.php @@ -241,7 +241,7 @@ class modReception extends DolibarrModules $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople as sp ON sp.rowid = ee.fk_socpeople'; $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople_extrafields as extra3 ON sp.rowid = extra3.fk_object'; } - $this->export_sql_end[$r] .= ' WHERE c.fk_soc = s.rowid AND c.rowid = ed.fk_reception AND ed.fk_commandefourndet = cd.rowid'; + $this->export_sql_end[$r] .= ' WHERE c.fk_soc = s.rowid AND c.rowid = ed.fk_reception AND ed.fk_elementdet = cd.rowid'; $this->export_sql_end[$r] .= ' AND c.entity IN ('.getEntity('reception').')'; if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) { $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : $user->id); diff --git a/htdocs/expedition/dispatch.php b/htdocs/expedition/dispatch.php index 7e3edde6355..ac376353e85 100644 --- a/htdocs/expedition/dispatch.php +++ b/htdocs/expedition/dispatch.php @@ -773,10 +773,6 @@ if ($object->id > 0 || !empty($object->ref)) { print ''; // Dispatch column print ''; // Warehouse column - /*$sql = "SELECT cfd.rowid, cfd.qty, cfd.fk_entrepot, cfd.batch, cfd.eatby, cfd.sellby, cfd.fk_product"; - $sql .= " FROM ".MAIN_DB_PREFIX."receptiondet_batch as cfd"; - $sql .= " WHERE cfd.fk_commandefourndet = ".(int) $objp->rowid;*/ - $sql = "SELECT ed.rowid, ed.qty, ed.fk_entrepot,"; $sql .= " eb.batch, eb.eatby, eb.sellby, cd.fk_product"; $sql .= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed"; diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index add091dd124..772ac2919ea 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -2252,7 +2252,7 @@ class CommandeFournisseur extends CommonOrder $this->db->begin(); $sql = "INSERT INTO ".$this->db->prefix()."receptiondet_batch"; - $sql .= " (fk_commande, fk_product, qty, fk_entrepot, fk_user, datec, fk_commandefourndet, status, comment, eatby, sellby, batch, fk_reception) VALUES"; + $sql .= " (fk_element, fk_product, qty, fk_entrepot, fk_user, datec, fk_elementdet, status, comment, eatby, sellby, batch, fk_reception) VALUES"; $sql .= " ('".$this->id."','".$product."','".$qty."',".($entrepot > 0 ? "'".$entrepot."'" : "null").",'".$user->id."','".$this->db->idate($now)."','".$fk_commandefourndet."', ".$dispatchstatus.", '".$this->db->escape($comment)."', "; $sql .= ($eatby ? "'".$this->db->idate($eatby)."'" : "null").", ".($sellby ? "'".$this->db->idate($sellby)."'" : "null").", ".($batch ? "'".$this->db->escape($batch)."'" : "null").", ".($fk_reception > 0 ? "'".$this->db->escape($fk_reception)."'" : "null"); $sql .= ")"; @@ -2497,7 +2497,7 @@ class CommandeFournisseur extends CommonOrder // List of already dispatched lines $sql = "SELECT p.ref, p.label,"; $sql .= " e.rowid as warehouse_id, e.ref as entrepot,"; - $sql .= " cfd.rowid as dispatchedlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.fk_commandefourndet"; + $sql .= " cfd.rowid as dispatchedlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.fk_elementdet"; $sql .= " FROM ".$this->db->prefix()."product as p,"; $sql .= " ".$this->db->prefix()."receptiondet_batch as cfd"; $sql .= " LEFT JOIN ".$this->db->prefix()."entrepot as e ON cfd.fk_entrepot = e.rowid"; @@ -2521,7 +2521,7 @@ class CommandeFournisseur extends CommonOrder 'productid' => $objp->fk_product, 'warehouseid' => $objp->warehouse_id, 'qty' => $objp->qty, - 'orderlineid' => $objp->fk_commandefourndet + 'orderlineid' => $objp->fk_elementdet ); } @@ -3670,7 +3670,7 @@ class CommandeFournisseur extends CommonOrder if ($filtre_statut >= 0) { $sql .= ' cfd.fk_reception = e.rowid AND'; } - $sql .= ' cfd.fk_commandefourndet = cd.rowid'; + $sql .= ' cfd.fk_elementdet = cd.rowid'; $sql .= ' AND cd.fk_commande ='.((int) $this->id); if (isset($this->fk_product) && !empty($this->fk_product) > 0) { $sql .= ' AND cd.fk_product = '.((int) $this->fk_product); diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index 90da456e660..bcd9678ed23 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -669,7 +669,7 @@ if ($id > 0 || !empty($ref)) { $products_dispatched = array(); $sql = "SELECT l.rowid, cfd.fk_product, sum(cfd.qty) as qty"; $sql .= " FROM ".MAIN_DB_PREFIX."receptiondet_batch as cfd"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseurdet as l on l.rowid = cfd.fk_commandefourndet"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseurdet as l on l.rowid = cfd.fk_elementdet"; $sql .= " WHERE cfd.fk_commande = ".((int) $object->id); $sql .= " GROUP BY l.rowid, cfd.fk_product"; @@ -1172,7 +1172,7 @@ if ($id > 0 || !empty($ref)) { } $sql .= " FROM ".MAIN_DB_PREFIX."product as p,"; $sql .= " ".MAIN_DB_PREFIX."receptiondet_batch as cfd"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseurdet as cd ON cd.rowid = cfd.fk_commandefourndet"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseurdet as cd ON cd.rowid = cfd.fk_elementdet"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entrepot as e ON cfd.fk_entrepot = e.rowid"; if ($conf->reception->enabled) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."reception as r ON cfd.fk_reception = r.rowid"; diff --git a/htdocs/install/mysql/migration/repair.sql b/htdocs/install/mysql/migration/repair.sql index 6b48ef5ac16..2c0e43dc3fe 100644 --- a/htdocs/install/mysql/migration/repair.sql +++ b/htdocs/install/mysql/migration/repair.sql @@ -1,10 +1,10 @@ -- -- Script to repair some fatal errors due to database corruption --- when current version is 2.6.0 or higher. +-- when current version is 2.6.0 or higher. -- --- Replace xxx with your IP Address +-- Replace xxx with your IP Address -- bind-address = xxx.xxx.xxx.xxx -- CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypass'; -- CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypass'; @@ -65,10 +65,10 @@ -- VMYSQL4.1 INSERT IGNORE INTO llx_product_lot (entity, fk_product, batch, eatby, sellby, datec, fk_user_creat, fk_user_modif) SELECT DISTINCT e.entity, ps.fk_product, pb.batch, pb.eatby, pb.sellby, pb.tms, e.fk_user_author, e.fk_user_author from llx_product_batch as pb, llx_product_stock as ps, llx_entrepot as e WHERE pb.fk_product_stock = ps.rowid AND ps.fk_entrepot = e.rowid; -- -- a tester VPGSQL9.5 INSERT IGNORE INTO llx_product_lot (entity, fk_product, batch, eatby, sellby, datec, fk_user_creat, fk_user_modif) SELECT DISTINCT e.entity, ps.fk_product, pb.batch, pb.eatby, pb.sellby, pb.tms, e.fk_user_author, e.fk_user_author from llx_product_batch as pb, llx_product_stock as ps, llx_entrepot as e WHERE pb.fk_product_stock = ps.rowid AND ps.fk_entrepot = e.rowid ON CONFLICT DO NOTHING; -- -- avant 9.5 faire en variant x pour qu'au 2eme passage, le premier doublon soit dans la tabel cible --- -- INSERT INTO llx_product_lot (entity, fk_product, batch, eatby, sellby, datec, fk_user_creat, fk_user_modif) --- -- SELECT DISTINCT e.entity, ps.fk_product, pb.batch, pb.eatby, pb.sellby, pb.tms, e.fk_user_author, e.fk_user_author +-- -- INSERT INTO llx_product_lot (entity, fk_product, batch, eatby, sellby, datec, fk_user_creat, fk_user_modif) +-- -- SELECT DISTINCT e.entity, ps.fk_product, pb.batch, pb.eatby, pb.sellby, pb.tms, e.fk_user_author, e.fk_user_author -- -- from llx_product_batch as pb, llx_product_stock as ps, llx_entrepot as e --- -- WHERE pb.fk_product_stock = ps.rowid AND ps.fk_entrepot = e.rowid +-- -- WHERE pb.fk_product_stock = ps.rowid AND ps.fk_entrepot = e.rowid -- -- AND NOT EXISTS (SELECT 1 FROM llx_product_lot as b WHERE b.fk_product=ps.fk_product and pb.batch=b.batch) LIMIT x @@ -145,13 +145,13 @@ update llx_product_batch set batch = '' where batch = 'Non défini'; update llx_stock_mouvement set batch = null where batch = 'Non défini'; update llx_stock_mouvement set batch = null where batch = 'Non défini'; -DELETE FROM llx_product_lot WHERE fk_product NOT IN (select rowid from llx_product); -DELETE FROM llx_product_stock WHERE fk_product NOT IN (select rowid from llx_product); +DELETE FROM llx_product_lot WHERE fk_product NOT IN (select rowid from llx_product); +DELETE FROM llx_product_stock WHERE fk_product NOT IN (select rowid from llx_product); DELETE FROM llx_product_stock WHERE reel = 0 AND rowid NOT IN (SELECT fk_product_stock FROM llx_product_batch as pb); --- Merge splitted lines into one in table llx_product_batch +-- Merge splitted lines into one in table llx_product_batch DROP TABLE tmp_llx_product_batch; DROP TABLE tmp_llx_product_batch2; CREATE TABLE tmp_llx_product_batch AS select fk_product_stock, eatby, sellby, batch, SUM(qty) as qty, COUNT(rowid) as nb FROM llx_product_batch GROUP BY fk_product_stock, eatby, sellby, batch HAVING COUNT(rowid) > 1; @@ -175,7 +175,7 @@ delete from llx_product_association where fk_product_fils NOT IN (select rowid f -- Fix: delete category child with no category parent. drop table tmp_categorie; -create table tmp_categorie as select * from llx_categorie; +create table tmp_categorie as select * from llx_categorie; -- select * from llx_categorie where fk_parent not in (select rowid from tmp_categorie) and fk_parent is not null and fk_parent <> 0; delete from llx_categorie where fk_parent not in (select rowid from tmp_categorie) and fk_parent is not null and fk_parent <> 0; drop table tmp_categorie; @@ -397,7 +397,7 @@ update llx_facturedet set product_type = 1 where product_type = 2; update llx_propal set fk_statut = 1 where fk_statut = -1; -delete from llx_commande_fournisseur_dispatch where fk_commandefourndet = 0 or fk_commandefourndet IS NULL; +delete from llx_receptiondet_batch where fk_elementdet = 0 or fk_elementdet IS NULL; delete from llx_menu where menu_handler = 'smartphone'; @@ -408,7 +408,7 @@ update llx_expedition set date_valid = NOW() where fk_statut = 1 and date_valid -- Detect bad consistency between duraction_effective of a task and sum of time of tasks -- select pt.rowid, pt.duration_effective, SUM(ptt.element_duration) as y from llx_projet_task as pt, llx_element_time as ptt where ptt.fk_element = pt.rowid and ptt.elementtype = 'task' group by pt.rowid, pt.duration_effective having pt.duration_effective <> y; update llx_projet_task as pt set pt.duration_effective = (select SUM(ptt.element_duration) as y from llx_element_time as ptt where ptt.fk_element = pt.rowid and ptt.elementtype = 'task') where pt.duration_effective <> (select SUM(ptt.element_duration) as y from llx_element_time as ptt where ptt.fk_element = pt.rowid and ptt.elementtype = 'task'); - + -- Remove duplicate of shipment mode (keep the one with tracking defined) drop table tmp_c_shipment_mode; @@ -443,9 +443,9 @@ UPDATE llx_expensereport_det SET fk_code_ventilation = 0 WHERE fk_code_ventilati -- Clean product prices ---delete from llx_product_price where date_price between '2017-04-20 06:51:00' and '2017-04-20 06:51:05'; +--delete from llx_product_price where date_price between '2017-04-20 06:51:00' and '2017-04-20 06:51:05'; -- Set product prices into llx_product with last price into llx_product_prices ---update llx_product as p set +--update llx_product as p set -- p.price = (select pp.price from llx_product_price as pp where pp.price_level = 1 and pp.fk_product = p.rowid order by pp.tms desc limit 1), -- p.price_ttc = (select pp.price_ttc from llx_product_price as pp where pp.price_level = 1 and pp.fk_product = p.rowid order by pp.tms desc limit 1), -- p.price_min = (select pp.price_min from llx_product_price as pp where pp.price_level = 1 and pp.fk_product = p.rowid order by pp.tms desc limit 1), @@ -503,7 +503,7 @@ UPDATE llx_chargesociales SET date_creation = tms WHERE date_creation IS NULL; --ALTER TABLE llx_table modify column columnname datetime DEFAULT CURRENT_TIMESTAMP; --- Backport a change of value into the hourly rate. +-- Backport a change of value into the hourly rate. -- update llx_element_time as ptt set ptt.thm = (SELECT thm from llx_user as u where ptt.fk_user = u.rowid) where (ptt.thm is null) @@ -513,14 +513,14 @@ update llx_facturedet set product_type = 1 where product_type = 0 AND fk_product update llx_facture_fourn_det set product_type = 0 where product_type = 1 AND fk_product > 0 AND fk_product IN (SELECT rowid FROM llx_product WHERE fk_product_type = 0); update llx_facture_fourn_det set product_type = 1 where product_type = 0 AND fk_product > 0 AND fk_product IN (SELECT rowid FROM llx_product WHERE fk_product_type = 1); - + DELETE FROM llx_mrp_production where qty = 0; UPDATE llx_accounting_bookkeeping set date_creation = tms where date_creation IS NULL; - + -- UPDATE llx_contratdet set label = NULL WHERE label IS NOT NULL; -- UPDATE llx_facturedet_rec set label = NULL WHERE label IS NOT NULL; @@ -528,21 +528,21 @@ UPDATE llx_accounting_bookkeeping set date_creation = tms where date_creation IS --Fix bad sign on multicompany column for customer invoice lines UPDATE llx_facturedet SET multicurrency_subprice = -multicurrency_subprice WHERE ((multicurrency_subprice < 0 and subprice > 0) OR (multicurrency_subprice > 0 and subprice < 0)); UPDATE llx_facturedet SET multicurrency_total_ht = -multicurrency_total_ht WHERE ((multicurrency_total_ht < 0 and total_ht > 0) OR (multicurrency_total_ht > 0 and total_ht < 0)); -UPDATE llx_facturedet SET multicurrency_total_tva = -multicurrency_total_tva WHERE ((multicurrency_total_tva < 0 and total_tva > 0) OR (multicurrency_total_tva > 0 and total_tva < 0)); -UPDATE llx_facturedet SET multicurrency_total_ttc = -multicurrency_total_ttc WHERE ((multicurrency_total_ttc < 0 and total_ttc > 0) OR (multicurrency_total_ttc > 0 and total_ttc < 0)); +UPDATE llx_facturedet SET multicurrency_total_tva = -multicurrency_total_tva WHERE ((multicurrency_total_tva < 0 and total_tva > 0) OR (multicurrency_total_tva > 0 and total_tva < 0)); +UPDATE llx_facturedet SET multicurrency_total_ttc = -multicurrency_total_ttc WHERE ((multicurrency_total_ttc < 0 and total_ttc > 0) OR (multicurrency_total_ttc > 0 and total_ttc < 0)); --Fix bad sign on multicompany column for customer invoices -UPDATE llx_facture SET multicurrency_total_ht = -multicurrency_total_ht WHERE ((multicurrency_total_ht < 0 and total_ht > 0) OR (multicurrency_total_ht > 0 and total_ht < 0)); -UPDATE llx_facture SET multicurrency_total_tva = -multicurrency_total_tva WHERE ((multicurrency_total_tva < 0 and total_tva > 0) OR (multicurrency_total_tva > 0 and total_tva < 0)); -UPDATE llx_facture SET multicurrency_total_ttc = -multicurrency_total_ttc WHERE ((multicurrency_total_ttc < 0 and total_ttc > 0) OR (multicurrency_total_ttc > 0 and total_ttc < 0)); +UPDATE llx_facture SET multicurrency_total_ht = -multicurrency_total_ht WHERE ((multicurrency_total_ht < 0 and total_ht > 0) OR (multicurrency_total_ht > 0 and total_ht < 0)); +UPDATE llx_facture SET multicurrency_total_tva = -multicurrency_total_tva WHERE ((multicurrency_total_tva < 0 and total_tva > 0) OR (multicurrency_total_tva > 0 and total_tva < 0)); +UPDATE llx_facture SET multicurrency_total_ttc = -multicurrency_total_ttc WHERE ((multicurrency_total_ttc < 0 and total_ttc > 0) OR (multicurrency_total_ttc > 0 and total_ttc < 0)); --Fix bad sign on multicurrency column for supplier invoice lines UPDATE llx_facture_fourn_det SET multicurrency_subprice = -multicurrency_subprice WHERE ((multicurrency_subprice < 0 and pu_ht > 0) OR (multicurrency_subprice > 0 and pu_ht < 0)); UPDATE llx_facture_fourn_det SET multicurrency_total_ht = -multicurrency_total_ht WHERE ((multicurrency_total_ht < 0 and total_ht > 0) OR (multicurrency_total_ht > 0 and total_ht < 0)); -UPDATE llx_facture_fourn_det SET multicurrency_total_tva = -multicurrency_total_tva WHERE ((multicurrency_total_tva < 0 and tva > 0) OR (multicurrency_total_tva > 0 and tva < 0)); -UPDATE llx_facture_fourn_det SET multicurrency_total_ttc = -multicurrency_total_ttc WHERE ((multicurrency_total_ttc < 0 and total_ttc > 0) OR (multicurrency_total_ttc > 0 and total_ttc < 0)); +UPDATE llx_facture_fourn_det SET multicurrency_total_tva = -multicurrency_total_tva WHERE ((multicurrency_total_tva < 0 and tva > 0) OR (multicurrency_total_tva > 0 and tva < 0)); +UPDATE llx_facture_fourn_det SET multicurrency_total_ttc = -multicurrency_total_ttc WHERE ((multicurrency_total_ttc < 0 and total_ttc > 0) OR (multicurrency_total_ttc > 0 and total_ttc < 0)); --Fix bad sign on multicompany column for customer invoices -UPDATE llx_facture_fourn SET multicurrency_total_ht = -multicurrency_total_ht WHERE ((multicurrency_total_ht < 0 and total_ht > 0) OR (multicurrency_total_ht > 0 and total_ht < 0)); -UPDATE llx_facture_fourn SET multicurrency_total_tva = -multicurrency_total_tva WHERE ((multicurrency_total_tva < 0 and total_tva > 0) OR (multicurrency_total_tva > 0 and total_tva < 0)); -UPDATE llx_facture_fourn SET multicurrency_total_ttc = -multicurrency_total_ttc WHERE ((multicurrency_total_ttc < 0 and total_ttc > 0) OR (multicurrency_total_ttc > 0 and total_ttc < 0)); +UPDATE llx_facture_fourn SET multicurrency_total_ht = -multicurrency_total_ht WHERE ((multicurrency_total_ht < 0 and total_ht > 0) OR (multicurrency_total_ht > 0 and total_ht < 0)); +UPDATE llx_facture_fourn SET multicurrency_total_tva = -multicurrency_total_tva WHERE ((multicurrency_total_tva < 0 and total_tva > 0) OR (multicurrency_total_tva > 0 and total_tva < 0)); +UPDATE llx_facture_fourn SET multicurrency_total_ttc = -multicurrency_total_ttc WHERE ((multicurrency_total_ttc < 0 and total_ttc > 0) OR (multicurrency_total_ttc > 0 and total_ttc < 0)); UPDATE llx_facturedet SET situation_percent = 100 WHERE situation_percent IS NULL AND fk_prev_id IS NULL; @@ -558,7 +558,7 @@ UPDATE llx_facturedet SET situation_percent = 100 WHERE situation_percent IS NUL --update llx_facture set paye = 1, fk_statut = 2 where rowid in (select rowid from tmp_invoice_deposit_mark_as_available); --- TODO We should fix multicurrency_amount that are empty into llx_societe_remise_except, but we can't because we don't know what is the rate +-- TODO We should fix multicurrency_amount that are empty into llx_societe_remise_except, but we can't because we don't know what is the rate -- We may retreive info fro minvoice line by using fk_facture_line or fk_facture_supplier_line -- select * from llx_societe_remise_except where multicurrency_amount_ht = 0 and amount_ht <> 0; @@ -586,7 +586,7 @@ DELETE FROM llx_rights_def WHERE module = 'hrm' AND perms = 'employee'; -- Sequence to fix the content of llx_bank.amount_main_currency (value was empty and should not for payment on bank account with a different currency so when amount_main_currency is different than amount) -- Note: amount is amount in the currency of the bank account -- Note: pamount is always amount into the main currency --- Note: pmulticurrencyamount is in the currency of invoice +-- Note: pmulticurrencyamount is in the currency of invoice -- Note: amount_main_currency must be NULL or amount in main currency of company (we set it when the currency of the bank account differs from main currency) -- DROP TABLE tmp_bank; -- CREATE TABLE tmp_bank SELECT b.rowid, b.amount, p.rowid as pid, p.amount as pamount, p.multicurrency_amount as pmulticurrencyamount, b.datec FROM llx_bank as b INNER JOIN llx_bank_url as bu ON bu.fk_bank=b.rowid AND bu.type = 'payment' INNER JOIN llx_paiement as p ON bu.url_id = p.rowid WHERE p.multicurrency_amount <> 0 AND p.multicurrency_amount <> p.amount; diff --git a/htdocs/install/mysql/tables/llx_receptiondet_batch.key.sql b/htdocs/install/mysql/tables/llx_receptiondet_batch.key.sql index 0c92a0d8302..4470247061b 100644 --- a/htdocs/install/mysql/tables/llx_receptiondet_batch.key.sql +++ b/htdocs/install/mysql/tables/llx_receptiondet_batch.key.sql @@ -20,4 +20,4 @@ ALTER TABLE llx_receptiondet_batch ADD INDEX idx_receptiondet_batch_fk_commande ALTER TABLE llx_receptiondet_batch ADD INDEX idx_receptiondet_batch_fk_reception (fk_reception); ALTER TABLE llx_receptiondet_batch ADD CONSTRAINT fk_receptiondet_batch_fk_reception FOREIGN KEY (fk_reception) REFERENCES llx_reception (rowid); ALTER TABLE llx_receptiondet_batch ADD INDEX idx_receptiondet_batch_fk_product (fk_product); -ALTER TABLE llx_receptiondet_batch ADD INDEX idx_receptiondet_batch_fk_commandefourndet (fk_commandefourndet); +ALTER TABLE llx_receptiondet_batch ADD INDEX idx_receptiondet_batch_fk_elementdet (fk_elementdet); diff --git a/htdocs/install/mysql/tables/llx_receptiondet_batch.sql b/htdocs/install/mysql/tables/llx_receptiondet_batch.sql index 3f3db04b8cb..4819ed80f6e 100644 --- a/htdocs/install/mysql/tables/llx_receptiondet_batch.sql +++ b/htdocs/install/mysql/tables/llx_receptiondet_batch.sql @@ -28,8 +28,8 @@ create table llx_receptiondet_batch ( rowid integer AUTO_INCREMENT PRIMARY KEY, fk_product integer, - fk_commande integer, -- should be renamed into fk_element - fk_commandefourndet integer, -- should be renamed into fk_elementdet + fk_element integer, -- should be renamed into fk_element + fk_elementdet integer, -- should be renamed into fk_elementdet element_type varchar(50) DEFAULT 'supplier_order' NOT NULL, -- Type of source ('supplier_order', ...) fk_projet integer DEFAULT NULL, fk_reception integer DEFAULT NULL, diff --git a/htdocs/install/repair.php b/htdocs/install/repair.php index 4f2b8adb94f..4b60a146c02 100644 --- a/htdocs/install/repair.php +++ b/htdocs/install/repair.php @@ -1488,7 +1488,7 @@ if ($ok && GETPOST('repair_link_dispatch_lines_supplier_order_lines')) { echo 'Repair llx_receptiondet_batch.fk_commandefourndet'; echo 'Repair in progress. This may take a while.'; - $sql_dispatch = 'SELECT * FROM '.MAIN_DB_PREFIX.'receptiondet_batch WHERE COALESCE(fk_commandefourndet, 0) = 0'; + $sql_dispatch = 'SELECT * FROM '.MAIN_DB_PREFIX.'receptiondet_batch WHERE COALESCE(fk_elementdet, 0) = 0'; $db->begin(); $resql_dispatch = $db->query($sql_dispatch); $n_processed_rows = 0; @@ -1529,12 +1529,12 @@ if ($ok && GETPOST('repair_link_dispatch_lines_supplier_order_lines')) { $qty_for_line = min($remaining_qty, $obj_line->qty); if ($first_iteration) { $sql_attach = 'UPDATE '.MAIN_DB_PREFIX.'receptiondet_batch'; - $sql_attach .= ' SET fk_commandefourndet = '.((int) $obj_line->rowid).', qty = '.((float) $qty_for_line); + $sql_attach .= ' SET fk_elementdet = '.((int) $obj_line->rowid).', qty = '.((float) $qty_for_line); $sql_attach .= ' WHERE rowid = '.((int) $obj_dispatch->rowid); $first_iteration = false; } else { $sql_attach_values = array( - ((int) $obj_dispatch->fk_commande), + ((int) $obj_dispatch->fk_element), ((int) $obj_dispatch->fk_product), ((int) $obj_line->rowid), ((float) $qty_for_line), @@ -1551,7 +1551,7 @@ if ($ok && GETPOST('repair_link_dispatch_lines_supplier_order_lines')) { $sql_attach_values = implode(', ', $sql_attach_values); $sql_attach = 'INSERT INTO '.MAIN_DB_PREFIX.'receptiondet_batch'; - $sql_attach .= ' (fk_commande, fk_product, fk_commandefourndet, qty, fk_entrepot, fk_user, datec, comment, status, tms, batch, eatby, sellby)'; + $sql_attach .= ' (fk_element, fk_product, fk_elementdet, qty, fk_entrepot, fk_user, datec, comment, status, tms, batch, eatby, sellby)'; $sql_attach .= " VALUES (".$sql_attach_values.")"; } diff --git a/htdocs/product/stock/class/productlot.class.php b/htdocs/product/stock/class/productlot.class.php index 3d46b4ff41e..edbf9be17b8 100644 --- a/htdocs/product/stock/class/productlot.class.php +++ b/htdocs/product/stock/class/productlot.class.php @@ -855,7 +855,7 @@ class Productlot extends CommonObject $sql = "SELECT COUNT(DISTINCT cf.fk_soc) as nb_customers, COUNT(DISTINCT cf.rowid) as nb,"; $sql .= " COUNT(cfd.rowid) as nb_rows, SUM(cfdi.qty) as qty"; $sql .= " FROM ".$this->db->prefix()."receptiondet_batch as cfdi"; - $sql .= " INNER JOIN ".$this->db->prefix()."commande_fournisseurdet as cfd ON (cfd.rowid = cfdi.fk_commandefourndet)"; + $sql .= " INNER JOIN ".$this->db->prefix()."commande_fournisseurdet as cfd ON (cfd.rowid = cfdi.fk_elementdet)"; $sql .= " INNER JOIN ".$this->db->prefix()."commande_fournisseur as cf ON (cf.rowid = cfd.fk_commande)"; // $sql .= ", ".$this->db->prefix()."societe as s"; if (!$user->hasRight('societe', 'client', 'voir')) { diff --git a/htdocs/product/stock/stats/commande_fournisseur.php b/htdocs/product/stock/stats/commande_fournisseur.php index e179a65e1e1..a2e40c1db92 100644 --- a/htdocs/product/stock/stats/commande_fournisseur.php +++ b/htdocs/product/stock/stats/commande_fournisseur.php @@ -224,7 +224,7 @@ if ($id > 0 || !empty($ref)) { $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."commande_fournisseur as cf ON (cf.fk_soc = s.rowid)"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."commande_fournisseurdet as cfd ON (cfd.fk_commande = cf.rowid)"; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."receptiondet_batch as cfdi ON (cfdi.fk_commandefourndet = cfd.rowid)"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."receptiondet_batch as cfdi ON (cfdi.fk_elementdet = cfd.rowid)"; if (!$user->hasRight('societe', 'client', 'voir')) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } diff --git a/htdocs/reception/card.php b/htdocs/reception/card.php index b3362854db6..28e7c1933f4 100644 --- a/htdocs/reception/card.php +++ b/htdocs/reception/card.php @@ -1825,7 +1825,7 @@ if ($action == 'create') { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid"; $sql .= " WHERE e.entity IN (".getEntity('reception').")"; $sql .= " AND obj.fk_commande = ".((int) $origin_id); - $sql .= " AND obj.rowid = ed.fk_commandefourndet"; + $sql .= " AND obj.rowid = ed.fk_elementdet"; $sql .= " AND ed.fk_reception = e.rowid"; $sql .= " AND ed.fk_reception !=".((int) $object->id); //if ($filter) $sql.= $filter; diff --git a/htdocs/reception/class/reception.class.php b/htdocs/reception/class/reception.class.php index 5a9257f8259..91aa0164dca 100644 --- a/htdocs/reception/class/reception.class.php +++ b/htdocs/reception/class/reception.class.php @@ -562,7 +562,7 @@ class Reception extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,"; $sql .= " ".MAIN_DB_PREFIX."receptiondet_batch as ed"; $sql .= " WHERE ed.fk_reception = ".((int) $this->id); - $sql .= " AND cd.rowid = ed.fk_commandefourndet"; + $sql .= " AND cd.rowid = ed.fk_elementdet"; dol_syslog(get_class($this)."::valid select details", LOG_DEBUG); $resql = $this->db->query($sql); @@ -1071,7 +1071,7 @@ class Reception extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,"; $sql .= " ".MAIN_DB_PREFIX."receptiondet_batch as ed"; $sql .= " WHERE ed.fk_reception = ".((int) $this->id); - $sql .= " AND cd.rowid = ed.fk_commandefourndet"; + $sql .= " AND cd.rowid = ed.fk_elementdet"; dol_syslog(get_class($this)."::delete select details", LOG_DEBUG); $resql = $this->db->query($sql); @@ -1660,7 +1660,7 @@ class Reception extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,"; $sql .= " ".MAIN_DB_PREFIX."receptiondet_batch as ed"; $sql .= " WHERE ed.fk_reception = ".((int) $this->id); - $sql .= " AND cd.rowid = ed.fk_commandefourndet"; + $sql .= " AND cd.rowid = ed.fk_elementdet"; dol_syslog(get_class($this)."::valid select details", LOG_DEBUG); $resql = $this->db->query($sql); @@ -1818,7 +1818,7 @@ class Reception extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,"; $sql .= " ".MAIN_DB_PREFIX."receptiondet_batch as ed"; $sql .= " WHERE ed.fk_reception = ".((int) $this->id); - $sql .= " AND cd.rowid = ed.fk_commandefourndet"; + $sql .= " AND cd.rowid = ed.fk_elementdet"; dol_syslog(get_class($this)."::valid select details", LOG_DEBUG); $resql = $this->db->query($sql); @@ -1952,7 +1952,7 @@ class Reception extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,"; $sql .= " ".MAIN_DB_PREFIX."receptiondet_batch as ed"; $sql .= " WHERE ed.fk_reception = ".((int) $this->id); - $sql .= " AND cd.rowid = ed.fk_commandefourndet"; + $sql .= " AND cd.rowid = ed.fk_elementdet"; dol_syslog(get_class($this)."::valid select details", LOG_DEBUG); $resql = $this->db->query($sql); diff --git a/htdocs/reception/dispatch.php b/htdocs/reception/dispatch.php index b48ea7b4164..60fc192ef97 100644 --- a/htdocs/reception/dispatch.php +++ b/htdocs/reception/dispatch.php @@ -462,7 +462,7 @@ if ($id > 0 || !empty($ref)) { $products_dispatched = array(); $sql = "SELECT l.rowid, cfd.fk_product, sum(cfd.qty) as qty"; $sql .= " FROM ".MAIN_DB_PREFIX."receptiondet_batch as cfd"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseurdet as l on l.rowid = cfd.fk_commandefourndet"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."receptiondet_batch as l on l.rowid = cfd.fk_elementdet"; $sql .= " WHERE cfd.fk_reception = ".((int) $object->id); $sql .= " GROUP BY l.rowid, cfd.fk_product"; @@ -691,7 +691,7 @@ if ($id > 0 || !empty($ref)) { $sql .= " FROM ".MAIN_DB_PREFIX."receptiondet_batch as cfd"; // commande_fournisseur_dispatch should be named receptiondet_batch $sql .= " WHERE cfd.fk_reception = ".((int) $object->id); $sql .= " AND cfd.fk_commande = ".((int) $objectsrc->id); - $sql .= " AND cfd.fk_commandefourndet = ".(int) $objp->rowid; + $sql .= " AND cfd.fk_elementdet = ".(int) $objp->rowid; //print $sql; $resultsql = $db->query($sql); From 3f5ffc5e9de8ab4b80a06643b61a470db528d27f Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Tue, 19 Mar 2024 15:50:15 +0100 Subject: [PATCH 006/114] renaming of columns impact db access --- htdocs/fourn/class/fournisseur.commande.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 772ac2919ea..1b47a9f1e43 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -2501,7 +2501,7 @@ class CommandeFournisseur extends CommonOrder $sql .= " FROM ".$this->db->prefix()."product as p,"; $sql .= " ".$this->db->prefix()."receptiondet_batch as cfd"; $sql .= " LEFT JOIN ".$this->db->prefix()."entrepot as e ON cfd.fk_entrepot = e.rowid"; - $sql .= " WHERE cfd.fk_commande = ".((int) $this->id); + $sql .= " WHERE cfd.fk_element = ".((int) $this->id); $sql .= " AND cfd.fk_product = p.rowid"; if ($status >= 0) { $sql .= " AND cfd.status = ".((int) $status); From 07597c4515a6c834f854ebdcb36959d7cbb4252d Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Tue, 19 Mar 2024 15:56:44 +0100 Subject: [PATCH 007/114] renaming of columns impact db access --- htdocs/fourn/class/fournisseur.commande.class.php | 2 +- htdocs/fourn/commande/dispatch.php | 4 ++-- htdocs/product/class/product.class.php | 2 +- htdocs/reception/class/reception.class.php | 2 +- htdocs/reception/dispatch.php | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 1b47a9f1e43..4cd598eeec3 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -3534,7 +3534,7 @@ class CommandeFournisseur extends CommonOrder $supplierorderdispatch = new CommandeFournisseurDispatch($this->db); - $filter = array('t.fk_commande' => $this->id); + $filter = array('t.fk_element' => $this->id); if (getDolGlobalString('SUPPLIER_ORDER_USE_DISPATCH_STATUS')) { $filter['t.status'] = 1; // Restrict to lines with status validated } diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index bcd9678ed23..f9ec2a67379 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -670,7 +670,7 @@ if ($id > 0 || !empty($ref)) { $sql = "SELECT l.rowid, cfd.fk_product, sum(cfd.qty) as qty"; $sql .= " FROM ".MAIN_DB_PREFIX."receptiondet_batch as cfd"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseurdet as l on l.rowid = cfd.fk_elementdet"; - $sql .= " WHERE cfd.fk_commande = ".((int) $object->id); + $sql .= " WHERE cfd.fk_element = ".((int) $object->id); $sql .= " GROUP BY l.rowid, cfd.fk_product"; $resql = $db->query($sql); @@ -1177,7 +1177,7 @@ if ($id > 0 || !empty($ref)) { if ($conf->reception->enabled) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."reception as r ON cfd.fk_reception = r.rowid"; } - $sql .= " WHERE cfd.fk_commande = ".((int) $object->id); + $sql .= " WHERE cfd.fk_element = ".((int) $object->id); $sql .= " AND cfd.fk_product = p.rowid"; $sql .= " ORDER BY cfd.rowid ASC"; diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 17aa0d9a6bb..da6b09cb318 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3501,7 +3501,7 @@ class Product extends CommonObject if (!$user->hasRight('societe', 'client', 'voir') && !$forVirtualStock) { $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } - $sql .= " WHERE cf.rowid = fd.fk_commande"; + $sql .= " WHERE cf.rowid = fd.fk_element"; $sql .= " AND cf.fk_soc = s.rowid"; $sql .= " AND cf.entity IN (".getEntity($forVirtualStock && getDolGlobalString('STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE') ? 'stock' : 'supplier_order').")"; $sql .= " AND fd.fk_product = ".((int) $this->id); diff --git a/htdocs/reception/class/reception.class.php b/htdocs/reception/class/reception.class.php index 91aa0164dca..0a5852a4ca2 100644 --- a/htdocs/reception/class/reception.class.php +++ b/htdocs/reception/class/reception.class.php @@ -747,7 +747,7 @@ class Reception extends CommonObject $qty_wished = array(); $supplierorderdispatch = new CommandeFournisseurDispatch($this->db); - $filter = array('t.fk_commande' => $this->origin_id); + $filter = array('t.fk_element' => $this->origin_id); if (getDolGlobalInt('SUPPLIER_ORDER_USE_DISPATCH_STATUS')) { $filter['t.status'] = 1; // Restrict to lines with status validated } diff --git a/htdocs/reception/dispatch.php b/htdocs/reception/dispatch.php index 60fc192ef97..3d2ed4bd36c 100644 --- a/htdocs/reception/dispatch.php +++ b/htdocs/reception/dispatch.php @@ -690,7 +690,7 @@ if ($id > 0 || !empty($ref)) { $sql = "SELECT cfd.rowid, cfd.qty, cfd.fk_entrepot, cfd.batch, cfd.eatby, cfd.sellby, cfd.fk_product"; $sql .= " FROM ".MAIN_DB_PREFIX."receptiondet_batch as cfd"; // commande_fournisseur_dispatch should be named receptiondet_batch $sql .= " WHERE cfd.fk_reception = ".((int) $object->id); - $sql .= " AND cfd.fk_commande = ".((int) $objectsrc->id); + $sql .= " AND cfd.fk_element = ".((int) $objectsrc->id); $sql .= " AND cfd.fk_elementdet = ".(int) $objp->rowid; //print $sql; From 81189c9759beb5319caf6f66ccf6bf6323d78e46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charl=C3=A8ne=20Benke?= <1179011+defrance@users.noreply.github.com> Date: Wed, 20 Mar 2024 12:58:28 +0100 Subject: [PATCH 008/114] Disable change on system product_nature element finished value 1 is associed to bom feature (and factory module) it's better to disable the change of the 2 initial value (consider it as system) --- htdocs/admin/dict.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index d895854ab2c..5a3364e8077 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -13,6 +13,7 @@ * Copyright (C) 2016 Raphaël Doursenaud * Copyright (C) 2019-2022 Frédéric France * Copyright (C) 2020-2022 Open-Dsi + * Copyright (C) 2024 Charlene Benke * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -2129,7 +2130,12 @@ if ($id > 0) { if ($tabname[$id] == "c_actioncomm") { $canbemodified = 1; } - + + if ($tabname[$id] == "c_product_nature" && in_array($obj->code, array(0, 1))) { + $canbedisabled = 0; + $canbemodified = 0; + $iserasable = 0; + } // Build Url. The table is id=, the id of line is rowid= $rowidcol = empty($tabrowid[$id]) ? 'rowid' : $tabrowid[$id]; // If rowidcol not defined From 979003e539023e3cbc18c0396f0c11ddc341e816 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 20 Mar 2024 14:15:47 +0100 Subject: [PATCH 009/114] Update dict.php --- htdocs/admin/dict.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index 5a3364e8077..da9b0271b15 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -2130,7 +2130,7 @@ if ($id > 0) { if ($tabname[$id] == "c_actioncomm") { $canbemodified = 1; } - + if ($tabname[$id] == "c_product_nature" && in_array($obj->code, array(0, 1))) { $canbedisabled = 0; $canbemodified = 0; From cb3880cc62b1a6964bced8d7177ed833777304d0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 20 Mar 2024 15:15:28 +0100 Subject: [PATCH 010/114] Clean translations --- dev/translation/ignore_translation_keys.lst | 11 ------- htdocs/admin/system/about.php | 10 +++--- htdocs/bookcal/admin/setup.php | 31 ------------------- .../movement/doc/pdf_standard.modules.php | 4 +-- htdocs/don/class/don.class.php | 2 +- 5 files changed, 8 insertions(+), 50 deletions(-) diff --git a/dev/translation/ignore_translation_keys.lst b/dev/translation/ignore_translation_keys.lst index 173355fe70a..0efa17f72b5 100644 --- a/dev/translation/ignore_translation_keys.lst +++ b/dev/translation/ignore_translation_keys.lst @@ -1025,15 +1025,10 @@ VideoGeneration ## pass - this list needs to be cleaned up ##################################################################### ##################################################################### -$minimum -AI_KEY_API_ AddService AnHelpMessage Analytic AnalyticLabel -BOOKCAL_MYPARAM10 -BOOKCAL_MYPARAM8 -BOOKCAL_MYPARAM9 BankId Bcc Birthdate @@ -1061,9 +1056,6 @@ Facture FailedToConnectToSFTPAfterSSHAuthentication FailedToLogin First -France -Germany -Greece GroupCreate GroupUpdate INVOICE_RETAINED_WARRANTY_LIMITED_TO_FINAL_SITUATION @@ -1078,7 +1070,6 @@ InputValueIsNotAnNumber InterDate Inventory Code InvoiceReplace -Italy ItemID JobApplications JobPosition @@ -1092,7 +1083,6 @@ LocalTax1IsUsedExample LocalTax2IsNotUsedExample LocalTax2IsUsedExample Logs -Lot/Série MAIN_IMAP_USE_PHPIMAPDesc MYMODULE_CATEGORY_ID_XXX MYMODULE_MYPARAM1 @@ -1138,7 +1128,6 @@ Recruited Ref. Product RefNewContract Societe -Spain Stable Suggested TaskModifieddInDolibarr diff --git a/htdocs/admin/system/about.php b/htdocs/admin/system/about.php index a9c87ca61a3..14ea98ccc00 100644 --- a/htdocs/admin/system/about.php +++ b/htdocs/admin/system/about.php @@ -90,31 +90,31 @@ print ''; if (preg_match('/^fr_/i', $langs->getDefaultLang())) { print '
  • '; - print ''.$langs->trans("OfficialWebSiteLocal", $langs->transnoentitiesnoconv("France")).''; + print ''.$langs->trans("OfficialWebSiteLocal", $langs->transnoentitiesnoconv("CountryFR")).''; print '
  • '; } if (preg_match('/^el_/i', $langs->getDefaultLang())) { print '
  • '; - print ''.$langs->trans("OfficialWebSiteLocal", $langs->transnoentitiesnoconv("Greece")).''; + print ''.$langs->trans("OfficialWebSiteLocal", $langs->transnoentitiesnoconv("CountryGR")).''; print '
  • '; } if (preg_match('/^es_/i', $langs->getDefaultLang())) { print '
  • '; - print ''.$langs->trans("OfficialWebSiteLocal", $langs->transnoentitiesnoconv("Spain")).''; + print ''.$langs->trans("OfficialWebSiteLocal", $langs->transnoentitiesnoconv("CountryES")).''; print '
  • '; } if (preg_match('/^it_/i', $langs->getDefaultLang())) { print '
  • '; - print ''.$langs->trans("OfficialWebSiteLocal", $langs->transnoentitiesnoconv("Italy")).''; + print ''.$langs->trans("OfficialWebSiteLocal", $langs->transnoentitiesnoconv("CountryIT")).''; print '
  • '; } if (preg_match('/^de_/i', $langs->getDefaultLang())) { print '
  • '; - print ''.$langs->trans("OfficialWebSiteLocal", $langs->transnoentitiesnoconv("Germany")).''; + print ''.$langs->trans("OfficialWebSiteLocal", $langs->transnoentitiesnoconv("CountryDE")).''; print '
  • '; }*/ print '
  • '; diff --git a/htdocs/bookcal/admin/setup.php b/htdocs/bookcal/admin/setup.php index dd16dfb720e..5d8a19b9d42 100644 --- a/htdocs/bookcal/admin/setup.php +++ b/htdocs/bookcal/admin/setup.php @@ -71,37 +71,6 @@ $formSetup = new FormSetup($db); // Setup conf BOOKCAL_PUBLIC_INTERFACE_TOPIC $item = $formSetup->newItem('BOOKCAL_PUBLIC_INTERFACE_TOPIC'); $item->defaultFieldValue = 'MyBigCompany public interface for Bookcal'; -/*// Setup conf BOOKCAL_MYPARAM8 -$item = $formSetup->newItem('BOOKCAL_MYPARAM8'); -$TField = array( - 'test01' => $langs->trans('test01'), - 'test02' => $langs->trans('test02'), - 'test03' => $langs->trans('test03'), - 'test04' => $langs->trans('test04'), - 'test05' => $langs->trans('test05'), - 'test06' => $langs->trans('test06'), -); -$item->setAsMultiSelect($TField); -$item->helpText = $langs->transnoentities('BOOKCAL_MYPARAM8'); - - -// Setup conf BOOKCAL_MYPARAM9 -$formSetup->newItem('BOOKCAL_MYPARAM9')->setAsSelect($TField); - - -// Setup conf BOOKCAL_MYPARAM10 -$item = $formSetup->newItem('BOOKCAL_MYPARAM10'); -$item->setAsColor(); -$item->defaultFieldValue = '#FF0000'; -$item->nameText = $item->getNameText().' more html text '; -$item->fieldInputOverride = ''; -$item->helpText = $langs->transnoentities('AnHelpMessage');*/ -//$item->fieldValue = ''; -//$item->fieldAttr = array() ; // fields attribute only for compatible fields like input text -//$item->fieldOverride = false; // set this var to override field output will override $fieldInputOverride and $fieldOutputOverride too -//$item->fieldInputOverride = false; // set this var to override field input -//$item->fieldOutputOverride = false; // set this var to override field output - $setupnotempty = + count($formSetup->items); diff --git a/htdocs/core/modules/movement/doc/pdf_standard.modules.php b/htdocs/core/modules/movement/doc/pdf_standard.modules.php index e6d6645d8b2..7226cf40377 100644 --- a/htdocs/core/modules/movement/doc/pdf_standard.modules.php +++ b/htdocs/core/modules/movement/doc/pdf_standard.modules.php @@ -66,7 +66,7 @@ class pdf_standard extends ModelePDFMovement global $conf, $langs, $mysoc; // Load traductions files required by page - $langs->loadLangs(array("main", "companies")); + $langs->loadLangs(array("main", "companies", "productbatch")); $this->db = $db; $this->name = "stdmouvement"; @@ -861,7 +861,7 @@ class pdf_standard extends ModelePDFMovement //$pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height); if (empty($hidetop)) { $pdf->SetXY($this->posxqty, $tab_top + 1); - $pdf->MultiCell($this->posxup - $this->posxqty, 2, $outputlangs->transnoentities("Lot/Série"), '', 'C'); + $pdf->MultiCell($this->posxup - $this->posxqty, 2, $outputlangs->transnoentities("Batch"), '', 'C'); } //Code Inv diff --git a/htdocs/don/class/don.class.php b/htdocs/don/class/don.class.php index 7645df64357..693b76e7b91 100644 --- a/htdocs/don/class/don.class.php +++ b/htdocs/don/class/don.class.php @@ -352,7 +352,7 @@ class Don extends CommonObject $err++; } else { if ($this->amount < $minimum && $minimum > 0) { - $error_string[] = $langs->trans('MinimumAmount', $langs->transnoentitiesnoconv('$minimum')); + $error_string[] = $langs->trans('MinimumAmount', $minimum); $err++; } } From e3c76ca86a941a215fa1560141c29ed42e7ba03c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 20 Mar 2024 15:25:47 +0100 Subject: [PATCH 011/114] Clean translation files --- dev/translation/dynamic_translation_keys.lst | 8 -------- dev/translation/ignore_translation_keys.lst | 1 + htdocs/core/class/html.formmail.class.php | 2 +- htdocs/langs/en_US/mails.lang | 1 - htdocs/langs/en_US/ticket.lang | 3 +-- 5 files changed, 3 insertions(+), 12 deletions(-) diff --git a/dev/translation/dynamic_translation_keys.lst b/dev/translation/dynamic_translation_keys.lst index 6c62129fae6..6be815d4eca 100644 --- a/dev/translation/dynamic_translation_keys.lst +++ b/dev/translation/dynamic_translation_keys.lst @@ -31,9 +31,6 @@ CodePaymentTerm IdPaymentTerm LabelPaymentTerm -# ticket -TicketAnswered - # website_template Message Map @@ -3685,8 +3682,3 @@ WebPortalSetupPage XSubsriptionErrors YouCanChooseAModelForYouMailContent YouCanMakeSomeInstructionForEmail -helpWithAi -ExtrafieldLinestringGeo -ExtrafieldMultiPointGeo -ExtrafieldPointGeo -ExtrafieldPolygonGeo diff --git a/dev/translation/ignore_translation_keys.lst b/dev/translation/ignore_translation_keys.lst index 0efa17f72b5..21b8f270427 100644 --- a/dev/translation/ignore_translation_keys.lst +++ b/dev/translation/ignore_translation_keys.lst @@ -39,6 +39,7 @@ FieldsTitle FileIntegrityIsOkButFilesWereAdded FirstUseDate FollowingLinksArePublic +HelpWithAI HidePassword IPP_Device InstallChoiceRecommanded diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 7d369ebe4f4..f5809abbe23 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -1452,7 +1452,7 @@ class FormMail extends Form $out = ''; $out .= ''; - //$out .= $form->textwithpicto($langs->trans('helpWithAi'), $langs->trans("YouCanMakeSomeInstructionForEmail")); + //$out .= $form->textwithpicto($langs->trans('HelpWithAI'), $langs->trans("YouCanMakeSomeInstructionForEmail")); $out .= ''; $out .= ''; diff --git a/htdocs/langs/en_US/mails.lang b/htdocs/langs/en_US/mails.lang index 136ee7edb0b..4c1a5a08f0a 100644 --- a/htdocs/langs/en_US/mails.lang +++ b/htdocs/langs/en_US/mails.lang @@ -187,7 +187,6 @@ EmailOptedOut=Email owner has requested to not contact him with this email anymo EvenUnsubscribe=Include opt-out emails EvenUnsubscribeDesc=Include opt-out emails when you select emails as targets. Useful for mandatory service emails for example. XEmailsDoneYActionsDone=%s emails pre-qualified, %s emails successfully processed (for %s record/actions done) -helpWithAi=Generate message from AI YouCanMakeSomeInstructionForEmail=You can make some instructions for your Email (Example: generate image in email template...) ModelTemplate=Email template YouCanChooseAModelForYouMailContent= You can choose one of template models or generate one with AI diff --git a/htdocs/langs/en_US/ticket.lang b/htdocs/langs/en_US/ticket.lang index b61db89919d..0f0faf90c05 100644 --- a/htdocs/langs/en_US/ticket.lang +++ b/htdocs/langs/en_US/ticket.lang @@ -69,7 +69,6 @@ Read=Read Assigned=Assigned NeedMoreInformation=Waiting for reporter feedback NeedMoreInformationShort=Waiting for feedback -TicketAnswered=Answered Waiting=Waiting SolvedClosed=Solved Deleted=Deleted @@ -135,7 +134,7 @@ TicketsActivatePublicInterfaceHelp=Public interface allow any visitors to create TicketsAutoAssignTicket=Automatically assign the user who created the ticket TicketsAutoAssignTicketHelp=When creating a ticket, the user can be automatically assigned to the ticket. TicketNumberingModules=Tickets numbering module -TicketsModelModule=Document templates for tickets +TicketsModelModule=Document templates for tickets TicketNotifyTiersAtCreation=Notify third party at creation TicketsDisableCustomerEmail=Always disable emails when a ticket is created from public interface TicketsPublicNotificationNewMessage=Send email(s) when a new message/comment is added to a ticket From 9e7aeca44744a86e5208ae85a11b9bae6c92f118 Mon Sep 17 00:00:00 2001 From: Kamel Khelifa Date: Wed, 20 Mar 2024 15:26:19 +0100 Subject: [PATCH 012/114] FIX: Fix save directory for invoice ODT and multientities --- .../modules/facture/doc/doc_generic_invoice_odt.modules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php b/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php index 6b28da3e1e1..66182bcebba 100644 --- a/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php +++ b/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php @@ -253,7 +253,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures $object->fetch_thirdparty(); - $dir = $conf->facture->dir_output; + $dir = empty($conf->facture->multidir_output[$object->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[$object->entity]; $objectref = dol_sanitizeFileName($object->ref); if (!preg_match('/specimen/i', $objectref)) { $dir .= "/".$objectref; From bd76a084a417053defada919e87884b5d7c1a01b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 20 Mar 2024 17:45:49 +0100 Subject: [PATCH 013/114] Better structure of payment pages to allow integration of other usages --- htdocs/public/payment/paymentko.php | 182 +++++++++++++------------ htdocs/public/payment/paymentok.php | 204 +++++++++++++++------------- 2 files changed, 209 insertions(+), 177 deletions(-) diff --git a/htdocs/public/payment/paymentko.php b/htdocs/public/payment/paymentko.php index 3df08fffe53..8e60a9adea9 100644 --- a/htdocs/public/payment/paymentko.php +++ b/htdocs/public/payment/paymentko.php @@ -120,6 +120,7 @@ $object = new stdClass(); // For triggers * Actions */ +// None @@ -127,6 +128,10 @@ $object = new stdClass(); // For triggers * View */ +// TODO check if we have redirtodomain to do. +$doactionsthenrediret = 0; + + dol_syslog("Callback url when an online payment is refused or canceled. query_string=".(empty($_SERVER["QUERY_STRING"]) ? '' : $_SERVER["QUERY_STRING"])." script_uri=".(empty($_SERVER["SCRIPT_URI"]) ? '' : $_SERVER["SCRIPT_URI"]), LOG_DEBUG, 0, '_payment'); $tracepost = ""; @@ -165,10 +170,7 @@ if (!empty($_SESSION['ipaddress'])) { // To avoid to make action twice } // Send an email - $sendemail = ''; - if (getDolGlobalString('ONLINE_PAYMENT_SENDEMAIL')) { - $sendemail = getDolGlobalString('ONLINE_PAYMENT_SENDEMAIL'); - } + $sendemail = getDolGlobalString('ONLINE_PAYMENT_SENDEMAIL'); // Send warning of error to administrator if ($sendemail) { @@ -208,89 +210,99 @@ if (!empty($_SESSION['ipaddress'])) { // To avoid to make action twice unset($_SESSION['ipaddress']); } -$head = ''; -if (getDolGlobalString('ONLINE_PAYMENT_CSS_URL')) { - $head = ''."\n"; -} - -$conf->dol_hide_topmenu = 1; -$conf->dol_hide_leftmenu = 1; - -$replacemainarea = (empty($conf->dol_hide_leftmenu) ? '
    ' : '').'
    '; -llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea); - - -// Show ko message -print ''."\n"; -print '
    '."\n"; - -// Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo) -// Define logo and logosmall -$logosmall = $mysoc->logo_small; -$logo = $mysoc->logo; -$paramlogo = 'ONLINE_PAYMENT_LOGO_'.$suffix; -if (!empty($conf->global->$paramlogo)) { - $logosmall = getDolGlobalString($paramlogo); -} elseif (getDolGlobalString('ONLINE_PAYMENT_LOGO')) { - $logosmall = getDolGlobalString('ONLINE_PAYMENT_LOGO'); -} -//print ''."\n"; -// Define urllogo -$urllogo = ''; -$urllogofull = ''; -if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) { - $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall); - $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall); -} elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) { - $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo); - $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo); -} - -// Output html code for logo -if ($urllogo) { - print '
    '; - print '
    '; - print ''; - print '
    '; - if (!getDolGlobalString('MAIN_HIDE_POWERED_BY')) { - print ''; +// Show answer page +if (empty($doactionsthenrediret)) { + $head = ''; + if (getDolGlobalString('ONLINE_PAYMENT_CSS_URL')) { + $head = ''."\n"; } - print '
    '; -} -if (getDolGlobalString('MAIN_IMAGE_PUBLIC_PAYMENT')) { - print '
    '; - print ''; - print '
    '; + + $conf->dol_hide_topmenu = 1; + $conf->dol_hide_leftmenu = 1; + + $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '
    ' : '').'
    '; + llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea); + + + // Show ko message + print ''."\n"; + print '
    '."\n"; + + // Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo) + // Define logo and logosmall + $logosmall = $mysoc->logo_small; + $logo = $mysoc->logo; + $paramlogo = 'ONLINE_PAYMENT_LOGO_'.$suffix; + if (!empty($conf->global->$paramlogo)) { + $logosmall = getDolGlobalString($paramlogo); + } elseif (getDolGlobalString('ONLINE_PAYMENT_LOGO')) { + $logosmall = getDolGlobalString('ONLINE_PAYMENT_LOGO'); + } + //print ''."\n"; + // Define urllogo + $urllogo = ''; + $urllogofull = ''; + if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) { + $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall); + $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall); + } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) { + $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo); + $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo); + } + + // Output html code for logo + if ($urllogo) { + print '
    '; + print '
    '; + print ''; + print '
    '; + if (!getDolGlobalString('MAIN_HIDE_POWERED_BY')) { + print ''; + } + print '
    '; + } + if (getDolGlobalString('MAIN_IMAGE_PUBLIC_PAYMENT')) { + print '
    '; + print ''; + print '
    '; + } + + + print '

    '; + + + print $langs->trans("YourPaymentHasNotBeenRecorded")."

    "; + + $key = 'ONLINE_PAYMENT_MESSAGE_KO'; + if (!empty($conf->global->$key)) { + print $conf->global->$key; + } + + $type = GETPOST('s', 'alpha'); + $ref = GETPOST('ref', 'alphanohtml'); + $tag = GETPOST('tag', 'alpha'); + require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; + if ($type || $tag) { + $urlsubscription = getOnlinePaymentUrl(0, ($type ? $type : 'free'), $ref, $FinalPaymentAmt, $tag); + + print $langs->trans("ClickHereToTryAgain", $urlsubscription); + } + + print "\n
    \n"; + + + htmlPrintOnlineFooter($mysoc, $langs, 0, $suffix); + + llxFooter('', 'public'); } -print '

    '; - - -print $langs->trans("YourPaymentHasNotBeenRecorded")."

    "; - -$key = 'ONLINE_PAYMENT_MESSAGE_KO'; -if (!empty($conf->global->$key)) { - print $conf->global->$key; -} - -$type = GETPOST('s', 'alpha'); -$ref = GETPOST('ref', 'alphanohtml'); -$tag = GETPOST('tag', 'alpha'); -require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; -if ($type || $tag) { - $urlsubscription = getOnlinePaymentUrl(0, ($type ? $type : 'free'), $ref, $FinalPaymentAmt, $tag); - - print $langs->trans("ClickHereToTryAgain", $urlsubscription); -} - -print "\n
    \n"; - - -htmlPrintOnlineFooter($mysoc, $langs, 0, $suffix); - - -llxFooter('', 'public'); - $db->close(); + + +// If option to do a redirect somewhere else is defined. +if (empty($doactionsthenrediret)) { + // Do the redirect to an error page + // TODO +} diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index 4e1c12dc196..4a6c958ba9a 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -159,15 +159,13 @@ $error = 0; /* - * Actions + * Actions and view */ +// TODO check if we have redirtodomain to do. +$doactionsthenrediret = 0; -/* - * View - */ - $now = dol_now(); dol_syslog("Callback url when a payment was done. query_string=".(empty($_SERVER["QUERY_STRING"]) ? '' : dol_escape_htmltag($_SERVER["QUERY_STRING"]))." script_uri=".(empty($_SERVER["SCRIPT_URI"]) ? '' : dol_escape_htmltag($_SERVER["SCRIPT_URI"])), LOG_DEBUG, 0, '_payment'); @@ -197,59 +195,64 @@ if (getDolGlobalString('ONLINE_PAYMENT_CSS_URL')) { $conf->dol_hide_topmenu = 1; $conf->dol_hide_leftmenu = 1; -$replacemainarea = (empty($conf->dol_hide_leftmenu) ? '
    ' : '').'
    '; -llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea); + +// Show header +if (empty($doactionsthenrediret)) { + $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '
    ' : '').'
    '; + llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea); -// Show message -print ''."\n"; -print '
    '."\n"; + // Show page content id="dolpaymentdiv" + print ''."\n"; + print '
    '."\n"; -// Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo) -// Define logo and logosmall -$logosmall = $mysoc->logo_small; -$logo = $mysoc->logo; -$paramlogo = 'ONLINE_PAYMENT_LOGO_'.$suffix; -if (!empty($conf->global->$paramlogo)) { - $logosmall = getDolGlobalString($paramlogo); -} elseif (getDolGlobalString('ONLINE_PAYMENT_LOGO')) { - $logosmall = getDolGlobalString('ONLINE_PAYMENT_LOGO'); -} -//print ''."\n"; -// Define urllogo -$urllogo = ''; -$urllogofull = ''; -if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) { - $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall); - $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall); -} elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) { - $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo); - $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo); -} - -// Output html code for logo -if ($urllogo) { - print '
    '; - print '
    '; - print ''; - print '
    '; - if (!getDolGlobalString('MAIN_HIDE_POWERED_BY')) { - print ''; + // Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo) + // Define logo and logosmall + $logosmall = $mysoc->logo_small; + $logo = $mysoc->logo; + $paramlogo = 'ONLINE_PAYMENT_LOGO_'.$suffix; + if (!empty($conf->global->$paramlogo)) { + $logosmall = getDolGlobalString($paramlogo); + } elseif (getDolGlobalString('ONLINE_PAYMENT_LOGO')) { + $logosmall = getDolGlobalString('ONLINE_PAYMENT_LOGO'); } - print '
    '; -} -if (getDolGlobalString('MAIN_IMAGE_PUBLIC_PAYMENT')) { - print '
    '; - print ''; - print '
    '; + //print ''."\n"; + // Define urllogo + $urllogo = ''; + $urllogofull = ''; + if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) { + $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall); + $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall); + } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) { + $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo); + $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo); + } + + // Output html code for logo + if ($urllogo) { + print '
    '; + print '
    '; + print ''; + print '
    '; + if (!getDolGlobalString('MAIN_HIDE_POWERED_BY')) { + print ''; + } + print '
    '; + } + if (getDolGlobalString('MAIN_IMAGE_PUBLIC_PAYMENT')) { + print '
    '; + print ''; + print '
    '; + } + + + print '


    '; } -print '


    '; - - +// Validate the payment (for payment mode that need another step after the callback return for this). if (isModEnabled('paypal')) { if ($paymentmethod === 'paypal') { // We call this page only if payment is ok on payment system if ($PAYPALTOKEN) { @@ -391,7 +394,7 @@ dol_syslog("ispaymentok=".$ispaymentok." tmptag=".var_export($tmptag, true), LOG $appli = $mysoc->name; -// Make complementary actions +// Make complementary actions (post payment actions if payment is ok) $ispostactionok = 0; $postactionmessages = array(); if ($ispaymentok) { @@ -1821,7 +1824,6 @@ if ($ispaymentok) { } } - if ($ispaymentok) { // Get on url call $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION['onlinetoken'] : $PAYPALTOKEN; @@ -1847,18 +1849,39 @@ if ($ispaymentok) { $error++; } } +} - print $langs->trans("YourPaymentHasBeenRecorded")."
    \n"; - if ($TRANSACTIONID) { - print $langs->trans("ThisIsTransactionId", $TRANSACTIONID)."

    \n"; + +// Show result message +if (empty($doactionsthenrediret)) { + if ($ispaymentok) { + print $langs->trans("YourPaymentHasBeenRecorded")."
    \n"; + if ($TRANSACTIONID) { + print $langs->trans("ThisIsTransactionId", $TRANSACTIONID)."

    \n"; + } + + // Show a custom message + $key = 'ONLINE_PAYMENT_MESSAGE_OK'; + if (getDolGlobalString($key)) { + print '
    '; + print getDolGlobalString($key); + } + } else { + print $langs->trans('DoExpressCheckoutPaymentAPICallFailed')."
    \n"; + print $langs->trans('DetailedErrorMessage').": ".$ErrorLongMsg."
    \n"; + print $langs->trans('ShortErrorMessage').": ".$ErrorShortMsg."
    \n"; + print $langs->trans('ErrorCode').": ".$ErrorCode."
    \n"; + print $langs->trans('ErrorSeverityCode').": ".$ErrorSeverityCode."
    \n"; + + if ($mysoc->email) { + print "\nPlease, send a screenshot of this page to ".$mysoc->email."
    \n"; + } } +} - $key = 'ONLINE_PAYMENT_MESSAGE_OK'; - if (!empty($conf->global->$key)) { - print '
    '; - print $conf->global->$key; - } +// Send email +if ($ispaymentok) { $sendemail = getDolGlobalString('ONLINE_PAYMENT_SENDEMAIL'); $tmptag = dolExplodeIntoArray($fulltag, '.', '='); @@ -1954,6 +1977,8 @@ if ($ispaymentok) { } } } else { + $sendemail = getDolGlobalString('ONLINE_PAYMENT_SENDEMAIL'); + // Get on url call $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION['onlinetoken'] : $PAYPALTOKEN; $payerID = empty($PAYPALPAYERID) ? $_SESSION['payerID'] : $PAYPALPAYERID; @@ -1971,29 +1996,6 @@ if ($ispaymentok) { // End call triggers } - print $langs->trans('DoExpressCheckoutPaymentAPICallFailed')."
    \n"; - print $langs->trans('DetailedErrorMessage').": ".$ErrorLongMsg."
    \n"; - print $langs->trans('ShortErrorMessage').": ".$ErrorShortMsg."
    \n"; - print $langs->trans('ErrorCode').": ".$ErrorCode."
    \n"; - print $langs->trans('ErrorSeverityCode').": ".$ErrorSeverityCode."
    \n"; - - if ($mysoc->email) { - print "\nPlease, send a screenshot of this page to ".$mysoc->email."
    \n"; - } - - $sendemail = ''; - if (getDolGlobalString('PAYMENTONLINE_SENDEMAIL')) { - $sendemail = getDolGlobalString('PAYMENTONLINE_SENDEMAIL'); - } - // TODO Remove local option to keep only the generic one ? - if ($paymentmethod == 'paypal' && getDolGlobalString('PAYPAL_PAYONLINE_SENDEMAIL')) { - $sendemail = getDolGlobalString('PAYPAL_PAYONLINE_SENDEMAIL'); - } elseif ($paymentmethod == 'paybox' && getDolGlobalString('PAYBOX_PAYONLINE_SENDEMAIL')) { - $sendemail = getDolGlobalString('PAYBOX_PAYONLINE_SENDEMAIL'); - } elseif ($paymentmethod == 'stripe' && getDolGlobalString('STRIPE_PAYONLINE_SENDEMAIL')) { - $sendemail = getDolGlobalString('STRIPE_PAYONLINE_SENDEMAIL'); - } - // Send warning of error to administrator if ($sendemail) { $companylangs = new Translate('', $conf); @@ -2036,19 +2038,37 @@ if ($ispaymentok) { } -print "\n
    \n"; - -print "\n"; - - -htmlPrintOnlineFooter($mysoc, $langs, 0, $suffix); - - // Clean session variables to avoid duplicate actions if post is resent unset($_SESSION["FinalPaymentAmt"]); unset($_SESSION["TRANSACTIONID"]); -llxFooter('', 'public'); +// Close page content id="dolpaymentdiv" +if (empty($doactionsthenrediret)) { + print "\n
    \n"; + + print "\n"; +} + + +// Show footer +if (empty($doactionsthenrediret)) { + htmlPrintOnlineFooter($mysoc, $langs, 0, $suffix); + + llxFooter('', 'public'); +} + $db->close(); + + +// If option to do a redirect somewhere else. +if (empty($doactionsthenrediret)) { + if ($ispaymentok) { + // Do the redirect to a success page + // TODO + } else { + // Do the redirect to an error page + // TODO + } +} From 5ff590c646f4f9954159ebfda163cabc379435ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 20 Mar 2024 17:49:43 +0100 Subject: [PATCH 014/114] fix phan --- htdocs/accountancy/admin/categories_list.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/htdocs/accountancy/admin/categories_list.php b/htdocs/accountancy/admin/categories_list.php index 2f1b22cf778..37f065d1c2e 100644 --- a/htdocs/accountancy/admin/categories_list.php +++ b/htdocs/accountancy/admin/categories_list.php @@ -328,6 +328,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes') { // delete // activate if ($action == $acts[0]) { + $sql = ''; $rowidcol = "rowid"; if ($rowid) { @@ -346,6 +347,7 @@ if ($action == $acts[0]) { // disable if ($action == $acts[1]) { + $sql = ''; $rowidcol = "rowid"; if ($rowid) { @@ -364,6 +366,7 @@ if ($action == $acts[1]) { // favorite if ($action == 'activate_favorite') { + $sql = ''; $rowidcol = "rowid"; if ($rowid) { @@ -382,6 +385,7 @@ if ($action == 'activate_favorite') { // disable favorite if ($action == 'disable_favorite') { + $sql = ''; $rowidcol = "rowid"; if ($rowid) { From 0191993a1633de75aabbc4f03d5c4b5f3eb1d08d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 20 Mar 2024 19:41:44 +0100 Subject: [PATCH 015/114] FIX Selection of line to copy --- htdocs/compta/facture/card.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 5ddd4d56809..69c113e86d7 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -3524,11 +3524,15 @@ if ($action == 'create') { setRadioForTypeOfInvoice(); }); function setRadioForTypeOfInvoice() { - console.log("Change radio"); + console.log("Change radio for type of invoice"); if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) { + jQuery("#checkforselects").prop("disabled", true); + jQuery("#checkforselects").prop("checked", false); jQuery(".checkforselect").prop("disabled", true); jQuery(".checkforselect").prop("checked", false); } else { + jQuery("#checkforselects").prop("disabled", false); + jQuery("#checkforselects").prop("checked", true); jQuery(".checkforselect").prop("disabled", false); jQuery(".checkforselect").prop("checked", true); } From 8ab3333eec2dc009ef294e783b5f83e15d87131a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 20 Mar 2024 20:59:08 +0100 Subject: [PATCH 016/114] FIX logo of paypal payment on payment page --- htdocs/public/payment/newpayment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 9e5d578e01a..9825b331f1b 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -2151,7 +2151,7 @@ if ($action != 'dopayment') { if (getDolGlobalString('PAYPAL_API_INTEGRAL_OR_PAYPALONLY') != 'integral') { print '
     
    '; } - print ' '; + print ' '; if (getDolGlobalString('PAYPAL_API_INTEGRAL_OR_PAYPALONLY') == 'integral') { print '
    '; print ''.$langs->trans("CreditOrDebitCard").' - '; From 34bd1f0fd300bfda0c263a5cce60a5122a94c213 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 20 Mar 2024 21:00:37 +0100 Subject: [PATCH 017/114] Doc --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 32270994e3b..9f275d641ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -72,7 +72,7 @@ FIX: #yogosha21416 For users: ---------- -NEW: Compatibility with PHP 8.2 +NEW: Compatibility with PHP 8.2 (warning must be disabled) NEW: Module Workstation (used to enhance the module BOM and Manufacturing Order) is now stable NEW: Add a confirmation popup when deleting extrafields NEW: Add type 'icon' type for extrafields From ef1d1fdcfbab89b6457423a4c8acfe843a111746 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 20 Mar 2024 21:09:32 +0100 Subject: [PATCH 018/114] Fix warnings --- htdocs/takepos/index.php | 21 ++++++++++++++------- htdocs/takepos/invoice.php | 5 ++++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index b4541b45715..8d020c7e7d4 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -959,11 +959,11 @@ function OpenDrawer(){ } function DolibarrOpenDrawer() { - console.log("DolibarrOpenDrawer call ajax url /takepos/ajax/ajax.php?action=opendrawer&token=&term="); + console.log("DolibarrOpenDrawer call ajax url /takepos/ajax/ajax.php?action=opendrawer&token=&term="); $.ajax({ type: "GET", data: { token: '' }, - url: "", + url: "", }); } @@ -1037,8 +1037,8 @@ $( document ).ready(function() { LoadProducts(0); Refresh(); 0 ? getDolGlobalInt('CASHDESK_READER_KEYCODE_FOR_ENTER'.$_SESSION['takeposterminal']) : ''; +$keyCodeForEnter = ''; +if (!empty($_SESSION['takeposterminal'])) { + $keyCodeForEnter = getDolGlobalInt('CASHDESK_READER_KEYCODE_FOR_ENTER'.$_SESSION['takeposterminal']) > 0 ? getDolGlobalString('CASHDESK_READER_KEYCODE_FOR_ENTER'.$_SESSION['takeposterminal']) : ''; +} ?>
    @@ -1134,7 +1137,11 @@ if (!getDolGlobalString('TAKEPOS_HIDE_HEAD_BAR')) { - trans("TerminalName", $_SESSION["takeposterminal"])); ?> + trans("TerminalName", $_SESSION["takeposterminal"])); + } + ?> - '.dol_print_date(dol_now(), "day").''; ?> @@ -1416,7 +1423,7 @@ if (getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0 || getDolGlobalString('T $sql = "SELECT rowid, status, entity FROM ".MAIN_DB_PREFIX."pos_cash_fence WHERE"; $sql .= " entity = ".((int) $conf->entity)." AND "; -$sql .= " posnumber = ".((int) $_SESSION["takeposterminal"])." AND "; +$sql .= " posnumber = ".((int) empty($_SESSION["takeposterminal"]) ? 0 : $_SESSION["takeposterminal"])." AND "; $sql .= " date_creation > '".$db->idate(dol_get_first_hour(dol_now()))."'"; $resql = $db->query($sql); diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index 1d2430e5d55..2592d778715 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -1840,8 +1840,11 @@ if ($placeid > 0) { $sql .= " AND ps.fk_product = ".((int) $line->fk_product); $resql = $db->query($sql); if ($resql) { + $stock_real = 0; $obj = $db->fetch_object($resql); - $stock_real = price2num($obj->reel, 'MS'); + if ($obj) { + $stock_real = price2num($obj->reel, 'MS'); + } $htmlforlines .= $line->qty; if ($line->qty && $line->qty > $stock_real) { $htmlforlines .= ''; From e16d1d5de934e6e77c569d1899dc2208601a43e7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 20 Mar 2024 21:27:28 +0100 Subject: [PATCH 019/114] FIX #28978 FIX #28976 --- htdocs/takepos/index.php | 3 +-- htdocs/user/logout.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index 8d020c7e7d4..4eb11d2286f 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -74,7 +74,6 @@ if ($setcurrency != "") { // We will recalculate amount for foreign currency at next call of invoice.php when $_SESSION["takeposcustomercurrency"] differs from invoice->multicurrency_code. } -$_SESSION["urlfrom"] = '/takepos/index.php'; $langs->loadLangs(array("bills", "orders", "commercial", "cashdesk", "receiptprinter", "banks")); @@ -1187,7 +1186,7 @@ if (!getDolGlobalString('TAKEPOS_HIDE_HEAD_BAR')) { ?>
    diff --git a/htdocs/user/logout.php b/htdocs/user/logout.php index 75f2fa6f069..be39b2fda02 100644 --- a/htdocs/user/logout.php +++ b/htdocs/user/logout.php @@ -72,7 +72,7 @@ if ($reshook < 0) { } // Define url to go after disconnect -$urlfrom = empty($_SESSION["urlfrom"]) ? '' : $_SESSION["urlfrom"]; +$urlfrom = empty($_SESSION["urlfrom"]) ? GETPOST('urlfrom') : $_SESSION["urlfrom"]; // Define url to go $url = DOL_URL_ROOT."/index.php"; // By default go to login page From 440c7b4493c67cf4e938341fd07096b96fb3e61c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 20 Mar 2024 21:27:28 +0100 Subject: [PATCH 020/114] FIX #28978 FIX #28976 --- htdocs/takepos/index.php | 3 +-- htdocs/user/logout.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index c58d0f5a81b..dc03d83ff90 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -73,7 +73,6 @@ if ($setcurrency != "") { // We will recalculate amount for foreign currency at next call of invoice.php when $_SESSION["takeposcustomercurrency"] differs from invoice->multicurrency_code. } -$_SESSION["urlfrom"] = '/takepos/index.php'; $langs->loadLangs(array("bills", "orders", "commercial", "cashdesk", "receiptprinter", "banks")); @@ -1146,7 +1145,7 @@ if (!getDolGlobalString('TAKEPOS_HIDE_HEAD_BAR')) { ?>
    diff --git a/htdocs/user/logout.php b/htdocs/user/logout.php index 4713d4e9e97..77fcb90a4b9 100644 --- a/htdocs/user/logout.php +++ b/htdocs/user/logout.php @@ -72,7 +72,7 @@ if ($reshook < 0) { } // Define url to go after disconnect -$urlfrom = empty($_SESSION["urlfrom"]) ? '' : $_SESSION["urlfrom"]; +$urlfrom = empty($_SESSION["urlfrom"]) ? GETPOST('urlfrom') : $_SESSION["urlfrom"]; // Define url to go $url = DOL_URL_ROOT."/index.php"; // By default go to login page From 5bae4ffe4d5cd6cbd323c92ecee6ef6e43f42460 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 20 Mar 2024 21:27:28 +0100 Subject: [PATCH 021/114] FIX #28978 FIX #28976 --- htdocs/takepos/index.php | 3 +-- htdocs/user/logout.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index 97dae7e1a14..99374eebc9f 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -73,7 +73,6 @@ if ($setcurrency != "") { // We will recalculate amount for foreign currency at next call of invoice.php when $_SESSION["takeposcustomercurrency"] differs from invoice->multicurrency_code. } -$_SESSION["urlfrom"] = '/takepos/index.php'; $langs->loadLangs(array("bills", "orders", "commercial", "cashdesk", "receiptprinter", "banks")); @@ -1107,7 +1106,7 @@ if (empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) { }?>
    diff --git a/htdocs/user/logout.php b/htdocs/user/logout.php index d71ee34d93f..129ae24df06 100644 --- a/htdocs/user/logout.php +++ b/htdocs/user/logout.php @@ -72,7 +72,7 @@ if ($reshook < 0) { } // Define url to go after disconnect -$urlfrom = empty($_SESSION["urlfrom"]) ? '' : $_SESSION["urlfrom"]; +$urlfrom = empty($_SESSION["urlfrom"]) ? GETPOST('urlfrom') : $_SESSION["urlfrom"]; // Define url to go $url = DOL_URL_ROOT."/index.php"; // By default go to login page From dc15b2ee79f3a25722eee498b86b34f121de1ef2 Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 20 Mar 2024 13:39:11 +0100 Subject: [PATCH 022/114] Qual: Bump logToCheckStyle for better filename handling # Qual: Bump logToCheckStyle for better filename handling Some notifications from the PHPCS step in pre-commit extracted too many characters for the filename in a specific case. The update to logToCheckStyle fixes that. --- .github/workflows/pre-commit.yml | 2 +- .github/workflows/windows-ci.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index b29ae8aa809..671a266c767 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -106,7 +106,7 @@ jobs: ls -l ~/.cache/pre-commit/ - name: Convert Raw Log to Annotations - uses: mdeweerd/logToCheckStyle@2024.3.2 + uses: mdeweerd/logToCheckStyle@v2024.3.4 if: ${{ failure() }} with: in: ${{ env.RAW_LOG }} diff --git a/.github/workflows/windows-ci.yaml b/.github/workflows/windows-ci.yaml index edcb9d39226..cb467055156 100644 --- a/.github/workflows/windows-ci.yaml +++ b/.github/workflows/windows-ci.yaml @@ -150,7 +150,7 @@ jobs: for /f "tokens=2 delims==" %%A in ('doskey /m:err') do EXIT /B %%A - name: Convert Raw Log to Annotations - uses: mdeweerd/logToCheckStyle@2024.3.2 + uses: mdeweerd/logToCheckStyle@v2024.3.4 if: ${{ failure() }} with: in: ${{ env.PHPUNIT_LOG }} From 33486f10c05b9e24796aa29ced078ccf31b13d3f Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 20 Mar 2024 13:58:43 +0100 Subject: [PATCH 023/114] Fix PhanTypeMismatchReturnNullable by initialising return value --- htdocs/adherents/class/adherent.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index c6ce7429708..f71fa705c3f 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -560,12 +560,13 @@ class Adherent extends CommonObject * Return translated label by the nature of a adherent (physical or moral) * * @param string $morphy Nature of the adherent (physical or moral) - * @param int $addbadge Add badge (1=Full label, 2=First letters only) + * @param int<0,2> $addbadge Add badge (1=Full label, 2=First letters only) * @return string Label */ public function getmorphylib($morphy = '', $addbadge = 0) { global $langs; + $s = ''; // Clean var if (!$morphy) { @@ -573,7 +574,6 @@ class Adherent extends CommonObject } if ($addbadge) { - $s = ''; $labeltoshowm = $langs->trans("Moral"); $labeltoshowp = $langs->trans("Physical"); if ($morphy == 'phy') { From 3b93de27097f3a8926d1d9f750a952472dffde8c Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 20 Mar 2024 14:10:45 +0100 Subject: [PATCH 024/114] Fix PhanTypeMismatchReturnNullable by initialising return value + Some PHPdoc typing --- .../adherents/class/adherentstats.class.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/htdocs/adherents/class/adherentstats.class.php b/htdocs/adherents/class/adherentstats.class.php index f99b20f86d5..612f408edd9 100644 --- a/htdocs/adherents/class/adherentstats.class.php +++ b/htdocs/adherents/class/adherentstats.class.php @@ -3,6 +3,7 @@ * Copyright (c) 2005-2011 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2023 Waël Almoman + * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -168,15 +169,15 @@ class AdherentStats extends Stats /** * Return count of member by status group by adh type, total and average * - * @param int $numberYears Number of years to scan (0 = all) - * @return array Array with total of draft, pending, uptodate, expired, resiliated for each member type + * @param int $numberYears Number of years to scan (0 = all) + * @return array Array with total of draft, pending, uptodate, expired, resiliated for each member type */ public function countMembersByTypeAndStatus($numberYears = 0) { global $user; $now = dol_now(); - $endYear = date('Y'); + $endYear = (int) date('Y'); $startYear = $endYear - $numberYears; $sql = "SELECT t.rowid as fk_adherent_type, t.libelle as label"; @@ -224,7 +225,7 @@ class AdherentStats extends Stats 'members_resiliated' => (int) $objp->members_resiliated ); $totalrow = 0; - foreach ($MembersCountArray[$objp->fk_adherent_type] as $key=>$nb) { + foreach ($MembersCountArray[$objp->fk_adherent_type] as $key => $nb) { if ($key != 'label') { $totalrow += $nb; $totalstatus[$key] += $nb; @@ -244,16 +245,17 @@ class AdherentStats extends Stats /** * Return count of member by status group by adh type, total and average * - * @param int $numberYears Number of years to scan (0 = all) - * @return array Array with total of draft, pending, uptodate, expired, resiliated for each member tag + * @param int $numberYears Number of years to scan (0 = all) + * @return array Array with total of draft, pending, uptodate, expired, resiliated for each member tag */ public function countMembersByTagAndStatus($numberYears = 0) { global $user; $now = dol_now(); - $endYear = date('Y'); + $endYear = (int) date('Y'); $startYear = $endYear - $numberYears; + $MembersCountArray = []; $sql = "SELECT c.rowid as fk_categorie, c.label as label"; $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_DRAFT, "'members_draft'", 'NULL').") as members_draft"; @@ -282,7 +284,6 @@ class AdherentStats extends Stats if ($result) { $num = $this->db->num_rows($result); $i = 0; - $MembersCountArray = []; $totalstatus = array( 'label' => 'Total', 'members_draft' => 0, @@ -304,7 +305,7 @@ class AdherentStats extends Stats 'members_resiliated' => (int) $objp->members_resiliated ); $totalrow = 0; - foreach ($MembersCountArray[$objp->fk_categorie] as $key=>$nb) { + foreach ($MembersCountArray[$objp->fk_categorie] as $key => $nb) { if ($key != 'label') { $totalrow += $nb; $totalstatus[$key] += $nb; From 3a27977b46fc942eb664e9f933bbab556051f5d8 Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 20 Mar 2024 14:18:37 +0100 Subject: [PATCH 025/114] Fix PhanTypeMismatchReturnNullable with typing test --- htdocs/comm/action/class/actioncomm.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index f4f77bcaa9d..09e73b188f8 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -1393,7 +1393,7 @@ class ActionComm extends CommonObject * * @param User $user Object user * @param int $load_state_board Load indicator array this->nb - * @return WorkboardResponse|int Return integer <0 if KO, WorkboardResponse if OK + * @return WorkboardResponse|int<-1,1> Return integer <0 if KO, WorkboardResponse if OK */ public function load_board($user, $load_state_board = 0) { @@ -1462,7 +1462,7 @@ class ActionComm extends CommonObject } $this->db->free($resql); - if (empty($load_state_board)) { + if (empty($load_state_board) && $response instanceof WorkboardResponse) { return $response; } else { return 1; From 0a1a663e3471360ce6a8b79e8df535ad027f6609 Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 20 Mar 2024 14:21:35 +0100 Subject: [PATCH 026/114] Fix PhanTypeMismatchReturnNullable with initialisation --- htdocs/comm/propal/class/api_proposals.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/comm/propal/class/api_proposals.class.php b/htdocs/comm/propal/class/api_proposals.class.php index aa1e3d0e980..546d40d052d 100644 --- a/htdocs/comm/propal/class/api_proposals.class.php +++ b/htdocs/comm/propal/class/api_proposals.class.php @@ -4,6 +4,7 @@ * Copyright (C) 2020 Thibault FOUCART * Copyright (C) 2022 ATM Consulting * Copyright (C) 2022 OpenDSI + * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -410,6 +411,7 @@ class Proposals extends DolibarrApi } $errors = []; + $updateRes = 0; $this->db->begin(); foreach ($request_data as $TData) { From d245dab56b56dcfab7454a395b790052a094a9c3 Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 20 Mar 2024 14:56:14 +0100 Subject: [PATCH 027/114] Fix PhanTypeMismatchReturnNullable by setting variable --- htdocs/projet/class/task.class.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index 45dcad80025..84d78726599 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -2051,9 +2051,10 @@ class Task extends CommonObjectLine $this->error = $clone_task->error; $error++; } - // End - if (!$error) { + if ($error) { + $clone_task_id = 0; // For static tool check + } else { $clone_task_id = $clone_task->id; $clone_task_ref = $clone_task->ref; From 7e1bf61c0db34f4deb6308e03472444a8da63249 Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 20 Mar 2024 17:59:48 +0100 Subject: [PATCH 028/114] Fix PhanTypeMismatchReturnNullable with init --- htdocs/core/class/html.formprojet.class.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/html.formprojet.class.php b/htdocs/core/class/html.formprojet.class.php index 9bbc5e75018..b6f50754c6b 100644 --- a/htdocs/core/class/html.formprojet.class.php +++ b/htdocs/core/class/html.formprojet.class.php @@ -3,6 +3,7 @@ * Copyright (C) 2015 Marcos García * Copyright (C) 2018 Charlene Benke * Copyright (C) 2024 Frédéric France + * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -686,7 +687,7 @@ class FormProjets extends Form * @param string $morecss Add more css * @param int $noadmininfo 0=Add admin info, 1=Disable admin info * @param int $addcombojs 1=Add a js combo - * @return int|string The HTML select list of element or '' if nothing or -1 if KO + * @return int<-1,-1>|string The HTML select list of element or '' if nothing or -1 if KO */ public function selectOpportunityStatus($htmlname, $preselected = '-1', $showempty = 1, $useshortlabel = 0, $showallnone = 0, $showpercent = 0, $morecss = '', $noadmininfo = 0, $addcombojs = 0) { @@ -701,6 +702,7 @@ class FormProjets extends Form if ($resql) { $num = $this->db->num_rows($resql); $i = 0; + $sellist = ''; if ($num > 0) { $sellist = ''; print ''; $newcardbutton = ''; -$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition')); -$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition')); +$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss' => 'reposition')); +$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss' => 'reposition')); $newcardbutton .= dolGetButtonTitleSeparator(); $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/variants/card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd); @@ -561,7 +563,7 @@ foreach ($object->fields as $key => $val) { // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php'; // Fields from hook -$parameters = array('arrayfields'=>$arrayfields); +$parameters = array('arrayfields' => $arrayfields); $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; @@ -618,7 +620,7 @@ foreach ($object->fields as $key => $val) { // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; // Hook fields -$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray); +$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray); $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; @@ -757,7 +759,7 @@ while ($i < $imaxinloop) { // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; // Fields from hook - $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray); + $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray); $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; // Other @@ -826,7 +828,7 @@ if ($num == 0) { $db->free($resql); -$parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql); +$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql); $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; diff --git a/htdocs/workstation/workstation_list.php b/htdocs/workstation/workstation_list.php index 2d1e9d9fefc..3638739a101 100644 --- a/htdocs/workstation/workstation_list.php +++ b/htdocs/workstation/workstation_list.php @@ -2,6 +2,7 @@ /* Copyright (C) 2007-2017 Laurent Destailleur * Copyright (C) 2020 Gauthier VERDOL + * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -149,6 +150,7 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php'; $object->fields = dol_sort_array($object->fields, 'position'); $arrayfields = dol_sort_array($arrayfields, 'position'); +'@phan-var-force array,position?:int,help?:string}> $arrayfields'; // dol_sort_array looses type for Phan $permissiontoread = $user->hasRight('workstation', 'workstation', 'read'); $permissiontoadd = $user->hasRight('workstation', 'workstation', 'write'); From 44ef0de1ef1a8440bb666a32bf77990426fba2bb Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 20 Mar 2024 20:05:35 +0100 Subject: [PATCH 043/114] Fix null return by initialising return value, forcing type --- htdocs/core/class/stats.class.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/htdocs/core/class/stats.class.php b/htdocs/core/class/stats.class.php index 14b636dd2ab..135c9118e03 100644 --- a/htdocs/core/class/stats.class.php +++ b/htdocs/core/class/stats.class.php @@ -129,6 +129,7 @@ abstract class Stats if ($foundintocache) { // Cache file found and is not too old dol_syslog(get_class($this).'::'.__FUNCTION__." read data from cache file ".$newpathofdestfile." ".$filedate."."); $data = json_decode(file_get_contents($newpathofdestfile), true); + '@phan-var-force array,array{0:int<1,12>,1:int}> $data'; } else { $year = $startyear; $sm = $startmonth - 1; @@ -188,7 +189,7 @@ abstract class Stats * @param int $cachedelay Delay we accept for cache file (0=No read, no save of cache, -1=No read but save) * @param int $format 0=Label of abscissa is a translated text, 1=Label of abscissa is month number, 2=Label of abscissa is first letter of month * @param int $startmonth month of the fiscal year start min 1 max 12 ; if 1 = january - * @return array Array of values + * @return array,array> Array of values */ public function getAmountByMonthWithPrevYear($endyear, $startyear, $cachedelay = 0, $format = 0, $startmonth = 1) { @@ -199,6 +200,7 @@ abstract class Stats } $datay = array(); + $data = array(); // Return value // Search into cache if (!empty($cachedelay)) { @@ -238,7 +240,6 @@ abstract class Stats $year++; } - $data = array(); // $data = array('xval'=>array(0=>xlabel,1=>yval1,2=>yval2...),...) for ($i = 0; $i < 12; $i++) { $data[$i][] = isset($datay[$endyear][($i + $sm) % 12]['label']) ? $datay[$endyear][($i + $sm) % 12]['label'] : $datay[$endyear][($i + $sm) % 12][0]; // set label @@ -272,17 +273,17 @@ abstract class Stats } /** - * @param int $year year number - * @return array array of values + * @param int $year year number + * @return array,array{0:int<1,12>,1:int|float}> Array of values */ abstract protected function getAverageByMonth($year); /** - * Return average of entity by month for several years + * Return average of entity by month for several years * * @param int $endyear Start year * @param int $startyear End year - * @return array{int<0,11>,array} Array of values + * @return array> Array of values */ public function getAverageByMonthWithPrevYear($endyear, $startyear) { @@ -291,6 +292,7 @@ abstract class Stats } $datay = array(); + $data = array(); $year = $startyear; while ($year <= $endyear) { @@ -298,8 +300,6 @@ abstract class Stats $year++; } - $data = array(); - for ($i = 0; $i < 12; $i++) { $data[$i][] = $datay[$endyear][$i][0]; $year = $startyear; @@ -353,6 +353,7 @@ abstract class Stats if ($foundintocache) { // Cache file found and is not too old dol_syslog(get_class($this).'::'.__FUNCTION__." read data from cache file ".$newpathofdestfile." ".$filedate."."); $data = json_decode(file_get_contents($newpathofdestfile), true); + '@phan-var-force array,array{0:int<1,12>,1:int|float}> $data'; // Phan can't decode json_decode's return value } else { // This method is defined in parent object only, not into abstract, so we disable phpstan warning /** @phpstan-ignore-next-line */ From 5ee5a4ac2c705b8225a4eff1ee0068b1b197462d Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 20 Mar 2024 20:49:03 +0100 Subject: [PATCH 044/114] Suppress PhanDeprecatedFunction message for stripe --- htdocs/stripe/admin/stripe.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/htdocs/stripe/admin/stripe.php b/htdocs/stripe/admin/stripe.php index d5a27ba20fb..919e80088c6 100644 --- a/htdocs/stripe/admin/stripe.php +++ b/htdocs/stripe/admin/stripe.php @@ -4,6 +4,7 @@ * Copyright (C) 2017 Saasprov * Copyright (C) 2018-2022 Thibault FOUCART * Copyright (C) 2018 Frédéric France + * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -256,6 +257,7 @@ if (empty($conf->stripeconnect->enabled)) { } } $endpoint->url = $url; + // @phan-suppress-next-line PhanDeprecatedFunction $endpoint->save(); if ($endpoint->status == 'enabled') { @@ -328,6 +330,7 @@ if (empty($conf->stripeconnect->enabled)) { } } $endpoint->url = $url; + // @phan-suppress-next-line PhanDeprecatedFunction $endpoint->save(); if ($endpoint->status == 'enabled') { print ''; From 942239b5d633be96558b2ac59c3f6543a2d52a81 Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 20 Mar 2024 19:56:20 +0100 Subject: [PATCH 045/114] Update PHPdoc to show nullable return --- htdocs/core/db/sqlite3.class.php | 12 ++++++------ htdocs/core/modules/DolibarrModules.class.php | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/htdocs/core/db/sqlite3.class.php b/htdocs/core/db/sqlite3.class.php index 060e7318b65..1c28d1d71a8 100644 --- a/htdocs/core/db/sqlite3.class.php +++ b/htdocs/core/db/sqlite3.class.php @@ -389,14 +389,14 @@ class DoliDBSqlite3 extends DoliDB } /** - * Execute a SQL request and return the resultset + * Execute a SQL request and return the resultset * - * @param string $query SQL query string - * @param int $usesavepoint 0=Default mode, 1=Run a savepoint before and a rollbock to savepoint if error (this allow to have some request with errors inside global transactions). + * @param string $query SQL query string + * @param int $usesavepoint 0=Default mode, 1=Run a savepoint before and a rollbock to savepoint if error (this allow to have some request with errors inside global transactions). * Note that with Mysql, this parameter is not used as Myssql can already commit a transaction even if one request is in error, without using savepoints. - * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) - * @param int $result_mode Result mode (not used with sqlite) - * @return bool|SQLite3Result Resultset of answer + * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) + * @param int $result_mode Result mode (not used with sqlite) + * @return bool|SQLite3Result|null Resultset of answer */ public function query($query, $usesavepoint = 0, $type = 'auto', $result_mode = 0) { diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index 0e0eb57ca22..850ec739d06 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -1295,7 +1295,7 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it } if (!$dirfound) { - dol_syslog("A module ask to load sql files into ".$reldir." but this directory was not found.", LOG_WARNING); + dol_syslog("A module wants to load sql files from ".$reldir." but this directory was not found.", LOG_WARNING); } return $ok; } From 53c628f2197d1177e53e9420380de8ac12010f84 Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 20 Mar 2024 20:06:46 +0100 Subject: [PATCH 046/114] Cast DolEditor::Create to string to avoid mistyping as void --- htdocs/core/class/commonobject.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index b826ea69205..41a9a69114d 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -7269,7 +7269,7 @@ abstract class CommonObject if (!preg_match('/search_/', $keyprefix)) { // If keyprefix is search_ or search_options_, we must just use a simple text field require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, false, ROWS_5, '90%'); - $out = $doleditor->Create(1, '', true, '', '', '', $morecss); + $out = (string) $doleditor->Create(1, '', true, '', '', '', $morecss); } else { $out = ''; } @@ -7277,7 +7277,7 @@ abstract class CommonObject if (!preg_match('/search_/', $keyprefix)) { // If keyprefix is search_ or search_options_, we must just use a simple text field require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, isModEnabled('fckeditor') && $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_5, '90%'); - $out = $doleditor->Create(1, '', true, '', '', $moreparam, $morecss); + $out = (string) $doleditor->Create(1, '', true, '', '', $moreparam, $morecss); } else { $out = ''; } From fc6af2047940c5b200a889985d14b97c2f226bff Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 20 Mar 2024 22:48:53 +0100 Subject: [PATCH 047/114] Update typing for database functions --- htdocs/core/db/Database.interface.php | 7 ++++--- htdocs/core/db/DoliDB.class.php | 2 +- htdocs/core/db/mysqli.class.php | 6 +++--- htdocs/core/db/pgsql.class.php | 4 ++-- htdocs/core/db/sqlite3.class.php | 6 +++--- htdocs/debugbar/class/TraceableDB.php | 7 ++++--- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/htdocs/core/db/Database.interface.php b/htdocs/core/db/Database.interface.php index 72a5114558a..9613688e753 100644 --- a/htdocs/core/db/Database.interface.php +++ b/htdocs/core/db/Database.interface.php @@ -5,6 +5,7 @@ * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2014-2015 Raphaël Doursenaud + * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -326,7 +327,7 @@ interface Database * Create a table into database * * @param string $table Name of table - * @param array $fields Associative table [field name][table of descriptions] + * @param array|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string}> $fields Associative table [field name][table of descriptions] * @param string $primary_key Name of the field that will be the primary key * @param string $type Type of the table * @param array $unique_keys Associative array Name of fields that will be unique key => value @@ -360,7 +361,7 @@ interface Database * * @param string $table Name of table * @param string $field_name Name of field to add - * @param string $field_desc Associative array of description of the field to insert [parameter name][parameter value] + * @param array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string} $field_desc Associative array of description of the field to insert [parameter name][parameter value] * @param string $field_position Optional ex .: "after field stuff" * @return int Return integer <0 if KO, >0 if OK */ @@ -384,7 +385,7 @@ interface Database * * @param string $table Name of table * @param string $field_name Name of field to modify - * @param string $field_desc Array with description of field format + * @param array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string} $field_desc Array with description of field format * @return int Return integer <0 if KO, >0 if OK */ public function DDLUpdateField($table, $field_name, $field_desc); diff --git a/htdocs/core/db/DoliDB.class.php b/htdocs/core/db/DoliDB.class.php index 73470391fce..19bb694558b 100644 --- a/htdocs/core/db/DoliDB.class.php +++ b/htdocs/core/db/DoliDB.class.php @@ -266,7 +266,7 @@ abstract class DoliDB implements Database /** * Return version of database server into an array * - * @return array Version array + * @return string[] Version array */ public function getVersionArray() { diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index ff63113e47b..be8ed977963 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -814,7 +814,7 @@ class DoliDBMysqli extends DoliDB * Create a table into database * * @param string $table Name of table - * @param array $fields Tableau associatif [nom champ][tableau des descriptions] + * @param array|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string}> $fields Tableau associatif [nom champ][tableau des descriptions] * @param string $primary_key Nom du champ qui sera la clef primaire * @param string $type Type de la table * @param array $unique_keys Tableau associatifs Nom de champs qui seront clef unique => valeur @@ -941,7 +941,7 @@ class DoliDBMysqli extends DoliDB * * @param string $table Name of table * @param string $field_name Name of field to add - * @param string $field_desc Associative table with description of field to insert [parameter name][parameter value] + * @param array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string} $field_desc Associative table with description of field to insert [parameter name][parameter value] * @param string $field_position Optional e.g.: "after some_field" * @return int Return integer <0 if KO, >0 if OK */ @@ -988,7 +988,7 @@ class DoliDBMysqli extends DoliDB * * @param string $table Name of table * @param string $field_name Name of field to modify - * @param string $field_desc Array with description of field format + * @param array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string} $field_desc Array with description of field format * @return int Return integer <0 if KO, >0 if OK */ public function DDLUpdateField($table, $field_name, $field_desc) diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index cba500c0a0e..14ba90b5bd9 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -1057,7 +1057,7 @@ class DoliDBPgsql extends DoliDB * Create a table into database * * @param string $table Nom de la table - * @param array $fields Tableau associatif [nom champ][tableau des descriptions] + * @param array|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string}> $fields Tableau associatif [nom champ][tableau des descriptions] * @param string $primary_key Nom du champ qui sera la clef primaire * @param string $type Type de la table * @param array $unique_keys Tableau associatifs Nom de champs qui seront clef unique => valeur @@ -1257,7 +1257,7 @@ class DoliDBPgsql extends DoliDB * * @param string $table Name of table * @param string $field_name Name of field to modify - * @param string $field_desc Array with description of field format + * @param array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string} $field_desc Array with description of field format * @return int Return integer <0 if KO, >0 if OK */ public function DDLUpdateField($table, $field_name, $field_desc) diff --git a/htdocs/core/db/sqlite3.class.php b/htdocs/core/db/sqlite3.class.php index 060e7318b65..b53bdeb8adc 100644 --- a/htdocs/core/db/sqlite3.class.php +++ b/htdocs/core/db/sqlite3.class.php @@ -959,7 +959,7 @@ class DoliDBSqlite3 extends DoliDB * Create a table into database * * @param string $table Nom de la table - * @param array $fields Tableau associatif [nom champ][tableau des descriptions] + * @param array|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string}> $fields Tableau associatif [nom champ][tableau des descriptions] * @param string $primary_key Nom du champ qui sera la clef primaire * @param string $type Type de la table * @param array $unique_keys Tableau associatifs Nom de champs qui seront clef unique => valeur @@ -1082,7 +1082,7 @@ class DoliDBSqlite3 extends DoliDB * * @param string $table Table name * @param string $field_name Field name to add - * @param string $field_desc Associative table with description of field to insert [parameter name][parameter value] + * @param array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string} $field_desc Associative table with description of field to insert [parameter name][parameter value] * @param string $field_position Optional e.g.: "after some_field" * @return int Return integer <0 if KO, >0 if OK */ @@ -1129,7 +1129,7 @@ class DoliDBSqlite3 extends DoliDB * * @param string $table Name of table * @param string $field_name Name of field to modify - * @param string $field_desc Array with description of field format + * @param array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string} $field_desc Array with description of field format * @return int Return integer <0 if KO, >0 if OK */ public function DDLUpdateField($table, $field_name, $field_desc) diff --git a/htdocs/debugbar/class/TraceableDB.php b/htdocs/debugbar/class/TraceableDB.php index 6f9af2136c7..9dc266ea5e0 100644 --- a/htdocs/debugbar/class/TraceableDB.php +++ b/htdocs/debugbar/class/TraceableDB.php @@ -1,5 +1,6 @@ + * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -494,7 +495,7 @@ class TraceableDB extends DoliDB * Create a table into database * * @param string $table Name of table - * @param array $fields Tableau associatif [nom champ][tableau des descriptions] + * @param array $fields Tableau associatif [nom champ][tableau des descriptions] * @param string $primary_key Nom du champ qui sera la clef primaire * @param string $type Type de la table * @param array $unique_keys Tableau associatifs Nom de champs qui seront clef unique => valeur @@ -533,7 +534,7 @@ class TraceableDB extends DoliDB * * @param string $table Name of table * @param string $field_name Name of field to add - * @param string $field_desc Tableau associatif de description du champ a inserer[nom du parameter][valeur du parameter] + * @param array{type:string,label:string,enabled:int|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array<int,string>,comment?:string} $field_desc Tableau associatif de description du champ a inserer[nom du parameter][valeur du parameter] * @param string $field_position Optionnel ex.: "after champtruc" * @return int Return integer <0 if KO, >0 if OK */ @@ -559,7 +560,7 @@ class TraceableDB extends DoliDB * * @param string $table Name of table * @param string $field_name Name of field to modify - * @param string $field_desc Array with description of field format + * @param array{type:string,label:string,enabled:int|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string} $field_desc Array with description of field format * @return int Return integer <0 if KO, >0 if OK */ public function DDLUpdateField($table, $field_name, $field_desc) From 2496d20d4fe19067463e67fe3a615e52c792d80a Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 20 Mar 2024 23:38:28 +0100 Subject: [PATCH 048/114] Fix nullable return with if($ok == 1) in stead of if($ok) # Fix nullable return with if($ok == 1) in stead of if($ok) This seems to be a bug in Phan where if($ok) changes the type of $ok. Testing with '$ok == 1' instead fixes the issue. This has been reported to the phan team. --- htdocs/core/modules/DolibarrModules.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index 850ec739d06..41d2b20efd1 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -1126,7 +1126,7 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it * * @param string $reldir Relative directory where to scan files. Example: '/install/mysql/' or '/module/sql/' * @param string $onlywithsuffix Only with the defined suffix - * @return int Return integer <=0 if KO, >0 if OK + * @return int<0,1> Return integer <=0 if KO, >0 if OK */ protected function _load_tables($reldir, $onlywithsuffix = '') { @@ -1135,6 +1135,7 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it $error = 0; $dirfound = 0; + $ok = 1; if (empty($reldir)) { return 1; @@ -1142,9 +1143,8 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it include_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; - $ok = 1; foreach ($conf->file->dol_document_root as $dirroot) { - if ($ok) { + if ($ok == 1) { $dirsql = $dirroot.$reldir; $ok = 0; From 976686262d5ee858842ffaf93588e51f4b141b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Maldonado?= Date: Thu, 21 Mar 2024 02:36:40 +0100 Subject: [PATCH 049/114] FIX: SQL syntax error in DDLUpdateField --- htdocs/core/db/pgsql.class.php | 4 ++-- test/phpunit/DoliDBTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index 2923992e345..29989873d3c 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -1273,9 +1273,9 @@ class DoliDBPgsql extends DoliDB if (isset($field_desc['default']) && $field_desc['default'] != '') { if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') { - $sql .= " DEFAULT ".$this->escape($field_desc['default']); + $sql .= ", ALTER COLUMN ".$this->escape($field_name)." SET DEFAULT ".$this->escape($field_desc['default']); } elseif ($field_desc['type'] != 'text') { - $sql .= " DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields + $sql .= ", ALTER COLUMN ".$this->escape($field_name)." SET DEFAULT '"." DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields } } diff --git a/test/phpunit/DoliDBTest.php b/test/phpunit/DoliDBTest.php index 999c3b3e54a..2a380fa637e 100644 --- a/test/phpunit/DoliDBTest.php +++ b/test/phpunit/DoliDBTest.php @@ -160,7 +160,7 @@ class DoliDBTest extends PHPUnit\Framework\TestCase print __METHOD__." result=".$result."\n"; // TODO Use $savtype and $savnull instead of hard coded - $field_desc = array('type'=>'varchar', 'value'=>'16', 'null'=>'NOT NULL'); + $field_desc = array('type'=>'varchar', 'value'=>'16', 'null'=>'NOT NULL', 'default'=>'aaaabbbbccccdddd'); $result = $db->DDLUpdateField($db->prefix().'c_paper_format', 'code', $field_desc); $this->assertEquals(1, $result); From 66d74b01f7c0f0231ccaf68857d39b305e93b01e Mon Sep 17 00:00:00 2001 From: brad Date: Thu, 21 Mar 2024 20:46:08 +1100 Subject: [PATCH 050/114] Fix send mail script - correctly send only set number of emails per call - will jump through each validated mailout --- scripts/emailings/mailing-send.php | 39 +++++++++++++++--------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/scripts/emailings/mailing-send.php b/scripts/emailings/mailing-send.php index 77871ecbf0b..2cdb4dacbb1 100755 --- a/scripts/emailings/mailing-send.php +++ b/scripts/emailings/mailing-send.php @@ -52,7 +52,7 @@ if (isset($argv[2]) || !empty($argv[2])) { $login = ''; } -$max = 0; +$max = -1; if (isset($argv[3]) || !empty($argv[3])) { $max = $argv[3]; @@ -105,7 +105,7 @@ if (!empty($login)) { } // We get list of emailing id to process -$sql = "SELECT m.rowid"; +$sql = "SELECT m.rowid, m.statut as status"; $sql .= " FROM ".MAIN_DB_PREFIX."mailing as m"; $sql .= " WHERE m.statut IN (1,2)"; if ($id != 'all') { @@ -118,13 +118,22 @@ if ($resql) { $num = $db->num_rows($resql); $j = 0; - if ($num) { - for ($j = 0; $j < $num; $j++) { + if ($num) + { + for ($j = 0; $j < $num && $max!=0; $j++) + { $obj = $db->fetch_object($resql); dol_syslog("Process mailing with id ".$obj->rowid); print "Process mailing with id ".$obj->rowid."\n"; + if ($obj->status==1) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."mailing SET statut=2 WHERE rowid=".$obj->rowid; + $result_sql = $db->query($sql); + dol_syslog("Started mailing campaign ".$obj->rowid, LOG_DEBUG); + } + $emailing = new Mailing($db); $emailing->fetch($obj->rowid); @@ -185,6 +194,7 @@ if ($resql) { $now = dol_now(); $obj = $db->fetch_object($resql2); + $max--; // sendto en RFC2822 $sendto = str_replace(',', ' ', dolGetFirstLastname($obj->firstname, $obj->lastname)." <".$obj->email.">"); @@ -405,25 +415,16 @@ if ($resql) { $i++; } } else { - $mesg = "Emailing id ".$id." has no recipient to target"; + //$mesg = "Emailing id ".$id." has no recipient to target"; print $mesg."\n"; dol_syslog($mesg, LOG_ERR); - } - // Loop finished, set global statut of mail - $statut = 2; - if (!$nbko) { - $statut = 3; - } + // Loop finished, set global statut of mail + $sql = "UPDATE ".MAIN_DB_PREFIX."mailing SET statut=3 WHERE rowid=".$obj->rowid; + $result_sql = $db->query($sql); - $sqlenddate = "UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".((int) $statut)." WHERE rowid=".((int) $id); - - dol_syslog("update global status", LOG_DEBUG); - print "Update status of emailing id ".$id." to ".$statut."\n"; - $resqlenddate = $db->query($sqlenddate); - if (!$resqlenddate) { - dol_print_error($db); - $error++; + dol_syslog("update global status", LOG_DEBUG); + print "Update status of emailing id ".$id." to ".$statut."\n"; } } else { dol_print_error($db); From 27c0192b7ca1657a48b559784f9e6df81437cc74 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Mar 2024 11:14:39 +0100 Subject: [PATCH 051/114] cast smallint --- htdocs/core/db/mysqli.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index ff63113e47b..6e11faa9fee 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -1013,8 +1013,8 @@ class DoliDBMysqli extends DoliDB } if (isset($field_desc['default']) && $field_desc['default'] != '') { - if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') { - $sql .= " DEFAULT ".$this->escape($field_desc['default']); + if (in_array($field_desc['type'], array('tinyint', 'smallint', 'int', 'double'))) { + $sql .= " DEFAULT ".((float) $field_desc['default']); } elseif ($field_desc['type'] != 'text') { $sql .= " DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields } From 01a058b2081d2fe031bbdc75d6fa903cd23fca76 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Mar 2024 11:22:12 +0100 Subject: [PATCH 052/114] Fix regression --- htdocs/core/db/pgsql.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index 29989873d3c..a5d226804b3 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -1273,9 +1273,9 @@ class DoliDBPgsql extends DoliDB if (isset($field_desc['default']) && $field_desc['default'] != '') { if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') { - $sql .= ", ALTER COLUMN ".$this->escape($field_name)." SET DEFAULT ".$this->escape($field_desc['default']); + $sql .= ", ALTER COLUMN ".$this->escape($field_name)." SET DEFAULT ".((float) $field_desc['default']); } elseif ($field_desc['type'] != 'text') { - $sql .= ", ALTER COLUMN ".$this->escape($field_name)." SET DEFAULT '"." DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields + $sql .= ", ALTER COLUMN ".$this->escape($field_name)." SET DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields } } From ebdcb0fa0ea995fa026273fd456fcdb85589e1f8 Mon Sep 17 00:00:00 2001 From: brad Date: Thu, 21 Mar 2024 21:56:09 +1100 Subject: [PATCH 053/114] Fix spaces/tabs --- scripts/emailings/mailing-send.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/scripts/emailings/mailing-send.php b/scripts/emailings/mailing-send.php index 2cdb4dacbb1..3d18373e86e 100755 --- a/scripts/emailings/mailing-send.php +++ b/scripts/emailings/mailing-send.php @@ -127,11 +127,10 @@ if ($resql) { dol_syslog("Process mailing with id ".$obj->rowid); print "Process mailing with id ".$obj->rowid."\n"; - if ($obj->status==1) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."mailing SET statut=2 WHERE rowid=".$obj->rowid; - $result_sql = $db->query($sql); - dol_syslog("Started mailing campaign ".$obj->rowid, LOG_DEBUG); + if ($obj->status==1) { + $sql = "UPDATE ".MAIN_DB_PREFIX."mailing SET statut=2 WHERE rowid=".$obj->rowid; + $result_sql = $db->query($sql); + dol_syslog("Started mailing campaign ".$obj->rowid, LOG_DEBUG); } $emailing = new Mailing($db); @@ -419,12 +418,12 @@ if ($resql) { print $mesg."\n"; dol_syslog($mesg, LOG_ERR); - // Loop finished, set global statut of mail - $sql = "UPDATE ".MAIN_DB_PREFIX."mailing SET statut=3 WHERE rowid=".$obj->rowid; - $result_sql = $db->query($sql); + // Loop finished, set global statut of mail + $sql = "UPDATE ".MAIN_DB_PREFIX."mailing SET statut=3 WHERE rowid=".$obj->rowid; + $result_sql = $db->query($sql); - dol_syslog("update global status", LOG_DEBUG); - print "Update status of emailing id ".$id." to ".$statut."\n"; + dol_syslog("update global status", LOG_DEBUG); + print "Update status of emailing id ".$id." to ".$statut."\n"; } } else { dol_print_error($db); From 4fc50c3761b1b1c0bf63e0137eda7a65a3d79075 Mon Sep 17 00:00:00 2001 From: brad Date: Thu, 21 Mar 2024 22:05:50 +1100 Subject: [PATCH 054/114] Fix newline after parenthesis --- scripts/emailings/mailing-send.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/emailings/mailing-send.php b/scripts/emailings/mailing-send.php index 3d18373e86e..fce65e69db3 100755 --- a/scripts/emailings/mailing-send.php +++ b/scripts/emailings/mailing-send.php @@ -118,10 +118,8 @@ if ($resql) { $num = $db->num_rows($resql); $j = 0; - if ($num) - { - for ($j = 0; $j < $num && $max!=0; $j++) - { + if ($num) { + for ($j = 0; $j < $num && $max!=0; $j++) { $obj = $db->fetch_object($resql); dol_syslog("Process mailing with id ".$obj->rowid); From ce2959b022a3cc0e74fe3353c70ee4680d9be1db Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Mar 2024 12:10:09 +0100 Subject: [PATCH 055/114] Clean method DDLCreateTable (used by modulebuilder only) #28996 --- htdocs/core/db/mysqli.class.php | 56 ++++++++++++++--------- htdocs/core/db/pgsql.class.php | 60 +++++++++++++++---------- htdocs/core/db/sqlite3.class.php | 65 ++++++++++++++++----------- htdocs/core/lib/modulebuilder.lib.php | 16 +++---- 4 files changed, 117 insertions(+), 80 deletions(-) diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index 6e11faa9fee..6f3feb04dcc 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -825,55 +825,66 @@ class DoliDBMysqli extends DoliDB public function DDLCreateTable($table, $fields, $primary_key, $type, $unique_keys = null, $fulltext_keys = null, $keys = null) { // phpcs:enable - // FIXME: $fulltext_keys parameter is unused + // @TODO: $fulltext_keys parameter is unused + + if (empty($type)) { + $type = 'InnoDB'; + } $pk = ''; $sqluq = $sqlk = array(); - // cles recherchees dans le tableau des descriptions (fields) : type,value,attribute,null,default,extra - // ex. : $fields['rowid'] = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); - $sql = "CREATE TABLE ".$table."("; + // Keys found into the array $fields: type,value,attribute,null,default,extra + // ex. : $fields['rowid'] = array( + // 'type'=>'int' or 'integer', + // 'value'=>'11', + // 'null'=>'not null', + // 'extra'=> 'auto_increment' + // ); + $sql = "CREATE TABLE ".$this->sanitize($table)."("; $i = 0; $sqlfields = array(); foreach ($fields as $field_name => $field_desc) { - $sqlfields[$i] = $field_name." "; - $sqlfields[$i] .= $field_desc['type']; - if (preg_match("/^[^\s]/i", $field_desc['value'])) { - $sqlfields[$i] .= "(".$field_desc['value'].")"; + $sqlfields[$i] = $this->sanitize($field_name)." "; + $sqlfields[$i] .= $this->sanitize($field_desc['type']); + if (!is_null($field_desc['value']) && $field_desc['value'] !== '') { + $sqlfields[$i] .= "(".$this->sanitize($field_desc['value']).")"; } - if (preg_match("/^[^\s]/i", $field_desc['attribute'])) { - $sqlfields[$i] .= " ".$field_desc['attribute']; + if (!is_null($field_desc['attribute']) && $field_desc['attribute'] !== '') { + $sqlfields[$i] .= " ".$this->sanitize($field_desc['attribute']); } - if (preg_match("/^[^\s]/i", $field_desc['default'])) { - if ((preg_match("/null/i", $field_desc['default'])) || (preg_match("/CURRENT_TIMESTAMP/i", $field_desc['default']))) { - $sqlfields[$i] .= " default ".$field_desc['default']; + if (!is_null($field_desc['default']) && $field_desc['default'] !== '') { + if (in_array($field_desc['type'], array('tinyint', 'smallint', 'int', 'double'))) { + $sqlfields[$i] .= " DEFAULT ".((float) $field_desc['default']); + } elseif ($field_desc['default'] == 'null' || $field_desc['default'] == 'CURRENT_TIMESTAMP') { + $sqlfields[$i] .= " DEFAULT ".$this->sanitize($field_desc['default']); } else { - $sqlfields[$i] .= " default '".$this->escape($field_desc['default'])."'"; + $sqlfields[$i] .= " DEFAULT '".$this->escape($field_desc['default'])."'"; } } - if (preg_match("/^[^\s]/i", $field_desc['null'])) { - $sqlfields[$i] .= " ".$field_desc['null']; + if (!is_null($field_desc['null']) && $field_desc['null'] !== '') { + $sqlfields[$i] .= " ".$this->sanitize($field_desc['null'], 0, 0, 1); } - if (preg_match("/^[^\s]/i", $field_desc['extra'])) { - $sqlfields[$i] .= " ".$field_desc['extra']; + if (!is_null($field_desc['extra']) && $field_desc['extra'] !== '') { + $sqlfields[$i] .= " ".$this->sanitize($field_desc['extra']); } $i++; } if ($primary_key != "") { - $pk = "primary key(".$primary_key.")"; + $pk = "PRIMARY KEY(".$this->sanitize($primary_key).")"; } if (is_array($unique_keys)) { $i = 0; foreach ($unique_keys as $key => $value) { - $sqluq[$i] = "UNIQUE KEY '".$key."' ('".$this->escape($value)."')"; + $sqluq[$i] = "UNIQUE KEY '".$this->sanitize($key)."' ('".$this->escape($value)."')"; $i++; } } if (is_array($keys)) { $i = 0; foreach ($keys as $key => $value) { - $sqlk[$i] = "KEY ".$key." (".$value.")"; + $sqlk[$i] = "KEY ".$this->sanitize($key)." (".$value.")"; $i++; } } @@ -887,7 +898,8 @@ class DoliDBMysqli extends DoliDB if (is_array($keys)) { $sql .= ",".implode(',', $sqlk); } - $sql .= ") engine=".$type; + $sql .= ")"; + $sql .= " engine=".$this->sanitize($type); if (!$this->query($sql)) { return -1; diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index 250a7da0855..3cfe5671085 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -1068,51 +1068,63 @@ class DoliDBPgsql extends DoliDB public function DDLCreateTable($table, $fields, $primary_key, $type, $unique_keys = null, $fulltext_keys = null, $keys = null) { // phpcs:enable - // FIXME: $fulltext_keys parameter is unused + // @TODO: $fulltext_keys parameter is unused $sqlfields = array(); $sqlk = array(); $sqluq = array(); - // cles recherchees dans le tableau des descriptions (fields) : type,value,attribute,null,default,extra - // ex. : $fields['rowid'] = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); - $sql = "create table ".$table."("; + // Keys found into the array $fields: type,value,attribute,null,default,extra + // ex. : $fields['rowid'] = array( + // 'type'=>'int' or 'integer', + // 'value'=>'11', + // 'null'=>'not null', + // 'extra'=> 'auto_increment' + // ); + $sql = "CREATE TABLE ".$this->sanitize($table)."("; $i = 0; + $sqlfields = array(); foreach ($fields as $field_name => $field_desc) { - $sqlfields[$i] = $field_name." "; - $sqlfields[$i] .= $field_desc['type']; - if (preg_match("/^[^\s]/i", $field_desc['value'])) { - $sqlfields[$i] .= "(".$field_desc['value'].")"; - } elseif (preg_match("/^[^\s]/i", $field_desc['attribute'])) { - $sqlfields[$i] .= " ".$field_desc['attribute']; - } elseif (preg_match("/^[^\s]/i", $field_desc['default'])) { - if (preg_match("/null/i", $field_desc['default'])) { - $sqlfields[$i] .= " default ".$field_desc['default']; + $sqlfields[$i] = $this->sanitize($field_name)." "; + $sqlfields[$i] .= $this->sanitize($field_desc['type']); + if (!is_null($field_desc['value']) && $field_desc['value'] !== '') { + $sqlfields[$i] .= "(".$this->sanitize($field_desc['value']).")"; + } + if (!is_null($field_desc['attribute']) && $field_desc['attribute'] !== '') { + $sqlfields[$i] .= " ".$this->sanitize($field_desc['attribute']); + } + if (!is_null($field_desc['default']) && $field_desc['default'] !== '') { + if (in_array($field_desc['type'], array('tinyint', 'smallint', 'int', 'double'))) { + $sqlfields[$i] .= " DEFAULT ".((float) $field_desc['default']); + } elseif ($field_desc['default'] == 'null' || $field_desc['default'] == 'CURRENT_TIMESTAMP') { + $sqlfields[$i] .= " DEFAULT ".$this->sanitize($field_desc['default']); } else { - $sqlfields[$i] .= " default '".$this->escape($field_desc['default'])."'"; + $sqlfields[$i] .= " DEFAULT '".$this->escape($field_desc['default'])."'"; } - } elseif (preg_match("/^[^\s]/i", $field_desc['null'])) { - $sqlfields[$i] .= " ".$field_desc['null']; - } elseif (preg_match("/^[^\s]/i", $field_desc['extra'])) { - $sqlfields[$i] .= " ".$field_desc['extra']; + } + if (!is_null($field_desc['null']) && $field_desc['null'] !== '') { + $sqlfields[$i] .= " ".$this->sanitize($field_desc['null'], 0, 0, 1); + } + if (!is_null($field_desc['extra']) && $field_desc['extra'] !== '') { + $sqlfields[$i] .= " ".$this->sanitize($field_desc['extra']); } $i++; } if ($primary_key != "") { - $pk = "primary key(".$primary_key.")"; + $pk = "PRIMARY KEY(".$this->sanitize($primary_key).")"; } if (is_array($unique_keys)) { $i = 0; foreach ($unique_keys as $key => $value) { - $sqluq[$i] = "UNIQUE KEY '".$key."' ('".$this->escape($value)."')"; + $sqluq[$i] = "UNIQUE KEY '".$this->sanitize($key)."' ('".$this->escape($value)."')"; $i++; } } if (is_array($keys)) { $i = 0; foreach ($keys as $key => $value) { - $sqlk[$i] = "KEY ".$key." (".$value.")"; + $sqlk[$i] = "KEY ".$this->sanitize($key)." (".$value.")"; $i++; } } @@ -1120,15 +1132,15 @@ class DoliDBPgsql extends DoliDB if ($primary_key != "") { $sql .= ",".$pk; } - if (is_array($unique_keys)) { + if ($unique_keys != "") { $sql .= ",".implode(',', $sqluq); } if (is_array($keys)) { $sql .= ",".implode(',', $sqlk); } - $sql .= ") type=".$type; + $sql .= ")"; + //$sql .= " engine=".$this->sanitize($type); - dol_syslog($sql, LOG_DEBUG); if (!$this->query($sql)) { return -1; } else { diff --git a/htdocs/core/db/sqlite3.class.php b/htdocs/core/db/sqlite3.class.php index 060e7318b65..477d7d33c42 100644 --- a/htdocs/core/db/sqlite3.class.php +++ b/htdocs/core/db/sqlite3.class.php @@ -970,51 +970,63 @@ class DoliDBSqlite3 extends DoliDB public function DDLCreateTable($table, $fields, $primary_key, $type, $unique_keys = null, $fulltext_keys = null, $keys = null) { // phpcs:enable - // FIXME: $fulltext_keys parameter is unused + // @TODO: $fulltext_keys parameter is unused $sqlfields = array(); $sqlk = array(); $sqluq = array(); - // cles recherchees dans le tableau des descriptions (fields) : type,value,attribute,null,default,extra - // ex. : $fields['rowid'] = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); - $sql = "create table ".$table."("; + // Keys found into the array $fields: type,value,attribute,null,default,extra + // ex. : $fields['rowid'] = array( + // 'type'=>'int' or 'integer', + // 'value'=>'11', + // 'null'=>'not null', + // 'extra'=> 'auto_increment' + // ); + $sql = "CREATE TABLE ".$this->sanitize($table)."("; $i = 0; + $sqlfields = array(); foreach ($fields as $field_name => $field_desc) { - $sqlfields[$i] = $field_name." "; - $sqlfields[$i] .= $field_desc['type']; - if (preg_match("/^[^\s]/i", $field_desc['value'])) { - $sqlfields[$i] .= "(".$field_desc['value'].")"; - } elseif (preg_match("/^[^\s]/i", $field_desc['attribute'])) { - $sqlfields[$i] .= " ".$field_desc['attribute']; - } elseif (preg_match("/^[^\s]/i", $field_desc['default'])) { - if (preg_match("/null/i", $field_desc['default'])) { - $sqlfields[$i] .= " default ".$field_desc['default']; + $sqlfields[$i] = $this->sanitize($field_name)." "; + $sqlfields[$i] .= $this->sanitize($field_desc['type']); + if (!is_null($field_desc['value']) && $field_desc['value'] !== '') { + $sqlfields[$i] .= "(".$this->sanitize($field_desc['value']).")"; + } + if (!is_null($field_desc['attribute']) && $field_desc['attribute'] !== '') { + $sqlfields[$i] .= " ".$this->sanitize($field_desc['attribute']); + } + if (!is_null($field_desc['default']) && $field_desc['default'] !== '') { + if (in_array($field_desc['type'], array('tinyint', 'smallint', 'int', 'double'))) { + $sqlfields[$i] .= " DEFAULT ".((float) $field_desc['default']); + } elseif ($field_desc['default'] == 'null' || $field_desc['default'] == 'CURRENT_TIMESTAMP') { + $sqlfields[$i] .= " DEFAULT ".$this->sanitize($field_desc['default']); } else { - $sqlfields[$i] .= " default '".$this->escape($field_desc['default'])."'"; + $sqlfields[$i] .= " DEFAULT '".$this->escape($field_desc['default'])."'"; } - } elseif (preg_match("/^[^\s]/i", $field_desc['null'])) { - $sqlfields[$i] .= " ".$field_desc['null']; - } elseif (preg_match("/^[^\s]/i", $field_desc['extra'])) { - $sqlfields[$i] .= " ".$field_desc['extra']; + } + if (!is_null($field_desc['null']) && $field_desc['null'] !== '') { + $sqlfields[$i] .= " ".$this->sanitize($field_desc['null'], 0, 0, 1); + } + if (!is_null($field_desc['extra']) && $field_desc['extra'] !== '') { + $sqlfields[$i] .= " ".$this->sanitize($field_desc['extra']); } $i++; } if ($primary_key != "") { - $pk = "primary key(".$primary_key.")"; + $pk = "PRIMARY KEY(".$this->sanitize($primary_key).")"; } if (is_array($unique_keys)) { $i = 0; foreach ($unique_keys as $key => $value) { - $sqluq[$i] = "UNIQUE KEY '".$key."' ('".$this->escape($value)."')"; + $sqluq[$i] = "UNIQUE KEY '".$this->sanitize($key)."' ('".$this->escape($value)."')"; $i++; } } if (is_array($keys)) { $i = 0; foreach ($keys as $key => $value) { - $sqlk[$i] = "KEY ".$key." (".$value.")"; + $sqlk[$i] = "KEY ".$this->sanitize($key)." (".$value.")"; $i++; } } @@ -1022,19 +1034,20 @@ class DoliDBSqlite3 extends DoliDB if ($primary_key != "") { $sql .= ",".$pk; } - if (is_array($unique_keys)) { + if ($unique_keys != "") { $sql .= ",".implode(',', $sqluq); } if (is_array($keys)) { $sql .= ",".implode(',', $sqlk); } - $sql .= ") type=".$type; + $sql .= ")"; + //$sql .= " engine=".$this->sanitize($type); - dol_syslog($sql, LOG_DEBUG); - if (!$this -> query($sql)) { + if (!$this->query($sql)) { return -1; + } else { + return 1; } - return 1; } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index 95e4711b396..159c5712399 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -1288,12 +1288,12 @@ function createNewDictionnary($modulename, $file, $namedic, $dictionnaires = nul } $columns = array( - 'rowid' => array('type' => 'integer(11)'), - 'code' => array('type' => 'varchar(255) NOT NULL'), - 'label' => array('type' => 'varchar(255) NOT NULL'), - 'position' => array('type' => 'integer(11) NULL'), - 'use_default' => array('type' => 'varchar(255) DEFAULT 1'), - 'active' => array('type' => 'integer') + 'rowid' => array('type' => 'integer', 'value' => 11), + 'code' => array('type' => 'varchar', 'value' => 255, 'null'=>'NOT NULL'), + 'label' => array('type' => 'varchar', 'value' => 255, 'null'=>'NOT NULL'), + 'position' => array('type' => 'integer', 'value' => 11, 'null'=>'NULL'), + 'use_default' => array('type' => 'varchar', 'value' => 11, 'default'=>'1'), + 'active' => array('type' => 'integer', 'value' => 3) ); @@ -1309,13 +1309,13 @@ function createNewDictionnary($modulename, $file, $namedic, $dictionnaires = nul } } // check if tablename exist in Database and create it if not - $query = "SHOW TABLES LIKE '" . MAIN_DB_PREFIX.strtolower($namedic) . "'"; + $query = "SHOW TABLES LIKE '" . $db->sanitize(MAIN_DB_PREFIX.strtolower($namedic)) . "'"; $checkTable = $db->query($query); if ($checkTable && $db->num_rows($checkTable) > 0) { setEventMessages($langs->trans("ErrorTableExist", $namedic), null, 'errors'); return; } else { - $_results = $db->DDLCreateTable(MAIN_DB_PREFIX.strtolower($namedic), $columns, $primaryKey, "InnoDB"); + $_results = $db->DDLCreateTable(MAIN_DB_PREFIX.strtolower($namedic), $columns, $primaryKey, ""); if ($_results < 0) { dol_print_error($db); $langs->load("errors"); From 171c32be342f08dd1c17a4997eb8b2f9123c424e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Mar 2024 12:21:38 +0100 Subject: [PATCH 056/114] Add DDLDropTable and DDLCreateTable into phpunit tests --- htdocs/core/db/mysqli.class.php | 2 +- test/phpunit/DoliDBTest.php | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index 6f3feb04dcc..9c2948cb262 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -920,7 +920,7 @@ class DoliDBMysqli extends DoliDB // phpcs:enable $tmptable = preg_replace('/[^a-z0-9\.\-\_]/i', '', $table); - $sql = "DROP TABLE ".$tmptable; + $sql = "DROP TABLE ".$this->sanitize($tmptable); if (!$this->query($sql)) { return -1; diff --git a/test/phpunit/DoliDBTest.php b/test/phpunit/DoliDBTest.php index c2a0de05a20..34f70e459c9 100644 --- a/test/phpunit/DoliDBTest.php +++ b/test/phpunit/DoliDBTest.php @@ -48,6 +48,41 @@ $conf->global->MAIN_DISABLE_ALL_MAILS = 1; */ class DoliDBTest extends CommonClassTest { + /** + * testDDLUpdateField + * + * @return int + */ + public function testDDLCreateTable() + { + global $conf,$user,$langs,$db; + $conf = $this->savconf; + $user = $this->savuser; + $langs = $this->savlangs; + $db = $this->savdb; + + $namedic = MAIN_DB_PREFIX.'tmptesttabletoremove'; + + $res = $db->DDLDropTable($namedic); + + $columns = array( + 'rowid' => array('type' => 'integer', 'value' => 11), + 'code' => array('type' => 'varchar', 'value' => 255, 'null'=>'NOT NULL'), + 'label' => array('type' => 'varchar', 'value' => 255, 'null'=>'NOT NULL'), + 'position' => array('type' => 'integer', 'value' => 11, 'null'=>'NULL'), + 'use_default' => array('type' => 'varchar', 'value' => 11, 'default'=>'1'), + 'active' => array('type' => 'integer', 'value' => 3) + ); + $primaryKey = 'rowid'; + + print __METHOD__.' db->type = '.$db->type."\n"; + + $res = $db->DDLCreateTable($namedic, $columns, $primaryKey, ""); + + $this->assertEquals(1, $res); + print __METHOD__." result=".$res."\n"; + } + /** * testDDLUpdateField * @@ -84,6 +119,7 @@ class DoliDBTest extends CommonClassTest $field_desc = array('type'=>'varchar', 'value'=>'16', 'null'=>'NOT NULL', 'default'=>'aaaabbbbccccdddd'); $result = $db->DDLUpdateField($db->prefix().'c_paper_format', 'code', $field_desc); + $this->assertEquals(1, $result); print __METHOD__." result=".$result."\n"; From aa77573cd9f6f4b16a39face533bdf78d03e0978 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Mar 2024 12:45:58 +0100 Subject: [PATCH 057/114] Sanitize DDL instructions --- htdocs/core/db/mysqli.class.php | 42 ++++++----- htdocs/core/db/pgsql.class.php | 104 +++++++++++++------------- htdocs/core/db/sqlite3.class.php | 22 +++--- htdocs/core/lib/modulebuilder.lib.php | 2 +- test/phpunit/DoliDBTest.php | 2 +- 5 files changed, 89 insertions(+), 83 deletions(-) diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index 9c2948cb262..5b43b4e2cbc 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -866,7 +866,7 @@ class DoliDBMysqli extends DoliDB $sqlfields[$i] .= " ".$this->sanitize($field_desc['null'], 0, 0, 1); } if (!is_null($field_desc['extra']) && $field_desc['extra'] !== '') { - $sqlfields[$i] .= " ".$this->sanitize($field_desc['extra']); + $sqlfields[$i] .= " ".$this->sanitize($field_desc['extra'], 0, 0, 1); } $i++; } @@ -940,7 +940,7 @@ class DoliDBMysqli extends DoliDB public function DDLDescTable($table, $field = "") { // phpcs:enable - $sql = "DESC ".$table." ".$field; + $sql = "DESC ".$this->sanitize($table)." ".$this->sanitize($field); dol_syslog(get_class($this)."::DDLDescTable ".$sql, LOG_DEBUG); $this->_results = $this->query($sql); @@ -962,30 +962,32 @@ class DoliDBMysqli extends DoliDB // phpcs:enable // cles recherchees dans le tableau des descriptions (field_desc) : type,value,attribute,null,default,extra // ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); - $sql = "ALTER TABLE ".$table." ADD ".$field_name." "; - $sql .= $field_desc['type']; - if (preg_match("/^[^\s]/i", $field_desc['value'])) { - if (!in_array($field_desc['type'], array('date', 'datetime')) && $field_desc['value']) { - $sql .= "(".$field_desc['value'].")"; + $sql = "ALTER TABLE ".$this->sanitize($table)." ADD ".$this->sanitize($field_name)." "; + $sql .= $this->sanitize($field_desc['type']); + if (isset($field_desc['value']) && preg_match("/^[^\s]/i", $field_desc['value'])) { + if (!in_array($field_desc['type'], array('tinyint', 'smallint', 'int', 'date', 'datetime')) && $field_desc['value']) { + $sql .= "(".$this->sanitize($field_desc['value']).")"; } } if (isset($field_desc['attribute']) && preg_match("/^[^\s]/i", $field_desc['attribute'])) { - $sql .= " ".$field_desc['attribute']; + $sql .= " ".$this->sanitize($field_desc['attribute']); } if (isset($field_desc['null']) && preg_match("/^[^\s]/i", $field_desc['null'])) { $sql .= " ".$field_desc['null']; } if (isset($field_desc['default']) && preg_match("/^[^\s]/i", $field_desc['default'])) { - if (preg_match("/null/i", $field_desc['default'])) { - $sql .= " default ".$field_desc['default']; + if (in_array($field_desc['type'], array('tinyint', 'smallint', 'int', 'double'))) { + $sql .= " DEFAULT ".((float) $field_desc['default']); + } elseif ($field_desc['default'] == 'null' || $field_desc['default'] == 'CURRENT_TIMESTAMP') { + $sql .= " DEFAULT ".$this->sanitize($field_desc['default']); } else { - $sql .= " default '".$this->escape($field_desc['default'])."'"; + $sql .= " DEFAULT '".$this->escape($field_desc['default'])."'"; } } if (isset($field_desc['extra']) && preg_match("/^[^\s]/i", $field_desc['extra'])) { - $sql .= " ".$field_desc['extra']; + $sql .= " ".$this->escape($field_desc['extra'], 0, 0, 1); } - $sql .= " ".$field_position; + $sql .= " ".$this->escape($field_position, 0, 0, 1); dol_syslog(get_class($this)."::DDLAddField ".$sql, LOG_DEBUG); if ($this->query($sql)) { @@ -1006,18 +1008,18 @@ class DoliDBMysqli extends DoliDB public function DDLUpdateField($table, $field_name, $field_desc) { // phpcs:enable - $sql = "ALTER TABLE ".$table; - $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type']; + $sql = "ALTER TABLE ".$this->sanitize($table); + $sql .= " MODIFY COLUMN ".$this->sanitize($field_name)." ".$this->sanitize($field_desc['type']); if (in_array($field_desc['type'], array('double', 'tinyint', 'int', 'varchar')) && $field_desc['value']) { - $sql .= "(".$field_desc['value'].")"; + $sql .= "(".$this->sanitize($field_desc['value']).")"; } if ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL') { // We will try to change format of column to NOT NULL. To be sure the ALTER works, we try to update fields that are NULL if ($field_desc['type'] == 'varchar' || $field_desc['type'] == 'text') { - $sqlbis = "UPDATE ".$table." SET ".$field_name." = '".$this->escape(isset($field_desc['default']) ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL"; + $sqlbis = "UPDATE ".$this->sanitize($table)." SET ".$this->sanitize($field_name)." = '".$this->escape(isset($field_desc['default']) ? $field_desc['default'] : '')."' WHERE ".$this->sanitize($field_name)." IS NULL"; $this->query($sqlbis); - } elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') { - $sqlbis = "UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape(isset($field_desc['default']) ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL"; + } elseif (in_array($field_desc['type'], array('tinyint', 'smallint', 'int', 'double'))) { + $sqlbis = "UPDATE ".$this->sanitize($table)." SET ".$this->sanitize($field_name)." = ".((float) $this->escape(isset($field_desc['default']) ? $field_desc['default'] : 0))." WHERE ".$this->sanitize($field_name)." IS NULL"; $this->query($sqlbis); } @@ -1053,7 +1055,7 @@ class DoliDBMysqli extends DoliDB // phpcs:enable $tmp_field_name = preg_replace('/[^a-z0-9\.\-\_]/i', '', $field_name); - $sql = "ALTER TABLE ".$table." DROP COLUMN `".$tmp_field_name."`"; + $sql = "ALTER TABLE ".$this->sanitize($table)." DROP COLUMN `".$this->sanitize($tmp_field_name)."`"; if ($this->query($sql)) { return 1; } diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index 3cfe5671085..51ea5e84447 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -1160,7 +1160,7 @@ class DoliDBPgsql extends DoliDB // phpcs:enable $tmptable = preg_replace('/[^a-z0-9\.\-\_]/i', '', $table); - $sql = "DROP TABLE ".$tmptable; + $sql = "DROP TABLE ".$this->sanitize($tmptable); if (!$this->query($sql)) { return -1; @@ -1169,31 +1169,6 @@ class DoliDBPgsql extends DoliDB } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Create a user to connect to database - * - * @param string $dolibarr_main_db_host Ip server - * @param string $dolibarr_main_db_user Name of user to create - * @param string $dolibarr_main_db_pass Password of user to create - * @param string $dolibarr_main_db_name Database name where user must be granted - * @return int Return integer <0 if KO, >=0 if OK - */ - public function DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name) - { - // phpcs:enable - // Note: using ' on user does not works with pgsql - $sql = "CREATE USER ".$this->escape($dolibarr_main_db_user)." with password '".$this->escape($dolibarr_main_db_pass)."'"; - - dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log - $resql = $this->query($sql); - if (!$resql) { - return -1; - } - - return 1; - } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return a pointer of line with description of a table or field @@ -1231,30 +1206,32 @@ class DoliDBPgsql extends DoliDB // phpcs:enable // cles recherchees dans le tableau des descriptions (field_desc) : type,value,attribute,null,default,extra // ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); - $sql = "ALTER TABLE ".$table." ADD ".$field_name." "; - $sql .= $field_desc['type']; - if (preg_match("/^[^\s]/i", $field_desc['value'])) { - if (!in_array($field_desc['type'], array('smallint', 'int', 'date', 'datetime')) && $field_desc['value']) { - $sql .= "(".$field_desc['value'].")"; + $sql = "ALTER TABLE ".$this->sanitize($table)." ADD ".$this->sanitize($field_name)." "; + $sql .= $this->sanitize($field_desc['type']); + if (isset($field_desc['value']) && preg_match("/^[^\s]/i", $field_desc['value'])) { + if (!in_array($field_desc['type'], array('tinyint', 'smallint', 'int', 'date', 'datetime')) && $field_desc['value']) { + $sql .= "(".$this->sanitize($field_desc['value']).")"; } } - if (preg_match("/^[^\s]/i", $field_desc['attribute'])) { - $sql .= " ".$field_desc['attribute']; + if (isset($field_desc['attribute']) && preg_match("/^[^\s]/i", $field_desc['attribute'])) { + $sql .= " ".$this->sanitize($field_desc['attribute']); } - if (preg_match("/^[^\s]/i", $field_desc['null'])) { + if (isset($field_desc['null']) && preg_match("/^[^\s]/i", $field_desc['null'])) { $sql .= " ".$field_desc['null']; } - if (preg_match("/^[^\s]/i", $field_desc['default'])) { - if (preg_match("/null/i", $field_desc['default'])) { - $sql .= " default ".$field_desc['default']; + if (isset($field_desc['default']) && preg_match("/^[^\s]/i", $field_desc['default'])) { + if (in_array($field_desc['type'], array('tinyint', 'smallint', 'int', 'double'))) { + $sql .= " DEFAULT ".((float) $field_desc['default']); + } elseif ($field_desc['default'] == 'null' || $field_desc['default'] == 'CURRENT_TIMESTAMP') { + $sql .= " DEFAULT ".$this->sanitize($field_desc['default']); } else { - $sql .= " default '".$this->escape($field_desc['default'])."'"; + $sql .= " DEFAULT '".$this->escape($field_desc['default'])."'"; } } - if (preg_match("/^[^\s]/i", $field_desc['extra'])) { - $sql .= " ".$field_desc['extra']; + if (isset($field_desc['extra']) && preg_match("/^[^\s]/i", $field_desc['extra'])) { + $sql .= " ".$this->escape($field_desc['extra'], 0, 0, 1); } - $sql .= " ".$field_position; + $sql .= " ".$this->escape($field_position, 0, 0, 1); dol_syslog($sql, LOG_DEBUG); if (!$this -> query($sql)) { @@ -1275,30 +1252,30 @@ class DoliDBPgsql extends DoliDB public function DDLUpdateField($table, $field_name, $field_desc) { // phpcs:enable - $sql = "ALTER TABLE ".$table; - $sql .= " ALTER COLUMN ".$this->escape($field_name)." TYPE ".$field_desc['type']; + $sql = "ALTER TABLE ".$this->sanitize($table); + $sql .= " ALTER COLUMN ".$this->sanitize($field_name)." TYPE ".$this->sanitize($field_desc['type']); if (preg_match("/^[^\s]/i", $field_desc['value'])) { if (!in_array($field_desc['type'], array('smallint', 'int', 'date', 'datetime')) && $field_desc['value']) { - $sql .= "(".$field_desc['value'].")"; + $sql .= "(".$this->sanitize($field_desc['value']).")"; } } if ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL') { // We will try to change format of column to NOT NULL. To be sure the ALTER works, we try to update fields that are NULL if ($field_desc['type'] == 'varchar' || $field_desc['type'] == 'text') { - $sqlbis = "UPDATE ".$table." SET ".$this->escape($field_name)." = '".$this->escape(isset($field_desc['default']) ? $field_desc['default'] : '')."' WHERE ".$this->escape($field_name)." IS NULL"; + $sqlbis = "UPDATE ".$this->sanitize($table)." SET ".$this->escape($field_name)." = '".$this->escape(isset($field_desc['default']) ? $field_desc['default'] : '')."' WHERE ".$this->escape($field_name)." IS NULL"; $this->query($sqlbis); - } elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') { - $sqlbis = "UPDATE ".$table." SET ".$this->escape($field_name)." = ".((int) $this->escape(isset($field_desc['default']) ? $field_desc['default'] : 0))." WHERE ".$this->escape($field_name)." IS NULL"; + } elseif (in_array($field_desc['type'], array('tinyint', 'smallint', 'int', 'double'))) { + $sqlbis = "UPDATE ".$this->sanitize($table)." SET ".$this->escape($field_name)." = ".((float) $this->escape(isset($field_desc['default']) ? $field_desc['default'] : 0))." WHERE ".$this->escape($field_name)." IS NULL"; $this->query($sqlbis); } } if (isset($field_desc['default']) && $field_desc['default'] != '') { - if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') { - $sql .= ", ALTER COLUMN ".$this->escape($field_name)." SET DEFAULT ".((float) $field_desc['default']); + if (in_array($field_desc['type'], array('tinyint', 'smallint', 'int', 'double'))) { + $sql .= ", ALTER COLUMN ".$this->sanitize($field_name)." SET DEFAULT ".((float) $field_desc['default']); } elseif ($field_desc['type'] != 'text') { // Default not supported on text fields ? - $sql .= ", ALTER COLUMN ".$this->escape($field_name)." SET DEFAULT '".$this->escape($field_desc['default'])."'"; + $sql .= ", ALTER COLUMN ".$this->sanitize($field_name)." SET DEFAULT '".$this->escape($field_desc['default'])."'"; } } @@ -1322,7 +1299,7 @@ class DoliDBPgsql extends DoliDB // phpcs:enable $tmp_field_name = preg_replace('/[^a-z0-9\.\-\_]/i', '', $field_name); - $sql = "ALTER TABLE ".$table." DROP COLUMN ".$tmp_field_name; + $sql = "ALTER TABLE ".$this->sanitize($table)." DROP COLUMN ".$this->sanitize($tmp_field_name); if (!$this->query($sql)) { $this->error = $this->lasterror(); return -1; @@ -1330,6 +1307,31 @@ class DoliDBPgsql extends DoliDB return 1; } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Create a user to connect to database + * + * @param string $dolibarr_main_db_host Ip server + * @param string $dolibarr_main_db_user Name of user to create + * @param string $dolibarr_main_db_pass Password of user to create + * @param string $dolibarr_main_db_name Database name where user must be granted + * @return int Return integer <0 if KO, >=0 if OK + */ + public function DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name) + { + // phpcs:enable + // Note: using ' on user does not works with pgsql + $sql = "CREATE USER ".$this->sanitize($dolibarr_main_db_user)." with password '".$this->escape($dolibarr_main_db_pass)."'"; + + dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log + $resql = $this->query($sql); + if (!$resql) { + return -1; + } + + return 1; + } + /** * Return charset used to store data in database * diff --git a/htdocs/core/db/sqlite3.class.php b/htdocs/core/db/sqlite3.class.php index 477d7d33c42..392b5addffa 100644 --- a/htdocs/core/db/sqlite3.class.php +++ b/htdocs/core/db/sqlite3.class.php @@ -1118,16 +1118,18 @@ class DoliDBSqlite3 extends DoliDB $sql .= " ".$field_desc['null']; } if (preg_match("/^[^\s]/i", $field_desc['default'])) { - if (preg_match("/null/i", $field_desc['default'])) { - $sql .= " default ".$field_desc['default']; + if (in_array($field_desc['type'], array('tinyint', 'smallint', 'int', 'double'))) { + $sql .= " DEFAULT ".((float) $field_desc['default']); + } elseif ($field_desc['default'] == 'null' || $field_desc['default'] == 'CURRENT_TIMESTAMP') { + $sql .= " DEFAULT ".$this->sanitize($field_desc['default']); } else { - $sql .= " default '".$this->escape($field_desc['default'])."'"; + $sql .= " DEFAULT '".$this->escape($field_desc['default'])."'"; } } - if (preg_match("/^[^\s]/i", $field_desc['extra'])) { - $sql .= " ".$field_desc['extra']; + if (isset($field_desc['extra']) && preg_match("/^[^\s]/i", $field_desc['extra'])) { + $sql .= " ".$this->escape($field_desc['extra'], 0, 0, 1); } - $sql .= " ".$field_position; + $sql .= " ".$this->escape($field_position, 0, 0, 1); dol_syslog(get_class($this)."::DDLAddField ".$sql, LOG_DEBUG); if (!$this->query($sql)) { @@ -1148,10 +1150,10 @@ class DoliDBSqlite3 extends DoliDB public function DDLUpdateField($table, $field_name, $field_desc) { // phpcs:enable - $sql = "ALTER TABLE ".$table; - $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type']; + $sql = "ALTER TABLE ".$this->sanitize($table); + $sql .= " MODIFY COLUMN ".$this->sanitize(($field_name)." ".$this->sanitize($field_desc['type']); if ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') { - $sql .= "(".$field_desc['value'].")"; + $sql .= "(".$this->sanitize($field_desc['value']).")"; } dol_syslog(get_class($this)."::DDLUpdateField ".$sql, LOG_DEBUG); @@ -1174,7 +1176,7 @@ class DoliDBSqlite3 extends DoliDB // phpcs:enable $tmp_field_name = preg_replace('/[^a-z0-9\.\-\_]/i', '', $field_name); - $sql = "ALTER TABLE ".$table." DROP COLUMN `".$tmp_field_name."`"; + $sql = "ALTER TABLE ".$this->sanitize($table)." DROP COLUMN `".$this->sanitize($tmp_field_name)."`"; if (!$this->query($sql)) { $this->error = $this->lasterror(); return -1; diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index 159c5712399..1ae0d52d93a 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -1288,7 +1288,7 @@ function createNewDictionnary($modulename, $file, $namedic, $dictionnaires = nul } $columns = array( - 'rowid' => array('type' => 'integer', 'value' => 11), + 'rowid' => array('type' => 'integer', 'value' => 11, 'extra' => 'AUTO_INCREMENT PRIMARY KEY'), 'code' => array('type' => 'varchar', 'value' => 255, 'null'=>'NOT NULL'), 'label' => array('type' => 'varchar', 'value' => 255, 'null'=>'NOT NULL'), 'position' => array('type' => 'integer', 'value' => 11, 'null'=>'NULL'), diff --git a/test/phpunit/DoliDBTest.php b/test/phpunit/DoliDBTest.php index 34f70e459c9..adafc6a676c 100644 --- a/test/phpunit/DoliDBTest.php +++ b/test/phpunit/DoliDBTest.php @@ -66,7 +66,7 @@ class DoliDBTest extends CommonClassTest $res = $db->DDLDropTable($namedic); $columns = array( - 'rowid' => array('type' => 'integer', 'value' => 11), + 'rowid' => array('type' => 'integer', 'value' => 11, 'AUTO_INCREMENT PRIMARY KEY'), 'code' => array('type' => 'varchar', 'value' => 255, 'null'=>'NOT NULL'), 'label' => array('type' => 'varchar', 'value' => 255, 'null'=>'NOT NULL'), 'position' => array('type' => 'integer', 'value' => 11, 'null'=>'NULL'), From ba9a84667225316dee92134d9a5a5178eb8af485 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Mar 2024 12:50:30 +0100 Subject: [PATCH 058/114] Fix trans missing --- dev/translation/dynamic_translation_keys.lst | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/translation/dynamic_translation_keys.lst b/dev/translation/dynamic_translation_keys.lst index 6be815d4eca..47ab2e14a79 100644 --- a/dev/translation/dynamic_translation_keys.lst +++ b/dev/translation/dynamic_translation_keys.lst @@ -40,6 +40,7 @@ Reservation ACCOUNTING_ACCOUNT_CUSTOMER ACCOUNTING_ACCOUNT_CUSTOMER_Desc ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY +ACCOUNTING_ACCOUNT_EXPENSEREPORT ACCOUNTING_ACCOUNT_SUPPLIER ACCOUNTING_ACCOUNT_SUPPLIER_Desc ACCOUNTING_ACCOUNT_SUSPENSE From 84f21216107d3961bcf12567c819bf241ee536f7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Mar 2024 12:58:39 +0100 Subject: [PATCH 059/114] Add a FIXME --- htdocs/core/lib/modulebuilder.lib.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index 1ae0d52d93a..0250110d229 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -1308,8 +1308,10 @@ function createNewDictionnary($modulename, $file, $namedic, $dictionnaires = nul break; } } + // check if tablename exist in Database and create it if not - $query = "SHOW TABLES LIKE '" . $db->sanitize(MAIN_DB_PREFIX.strtolower($namedic)) . "'"; + // @FIXME We must use $db->DDLDescTable($table) to know if a table exists. + $query = "SHOW TABLES LIKE '" . $db->escape(MAIN_DB_PREFIX.strtolower($namedic)) . "'"; $checkTable = $db->query($query); if ($checkTable && $db->num_rows($checkTable) > 0) { setEventMessages($langs->trans("ErrorTableExist", $namedic), null, 'errors'); From 9d5aa4a44841ff0f474741d8596379e1590157b1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Mar 2024 13:02:41 +0100 Subject: [PATCH 060/114] Fix sanitization --- htdocs/core/db/mysqli.class.php | 4 ++-- htdocs/core/db/pgsql.class.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index 5b43b4e2cbc..0c50397d386 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -985,9 +985,9 @@ class DoliDBMysqli extends DoliDB } } if (isset($field_desc['extra']) && preg_match("/^[^\s]/i", $field_desc['extra'])) { - $sql .= " ".$this->escape($field_desc['extra'], 0, 0, 1); + $sql .= " ".$this->sanitize($field_desc['extra'], 0, 0, 1); } - $sql .= " ".$this->escape($field_position, 0, 0, 1); + $sql .= " ".$this->sanitize($field_position, 0, 0, 1); dol_syslog(get_class($this)."::DDLAddField ".$sql, LOG_DEBUG); if ($this->query($sql)) { diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index 51ea5e84447..430351e6317 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -1106,7 +1106,7 @@ class DoliDBPgsql extends DoliDB $sqlfields[$i] .= " ".$this->sanitize($field_desc['null'], 0, 0, 1); } if (!is_null($field_desc['extra']) && $field_desc['extra'] !== '') { - $sqlfields[$i] .= " ".$this->sanitize($field_desc['extra']); + $sqlfields[$i] .= " ".$this->sanitize($field_desc['extra'], 0, 0, 1); } $i++; } @@ -1229,9 +1229,9 @@ class DoliDBPgsql extends DoliDB } } if (isset($field_desc['extra']) && preg_match("/^[^\s]/i", $field_desc['extra'])) { - $sql .= " ".$this->escape($field_desc['extra'], 0, 0, 1); + $sql .= " ".$this->sanitize($field_desc['extra'], 0, 0, 1); } - $sql .= " ".$this->escape($field_position, 0, 0, 1); + $sql .= " ".$this->sanitize($field_position, 0, 0, 1); dol_syslog($sql, LOG_DEBUG); if (!$this -> query($sql)) { From 58e719eb56f154345f26c06b9e3ae36e56c6ffd8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Mar 2024 13:03:30 +0100 Subject: [PATCH 061/114] Fix sanitization --- htdocs/core/db/sqlite3.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/db/sqlite3.class.php b/htdocs/core/db/sqlite3.class.php index c210c7a836f..adcb7bf9f65 100644 --- a/htdocs/core/db/sqlite3.class.php +++ b/htdocs/core/db/sqlite3.class.php @@ -1151,7 +1151,7 @@ class DoliDBSqlite3 extends DoliDB { // phpcs:enable $sql = "ALTER TABLE ".$this->sanitize($table); - $sql .= " MODIFY COLUMN ".$this->sanitize(($field_name)." ".$this->sanitize($field_desc['type']); + $sql .= " MODIFY COLUMN ".$this->sanitize($field_name)." ".$this->sanitize($field_desc['type']); if ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') { $sql .= "(".$this->sanitize($field_desc['value']).")"; } From aee4ccc32c4dbeafbed508b076919df3c9d61355 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Mar 2024 13:06:20 +0100 Subject: [PATCH 062/114] Fix warnings --- htdocs/core/db/mysqli.class.php | 2 +- htdocs/core/db/pgsql.class.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index 0c50397d386..d915bb27de0 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -1013,7 +1013,7 @@ class DoliDBMysqli extends DoliDB if (in_array($field_desc['type'], array('double', 'tinyint', 'int', 'varchar')) && $field_desc['value']) { $sql .= "(".$this->sanitize($field_desc['value']).")"; } - if ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL') { + if (isset($field_desc['value']) && ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL')) { // We will try to change format of column to NOT NULL. To be sure the ALTER works, we try to update fields that are NULL if ($field_desc['type'] == 'varchar' || $field_desc['type'] == 'text') { $sqlbis = "UPDATE ".$this->sanitize($table)." SET ".$this->sanitize($field_name)." = '".$this->escape(isset($field_desc['default']) ? $field_desc['default'] : '')."' WHERE ".$this->sanitize($field_name)." IS NULL"; diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index 430351e6317..531dc7cb07d 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -1254,13 +1254,13 @@ class DoliDBPgsql extends DoliDB // phpcs:enable $sql = "ALTER TABLE ".$this->sanitize($table); $sql .= " ALTER COLUMN ".$this->sanitize($field_name)." TYPE ".$this->sanitize($field_desc['type']); - if (preg_match("/^[^\s]/i", $field_desc['value'])) { + if (isset($field_desc['value']) && preg_match("/^[^\s]/i", $field_desc['value'])) { if (!in_array($field_desc['type'], array('smallint', 'int', 'date', 'datetime')) && $field_desc['value']) { $sql .= "(".$this->sanitize($field_desc['value']).")"; } } - if ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL') { + if (isset($field_desc['value']) && ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL')) { // We will try to change format of column to NOT NULL. To be sure the ALTER works, we try to update fields that are NULL if ($field_desc['type'] == 'varchar' || $field_desc['type'] == 'text') { $sqlbis = "UPDATE ".$this->sanitize($table)." SET ".$this->escape($field_name)." = '".$this->escape(isset($field_desc['default']) ? $field_desc['default'] : '')."' WHERE ".$this->escape($field_name)." IS NULL"; From f3e6b38d9dd29d4569058c303e7263c56c78deaf Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Mar 2024 13:16:59 +0100 Subject: [PATCH 063/114] Fix warning --- htdocs/core/db/sqlite3.class.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/htdocs/core/db/sqlite3.class.php b/htdocs/core/db/sqlite3.class.php index adcb7bf9f65..a41aea9d1ea 100644 --- a/htdocs/core/db/sqlite3.class.php +++ b/htdocs/core/db/sqlite3.class.php @@ -1008,7 +1008,7 @@ class DoliDBSqlite3 extends DoliDB $sqlfields[$i] .= " ".$this->sanitize($field_desc['null'], 0, 0, 1); } if (!is_null($field_desc['extra']) && $field_desc['extra'] !== '') { - $sqlfields[$i] .= " ".$this->sanitize($field_desc['extra']); + $sqlfields[$i] .= " ".$this->sanitize($field_desc['extra'], 0, 0, 1); } $i++; } @@ -1106,18 +1106,18 @@ class DoliDBSqlite3 extends DoliDB // ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); $sql = "ALTER TABLE ".$table." ADD ".$field_name." "; $sql .= $field_desc['type']; - if (preg_match("/^[^\s]/i", $field_desc['value'])) { + if (isset($field_desc['value']) && preg_match("/^[^\s]/i", $field_desc['value'])) { if (!in_array($field_desc['type'], array('date', 'datetime'))) { $sql .= "(".$field_desc['value'].")"; } } - if (preg_match("/^[^\s]/i", $field_desc['attribute'])) { - $sql .= " ".$field_desc['attribute']; + if (isset($field_desc['attribute']) && preg_match("/^[^\s]/i", $field_desc['attribute'])) { + $sql .= " ".$this->sanitize($field_desc['attribute']); } - if (preg_match("/^[^\s]/i", $field_desc['null'])) { - $sql .= " ".$field_desc['null']; + if (isset($field_desc['null']) && preg_match("/^[^\s]/i", $field_desc['null'])) { + $sql .= " ".$this->sanitize($field_desc['null'], 0, 0, 1); } - if (preg_match("/^[^\s]/i", $field_desc['default'])) { + if (isset($field_desc['default']) && preg_match("/^[^\s]/i", $field_desc['default'])) { if (in_array($field_desc['type'], array('tinyint', 'smallint', 'int', 'double'))) { $sql .= " DEFAULT ".((float) $field_desc['default']); } elseif ($field_desc['default'] == 'null' || $field_desc['default'] == 'CURRENT_TIMESTAMP') { @@ -1127,9 +1127,9 @@ class DoliDBSqlite3 extends DoliDB } } if (isset($field_desc['extra']) && preg_match("/^[^\s]/i", $field_desc['extra'])) { - $sql .= " ".$this->escape($field_desc['extra'], 0, 0, 1); + $sql .= " ".$this->sanitize($field_desc['extra'], 0, 0, 1); } - $sql .= " ".$this->escape($field_position, 0, 0, 1); + $sql .= " ".$this->sanitize($field_position, 0, 0, 1); dol_syslog(get_class($this)."::DDLAddField ".$sql, LOG_DEBUG); if (!$this->query($sql)) { From 380c1092ebcbd96a51cf075708efb779909419af Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Mar 2024 13:19:31 +0100 Subject: [PATCH 064/114] Fix warnings --- htdocs/core/db/mysqli.class.php | 3 ++- htdocs/core/db/pgsql.class.php | 1 - htdocs/core/db/sqlite3.class.php | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index d915bb27de0..68fe297edf9 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -832,7 +832,8 @@ class DoliDBMysqli extends DoliDB } $pk = ''; - $sqluq = $sqlk = array(); + $sqlk = array(); + $sqluq = array(); // Keys found into the array $fields: type,value,attribute,null,default,extra // ex. : $fields['rowid'] = array( diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index 531dc7cb07d..71ba5f5279a 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -1070,7 +1070,6 @@ class DoliDBPgsql extends DoliDB // phpcs:enable // @TODO: $fulltext_keys parameter is unused - $sqlfields = array(); $sqlk = array(); $sqluq = array(); diff --git a/htdocs/core/db/sqlite3.class.php b/htdocs/core/db/sqlite3.class.php index a41aea9d1ea..532ae556eb5 100644 --- a/htdocs/core/db/sqlite3.class.php +++ b/htdocs/core/db/sqlite3.class.php @@ -972,7 +972,6 @@ class DoliDBSqlite3 extends DoliDB // phpcs:enable // @TODO: $fulltext_keys parameter is unused - $sqlfields = array(); $sqlk = array(); $sqluq = array(); From b5804aecfdf807e6bf70acf067b532398406ce4e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Mar 2024 13:34:16 +0100 Subject: [PATCH 065/114] Fix bad cast for name newtoken --- htdocs/takepos/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index 4eb11d2286f..952b2d8a7ad 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -1186,7 +1186,7 @@ if (!getDolGlobalString('TAKEPOS_HIDE_HEAD_BAR')) { ?>
    From 3908b4df9d23fe0c0a08f1018a57ea7295fe39c0 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 12:21:23 +0100 Subject: [PATCH 066/114] Qual: Enable PhanTypeInvalidLeftOperandOfBitwiseOp (all fixed) --- dev/tools/phan/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tools/phan/config.php b/dev/tools/phan/config.php index 4875cd7bafd..01043b3adc3 100644 --- a/dev/tools/phan/config.php +++ b/dev/tools/phan/config.php @@ -495,7 +495,7 @@ return [ 'PhanPossiblyNullTypeMismatchProperty', 'PhanRedefineClass', 'PhanRedefineFunction', - 'PhanTypeInvalidLeftOperandOfBitwiseOp', + // 'PhanTypeInvalidLeftOperandOfBitwiseOp', // 'PhanTypeMismatchDimAssignment', // 'PhanPluginDescriptionlessCommentOnProtectedMethod', // 'PhanPluginPrintfIncompatibleArgumentTypeWeak', From 81d9e8aa01f6403dbc6abc14b13fab3d6a87f20b Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 11:36:51 +0100 Subject: [PATCH 067/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = $var || ... . Add cast before ... when needed (@include does not always return bool). --- htdocs/asset/class/asset.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/asset/class/asset.class.php b/htdocs/asset/class/asset.class.php index 8666a469aee..ada95d4de5a 100644 --- a/htdocs/asset/class/asset.class.php +++ b/htdocs/asset/class/asset.class.php @@ -1548,7 +1548,7 @@ class Asset extends CommonObject $dir = dol_buildpath($reldir."core/modules/asset/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = $mybool || (bool) @include_once $dir.$file; } if ($mybool === false) { From b6ac5dcf76f62482e770fec366a260a3b4eb8588 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:20:54 +0100 Subject: [PATCH 068/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/asset/class/asset.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/asset/class/asset.class.php b/htdocs/asset/class/asset.class.php index ada95d4de5a..ed7a57e3af5 100644 --- a/htdocs/asset/class/asset.class.php +++ b/htdocs/asset/class/asset.class.php @@ -1548,7 +1548,7 @@ class Asset extends CommonObject $dir = dol_buildpath($reldir."core/modules/asset/"); // Load file with numbering class (if found) - $mybool = $mybool || (bool) @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From 43a7db166e40d15de71b7203fbf3f659838b31fb Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Mar 2024 13:44:57 +0100 Subject: [PATCH 069/114] Update mailing-send.php --- scripts/emailings/mailing-send.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/emailings/mailing-send.php b/scripts/emailings/mailing-send.php index 78fb388acce..dac34f9ff65 100755 --- a/scripts/emailings/mailing-send.php +++ b/scripts/emailings/mailing-send.php @@ -128,8 +128,8 @@ if ($resql) { dol_syslog("Process mailing with id ".$obj->rowid); print "Process mailing with id ".$obj->rowid."\n"; - if ($obj->status==1) { - $sql = "UPDATE ".MAIN_DB_PREFIX."mailing SET statut=2 WHERE rowid=".$obj->rowid; + if ($obj->status == 1) { + $sql = "UPDATE ".MAIN_DB_PREFIX."mailing SET statut = 2 WHERE rowid = ".((int) $obj->rowid); $result_sql = $db->query($sql); dol_syslog("Started mailing campaign ".$obj->rowid, LOG_DEBUG); } From bf4243e0ab380b1e9a78fa1932ffeaea795e0c0f Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:20:56 +0100 Subject: [PATCH 070/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/bom/class/bom.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index 702ddb9fb8f..6de866029f7 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -875,7 +875,7 @@ class BOM extends CommonObject $dir = dol_buildpath($reldir."core/modules/bom/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From 66804f5f4dc825f287e08932f32bdb2fa4e690ed Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:20:59 +0100 Subject: [PATCH 071/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/bookcal/class/availabilities.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/bookcal/class/availabilities.class.php b/htdocs/bookcal/class/availabilities.class.php index ad34e08abcd..6a4553e15f2 100644 --- a/htdocs/bookcal/class/availabilities.class.php +++ b/htdocs/bookcal/class/availabilities.class.php @@ -975,7 +975,7 @@ class Availabilities extends CommonObject $dir = dol_buildpath($reldir."core/modules/bookcal/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From e114884d118d66a07833cb3e8777ed8a249dd0fe Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:21:02 +0100 Subject: [PATCH 072/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/bookcal/class/calendar.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/bookcal/class/calendar.class.php b/htdocs/bookcal/class/calendar.class.php index b66f950fd12..d64aad6791c 100644 --- a/htdocs/bookcal/class/calendar.class.php +++ b/htdocs/bookcal/class/calendar.class.php @@ -964,7 +964,7 @@ class Calendar extends CommonObject $dir = dol_buildpath($reldir."core/modules/bookcal/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From e44e29c446fa1923f330f75d4b90109607a1a07c Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:21:04 +0100 Subject: [PATCH 073/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/comm/propal/class/propal.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 97f818d82a3..04b4a6e99b2 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -3615,7 +3615,7 @@ class Propal extends CommonObject $dir = dol_buildpath($reldir."core/modules/propale/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if (!$mybool) { From 170a9296564023dc1290fc2b9feb2933f239aad1 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:21:06 +0100 Subject: [PATCH 074/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/commande/class/commande.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 11e5a4adc8c..291ead61cd3 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -416,7 +416,7 @@ class Commande extends CommonOrder $dir = dol_buildpath($reldir."core/modules/commande/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From ecf24fd3b4139c569b917dc473e259b4a0ada061 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:21:09 +0100 Subject: [PATCH 075/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/compta/facture/class/facture.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index b3d8b940673..8f5c63a86f0 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -4609,7 +4609,7 @@ class Facture extends CommonInvoice // Load file with numbering class (if found) if (is_file($dir.$file) && is_readable($dir.$file)) { - $mybool |= include_once $dir.$file; + $mybool = ((bool) include_once $dir.$file) || $mybool; } } @@ -4624,7 +4624,7 @@ class Facture extends CommonInvoice // Load file with numbering class (if found) if (is_file($dir.$file) && is_readable($dir.$file)) { - $mybool |= include_once $dir.$file; + $mybool = (include_once $dir.$file) || $mybool; } } } From 8e5871d1fc22959d1dd476d99c430f972ad0c776 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:21:12 +0100 Subject: [PATCH 076/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/compta/paiement/cheque/class/remisecheque.class.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/paiement/cheque/class/remisecheque.class.php b/htdocs/compta/paiement/cheque/class/remisecheque.class.php index 2be5b322d69..71496b46c6f 100644 --- a/htdocs/compta/paiement/cheque/class/remisecheque.class.php +++ b/htdocs/compta/paiement/cheque/class/remisecheque.class.php @@ -5,6 +5,7 @@ * Copyright (C) 2011-2016 Juanjo Menent * Copyright (C) 2015 Marcos García * Copyright (C) 2024 Frédéric France + * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -423,7 +424,7 @@ class RemiseCheque extends CommonObject // Load file with numbering class (if found) if (is_file($dir.$file) && is_readable($dir.$file)) { - $mybool |= include_once $dir.$file; + $mybool = (include_once $dir.$file) || $mybool; } } @@ -438,7 +439,7 @@ class RemiseCheque extends CommonObject // Load file with numbering class (if found) if (is_file($dir.$file) && is_readable($dir.$file)) { - $mybool |= include_once $dir.$file; + $mybool = (include_once $dir.$file) || $mybool; } } } From a42203cc9356faa6a4335d7452fd1911ecfa6619 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:21:16 +0100 Subject: [PATCH 077/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/compta/paiement/class/paiement.class.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index d60aa17ce3b..921ecddab78 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -13,6 +13,7 @@ * Copyright (C) 2021 OpenDsi * Copyright (C) 2023 Joachim Kueter * Copyright (C) 2023 Sylvain Legrand + * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -847,7 +848,7 @@ class Paiement extends CommonObject // Add link to the Direct Debit if invoice refused ('InvoiceRefused') in bank_url if (!$error && $label == '(InvoiceRefused)') { - $result=$acc->add_url_line( + $result = $acc->add_url_line( $bank_line_id, $this->id_prelevement, DOL_URL_ROOT.'/compta/prelevement/card.php?id=', @@ -1182,7 +1183,7 @@ class Paiement extends CommonObject // Load file with numbering class (if found) if (is_file($dir.$file) && is_readable($dir.$file)) { - $mybool |= include_once $dir.$file; + $mybool = (include_once $dir.$file) || $mybool; } } @@ -1197,7 +1198,7 @@ class Paiement extends CommonObject // Load file with numbering class (if found) if (is_file($dir.$file) && is_readable($dir.$file)) { - $mybool |= include_once $dir.$file; + $mybool = (include_once $dir.$file) || $mybool; } } } @@ -1352,7 +1353,7 @@ class Paiement extends CommonObject $result .= $linkend; global $action; $hookmanager->initHooks(array($this->element . 'dao')); - $parameters = array('id'=>$this->id, 'getnomurl' => &$result); + $parameters = array('id' => $this->id, 'getnomurl' => &$result); $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if ($reshook > 0) { $result = $hookmanager->resPrint; From 6a14a8304df9f44e2a58c18fdbe9a831fec42256 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:21:20 +0100 Subject: [PATCH 078/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/contrat/class/contrat.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index ccd92dccf39..c3e5001b2af 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -337,7 +337,7 @@ class Contrat extends CommonObject $dir = dol_buildpath($reldir."core/modules/contract/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if (!$mybool) { From 2ec5504dcbbae5c585026894210607d0a223bf19 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:21:22 +0100 Subject: [PATCH 079/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/core/class/timespent.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/timespent.class.php b/htdocs/core/class/timespent.class.php index 927dbed57ca..e32be223840 100644 --- a/htdocs/core/class/timespent.class.php +++ b/htdocs/core/class/timespent.class.php @@ -951,7 +951,7 @@ class TimeSpent extends CommonObject $dir = dol_buildpath($reldir."core/modules/timespent/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From 4cac66ba178232fc02eb0aac74fbed94ae0a2e82 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:21:24 +0100 Subject: [PATCH 080/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- .../eventorganization/class/conferenceorboothattendee.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/eventorganization/class/conferenceorboothattendee.class.php b/htdocs/eventorganization/class/conferenceorboothattendee.class.php index f6e4bff74cd..f30196c2ef3 100644 --- a/htdocs/eventorganization/class/conferenceorboothattendee.class.php +++ b/htdocs/eventorganization/class/conferenceorboothattendee.class.php @@ -969,7 +969,7 @@ class ConferenceOrBoothAttendee extends CommonObject $dir = dol_buildpath($reldir."core/modules/eventorganization/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From 5be1600c5231baf646b92d7bb8c8da1ddd59dfa5 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:21:27 +0100 Subject: [PATCH 081/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/expedition/class/expedition.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 259d1470a24..897927b03d6 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -306,7 +306,7 @@ class Expedition extends CommonObject $dir = dol_buildpath($reldir."core/modules/expedition/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if (!$mybool) { From 1e0f368d6a6f0bfc0230072bf97fefe56961eb8d Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:21:30 +0100 Subject: [PATCH 082/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/expensereport/class/expensereport.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index 551390582f4..b7aced293b3 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -1729,7 +1729,7 @@ class ExpenseReport extends CommonObject $dir = dol_buildpath($reldir."core/modules/expensereport/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From d3a58e2e487ac45a69d12cbeebc9b8ee31807b99 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:21:33 +0100 Subject: [PATCH 083/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/fichinter/class/fichinter.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index f5b57037c0d..d54497125c1 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -200,17 +200,17 @@ class Fichinter extends CommonObject /* * Signed by sender */ - CONST STATUS_SIGNED_SENDER = 1; + const STATUS_SIGNED_SENDER = 1; /* * Signed by receiver */ - CONST STATUS_SIGNED_RECEIVER = 2; + const STATUS_SIGNED_RECEIVER = 2; /* * Signed by all */ - CONST STATUS_SIGNED_ALL = 9; // To handle future kind of signature (ex: tripartite contract) + const STATUS_SIGNED_ALL = 9; // To handle future kind of signature (ex: tripartite contract) /** * Date delivery @@ -1010,7 +1010,7 @@ class Fichinter extends CommonObject $dir = dol_buildpath($reldir."core/modules/fichinter/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From 476d8cfd9c9495e2025becf5e10441d22dd4db7a Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:21:36 +0100 Subject: [PATCH 084/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/fourn/class/fournisseur.commande.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index d9f7863c16c..3f30bf444de 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -1129,7 +1129,7 @@ class CommandeFournisseur extends CommonOrder $dir = dol_buildpath($reldir."core/modules/supplier_order/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From e19a60cd6237355fe1f8cbaf7039c6678002ac8f Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:21:38 +0100 Subject: [PATCH 085/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/fourn/class/fournisseur.facture.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 7c733bc8f5a..576645afab4 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -2963,7 +2963,7 @@ class FactureFournisseur extends CommonInvoice $dir = dol_buildpath($reldir."core/modules/supplier_invoice/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From effe9e79b5043687f6739c5271127ad8de6f8ec0 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:21:40 +0100 Subject: [PATCH 086/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/fourn/class/paiementfourn.class.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/htdocs/fourn/class/paiementfourn.class.php b/htdocs/fourn/class/paiementfourn.class.php index c01feb22892..8c221fff4d9 100644 --- a/htdocs/fourn/class/paiementfourn.class.php +++ b/htdocs/fourn/class/paiementfourn.class.php @@ -10,6 +10,7 @@ * Copyright (C) 2023 Joachim Kueter * Copyright (C) 2023 Sylvain Legrand * Copyright (C) 2024 Frédéric France + * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -279,9 +280,9 @@ class PaiementFourn extends Paiement // If we want to closed paid invoices if ($closepaidinvoices) { $paiement = $invoice->getSommePaiement(); - $creditnotes=$invoice->getSumCreditNotesUsed(); + $creditnotes = $invoice->getSumCreditNotesUsed(); //$creditnotes = 0; - $deposits=$invoice->getSumDepositsUsed(); + $deposits = $invoice->getSumDepositsUsed(); //$deposits = 0; $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT'); $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT'); @@ -712,7 +713,7 @@ class PaiementFourn extends Paiement global $action; $hookmanager->initHooks(array($this->element . 'dao')); - $parameters = array('id'=>$this->id, 'getnomurl' => &$result); + $parameters = array('id' => $this->id, 'getnomurl' => &$result); $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if ($reshook > 0) { $result = $hookmanager->resPrint; @@ -783,7 +784,7 @@ class PaiementFourn extends Paiement // Load file with numbering class (if found) if (is_file($dir.$file) && is_readable($dir.$file)) { - $mybool |= include_once $dir.$file; + $mybool = (include_once $dir.$file) || $mybool; } } @@ -798,7 +799,7 @@ class PaiementFourn extends Paiement // Load file with numbering class (if found) if (is_file($dir.$file) && is_readable($dir.$file)) { - $mybool |= include_once $dir.$file; + $mybool = (include_once $dir.$file) || $mybool; } } } From 1a6ad0ea67f70b615670e8391cae1dbbf8a99926 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:21:42 +0100 Subject: [PATCH 087/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/holiday/class/holiday.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php index e5afa1e524a..6608cbbbb34 100644 --- a/htdocs/holiday/class/holiday.class.php +++ b/htdocs/holiday/class/holiday.class.php @@ -232,7 +232,7 @@ class Holiday extends CommonObject $dir = dol_buildpath($reldir."core/modules/holiday/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From 0df51158dd177f4a028e4ec024826b39b9703528 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:21:45 +0100 Subject: [PATCH 088/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/hrm/class/evaluation.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/hrm/class/evaluation.class.php b/htdocs/hrm/class/evaluation.class.php index 7b551e80d99..0598a8cf46b 100644 --- a/htdocs/hrm/class/evaluation.class.php +++ b/htdocs/hrm/class/evaluation.class.php @@ -952,7 +952,7 @@ class Evaluation extends CommonObject $dir = dol_buildpath($reldir."core/modules/hrm/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From 169d1a2ff8d37af1d8e63f81b286f74f49e8ce19 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:21:48 +0100 Subject: [PATCH 089/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/hrm/class/evaluationdet.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/hrm/class/evaluationdet.class.php b/htdocs/hrm/class/evaluationdet.class.php index 992e7fa4ce0..0c6b5149f8a 100644 --- a/htdocs/hrm/class/evaluationdet.class.php +++ b/htdocs/hrm/class/evaluationdet.class.php @@ -922,7 +922,7 @@ class EvaluationLine extends CommonObjectLine $dir = dol_buildpath($reldir."core/modules/hrm/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From f28af956f997a4d8e8205679671c0c651bb31f77 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:21:50 +0100 Subject: [PATCH 090/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/hrm/class/job.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/hrm/class/job.class.php b/htdocs/hrm/class/job.class.php index 5c2f34a5588..ec9cbea1b91 100644 --- a/htdocs/hrm/class/job.class.php +++ b/htdocs/hrm/class/job.class.php @@ -961,7 +961,7 @@ class Job extends CommonObject $dir = dol_buildpath($reldir."core/modules/hrm/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From 579f2dee4c59a23e8442341385f356813c53a81c Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:21:52 +0100 Subject: [PATCH 091/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/hrm/class/position.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/hrm/class/position.class.php b/htdocs/hrm/class/position.class.php index bcd91410fda..197ac19eb5b 100644 --- a/htdocs/hrm/class/position.class.php +++ b/htdocs/hrm/class/position.class.php @@ -1001,7 +1001,7 @@ class Position extends CommonObject $dir = dol_buildpath($reldir . "core/modules/hrm/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir . $file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From b3cda67e361eb5baef56a89cee7b1a5c709c769e Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:21:54 +0100 Subject: [PATCH 092/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/hrm/class/skill.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/hrm/class/skill.class.php b/htdocs/hrm/class/skill.class.php index b6759336016..4ce76501127 100644 --- a/htdocs/hrm/class/skill.class.php +++ b/htdocs/hrm/class/skill.class.php @@ -1001,7 +1001,7 @@ class Skill extends CommonObject $dir = dol_buildpath($reldir."core/modules/hrm/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From ee5d837fcc67602edddc760aeebac8c71e48d1bd Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:21:56 +0100 Subject: [PATCH 093/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/hrm/class/skilldet.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/hrm/class/skilldet.class.php b/htdocs/hrm/class/skilldet.class.php index 6c02ca26c50..9190c413bcc 100644 --- a/htdocs/hrm/class/skilldet.class.php +++ b/htdocs/hrm/class/skilldet.class.php @@ -889,7 +889,7 @@ class Skilldet extends CommonObjectLine $dir = dol_buildpath($reldir."core/modules/hrm/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From 519da008972b545b0bdd74fbdf6cbd5888d7f5a9 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:21:58 +0100 Subject: [PATCH 094/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/hrm/class/skillrank.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/hrm/class/skillrank.class.php b/htdocs/hrm/class/skillrank.class.php index 3cde6ae6476..7640049c4f5 100644 --- a/htdocs/hrm/class/skillrank.class.php +++ b/htdocs/hrm/class/skillrank.class.php @@ -965,7 +965,7 @@ class SkillRank extends CommonObject $dir = dol_buildpath($reldir."core/modules/hrm/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From fe5e5b4bc4256e8fd9769ba9de21cbc135183468 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:22:00 +0100 Subject: [PATCH 095/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/knowledgemanagement/class/knowledgerecord.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/knowledgemanagement/class/knowledgerecord.class.php b/htdocs/knowledgemanagement/class/knowledgerecord.class.php index 1bb1040553a..402e41c7d76 100644 --- a/htdocs/knowledgemanagement/class/knowledgerecord.class.php +++ b/htdocs/knowledgemanagement/class/knowledgerecord.class.php @@ -1027,7 +1027,7 @@ class KnowledgeRecord extends CommonObject $dir = dol_buildpath($reldir."core/modules/knowledgemanagement/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From 67f43f0558751ab76e9792c4c32a1f8a5c8c84e5 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:22:02 +0100 Subject: [PATCH 096/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/mrp/class/mo.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php index c8589a3f4ba..c82f54d4568 100644 --- a/htdocs/mrp/class/mo.class.php +++ b/htdocs/mrp/class/mo.class.php @@ -1020,7 +1020,7 @@ class Mo extends CommonObject $dir = dol_buildpath($reldir."core/modules/mrp/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From c9f314958edc4c9bdb40328ed99edab6bf46c4dd Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:22:05 +0100 Subject: [PATCH 097/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/partnership/class/partnership.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/partnership/class/partnership.class.php b/htdocs/partnership/class/partnership.class.php index 7d26d35cb44..68ffaeb291c 100644 --- a/htdocs/partnership/class/partnership.class.php +++ b/htdocs/partnership/class/partnership.class.php @@ -1230,7 +1230,7 @@ class Partnership extends CommonObject $dir = dol_buildpath($reldir."core/modules/partnership/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From 4e22e336380a1fb9c7ac2b405ab7fe09db39be38 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:22:08 +0100 Subject: [PATCH 098/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/product/class/productfournisseurprice.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/class/productfournisseurprice.class.php b/htdocs/product/class/productfournisseurprice.class.php index 6e3b15405d0..93666b0431b 100644 --- a/htdocs/product/class/productfournisseurprice.class.php +++ b/htdocs/product/class/productfournisseurprice.class.php @@ -824,7 +824,7 @@ class ProductFournisseurPrice extends CommonObject $dir = dol_buildpath($reldir."core/modules/buypricehistory/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From 6ebe4f1b22f8f9acebc96b528d8fefb71496a0bb Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:22:11 +0100 Subject: [PATCH 099/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- .../product/stock/stocktransfer/class/stocktransfer.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php b/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php index 4bf107d58f3..a8e1267175d 100644 --- a/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php +++ b/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php @@ -975,7 +975,7 @@ class StockTransfer extends CommonObject $dir = dol_buildpath($reldir."core/modules/stocktransfer/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From 25bd4930a28dc9d4a940f951ab3f5ac85b495452 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:22:13 +0100 Subject: [PATCH 100/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- .../stock/stocktransfer/class/stocktransferline.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/stock/stocktransfer/class/stocktransferline.class.php b/htdocs/product/stock/stocktransfer/class/stocktransferline.class.php index ac930e58b94..cd77a955806 100644 --- a/htdocs/product/stock/stocktransfer/class/stocktransferline.class.php +++ b/htdocs/product/stock/stocktransfer/class/stocktransferline.class.php @@ -939,7 +939,7 @@ class StockTransferLine extends CommonObjectLine $dir = dol_buildpath($reldir."core/modules/stocktransfer/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From a960e74a5cd4df7c134ccc9e64f1dfdfb42993f6 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:22:15 +0100 Subject: [PATCH 101/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/reception/class/reception.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/reception/class/reception.class.php b/htdocs/reception/class/reception.class.php index 8ba93145914..92a59e101e5 100644 --- a/htdocs/reception/class/reception.class.php +++ b/htdocs/reception/class/reception.class.php @@ -180,7 +180,7 @@ class Reception extends CommonObject $dir = dol_buildpath($reldir."core/modules/reception/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if (!$mybool) { From 105a4d0402c65cd4d2e01421a196799abdc0ad3b Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:22:18 +0100 Subject: [PATCH 102/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/recruitment/class/recruitmentcandidature.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/recruitment/class/recruitmentcandidature.class.php b/htdocs/recruitment/class/recruitmentcandidature.class.php index f80911e4381..59c152cac47 100644 --- a/htdocs/recruitment/class/recruitmentcandidature.class.php +++ b/htdocs/recruitment/class/recruitmentcandidature.class.php @@ -953,7 +953,7 @@ class RecruitmentCandidature extends CommonObject $dir = dol_buildpath($reldir."core/modules/recruitment/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From b452a89cc3a68db7d1edd8d5e2aae9500fd8fd00 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:22:21 +0100 Subject: [PATCH 103/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/recruitment/class/recruitmentjobposition.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/recruitment/class/recruitmentjobposition.class.php b/htdocs/recruitment/class/recruitmentjobposition.class.php index 90fe44b212d..dbc9e11cce1 100644 --- a/htdocs/recruitment/class/recruitmentjobposition.class.php +++ b/htdocs/recruitment/class/recruitmentjobposition.class.php @@ -1010,7 +1010,7 @@ class RecruitmentJobPosition extends CommonObject $dir = dol_buildpath($reldir."core/modules/recruitment/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From 15f38d472ebc5d8a643cd93f1a8d2f67ed1a925e Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:22:22 +0100 Subject: [PATCH 104/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/supplier_proposal/class/supplier_proposal.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index fee21d4365b..503f99b65aa 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -2429,7 +2429,7 @@ class SupplierProposal extends CommonObject $dir = dol_buildpath($reldir."core/modules/supplier_proposal/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if (!$mybool) { From 474c85825f74b33bfb01d4775cc98379d389dba0 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:22:26 +0100 Subject: [PATCH 105/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/webhook/class/target.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/webhook/class/target.class.php b/htdocs/webhook/class/target.class.php index ef405bfadea..abd25cd844e 100644 --- a/htdocs/webhook/class/target.class.php +++ b/htdocs/webhook/class/target.class.php @@ -901,7 +901,7 @@ class Target extends CommonObject $dir = dol_buildpath($reldir."core/modules/webhook/"); // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } if ($mybool === false) { From c9d897ee356bc3cb93468bf38118df751d8e43f4 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:22:28 +0100 Subject: [PATCH 106/114] Fix $mybool |=... which is binary op, not boolean op # Fix $mybool |=... which is binary op, not boolean op This fixes PhanTypeInvalidLeftOperandOfBitwiseOp. Replace $var |= ... with $var = ... || $var . Add cast before ... when needed (@include does not always return bool). |= always evaluates expression, there for || $var, not $var || --- htdocs/workstation/class/workstation.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/workstation/class/workstation.class.php b/htdocs/workstation/class/workstation.class.php index c4b4cecc710..bed11601dc0 100644 --- a/htdocs/workstation/class/workstation.class.php +++ b/htdocs/workstation/class/workstation.class.php @@ -878,7 +878,7 @@ class Workstation extends CommonObject // Load file with numbering class (if found) if (file_exists($dir.$file)) { - $mybool |= @include_once $dir.$file; + $mybool = ((bool) @include_once $dir.$file) || $mybool; } } From 9d31390e7483ad1a0c69790d8215746305429d1f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Mar 2024 13:48:50 +0100 Subject: [PATCH 107/114] Update mailing-send.php --- scripts/emailings/mailing-send.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/emailings/mailing-send.php b/scripts/emailings/mailing-send.php index dac34f9ff65..a9a701f9f80 100755 --- a/scripts/emailings/mailing-send.php +++ b/scripts/emailings/mailing-send.php @@ -122,7 +122,7 @@ if ($resql) { $j = 0; if ($num) { - for ($j = 0; $j < $num && $max!=0; $j++) { + for ($j = 0; $j < $num && $max != 0; $j++) { $obj = $db->fetch_object($resql); dol_syslog("Process mailing with id ".$obj->rowid); From 477fb7a03526079e643eaaa900c55737377cf662 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Mar 2024 13:55:23 +0100 Subject: [PATCH 108/114] Fix warning --- htdocs/core/db/mysqli.class.php | 10 +++++----- scripts/emailings/mailing-send.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index 68fe297edf9..c1b7bdd487c 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -848,13 +848,13 @@ class DoliDBMysqli extends DoliDB foreach ($fields as $field_name => $field_desc) { $sqlfields[$i] = $this->sanitize($field_name)." "; $sqlfields[$i] .= $this->sanitize($field_desc['type']); - if (!is_null($field_desc['value']) && $field_desc['value'] !== '') { + if (isset($field_desc['value']) && $field_desc['value'] !== '') { $sqlfields[$i] .= "(".$this->sanitize($field_desc['value']).")"; } - if (!is_null($field_desc['attribute']) && $field_desc['attribute'] !== '') { + if (isset($field_desc['attribute']) && $field_desc['attribute'] !== '') { $sqlfields[$i] .= " ".$this->sanitize($field_desc['attribute']); } - if (!is_null($field_desc['default']) && $field_desc['default'] !== '') { + if (isset($field_desc['default']) && $field_desc['default'] !== '') { if (in_array($field_desc['type'], array('tinyint', 'smallint', 'int', 'double'))) { $sqlfields[$i] .= " DEFAULT ".((float) $field_desc['default']); } elseif ($field_desc['default'] == 'null' || $field_desc['default'] == 'CURRENT_TIMESTAMP') { @@ -863,10 +863,10 @@ class DoliDBMysqli extends DoliDB $sqlfields[$i] .= " DEFAULT '".$this->escape($field_desc['default'])."'"; } } - if (!is_null($field_desc['null']) && $field_desc['null'] !== '') { + if (isset($field_desc['null']) && $field_desc['null'] !== '') { $sqlfields[$i] .= " ".$this->sanitize($field_desc['null'], 0, 0, 1); } - if (!is_null($field_desc['extra']) && $field_desc['extra'] !== '') { + if (isset($field_desc['extra']) && $field_desc['extra'] !== '') { $sqlfields[$i] .= " ".$this->sanitize($field_desc['extra'], 0, 0, 1); } $i++; diff --git a/scripts/emailings/mailing-send.php b/scripts/emailings/mailing-send.php index bd3f7e45953..2a724ab2042 100755 --- a/scripts/emailings/mailing-send.php +++ b/scripts/emailings/mailing-send.php @@ -154,7 +154,7 @@ if ($resql) { $sql2 .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc"; $sql2 .= " WHERE mc.statut < 1 AND mc.fk_mailing = ".((int) $id); if (getDolGlobalInt('MAILING_LIMIT_SENDBYCLI') > 0 && empty($max)) { - $sql2 .= " LIMIT " . getDolGlobalString('MAILING_LIMIT_SENDBYCLI'); + $sql2 .= " LIMIT " . getDolGlobalInt('MAILING_LIMIT_SENDBYCLI'); } elseif (getDolGlobalInt('MAILING_LIMIT_SENDBYCLI') > 0 && $max > 0) { $sql2 .= " LIMIT ".min(getDolGlobalInt('MAILING_LIMIT_SENDBYCLI'), $max); } elseif ($max > 0) { From 7032578914b30e766891e993d36f5e0bd039277d Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Mar 2024 13:55:29 +0100 Subject: [PATCH 109/114] Fix PHPdoc typing --- htdocs/debugbar/class/TraceableDB.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/debugbar/class/TraceableDB.php b/htdocs/debugbar/class/TraceableDB.php index 9dc266ea5e0..013a31b66ac 100644 --- a/htdocs/debugbar/class/TraceableDB.php +++ b/htdocs/debugbar/class/TraceableDB.php @@ -495,7 +495,7 @@ class TraceableDB extends DoliDB * Create a table into database * * @param string $table Name of table - * @param array $fields Tableau associatif [nom champ][tableau des descriptions] + * @param array|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string}> $fields Associative table [field name][table of descriptions] * @param string $primary_key Nom du champ qui sera la clef primaire * @param string $type Type de la table * @param array $unique_keys Tableau associatifs Nom de champs qui seront clef unique => valeur @@ -534,7 +534,7 @@ class TraceableDB extends DoliDB * * @param string $table Name of table * @param string $field_name Name of field to add - * @param array{type:string,label:string,enabled:int|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array<int,string>,comment?:string} $field_desc Tableau associatif de description du champ a inserer[nom du parameter][valeur du parameter] + * @param array{type:string,label:string,enabled:int|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string} $field_desc Tableau associatif de description du champ a inserer[nom du parameter][valeur du parameter] * @param string $field_position Optionnel ex.: "after champtruc" * @return int Return integer <0 if KO, >0 if OK */ From 2d0e57ce7cf8b4ba6df6623c9bc5c8a58748bc75 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Mar 2024 14:13:17 +0100 Subject: [PATCH 110/114] Fix test for pgsql --- htdocs/core/db/mysqli.class.php | 2 +- htdocs/core/db/pgsql.class.php | 2 +- test/phpunit/DoliDBTest.php | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index c1b7bdd487c..245eb650990 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -889,7 +889,7 @@ class DoliDBMysqli extends DoliDB $i++; } } - $sql .= implode(',', $sqlfields); + $sql .= implode(', ', $sqlfields); if ($primary_key != "") { $sql .= ",".$pk; } diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index 71ba5f5279a..0a32d49325e 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -1127,7 +1127,7 @@ class DoliDBPgsql extends DoliDB $i++; } } - $sql .= implode(',', $sqlfields); + $sql .= implode(', ', $sqlfields); if ($primary_key != "") { $sql .= ",".$pk; } diff --git a/test/phpunit/DoliDBTest.php b/test/phpunit/DoliDBTest.php index adafc6a676c..e2af4b7071c 100644 --- a/test/phpunit/DoliDBTest.php +++ b/test/phpunit/DoliDBTest.php @@ -66,11 +66,11 @@ class DoliDBTest extends CommonClassTest $res = $db->DDLDropTable($namedic); $columns = array( - 'rowid' => array('type' => 'integer', 'value' => 11, 'AUTO_INCREMENT PRIMARY KEY'), + 'rowid' => array('type' => 'integer', 'AUTO_INCREMENT PRIMARY KEY'), 'code' => array('type' => 'varchar', 'value' => 255, 'null'=>'NOT NULL'), 'label' => array('type' => 'varchar', 'value' => 255, 'null'=>'NOT NULL'), - 'position' => array('type' => 'integer', 'value' => 11, 'null'=>'NULL'), - 'use_default' => array('type' => 'varchar', 'value' => 11, 'default'=>'1'), + 'position' => array('type' => 'integer', 'null'=>'NULL'), + 'use_default' => array('type' => 'varchar', 'value' => 1, 'default'=>'1'), 'active' => array('type' => 'integer', 'value' => 3) ); $primaryKey = 'rowid'; From 7cbff76f9dce43c3bb4b28dd5f2654b4eb5cc893 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Mar 2024 14:48:03 +0100 Subject: [PATCH 111/114] Fix phpunit --- test/phpunit/DoliDBTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/phpunit/DoliDBTest.php b/test/phpunit/DoliDBTest.php index e2af4b7071c..5cc4cd695fe 100644 --- a/test/phpunit/DoliDBTest.php +++ b/test/phpunit/DoliDBTest.php @@ -71,7 +71,7 @@ class DoliDBTest extends CommonClassTest 'label' => array('type' => 'varchar', 'value' => 255, 'null'=>'NOT NULL'), 'position' => array('type' => 'integer', 'null'=>'NULL'), 'use_default' => array('type' => 'varchar', 'value' => 1, 'default'=>'1'), - 'active' => array('type' => 'integer', 'value' => 3) + 'active' => array('type' => 'integer') ); $primaryKey = 'rowid'; From 5121185541171380a7894e0355ee49af7ad19b79 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Mar 2024 15:00:54 +0100 Subject: [PATCH 112/114] Code readability --- htdocs/societe/notify/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/notify/card.php b/htdocs/societe/notify/card.php index e79ccda49a0..4962c150888 100644 --- a/htdocs/societe/notify/card.php +++ b/htdocs/societe/notify/card.php @@ -260,7 +260,7 @@ if ($result > 0) { // Add notification form //print load_fiche_titre($titlelist.' ('.$num.')', '', ''); $num = $nbtotalofrecords; - print_barre_liste($titlelist, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, empty($nbtotalofrecords) ? -1 : $nbtotalofrecords, 'email', 0, $newcardbutton, '', $limit, 0, 0, 1); + print_barre_liste($titlelist, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, (empty($nbtotalofrecords) ? -1 : $nbtotalofrecords), 'email', 0, $newcardbutton, '', $limit, 0, 0, 1); print '
    '; print ''; From 7290ffd1ab7206432319f8586161219afe60d314 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Mar 2024 15:57:45 +0100 Subject: [PATCH 113/114] Better support for postgesql --- htdocs/core/db/mysqli.class.php | 9 +++------ htdocs/core/db/pgsql.class.php | 19 ++++++++----------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index cd184db9a5c..7fc92bf23ff 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -869,11 +869,11 @@ class DoliDBMysqli extends DoliDB if (isset($field_desc['extra']) && $field_desc['extra'] !== '') { $sqlfields[$i] .= " ".$this->sanitize($field_desc['extra'], 0, 0, 1); } + if (!empty($primary_key) && $primary_key == $field_name) { + $sqlfields[$i] .= " AUTO_INCREMENT PRIMARY KEY"; // mysql instruction that will be converted by driver late + } $i++; } - if ($primary_key != "") { - $pk = "PRIMARY KEY(".$this->sanitize($primary_key).")"; - } if (is_array($unique_keys)) { $i = 0; @@ -890,9 +890,6 @@ class DoliDBMysqli extends DoliDB } } $sql .= implode(', ', $sqlfields); - if ($primary_key != "") { - $sql .= ",".$pk; - } if ($unique_keys != "") { $sql .= ",".implode(',', $sqluq); } diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index 5615ee37255..43facbe2a19 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -1086,13 +1086,13 @@ class DoliDBPgsql extends DoliDB foreach ($fields as $field_name => $field_desc) { $sqlfields[$i] = $this->sanitize($field_name)." "; $sqlfields[$i] .= $this->sanitize($field_desc['type']); - if (!is_null($field_desc['value']) && $field_desc['value'] !== '') { + if (isset($field_desc['value']) && $field_desc['value'] !== '') { $sqlfields[$i] .= "(".$this->sanitize($field_desc['value']).")"; } - if (!is_null($field_desc['attribute']) && $field_desc['attribute'] !== '') { + if (isset($field_desc['attribute']) && $field_desc['attribute'] !== '') { $sqlfields[$i] .= " ".$this->sanitize($field_desc['attribute']); } - if (!is_null($field_desc['default']) && $field_desc['default'] !== '') { + if (isset($field_desc['default']) && $field_desc['default'] !== '') { if (in_array($field_desc['type'], array('tinyint', 'smallint', 'int', 'double'))) { $sqlfields[$i] .= " DEFAULT ".((float) $field_desc['default']); } elseif ($field_desc['default'] == 'null' || $field_desc['default'] == 'CURRENT_TIMESTAMP') { @@ -1101,17 +1101,17 @@ class DoliDBPgsql extends DoliDB $sqlfields[$i] .= " DEFAULT '".$this->escape($field_desc['default'])."'"; } } - if (!is_null($field_desc['null']) && $field_desc['null'] !== '') { + if (isset($field_desc['null']) && $field_desc['null'] !== '') { $sqlfields[$i] .= " ".$this->sanitize($field_desc['null'], 0, 0, 1); } - if (!is_null($field_desc['extra']) && $field_desc['extra'] !== '') { + if (isset($field_desc['extra']) && $field_desc['extra'] !== '') { $sqlfields[$i] .= " ".$this->sanitize($field_desc['extra'], 0, 0, 1); } + if (!empty($primary_key) && $primary_key == $field_name) { + $sqlfields[$i] .= " AUTO_INCREMENT PRIMARY KEY"; // mysql instruction that will be converted by driver late + } $i++; } - if ($primary_key != "") { - $pk = "PRIMARY KEY(".$this->sanitize($primary_key).")"; - } if (is_array($unique_keys)) { $i = 0; @@ -1128,9 +1128,6 @@ class DoliDBPgsql extends DoliDB } } $sql .= implode(', ', $sqlfields); - if ($primary_key != "") { - $sql .= ",".$pk; - } if ($unique_keys != "") { $sql .= ",".implode(',', $sqluq); } From fd1322c095fab3eeb2bb44587f431a55a88b3e79 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Mar 2024 16:33:57 +0100 Subject: [PATCH 114/114] Fix warning --- htdocs/install/repair.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/htdocs/install/repair.php b/htdocs/install/repair.php index bf0b8cd6534..d9c5a808bb5 100644 --- a/htdocs/install/repair.php +++ b/htdocs/install/repair.php @@ -1534,12 +1534,12 @@ if ($ok && GETPOST('repair_link_dispatch_lines_supplier_order_lines')) { $first_iteration = false; } else { $sql_attach_values = array( - ((int) $obj_dispatch->fk_element), - ((int) $obj_dispatch->fk_product), - ((int) $obj_line->rowid), - ((float) $qty_for_line), - ((int) $obj_dispatch->fk_entrepot), - ((int) $obj_dispatch->fk_user), + (string) ((int) $obj_dispatch->fk_element), + (string) ((int) $obj_dispatch->fk_product), + (string) ((int) $obj_line->rowid), + (string) ((float) $qty_for_line), + (string) ((int) $obj_dispatch->fk_entrepot), + (string) ((int) $obj_dispatch->fk_user), $obj_dispatch->datec ? "'".$db->idate($db->jdate($obj_dispatch->datec))."'" : 'NULL', $obj_dispatch->comment ? "'".$db->escape($obj_dispatch->comment)."'" : 'NULL', $obj_dispatch->status ? (string) ((int) $obj_dispatch->status) : 'NULL', @@ -1552,7 +1552,7 @@ if ($ok && GETPOST('repair_link_dispatch_lines_supplier_order_lines')) { $sql_attach = 'INSERT INTO '.MAIN_DB_PREFIX.'receptiondet_batch'; $sql_attach .= ' (fk_element, fk_product, fk_elementdet, qty, fk_entrepot, fk_user, datec, comment, status, tms, batch, eatby, sellby)'; - $sql_attach .= " VALUES (".$sql_attach_values.")"; + $sql_attach .= " VALUES (".$sql_attach_values.")"; // The string is already sanitized } if ($repair_link_dispatch_lines_supplier_order_lines == 'confirmed') {