mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-26 00:29:38 +01:00
* restore to current system charset, to force all restores to utf-8, and do NOT halt on sql errors in restore
This commit is contained in:
parent
6699869e2b
commit
a65406b88b
@ -347,23 +347,26 @@ class db_backup
|
||||
'httpproxy_port',
|
||||
'httpproxy_server_username',
|
||||
'httpproxy_server_password',
|
||||
'system_charset',
|
||||
);
|
||||
|
||||
/**
|
||||
* Backup all data in the form of a (compressed) csv file
|
||||
*
|
||||
* @param resource $f file opened with fopen for reading
|
||||
* @param boolean $convert_to_system_charset=false convert the restored data to the selected system-charset
|
||||
* @param boolean $convert_to_system_charset=true convert the restored data to the selected system-charset
|
||||
* @param string $filename='' gives the file name which is used in case of a zip archive.
|
||||
* @param boolean $protect_system_config=true should above system_config values be protected (NOT overwritten)
|
||||
*
|
||||
* @returns An empty string or an error message in case of failure.
|
||||
*/
|
||||
function restore($f,$convert_to_system_charset=false,$filename='',$protect_system_config=true)
|
||||
function restore($f,$convert_to_system_charset=true,$filename='',$protect_system_config=true)
|
||||
{
|
||||
@set_time_limit(0);
|
||||
ini_set('auto_detect_line_endings',true);
|
||||
|
||||
$convert_to_system_charset = true; // enforce now utf-8 as system charset restores of old backups
|
||||
|
||||
if ($protect_system_config)
|
||||
{
|
||||
$system_config = array();
|
||||
@ -419,6 +422,12 @@ class db_backup
|
||||
return lang("Cant open '%1' for %2", $filename, lang("reading"))."<br>\n";
|
||||
}
|
||||
}
|
||||
// do not stop if for whatever reason some sql statement fails
|
||||
if ($this->db->Halt_On_Error != 'no')
|
||||
{
|
||||
$backup_db_halt_on_error = $this->db->Halt_On_Error;
|
||||
$this->db->Halt_On_Error = 'no';
|
||||
}
|
||||
$table = False;
|
||||
$n = 0;
|
||||
while(!feof($f))
|
||||
@ -547,14 +556,7 @@ class db_backup
|
||||
'config_name' => 'system_charset',
|
||||
),__LINE__,__FILE__);
|
||||
}
|
||||
// zip?
|
||||
if($type == 'zip')
|
||||
{
|
||||
fclose($f);
|
||||
$f = $save_f;
|
||||
unlink($name);
|
||||
rmdir($dir.'/database_backup');
|
||||
}
|
||||
// restore protected system config
|
||||
if ($protect_system_config)
|
||||
{
|
||||
foreach($system_config as $row)
|
||||
@ -565,6 +567,19 @@ class db_backup
|
||||
),__LINE__,__FILE__);
|
||||
}
|
||||
}
|
||||
// restore original Halt_On_Error state (if changed)
|
||||
if ($backup_db_halt_on_error)
|
||||
{
|
||||
$this->db->Halt_On_Error = $backup_db_halt_on_error;
|
||||
}
|
||||
// zip?
|
||||
if($type == 'zip')
|
||||
{
|
||||
fclose($f);
|
||||
$f = $save_f;
|
||||
unlink($name);
|
||||
rmdir($dir.'/database_backup');
|
||||
}
|
||||
if (!$this->db->transaction_commit())
|
||||
{
|
||||
return lang('Restore failed');
|
||||
|
@ -28,8 +28,8 @@ if (!is_object(@$GLOBALS['egw'])) // called from outside eGW ==> setup
|
||||
$tpl_root = $GLOBALS['egw_setup']->html->setup_tpl_dir('setup');
|
||||
$self = 'db_backup.php';
|
||||
}
|
||||
$db_backup = CreateObject('phpgwapi.db_backup');
|
||||
$asyncservice = CreateObject('phpgwapi.asyncservice');
|
||||
$db_backup = new db_backup();
|
||||
$asyncservice = new asyncservice();
|
||||
|
||||
// download a backup, has to be before any output !!!
|
||||
if ($_POST['download'])
|
||||
@ -176,7 +176,7 @@ if ($_POST['restore'])
|
||||
if (is_resource($f = $db_backup->fopen_backup($file,true)))
|
||||
{
|
||||
echo '<p align="center">'.lang('restore started, this might take a few minutes ...')."</p>\n".str_repeat(' ',4096);
|
||||
$db_backup->restore($f, FALSE, $file);
|
||||
$db_backup->restore($f, true, $file); // allways convert to current system charset on restore
|
||||
$setup_tpl->set_var('error_msg',lang("backup '%1' restored",$file));
|
||||
if ($run_in_egw)
|
||||
{
|
||||
@ -185,6 +185,7 @@ if ($_POST['restore'])
|
||||
$GLOBALS['egw_info']['server']['header_admin_user']='admin',
|
||||
$GLOBALS['egw_info']['server']['header_admin_password']=uniqid('pw',true),false,true);
|
||||
echo $cmd->run()."\n";
|
||||
echo '<h3>'.lang('You should %1log out%2 and in again, to update your current session!','<a href="'.egw::link('/logout.php').'" target="_parent">','</a>')."</h3>\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user