2
0
forked from Wavyzz/dolibarr

New: build_class_from_table can work with a distant database server.

This commit is contained in:
Laurent Destailleur
2014-02-26 10:42:45 +01:00
parent d4d69e41b1
commit 473b0f73be

View File

@@ -1,6 +1,6 @@
#!/usr/bin/php #!/usr/bin/php
<?php <?php
/* Copyright (C) 2008-2011 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2008-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -50,12 +50,18 @@ print "***** $script_file ($version) *****\n";
// -------------------- START OF BUILD_CLASS_FROM_TABLE SCRIPT -------------------- // -------------------- START OF BUILD_CLASS_FROM_TABLE SCRIPT --------------------
// Check parameters // Check parameters
if (! isset($argv[1])) if (! isset($argv[1]) || (isset($argv[2]) && ! isset($argv[6])))
{ {
print "Usage: $script_file tablename\n"; print "Usage: $script_file tablename [server port databasename user pass]\n";
exit; exit;
} }
if (isset($argv[2]) && isset($argv[3]) && isset($argv[4]) && isset($argv[5]) && isset($argv[6]))
{
print 'Use specific database ids'."\n";
$db=getDoliDBInstance('mysqli',$argv[2],$argv[5],$argv[6],$argv[4],$argv[3]);
}
if ($db->type != 'mysql' && $db->type != 'mysqli') if ($db->type != 'mysql' && $db->type != 'mysqli')
{ {
print "Error: This script works with mysql or mysqli driver only\n"; print "Error: This script works with mysql or mysqli driver only\n";
@@ -184,7 +190,7 @@ $varprop="\n";
$cleanparam=''; $cleanparam='';
foreach($property as $key => $prop) foreach($property as $key => $prop)
{ {
if ($prop['field'] != 'rowid') if ($prop['field'] != 'rowid' && $prop['field'] != 'id')
{ {
$varprop.="\tvar \$".$prop['field']; $varprop.="\tvar \$".$prop['field'];
if ($prop['istime']) $varprop.="=''"; if ($prop['istime']) $varprop.="=''";
@@ -201,7 +207,7 @@ $varprop="\n";
$cleanparam=''; $cleanparam='';
foreach($property as $key => $prop) foreach($property as $key => $prop)
{ {
if ($prop['field'] != 'rowid' && ! $prop['istime']) if ($prop['field'] != 'rowid' && $prop['field'] != 'id' && ! $prop['istime'])
{ {
$varprop.="\t\tif (isset(\$this->".$prop['field'].")) \$this->".$prop['field']."=trim(\$this->".$prop['field'].");"; $varprop.="\t\tif (isset(\$this->".$prop['field'].")) \$this->".$prop['field']."=trim(\$this->".$prop['field'].");";
$varprop.="\n"; $varprop.="\n";
@@ -283,7 +289,7 @@ $i=0;
foreach($property as $key => $prop) foreach($property as $key => $prop)
{ {
$i++; $i++;
if ($prop['field'] != 'rowid') if ($prop['field'] != 'rowid' && $prop['field'] != 'id')
{ {
$varprop.="\t\t\$sql.= \" "; $varprop.="\t\t\$sql.= \" ";
$varprop.=$prop['field'].'='; $varprop.=$prop['field'].'=';
@@ -324,7 +330,7 @@ $i=0;
foreach($property as $key => $prop) foreach($property as $key => $prop)
{ {
$i++; $i++;
if ($prop['field'] != 'rowid') if ($prop['field'] != 'rowid' && $prop['field'] != 'id')
{ {
$varprop.="\t\t\t\t\$this->".$prop['field']." = "; $varprop.="\t\t\t\t\$this->".$prop['field']." = ";
if ($prop['istime']) $varprop.='$this->db->jdate('; if ($prop['istime']) $varprop.='$this->db->jdate(';
@@ -343,7 +349,7 @@ $varprop="\n";
$cleanparam=''; $cleanparam='';
foreach($property as $key => $prop) foreach($property as $key => $prop)
{ {
if ($prop['field'] != 'rowid') if ($prop['field'] != 'rowid' && $prop['field'] != 'id')
{ {
$varprop.="\t\t\$this->".$prop['field']."='';"; $varprop.="\t\t\$this->".$prop['field']."='';";
$varprop.="\n"; $varprop.="\n";
@@ -462,6 +468,6 @@ else $error++;
// -------------------- END OF BUILD_CLASS_FROM_TABLE SCRIPT -------------------- // -------------------- END OF BUILD_CLASS_FROM_TABLE SCRIPT --------------------
print "You can now rename generated files by removing the 'out.' prefix in their name and store them in a directory of your choice.\n"; print "You can now rename generated files by removing the 'out.' prefix in their name and store them into directory /yourmodule/class.\n";
return $error; return $error;
?> ?>