Fix: Errors in postgreSQL support

This commit is contained in:
Laurent Destailleur 2009-10-26 03:10:12 +00:00
parent d8bd1006eb
commit 3445244487
6 changed files with 252 additions and 115 deletions

View File

@ -73,10 +73,7 @@ if ($_GET["msg"])
//<![CDATA[
function hide_them_all() {
document.getElementById("mysql_options").style.display = 'none';
// document.getElementById("csv_options").style.display = 'none';
// document.getElementById("latex_options").style.display = 'none';
// document.getElementById("pdf_options").style.display = 'none';
// document.getElementById("none_options").style.display = 'none';
document.getElementById("postgresql_options").style.display = 'none';
}
function show_checked_option() {
@ -85,19 +82,9 @@ function show_checked_option() {
if (document.getElementById('radio_dump_mysql')) {
document.getElementById('mysql_options').style.display = 'block';
}
// if (document.getElementById('radio_dump_latex').checked) {
// document.getElementById('latex_options').style.display = 'block';
// }
// if (document.getElementById('radio_dump_pdf').checked) {
// document.getElementById('pdf_options').style.display = 'block';
// }
// if (document.getElementById('radio_dump_xml').checked) {
// document.getElementById('none_options').style.display = 'block';
// }
// if (document.getElementById('radio_dump_csv')) {
// document.getElementById('csv_options').style.display = 'block';
// }
if (document.getElementById('radio_dump_postgresql')) {
document.getElementById('postgresql_options').style.display = 'block';
}
}
//]]>
@ -117,7 +104,10 @@ print '<br>';
<div id="div_container_exportoptions">
<fieldset id="exportoptions">
<legend><?php echo $langs->trans("ExportMethod"); ?></legend>
<?php
if ($db->label == 'MySQL')
{
?>
<div class="formelementrow">
<input type="radio" name="what" value="mysql" id="radio_dump_mysql"
onclick="
@ -126,56 +116,30 @@ print '<br>';
document.getElementById('mysql_options').style.display = 'block';
}; return true"
/>
<label for="radio_dump_mysql">MySQLDump</label>
<label for="radio_dump_mysql">MySQL Dump (mysqldump)</label>
</div>
<!--
<?php
}
else if ($db->label == 'PostgreSQL')
{
?>
<div class="formelementrow">
<input type="radio" name="what" value="latex" id="radio_dump_latex"
<input type="radio" name="what" value="postgresql" id="radio_dump_postgresql"
onclick="
if (this.checked) {
hide_them_all();
document.getElementById('latex_options').style.display = 'block';
document.getElementById('postgresql_options').style.display = 'block';
}; return true"
/>
<label for="radio_dump_latex">LaTeX</label>
<label for="radio_dump_postgresql">PostgreSQL Dump (pg_dump)</label>
</div>
<div class="formelementrow">
<input type="radio" name="what" value="pdf" id="radio_dump_pdf"
onclick="
if (this.checked) {
hide_them_all();
document.getElementById('pdf_options').style.display = 'block';
}; return true"
/>
<label for="radio_dump_pdf">PDF</label>
</div>
<div class="formelementrow">
<input type="radio" name="what" value="csv" id="radio_dump_csv"
onclick="if
(this.checked) {
hide_them_all();
document.getElementById('csv_options').style.display = 'block';
}; return true"
/>
<label for="radio_dump_csv">CSV</label>
</div>
<div class="formelementrow">
<input type="radio" name="what" value="xml" id="radio_dump_xml"
onclick="
if (this.checked) {
hide_them_all();
document.getElementById('none_options').style.display = 'block';
}; return true"
/>
<label for="radio_dump_xml">XML</label>
</div>
-->
<?php
}
else
{
print 'No method available with database '.$db->label;
}
?>
</fieldset>
</div>
@ -186,6 +150,7 @@ print '<br>';
<div id="div_container_sub_exportoptions">
<!-- Fieldset mysqldump -->
<fieldset id="mysql_options">
<legend><?php echo $langs->trans("MySqlExportParameters"); ?></legend>
@ -214,41 +179,46 @@ print '<br>';
value="<?php echo $fullpathofmysqldump; ?>" />
</div>
<div class="formelementrow">
<input type="checkbox" name="use_transaction" value="yes"
id="checkbox_use_transaction"
/>
<label for="checkbox_use_transaction">
<?php echo $langs->trans("UseTransactionnalMode"); ?></label>
</div>
<div class="formelementrow">
<input type="checkbox" name="disable_fk" value="yes" id="checkbox_disable_fk" checked="true" />
<label for="checkbox_disable_fk">
<?php echo $langs->trans("CommandsToDisableForeignKeysForImport"); ?></label>
</div>
<label for="select_sql_compat">
<?php echo $langs->trans("ExportCompatibility"); ?></label>
<select name="sql_compat" id="select_sql_compat">
<option value="NONE" selected="selected">NONE</option>
<option value="ANSI">ANSI</option>
<option value="DB2">DB2</option>
<option value="MAXDB">MAXDB</option>
<option value="MYSQL323">MYSQL323</option>
<option value="MYSQL40">MYSQL40</option>
<option value="MSSQL">MSSQL</option>
<option value="ORACLE">ORACLE</option>
<option value="POSTGRESQL">POSTGRESQL</option>
</select>
<br>
<fieldset>
<legend><?php echo $langs->trans("ExportOptions"); ?></legend>
<div class="formelementrow">
<input type="checkbox" name="use_transaction" value="yes"
id="checkbox_use_transaction"
/>
<label for="checkbox_use_transaction">
<?php echo $langs->trans("UseTransactionnalMode"); ?></label>
</div>
<div class="formelementrow">
<input type="checkbox" name="disable_fk" value="yes" id="checkbox_disable_fk" checked="true" />
<label for="checkbox_disable_fk">
<?php echo $langs->trans("CommandsToDisableForeignKeysForImport"); ?></label>
</div>
<label for="select_sql_compat">
<?php echo $langs->trans("ExportCompatibility"); ?></label>
<select name="sql_compat" id="select_sql_compat">
<option value="NONE" selected="selected">NONE</option>
<option value="ANSI">ANSI</option>
<option value="DB2">DB2</option>
<option value="MAXDB">MAXDB</option>
<option value="MYSQL323">MYSQL323</option>
<option value="MYSQL40">MYSQL40</option>
<option value="MSSQL">MSSQL</option>
<option value="ORACLE">ORACLE</option>
<option value="POSTGRESQL">POSTGRESQL</option>
</select>
<br>
<input type="checkbox" name="drop_database" value="yes"
id="checkbox_drop_database"
/>
<label for="checkbox_drop_database"><?php echo $langs->trans("AddDropDatabase"); ?></label>
</fieldset>
<br>
<fieldset>
<legend>
<input type="checkbox" name="sql_structure" value="structure"
@ -264,8 +234,9 @@ print '<br>';
<input type="checkbox" name="drop" value="1" id="checkbox_dump_drop"
/>
<label for="checkbox_dump_drop"><?php echo $langs->trans("AddDropTable"); ?></label><br />
</fieldset>
<br>
<fieldset>
<legend>
@ -311,6 +282,89 @@ print '<br>';
</fieldset>
</fieldset>
<!-- Fieldset pg_dump -->
<fieldset id="postgresql_options">
<legend><?php echo $langs->trans("PostgreSqlExportParameters"); ?></legend>
<div class="formelementrow">
<?php echo $langs->trans("FullPathToPostgreSQLdumpCommand");
if (empty($conf->global->SYSTEMTOOLS_POSTGRESQLDUMP))
{
$resql=$db->query('SHOW data_directory');
if ($resql)
{
$liste=$db->fetch_array($resql);
$basedir=$liste['data_directory'];
$fullpathofpgdump=preg_replace('/data$/','bin',$basedir).'/pg_dump';
}
else
{
$fullpathofpgdump='/pathtopgdump/pg_dump';
}
}
else
{
$fullpathofpgdump=$conf->global->SYSTEMTOOLS_POSTGRESQLDUMP;
}
?><br />
<input type="text" name="postgresqldump" size="80"
value="<?php echo $fullpathofpgdump; ?>" />
</div>
<br>
<fieldset>
<legend><?php echo $langs->trans("ExportOptions"); ?></legend>
<label for="select_sql_compat">
<?php echo $langs->trans("ExportCompatibility"); ?></label>
<select name="sql_compat" id="select_sql_compat">
<option value="POSTGRESQL" selected="selected">POSTGRESQL</option>
<option value="ANSI">ANSI</option>
</select><br>
<input type="checkbox" name="drop_database" value="yes"
id="checkbox_drop_database"
/>
<label for="checkbox_drop_database"><?php echo $langs->trans("AddDropDatabase"); ?></label>
</fieldset>
<br>
<fieldset>
<legend>
<input type="checkbox" name="sql_structure" value="structure"
id="checkbox_sql_structure"
checked="checked" onclick="
if (!this.checked &amp;&amp; !document.getElementById('checkbox_sql_data').checked)
return false;
else return true;" />
<label for="checkbox_sql_structure">
Structure</label>
</legend>
</fieldset>
<br>
<fieldset>
<legend>
<input type="checkbox" name="sql_data" value="data"
id="checkbox_sql_data" checked="checked" onclick="
if (!this.checked &amp;&amp; (!document.getElementById('checkbox_sql_structure') || !document.getElementById('checkbox_sql_structure').checked))
return false;
else return true;" />
<label for="checkbox_sql_data">
<?php echo $langs->trans("Datas"); ?></label>
</legend>
<input type="checkbox" name="showcolumns" value="yes"
id="checkbox_dump_showcolumns"
/>
<label for="checkbox_dump_showcolumns">
<?php echo $langs->trans("NameColumn"); ?></label><br />
</fieldset>
</fieldset>
<!--
<fieldset id="latex_options">
<legend>Parametres export LaTeX</legend>
@ -516,7 +570,10 @@ print '<br>';
<?php echo $langs->trans("FileNameToGenerate"); ?></label> :
<input type="text" name="filename_template" size="60" id="filename_template"
value="<?php
$file='mysqldump_'.$dolibarr_main_db_name.'_'.dol_sanitizeFileName(DOL_VERSION).'_'.strftime("%Y%m%d%H%M").'.sql';
$prefix='dump';
if ($db->label == 'MySQL') $prefix='mysqldump';
if ($db->label == 'PostgreSQL') $prefix='pg_dump';
$file=$prefix.'_'.$dolibarr_main_db_name.'_'.dol_sanitizeFileName(DOL_VERSION).'_'.strftime("%Y%m%d%H%M").'.sql';
echo $file;
?>" />
@ -524,17 +581,23 @@ echo $file;
<?php
print '<div class="formelementrow">';
print "\n";
print $langs->trans("Compression").': &nbsp; ';
// Define compressions array
$compression=array(
'none' => array('function' => '', 'id' => 'radio_compression_none', 'label' => $langs->trans("None")),
// 'zip' => array('function' => 'zip_open', 'id' => 'radio_compression_zip', 'label' => $langs->trans("Zip")), Not open source
'gz' => array('function' => 'gzopen', 'id' => 'radio_compression_gzip', 'label' => $langs->trans("Gzip")),
'bz' => array('function' => 'bzopen', 'id' => 'radio_compression_bzip', 'label' => $langs->trans("Bzip2"))
);
if ($db->label == 'MySQL')
{
$compression['bz']=array('function' => 'bzopen', 'id' => 'radio_compression_bzip', 'label' => $langs->trans("Bzip2"));
}
// Show compression choices
print '<div class="formelementrow">';
print "\n";
print $langs->trans("Compression").': &nbsp; ';
foreach($compression as $key => $val)
{

View File

@ -77,25 +77,32 @@ $dump_buffer_len = 0;
$time_start = time();
// MYSQL
if ($what == 'mysql')
{
$mysqldump=$_POST["mysqldump"];
if ($mysqldump)
$cmddump=$_POST["mysqldump"];
if ($cmddump)
{
dolibarr_set_const($db, 'SYSTEMTOOLS_MYSQLDUMP', $mysqldump,'chaine',0,'',$conf->entity);
dolibarr_set_const($db, 'SYSTEMTOOLS_MYSQLDUMP', $cmddump,'chaine',0,'',$conf->entity);
}
$outputdir = $conf->admin->dir_temp;
$outputfile = $outputdir.'/'.$file;
// for compression format, we add extension
$compression=isset($_POST['compression']) ? $_POST['compression'] : 'none';
if ($compression == 'gz') $outputfile.='.gz';
if ($compression == 'bz') $outputfile.='.bz2';
$outputerror = $outputfile.'.err';
create_exdir($conf->admin->dir_temp);
// Parameteres execution
$command=$mysqldump;
$command=$cmddump;
if (preg_match("/\s/",$command)) $command=$command=escapeshellarg($command); // Use quotes on command
//$param=escapeshellarg($dolibarr_main_db_name)." -h ".escapeshellarg($dolibarr_main_db_host)." -u ".escapeshellarg($dolibarr_main_db_user)." -p".escapeshellarg($dolibarr_main_db_pass);
$param=$dolibarr_main_db_name." -h ".$dolibarr_main_db_host;
$param.=" -u ".$dolibarr_main_db_user;
if (! empty($dolibarr_main_db_port)) $param.=" -P ".$dolibarr_main_db_port;
$compression=isset($_POST['compression']) ? $_POST['compression'] : 'none';
if (! $_POST["use_transaction"]) $param.=" -l --single-transaction";
if ($_POST["disable_fk"]) $param.=" -K";
if ($_POST["sql_compat"] && $_POST["sql_compat"] != 'NONE') $param.=" --compatible=".$_POST["sql_compat"];
@ -129,18 +136,13 @@ if ($what == 'mysql')
$paramclear.=" -p".$dolibarr_main_db_pass;
}
$outputdir = $conf->admin->dir_temp;
$outputfile = $outputdir.'/'.$file;
// for compression format, we add extension
if ($compression == 'gz') $outputfile.='.gz';
if ($compression == 'bz') $outputfile.='.bz2';
$outputerror = $outputfile.'.err';
print $langs->trans("RunCommandSummary").':<br>'."\n";
print '<textarea rows="1" cols="120">'.$command." ".$paramcrypted.'</textarea><br>'."\n";
print '<textarea rows="'.ROWS_2.'" cols="120">'.$command." ".$paramcrypted.'</textarea><br>'."\n";
print '<br>';
// Now run command and show result
print $langs->trans("BackupResult").': ';
$errormsg='';
@ -175,7 +177,7 @@ if ($what == 'mysql')
else
{
$langs->load("errors");
dol_syslog("Failed to open file $outputfile",LOG_ERR);
dol_syslog("Failed to open file ".$outputfile,LOG_ERR);
$errormsg=$langs->trans("ErrorFailedToWriteInDir");
}
// Get errorstring
@ -200,9 +202,78 @@ if ($what == 'mysql')
}
}
// Fin execution commande
}
// POSTGRESQL
if ($what == 'postgresql')
{
$cmddump=$_POST["postgresqldump"];
if ($cmddump)
{
dolibarr_set_const($db, 'SYSTEMTOOLS_POSTGRESQLDUMP', $cmddump,'chaine',0,'',$conf->entity);
}
$outputdir = $conf->admin->dir_temp;
$outputfile = $outputdir.'/'.$file;
// for compression format, we add extension
$compression=isset($_POST['compression']) ? $_POST['compression'] : 'none';
if ($compression == 'gz') $outputfile.='.gz';
if ($compression == 'bz') $outputfile.='.bz2';
$outputerror = $outputfile.'.err';
create_exdir($conf->admin->dir_temp);
// Parameteres execution
$command=$cmddump;
if (preg_match("/\s/",$command)) $command=$command=escapeshellarg($command); // Use quotes on command
//$param=escapeshellarg($dolibarr_main_db_name)." -h ".escapeshellarg($dolibarr_main_db_host)." -u ".escapeshellarg($dolibarr_main_db_user)." -p".escapeshellarg($dolibarr_main_db_pass);
$param=" --no-tablespaces --inserts -h ".$dolibarr_main_db_host;
$param.=" -U ".$dolibarr_main_db_user;
if (! empty($dolibarr_main_db_port)) $param.=" -p ".$dolibarr_main_db_port;
if ($_POST["sql_compat"] && $_POST["sql_compat"] == 'ANSI') $param.=" --disable-dollar-quoting";
if ($_POST["drop_database"]) $param.=" -c -C";
if ($_POST["sql_structure"])
{
if ($_POST["drop"]) $param.=" --add-drop-table";
if (empty($_POST["sql_data"])) $param.=" -s";
}
if ($_POST["sql_data"])
{
if (empty($_POST["sql_structure"])) $param.=" -a";
if ($_POST["showcolumns"]) $param.=" -c";
}
$param.=' -f "'.$outputfile.'"';
//if ($compression == 'none')
if ($compression == 'gz') $param.=' -Z 9';
//if ($compression == 'bz')
$paramcrypted=$param;
$paramclear=$param;
if (! empty($dolibarr_main_db_pass))
{
//$paramcrypted.=" -W".preg_replace('/./i','*',$dolibarr_main_db_pass);
//$paramclear.=" -W".$dolibarr_main_db_pass;
}
$paramcrypted.=" -w ".$dolibarr_main_db_name;
$paramclear.=" -w ".$dolibarr_main_db_name;
print $langs->trans("RunCommandSummary").':<br>'."\n";
print '<textarea rows="'.ROWS_3.'" cols="120">'.$command." ".$paramcrypted.'</textarea><br>'."\n";
print '<br>';
// Now show to ask to run command
print $langs->trans("YouMustRunCommandFromCommandLineAfterLoginToUser",$dolibarr_main_db_user);
print '<br>';
print '<br>';
$what='';
}
// Si on a demande une generation
if ($what)
{

View File

@ -723,7 +723,9 @@ RestoreDesc3=* Restore the data, from a backup dump file, into the database of t
ForcedToByAModule = This rule is forced to <b>%s</b> by an activated module
PreviousDumpFiles=Available database backup dump files
WeekStartOnDay=First day of week
RunningUpdateProcessMayBeRequired=Le lancement du processus de mise a jour semble requis (La version des programme %s differe de la version de la base %s)
RunningUpdateProcessMayBeRequired=Running the upgrade process seems to be required (Programs version %s differs from database version %s)
YouMustRunCommandFromCommandLineAfterLoginToUser=You must run this command from command line after login to a shell with user <b>%s</b>.
##### Module password generation
PasswordGenerationStandard=Return a password generated according to internal Dolibarr algorithm: 8 characters containing shared numbers and characters in lowercase.
PasswordGenerationNone=Do not suggest any generated password. Password must be type in manually.

View File

@ -57,7 +57,7 @@ CreateUser=Create user
DatabaseSuperUserAccess=Database - Superuser access
CheckToCreateDatabase=Check box if database does not exist and must be created.<br>In this case, you must fill the login/password for superuser account at the bottom of this page.
CheckToCreateUser=Check box if login does not exist and must be created.<br>In this case, you must fill the login/password for superuser account at the bottom of this page.
Experimental=(experimental, non operational)
Experimental=(experimental)
DatabaseRootLoginDescription=Login of the user allowed to create new databases or new users, useless if your database and your database login already exists (like when you're hosted by a web hosting provider).
KeepEmptyIfNoPassword=Leave empty if user has no password (avoid this)
SaveConfigurationFile=Save values

View File

@ -723,7 +723,8 @@ RestoreDesc3 = * Recharger depuis le fichier dump sauvegardé, la base de donné
ForcedToByAModule = Cette règle est forcée à <b>%s</b> par un des modules activés
PreviousDumpFiles=Fichiers disponibles de sauvegarde de la base de donnée
WeekStartOnDay=Premier jour de la semaine
RunningUpdateProcessMayBeRequired=Running the upgrade process seems to be required (Programs version %s differs from database version %s)
RunningUpdateProcessMayBeRequired=Le lancement du processus de mise a jour semble requis (La version des programme %s differe de la version de la base %s)
YouMustRunCommandFromCommandLineAfterLoginToUser=Vous devez exécuter la commande sous un shell après vous etres logués avec le compte <b>%s</b>.
##### Module password generation = undefined
PasswordGenerationStandard = Renvoie un mot de passe généré selon algorithme interne Dolibarr: 8 caractères, chiffres et caractères en minuscules mélangés.

View File

@ -57,7 +57,7 @@ CreateUser=Créer l'utilisateur
DatabaseSuperUserAccess=Base de données - Accès super utilisateur
CheckToCreateDatabase=Cochez cette option si la base de données n'existe pas et doit être créée.<br>Dans ce cas, il faut renseigner le login/mot de passe du superutilisateur au bas de cette page.
CheckToCreateUser=Cochez cette option si le login n'existe pas et doit être créé.<br>Dans ce cas, il faut renseigner le login/mot de passe du superutilisateur au bas de cette page.
Experimental=(expérimental, non opérationnel)
Experimental=(expérimental)
DatabaseRootLoginDescription=Login de l'utilisateur de la base ayant les droits de création de bases de données ou de comptes pour la base, inutile si la base et son compte d'accès existe déjà (comme lorsque vous êtes chez un hébergeur).
KeepEmptyIfNoPassword=Laissez vide si l'utilisateur n'a pas de mot de passe (à éviter)
SaveConfigurationFile=Enregistrement du fichier de configuration