From c07bbde11dbc6602e8427e35402b006106e55e59 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 19 Aug 2010 08:09:27 +0000 Subject: [PATCH] * restore to current system charset, to force all restores to utf-8, and do NOT halt on sql errors in restore --- phpgwapi/inc/class.db_backup.inc.php | 35 ++++++++++++++++++++-------- setup/db_backup.php | 7 +++--- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/phpgwapi/inc/class.db_backup.inc.php b/phpgwapi/inc/class.db_backup.inc.php index 94443aca32..4ed0cf58c1 100644 --- a/phpgwapi/inc/class.db_backup.inc.php +++ b/phpgwapi/inc/class.db_backup.inc.php @@ -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"))."
\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'); diff --git a/setup/db_backup.php b/setup/db_backup.php index d79194e6ad..da4a019172 100644 --- a/setup/db_backup.php +++ b/setup/db_backup.php @@ -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 '

'.lang('restore started, this might take a few minutes ...')."

\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 '

'.lang('You should %1log out%2 and in again, to update your current session!','','')."

\n"; } } else