Debug modulebuilder

This commit is contained in:
Laurent Destailleur 2017-09-05 22:33:55 +02:00
parent f29a4c1fb1
commit 0c066b471d
5 changed files with 60 additions and 21 deletions

View File

@ -96,7 +96,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir='
dol_sort_array($object->fields, 'position'); dol_sort_array($object->fields, 'position');
$i=0; $i=0;
$texttoinsert = "\t".'// BEGIN MODULEBUILDER PROPERTIES'."\n"; $texttoinsert = '// BEGIN MODULEBUILDER PROPERTIES'."\n";
$texttoinsert.= "\t".'/**'."\n"; $texttoinsert.= "\t".'/**'."\n";
$texttoinsert.= "\t".' * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.'."\n"; $texttoinsert.= "\t".' * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.'."\n";
$texttoinsert.= "\t".' */'."\n"; $texttoinsert.= "\t".' */'."\n";
@ -111,7 +111,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir='
$texttoinsert.= " 'visible'=>".($val['visible']!=''?$val['visible']:-1).","; $texttoinsert.= " 'visible'=>".($val['visible']!=''?$val['visible']:-1).",";
$texttoinsert.= " 'enabled'=>".($val['enabled']!=''?$val['enabled']:1).","; $texttoinsert.= " 'enabled'=>".($val['enabled']!=''?$val['enabled']:1).",";
$texttoinsert.= " 'position'=>".($val['position']!=''?$val['position']:50).","; $texttoinsert.= " 'position'=>".($val['position']!=''?$val['position']:50).",";
if ($val['notnull']) $texttoinsert.= " 'notnull'=>".$val['notnull'].","; $texttoinsert.= " 'notnull'=>".($val['notnull']!=''?$val['notnull']:-1).",";
if ($val['index']) $texttoinsert.= " 'index'=>".$val['index'].","; if ($val['index']) $texttoinsert.= " 'index'=>".$val['index'].",";
if ($val['searchall']) $texttoinsert.= " 'searchall'=>".$val['searchall'].","; if ($val['searchall']) $texttoinsert.= " 'searchall'=>".$val['searchall'].",";
if ($val['comment']) $texttoinsert.= " 'comment'=>'".$val['comment']."',"; if ($val['comment']) $texttoinsert.= " 'comment'=>'".$val['comment']."',";
@ -216,7 +216,7 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir='')
$texttoinsert.= "\t".$key." ".$val['type']; $texttoinsert.= "\t".$key." ".$val['type'];
if ($key == 'rowid') $texttoinsert.= ' AUTO_INCREMENT PRIMARY KEY'; if ($key == 'rowid') $texttoinsert.= ' AUTO_INCREMENT PRIMARY KEY';
if ($key == 'entity') $texttoinsert.= ' DEFAULT 1'; if ($key == 'entity') $texttoinsert.= ' DEFAULT 1';
$texttoinsert.= ($val['notnull']?' NOT NULL':''); $texttoinsert.= (($val['notnull'] > 0)?' NOT NULL':'');
if ($i < count($object->fields)) $texttoinsert.=", "; if ($i < count($object->fields)) $texttoinsert.=", ";
$texttoinsert.= "\n"; $texttoinsert.= "\n";
} }

View File

@ -306,6 +306,8 @@ KiloBytes=Kilobytes
MegaBytes=Megabytes MegaBytes=Megabytes
GigaBytes=Gigabytes GigaBytes=Gigabytes
TeraBytes=Terabytes TeraBytes=Terabytes
UserAuthor=User of creation
UserModif=User of last update
b=b. b=b.
Kb=Kb Kb=Kb
Mb=Mb Mb=Mb

View File

