From d46417c8bd907df8cb9292c05a151fe9f3705b14 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 3 Apr 2020 17:53:17 +0200 Subject: [PATCH] FIX #13482 --- htdocs/modulebuilder/index.php | 20 ++++++++++++++++--- .../template/class/myobject.class.php | 6 +++--- .../mymodule/mod_myobject_advanced.php | 15 +++++++++----- .../mymodule/mod_myobject_standard.php | 19 ++++++++++++++---- 4 files changed, 45 insertions(+), 15 deletions(-) diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 313eb65e727..31d593926d1 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -888,17 +888,31 @@ if ($dirins && $action == 'initobject' && $module && $objectname) // Edit the class 'class/'.strtolower($objectname).'.class.php' if (GETPOST('includerefgeneration', 'aZ09')) { // Replace 'visible'=>1, 'noteditable'=>0, 'default'=>'' - $arrayreplacement = array('/\'visible\'=>1,\s*\'noteditable\'=>0,\s*\'default\'=>\'\'/' => "'visible'=>4, 'noteditable'=>1, 'default'=>'(PROV)'"); + $arrayreplacement = array( + '/\'visible\'=>1,\s*\'noteditable\'=>0,\s*\'default\'=>\'\'/' => "'visible'=>4, 'noteditable'=>1, 'default'=>'(PROV)'" + ); //var_dump($arrayreplacement);exit; //var_dump($destdir.'/class/'.strtolower($objectname).'.class.php');exit; dolReplaceInFile($destdir.'/class/'.strtolower($objectname).'.class.php', $arrayreplacement, '', 0, 0, 1); + + $arrayreplacement = array( + '/\'models\' => 0,/' => '\'models\' => 1,' + ); + dolReplaceInFile($destdir.'/core/modules/mod'.$module.'.class.php', $arrayreplacement, '', 0, 0, 1); } // Edit the setup file and the card page if (GETPOST('includedocgeneration', 'aZ09')) { - // Replace '$includedocgeneration = 0;' into '$includedocgeneration = 1;' into files - $arrayreplacement = array('/\$includedocgeneration = 0;/' => '$includedocgeneration = 1;'); + // Replace some var init into some files + $arrayreplacement = array( + '/\$includedocgeneration = 0;/' => '$includedocgeneration = 1;' + ); dolReplaceInFile($destdir.'/class/'.strtolower($objectname).'.class.php', $arrayreplacement, '', 0, 0, 1); + + $arrayreplacement = array( + '/\'models\' => 0,/' => '\'models\' => 1,' + ); + dolReplaceInFile($destdir.'/core/modules/mod'.$module.'.class.php', $arrayreplacement, '', 0, 0, 1); } // Scan for object class files diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index f893e244a7c..97997a57542 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -922,7 +922,7 @@ class MyObject extends CommonObject $langs->load("mymodule@myobject"); if (empty($conf->global->MYMODULE_MYOBJECT_ADDON)) { - $conf->global->MYMODULE_MYOBJECT_ADDON = 'mod_mymobject_standard'; + $conf->global->MYMODULE_MYOBJECT_ADDON = 'mod_myobject_standard'; } if (!empty($conf->global->MYMODULE_MYOBJECT_ADDON)) @@ -952,7 +952,7 @@ class MyObject extends CommonObject $obj = new $classname(); $numref = $obj->getNextValue($this); - if ($numref != "") + if ($numref != '' && $numref != '-1') { return $numref; } @@ -963,7 +963,7 @@ class MyObject extends CommonObject return ""; } } else { - print $langs->trans("Error")." ".$langs->trans("ClassNotFound"); + print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname; return ""; } } diff --git a/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php b/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php index 26866a6b9f1..33edc24e983 100644 --- a/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php +++ b/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php @@ -100,13 +100,18 @@ class mod_myobject_advanced extends ModeleNumRefMyObject { global $conf,$langs,$mysoc; - $old_code_client=$mysoc->code_client; + $object = new MyObject($this->db); + $object->initAsSpecimen(); + + /*$old_code_client=$mysoc->code_client; $old_code_type=$mysoc->typent_code; $mysoc->code_client='CCCCCCCCCC'; - $mysoc->typent_code='TTTTTTTTTT'; - $numExample = $this->getNextValue($mysoc, ''); - $mysoc->code_client=$old_code_client; - $mysoc->typent_code=$old_code_type; + $mysoc->typent_code='TTTTTTTTTT';*/ + + $numExample = $this->getNextValue($object, ''); + + /*$mysoc->code_client=$old_code_client; + $mysoc->typent_code=$old_code_type;*/ if (! $numExample) { diff --git a/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_standard.php b/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_standard.php index e18e7636b6d..a213fee7174 100644 --- a/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_standard.php +++ b/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_standard.php @@ -76,9 +76,10 @@ class mod_myobject_standard extends ModeleNumRefMyObject * Checks if the numbers already in force in the data base do not * cause conflicts that would prevent this numbering from working. * - * @return boolean false if conflict, true if ok + * @param Object $object Object we need next value for + * @return boolean false if conflict, true if ok */ - public function canBeActivated() + public function canBeActivated($object) { global $conf,$langs,$db; @@ -88,7 +89,12 @@ class mod_myobject_standard extends ModeleNumRefMyObject $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; $sql.= " FROM ".MAIN_DB_PREFIX."mymodule_myobject"; $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; - $sql.= " AND entity = ".$conf->entity; + if ($object->ismultientitymanaged == 1) { + $sql.= " AND entity = ".$conf->entity; + } + elseif ($object->ismultientitymanaged == 2) { + // TODO + } $resql=$db->query($sql); if ($resql) @@ -121,7 +127,12 @@ class mod_myobject_standard extends ModeleNumRefMyObject $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; $sql.= " FROM ".MAIN_DB_PREFIX."mymodule_myobject"; $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; - $sql.= " AND entity = ".$conf->entity; + if ($object->ismultientitymanaged == 1) { + $sql.= " AND entity = ".$conf->entity; + } + elseif ($object->ismultientitymanaged == 2) { + // TODO + } $resql=$db->query($sql); if ($resql)