From 89f1b2f608e8e098dc6069aca074717046b20fcf Mon Sep 17 00:00:00 2001 From: ldestailleur Date: Mon, 28 Jul 2025 18:55:03 +0200 Subject: [PATCH 1/3] Fix CI --- htdocs/core/lib/ftp.lib.php | 71 +++++++++++++++---------------------- 1 file changed, 28 insertions(+), 43 deletions(-) diff --git a/htdocs/core/lib/ftp.lib.php b/htdocs/core/lib/ftp.lib.php index 245953cec8f..96e4caf9996 100644 --- a/htdocs/core/lib/ftp.lib.php +++ b/htdocs/core/lib/ftp.lib.php @@ -1,7 +1,7 @@ +/* Copyright (C) 2022-2025 Laurent Destailleur * Copyright (C) 2022 Anthony Berton - * Copyright (C) 2024 MDW + * 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 @@ -34,7 +34,7 @@ * @param string $ftp_password FTP password * @param string $section Directory * @param integer $ftp_passive Use a passive mode - * @return array Result of connect + * @return array{conn_id:false|null|resource,ok:int<0,1>,mesg:string,curdir:string,curdiriso:string} Result of connect */ function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive = 0) { @@ -53,6 +53,7 @@ function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $sect if ($ok) { $connecttimeout = (!getDolGlobalString('FTP_CONNECT_TIMEOUT') ? 40 : $conf->global->FTP_CONNECT_TIMEOUT); + $tmp_conn_id = 0; if (getDolGlobalString('FTP_CONNECT_WITH_SFTP')) { dol_syslog('Try to connect with ssh2_connect'); $tmp_conn_id = ssh2_connect($ftp_server, (int) $ftp_port); @@ -67,7 +68,7 @@ function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $sect if ($ftp_user) { if (getDolGlobalString('FTP_CONNECT_WITH_SFTP')) { dol_syslog('Try to authenticate with ssh2_auth_password'); - if (ssh2_auth_password($tmp_conn_id, $ftp_user, $ftp_password)) { + if (!empty($tmp_conn_id) && ssh2_auth_password($tmp_conn_id, $ftp_user, $ftp_password)) { // Turn on passive mode transfers (must be after a successful login //if ($ftp_passive) ftp_pasv($connect_id, true); @@ -88,7 +89,7 @@ function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $sect $error++; } } else { - if (ftp_login($connect_id, $ftp_user, $ftp_password)) { + if (!empty($connect_id) && ftp_login($connect_id, $ftp_user, $ftp_password)) { // Turn on passive mode transfers (must be after a successful login) if ($ftp_passive) { ftp_pasv($connect_id, true); @@ -121,9 +122,9 @@ function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $sect /** * Tell if an entry is a FTP directory * - * @param resource $connect_id Connection handler - * @param string $dir Directory - * @return int 1=directory, 0=not a directory + * @param resource|FTP\Connection $connect_id Connection handler + * @param string $dir Directory + * @return int 1=directory, 0=not a directory */ function ftp_isdir($connect_id, $dir) { @@ -138,13 +139,11 @@ function ftp_isdir($connect_id, $dir) /** * Tell if an entry is a FTP directory * - * @param resource $connect_id Connection handler - * @return boolean Result of closing + * @param resource|FTP\Connection $connect_id Connection handler + * @return boolean Result of closing */ function dol_ftp_close($connect_id) { - global $conf; - // Close FTP connection if ($connect_id) { if (!getDolGlobalString('FTP_CONNECT_WITH_SFTP')) { @@ -157,21 +156,18 @@ function dol_ftp_close($connect_id) /** * Delete a FTP file * - * @param resource $connect_id Connection handler - * @param string $file File - * @param string $newsection $newsection + * @param resource|FTP\Connection $connect_id Connection handler + * @param string $file File + * @param string $newsection Directory * @return bool */ function dol_ftp_delete($connect_id, $file, $newsection) { - global $conf; - if (getDolGlobalString('FTP_CONNECT_WITH_SFTP')) { $newsection = ssh2_sftp_realpath($connect_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169 } // Remote file - $filename = $file; $remotefile = $newsection.(preg_match('@[\\\/]$@', $newsection) ? '' : '/').$file; $newremotefileiso = mb_convert_encoding($remotefile, 'ISO-8859-1'); @@ -187,22 +183,19 @@ function dol_ftp_delete($connect_id, $file, $newsection) /** * Download a FTP file * - * @param resource $connect_id Connection handler - * @param string $localfile The local file path - * @param string $file The remote file path - * @param string $newsection $newsection + * @param resource|FTP\Connection $connect_id Connection handler + * @param string $localfile The local file path + * @param string $file The remote file path + * @param string $newsection Directory * @return bool|resource */ function dol_ftp_get($connect_id, $localfile, $file, $newsection) { - global $conf; - if (getDolGlobalString('FTP_CONNECT_WITH_SFTP')) { $newsection = ssh2_sftp_realpath($connect_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169 } // Remote file - $filename = $file; $remotefile = $newsection.(preg_match('@[\\\/]$@', $newsection) ? '' : '/').$file; $newremotefileiso = mb_convert_encoding($remotefile, 'ISO-8859-1'); @@ -216,22 +209,19 @@ function dol_ftp_get($connect_id, $localfile, $file, $newsection) /** * Upload a FTP file * - * @param resource $connect_id Connection handler - * @param string $file File name - * @param string $localfile The path to the local file - * @param string $newsection $newsection + * @param resource|FTP\Connection $connect_id Connection handler + * @param string $file File name + * @param string $localfile The path to the local file + * @param string $newsection Directory * @return bool */ function dol_ftp_put($connect_id, $file, $localfile, $newsection) { - global $conf; - if (getDolGlobalString('FTP_CONNECT_WITH_SFTP')) { $newsection = ssh2_sftp_realpath($connect_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169 } // Remote file - $filename = $file; $remotefile = $newsection.(preg_match('@[\\\/]$@', $newsection) ? '' : '/').$file; $newremotefileiso = mb_convert_encoding($remotefile, 'ISO-8859-1'); @@ -245,21 +235,18 @@ function dol_ftp_put($connect_id, $file, $localfile, $newsection) /** * Remove FTP directory * - * @param resource $connect_id Connection handler - * @param string $file File - * @param string $newsection $newsection + * @param resource|FTP\Connection $connect_id Connection handler + * @param string $file File + * @param string $newsection Directory * @return bool */ function dol_ftp_rmdir($connect_id, $file, $newsection) { - global $conf; - if (getDolGlobalString('FTP_CONNECT_WITH_SFTP')) { $newsection = ssh2_sftp_realpath($connect_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169 } // Remote file - $filename = $file; $remotefile = $newsection.(preg_match('@[\\\/]$@', $newsection) ? '' : '/').$file; $newremotefileiso = mb_convert_encoding($remotefile, 'ISO-8859-1'); @@ -274,15 +261,13 @@ function dol_ftp_rmdir($connect_id, $file, $newsection) /** * Remove FTP directory * - * @param resource $connect_id Connection handler - * @param string $newdir Dir create - * @param string $newsection $newsection + * @param resource|FTP\Connection $connect_id Connection handler + * @param string $newdir Dir create + * @param string $newsection Directory * @return bool|string */ function dol_ftp_mkdir($connect_id, $newdir, $newsection) { - global $conf; - if (getDolGlobalString('FTP_CONNECT_WITH_SFTP')) { $newsection = ssh2_sftp_realpath($connect_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169 } From ae8e509c9f8cb00d8cc6166b91a08425bff1b543 Mon Sep 17 00:00:00 2001 From: ldestailleur Date: Mon, 28 Jul 2025 18:59:12 +0200 Subject: [PATCH 2/3] Fix CI --- htdocs/core/class/commonobject.class.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 3bcc8151584..7e513eb2bc1 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -9383,7 +9383,7 @@ abstract class CommonObject * @param float $unitPrice Product unit price * @param float $discountPercent Line discount percent * @param int $fk_product Product id - * @return float|int<-1,-1> Return buy price if OK, integer <0 if KO + * @return float|int<-2,-1> Return buy price if OK, integer <0 if KO */ public function defineBuyPrice($unitPrice = 0.0, $discountPercent = 0.0, $fk_product = 0) { @@ -9436,7 +9436,8 @@ abstract class CommonObject } } } - return $buyPrice; + + return (float) $buyPrice; } /** From 11abac15324ca36ed3edeac5653e5ccd9f1ca1f1 Mon Sep 17 00:00:00 2001 From: ldestailleur Date: Mon, 28 Jul 2025 19:01:18 +0200 Subject: [PATCH 3/3] Fix CI --- htdocs/compta/facture/class/api_invoices.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 398c408f3b9..10df6b85f18 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -1622,14 +1622,14 @@ class Invoices extends DolibarrApi $totalpaid = $this->invoice->getSommePaiement($is_multicurrency); $totalcreditnotes = $this->invoice->getSumCreditNotesUsed($is_multicurrency); $totaldeposits = $this->invoice->getSumDepositsUsed($is_multicurrency); - $remainstopay = $amount = price2num($total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits, 'MT'); + $remainstopay = $amount = (float) price2num($total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits, 'MT'); if (!$is_multicurrency && $amountarray["amount"] != 'remain') { - $amount = price2num($amountarray["amount"], 'MT'); + $amount = (float) price2num($amountarray["amount"], 'MT'); } if ($is_multicurrency && $amountarray["multicurrency_amount"] != 'remain') { - $amount = price2num($amountarray["multicurrency_amount"], 'MT'); + $amount = (float) price2num($amountarray["multicurrency_amount"], 'MT'); } if (abs($amount) > abs($remainstopay) && !$accepthigherpayment) { @@ -1638,7 +1638,7 @@ class Invoices extends DolibarrApi } if ($this->invoice->type == Facture::TYPE_CREDIT_NOTE) { - $amount = price2num(-1 * abs((float) $amount), 'MT'); + $amount = (float) price2num(-1 * abs((float) $amount), 'MT'); } if ($is_multicurrency) {