From 6cf15c70ac908f8a5e25430b8951c2da75008458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 19 Feb 2025 14:15:05 +0100 Subject: [PATCH 1/5] fix CI --- htdocs/accountancy/bookkeeping/list.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index 7dff65c8697..7ccdfc2354d 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -4,7 +4,7 @@ * Copyright (C) 2013-2024 Alexandre Spangaro * Copyright (C) 2022 Lionel Vessiller * Copyright (C) 2016-2017 Laurent Destailleur - * Copyright (C) 2018-2024 Frédéric France + * Copyright (C) 2018-2025 Frédéric France * Copyright (C) 2022 Progiseize * Copyright (C) 2024 MDW * @@ -81,7 +81,7 @@ $search_date_export_start = GETPOSTDATE('search_date_export_start', 'getpost'); $search_date_export_end = GETPOSTDATE('search_date_export_end', 'getpostend'); $search_date_validation_start = GETPOSTDATE('search_date_validation_start', 'getpost'); -$search_date_validation_start = GETPOSTDATE('search_date_validation_end', 'getpostend'); +$search_date_validation_end = GETPOSTDATE('search_date_validation_end', 'getpostend'); // Due date start $search_date_due_start_day = GETPOSTINT('search_date_due_start_day'); From e0d459a1b2bcb0e74b7e9bd32d5acd6f734264cd Mon Sep 17 00:00:00 2001 From: VESSILLER Date: Wed, 19 Feb 2025 14:41:37 +0100 Subject: [PATCH 2/5] QUAL use one var to determine if sell-by or eat-by date is enabled --- htdocs/expedition/dispatch.php | 47 ++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/htdocs/expedition/dispatch.php b/htdocs/expedition/dispatch.php index 0df964b4214..4dd2665a0a0 100644 --- a/htdocs/expedition/dispatch.php +++ b/htdocs/expedition/dispatch.php @@ -56,7 +56,10 @@ if (isModEnabled('project')) { // Load translation files required by the page $langs->loadLangs(array("sendings", "companies", "bills", 'deliveries', 'orders', 'stocks', 'other', 'propal', 'receptions')); -if (isModEnabled('productbatch')) { +$is_mod_batch_enabled = isModEnabled('productbatch'); +$is_eat_by_enabled = !getDolGlobalInt('PRODUCT_DISABLE_EATBY'); +$is_sell_by_enabled = !getDolGlobalInt('PRODUCT_DISABLE_SELLBY'); +if ($is_mod_batch_enabled) { $langs->load('productbatch'); } @@ -531,7 +534,7 @@ if ($object->id > 0 || !empty($object->ref)) { print ''; print '
'; - if (isModEnabled('barcode') || isModEnabled('productbatch')) { + if (isModEnabled('barcode') || $is_mod_batch_enabled) { print ''.img_picto('', 'barcode', 'class="paddingrightonly"').$langs->trans("UpdateByScaning").''; } print ''.img_picto("", 'autofill', 'class="pictofixedwidth"').$langs->trans("RestoreWithCurrentQtySaved").''; @@ -634,12 +637,12 @@ if ($object->id > 0 || !empty($object->ref)) { print ''; print ''.$langs->trans("Description").''; - if (isModEnabled('productbatch')) { + if ($is_mod_batch_enabled) { print ''.$langs->trans("batch_number").''; - if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) { + if ($is_sell_by_enabled) { print ''.$langs->trans("SellByDate").''; } - if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) { + if ($is_eat_by_enabled) { print ''.$langs->trans("EatByDate").''; } } else { @@ -733,17 +736,17 @@ if ($object->id > 0 || !empty($object->ref)) { $linktoprod = $tmpproduct->getNomUrl(1); $linktoprod .= ' - '.$objp->label."\n"; - if (isModEnabled('productbatch')) { + if ($is_mod_batch_enabled) { if ($objp->tobatch) { // Product print ''; print $linktoprod; print ""; print ''; - if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) { + if ($is_sell_by_enabled) { print ''; } - if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) { + if ($is_eat_by_enabled) { print ''; } } else { @@ -754,10 +757,10 @@ if ($object->id > 0 || !empty($object->ref)) { print ''; print ''.$langs->trans("ProductDoesNotUseBatchSerial").''; print ''; - if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) { + if ($is_sell_by_enabled) { print ''; } - if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) { + if ($is_eat_by_enabled) { print ''; } } @@ -806,7 +809,7 @@ if ($object->id > 0 || !empty($object->ref)) { $suffix = "_".$j."_".$i; $objd = $db->fetch_object($resultsql); - if (isModEnabled('productbatch') && (!empty($objd->batch) || (is_null($objd->batch) && $tmpproduct->status_batch > 0))) { + if ($is_mod_batch_enabled && (!empty($objd->batch) || (is_null($objd->batch) && $tmpproduct->status_batch > 0))) { $type = 'batch'; // Enable hooks to append additional columns @@ -846,13 +849,13 @@ if ($object->id > 0 || !empty($object->ref)) { print ''; //print ''; print ''; - if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) { + if ($is_sell_by_enabled) { print ''; $dlcdatesuffix = !empty($objd->sellby) ? dol_stringtotime($objd->sellby) : dol_mktime(0, 0, 0, GETPOSTINT('dlc'.$suffix.'month'), GETPOSTINT('dlc'.$suffix.'day'), GETPOSTINT('dlc'.$suffix.'year')); print $form->selectDate($dlcdatesuffix, 'dlc'.$suffix, 0, 0, 1, ''); print ''; } - if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) { + if ($is_eat_by_enabled) { print ''; $dluodatesuffix = !empty($objd->eatby) ? dol_stringtotime($objd->eatby) : dol_mktime(0, 0, 0, GETPOSTINT('dluo'.$suffix.'month'), GETPOSTINT('dluo'.$suffix.'day'), GETPOSTINT('dluo'.$suffix.'year')); print $form->selectDate($dluodatesuffix, 'dluo'.$suffix, 0, 0, 1, ''); @@ -862,8 +865,8 @@ if ($object->id > 0 || !empty($object->ref)) { } else { $type = 'dispatch'; $colspan = 6; - $colspan = (getDolGlobalString('PRODUCT_DISABLE_SELLBY')) ? --$colspan : $colspan; - $colspan = (getDolGlobalString('PRODUCT_DISABLE_EATBY')) ? --$colspan : $colspan; + $colspan = $is_sell_by_enabled ? $colspan : --$colspan; + $colspan = $is_eat_by_enabled ? $colspan : --$colspan; // Enable hooks to append additional columns $parameters = array( @@ -904,7 +907,7 @@ if ($object->id > 0 || !empty($object->ref)) { print ''; print ''; print ''; - if (isModEnabled('productbatch') && $objp->tobatch > 0) { + if ($is_mod_batch_enabled && $objp->tobatch > 0) { $type = 'batch'; print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton" '.($numd != $j + 1 ? 'style="display:none"' : '').' onClick="addDispatchLine('.$i.', \''.$type.'\')"'); } else { @@ -953,7 +956,7 @@ if ($object->id > 0 || !empty($object->ref)) { } if ($j == 0) { - if (isModEnabled('productbatch') && !empty($objp->tobatch)) { + if ($is_mod_batch_enabled && !empty($objp->tobatch)) { $type = 'batch'; // Enable hooks to append additional columns @@ -991,13 +994,13 @@ if ($object->id > 0 || !empty($object->ref)) { print ''; print ''; print ''; - if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) { + if ($is_sell_by_enabled) { print ''; $dlcdatesuffix = dol_mktime(0, 0, 0, GETPOSTINT('dlc'.$suffix.'month'), GETPOSTINT('dlc'.$suffix.'day'), GETPOSTINT('dlc'.$suffix.'year')); print $form->selectDate($dlcdatesuffix, 'dlc'.$suffix, 0, 0, 1, ''); print ''; } - if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) { + if ($is_eat_by_enabled) { print ''; $dluodatesuffix = dol_mktime(0, 0, 0, GETPOSTINT('dluo'.$suffix.'month'), GETPOSTINT('dluo'.$suffix.'day'), GETPOSTINT('dluo'.$suffix.'year')); print $form->selectDate($dluodatesuffix, 'dluo'.$suffix, 0, 0, 1, ''); @@ -1007,8 +1010,8 @@ if ($object->id > 0 || !empty($object->ref)) { } else { $type = 'dispatch'; $colspan = 6; - $colspan = (getDolGlobalString('PRODUCT_DISABLE_SELLBY')) ? --$colspan : $colspan; - $colspan = (getDolGlobalString('PRODUCT_DISABLE_EATBY')) ? --$colspan : $colspan; + $colspan = $is_sell_by_enabled ? $colspan : --$colspan; + $colspan = $is_eat_by_enabled ? $colspan : --$colspan; // Enable hooks to append additional columns $parameters = array( @@ -1054,7 +1057,7 @@ if ($object->id > 0 || !empty($object->ref)) { print ''; print ''; print ''; - if (isModEnabled('productbatch') && $objp->tobatch > 0) { + if ($is_mod_batch_enabled && $objp->tobatch > 0) { $type = 'batch'; print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton" onClick="addDispatchLine('.$i.', \''.$type.'\')"'); } else { From 27e3a3ffc6d57b4e4817fa7889e0d1337c45d7f3 Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 19 Feb 2025 15:20:05 +0100 Subject: [PATCH 3/5] Fix: DeprecationHandler, correct isset(), ignore false phpstan positive # Fix: DeprecationHandler, correct isset(), ignore false phpstan positive When the old property name is used, the 'isset' result was not tested on the property. Also ignore a false positive from phpstan --- htdocs/core/class/doldeprecationhandler.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/class/doldeprecationhandler.class.php b/htdocs/core/class/doldeprecationhandler.class.php index ac5d6afedef..bb68b683481 100644 --- a/htdocs/core/class/doldeprecationhandler.class.php +++ b/htdocs/core/class/doldeprecationhandler.class.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2024-2025 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 @@ -142,7 +142,7 @@ trait DolDeprecationHandler if ($this->isDeprecatedReportingEnabled()) { trigger_error($msg, E_USER_DEPRECATED); } - return isset($newProperty); + return isset($this->$newProperty); } elseif ($this->isDynamicPropertiesEnabled()) { return isset($this->$name); } @@ -203,7 +203,7 @@ trait DolDeprecationHandler { // By default, if enableDynamicProperties is set, use that value. - if (property_exists($this, 'enableDynamicProperties')) { + if (property_exists($this, 'enableDynamicProperties')) { // @phpstan-ignore-line // If the property exists, then we use it. return (bool) $this->enableDynamicProperties; } From cee100dea4cc7e1a7a291add098c01b534c6f52d Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 19 Feb 2025 15:50:41 +0100 Subject: [PATCH 4/5] Update DolDeprecationHandlerTest --- test/phpunit/DolDeprecationHandlerTest.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/test/phpunit/DolDeprecationHandlerTest.php b/test/phpunit/DolDeprecationHandlerTest.php index df349fb06ec..d8851067941 100644 --- a/test/phpunit/DolDeprecationHandlerTest.php +++ b/test/phpunit/DolDeprecationHandlerTest.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2024-2025 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 @@ -72,6 +72,12 @@ class DolDeprecationHandlerTest extends CommonClassTest $this->handler = new class () { use DolDeprecationHandler; + /** + * @var bool Configuration enabling throwing exceptions + * for deprecated access. + */ + private $enableDeprecatedReporting = true; + /** * @var string Private var to check that magic * is triggered. @@ -256,7 +262,15 @@ class DolDeprecationHandlerTest extends CommonClassTest */ public function testDeprecatedPropertyUnset() { - $this->handler->newProperty = "TestUnset"; + // Initially the new property should be unset + $this->assertFalse(isset($this->handler->newProperty)); + + // Then we set the new property, so it should be set + $this->handler->newProperty = "ValueIsSet"; + $this->assertTrue(isset($this->handler->newProperty)); + + // Then we set the new property using the old name, + // so it should be unset. unset($this->handler->oldProperty); $this->assertFalse(isset($this->handler->newProperty)); } @@ -288,7 +302,7 @@ class DolDeprecationHandlerTest extends CommonClassTest $this->expectExceptionMessage("Undefined property 'privateVarShouldTrigger'"); $this->handler->privateVarShouldTrigger; - $this->expectExceptionMessage("Accessing deprecated property 'privateDeprecated'. Use 'newProperty' instead."); + $this->expectExceptionMessage("Accessing deprecated property 'privateDeprecated'"); $this->handler->privateDeprecated; // Restore error_reporting From 1811ea7e39ba4fd6b914f22310da3f1f9351fff0 Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 19 Feb 2025 15:56:13 +0100 Subject: [PATCH 5/5] Qual: Fix CommanClassTest in case there is no logfile # Qual: Fix CommanClassTest in case there is no logfile When running an individual test in the absence of a logfile, the test did not run properly (setup issues, and tearDown issues on error). This adds checks that the logfile exists. --- test/phpunit/CommonClassTest.class.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/phpunit/CommonClassTest.class.php b/test/phpunit/CommonClassTest.class.php index 7e71bfda436..d15cf05061d 100644 --- a/test/phpunit/CommonClassTest.class.php +++ b/test/phpunit/CommonClassTest.class.php @@ -132,7 +132,12 @@ abstract class CommonClassTest extends TestCase // Get the lines that were added since the start of the test - $filecontent = (string) @file_get_contents($this->logfile); + if (file_exists($this->logfile)) { + $filecontent = (string) @file_get_contents($this->logfile); + } else { + $filecontent = ''; + } + $currentSize = strlen($filecontent); if ($currentSize >= $this->logSizeAtSetup) { $filecontent = substr($filecontent, $this->logSizeAtSetup); @@ -214,7 +219,11 @@ abstract class CommonClassTest extends TestCase $db = $this->savdb; // Record the filesize to determine which part of the log to show on error - $this->logSizeAtSetup = (int) filesize($this->logfile); + if (file_exists($this->logfile)) { + $this->logSizeAtSetup = (int) filesize($this->logfile); + } else { + $this->logSizeAtSetup = 0; + } if ((int) getenv('PHPUNIT_DEBUG') > 0) { print get_called_class().'::'.$this->getName(false)."::".__FUNCTION__.PHP_EOL;