Work on modulebuilder

This commit is contained in:
Laurent Destailleur 2017-11-21 11:50:57 +01:00
parent ff9a62e519
commit a630e665d9
8 changed files with 125 additions and 7 deletions

View File

@ -280,7 +280,7 @@ interface Database
/**
* Create a table into database
*
* @param string $table Nom de la table
* @param string $table Name of table
* @param array $fields Tableau associatif [nom champ][tableau des descriptions]
* @param string $primary_key Nom du champ qui sera la clef primaire
* @param string $type Type de la table
@ -291,6 +291,14 @@ interface Database
*/
function DDLCreateTable($table, $fields, $primary_key, $type, $unique_keys = null, $fulltext_keys = null, $keys = null);
/**
* Drop a table into database
*
* @param string $table Name of table
* @return int <0 if KO, >=0 if OK
*/
function DDLDropTable($table);
/**
* Return list of available charset that can be used to store data in database
*

View File

@ -863,6 +863,22 @@ class DoliDBMssql extends DoliDB
return 1;
}
/**
* Drop a table into database
*
* @param string $table Name of table
* @return int <0 if KO, >=0 if OK
*/
function DDLDropTable($table)
{
$sql = "DROP TABLE ".$table;
if (! $this->query($sql))
return -1;
else
return 1;
}
/**
* Return a pointer of line with description of a table or field
*

View File

@ -629,7 +629,7 @@ class DoliDBMysqli extends DoliDB
/**
* Create a table into database
*
* @param string $table Nom de la table
* @param string $table Name of table
* @param array $fields Tableau associatif [nom champ][tableau des descriptions]
* @param string $primary_key Nom du champ qui sera la clef primaire
* @param string $type Type de la table
@ -702,13 +702,28 @@ class DoliDBMysqli extends DoliDB
$sql .= ",".implode(',',$sqlk);
$sql .=") engine=".$type;
dol_syslog($sql,LOG_DEBUG);
if(! $this -> query($sql))
if(! $this->query($sql))
return -1;
else
return 1;
}
/**
* Drop a table into database
*
* @param string $table Name of table
* @return int <0 if KO, >=0 if OK
*/
function DDLDropTable($table)
{
$sql = "DROP TABLE ".$table;
if (! $this->query($sql))
return -1;
else
return 1;
}
/**
* Return a pointer of line with description of a table or field
*

View File

@ -999,6 +999,22 @@ class DoliDBPgsql extends DoliDB
return 1;
}
/**
* Drop a table into database
*
* @param string $table Name of table
* @return int <0 if KO, >=0 if OK
*/
function DDLDropTable($table)
{
$sql = "DROP TABLE ".$table;
if (! $this->query($sql))
return -1;
else
return 1;
}
/**
* Create a user to connect to database
*

View File

@ -945,6 +945,22 @@ class DoliDBSqlite3 extends DoliDB
return 1;
}
/**
* Drop a table into database
*
* @param string $table Name of table
* @return int <0 if KO, >=0 if OK
*/
function DDLDropTable($table)
{
$sql = "DROP TABLE ".$table;
if (! $this->query($sql))
return -1;
else
return 1;
}
/**
* Return a pointer of line with description of a table or field
*

View File

@ -88,4 +88,7 @@ ToolkitForDevelopers=Toolkit for Dolibarr developers
TryToUseTheModuleBuilder=If you have knowledge in SQL and PHP, you can try to use the native module builder wizard. Just enable the module and use the wizard by clicking the <span class="fa fa-bug"></span> on the top right menu. Warning: This is a developer feature, bad use may breaks your application.
SeeTopRightMenu=See <span class="fa fa-bug"></span> on the top right menu
AddLanguageFile=Add language file
YouCanUseTranslationKey=You can use here a key that is the translation key found into language file (see tab "Languages")
YouCanUseTranslationKey=You can use here a key that is the translation key found into language file (see tab "Languages")
DropTableIfEmpty=(Delete table if empty)
TableDoesNotExists=The table %s does not exists
TableDropped=Table %s deleted

View File

@ -371,6 +371,51 @@ if ($dirins && $action == 'initobject' && $module && $objectname)
}
}
if ($dirins && ($action == 'droptable' || $action == 'droptableextrafields') && !empty($module) && ! empty($tabobj))
{
$objectname = $tabobj;
$arrayoftables=array();
if ($action == 'droptable') $arrayoftables[] = MAIN_DB_PREFIX.strtolower($module).'_'.strtolower($tabobj);
if ($action == 'droptableextrafields') $arrayoftables[] = MAIN_DB_PREFIX.strtolower($module).'_'.strtolower($tabobj).'_extrafields';
foreach($arrayoftables as $tabletodrop)
{
$nb = -1;
$sql="SELECT COUNT(*) as nb FROM ".$tabletodrop;
$resql = $db->query($sql);
if ($resql)
{
$obj = $db->fetch_object($resql);
if ($obj)
{
$nb = $obj->nb;
}
}
else
{
if ($db->lasterrno() == 'DB_ERROR_NOSUCHTABLE')
{
setEventMessages($langs->trans("TableDoesNotExists", $tabletodrop), null, 'warnings');
}
else
{
dol_print_error($db);
}
}
if ($nb == 0)
{
$resql=$db->DDLDropTable($tabletodrop);
//var_dump($resql);
setEventMessages($langs->trans("TableDropped", $tabletodrop), null, 'mesgs');
}
elseif ($nb > 0)
{
setEventMessages($langs->trans("TableNotEmptyDropCanceled", $tabletodrop), null, 'warnings');
}
}
}
if ($dirins && $action == 'addproperty' && !empty($module) && ! empty($tabobj))
{
$objectname = $tabobj;
@ -1515,6 +1560,7 @@ elseif (! empty($module))
print '<br>';
print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFileExtraFields").' : <strong>'.($realpathtosqlextra?'':'<strike>').$pathtosqlextra.($realpathtosqlextra?'':'</strike>').'</strong>';
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=editfile&file='.urlencode($pathtosqlextra).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=droptableextrafields">'.$langs->trans("DropTableIfEmpty").'</a>';
//print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
print '<br>';
print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFileKey").' : <strong>'.($realpathtosqlkey?'':'<strike>').$pathtosqlkey.($realpathtosqlkey?'':'</strike>').'</strong>';

View File

@ -230,7 +230,6 @@ class modMyModule extends DolibarrModules
// Add here entries to declare new menus
// Example to declare a new Top Menu entry and its Left menu entry:
/* BEGIN MODULEBUILDER TOPMENU */
$this->menu[$r++]=array('fk_menu'=>'', // '' 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'=>'top', // This is a Top menu entry
@ -247,7 +246,6 @@ class modMyModule extends DolibarrModules
/* END MODULEBUILDER TOPMENU */
// Example to declare a Left Menu entry into an existing Top menu entry:
/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT
$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