From 46d2e741bf73c43c4852c96b991e4e90b9a74460 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Morfin Date: Mon, 3 Apr 2023 14:29:00 +0200 Subject: [PATCH] Sur la branche master: secure installation if extra fields already exist --- core/modules/modCDav.class.php | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/core/modules/modCDav.class.php b/core/modules/modCDav.class.php index 5310c38..334cf6f 100644 --- a/core/modules/modCDav.class.php +++ b/core/modules/modCDav.class.php @@ -58,7 +58,7 @@ function __construct($db) // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module) $this->description = "Allows caldav and carddav clients to sync with Dolibarr."; // Possible values for version are: 'development', 'experimental', 'dolibarr' or version - $this->version = '2.23'; + $this->version = '2.24'; // Key used in llx_const table to save module status enabled/disabled (where CDAV is value of property name of module in uppercase) $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); // Where to store the module in setup page (0=common,1=interface,2=others,3=very specific) @@ -310,22 +310,28 @@ function init($options='') // Create 2 extrafields include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $extrafields_cmd = new ExtraFields($this->db); - //function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique=0, $required=0, $default_value='', $param='', $alwayseditable=0, $perms='', $list='-1', $help='', $computed='', $entity='', $langfile='', $enabled='1') - $result_cmd=$extrafields_cmd->addExtraField('cdav_duration', $langs->trans("DurationEx"), 'varchar', 1, '10', 'commandedet', 0, 0, '', '', 1, '', '1'); - if( ! $result_cmd ) + + try { - $this->error=$extrafields_cmd->error; - return -1; + //function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique=0, $required=0, $default_value='', $param='', $alwayseditable=0, $perms='', $list='-1', $help='', $computed='', $entity='', $langfile='', $enabled='1') + $result_cmd=$extrafields_cmd->addExtraField('cdav_duration', $langs->trans("DurationEx"), 'varchar', 1, '10', 'commandedet', 0, 0, '', '', 1, '', '1'); + if( ! $result_cmd ) + { + $this->error=$extrafields_cmd->error; + } + $extrafields_prop = new ExtraFields($this->db); + $result_prop=$extrafields_prop->addExtraField('cdav_duration', $langs->trans("DurationEx"), 'varchar', 1, '10', 'propaldet', 0, 0, '', '', 1, '', '1'); + if( ! $result_prop ) + { + $this->error=$extrafields_prop->error; + } + + $result=$this->_load_tables('/cdav/sql/'); } - $extrafields_prop = new ExtraFields($this->db); - $result_prop=$extrafields_prop->addExtraField('cdav_duration', $langs->trans("DurationEx"), 'varchar', 1, '10', 'propaldet', 0, 0, '', '', 1, '', '1'); - if( ! $result_prop ) + catch(Exception $ex) { - $this->error=$extrafields_prop->error; - return -1; + $this->error = $ex->getMessage(); } - - $result=$this->_load_tables('/cdav/sql/'); return $this->_init($sql, $options); }