dolibarr/htdocs/admin/tools/dolibarr_import.php

272 lines
7.6 KiB
PHP
Raw Permalink Normal View History

2006-08-20 19:15:47 +00:00
<?php
2025-08-27 01:12:48 +00:00
/* Copyright (C) 2006-2021 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2006-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
2006-08-20 19:15:47 +00:00
*
* 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
* the Free Software Foundation; either version 3 of the License, or
2006-08-20 19:15:47 +00:00
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 19:55:30 +00:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2006-08-20 19:15:47 +00:00
*/
/**
* \file htdocs/admin/tools/dolibarr_import.php
2009-07-06 18:29:40 +00:00
* \ingroup core
* \brief Page to import database
*/
2021-08-04 10:26:38 +00:00
if (! defined('CSRFCHECK_WITH_TOKEN')) {
define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
}
2022-09-07 18:08:59 +00:00
// Load Dolibarr environment
require '../../main.inc.php';
2006-08-20 19:15:47 +00:00
add baseline exclude for phpstan (#31632) * add baseline exclude for phpstan * update * update * update * update * update * merge * restore one filter * delete old errors * fix * fix * fix * $moreforfilter can t be empty * fix * enable check * refresh baseline * add phpdoc * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2024-11-04 22:53:20 +00:00
/**
2025-08-27 01:12:48 +00:00
* @var string $dolibarr_main_db_host
* @var string $dolibarr_main_db_name
* @var string $dolibarr_main_db_user
* @var string $dolibarr_main_db_pass
add baseline exclude for phpstan (#31632) * add baseline exclude for phpstan * update * update * update * update * update * merge * restore one filter * delete old errors * fix * fix * fix * $moreforfilter can t be empty * fix * enable check * refresh baseline * add phpdoc * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2024-11-04 22:53:20 +00:00
* @var Conf $conf
* @var DoliDB $db
* @var HookManager $hookmanager
* @var Translate $langs
* @var User $user
*/
2018-09-08 08:30:10 +00:00
// Load translation files required by the page
$langs->loadLangs(array("other", "admin"));
2006-08-20 19:15:47 +00:00
2021-02-26 21:04:03 +00:00
if (!$user->admin) {
2012-08-02 08:07:55 +00:00
accessforbidden();
2021-02-26 21:04:03 +00:00
}
2012-08-02 08:07:55 +00:00
$radio_dump = GETPOST('radio_dump');
2024-11-28 12:40:38 +00:00
$action = GETPOST('action', 'aZ09');
2006-08-20 19:15:47 +00:00
/*
* View
*/
$label = $db::LABEL;
$type = $db->type;
$help_url = 'EN:Restores|FR:Restaurations|ES:Restauraciones';
llxHeader('', '', $help_url, '', 0, 0, '', '', '', 'mod-admin page-tools_dolibarr_import');
2006-08-20 19:15:47 +00:00
?>
2011-11-21 00:34:37 +00:00
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#mysql_options").<?php echo $radio_dump == 'mysql_options' ? 'show()' : 'hide()'; ?>;
jQuery("#postgresql_options").<?php echo $radio_dump == 'postgresql_options' ? 'show()' : 'hide()'; ?>;
jQuery("#radio_dump_mysql").click(function() {
jQuery("#mysql_options").show();
});
jQuery("#radio_dump_postgresql").click(function() {
jQuery("#postgresql_options").show();
});
<?php
2021-02-26 21:04:03 +00:00
if ($label == 'MySQL') {
print 'jQuery("#radio_dump_mysql").click();';
}
if ($label == 'PostgreSQL') {
print 'jQuery("#radio_dump_postgresql").click();';
}
?>
});
</script>
<?php
print load_fiche_titre($langs->trans("Restore"), '', 'title_setup');
2021-08-04 10:26:38 +00:00
print '<div class="center">';
2025-10-20 13:12:35 +00:00
print $langs->trans("RestoreDesc", 3);
2017-05-20 16:46:15 +00:00
print '</div>';
2017-07-12 20:52:56 +00:00
print '<br>';
2025-10-20 13:12:35 +00:00
print '<span class="small opacitymedium">'.$langs->trans("RestoreDescMore").'</span><br>';
print '<br>';
2017-05-20 16:46:15 +00:00
?>
<fieldset>
<legend style="font-size: 3em">1</legend>
<?php
2021-08-04 10:26:38 +00:00
print '<span class="opacitymedium">';
print $langs->trans("RestoreDesc2", DOL_DATA_ROOT).'<br><br>';
2021-08-04 10:26:38 +00:00
print '</span>';
?>
</fieldset>
<br>
<fieldset>
<legend style="font-size: 3em">2</legend>
<?php
2021-08-04 10:26:38 +00:00
print '<span class="opacitymedium">';
print $langs->trans("RestoreDesc3", $dolibarr_main_db_name).'<br><br>';
2021-08-04 10:26:38 +00:00
print '</span>';
?>
<?php print $langs->trans("DatabaseName").' : <b>'.$dolibarr_main_db_name.'</b>'; ?><br><br>
2017-05-20 16:46:15 +00:00
<table class="centpercent"><tr><td class="tdtop">
<?php if ($conf->use_javascript_ajax) { ?>
<div id="div_container_exportoptions">
<fieldset id="exportoptions">
<legend><?php echo $langs->trans("ImportMethod"); ?></legend>
2021-02-26 21:04:03 +00:00
<?php
if (in_array($type, array('mysql', 'mysqli'))) {
?>
2021-02-26 21:04:03 +00:00
<div class="formelementrow">
2023-12-04 10:41:14 +00:00
<input type="radio" name="what" value="mysql" id="radio_dump_mysql"<?php echo($radio_dump == 'mysql_options' ? ' checked' : ''); ?> />
2021-02-26 21:04:03 +00:00
<label for="radio_dump_mysql">MySQL (mysql)</label>
</div>
<?php
} elseif (in_array($type, array('pgsql'))) {
?>
2021-02-26 21:04:03 +00:00
<div class="formelementrow">
2023-12-04 10:41:14 +00:00
<input type="radio" name="what" value="mysql" id="radio_dump_postgresql"<?php echo($radio_dump == 'postgresql_options' ? ' checked' : ''); ?> />
2021-02-26 21:04:03 +00:00
<label for="radio_dump_postgresql">PostgreSQL Restore (pg_restore or psql)</label>
</div>
<?php
} else {
print 'No method available with database '.$label;
}
?>
</fieldset>
2025-10-20 13:12:35 +00:00
<br>
</div>
<?php } ?>
2017-01-22 11:13:32 +00:00
</td><td class="tdtop">
2017-05-20 16:46:15 +00:00
<div id="div_container_sub_exportoptions" >
<?php
2021-02-26 21:04:03 +00:00
if (in_array($type, array('mysql', 'mysqli'))) {
2024-11-28 12:40:38 +00:00
print '<fieldset id="mysql_options">';
print '<legend>'.$langs->trans('RestoreMySQL').'</legend>';
print '<div class="formelementrow centpercent">';
// Parameters execution
$command = $db->getPathOfRestore();
2023-12-13 11:46:23 +00:00
if (preg_match("/\s/", $command)) {
$command = $command = escapeshellarg($command); // Use quotes on command
}
2023-12-04 10:41:14 +00:00
$param = $dolibarr_main_db_name;
$param .= " -h ".$dolibarr_main_db_host;
2023-12-13 11:46:23 +00:00
if (!empty($dolibarr_main_db_port)) {
$param .= " -P ".$dolibarr_main_db_port;
}
2023-12-04 10:41:14 +00:00
$param .= " -u ".$dolibarr_main_db_user;
$paramcrypted = $param;
$paramclear = $param;
2023-12-13 11:46:23 +00:00
if (!empty($dolibarr_main_db_pass)) {
$paramcrypted .= " -p".preg_replace('/./i', '*', $dolibarr_main_db_pass);
$paramclear .= " -p".$dolibarr_main_db_pass;
}
2009-01-23 14:46:33 +00:00
2024-11-28 12:40:38 +00:00
print $langs->trans("ImportMySqlDesc");
print '<br>';
2025-08-20 15:36:37 +00:00
print '<textarea rows="1" id="restorecommand" class="centpercent" spellcheck="false">'.$langs->trans("ImportMySqlCommand", $command, ($action == 'showpass' ? $paramclear : $paramcrypted)).'</textarea><br>';
2024-11-28 12:40:38 +00:00
print ajax_autoselect('restorecommand');
2017-07-12 20:52:56 +00:00
2024-11-28 12:40:38 +00:00
if (GETPOST("action") != 'showpass' && $dolibarr_main_db_pass) {
print '<br><a href="'.$_SERVER["PHP_SELF"].'?action=showpass&token='.newToken().'&radio_dump=mysql_options">'.$langs->trans("UnHidePassword").'</a>';
2023-12-13 11:46:23 +00:00
}
2024-11-28 12:40:38 +00:00
//else print '<br><a href="'.$_SERVER["PHP_SELF"].'?radio_dump=mysql_options">'.$langs->trans("HidePassword").'</a>';
print '</div>';
2025-10-20 13:12:35 +00:00
2024-11-28 12:40:38 +00:00
print '</fieldset>';
2025-10-20 13:12:35 +00:00
print '<br>';
2023-12-13 11:46:23 +00:00
} elseif (in_array($type, array('pgsql'))) {
print '<fieldset id="postgresql_options">';
print '<legend>Restore PostgreSQL</legend>';
print '<div class="formelementrow">';
// Parameters execution
2023-12-13 11:46:23 +00:00
$command = $db->getPathOfRestore();
if (preg_match("/\s/", $command)) {
$command = $command = escapeshellarg($command); // Use quotes on command
}
2023-12-13 11:46:23 +00:00
$param = " -d ".$dolibarr_main_db_name;
$param .= " -h ".$dolibarr_main_db_host;
if (!empty($dolibarr_main_db_port)) {
$param .= " -p ".$dolibarr_main_db_port;
2021-02-26 21:04:03 +00:00
}
2023-12-13 11:46:23 +00:00
$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";
// With psql:
$paramcrypted .= " -f";
$paramclear .= " -f";
echo $langs->trans("ImportPostgreSqlDesc");
print '<br>';
2024-11-28 12:40:38 +00:00
print '<textarea rows="1" id="restorecommand" class="centpercent">'.$langs->trans("ImportPostgreSqlCommand", $command, ($action == 'showpass' ? $paramclear : $paramcrypted)).'</textarea><br>';
2023-12-13 11:46:23 +00:00
print ajax_autoselect('restorecommand');
print '</div>';
print '<br>';
print '</fieldset>';
}
2009-01-23 14:46:33 +00:00
2019-10-19 23:09:11 +00:00
print '</div>';
2019-10-19 23:09:11 +00:00
print '</td></tr></table>';
print '</fieldset>';
2025-10-20 13:12:35 +00:00
print "<br>\n";
print "<!-- Save setup conf -->\n";
print '<fieldset><legend class="legendforfieldsetstep" style="font-size: 3em">3</legend>';
print '<br>';
print '<span class="opacitymedium">';
2026-03-31 21:54:33 +00:00
print $langs->trans("RestoreDesc4", 'dolibarr_main_instance_unique_id '.$langs->transnoentitiesnoconv("or").' dolibarr_main_dolcrypt_key').'<br>';
2025-10-20 13:12:35 +00:00
print '</span>';
print '<br>';
print '<div id="backupfileright">';
print $langs->trans("SeeValueIntoConfPhp");
//print $langs->trans("SeeValueIntoConfPhp2");
print '<br>';
print '<br>';
print '</div>';
print '</fieldset>';
2018-07-28 12:29:28 +00:00
// End of page
2011-12-28 00:28:16 +00:00
llxFooter();
$db->close();