Debug modulebuilder
This commit is contained in:
parent
f29a4c1fb1
commit
0c066b471d
@ -96,7 +96,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir='
|
||||
dol_sort_array($object->fields, 'position');
|
||||
|
||||
$i=0;
|
||||
$texttoinsert = "\t".'// BEGIN MODULEBUILDER PROPERTIES'."\n";
|
||||
$texttoinsert = '// BEGIN MODULEBUILDER PROPERTIES'."\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".' */'."\n";
|
||||
@ -111,7 +111,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir='
|
||||
$texttoinsert.= " 'visible'=>".($val['visible']!=''?$val['visible']:-1).",";
|
||||
$texttoinsert.= " 'enabled'=>".($val['enabled']!=''?$val['enabled']:1).",";
|
||||
$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['searchall']) $texttoinsert.= " 'searchall'=>".$val['searchall'].",";
|
||||
if ($val['comment']) $texttoinsert.= " 'comment'=>'".$val['comment']."',";
|
||||
@ -216,7 +216,7 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir='')
|
||||
$texttoinsert.= "\t".$key." ".$val['type'];
|
||||
if ($key == 'rowid') $texttoinsert.= ' AUTO_INCREMENT PRIMARY KEY';
|
||||
if ($key == 'entity') $texttoinsert.= ' DEFAULT 1';
|
||||
$texttoinsert.= ($val['notnull']?' NOT NULL':'');
|
||||
$texttoinsert.= (($val['notnull'] > 0)?' NOT NULL':'');
|
||||
if ($i < count($object->fields)) $texttoinsert.=", ";
|
||||
$texttoinsert.= "\n";
|
||||
}
|
||||
|
||||
@ -306,6 +306,8 @@ KiloBytes=Kilobytes
|
||||
MegaBytes=Megabytes
|
||||
GigaBytes=Gigabytes
|
||||
TeraBytes=Terabytes
|
||||
UserAuthor=User of creation
|
||||
UserModif=User of last update
|
||||
b=b.
|
||||
Kb=Kb
|
||||
Mb=Mb
|
||||
|
||||
@ -236,15 +236,28 @@ if ($dirins && $action == 'initobject' && $module && $objectname)
|
||||
setEventMessages($langs->trans("FileAlreadyExists", $destfile), null, 'warnings');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Copy is ok
|
||||
if ($destfile == 'class/'.$objectname.'.txt')
|
||||
{
|
||||
// Regenerate left menu entry in descriptor
|
||||
$stringtoadd='';
|
||||
// TODO Loop on each .txt file in class dir.
|
||||
$stringtoadd.="
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
// Scan for object class files
|
||||
$listofobject = dol_dir_list($destdir.'/class', 'files', 0, '\.class\.php$');
|
||||
|
||||
$firstobjectname='';
|
||||
foreach($listofobject as $fileobj)
|
||||
{
|
||||
if (preg_match('/^api_/',$fileobj['name'])) continue;
|
||||
if (preg_match('/^actions_/',$fileobj['name'])) continue;
|
||||
|
||||
$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(
|
||||
'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
|
||||
@ -272,14 +285,22 @@ if ($dirins && $action == 'initobject' && $module && $objectname)
|
||||
'target'=>'',
|
||||
'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 Avoid duplicate addition
|
||||
|
||||
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.
|
||||
$filetogenerate[]='core/modules/mod'.$module.'.class.php';
|
||||
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -361,7 +382,15 @@ if ($dirins && $action == 'addproperty' && !empty($module) && ! empty($tabobj))
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
clearstatcache();
|
||||
|
||||
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)
|
||||
{
|
||||
clearstatcache();
|
||||
|
||||
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 '</td>';
|
||||
print '<td class="center">';
|
||||
print $propnotnull?'X':'';
|
||||
print $propnotnull;
|
||||
print '</td>';
|
||||
/*print '<td>';
|
||||
print $propdefault;
|
||||
|
||||
@ -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
|
||||
|
||||
$object->$key=GETPOST($key,'alpha');
|
||||
if ($val['notnull'] && $object->$key == '')
|
||||
if ($val['notnull'] > 0 && $object->$key == '')
|
||||
{
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv($val['label'])), null, 'errors');
|
||||
@ -170,7 +170,7 @@ if (empty($reshook))
|
||||
{
|
||||
$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 ($val['notnull'] && $object->$key == '')
|
||||
if ($val['notnull'] > 0 && $object->$key == '')
|
||||
{
|
||||
$error++;
|
||||
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;
|
||||
print '<tr id="field_'.$key.'"><td';
|
||||
print ' class="titlefieldcreate';
|
||||
if ($val['notnull']) print ' fieldrequired';
|
||||
if ($val['notnull'] > 0) print ' fieldrequired';
|
||||
print '"';
|
||||
print '>'.$langs->trans($val['label']).'</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;
|
||||
print '<tr><td';
|
||||
print ' class="titlefieldcreate';
|
||||
if ($val['notnull']) print ' fieldrequired';
|
||||
if ($val['notnull'] > 0) print ' fieldrequired';
|
||||
print '"';
|
||||
print '>'.$langs->trans($val['label']).'</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;
|
||||
print '<tr><td';
|
||||
print ' class="titlefieldcreate';
|
||||
if ($val['notnull']) print ' fieldrequired';
|
||||
if ($val['notnull'] > 0) print ' fieldrequired';
|
||||
print '"';
|
||||
print '>'.$langs->trans($val['label']).'</td>';
|
||||
print '<td><input class="flat" type="text" name="'.$key.'" value="'.(GETPOST($key,'alpha')?GETPOST($key,'alpha'):'').'"></td>';
|
||||
|
||||
@ -15,8 +15,8 @@
|
||||
|
||||
|
||||
CREATE TABLE llx_myobject(
|
||||
rowid INTEGER AUTO_INCREMENT PRIMARY KEY,
|
||||
-- BEGIN MODULEBUILDER FIELDS
|
||||
rowid INTEGER AUTO_INCREMENT PRIMARY KEY,
|
||||
entity INTEGER DEFAULT 1 NOT NULL,
|
||||
label VARCHAR(255),
|
||||
qty INTEGER,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user