@ -236,15 +236,28 @@ if ($dirins && $action == 'initobject' && $module && $objectname)
setEventMessages($langs->trans("FileAlreadyExists", $destfile), null, 'warnings'); setEventMessages($langs->trans("FileAlreadyExists", $destfile), null, 'warnings');
} }
} }
else }
if (! $error)
{ {
// Copy is ok // Scan for object class files
if ($destfile == 'class/'.$objectname.'.txt') $listofobject = dol_dir_list($destdir.'/class', 'files', 0, '\.class\.php$');
$firstobjectname='';
foreach($listofobject as $fileobj)
{ {
// Regenerate left menu entry in descriptor if (preg_match('/^api_/',$fileobj['name'])) continue;
$stringtoadd=''; if (preg_match('/^actions_/',$fileobj['name'])) continue;
// TODO Loop on each .txt file in class dir.
$stringtoadd.=" $tmpcontent=file_get_contents($fileobj['fullname']);
if (preg_match('/class\s+([^\s]*)\s+extends\s+CommonObject/ims',$tmpcontent,$reg))
{
$objectnameloop = $reg[1];
if (empty($firstobjectname)) $firstobjectname = $objectnameloop;
}
// Regenerate left menu entry in descriptor for $objectname
$stringtoadd="
\t\t\$this->menu[\$r++]=array( \t\t\$this->menu[\$r++]=array(
'fk_menu'=>'fk_mainmenu=mymodule', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode 'fk_menu'=>'fk_mainmenu=mymodule', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
'type'=>'left', // This is a Left menu entry 'type'=>'left', // This is a Left menu entry
@ -272,13 +285,21 @@ if ($dirins && $action == 'initobject' && $module && $objectname)
'target'=>'', 'target'=>'',
'user'=>2); // 0=Menu for internal users, 1=external users, 2=both 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
"; ";
$moduledescriptorfile=$dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php'; $stringtoadd = preg_replace('/MyObject/', $objectnameloop, $stringtoadd);
$stringtoadd = preg_replace('/mymodule/', strtolower($module), $stringtoadd);
$stringtoadd = preg_replace('/myobject/', strtolower($objectnameloop), $stringtoadd);
$moduledescriptorfile=$destdir.'/core/modules/mod'.$module.'.class.php';
// TODO Allow a replace with regex using dolReplaceRegexInFile // TODO Allow a replace with regex using dolReplaceRegexInFile
// TODO Avoid duplicate addition
dolReplaceInFile($moduledescriptorfile, array('END MODULEBUILDER LEFTMENU MYOBJECT */' => '*/'."\n".$stringtoadd."\n\t\t/* END MODULEBUILDER LEFTMENU MYOBJECT */")); dolReplaceInFile($moduledescriptorfile, array('END MODULEBUILDER LEFTMENU MYOBJECT */' => '*/'."\n".$stringtoadd."\n\t\t/* END MODULEBUILDER LEFTMENU MYOBJECT */"));
// Add module descriptor to list of files to replace "MyObject' string with real name of object. // Add module descriptor to list of files to replace "MyObject' string with real name of object.
$filetogenerate[]='core/modules/mod'.$module.'.class.php'; $filetogenerate[]='core/modules/mod'.$module.'.class.php';
}
// TODO
} }
} }
} }
@ -361,7 +382,15 @@ if ($dirins && $action == 'addproperty' && !empty($module) && ! empty($tabobj))
if (! $error) if (! $error)
{ {
clearstatcache();
setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null); setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null);
// Make a redirect to reload all data
header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module.'&tabobj='.$objectname);
clearstatcache();
exit;
} }
} }
@ -389,7 +418,15 @@ if ($dirins && $action == 'confirm_deleteproperty' && $propertykey)
if (! $error) if (! $error)
{ {
clearstatcache();
setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null); setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null);
// Make a redirect to reload all data
header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module.'&tabobj='.$objectname);
clearstatcache();
exit;
} }
} }
@ -1473,7 +1510,7 @@ elseif (! empty($module))
print $proptype; print $proptype;
print '</td>'; print '</td>';
print '<td class="center">'; print '<td class="center">';
print $propnotnull?'X':''; print $propnotnull;
print '</td>'; print '</td>';
/*print '<td>'; /*print '<td>';
print $propdefault; print $propdefault;

View File

@ -132,7 +132,7 @@ if (empty($reshook))
if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; // Ignore special fields if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; // Ignore special fields
$object->$key=GETPOST($key,'alpha'); $object->$key=GETPOST($key,'alpha');
if ($val['notnull'] && $object->$key == '') if ($val['notnull'] > 0 && $object->$key == '')
{ {
$error++; $error++;
setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv($val['label'])), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv($val['label'])), null, 'errors');
@ -170,7 +170,7 @@ if (empty($reshook))
{ {
$object->$key=GETPOST($key,'alpha'); $object->$key=GETPOST($key,'alpha');
if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue;
if ($val['notnull'] && $object->$key == '') if ($val['notnull'] > 0 && $object->$key == '')
{ {
$error++; $error++;
setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv($val['label'])), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv($val['label'])), null, 'errors');
@ -265,7 +265,7 @@ if ($action == 'create')
if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue;
print '<tr id="field_'.$key.'"><td'; print '<tr id="field_'.$key.'"><td';
print ' class="titlefieldcreate'; print ' class="titlefieldcreate';
if ($val['notnull']) print ' fieldrequired'; if ($val['notnull'] > 0) print ' fieldrequired';
print '"'; print '"';
print '>'.$langs->trans($val['label']).'</td>'; print '>'.$langs->trans($val['label']).'</td>';
print '<td><input class="flat" type="text" name="'.$key.'" value="'.(GETPOST($key,'alpha')?GETPOST($key,'alpha'):'').'"></td>'; print '<td><input class="flat" type="text" name="'.$key.'" value="'.(GETPOST($key,'alpha')?GETPOST($key,'alpha'):'').'"></td>';
@ -300,7 +300,7 @@ if (($id || $ref) && $action == 'edit')
if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue;
print '<tr><td'; print '<tr><td';
print ' class="titlefieldcreate'; print ' class="titlefieldcreate';
if ($val['notnull']) print ' fieldrequired'; if ($val['notnull'] > 0) print ' fieldrequired';
print '"'; print '"';
print '>'.$langs->trans($val['label']).'</td>'; print '>'.$langs->trans($val['label']).'</td>';
print '<td><input class="flat" type="text" name="'.$key.'" value="'.(GETPOST($key,'alpha')?GETPOST($key,'alpha'):'').'"></td>'; print '<td><input class="flat" type="text" name="'.$key.'" value="'.(GETPOST($key,'alpha')?GETPOST($key,'alpha'):'').'"></td>';
@ -421,7 +421,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue;
print '<tr><td'; print '<tr><td';
print ' class="titlefieldcreate'; print ' class="titlefieldcreate';
if ($val['notnull']) print ' fieldrequired'; if ($val['notnull'] > 0) print ' fieldrequired';
print '"'; print '"';
print '>'.$langs->trans($val['label']).'</td>'; print '>'.$langs->trans($val['label']).'</td>';
print '<td><input class="flat" type="text" name="'.$key.'" value="'.(GETPOST($key,'alpha')?GETPOST($key,'alpha'):'').'"></td>'; print '<td><input class="flat" type="text" name="'.$key.'" value="'.(GETPOST($key,'alpha')?GETPOST($key,'alpha'):'').'"></td>';

View File

@ -15,8 +15,8 @@
CREATE TABLE llx_myobject( CREATE TABLE llx_myobject(
rowid INTEGER AUTO_INCREMENT PRIMARY KEY,
-- BEGIN MODULEBUILDER FIELDS -- BEGIN MODULEBUILDER FIELDS
rowid INTEGER AUTO_INCREMENT PRIMARY KEY,
entity INTEGER DEFAULT 1 NOT NULL, entity INTEGER DEFAULT 1 NOT NULL,
label VARCHAR(255), label VARCHAR(255),
qty INTEGER, qty INTEGER,