From e9b880707ad27d58015012aa350b49e2390b79bf Mon Sep 17 00:00:00 2001 From: ldestailleur Date: Tue, 1 Apr 2025 20:13:54 +0200 Subject: [PATCH 1/6] Clean code --- .../modulebuilder/template/core/modules/modMyModule.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php index f7f6805d64a..8a722bd74d9 100644 --- a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php +++ b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php @@ -385,7 +385,7 @@ class modMyModule extends DolibarrModules // Exports profiles provided by this module - $r = 1; + $r = 0; /* BEGIN MODULEBUILDER EXPORT MYOBJECT */ /* $langs->load("mymodule@mymodule"); @@ -416,7 +416,7 @@ class modMyModule extends DolibarrModules /* END MODULEBUILDER EXPORT MYOBJECT */ // Imports profiles provided by this module - $r = 1; + $r = 0; /* BEGIN MODULEBUILDER IMPORT MYOBJECT */ /* $langs->load("mymodule@mymodule"); From 5832f1807c7476feca0470ee82c780767e02422c Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Date: Tue, 1 Apr 2025 20:29:06 +0200 Subject: [PATCH 2/6] FIX: invoice export models are incorrect after 20.0 migration (#33688) * FIX: shift export models at upgrade * FIX: 20.0 invoice export model mogrations: place lock in root of data dir --- htdocs/install/upgrade2.php | 83 +++++++++++++++++++++++++++++++++ htdocs/langs/en_US/install.lang | 1 + 2 files changed, 84 insertions(+) diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 92e58782523..8b1ecaa9531 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -509,6 +509,13 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ migrate_contractdet_rank(); } */ + + // Scripts for 20.0 + $afterversionarray = explode('.', '19.0.9'); + $beforeversionarray = explode('.', '20.0.9'); + if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) { + migrate_invoice_export_models(); + } } @@ -5060,3 +5067,79 @@ function migrate_contractdet_rank() print ''.$langs->trans("NothingToDo")."\n"; } } + +/** + * Invoice exports been shifted (facture_1 => facture_0, facture_2 => facture_1) in version 20, shift export models accordingly + * + * @return void + */ +function migrate_invoice_export_models() +{ + global $db, $langs; + + $lock = DOL_DATA_ROOT.'/invoice_models_migrated.lock'; + $firstInstallVersion = getDolGlobalString('MAIN_VERSION_FIRST_INSTALL', DOL_VERSION); + $migrationNeeded = versioncompare(explode('.', $firstInstallVersion, 3), array(20, 0, -5)) < 0 && !file_exists($lock); + + if (! $migrationNeeded) { + touch($lock); + return; + } + + print ''; + print ''.$langs->trans('InvoiceExportModelsMigration')."
\n"; + + $db->begin(); + + $sql1 = " + UPDATE ".$db->prefix()."export_model + SET type = 'facture_0' + WHERE type = 'facture_1' + "; + + $resql1 = $db->query($sql1); + + if (! $resql1) { + dol_print_error($db); + $db->rollback(); + print ''; + return; + } + + $modified1 = $db->affected_rows($resql1); + + print str_repeat('.', $modified1); + + $db->free($resql1); + + $sql2 = " + UPDATE ".$db->prefix()."export_model + SET type = 'facture_1' + WHERE type = 'facture_2' + "; + + $resql2 = $db->query($sql2); + + if (! $resql2) { + dol_print_error($db); + $db->rollback(); + print ''; + return; + } + + $modified2 = $db->affected_rows($resql2); + + print str_repeat('.', $modified2); + + $db->free($resql2); + + if (empty($modified1 + $modified2)) { + print $langs->trans('NothingToDo'); + } + + $db->commit(); + + touch($lock); + + echo ''; +} diff --git a/htdocs/langs/en_US/install.lang b/htdocs/langs/en_US/install.lang index 21b58f4c4d9..6cbaef2093f 100644 --- a/htdocs/langs/en_US/install.lang +++ b/htdocs/langs/en_US/install.lang @@ -217,3 +217,4 @@ FunctionTest=Function test NodoUpgradeAfterDB=No action requested by external modules after upgrade of database NodoUpgradeAfterFiles=No action requested by external modules after upgrade of files or directories MigrationContractLineRank=Migrate Contract Line to use Rank (and enable Reorder) +InvoiceExportModelsMigration=Migrate invoice export models From de75d13c7ae9ef39f04b3456930dc1657dbbdadc Mon Sep 17 00:00:00 2001 From: ldestailleur Date: Tue, 1 Apr 2025 20:36:55 +0200 Subject: [PATCH 3/6] Use a database flag --- htdocs/install/upgrade2.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 8b1ecaa9531..1d2dfa6bb7f 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -53,6 +53,7 @@ require_once $dolibarr_main_document_root.'/commande/class/commande.class.php'; require_once $dolibarr_main_document_root.'/fourn/class/fournisseur.commande.class.php'; require_once $dolibarr_main_document_root.'/core/lib/price.lib.php'; require_once $dolibarr_main_document_root.'/core/class/menubase.class.php'; +require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php'; require_once $dolibarr_main_document_root.'/core/lib/files.lib.php'; global $langs; @@ -5077,12 +5078,13 @@ function migrate_invoice_export_models() { global $db, $langs; - $lock = DOL_DATA_ROOT.'/invoice_models_migrated.lock'; + $lock = getDolGlobalInt('MIGRATION_INVOICE_MODELS_V20'); + $firstInstallVersion = getDolGlobalString('MAIN_VERSION_FIRST_INSTALL', DOL_VERSION); $migrationNeeded = versioncompare(explode('.', $firstInstallVersion, 3), array(20, 0, -5)) < 0 && !file_exists($lock); if (! $migrationNeeded) { - touch($lock); + dolibarr_set_const($db, 'MIGRATION_INVOICE_MODELS_V20', 1, 'chaine', 0, 'To flag the upgrade of invoice template has been set', 0); return; } @@ -5091,11 +5093,7 @@ function migrate_invoice_export_models() $db->begin(); - $sql1 = " - UPDATE ".$db->prefix()."export_model - SET type = 'facture_0' - WHERE type = 'facture_1' - "; + $sql1 = "UPDATE ".$db->prefix()."export_model SET type = 'facture_0' WHERE type = 'facture_1'"; $resql1 = $db->query($sql1); @@ -5112,11 +5110,7 @@ function migrate_invoice_export_models() $db->free($resql1); - $sql2 = " - UPDATE ".$db->prefix()."export_model - SET type = 'facture_1' - WHERE type = 'facture_2' - "; + $sql2 = "UPDATE ".$db->prefix()."export_model SET type = 'facture_1' WHERE type = 'facture_2'"; $resql2 = $db->query($sql2); From 21b5eb7b82a8a50f2d0ceb0d6a6f6f4e1522416f Mon Sep 17 00:00:00 2001 From: ldestailleur Date: Tue, 1 Apr 2025 20:45:46 +0200 Subject: [PATCH 4/6] Debug migrate using the database flag --- htdocs/install/upgrade2.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 1d2dfa6bb7f..22b88fc2b01 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -5081,15 +5081,18 @@ function migrate_invoice_export_models() $lock = getDolGlobalInt('MIGRATION_INVOICE_MODELS_V20'); $firstInstallVersion = getDolGlobalString('MAIN_VERSION_FIRST_INSTALL', DOL_VERSION); - $migrationNeeded = versioncompare(explode('.', $firstInstallVersion, 3), array(20, 0, -5)) < 0 && !file_exists($lock); + $migrationNeeded = (versioncompare(explode('.', $firstInstallVersion, 3), array(20, 0, -5)) < 0 && !$lock); + + print ''; + print ''.$langs->trans('InvoiceExportModelsMigration').": \n"; if (! $migrationNeeded) { + print $langs->trans("AlreadyDone"); + print ''; dolibarr_set_const($db, 'MIGRATION_INVOICE_MODELS_V20', 1, 'chaine', 0, 'To flag the upgrade of invoice template has been set', 0); return; } - print ''; - print ''.$langs->trans('InvoiceExportModelsMigration')."
\n"; $db->begin(); @@ -5133,7 +5136,7 @@ function migrate_invoice_export_models() $db->commit(); - touch($lock); + dolibarr_set_const($db, 'MIGRATION_INVOICE_MODELS_V20', 1, 'chaine', 0, 'To flag the upgrade of invoice template has been set', 0); echo ''; } From 514e367d946e11782f1e77e65058c6fd2b78b695 Mon Sep 17 00:00:00 2001 From: ldestailleur Date: Tue, 1 Apr 2025 20:46:31 +0200 Subject: [PATCH 5/6] Rename constant --- htdocs/install/upgrade2.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 22b88fc2b01..52f00eaec8a 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -5078,7 +5078,7 @@ function migrate_invoice_export_models() { global $db, $langs; - $lock = getDolGlobalInt('MIGRATION_INVOICE_MODELS_V20'); + $lock = getDolGlobalInt('MIGRATION_FLAG_INVOICE_MODELS_V20'); $firstInstallVersion = getDolGlobalString('MAIN_VERSION_FIRST_INSTALL', DOL_VERSION); $migrationNeeded = (versioncompare(explode('.', $firstInstallVersion, 3), array(20, 0, -5)) < 0 && !$lock); @@ -5089,7 +5089,7 @@ function migrate_invoice_export_models() if (! $migrationNeeded) { print $langs->trans("AlreadyDone"); print ''; - dolibarr_set_const($db, 'MIGRATION_INVOICE_MODELS_V20', 1, 'chaine', 0, 'To flag the upgrade of invoice template has been set', 0); + dolibarr_set_const($db, 'MIGRATION_FLAG_INVOICE_MODELS_V20', 1, 'chaine', 0, 'To flag the upgrade of invoice template has been set', 0); return; } @@ -5136,7 +5136,7 @@ function migrate_invoice_export_models() $db->commit(); - dolibarr_set_const($db, 'MIGRATION_INVOICE_MODELS_V20', 1, 'chaine', 0, 'To flag the upgrade of invoice template has been set', 0); + dolibarr_set_const($db, 'MIGRATION_FLAG_INVOICE_MODELS_V20', 1, 'chaine', 0, 'To flag the upgrade of invoice template has been set', 0); echo ''; } From e1273a410a0c6422e3ed9dba62d034ffcde3b4b4 Mon Sep 17 00:00:00 2001 From: ldestailleur Date: Tue, 1 Apr 2025 22:37:23 +0200 Subject: [PATCH 6/6] FIX for #33403 and #33404 --- htdocs/contact/class/contact.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 57f24b67a4c..9ac7b17c64c 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -1153,7 +1153,7 @@ class Contact extends CommonObject } } - return 1; + return $this->id; } else { $this->error = $langs->trans("RecordNotFound"); return 0;