From 4a5d89e6cc0d58d8cf8c860ff24d6a9501b742fa Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 22 Aug 2012 17:33:09 +0200 Subject: [PATCH] Fix: move barcode type entries in module descriptor for best compatibility with multicompany --- htdocs/admin/barcode.php | 12 +++--- htdocs/core/modules/DolibarrModules.class.php | 5 ++- htdocs/core/modules/modBarcode.class.php | 13 +++++-- .../install/mysql/data/llx_c_barcode_type.sql | 37 ------------------- .../install/mysql/migration/3.1.0-3.2.0.sql | 2 + .../install/mysql/migration/3.2.0-3.3.0.sql | 2 + .../mysql/tables/llx_c_barcode_type.key.sql | 19 ++++++++++ 7 files changed, 43 insertions(+), 47 deletions(-) delete mode 100644 htdocs/install/mysql/data/llx_c_barcode_type.sql create mode 100755 htdocs/install/mysql/tables/llx_c_barcode_type.key.sql diff --git a/htdocs/admin/barcode.php b/htdocs/admin/barcode.php index 39e059d3c97..3670f766b68 100644 --- a/htdocs/admin/barcode.php +++ b/htdocs/admin/barcode.php @@ -1,8 +1,8 @@ - * Copyright (C) 2004-2011 Laurent Destailleur - * Copyright (C) 2005-2009 Regis Houssin - * Copyright (C) 2011 Juanjo Menent +/* Copyright (C) 2003-2004 Rodolphe Quiedeville + * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2011 Juanjo Menent * * 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 @@ -108,11 +108,11 @@ clearstatcache(); // Scan list of all barcode included provided by external modules -$dirbarcode=array_merge(array("/core/modules/barcode/"),$conf->modules_parts['barcode']); +$dirbarcode=array_merge(array("/core/modules/barcode/"), $conf->modules_parts['barcode']); foreach($dirbarcode as $reldir) { - $dir=dol_buildpath($reldir,0); + $dir=dol_buildpath($reldir); $newdir=dol_osencode($dir); // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php) diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index 5653c8977cd..843f7e40cac 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -62,7 +62,7 @@ abstract class DolibarrModules */ function _init($array_sql, $options='') { - global $langs; + global $conf, $langs; $err=0; $this->db->begin(); @@ -113,6 +113,9 @@ abstract class DolibarrModules $sql=$val; } + // Add current entity id + $sql=str_replace('__ENTITY__', $conf->entity, $sql); + dol_syslog(get_class($this)."::_init ignoreerror=".$ignoreerror." sql=".$sql, LOG_DEBUG); $result=$this->db->query($sql); if (! $result) diff --git a/htdocs/core/modules/modBarcode.class.php b/htdocs/core/modules/modBarcode.class.php index 34cd7aac886..aef4e0426d4 100644 --- a/htdocs/core/modules/modBarcode.class.php +++ b/htdocs/core/modules/modBarcode.class.php @@ -112,9 +112,16 @@ class modBarcode extends DolibarrModules // Permissions $this->remove($options); - $sql = array(); + $sql = array( + array('sql'=>'INSERT INTO llx_c_barcode_type (code, libelle, coder, example, entity) VALUES ("EAN8", "EAN8", 0, "1234567", __ENTITY__)','ignoreerror'=>1), + array('sql'=>'INSERT INTO llx_c_barcode_type (code, libelle, coder, example, entity) VALUES ("EAN13", "EAN13", 0, "123456789012", __ENTITY__)','ignoreerror'=>1), + array('sql'=>'INSERT INTO llx_c_barcode_type (code, libelle, coder, example, entity) VALUES ("UPC", "UPC", 0, "123456789012", __ENTITY__)','ignoreerror'=>1), + array('sql'=>'INSERT INTO llx_c_barcode_type (code, libelle, coder, example, entity) VALUES ("ISBN", "ISBN", 0, "123456789", __ENTITY__)','ignoreerror'=>1), + array('sql'=>'INSERT INTO llx_c_barcode_type (code, libelle, coder, example, entity) VALUES ("C39", "Code 39", 0, "1234567890", __ENTITY__)','ignoreerror'=>1), + array('sql'=>'INSERT INTO llx_c_barcode_type (code, libelle, coder, example, entity) VALUES ("C128", "Code 128", 0, "ABCD1234567890", __ENTITY__)','ignoreerror'=>1) + ); - return $this->_init($sql,$options); + return $this->_init($sql, $options); } /** @@ -129,7 +136,7 @@ class modBarcode extends DolibarrModules { $sql = array(); - return $this->_remove($sql,$options); + return $this->_remove($sql, $options); } } diff --git a/htdocs/install/mysql/data/llx_c_barcode_type.sql b/htdocs/install/mysql/data/llx_c_barcode_type.sql deleted file mode 100644 index af10d8d1e76..00000000000 --- a/htdocs/install/mysql/data/llx_c_barcode_type.sql +++ /dev/null @@ -1,37 +0,0 @@ --- Copyright (C) 2001-2004 Rodolphe Quiedeville --- Copyright (C) 2003 Jean-Louis Bergamo --- Copyright (C) 2004-2009 Laurent Destailleur --- Copyright (C) 2004 Benoit Mortier --- Copyright (C) 2004 Guillaume Delecourt --- Copyright (C) 2005-2009 Regis Houssin --- Copyright (C) 2007 Patrick Raguin --- --- 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 2 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 . --- --- - --- --- Ne pas placer de commentaire en fin de ligne, ce fichier est parsé lors --- de l'install et tous les sigles '--' sont supprimés. --- - --- --- Codes barres --- -INSERT INTO llx_c_barcode_type (rowid, code, libelle, coder, example) VALUES (1, 'EAN8', 'EAN8', 0, '1234567'); -INSERT INTO llx_c_barcode_type (rowid, code, libelle, coder, example) VALUES (2, 'EAN13', 'EAN13', 0, '123456789012'); -INSERT INTO llx_c_barcode_type (rowid, code, libelle, coder, example) VALUES (3, 'UPC', 'UPC', 0, '123456789012'); -INSERT INTO llx_c_barcode_type (rowid, code, libelle, coder, example) VALUES (4, 'ISBN', 'ISBN', 0, '123456789'); -INSERT INTO llx_c_barcode_type (rowid, code, libelle, coder, example) VALUES (5, 'C39', 'Code 39', 0, '1234567890'); -INSERT INTO llx_c_barcode_type (rowid, code, libelle, coder, example) VALUES (6, 'C128', 'Code 128', 0, 'ABCD1234567890'); diff --git a/htdocs/install/mysql/migration/3.1.0-3.2.0.sql b/htdocs/install/mysql/migration/3.1.0-3.2.0.sql index 39d346c1de2..2f2e8982614 100755 --- a/htdocs/install/mysql/migration/3.1.0-3.2.0.sql +++ b/htdocs/install/mysql/migration/3.1.0-3.2.0.sql @@ -460,3 +460,5 @@ UPDATE llx_product SET canvas = NULL where canvas = 'product@product'; UPDATE llx_product SET canvas = NULL where canvas = 'service@product'; DELETE FROM llx_const WHERE __DECRYPT('name')__ = 'SOCIETE_CODECOMPTA_ADDON' AND __DECRYPT('value')__ = 'mod_codecompta_digitaria'; + +ALTER TABLE llx_c_barcode_type ADD UNIQUE INDEX uk_c_barcode_type(code, entity); diff --git a/htdocs/install/mysql/migration/3.2.0-3.3.0.sql b/htdocs/install/mysql/migration/3.2.0-3.3.0.sql index 775447fc03f..e1d124eee8b 100755 --- a/htdocs/install/mysql/migration/3.2.0-3.3.0.sql +++ b/htdocs/install/mysql/migration/3.2.0-3.3.0.sql @@ -69,3 +69,5 @@ ALTER TABLE llx_propal CHANGE fk_demand_reason fk_input_reason INT(11) NULL DEFA ALTER TABLE llx_commande_fournisseur CHANGE fk_methode_commande fk_input_method INT(11) NULL DEFAULT 0; INSERT INTO llx_const (name, value, type, note, visible) values ('PRODUCT_CODEPRODUCT_ADDON','mod_codeproduct_leopard','yesno','Module to control product codes',0); + +ALTER TABLE llx_c_barcode_type ADD UNIQUE INDEX uk_c_barcode_type(code, entity); diff --git a/htdocs/install/mysql/tables/llx_c_barcode_type.key.sql b/htdocs/install/mysql/tables/llx_c_barcode_type.key.sql new file mode 100755 index 00000000000..ca4cf7fc898 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_c_barcode_type.key.sql @@ -0,0 +1,19 @@ +-- ======================================================================== +-- Copyright (C) 2012 Regis Houssin +-- +-- 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 2 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_barcode_type ADD UNIQUE INDEX uk_c_barcode_type(code, entity);