From bc71380410178d2ffa191a4f268cf2113e4ef898 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 9 Sep 2023 21:16:58 +0200 Subject: [PATCH] Fix sql errors --- .travis.yml | 7 ++++++- htdocs/compta/bank/class/account.class.php | 9 +++++---- htdocs/societe/class/companybankaccount.class.php | 8 +++----- test/phpunit/BankAccountTest.php | 4 ++-- test/phpunit/SecurityTest.php | 3 +++ 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 93de22b04a8..34aecc1c68c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -373,6 +373,7 @@ script: echo '$'force_install_mainforcehttps=false';' >> $INSTALL_FORCED_FILE echo '$'force_install_main_data_root=\'$TRAVIS_BUILD_DIR/htdocs\'';' >> $INSTALL_FORCED_FILE #cat $INSTALL_FORCED_FILE + echo - | echo "Upgrading Dolibarr" @@ -441,12 +442,14 @@ script: php upgrade.php 18.0.0 19.0.0 ignoredbversion > $TRAVIS_BUILD_DIR/upgrade18001900.log || cat $TRAVIS_BUILD_DIR/upgrade18001900.log php upgrade2.php 18.0.0 19.0.0 > $TRAVIS_BUILD_DIR/upgrade18001900-2.log || cat $TRAVIS_BUILD_DIR/upgrade18001900-2.log php step5.php 18.0.0 19.0.0 > $TRAVIS_BUILD_DIR/upgrade18001900-3.log || cat $TRAVIS_BUILD_DIR/upgrade18001900-3.log - set -e + set +e + echo - | echo Show some debug info like table content or log #echo '\d llx_adherent' | psql 'postgresql://postgres:postgres@127.0.0.1:5432/travis' cat $TRAVIS_BUILD_DIR/upgrade18001900.log + echo - | echo Result of migration scripts @@ -470,6 +473,7 @@ script: echo #cat /tmp/dolibarr_install.log cat $TRAVIS_BUILD_DIR/enablemodule.log + echo - | echo "Unit testing" @@ -479,6 +483,7 @@ script: phpunitresult=$? echo "Phpunit return code = $phpunitresult" set +e + echo after_script: - | diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 3a390e51b5e..7885b030b1f 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -701,7 +701,7 @@ class Account extends CommonObject return -1; } - // Chargement librairie pour acces fonction controle RIB + // Load librairies to check BAN require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php'; $now = dol_now(); @@ -778,13 +778,13 @@ class Account extends CommonObject $result = $this->update($user, 1); if ($result > 0) { $accline = new AccountLine($this->db); - $accline->datec = $this->db->idate($now); + $accline->datec = $now; $accline->label = '('.$langs->trans("InitialBankBalance").')'; $accline->amount = price2num($this->solde); $accline->fk_user_author = $user->id; $accline->fk_account = $this->id; - $accline->datev = $this->db->idate($this->date_solde); - $accline->dateo = $this->db->idate($this->date_solde); + $accline->datev = $this->date_solde; + $accline->dateo = $this->date_solde; $accline->fk_type = 'SOLD'; if ($accline->insert() < 0) { @@ -2131,6 +2131,7 @@ class AccountLine extends CommonObjectLine $sql .= ", ".($this->num_releve ? "'".$this->db->escape($this->num_releve)."'" : "null"); $sql .= ")"; + dol_syslog(get_class($this)."::insert", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { diff --git a/htdocs/societe/class/companybankaccount.class.php b/htdocs/societe/class/companybankaccount.class.php index 0b0eeac8d9c..b1b487bbf03 100644 --- a/htdocs/societe/class/companybankaccount.class.php +++ b/htdocs/societe/class/companybankaccount.class.php @@ -282,11 +282,9 @@ class CompanyBankAccount extends Account $this->db->begin(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_rib (fk_soc, type, datec"; - $sql .= ", model_pdf"; - $sql .= ")"; - $sql .= " VALUES (".((int) $this->socid).", '".$this->type."', '".$this->db->idate($this->datec)."'"; - $sql .= ",\"".$this->db->escape(getDolGlobalString("BANKADDON_PDF"))."\""; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_rib (fk_soc, type, datec, model_pdf)"; + $sql .= " VALUES (".((int) $this->socid).", '".$this->type."', '".$this->db->idate($this->datec)."',"; + $sql .= " '".$this->db->escape(getDolGlobalString("BANKADDON_PDF"))."'"; $sql .= ")"; $resql = $this->db->query($sql); if ($resql) { diff --git a/test/phpunit/BankAccountTest.php b/test/phpunit/BankAccountTest.php index 8a900f5768f..b78b473d435 100644 --- a/test/phpunit/BankAccountTest.php +++ b/test/phpunit/BankAccountTest.php @@ -143,9 +143,9 @@ class BankAccountTest extends PHPUnit\Framework\TestCase $langs=$this->savlangs; $db=$this->savdb; - $localobject=new Account($db); + $localobject = new Account($db); $localobject->initAsSpecimen(); - $localobject->date_solde=dol_now(); + $localobject->date_solde = dol_now(); $result=$localobject->create($user); print __METHOD__." result=".$result."\n"; diff --git a/test/phpunit/SecurityTest.php b/test/phpunit/SecurityTest.php index 85cf4b443df..d4d45837e74 100644 --- a/test/phpunit/SecurityTest.php +++ b/test/phpunit/SecurityTest.php @@ -126,6 +126,9 @@ class SecurityTest extends PHPUnit\Framework\TestCase global $conf,$user,$langs,$db; $db->rollback(); + // Restore value to a neutral value (it was set to a test value by some tests) + unset($_SERVER["PHP_SELF"]); + print __METHOD__."\n"; }