mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-07 10:08:27 +01:00
Debug
This commit is contained in:
@@ -30,7 +30,7 @@
|
|||||||
* @param string $objectname Name of object
|
* @param string $objectname Name of object
|
||||||
* @param string $newmask New mask
|
* @param string $newmask New mask
|
||||||
* @param string $readdir Directory source (use $destdir when not defined)
|
* @param string $readdir Directory source (use $destdir when not defined)
|
||||||
* @param string $addfieldentry Array of the field entry to add array('key'=>,'type'=>,''label'=>,'visible'=>,'enabled'=>,'position'=>,'notnull'=>','index'=>,'searchall'=>,'comment'=>,'help'=>,'isameasure')
|
* @param string $addfieldentry Array of 1 field entry to add array('key'=>,'type'=>,''label'=>,'visible'=>,'enabled'=>,'position'=>,'notnull'=>','index'=>,'searchall'=>,'comment'=>,'help'=>,'isameasure')
|
||||||
* @param string $delfieldentry Id of field to remove
|
* @param string $delfieldentry Id of field to remove
|
||||||
* @return int|object <=0 if KO, Object if OK
|
* @return int|object <=0 if KO, Object if OK
|
||||||
* @see rebuildObjectSql()
|
* @see rebuildObjectSql()
|
||||||
@@ -40,7 +40,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
|
|||||||
global $db, $langs;
|
global $db, $langs;
|
||||||
|
|
||||||
if (empty($objectname)) {
|
if (empty($objectname)) {
|
||||||
return -1;
|
return -6;
|
||||||
}
|
}
|
||||||
if (empty($readdir)) {
|
if (empty($readdir)) {
|
||||||
$readdir = $destdir;
|
$readdir = $destdir;
|
||||||
@@ -48,9 +48,11 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
|
|||||||
|
|
||||||
if (!empty($addfieldentry['arrayofkeyval']) && !is_array($addfieldentry['arrayofkeyval'])) {
|
if (!empty($addfieldentry['arrayofkeyval']) && !is_array($addfieldentry['arrayofkeyval'])) {
|
||||||
dol_print_error('', 'Bad parameter addfieldentry with a property arrayofkeyval defined but that is not an array.');
|
dol_print_error('', 'Bad parameter addfieldentry with a property arrayofkeyval defined but that is not an array.');
|
||||||
return -1;
|
return -7;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$error = 0;
|
||||||
|
|
||||||
// Check parameters
|
// Check parameters
|
||||||
if (is_array($addfieldentry) && count($addfieldentry) > 0) {
|
if (is_array($addfieldentry) && count($addfieldentry) > 0) {
|
||||||
if (empty($addfieldentry['name'])) {
|
if (empty($addfieldentry['name'])) {
|
||||||
@@ -62,8 +64,8 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
|
|||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
if (!preg_match('/^(integer|price|sellist|varchar|double|text|html|duration)/', $addfieldentry['type'])
|
if (!preg_match('/^(integer|price|sellist|varchar|double|text|html|duration)/', $addfieldentry['type'])
|
||||||
&& !preg_match('/^(boolean|real|date|datetime|timestamp)$/', $addfieldentry['type'])) {
|
&& !preg_match('/^(boolean|smallint|real|date|datetime|timestamp|phone|mail|url|ip|password)$/', $addfieldentry['type'])) {
|
||||||
setEventMessages($langs->trans('BadValueForType', $objectname), null, 'errors');
|
setEventMessages($langs->trans('BadValueForType', $addfieldentry['type']), null, 'errors');
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -217,10 +219,14 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
|
|||||||
dol_mkdir(dirname($pathoffiletoedittarget));
|
dol_mkdir(dirname($pathoffiletoedittarget));
|
||||||
|
|
||||||
//file_put_contents($pathoffiletoedittmp, $contentclass);
|
//file_put_contents($pathoffiletoedittmp, $contentclass);
|
||||||
file_put_contents(dol_osencode($pathoffiletoedittarget), $contentclass);
|
$result = file_put_contents(dol_osencode($pathoffiletoedittarget), $contentclass);
|
||||||
@chmod($pathoffiletoedittarget, octdec($newmask));
|
if ($result) {
|
||||||
|
@chmod($pathoffiletoedittarget, octdec($newmask));
|
||||||
|
} else {
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
return $object;
|
return $error ? -1 : $object;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
print $e->getMessage();
|
print $e->getMessage();
|
||||||
return -5;
|
return -5;
|
||||||
@@ -257,13 +263,33 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = '
|
|||||||
|
|
||||||
// Edit .sql file
|
// Edit .sql file
|
||||||
if ($moduletype == 'internal') {
|
if ($moduletype == 'internal') {
|
||||||
$pathoffiletoeditsrc = $readdir.'/../install/mysql/tables/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql';
|
$pathoffiletoeditsrc = '/../install/mysql/tables/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql';
|
||||||
$pathoffiletoedittarget = $destdir.'/../install/mysql/tables/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql'.($readdir != $destdir ? '.new' : '');
|
if (! dol_is_file($readdir.$pathoffiletoeditsrc)) {
|
||||||
|
$pathoffiletoeditsrc = '/../install/mysql/tables/llx_'.strtolower($module).'_'.strtolower($objectname).'-'.strtolower($module).'.sql';
|
||||||
|
if (! dol_is_file($readdir.$pathoffiletoeditsrc)) {
|
||||||
|
$pathoffiletoeditsrc = '/../install/mysql/tables/llx_'.strtolower($module).'-'.strtolower($module).'.sql';
|
||||||
|
if (! dol_is_file($readdir.$pathoffiletoeditsrc)) {
|
||||||
|
$pathoffiletoeditsrc = '/../install/mysql/tables/llx_'.strtolower($module).'.sql';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$pathoffiletoeditsrc = $readdir.'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql';
|
$pathoffiletoeditsrc = '/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql';
|
||||||
$pathoffiletoedittarget = $destdir.'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql'.($readdir != $destdir ? '.new' : '');
|
if (! dol_is_file($readdir.$pathoffiletoeditsrc)) {
|
||||||
|
$pathoffiletoeditsrc = '/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'-'.strtolower($module).'.sql';
|
||||||
|
if (! dol_is_file($readdir.$pathoffiletoeditsrc)) {
|
||||||
|
$pathoffiletoeditsrc = '/sql/llx_'.strtolower($module).'-'.strtolower($module).'.sql';
|
||||||
|
if (! dol_is_file($readdir.$pathoffiletoeditsrc)) {
|
||||||
|
$pathoffiletoeditsrc = '/sql/llx_'.strtolower($module).'.sql';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Complete path to be full path
|
||||||
|
$pathoffiletoedittarget = $destdir.$pathoffiletoeditsrc.($readdir != $destdir ? '.new' : '');
|
||||||
|
$pathoffiletoeditsrc = $readdir.$pathoffiletoeditsrc;
|
||||||
|
|
||||||
if (!dol_is_file($pathoffiletoeditsrc)) {
|
if (!dol_is_file($pathoffiletoeditsrc)) {
|
||||||
$langs->load("errors");
|
$langs->load("errors");
|
||||||
setEventMessages($langs->trans("ErrorFileNotFound", $pathoffiletoeditsrc), null, 'errors');
|
setEventMessages($langs->trans("ErrorFileNotFound", $pathoffiletoeditsrc), null, 'errors');
|
||||||
@@ -340,16 +366,13 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = '
|
|||||||
@chmod($pathoffiletoedittarget, octdec($newmask));
|
@chmod($pathoffiletoedittarget, octdec($newmask));
|
||||||
} else {
|
} else {
|
||||||
$error++;
|
$error++;
|
||||||
|
setEventMessages($langs->trans("ErrorFailToCreateFile", $pathoffiletoedittarget), null, 'errors');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Edit .key.sql file
|
// Edit .key.sql file
|
||||||
if ($moduletype == 'internal') {
|
$pathoffiletoeditsrc = preg_replace('/\.sql$/', '.key.sql', $pathoffiletoeditsrc);
|
||||||
$pathoffiletoeditsrc = $readdir.'/../install/mysql/tables/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql';
|
$pathoffiletoedittarget = preg_replace('/\.sql$/', '.key.sql', $pathoffiletoedittarget);
|
||||||
$pathoffiletoedittarget = $destdir.'/../install/mysql/tables/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql'.($readdir != $destdir ? '.new' : '');
|
$pathoffiletoedittarget = preg_replace('/\.sql.new$/', '.key.sql.new', $pathoffiletoedittarget);
|
||||||
} else {
|
|
||||||
$pathoffiletoeditsrc = $destdir.'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql';
|
|
||||||
$pathoffiletoedittarget = $destdir.'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql'.($readdir != $destdir ? '.new' : '');
|
|
||||||
}
|
|
||||||
|
|
||||||
$contentsql = file_get_contents(dol_osencode($pathoffiletoeditsrc), 'r');
|
$contentsql = file_get_contents(dol_osencode($pathoffiletoeditsrc), 'r');
|
||||||
|
|
||||||
@@ -378,10 +401,11 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = '
|
|||||||
dol_mkdir(dirname($pathoffiletoedittarget));
|
dol_mkdir(dirname($pathoffiletoedittarget));
|
||||||
|
|
||||||
$result2 = file_put_contents($pathoffiletoedittarget, $contentsql);
|
$result2 = file_put_contents($pathoffiletoedittarget, $contentsql);
|
||||||
if ($result) {
|
if ($result2) {
|
||||||
@chmod($pathoffiletoedittarget, octdec($newmask));
|
@chmod($pathoffiletoedittarget, octdec($newmask));
|
||||||
} else {
|
} else {
|
||||||
$error++;
|
$error++;
|
||||||
|
setEventMessages($langs->trans("ErrorFailToCreateFile", $pathoffiletoedittarget), null, 'errors');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $error ? -1 : 1;
|
return $error ? -1 : 1;
|
||||||
|
|||||||
@@ -155,3 +155,4 @@ LinkToParentMenu=Parent menu (fk_xxxxmenu)
|
|||||||
ListOfTabsEntries=List of tab entries
|
ListOfTabsEntries=List of tab entries
|
||||||
TabsDefDesc=Define here the tabs provided by your module
|
TabsDefDesc=Define here the tabs provided by your module
|
||||||
TabsDefDescTooltip=The tabs provided by your module/application are defined into the array <strong>$this->tabs</strong> into the module descriptor file. You can edit manually this file or use the embedded editor.
|
TabsDefDescTooltip=The tabs provided by your module/application are defined into the array <strong>$this->tabs</strong> into the module descriptor file. You can edit manually this file or use the embedded editor.
|
||||||
|
BadValueForType=Bad value for type %s
|
||||||
@@ -1518,9 +1518,10 @@ if ($dirins && $action == 'addproperty' && empty($cancel) && !empty($module) &&
|
|||||||
$error++;
|
$error++;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
$moduletype = $listofmodules[strtolower($module)]['moduletype'];
|
||||||
|
|
||||||
// Edit the class file to write properties
|
// Edit the class file to write properties
|
||||||
if (!$error) {
|
if (!$error) {
|
||||||
$moduletype = 'external';
|
|
||||||
$object = rebuildObjectClass($destdir, $module, $objectname, $newmask, $srcdir, $addfieldentry, $moduletype);
|
$object = rebuildObjectClass($destdir, $module, $objectname, $newmask, $srcdir, $addfieldentry, $moduletype);
|
||||||
|
|
||||||
if (is_numeric($object) && $object <= 0) {
|
if (is_numeric($object) && $object <= 0) {
|
||||||
@@ -1530,21 +1531,20 @@ if ($dirins && $action == 'addproperty' && empty($cancel) && !empty($module) &&
|
|||||||
|
|
||||||
// Edit sql with new properties
|
// Edit sql with new properties
|
||||||
if (!$error) {
|
if (!$error) {
|
||||||
$moduletype = 'external';
|
|
||||||
|
|
||||||
$result = rebuildObjectSql($destdir, $module, $objectname, $newmask, $srcdir, $object, $moduletype);
|
$result = rebuildObjectSql($destdir, $module, $objectname, $newmask, $srcdir, $object, $moduletype);
|
||||||
|
|
||||||
if ($result <= 0) {
|
if ($result <= 0) {
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$error) {
|
if (!$error) {
|
||||||
|
clearstatcache(true);
|
||||||
|
|
||||||
setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null);
|
setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null);
|
||||||
|
|
||||||
setEventMessages($langs->trans('WarningDatabaseIsNotUpdated'), null);
|
setEventMessages($langs->trans('WarningDatabaseIsNotUpdated'), null);
|
||||||
|
|
||||||
clearstatcache(true);
|
|
||||||
|
|
||||||
// Make a redirect to reload all data
|
// Make a redirect to reload all data
|
||||||
header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj='.$objectname.'&nocache='.time());
|
header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj='.$objectname.'&nocache='.time());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user