From 706ee8ce6236e3de47a3b148a0bed57706ae170b Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Tue, 28 Dec 2021 16:26:21 +0100 Subject: [PATCH 1/5] Fix #19662 : mysql8 user creation in 2 steps --- htdocs/core/db/mysqli.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index 3a8aabd3bf9..c733792b6b6 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -939,7 +939,7 @@ class DoliDBMysqli extends DoliDB public function DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name) { // phpcs:enable - $sql = "CREATE USER '".$this->escape($dolibarr_main_db_user)."'"; + $sql = "CREATE USER '".$this->escape($dolibarr_main_db_user)."'@'".$this->escape($dolibarr_main_db_host)."' IDENTIFIED BY '".$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) { @@ -952,14 +952,14 @@ class DoliDBMysqli extends DoliDB } // Redo with localhost forced (sometimes user is created on %) - $sql = "CREATE USER '".$this->escape($dolibarr_main_db_user)."'@'localhost'"; + $sql = "CREATE USER '".$this->escape($dolibarr_main_db_user)."'@'localhost' IDENTIFIED BY '".$this->escape($dolibarr_main_db_pass)."'"; $resql = $this->query($sql); - $sql = "GRANT ALL PRIVILEGES ON ".$this->escape($dolibarr_main_db_name).".* TO '".$this->escape($dolibarr_main_db_user)."'@'".$this->escape($dolibarr_main_db_host)."' IDENTIFIED BY '".$this->escape($dolibarr_main_db_pass)."'"; + $sql = "GRANT ALL PRIVILEGES ON ".$this->escape($dolibarr_main_db_name).".* TO '".$this->escape($dolibarr_main_db_user)."'@'".$this->escape($dolibarr_main_db_host)."'"; dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log $resql = $this->query($sql); if (!$resql) { - $this->error = "Connected user not allowed to GRANT ALL PRIVILEGES ON ".$this->escape($dolibarr_main_db_name).".* TO '".$this->escape($dolibarr_main_db_user)."'@'".$this->escape($dolibarr_main_db_host)."' IDENTIFIED BY '*****'"; + $this->error = "Connected user not allowed to GRANT ALL PRIVILEGES ON ".$this->escape($dolibarr_main_db_name).".* TO '".$this->escape($dolibarr_main_db_user)."'@'".$this->escape($dolibarr_main_db_host)."'"; return -1; } From 732b1ab5489520dea4aa42921100443d75890a9c Mon Sep 17 00:00:00 2001 From: jpb Date: Tue, 29 Mar 2022 14:31:17 +0200 Subject: [PATCH 2/5] add trigger update and delete on expense report det add class name on card.php expensereport --- htdocs/expensereport/card.php | 21 +++++------ .../class/expensereport.class.php | 35 +++++++++++++++---- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index 9d9eebae245..b87991f7cd2 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -2265,7 +2265,7 @@ if ($action == 'create') { print $numline; print ''; - print ''; + print ' '; print ''.$langs->trans("UploadANewFileNow"); print img_picto($langs->trans("UploadANewFileNow"), 'chevron-down', '', false, 0, 0, '', 'marginleftonly'); print ''; @@ -2387,6 +2387,7 @@ if ($action == 'create') { print ''; print ''; + } $i++; @@ -2501,19 +2502,19 @@ if ($action == 'create') { print ''; // Select date - print ''; + print ''; print $form->selectDate($date ? $date : -1, 'date', 0, 0, 0, '', 1, 1); print ''; // Select project if (!empty($conf->projet->enabled)) { - print ''; + print ''; $formproject->select_projects(-1, $fk_project, 'fk_project', 0, 0, $projectRequired ? 0 : 1, -1, 0, 0, 0, '', 0, 0, 'maxwidth300'); print ''; } // Select type - print ''; + print ''; print $formexpensereport->selectTypeExpenseReport($fk_c_type_fees, 'fk_c_type_fees', 1); print ''; @@ -2525,12 +2526,12 @@ if ($action == 'create') { } // Add comments - print ''; + print ''; print ''; print ''; // Select VAT - print ''; + print ''; $defaultvat = -1; if (!empty($conf->global->EXPENSEREPORT_NO_DEFAULT_VAT)) { $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS = 'none'; @@ -2539,17 +2540,17 @@ if ($action == 'create') { print ''; // Unit price net - print ''; + print ''; print ''; print ''; // Unit price with tax - print ''; + print ''; print ''; print ''; // Quantity - print ''; + print ''; print ''; // We must be able to enter decimal qty print ''; @@ -2561,7 +2562,7 @@ if ($action == 'create') { print ''; } - print ''; + print ''; print $form->buttonsSaveCancel("Add", '', '', 1); print ''; diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index f2f0b7dbf0d..24d56b0c0b7 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -2063,7 +2063,7 @@ class ExpenseReport extends CommonObject * @param int $fk_ecm_files Id of ECM file to link to this expensereport line * @return int <0 if KO, >0 if OK */ - public function updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $expensereport_id, $fk_c_exp_tax_cat = 0, $fk_ecm_files = 0) + public function updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $expensereport_id, $fk_c_exp_tax_cat = 0, $fk_ecm_files = 0, $notrigger = 0) { global $user, $mysoc; @@ -2153,9 +2153,19 @@ class ExpenseReport extends CommonObject $this->applyOffset(); $this->checkRules(); - + $error = 0; $result = $this->line->update($user); - if ($result > 0) { + + if ($result > 0 && !$notrigger) { + // Call triggers + $result = $this->call_trigger('EXPENSE_REPORT_DET_UPDATE', $user); + if ($result < 0) { + $error++; + } + // End call triggers + } + + if ($result > 0 && $error == 0) { $this->db->commit(); return 1; } else { @@ -2174,16 +2184,29 @@ class ExpenseReport extends CommonObject * @param User $fuser User * @return int <0 if KO, >0 if OK */ - public function deleteline($rowid, $fuser = '') + public function deleteline($rowid, $fuser = '', $notrigger = 0) { + $error=0; + $this->db->begin(); - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element_line; + if (!$notrigger) { + // Call triggers + $result = $this->call_trigger('EXPENSE_REPORT_DET_DELETE', $fuser); + if ($result < 0) { + $error++; + } + // End call triggers + } + + + $sql = ' DELETE FROM '.MAIN_DB_PREFIX.$this->table_element_line; $sql .= ' WHERE rowid = '.((int) $rowid); dol_syslog(get_class($this)."::deleteline sql=".$sql); $result = $this->db->query($sql); - if (!$result) { + + if (!$result || $error > 0 ) { $this->error = $this->db->error(); dol_syslog(get_class($this)."::deleteline Error ".$this->error, LOG_ERR); $this->db->rollback(); From 147f1b9a0c0ca76296f46b95995a3c05b01da050 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 29 Mar 2022 12:39:13 +0000 Subject: [PATCH 3/5] Fixing style errors. --- htdocs/expensereport/card.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index b87991f7cd2..7696e8c9807 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -2387,7 +2387,6 @@ if ($action == 'create') { print ''; print ''; - } $i++; From 4e9c7afc01acfc68c74ca7c7f4707e95076d1137 Mon Sep 17 00:00:00 2001 From: jpb Date: Tue, 29 Mar 2022 15:54:49 +0200 Subject: [PATCH 4/5] add td --- htdocs/expensereport/card.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index 7696e8c9807..5ffef81e4c0 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -2493,6 +2493,8 @@ if ($action == 'create') { print ''; print ''; print ''; + print ''; + print ''; print ''; print ''; From cd81312b6af0433f441885e2e34efbef73efd33a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 31 Mar 2022 16:04:28 +0200 Subject: [PATCH 5/5] Update mysqli.class.php --- htdocs/core/db/mysqli.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index c733792b6b6..e500708f96a 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -939,7 +939,7 @@ class DoliDBMysqli extends DoliDB public function DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name) { // phpcs:enable - $sql = "CREATE USER '".$this->escape($dolibarr_main_db_user)."'@'".$this->escape($dolibarr_main_db_host)."' IDENTIFIED BY '".$this->escape($dolibarr_main_db_pass)."'"; + $sql = "CREATE USER '".$this->escape($dolibarr_main_db_user)."' IDENTIFIED BY '".$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) {