forked from Wavyzz/dolibarr
Fix: Pb in postgresql restore
This commit is contained in:
@@ -94,17 +94,17 @@ if ($_GET["msg"])
|
||||
if ($db->label == 'MySQL')
|
||||
{
|
||||
?>
|
||||
<div class="formelementrow"><input type="radio" name="what"
|
||||
value="mysql" id="radio_dump_mysql" /> <label for="radio_dump_mysql">MySQL
|
||||
Dump (mysqldump)</label></div>
|
||||
<div class="formelementrow"><input type="radio" name="what" value="mysql" id="radio_dump_mysql" />
|
||||
<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="postgresql" id="radio_dump_postgresql" /> <label
|
||||
for="radio_dump_postgresql">PostgreSQL Dump (pg_dump)</label></div>
|
||||
<div class="formelementrow"><input type="radio" name="what" value="postgresql" id="radio_dump_postgresql" />
|
||||
<label for="radio_dump_postgresql">PostgreSQL Dump (pg_dump)</label>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
else
|
||||
|
||||
@@ -70,12 +70,30 @@ print $langs->trans("RestoreDesc3",DOL_DATA_ROOT).'<br><br>';
|
||||
<div id="div_container_exportoptions">
|
||||
<fieldset id="exportoptions">
|
||||
<legend><?php echo $langs->trans("ImportMethod"); ?></legend>
|
||||
<?php
|
||||
if ($db->label == 'MySQL')
|
||||
{
|
||||
?>
|
||||
<div class="formelementrow">
|
||||
<input type="radio" name="what" value="mysql" id="radio_dump_mysql"
|
||||
<?php echo ($_GET["radio_dump"]=='mysql_options'?' checked':''); ?>
|
||||
/>
|
||||
<label for="radio_dump_mysql">MySQL</label>
|
||||
<input type="radio" name="what" value="mysql" id="radio_dump_mysql" <?php echo ($_GET["radio_dump"]=='mysql_options'?' checked':''); ?> />
|
||||
<label for="radio_dump_mysql">MySQL (mysql)</label>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
else if ($db->label == 'PostgreSQL')
|
||||
{
|
||||
?>
|
||||
<div class="formelementrow">
|
||||
<input type="radio" name="what" value="mysql" id="radio_dump_postgresql" <?php echo ($_GET["radio_dump"]=='postgresql_options'?' checked':''); ?> />
|
||||
<label for="radio_dump_postgresql">PostgreSQL Restore (pg_restore)</label>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
else
|
||||
{
|
||||
print 'No method available with database '.$db->label;
|
||||
}
|
||||
?>
|
||||
</fieldset>
|
||||
</div>
|
||||
<?php } ?>
|
||||
@@ -118,6 +136,41 @@ if ($db->label == 'MySQL')
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
else if ($db->label == 'PostgreSQL')
|
||||
{
|
||||
?>
|
||||
<fieldset id="postgresql_options">
|
||||
<legend>Restore PostgreSQL</legend>
|
||||
<div class="formelementrow">
|
||||
<?php
|
||||
// Parameteres execution
|
||||
$command=$db->getPathOfRestore();
|
||||
if (preg_match("/\s/",$command)) $command=$command=escapeshellarg($command); // Use quotes on command
|
||||
|
||||
$param=" -d ".$dolibarr_main_db_name;
|
||||
$param.=" -h ".$dolibarr_main_db_host;
|
||||
if (! empty($dolibarr_main_db_port)) $param.=" -p ".$dolibarr_main_db_port;
|
||||
$param.=" -U ".$dolibarr_main_db_user;
|
||||
$paramcrypted=$param;
|
||||
$paramclear=$param;
|
||||
/*if (! empty($dolibarr_main_db_pass))
|
||||
{
|
||||
$paramcrypted.=" -p".preg_replace('/./i','*',$dolibarr_main_db_pass);
|
||||
$paramclear.=" -p".$dolibarr_main_db_pass;
|
||||
}*/
|
||||
$paramcrypted.=" -W";
|
||||
$paramclear.=" -W";
|
||||
|
||||
echo $langs->trans("ImportPostgreSqlDesc");
|
||||
print '<br>';
|
||||
print '<textarea rows="1" cols="120">'.$langs->trans("ImportPostgreSqlCommand",$command,$_GET["showpass"]?$paramclear:$paramcrypted).'</textarea><br>';
|
||||
|
||||
if (empty($_GET["showpass"]) && $dolibarr_main_db_pass) print '<br><a href="'.$_SERVER["PHP_SELF"].'?showpass=1&radio_dump=postgresql_options">'.$langs->trans("UnHidePassword").'</a>';
|
||||
//else print '<br><a href="'.$_SERVER["PHP_SELF"].'?showpass=0&radio_dump=mysql_options">'.$langs->trans("HidePassword").'</a>';
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
</fieldset>
|
||||
|
||||
@@ -146,7 +146,9 @@ ExportMethod=Export method
|
||||
ImportMethod=Import method
|
||||
ToBuildBackupFileClickHere=To build a backup file, click <a href="%s">here</a>.
|
||||
ImportMySqlDesc=To import a backup file, you must use mysql command from command line:
|
||||
ImportPostgreSqlDesc=To import a backup file, you must use pg_restore command from command line:
|
||||
ImportMySqlCommand=%s %s < mybackupfile.sql
|
||||
ImportPostgreSqlCommand=%s %s mybackupfile.sql
|
||||
FileNameToGenerate=File name to generate
|
||||
CommandsToDisableForeignKeysForImport=Command to disable foreign keys on import
|
||||
ExportCompatibility=Compatibility of generated export file
|
||||
|
||||
@@ -146,7 +146,9 @@ ExportMethod= Méthode d'export
|
||||
ImportMethod= Méthode d'import
|
||||
ToBuildBackupFileClickHere= Pour générer un fichier de sauvegarde, cliquez <a href="%s">ici</a>.
|
||||
ImportMySqlDesc= Pour importer une sauvegarde, il faut utiliser la commande mysql en ligne suivante:
|
||||
ImportPostgreSqlDesc=Pour importer une sauvegarde, il faut utiliser la commande pg_restore en ligne suivante:
|
||||
ImportMySqlCommand= %s %s < monfichierbackup.sql
|
||||
ImportPostgreSqlCommand=%s %s monfichierbackup.sql
|
||||
FileNameToGenerate= Nom du fichier à générer
|
||||
CommandsToDisableForeignKeysForImport= Commande pour désactiver les clés étrangères à l'import
|
||||
ExportCompatibility= Compatibilité du fichier export généré
|
||||
|
||||
@@ -1236,16 +1236,25 @@ class DoliDb
|
||||
*/
|
||||
function getPathOfRestore()
|
||||
{
|
||||
$fullpathofmysqldump='/pathtomysql/mysql';
|
||||
$fullpathofdump='/pathtopgrestore/pg_restore';
|
||||
|
||||
$resql=$this->query('SHOW VARIABLES LIKE \'basedir\'');
|
||||
if (file_exists('/usr/bin/pg_restore'))
|
||||
{
|
||||
$fullpathofdump='/usr/bin/pg_restore';
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO L'utilisateur de la base doit etre un superadmin pour lancer cette commande
|
||||
$resql=$this->query('SHOW data_directory');
|
||||
if ($resql)
|
||||
{
|
||||
$liste=$this->fetch_array($resql);
|
||||
$basedir=$liste['Value'];
|
||||
$fullpathofmysqldump=$basedir.'bin/mysql';
|
||||
$basedir=$liste['data_directory'];
|
||||
$fullpathofdump=preg_replace('/data$/','bin',$basedir).'/pg_restore';
|
||||
}
|
||||
return $fullpathofmysqldump;
|
||||
}
|
||||
|
||||
return $fullpathofdump;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user