From 2e14655fa0b5bc45778cc3e4b393a737480a7472 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Tue, 4 Jul 2023 20:50:57 +0200 Subject: [PATCH 01/69] unify categories --- htdocs/filefunc.inc.php | 2 +- .../install/mysql/migration/18.0.0-19.0.0.sql | 67 +++++++++++++++++++ .../mysql/tables/llx_c_category.key.sql | 19 ++++++ .../install/mysql/tables/llx_c_category.sql | 25 +++++++ ...e.key.sql => llx_element_category.key.sql} | 4 +- ...categorie.sql => llx_element_category.sql} | 4 +- htdocs/install/upgrade2.php | 37 ++++++++++ htdocs/langs/en_US/install.lang | 1 + 8 files changed, 154 insertions(+), 5 deletions(-) create mode 100644 htdocs/install/mysql/migration/18.0.0-19.0.0.sql create mode 100644 htdocs/install/mysql/tables/llx_c_category.key.sql create mode 100644 htdocs/install/mysql/tables/llx_c_category.sql rename htdocs/install/mysql/tables/{llx_element_categorie.key.sql => llx_element_category.key.sql} (78%) rename htdocs/install/mysql/tables/{llx_element_categorie.sql => llx_element_category.sql} (93%) diff --git a/htdocs/filefunc.inc.php b/htdocs/filefunc.inc.php index f4f7e281cd3aa..8626ecbb6b791 100644 --- a/htdocs/filefunc.inc.php +++ b/htdocs/filefunc.inc.php @@ -34,7 +34,7 @@ define('DOL_APPLICATION_TITLE', 'Dolibarr'); } if (!defined('DOL_VERSION')) { - define('DOL_VERSION', '18.0.0-beta'); // a.b.c-alpha, a.b.c-beta, a.b.c-rcX or a.b.c + define('DOL_VERSION', '19.0.0-alpha'); // a.b.c-alpha, a.b.c-beta, a.b.c-rcX or a.b.c } if (!defined('EURO')) { diff --git a/htdocs/install/mysql/migration/18.0.0-19.0.0.sql b/htdocs/install/mysql/migration/18.0.0-19.0.0.sql new file mode 100644 index 0000000000000..65ffef53ff239 --- /dev/null +++ b/htdocs/install/mysql/migration/18.0.0-19.0.0.sql @@ -0,0 +1,67 @@ +-- +-- Be carefull to requests order. +-- This file must be loaded by calling /install/index.php page +-- when current version is 19.0.0 or higher. +-- +-- To restrict request to Mysql version x.y minimum use -- VMYSQLx.y +-- To restrict request to Pgsql version x.y minimum use -- VPGSQLx.y +-- To rename a table: ALTER TABLE llx_table RENAME TO llx_table_new; +-- To add a column: ALTER TABLE llx_table ADD COLUMN newcol varchar(60) NOT NULL DEFAULT '0' AFTER existingcol; +-- To rename a column: ALTER TABLE llx_table CHANGE COLUMN oldname newname varchar(60); +-- To drop a column: ALTER TABLE llx_table DROP COLUMN oldname; +-- To change type of field: ALTER TABLE llx_table MODIFY COLUMN name varchar(60); +-- To drop a foreign key: ALTER TABLE llx_table DROP FOREIGN KEY fk_name; +-- To create a unique index ALTER TABLE llx_table ADD UNIQUE INDEX uk_table_field (field); +-- To drop an index: -- VMYSQL4.1 DROP INDEX nomindex on llx_table; +-- To drop an index: -- VPGSQL8.2 DROP INDEX nomindex; +-- To make pk to be auto increment (mysql): +-- -- VMYSQL4.3 ALTER TABLE llx_table ADD PRIMARY KEY(rowid); +-- -- VMYSQL4.3 ALTER TABLE llx_table CHANGE COLUMN rowid rowid INTEGER NOT NULL AUTO_INCREMENT; +-- To make pk to be auto increment (postgres): +-- -- VPGSQL8.2 CREATE SEQUENCE llx_table_rowid_seq OWNED BY llx_table.rowid; +-- -- VPGSQL8.2 ALTER TABLE llx_table ADD PRIMARY KEY (rowid); +-- -- VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN rowid SET DEFAULT nextval('llx_table_rowid_seq'); +-- -- VPGSQL8.2 SELECT setval('llx_table_rowid_seq', MAX(rowid)) FROM llx_table; +-- To set a field as NULL: -- VMYSQL4.3 ALTER TABLE llx_table MODIFY COLUMN name varchar(60) NULL; +-- To set a field as NULL: -- VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name DROP NOT NULL; +-- To set a field as NOT NULL: -- VMYSQL4.3 ALTER TABLE llx_table MODIFY COLUMN name varchar(60) NOT NULL; +-- To set a field as NOT NULL: -- VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name SET NOT NULL; +-- To set a field as default NULL: -- VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name SET DEFAULT NULL; +-- Note: fields with type BLOB/TEXT can't have default value. +-- To rebuild sequence for postgresql after insert by forcing id autoincrement fields: +-- -- VPGSQL8.2 SELECT dol_util_rebuild_sequences(); + + +-- v19 +create table llx_c_category +( + rowid integer AUTO_INCREMENT PRIMARY KEY NOT NULL, + classname varchar(32) NOT NULL, + module varchar(32) NOT NULL +)ENGINE=innodb; + +ALTER TABLE llx_c_category ADD UNIQUE INDEX uk_c_module(module); + +INSERT INTO llx_c_category (rowid,module,classname) VALUES (0, 'product', 'Product'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (1, 'supplier', 'Fournisseur'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (2, 'customer', 'Societe'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (3, 'member', 'Adherent'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (4, 'contact', 'Contact'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (5, 'bank_account', 'Account'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (6, 'project', 'Project'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (7, 'user', 'User'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (8, 'bank_line', 'AccountLine'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (9, 'warehouse', 'Entrepot'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (10, 'actioncomm', 'Actioncomm'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (11, 'website_page', 'WebsitePage'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (12, 'ticket', 'Ticket'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (13, 'knowledgemanagement', 'KnowledgeRecord'); + +-- VMYSQL4.1 DROP INDEX idx_element_categorie_idx on llx_element_categorie; +-- VPGSQL8.2 DROP INDEX idx_element_categorie_idx; +ALTER TABLE llx_element_categorie DROP FOREIGN KEY fk_element_categorie_fk_categorie; +ALTER TABLE llx_element_categorie CHANGE COLUMN fk_categorie fk_category integer NOT NULL; +ALTER TABLE llx_element_categorie RENAME TO llx_element_category; + +ALTER TABLE llx_element_category ADD UNIQUE INDEX idx_element_category_idx (fk_element, fk_category); +ALTER TABLE llx_element_category ADD CONSTRAINT fk_element_category_fk_category FOREIGN KEY (fk_category) REFERENCES llx_categorie(rowid); diff --git a/htdocs/install/mysql/tables/llx_c_category.key.sql b/htdocs/install/mysql/tables/llx_c_category.key.sql new file mode 100644 index 0000000000000..9cfd48b25363f --- /dev/null +++ b/htdocs/install/mysql/tables/llx_c_category.key.sql @@ -0,0 +1,19 @@ +-- ======================================================================== +-- Copyright (C) 2023 Frédéric France +-- +-- 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 +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- ======================================================================== + +ALTER TABLE llx_c_category ADD UNIQUE INDEX uk_c_module(module); diff --git a/htdocs/install/mysql/tables/llx_c_category.sql b/htdocs/install/mysql/tables/llx_c_category.sql new file mode 100644 index 0000000000000..ecb1977ca6736 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_c_category.sql @@ -0,0 +1,25 @@ +-- ======================================================================== +-- Copyright (C) 2023 Frédéric France +-- +-- 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 +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- ======================================================================== + +create table llx_c_category +( + rowid integer AUTO_INCREMENT PRIMARY KEY NOT NULL, + classname varchar(32) NOT NULL, + module varchar(32) NULL +)ENGINE=innodb; + diff --git a/htdocs/install/mysql/tables/llx_element_categorie.key.sql b/htdocs/install/mysql/tables/llx_element_category.key.sql similarity index 78% rename from htdocs/install/mysql/tables/llx_element_categorie.key.sql rename to htdocs/install/mysql/tables/llx_element_category.key.sql index 9bc70cf0863a2..263be886b44e6 100644 --- a/htdocs/install/mysql/tables/llx_element_categorie.key.sql +++ b/htdocs/install/mysql/tables/llx_element_category.key.sql @@ -17,6 +17,6 @@ -- ============================================================================ -ALTER TABLE llx_element_categorie ADD UNIQUE INDEX idx_element_categorie_idx (fk_element, fk_categorie); +ALTER TABLE llx_element_category ADD UNIQUE INDEX idx_element_category_idx (fk_element, fk_category); -ALTER TABLE llx_element_categorie ADD CONSTRAINT fk_element_categorie_fk_categorie FOREIGN KEY (fk_categorie) REFERENCES llx_categorie(rowid); +ALTER TABLE llx_element_category ADD CONSTRAINT fk_element_category_fk_category FOREIGN KEY (fk_categorie) REFERENCES llx_categorie(rowid); diff --git a/htdocs/install/mysql/tables/llx_element_categorie.sql b/htdocs/install/mysql/tables/llx_element_category.sql similarity index 93% rename from htdocs/install/mysql/tables/llx_element_categorie.sql rename to htdocs/install/mysql/tables/llx_element_category.sql index a1c7fddb0eb7a..20df8a4d643f5 100644 --- a/htdocs/install/mysql/tables/llx_element_categorie.sql +++ b/htdocs/install/mysql/tables/llx_element_category.sql @@ -16,10 +16,10 @@ -- -- ============================================================================ -create table llx_element_categorie +create table llx_element_category ( rowid integer AUTO_INCREMENT PRIMARY KEY, - fk_categorie integer NOT NULL, + fk_category integer NOT NULL, fk_element integer NOT NULL, import_key varchar(14) )ENGINE=innodb; diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 1dc5c7337d407..785e228be84ac 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -499,6 +499,13 @@ if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) { migrate_contractdet_rank(); } + // Scripts for 19.0 + $afterversionarray = explode('.', '18.0.9'); + $beforeversionarray = explode('.', '19.0.9'); + if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) { + // migrate categories + migrate_element_category($db, $langs, $conf); + } } @@ -3312,6 +3319,36 @@ function migrate_actioncomm_element($db, $langs, $conf) print ''; } +/** + * Migrate categories in one table + * + * @param DoliDB $db Database handler + * @param Translate $langs Object langs + * @param Conf $conf Object conf + * @return void + */ +function migrate_element_category($db, $langs, $conf) +{ + dolibarr_install_syslog("upgrade2::migrate_element_time"); + + print ''; + + print '
'; + print ''.$langs->trans('MigrationCategories')."
\n"; + + $error = 0; + + $db->begin(); + + if ($error == 0) { + $db->commit(); + } else { + $db->rollback(); + } + + print ''; +} + /** * Migrate link stored into fk_mode_reglement * diff --git a/htdocs/langs/en_US/install.lang b/htdocs/langs/en_US/install.lang index 58e57018ac397..155b0d5c57164 100644 --- a/htdocs/langs/en_US/install.lang +++ b/htdocs/langs/en_US/install.lang @@ -190,6 +190,7 @@ MigrationProjectTaskActors=Data migration for table llx_projet_task_actors MigrationProjectUserResp=Data migration field fk_user_resp of llx_projet to llx_element_contact MigrationProjectTaskTime=Update time spent in seconds MigrationActioncommElement=Update data on actions +MigrationCategories=Update data on categories MigrationPaymentMode=Data migration for payment type MigrationCategorieAssociation=Migration of categories MigrationEvents=Migration of events to add event owner into assignment table From f1cdfef7bf6814cff80cd4d5221dda011c92d253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Tue, 4 Jul 2023 20:56:30 +0200 Subject: [PATCH 02/69] unify categories unify categories unify categories --- htdocs/install/mysql/data/llx_c_category.sql | 33 +++++++++++++++++++ .../install/mysql/migration/18.0.0-19.0.0.sql | 2 +- .../install/mysql/tables/llx_c_category.sql | 2 +- .../mysql/tables/llx_element_category.sql | 2 +- 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 htdocs/install/mysql/data/llx_c_category.sql diff --git a/htdocs/install/mysql/data/llx_c_category.sql b/htdocs/install/mysql/data/llx_c_category.sql new file mode 100644 index 0000000000000..8bbac804938b5 --- /dev/null +++ b/htdocs/install/mysql/data/llx_c_category.sql @@ -0,0 +1,33 @@ +-- 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 +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- + +-- WARNING +-- Do not place a comment at the end of the line, this file is parsed during +-- installation and all '--' symbols are removed. +-- +INSERT INTO llx_c_category (rowid,module,classname) VALUES (0, 'product', 'Product'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (1, 'supplier', 'Fournisseur'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (2, 'customer', 'Societe'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (3, 'member', 'Adherent'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (4, 'contact', 'Contact'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (5, 'bank_account', 'Account'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (6, 'project', 'Project'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (7, 'user', 'User'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (8, 'bank_line', 'AccountLine'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (9, 'warehouse', 'Entrepot'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (10, 'actioncomm', 'Actioncomm'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (11, 'website_page', 'WebsitePage'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (12, 'ticket', 'Ticket'); +INSERT INTO llx_c_category (rowid,module,classname) VALUES (13, 'knowledgemanagement', 'KnowledgeRecord'); diff --git a/htdocs/install/mysql/migration/18.0.0-19.0.0.sql b/htdocs/install/mysql/migration/18.0.0-19.0.0.sql index 65ffef53ff239..07da35f94ecb5 100644 --- a/htdocs/install/mysql/migration/18.0.0-19.0.0.sql +++ b/htdocs/install/mysql/migration/18.0.0-19.0.0.sql @@ -33,7 +33,7 @@ -- v19 -create table llx_c_category +CREATE TABLE llx_c_category ( rowid integer AUTO_INCREMENT PRIMARY KEY NOT NULL, classname varchar(32) NOT NULL, diff --git a/htdocs/install/mysql/tables/llx_c_category.sql b/htdocs/install/mysql/tables/llx_c_category.sql index ecb1977ca6736..dc35cf9dd90e7 100644 --- a/htdocs/install/mysql/tables/llx_c_category.sql +++ b/htdocs/install/mysql/tables/llx_c_category.sql @@ -16,7 +16,7 @@ -- -- ======================================================================== -create table llx_c_category +CREATE TABLE llx_c_category ( rowid integer AUTO_INCREMENT PRIMARY KEY NOT NULL, classname varchar(32) NOT NULL, diff --git a/htdocs/install/mysql/tables/llx_element_category.sql b/htdocs/install/mysql/tables/llx_element_category.sql index 20df8a4d643f5..96ee906de448a 100644 --- a/htdocs/install/mysql/tables/llx_element_category.sql +++ b/htdocs/install/mysql/tables/llx_element_category.sql @@ -16,7 +16,7 @@ -- -- ============================================================================ -create table llx_element_category +CREATE TABLE llx_element_category ( rowid integer AUTO_INCREMENT PRIMARY KEY, fk_category integer NOT NULL, From 81777588e02dd2076511f1deec762cd4d94d2c9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Tue, 4 Jul 2023 21:59:24 +0200 Subject: [PATCH 03/69] unify categories --- htdocs/install/upgrade2.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 785e228be84ac..8b43858b39263 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -3329,7 +3329,7 @@ function migrate_actioncomm_element($db, $langs, $conf) */ function migrate_element_category($db, $langs, $conf) { - dolibarr_install_syslog("upgrade2::migrate_element_time"); + dolibarr_install_syslog("upgrade2::migrate_element_category"); print ''; @@ -3340,6 +3340,17 @@ function migrate_element_category($db, $langs, $conf) $db->begin(); + // product + $sql = 'SELECT fk_categorie, fk_product, import_key FROM '.MAIN_DB_PREFIX."categorie_product"; + $result = $db->query($sql); + if ($result) { + while ($obj = $db->fetch_object($result)) { + $db->query('INSERT INTO '.MAIN_DB_PREFIX.'element_category (fk_category, fk_element) VALUES('.(int) $obj->fk_categorie.','.(int)$obj->fk_product.')'); + } + } else { + $error++; + } + if ($error == 0) { $db->commit(); } else { From d65ac6952f4641de63da4d5971c595ddb47faf85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Tue, 4 Jul 2023 22:14:18 +0200 Subject: [PATCH 04/69] unify categories --- htdocs/install/upgrade2.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 8b43858b39263..4bd1ede9e93bf 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -3345,7 +3345,18 @@ function migrate_element_category($db, $langs, $conf) $result = $db->query($sql); if ($result) { while ($obj = $db->fetch_object($result)) { - $db->query('INSERT INTO '.MAIN_DB_PREFIX.'element_category (fk_category, fk_element) VALUES('.(int) $obj->fk_categorie.','.(int)$obj->fk_product.')'); + $db->query('INSERT INTO '.MAIN_DB_PREFIX.'element_category (fk_category, fk_element, import_key) VALUES('.(int) $obj->fk_categorie.','.(int)$obj->fk_product.', '.(is_null($obj->import_key) ? 'null' : $db->escape($obj->import_key)).')'); + } + } else { + $error++; + } + + // supplier + $sql = 'SELECT fk_categorie, fk_soc, import_key FROM '.MAIN_DB_PREFIX."categorie_fournisseur"; + $result = $db->query($sql); + if ($result) { + while ($obj = $db->fetch_object($result)) { + $db->query('INSERT INTO '.MAIN_DB_PREFIX.'element_category (fk_category, fk_element, import_key) VALUES('.(int) $obj->fk_categorie.','.(int)$obj->fk_soc.', '.(is_null($obj->import_key) ? 'null' : $db->escape($obj->import_key)).')'); } } else { $error++; From f5b3fee94a4dd65f755bc26b905d9e8abd0086e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Tue, 4 Jul 2023 22:16:58 +0200 Subject: [PATCH 05/69] unify categories --- htdocs/install/upgrade2.php | 55 ++++++++++++++++++++++++++++----- htdocs/langs/en_US/install.lang | 2 +- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 4bd1ede9e93bf..aec925a93d494 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -3331,44 +3331,85 @@ function migrate_element_category($db, $langs, $conf) { dolibarr_install_syslog("upgrade2::migrate_element_category"); - print ''; - - print '
'; - print ''.$langs->trans('MigrationCategories')."
\n"; - $error = 0; $db->begin(); // product + print ''; $sql = 'SELECT fk_categorie, fk_product, import_key FROM '.MAIN_DB_PREFIX."categorie_product"; $result = $db->query($sql); if ($result) { while ($obj = $db->fetch_object($result)) { $db->query('INSERT INTO '.MAIN_DB_PREFIX.'element_category (fk_category, fk_element, import_key) VALUES('.(int) $obj->fk_categorie.','.(int)$obj->fk_product.', '.(is_null($obj->import_key) ? 'null' : $db->escape($obj->import_key)).')'); } + print ''.$langs->trans('MigrationCategories', 'Products')."
\n"; } else { $error++; } + print ''; // supplier + print ''; $sql = 'SELECT fk_categorie, fk_soc, import_key FROM '.MAIN_DB_PREFIX."categorie_fournisseur"; $result = $db->query($sql); if ($result) { while ($obj = $db->fetch_object($result)) { $db->query('INSERT INTO '.MAIN_DB_PREFIX.'element_category (fk_category, fk_element, import_key) VALUES('.(int) $obj->fk_categorie.','.(int)$obj->fk_soc.', '.(is_null($obj->import_key) ? 'null' : $db->escape($obj->import_key)).')'); } + print ''.$langs->trans('MigrationCategories', 'Suppliers')."
\n"; } else { $error++; } + print ''; + + // customer + print ''; + $sql = 'SELECT fk_categorie, fk_soc, import_key FROM '.MAIN_DB_PREFIX."categorie_societe"; + $result = $db->query($sql); + if ($result) { + while ($obj = $db->fetch_object($result)) { + $db->query('INSERT INTO '.MAIN_DB_PREFIX.'element_category (fk_category, fk_element, import_key) VALUES('.(int) $obj->fk_categorie.','.(int)$obj->fk_soc.', '.(is_null($obj->import_key) ? 'null' : $db->escape($obj->import_key)).')'); + } + print ''.$langs->trans('MigrationCategories', 'Customers')."
\n"; + } else { + $error++; + } + print ''; + + // member + print ''; + $sql = 'SELECT fk_categorie, fk_member FROM '.MAIN_DB_PREFIX."categorie_member"; + $result = $db->query($sql); + if ($result) { + while ($obj = $db->fetch_object($result)) { + $db->query('INSERT INTO '.MAIN_DB_PREFIX.'element_category (fk_category, fk_element) VALUES('.(int) $obj->fk_categorie.','.(int)$obj->fk_member.')'); + } + print ''.$langs->trans('MigrationCategories', 'Members')."
\n"; + } else { + $error++; + } + print ''; + + // contact + print ''; + $sql = 'SELECT fk_categorie, fk_socpeople, import_key FROM '.MAIN_DB_PREFIX."categorie_contact"; + $result = $db->query($sql); + if ($result) { + while ($obj = $db->fetch_object($result)) { + $db->query('INSERT INTO '.MAIN_DB_PREFIX.'element_category (fk_category, fk_element, import_key) VALUES('.(int) $obj->fk_categorie.','.(int)$obj->fk_socpeople.', '.(is_null($obj->import_key) ? 'null' : $db->escape($obj->import_key)).')'); + } + print ''.$langs->trans('MigrationCategories', 'Contacts')."
\n"; + } else { + $error++; + } + print ''; if ($error == 0) { $db->commit(); } else { $db->rollback(); } - - print ''; } /** diff --git a/htdocs/langs/en_US/install.lang b/htdocs/langs/en_US/install.lang index 155b0d5c57164..9618c1b58f2a3 100644 --- a/htdocs/langs/en_US/install.lang +++ b/htdocs/langs/en_US/install.lang @@ -190,7 +190,7 @@ MigrationProjectTaskActors=Data migration for table llx_projet_task_actors MigrationProjectUserResp=Data migration field fk_user_resp of llx_projet to llx_element_contact MigrationProjectTaskTime=Update time spent in seconds MigrationActioncommElement=Update data on actions -MigrationCategories=Update data on categories +MigrationCategories=Update data on %s categories MigrationPaymentMode=Data migration for payment type MigrationCategorieAssociation=Migration of categories MigrationEvents=Migration of events to add event owner into assignment table From be7b6b24f06adc68f9b9e39499fc936efb53ef71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Tue, 4 Jul 2023 23:00:17 +0200 Subject: [PATCH 06/69] unify categories --- htdocs/install/upgrade2.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index aec925a93d494..0f6e95c7b435a 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -3405,6 +3405,20 @@ function migrate_element_category($db, $langs, $conf) } print ''; + // bank_account + print ''; + $sql = 'SELECT fk_categorie, fk_account, import_key FROM '.MAIN_DB_PREFIX."categorie_account"; + $result = $db->query($sql); + if ($result) { + while ($obj = $db->fetch_object($result)) { + $db->query('INSERT INTO '.MAIN_DB_PREFIX.'element_category (fk_category, fk_element, import_key) VALUES('.(int) $obj->fk_categorie.','.(int)$obj->fk_account.', '.(is_null($obj->import_key) ? 'null' : $db->escape($obj->import_key)).')'); + } + print ''.$langs->trans('MigrationCategories', 'Accounts')."
\n"; + } else { + $error++; + } + print ''; + if ($error == 0) { $db->commit(); } else { From d4cf3a4da1e23cc728dc6ccb695b02b6d894f1bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Wed, 5 Jul 2023 12:25:12 +0200 Subject: [PATCH 07/69] unify categories --- htdocs/filefunc.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/filefunc.inc.php b/htdocs/filefunc.inc.php index 8626ecbb6b791..e9d2069154f89 100644 --- a/htdocs/filefunc.inc.php +++ b/htdocs/filefunc.inc.php @@ -34,7 +34,7 @@ define('DOL_APPLICATION_TITLE', 'Dolibarr'); } if (!defined('DOL_VERSION')) { - define('DOL_VERSION', '19.0.0-alpha'); // a.b.c-alpha, a.b.c-beta, a.b.c-rcX or a.b.c + define('DOL_VERSION', '19.0.0-dev'); // a.b.c-alpha, a.b.c-beta, a.b.c-rcX or a.b.c } if (!defined('EURO')) { From b46a48d0d91be78bdf4092d9cf45231065007856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Wed, 5 Jul 2023 21:44:17 +0200 Subject: [PATCH 08/69] unify categories --- htdocs/install/upgrade2.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 0f6e95c7b435a..eac9f234aa147 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -3419,6 +3419,34 @@ function migrate_element_category($db, $langs, $conf) } print ''; + // project + print ''; + $sql = 'SELECT fk_categorie, fk_project, import_key FROM '.MAIN_DB_PREFIX."categorie_project"; + $result = $db->query($sql); + if ($result) { + while ($obj = $db->fetch_object($result)) { + $db->query('INSERT INTO '.MAIN_DB_PREFIX.'element_category (fk_category, fk_element, import_key) VALUES('.(int) $obj->fk_categorie.','.(int)$obj->fk_project.', '.(is_null($obj->import_key) ? 'null' : $db->escape($obj->import_key)).')'); + } + print ''.$langs->trans('MigrationCategories', 'Projects')."
\n"; + } else { + $error++; + } + print ''; + + // user + print ''; + $sql = 'SELECT fk_categorie, fk_user, import_key FROM '.MAIN_DB_PREFIX."categorie_user"; + $result = $db->query($sql); + if ($result) { + while ($obj = $db->fetch_object($result)) { + $db->query('INSERT INTO '.MAIN_DB_PREFIX.'element_category (fk_category, fk_element, import_key) VALUES('.(int) $obj->fk_categorie.','.(int)$obj->fk_user.', '.(is_null($obj->import_key) ? 'null' : $db->escape($obj->import_key)).')'); + } + print ''.$langs->trans('MigrationCategories', 'Users')."
\n"; + } else { + $error++; + } + print ''; + if ($error == 0) { $db->commit(); } else { From b48eb4df2d5bf476582670fcc06fc2cc20c69cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Wed, 5 Jul 2023 22:24:50 +0200 Subject: [PATCH 09/69] unify categories --- htdocs/install/upgrade2.php | 51 +++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index eac9f234aa147..cb879f80a21f1 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -3447,6 +3447,57 @@ function migrate_element_category($db, $langs, $conf) } print ''; + // warehouse + print ''; + $sql = 'SELECT fk_categorie, fk_warehouse, import_key FROM '.MAIN_DB_PREFIX."categorie_warehouse"; + $result = $db->query($sql); + if ($result) { + while ($obj = $db->fetch_object($result)) { + $db->query('INSERT INTO '.MAIN_DB_PREFIX.'element_category (fk_category, fk_element, import_key) VALUES('.(int) $obj->fk_categorie.','.(int)$obj->fk_warehouse.', '.(is_null($obj->import_key) ? 'null' : $db->escape($obj->import_key)).')'); + } + print ''.$langs->trans('MigrationCategories', 'Warehouses')."
\n"; + } else { + $error++; + } + print ''; + + // actioncomm + print ''; + $sql = 'SELECT fk_categorie, fk_actioncomm, import_key FROM '.MAIN_DB_PREFIX."categorie_actioncomm"; + $result = $db->query($sql); + if ($result) { + while ($obj = $db->fetch_object($result)) { + $db->query('INSERT INTO '.MAIN_DB_PREFIX.'element_category (fk_category, fk_element, import_key) VALUES('.(int) $obj->fk_categorie.','.(int)$obj->fk_actioncomm.', '.(is_null($obj->import_key) ? 'null' : $db->escape($obj->import_key)).')'); + } + print ''.$langs->trans('MigrationCategories', 'Actioncomms')."
\n"; + } else { + $error++; + } + print ''; + + // website_page + print ''; + // if module website never enabled, table may not exist + if ($db->DDLDescTable(MAIN_DB_PREFIX."categorie_website_page")) { + $sql = 'SELECT fk_categorie, fk_website_page, import_key FROM '.MAIN_DB_PREFIX."categorie_website_page"; + $result = $db->query($sql); + if ($result) { + while ($obj = $db->fetch_object($result)) { + $db->query('INSERT INTO '.MAIN_DB_PREFIX.'element_category (fk_category, fk_element, import_key) VALUES('.(int) $obj->fk_categorie.','.(int)$obj->fk_website_page.', '.(is_null($obj->import_key) ? 'null' : $db->escape($obj->import_key)).')'); + } + print ''.$langs->trans('MigrationCategories', 'WebsitePages')."
\n"; + } else { + $error++; + } + } else { + print ''.$langs->trans('MigrationCategories', 'WebsitePages')." Table not found
\n"; + } + print ''; + + // ticket + + // knowledgemanagement + if ($error == 0) { $db->commit(); } else { From 4e2c53f9bf83b2b11a2a38294cde92bcfd080f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Wed, 5 Jul 2023 23:14:16 +0200 Subject: [PATCH 10/69] unify categories --- htdocs/install/upgrade2.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index cb879f80a21f1..cd2ed26d83d61 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -3495,6 +3495,23 @@ function migrate_element_category($db, $langs, $conf) print ''; // ticket + print ''; + // if module ticket never enabled, table may not exist + if ($db->DDLDescTable(MAIN_DB_PREFIX."categorie_ticket")) { + $sql = 'SELECT fk_categorie, fk_ticket, import_key FROM '.MAIN_DB_PREFIX."categorie_ticket"; + $result = $db->query($sql); + if ($result) { + while ($obj = $db->fetch_object($result)) { + $db->query('INSERT INTO '.MAIN_DB_PREFIX.'element_category (fk_category, fk_element, import_key) VALUES('.(int) $obj->fk_categorie.','.(int)$obj->fk_ticket.', '.(is_null($obj->import_key) ? 'null' : $db->escape($obj->import_key)).')'); + } + print ''.$langs->trans('MigrationCategories', 'Tickets')."
\n"; + } else { + $error++; + } + } else { + print ''.$langs->trans('MigrationCategories', 'Tickets')." Table not found
\n"; + } + print ''; // knowledgemanagement From d39dd4b85123092a5394485de03a6909afca0055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Thu, 6 Jul 2023 01:07:50 +0200 Subject: [PATCH 11/69] unify categories --- htdocs/install/upgrade2.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index cd2ed26d83d61..864c225679f16 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -3514,6 +3514,23 @@ function migrate_element_category($db, $langs, $conf) print ''; // knowledgemanagement + print ''; + // if module knowledgemanagement never enabled, table may not exist + if ($db->DDLDescTable(MAIN_DB_PREFIX."categorie_knowledgemanagement")) { + $sql = 'SELECT fk_categorie, fk_knowledgemanagement, import_key FROM '.MAIN_DB_PREFIX."categorie_knowledgemanagement"; + $result = $db->query($sql); + if ($result) { + while ($obj = $db->fetch_object($result)) { + $db->query('INSERT INTO '.MAIN_DB_PREFIX.'element_category (fk_category, fk_element, import_key) VALUES('.(int) $obj->fk_categorie.','.(int)$obj->fk_knowledgemanagement.', '.(is_null($obj->import_key) ? 'null' : $db->escape($obj->import_key)).')'); + } + print ''.$langs->trans('MigrationCategories', 'Knowledgemanagement')."
\n"; + } else { + $error++; + } + } else { + print ''.$langs->trans('MigrationCategories', 'Knowledgemanagement')." Table not found
\n"; + } + print ''; if ($error == 0) { $db->commit(); From a6e00a1de17f65d649c533c871b7d48516b39a22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Fri, 7 Jul 2023 16:27:21 +0200 Subject: [PATCH 12/69] wip --- htdocs/categories/class/categorie.class.php | 104 +++++++++++------- htdocs/install/mysql/data/llx_c_category.sql | 28 ++--- .../install/mysql/migration/18.0.0-19.0.0.sql | 30 ++--- .../install/mysql/tables/llx_c_category.sql | 2 +- 4 files changed, 93 insertions(+), 71 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 3f9524d3f6e2e..2552667670053 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -72,42 +72,43 @@ class Categorie extends CommonObject * @var array Table of mapping between type string and ID used for field 'type' in table llx_categories */ protected $MAP_ID = array( - 'product' => 0, - 'supplier' => 1, - 'customer' => 2, - 'member' => 3, - 'contact' => 4, - 'bank_account' => 5, - 'project' => 6, - 'user' => 7, - 'bank_line' => 8, - 'warehouse' => 9, - 'actioncomm' => 10, - 'website_page' => 11, - 'ticket' => 12, - 'knowledgemanagement' => 13 + // 'product' => 0, + // 'supplier' => 1, + // 'customer' => 2, + // 'member' => 3, + // 'contact' => 4, + // 'bank_account' => 5, + // 'project' => 6, + // 'user' => 7, + // 'bank_line' => 8, + // 'warehouse' => 9, + // 'actioncomm' => 10, + // 'website_page' => 11, + // 'ticket' => 12, + // 'knowledgemanagement' => 13 ); /** * @var array Code mapping from ID * * @note This array should be removed in future, once previous constants are moved to the string value. Deprecated + * @deprecated */ public static $MAP_ID_TO_CODE = array( - 0 => 'product', - 1 => 'supplier', - 2 => 'customer', - 3 => 'member', - 4 => 'contact', - 5 => 'bank_account', - 6 => 'project', - 7 => 'user', - 8 => 'bank_line', - 9 => 'warehouse', - 10 => 'actioncomm', - 11 => 'website_page', - 12 => 'ticket', - 13 => 'knowledgemanagement' + // 0 => 'product', + // 1 => 'supplier', + // 2 => 'customer', + // 3 => 'member', + // 4 => 'contact', + // 5 => 'bank_account', + // 6 => 'project', + // 7 => 'user', + // 8 => 'bank_line', + // 9 => 'warehouse', + // 10 => 'actioncomm', + // 11 => 'website_page', + // 12 => 'ticket', + // 13 => 'knowledgemanagement' ); /** @@ -139,20 +140,20 @@ class Categorie extends CommonObject * @note Move to const array when PHP 5.6 will be our minimum target */ public $MAP_OBJ_CLASS = array( - 'product' => 'Product', - 'customer' => 'Societe', - 'supplier' => 'Fournisseur', - 'member' => 'Adherent', - 'contact' => 'Contact', - 'user' => 'User', - 'account' => 'Account', // old for bank account - 'bank_account' => 'Account', - 'project' => 'Project', - 'warehouse'=> 'Entrepot', - 'actioncomm' => 'ActionComm', - 'website_page' => 'WebsitePage', - 'ticket' => 'Ticket', - 'knowledgemanagement' => 'KnowledgeRecord' + // 'product' => 'Product', + // 'customer' => 'Societe', + // 'supplier' => 'Fournisseur', + // 'member' => 'Adherent', + // 'contact' => 'Contact', + // 'user' => 'User', + // 'account' => 'Account', // old for bank account + // 'bank_account' => 'Account', + // 'project' => 'Project', + // 'warehouse'=> 'Entrepot', + // 'actioncomm' => 'ActionComm', + // 'website_page' => 'WebsitePage', + // 'ticket' => 'Ticket', + // 'knowledgemanagement' => 'KnowledgeRecord' ); /** @@ -276,6 +277,8 @@ public function __construct($db) $this->db = $db; + $this->getMapId(); + if (is_object($hookmanager)) { $hookmanager->initHooks(array('category')); $parameters = array(); @@ -295,6 +298,23 @@ public function __construct($db) } } + /** + * getMapId from table llx_c_category + * @return void + */ + private function getMapId() + { + $resql = $this->db->query('SELECT id, module, classname FROM '.$this->db->prefix().'c_category'); + if ($resql) { + while ($obj = $this->db->fetch_object($resql)) { + $this->MAP_ID[$obj->module] = $obj->id; + $this->MAP_ID_TO_CODE[$obj->id] = $obj->module; + $this->MAP_OBJ_CLASS[$obj->module] = $obj->classname; + } + } + + } + /** * Get map list * diff --git a/htdocs/install/mysql/data/llx_c_category.sql b/htdocs/install/mysql/data/llx_c_category.sql index 8bbac804938b5..359e9f2f29192 100644 --- a/htdocs/install/mysql/data/llx_c_category.sql +++ b/htdocs/install/mysql/data/llx_c_category.sql @@ -17,17 +17,17 @@ -- Do not place a comment at the end of the line, this file is parsed during -- installation and all '--' symbols are removed. -- -INSERT INTO llx_c_category (rowid,module,classname) VALUES (0, 'product', 'Product'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (1, 'supplier', 'Fournisseur'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (2, 'customer', 'Societe'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (3, 'member', 'Adherent'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (4, 'contact', 'Contact'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (5, 'bank_account', 'Account'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (6, 'project', 'Project'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (7, 'user', 'User'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (8, 'bank_line', 'AccountLine'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (9, 'warehouse', 'Entrepot'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (10, 'actioncomm', 'Actioncomm'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (11, 'website_page', 'WebsitePage'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (12, 'ticket', 'Ticket'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (13, 'knowledgemanagement', 'KnowledgeRecord'); +INSERT INTO llx_c_category (id,module,classname) VALUES (0, 'product', 'Product'); +INSERT INTO llx_c_category (id,module,classname) VALUES (1, 'supplier', 'Fournisseur'); +INSERT INTO llx_c_category (id,module,classname) VALUES (2, 'customer', 'Societe'); +INSERT INTO llx_c_category (id,module,classname) VALUES (3, 'member', 'Adherent'); +INSERT INTO llx_c_category (id,module,classname) VALUES (4, 'contact', 'Contact'); +INSERT INTO llx_c_category (id,module,classname) VALUES (5, 'bank_account', 'Account'); +INSERT INTO llx_c_category (id,module,classname) VALUES (6, 'project', 'Project'); +INSERT INTO llx_c_category (id,module,classname) VALUES (7, 'user', 'User'); +INSERT INTO llx_c_category (id,module,classname) VALUES (8, 'bank_line', 'AccountLine'); +INSERT INTO llx_c_category (id,module,classname) VALUES (9, 'warehouse', 'Entrepot'); +INSERT INTO llx_c_category (id,module,classname) VALUES (10, 'actioncomm', 'Actioncomm'); +INSERT INTO llx_c_category (id,module,classname) VALUES (11, 'website_page', 'WebsitePage'); +INSERT INTO llx_c_category (id,module,classname) VALUES (12, 'ticket', 'Ticket'); +INSERT INTO llx_c_category (id,module,classname) VALUES (13, 'knowledgemanagement', 'KnowledgeRecord'); diff --git a/htdocs/install/mysql/migration/18.0.0-19.0.0.sql b/htdocs/install/mysql/migration/18.0.0-19.0.0.sql index 07da35f94ecb5..d8f7454ccd3dd 100644 --- a/htdocs/install/mysql/migration/18.0.0-19.0.0.sql +++ b/htdocs/install/mysql/migration/18.0.0-19.0.0.sql @@ -36,26 +36,28 @@ CREATE TABLE llx_c_category ( rowid integer AUTO_INCREMENT PRIMARY KEY NOT NULL, + id integer NOT NULL, classname varchar(32) NOT NULL, module varchar(32) NOT NULL )ENGINE=innodb; ALTER TABLE llx_c_category ADD UNIQUE INDEX uk_c_module(module); +ALTER TABLE llx_c_category ADD UNIQUE INDEX idx_id_idx (id); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (0, 'product', 'Product'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (1, 'supplier', 'Fournisseur'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (2, 'customer', 'Societe'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (3, 'member', 'Adherent'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (4, 'contact', 'Contact'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (5, 'bank_account', 'Account'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (6, 'project', 'Project'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (7, 'user', 'User'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (8, 'bank_line', 'AccountLine'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (9, 'warehouse', 'Entrepot'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (10, 'actioncomm', 'Actioncomm'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (11, 'website_page', 'WebsitePage'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (12, 'ticket', 'Ticket'); -INSERT INTO llx_c_category (rowid,module,classname) VALUES (13, 'knowledgemanagement', 'KnowledgeRecord'); +INSERT INTO llx_c_category (id,module,classname) VALUES (0, 'product', 'Product'); +INSERT INTO llx_c_category (id,module,classname) VALUES (1, 'supplier', 'Fournisseur'); +INSERT INTO llx_c_category (id,module,classname) VALUES (2, 'customer', 'Societe'); +INSERT INTO llx_c_category (id,module,classname) VALUES (3, 'member', 'Adherent'); +INSERT INTO llx_c_category (id,module,classname) VALUES (4, 'contact', 'Contact'); +INSERT INTO llx_c_category (id,module,classname) VALUES (5, 'bank_account', 'Account'); +INSERT INTO llx_c_category (id,module,classname) VALUES (6, 'project', 'Project'); +INSERT INTO llx_c_category (id,module,classname) VALUES (7, 'user', 'User'); +INSERT INTO llx_c_category (id,module,classname) VALUES (8, 'bank_line', 'AccountLine'); +INSERT INTO llx_c_category (id,module,classname) VALUES (9, 'warehouse', 'Entrepot'); +INSERT INTO llx_c_category (id,module,classname) VALUES (10, 'actioncomm', 'Actioncomm'); +INSERT INTO llx_c_category (id,module,classname) VALUES (11, 'website_page', 'WebsitePage'); +INSERT INTO llx_c_category (id,module,classname) VALUES (12, 'ticket', 'Ticket'); +INSERT INTO llx_c_category (id,module,classname) VALUES (13, 'knowledgemanagement', 'KnowledgeRecord'); -- VMYSQL4.1 DROP INDEX idx_element_categorie_idx on llx_element_categorie; -- VPGSQL8.2 DROP INDEX idx_element_categorie_idx; diff --git a/htdocs/install/mysql/tables/llx_c_category.sql b/htdocs/install/mysql/tables/llx_c_category.sql index dc35cf9dd90e7..3175a1784a837 100644 --- a/htdocs/install/mysql/tables/llx_c_category.sql +++ b/htdocs/install/mysql/tables/llx_c_category.sql @@ -19,7 +19,7 @@ CREATE TABLE llx_c_category ( rowid integer AUTO_INCREMENT PRIMARY KEY NOT NULL, + id integer NOT NULL, classname varchar(32) NOT NULL, module varchar(32) NULL )ENGINE=innodb; - From bf7b40fed7502abb62f73d463711985b790b4b24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Fri, 7 Jul 2023 16:58:25 +0200 Subject: [PATCH 13/69] wip unify categories --- htdocs/categories/class/categorie.class.php | 2 +- htdocs/categories/edit.php | 2 +- htdocs/categories/index.php | 2 +- htdocs/categories/info.php | 2 +- htdocs/categories/photos.php | 2 +- htdocs/categories/traduction.php | 2 +- htdocs/categories/viewcat.php | 2 +- htdocs/core/class/extrafields.class.php | 6 +++-- htdocs/core/modules/modCategorie.class.php | 29 +++++++++++---------- htdocs/takepos/admin/orderprinters.php | 3 ++- 10 files changed, 28 insertions(+), 24 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 2552667670053..05b2c1ddafbc2 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -1519,7 +1519,7 @@ public function containing($id, $type, $mode = 'object') $cats = array(); if (is_numeric($type)) { - $type = Categorie::$MAP_ID_TO_CODE[$type]; + $type = $this->MAP_ID_TO_CODE[$type]; } if ($type === Categorie::TYPE_BANK_LINE) { // TODO Remove this with standard category code after migration of llx_bank_categ into llx_categorie diff --git a/htdocs/categories/edit.php b/htdocs/categories/edit.php index b21d0a1c27cac..025c47b3f2a17 100644 --- a/htdocs/categories/edit.php +++ b/htdocs/categories/edit.php @@ -64,7 +64,7 @@ $type = $object->type; if (is_numeric($type)) { - $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility + $type = $object->MAP_ID_TO_CODE[$type]; // For backward compatibility } $extrafields = new ExtraFields($db); diff --git a/htdocs/categories/index.php b/htdocs/categories/index.php index 69747248906d5..0a6c8a13530b8 100644 --- a/htdocs/categories/index.php +++ b/htdocs/categories/index.php @@ -43,7 +43,7 @@ $categstatic = new Categorie($db); if (is_numeric($type)) { - $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility + $type = $categstatic->MAP_ID_TO_CODE[$type]; // For backward compatibility } // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array diff --git a/htdocs/categories/info.php b/htdocs/categories/info.php index f5f63091f9cbc..e353da64a962f 100644 --- a/htdocs/categories/info.php +++ b/htdocs/categories/info.php @@ -54,7 +54,7 @@ $type = $object->type; if (is_numeric($type)) { - $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility + $type = $object->MAP_ID_TO_CODE[$type]; // For backward compatibility } /* diff --git a/htdocs/categories/photos.php b/htdocs/categories/photos.php index bd98afb87f7cb..dfeec0f5c99bd 100644 --- a/htdocs/categories/photos.php +++ b/htdocs/categories/photos.php @@ -58,7 +58,7 @@ $type = $object->type; if (is_numeric($type)) { - $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility + $type = $object->MAP_ID_TO_CODE[$type]; // For backward compatibility } $upload_dir = $conf->categorie->multidir_output[$object->entity]; diff --git a/htdocs/categories/traduction.php b/htdocs/categories/traduction.php index b63431780e75b..e0487db7806a0 100644 --- a/htdocs/categories/traduction.php +++ b/htdocs/categories/traduction.php @@ -57,7 +57,7 @@ $type = $object->type; if (is_numeric($type)) { - $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility + $type = $object->MAP_ID_TO_CODE[$type]; // For backward compatibility } diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php index 2ce3706d2164f..99a6b1839196b 100644 --- a/htdocs/categories/viewcat.php +++ b/htdocs/categories/viewcat.php @@ -81,7 +81,7 @@ $type = $object->type; if (is_numeric($type)) { - $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility + $type = $object->MAP_ID_TO_CODE[$type]; // For backward compatibility } $extrafields = new ExtraFields($db); diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 8e74a7c13eb58..4f0b0a1c64f98 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -1318,7 +1318,8 @@ public function showInputField($key, $value, $moreparam = '', $keysuffix = '', $ } } else { require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; - $data = $form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]], '', 'parent', 64, $InfoFieldList[6], 1, 1); + $categorystatic = new Categorie($this->db); + $data = $form->select_all_categories($categorystatic->MAP_ID_TO_CODE[$InfoFieldList[5]], '', 'parent', 64, $InfoFieldList[6], 1, 1); $out .= ''; if (is_array($data)) { foreach ($data as $data_key => $data_value) { @@ -1547,7 +1548,8 @@ public function showInputField($key, $value, $moreparam = '', $keysuffix = '', $ } } else { require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; - $data = $form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]], '', 'parent', 64, $InfoFieldList[6], 1, 1); + $categorystatic = new Categorie($this->db); + $data = $form->select_all_categories($categorystatic->MAP_ID_TO_CODE[$InfoFieldList[5]], '', 'parent', 64, $InfoFieldList[6], 1, 1); $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); } } diff --git a/htdocs/core/modules/modCategorie.class.php b/htdocs/core/modules/modCategorie.class.php index ed84a7e9c4bc9..44e992bcf6096 100644 --- a/htdocs/core/modules/modCategorie.class.php +++ b/htdocs/core/modules/modCategorie.class.php @@ -177,7 +177,8 @@ public function __construct($db) // 0 Products $r++; - $this->export_code[$r] = $this->rights_class.'_0_'.Categorie::$MAP_ID_TO_CODE[0]; + $categorystatic = new Categorie($this->db); + $this->export_code[$r] = $this->rights_class.'_0_'.$categorystatic->MAP_ID_TO_CODE[0]; $this->export_label[$r] = 'CatProdList'; $this->export_icon[$r] = $this->picto; $this->export_enabled[$r] = 'isModEnabled("product") || isModEnabled("service")'; @@ -202,7 +203,7 @@ public function __construct($db) // 1 Suppliers $r++; - $this->export_code[$r] = $this->rights_class.'_1_'.Categorie::$MAP_ID_TO_CODE[1]; + $this->export_code[$r] = $this->rights_class.'_1_'.$categorystatic->MAP_ID_TO_CODE[1]; $this->export_label[$r] = 'CatSupList'; $this->export_icon[$r] = $this->picto; $this->export_enabled[$r] = 'isModEnabled("supplier_order") || isModEnabled("supplier_invoice")'; @@ -249,7 +250,7 @@ public function __construct($db) // 2 Customers/Prospects $r++; - $this->export_code[$r] = $this->rights_class.'_2_'.Categorie::$MAP_ID_TO_CODE[2]; + $this->export_code[$r] = $this->rights_class.'_2_'.$categorystatic->MAP_ID_TO_CODE[2]; $this->export_label[$r] = 'CatCusList'; $this->export_icon[$r] = $this->picto; $this->export_enabled[$r] = 'isModEnabled("societe")'; @@ -298,7 +299,7 @@ public function __construct($db) // 3 Members $r++; - $this->export_code[$r] = $this->rights_class.'_3_'.Categorie::$MAP_ID_TO_CODE[3]; + $this->export_code[$r] = $this->rights_class.'_3_'.$categorystatic->MAP_ID_TO_CODE[3]; $this->export_label[$r] = 'CatMemberList'; $this->export_icon[$r] = $this->picto; $this->export_enabled[$r] = 'isModEnabled("adherent")'; @@ -323,7 +324,7 @@ public function __construct($db) // 4 Contacts $r++; - $this->export_code[$r] = $this->rights_class.'_4_'.Categorie::$MAP_ID_TO_CODE[4]; + $this->export_code[$r] = $this->rights_class.'_4_'.$categorystatic->MAP_ID_TO_CODE[4]; $this->export_label[$r] = 'CatContactList'; $this->export_icon[$r] = $this->picto; $this->export_enabled[$r] = 'isModEnabled("societe")'; @@ -382,7 +383,7 @@ public function __construct($db) // 6 Projects $r++; - $this->export_code[$r] = $this->rights_class.'_6_'.Categorie::$MAP_ID_TO_CODE[6]; + $this->export_code[$r] = $this->rights_class.'_6_'.$categorystatic->MAP_ID_TO_CODE[6]; $this->export_label[$r] = 'CatProjectsList'; $this->export_icon[$r] = $this->picto; $this->export_enabled[$r] = "isModEnabled('project')"; @@ -408,7 +409,7 @@ public function __construct($db) // 7 Users $r++; - $this->export_code[$r] = $this->rights_class.'_7_'.Categorie::$MAP_ID_TO_CODE[7]; + $this->export_code[$r] = $this->rights_class.'_7_'.$categorystatic->MAP_ID_TO_CODE[7]; $this->export_label[$r] = 'CatUsersList'; $this->export_icon[$r] = $this->picto; $this->export_enabled[$r] = 'isModEnabled("user")'; @@ -476,7 +477,7 @@ public function __construct($db) // 0 Products if (isModEnabled("product")) { $r++; - $this->import_code[$r] = $this->rights_class.'_0_'.Categorie::$MAP_ID_TO_CODE[0]; + $this->import_code[$r] = $this->rights_class.'_0_'.$categorystatic->MAP_ID_TO_CODE[0]; $this->import_label[$r] = "CatProdLinks"; // Translation key $this->import_icon[$r] = $this->picto; $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon @@ -495,7 +496,7 @@ public function __construct($db) // 1 Suppliers if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) { $r++; - $this->import_code[$r] = $this->rights_class.'_1_'.Categorie::$MAP_ID_TO_CODE[1]; + $this->import_code[$r] = $this->rights_class.'_1_'.$categorystatic->MAP_ID_TO_CODE[1]; $this->import_label[$r] = "CatSupLinks"; // Translation key $this->import_icon[$r] = $this->picto; $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon @@ -516,7 +517,7 @@ public function __construct($db) // 2 Customers if (isModEnabled("societe")) { $r++; - $this->import_code[$r] = $this->rights_class.'_2_'.Categorie::$MAP_ID_TO_CODE[2]; + $this->import_code[$r] = $this->rights_class.'_2_'.$categorystatic->MAP_ID_TO_CODE[2]; $this->import_label[$r] = "CatCusLinks"; // Translation key $this->import_icon[$r] = $this->picto; $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon @@ -537,7 +538,7 @@ public function __construct($db) // 3 Members if (isModEnabled('adherent')) { $r++; - $this->import_code[$r] = $this->rights_class.'_3_'.Categorie::$MAP_ID_TO_CODE[3]; + $this->import_code[$r] = $this->rights_class.'_3_'.$categorystatic->MAP_ID_TO_CODE[3]; $this->import_label[$r] = "CatMembersLinks"; // Translation key $this->import_icon[$r] = $this->picto; $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon @@ -555,7 +556,7 @@ public function __construct($db) // 4 Contacts/Addresses if (isModEnabled("societe")) { $r++; - $this->import_code[$r] = $this->rights_class.'_4_'.Categorie::$MAP_ID_TO_CODE[4]; + $this->import_code[$r] = $this->rights_class.'_4_'.$categorystatic->MAP_ID_TO_CODE[4]; $this->import_label[$r] = "CatContactsLinks"; // Translation key $this->import_icon[$r] = $this->picto; $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon @@ -578,7 +579,7 @@ public function __construct($db) // 6 Projects if (isModEnabled('project')) { $r++; - $this->import_code[$r] = $this->rights_class.'_6_'.Categorie::$MAP_ID_TO_CODE[6]; + $this->import_code[$r] = $this->rights_class.'_6_'.$categorystatic->MAP_ID_TO_CODE[6]; $this->import_label[$r] = "CatProjectsLinks"; // Translation key $this->import_icon[$r] = $this->picto; $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon @@ -596,7 +597,7 @@ public function __construct($db) // 7 Users if (isModEnabled('user')) { $r++; - $this->import_code[$r] = $this->rights_class.'_7_'.Categorie::$MAP_ID_TO_CODE[7]; + $this->import_code[$r] = $this->rights_class.'_7_'.$categorystatic->MAP_ID_TO_CODE[7]; $this->import_label[$r] = "CatUsersLinks"; // Translation key $this->import_icon[$r] = $this->picto; $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon diff --git a/htdocs/takepos/admin/orderprinters.php b/htdocs/takepos/admin/orderprinters.php index e851573cba46f..4ee5a3ae58df5 100644 --- a/htdocs/takepos/admin/orderprinters.php +++ b/htdocs/takepos/admin/orderprinters.php @@ -44,7 +44,8 @@ $printer3 = GETPOST('printer3', 'alpha'); if (is_numeric($type)) { - $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility + $categorystatic = new Categorie($db); + $type = $categorystatic->MAP_ID_TO_CODE[$type]; // For backward compatibility } if (!$user->hasRight('categorie', 'lire')) { From b564b682859f93e9058d997af9ac50c9b8d7853e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Fri, 7 Jul 2023 18:02:38 +0200 Subject: [PATCH 14/69] unify categories --- htdocs/core/class/commonobject.class.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index c9d8f89703a76..f6c08ebcbe2f4 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -7146,7 +7146,8 @@ public function showInputField($val, $key, $value, $moreparam = '', $keysuffix = } } else { require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; - $data = $form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]], '', 'parent', 64, $InfoFieldList[6], 1, 1); + $categorystatic = new Categorie($this->db); + $data = $form->select_all_categories($categorystatic->MAP_ID_TO_CODE[$InfoFieldList[5]], '', 'parent', 64, $InfoFieldList[6], 1, 1); $out .= ''; foreach ($data as $data_key => $data_value) { $out .= '