From 10a10f459cbd88b4f57e357ba8b57cc9e9148876 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 16 Jan 2017 01:23:43 +0100 Subject: [PATCH 1/6] Update ChangeLog --- ChangeLog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog b/ChangeLog index 798f3ef91f4..33390ca90c0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -151,6 +151,8 @@ Dolibarr better: no more required, were also removed. Use this new one if you were using one of them. - The trigger that activate or close a contract line is run on a contract line, not on contract. +Dolibarr 5.0 was frozen before PHP 7.1 was released. It is compatible with PHP 5.3 to 7.0 but not with PHP 7.1 (Dolibarr 6.0 will be). + ***** ChangeLog for 4.0.3 to 4.0.2 ***** FIX: #5853 $conf->global->$calc==0 || $conf->global->$calc==1 From a05132d26ef79f5581c6e3a179d89b6b335a93f0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 16 Jan 2017 00:53:59 +0100 Subject: [PATCH 2/6] Fix PHP 7.1 error --- htdocs/compta/bank/class/account.class.php | 2 +- htdocs/core/lib/bank.lib.php | 3 ++- htdocs/societe/class/companybankaccount.class.php | 7 ++++--- htdocs/societe/class/societe.class.php | 3 +-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 73dd2d4f199..0e9b25c39a8 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -662,7 +662,7 @@ class Account extends CommonObject * * @param User $user Object user making action * @param int $notrigger 1=Disable triggers - * @return int <0 si ko, >0 si ok + * @return int <0 if KO, >0 if OK */ function update(User $user = null, $notrigger = 0) { diff --git a/htdocs/core/lib/bank.lib.php b/htdocs/core/lib/bank.lib.php index 74078740080..1df180452c3 100644 --- a/htdocs/core/lib/bank.lib.php +++ b/htdocs/core/lib/bank.lib.php @@ -197,9 +197,10 @@ function checkBanForAccount($account) $rib = strtr($rib, "abcdefghijklmnopqrstuvwxyz", "12345678912345678923456789"); // Separation du rib en 3 groupes de 7 + 1 groupe de 2. // Multiplication de chaque groupe par les coef du tableau +var_dump($rib); for ($i = 0, $s = 0; $i < 3; $i++) { $code = substr($rib, 7 * $i, 7); - $s += (0 + $code) * $coef[$i]; + $s += (0 + (int) $code) * $coef[$i]; } // Soustraction du modulo 97 de $s a 97 pour obtenir la cle $cle_rib = 97 - ($s % 97); diff --git a/htdocs/societe/class/companybankaccount.class.php b/htdocs/societe/class/companybankaccount.class.php index e5d5eb5cc8f..46927e7bc64 100644 --- a/htdocs/societe/class/companybankaccount.class.php +++ b/htdocs/societe/class/companybankaccount.class.php @@ -102,10 +102,11 @@ class CompanyBankAccount extends Account /** * Update bank account * - * @param User $user Object user - * @return int <=0 if KO, >0 if OK + * @param User $user Object user + * @param int $notrigger 1=Disable triggers + * @return int <=0 if KO, >0 if OK */ - function update(User $user = null) + function update(User $user = null, $notrigger=0) { global $conf; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index fd3445375a9..9248a07469c 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1909,10 +1909,9 @@ class Societe extends CommonObject if (! empty($conf->accounting->enabled) && $this->fournisseur) $label.= '
' . $langs->trans('SupplierAccountancyCode') . ': '. $this->code_compta_fournisseur; - if (! empty($this->logo)) + if (! empty($this->logo) && class_exists('Form')) { $label.= '
'; - //if (! is_object($form)) $form = new Form($db); $label.= Form::showphoto('societe', $this, 80, 0, 0, 'photowithmargin', 'mini'); $label.= '
'; } From 36bd63c1a7b7292924e78aa6cb77ea060162a4c2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 16 Jan 2017 01:21:33 +0100 Subject: [PATCH 3/6] NEW PHP 7.1 compatibility --- htdocs/core/class/commonobject.class.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index fd15bdd5886..b75bc9e3d05 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3017,9 +3017,16 @@ abstract class CommonObject foreach ($this->lines as $line) { - - $totalOrdered+=$line->qty_asked; // defined for shipment only - $totalToShip+=$line->qty_shipped; // defined for shipment only + if (isset($line->qty_asked)) + { + if (empty($totalOrdered)) $totalOrdered=0; // Avoid warning because $totalOrdered is '' + $totalOrdered+=$line->qty_asked; // defined for shipment only + } + if (isset($line->qty_shipped)) + { + if (empty($totalToShip)) $totalToShip=0; // Avoid warning because $totalToShip is '' + $totalToShip+=$line->qty_shipped; // defined for shipment only + } // Define qty, weight, volume, weight_units, volume_units if ($this->element == 'shipping') $qty=$line->qty_shipped; // for shipments @@ -3034,8 +3041,11 @@ abstract class CommonObject if (! empty($weight_units)) $weightUnit = $weight_units; if (! empty($volume_units)) $volumeUnit = $volume_units; + if (empty($totalWeight)) $totalWeight=0; // Avoid warning because $totalWeight is '' + if (empty($totalVolume)) $totalVolume=0; // Avoid warning because $totalVolume is '' + //var_dump($line->volume_units); - if ($weight_units < 50) // >50 means a standard unit (power of 10 of official unit) > 50 means an exotic unit (like inch) + if ($weight_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) { $trueWeightUnit=pow(10, $weightUnit); $totalWeight += $weight * $qty * $trueWeightUnit; @@ -3044,7 +3054,7 @@ abstract class CommonObject { $totalWeight += $weight * $qty; // This may be wrong if we mix different units } - if ($volume_units < 50) // >50 means a standard unit (power of 10 of official unit) > 50 means an exotic unit (like inch) + if ($volume_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) { //print $line->volume."x".$line->volume_units."x".($line->volume_units < 50)."x".$volumeUnit; $trueVolumeUnit=pow(10, $volumeUnit); From ac80d4057d955b49984d8d70aa36f13fa85919c2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 16 Jan 2017 09:30:28 +0100 Subject: [PATCH 4/6] Fix several running time errors --- htdocs/core/lib/date.lib.php | 4 ++-- htdocs/core/lib/price.lib.php | 1 + htdocs/holiday/class/holiday.class.php | 14 ++++++++------ test/phpunit/MarginsLibTest.php | 1 - 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php index a0d61144582..cd897071551 100644 --- a/htdocs/core/lib/date.lib.php +++ b/htdocs/core/lib/date.lib.php @@ -175,7 +175,7 @@ function convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengt $sTime=''; $sDay=0; - $sWeek=''; + $sWeek=0; if ($iSecond >= $lengthOfDay) { @@ -218,7 +218,7 @@ function convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengt } if ($format == 'allhourmin') { - return sprintf("%02d",($sWeek*$lengthOfWeek*24 + $sDay*24 + (int) floor($iSecond/3600))).':'.sprintf("%02d",((int) floor(($iSecond % 3600)/60))); + return sprintf("%02d",($sWeek*$lengthOfWeek*24 + $sDay*24 + (int) floor($iSecond/3600))).':'.sprintf("%02d",((int) floor(($iSecond % 3600)/60))); } if ($format == 'allhour') { diff --git a/htdocs/core/lib/price.lib.php b/htdocs/core/lib/price.lib.php index e94c0c7dcfe..2fe652f6ac9 100644 --- a/htdocs/core/lib/price.lib.php +++ b/htdocs/core/lib/price.lib.php @@ -80,6 +80,7 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocalt $result=array(); // Clean parameters + if (empty($info_bits)) $info_bits=0; if (empty($txtva)) $txtva=0; if (empty($seller) || ! is_object($seller)) { diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php index 78bc1582a65..10534082b9e 100644 --- a/htdocs/holiday/class/holiday.class.php +++ b/htdocs/holiday/class/holiday.class.php @@ -127,7 +127,8 @@ class Holiday extends CommonObject // Check parameters if (empty($this->fk_user) || ! is_numeric($this->fk_user) || $this->fk_user < 0) { $this->error="ErrorBadParameter"; return -1; } if (empty($this->fk_validator) || ! is_numeric($this->fk_validator) || $this->fk_validator < 0) { $this->error="ErrorBadParameter"; return -1; } - + if (empty($this->fk_type) || ! is_numeric($this->fk_type) || $this->fk_type < 0) { $this->error="ErrorBadParameter"; return -1; } + // Insert request $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday("; $sql.= "fk_user,"; @@ -150,7 +151,7 @@ class Holiday extends CommonObject $sql.= " ".$this->halfday.","; $sql.= " '1',"; $sql.= " '".$this->fk_validator."',"; - $sql.= " '".$this->fk_type."',"; + $sql.= " ".$this->fk_type.","; $sql.= " ".$user->id.","; $sql.= " ".$conf->entity; $sql.= ")"; @@ -281,7 +282,7 @@ class Holiday extends CommonObject $sql = "SELECT"; $sql.= " cp.rowid,"; - + $sql.= " cp.fk_user,"; $sql.= " cp.date_create,"; $sql.= " cp.description,"; @@ -868,7 +869,7 @@ class Holiday extends CommonObject { $sql = "SELECT value"; $sql.= " FROM ".MAIN_DB_PREFIX."holiday_config"; - $sql.= " WHERE name = '".$name."'"; + $sql.= " WHERE name = '".$this->db->escape($name)."'"; dol_syslog(get_class($this).'::getConfCP name='.$name.' createifnotfound='.$createifnotfound, LOG_DEBUG); $result = $this->db->query($sql); @@ -882,7 +883,7 @@ class Holiday extends CommonObject if ($createifnotfound) { $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_config(name, value)"; - $sql.= " VALUES('".$name."', '".$createifnotfound."')"; + $sql.= " VALUES('".$this->db->escape($name)."', '".$this->db->escape($createifnotfound)."')"; $result = $this->db->query($sql); if ($result) { @@ -947,7 +948,7 @@ class Holiday extends CommonObject $nbUser = count($users); $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET"; - $sql.= " value = '".$newdateforlastupdate."'"; + $sql.= " value = '".$this->db->escape($newdateforlastupdate)."'"; $sql.= " WHERE name = 'lastUpdate'"; $result = $this->db->query($sql); @@ -1634,6 +1635,7 @@ class Holiday extends CommonObject $this->date_fin=dol_now()+(24*3600); $this->fk_validator=1; $this->halfday=0; + $this->fk_type=1; } } diff --git a/test/phpunit/MarginsLibTest.php b/test/phpunit/MarginsLibTest.php index 7c2e8f68ef6..e6f130d2e3b 100644 --- a/test/phpunit/MarginsLibTest.php +++ b/test/phpunit/MarginsLibTest.php @@ -138,7 +138,6 @@ class MarginsLibTest extends PHPUnit_Framework_TestCase $this->assertEquals(20,$result[2]); $result=getMarginInfos(10, 10, 19.6, 0, 0, 0, 8); - var_dump($result); print __METHOD__." result[0]=".$result[0]."\n"; $this->assertEquals(8,$result[0]); print __METHOD__." result[1]=".$result[1]."\n"; From f36dea5be7bcd993ca0a94eb30750d6ce87470dc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 16 Jan 2017 09:30:00 +0100 Subject: [PATCH 5/6] Fix holiday class Conflicts: htdocs/holiday/class/holiday.class.php --- 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 10534082b9e..e69fd312f45 100644 --- a/htdocs/holiday/class/holiday.class.php +++ b/htdocs/holiday/class/holiday.class.php @@ -127,7 +127,7 @@ class Holiday extends CommonObject // Check parameters if (empty($this->fk_user) || ! is_numeric($this->fk_user) || $this->fk_user < 0) { $this->error="ErrorBadParameter"; return -1; } if (empty($this->fk_validator) || ! is_numeric($this->fk_validator) || $this->fk_validator < 0) { $this->error="ErrorBadParameter"; return -1; } - if (empty($this->fk_type) || ! is_numeric($this->fk_type) || $this->fk_type < 0) { $this->error="ErrorBadParameter"; return -1; } + if (empty($this->fk_type) || ! is_numeric($this->fk_type) || $this->fk_type < 0) { $this->error="ErrorBadParameter"; return -1; } // Insert request $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday("; From d2b766f9f45c5353436893ab4761f984a73e77a6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 16 Jan 2017 10:15:57 +0100 Subject: [PATCH 6/6] Fix PHP 7.1 --- .travis.yml | 2 +- ChangeLog | 3 ++- htdocs/user/card.php | 6 +++--- htdocs/user/class/user.class.php | 2 +- test/phpunit/WebservicesUserTest.php | 8 ++++---- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index a9e47ccb9c6..4f32a1dea43 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ php: - '5.5' - '5.6' - '7.0' -#- '7.1' +- '7.1' - nightly addons: diff --git a/ChangeLog b/ChangeLog index 33390ca90c0..87e7f4ba18b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -151,7 +151,8 @@ Dolibarr better: no more required, were also removed. Use this new one if you were using one of them. - The trigger that activate or close a contract line is run on a contract line, not on contract. -Dolibarr 5.0 was frozen before PHP 7.1 was released. It is compatible with PHP 5.3 to 7.0 but not with PHP 7.1 (Dolibarr 6.0 will be). +Dolibarr 5.0 was frozen before PHP 7.1 was released. Unit tests are successful on PHP 7.1 but we don't have enough +feedback to confirm all application is compatible. Current officiel supported PHP versions are PHP 5.3 to 7.0. ***** ChangeLog for 4.0.3 to 4.0.2 ***** diff --git a/htdocs/user/card.php b/htdocs/user/card.php index 8b5ab723bd3..e7614f06f9d 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -1090,9 +1090,9 @@ if (($action == 'create') || ($action == 'adduserldap')) // Categories if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) { - print '' . fieldLabel( 'Categories', 'usercats' ) . ''; - $cate_arbo = $form->select_all_categories( Categorie::TYPE_USER, null, 'parent', null, null, 1 ); - print $form->multiselectarray( 'usercats', $cate_arbo, GETPOST( 'usercats', 'array' ), null, null, null, + print '' . fieldLabel('Categories', 'usercats') . ''; + $cate_arbo = $form->select_all_categories('user', null, 'parent', null, null, 1); + print $form->multiselectarray('usercats', $cate_arbo, GETPOST('usercats', 'array'), null, null, null, null, '90%' ); print ""; } diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 5f44e675ece..ee76525a6ae 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -330,7 +330,7 @@ class User extends CommonObject } else { - $this->error=$this->db->error(); + $this->error=$this->db->lasterror(); return -1; } diff --git a/test/phpunit/WebservicesUserTest.php b/test/phpunit/WebservicesUserTest.php index 9be97167104..78d3d311fe0 100644 --- a/test/phpunit/WebservicesUserTest.php +++ b/test/phpunit/WebservicesUserTest.php @@ -154,7 +154,7 @@ class WebservicesUserTest extends PHPUnit_Framework_TestCase // Test URL $result=''; - $parameters = array('authentication'=>$authentication,'ref'=>'admin'); + $parameters = array('authentication'=>$authentication,'id'=>0,'ref'=>'admin'); print __METHOD__."Call method ".$WS_METHOD."\n"; try { $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); @@ -177,11 +177,11 @@ class WebservicesUserTest extends PHPUnit_Framework_TestCase } print __METHOD__." result=".$result."\n"; - $this->assertEquals('OK',$result['result']['result_code']); + $this->assertEquals('OK', $result['result']['result_code'], 'Test on ref admin'); // Test URL $result=''; - $parameters = array('authentication'=>$authentication,'ref'=>'refthatdoesnotexists'); + $parameters = array('authentication'=>$authentication,'id'=>0,'ref'=>'refthatdoesnotexists'); print __METHOD__."Call method ".$WS_METHOD."\n"; try { $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); @@ -200,7 +200,7 @@ class WebservicesUserTest extends PHPUnit_Framework_TestCase } print __METHOD__." result=".$result."\n"; - $this->assertEquals('NOT_FOUND',$result['result']['result_code']); + $this->assertEquals('NOT_FOUND', $result['result']['result_code'], 'Test on ref that does not exists'); return $result; }