mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-03 04:29:28 +01:00
Fix backup->restore() as discussed on the devel list:
- Internationalization of error messages. - Typos - Add missing code documentation - Respect return code of db->transaction_commit() - Add missing filename arguments in restore() calls.
This commit is contained in:
parent
4a709b2024
commit
9c5fd08d90
@ -183,7 +183,7 @@ class db_backup
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens the backup-file using the highest availible compression
|
* Opens the backup-file using the highest available compression
|
||||||
*
|
*
|
||||||
* @param $name=false string/boolean filename to use, or false for the default one
|
* @param $name=false string/boolean filename to use, or false for the default one
|
||||||
* @param $reading=false opening for reading ('rb') or writing ('wb')
|
* @param $reading=false opening for reading ('rb') or writing ('wb')
|
||||||
@ -216,7 +216,7 @@ class db_backup
|
|||||||
{
|
{
|
||||||
$this->backup_files = false;
|
$this->backup_files = false;
|
||||||
//echo ' -> (new ZipArchive) == NULL<br>'; // !
|
//echo ' -> (new ZipArchive) == NULL<br>'; // !
|
||||||
return lang("Cant open $name, needs ZipArchive")."<br>";
|
return lang("Cant open %1, needs ZipArchive", $name)."<br>\n";
|
||||||
}
|
}
|
||||||
if(!($f = fopen($name, $mode)))
|
if(!($f = fopen($name, $mode)))
|
||||||
{
|
{
|
||||||
@ -336,6 +336,9 @@ class db_backup
|
|||||||
*
|
*
|
||||||
* @param resource $f file opened with fopen for reading
|
* @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=false 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.
|
||||||
|
*
|
||||||
|
* @returns An empty string or an error message in case of failure.
|
||||||
*/
|
*/
|
||||||
function restore($f,$convert_to_system_charset=false,$filename='')
|
function restore($f,$convert_to_system_charset=false,$filename='')
|
||||||
{
|
{
|
||||||
@ -370,10 +373,11 @@ class db_backup
|
|||||||
$_f = NULL;
|
$_f = NULL;
|
||||||
if($type == 'zip')
|
if($type == 'zip')
|
||||||
{
|
{
|
||||||
|
// has already been verified to be available in fopen_backup
|
||||||
$zip = new ZipArchive;
|
$zip = new ZipArchive;
|
||||||
if(($zip->open($filename)) !== TRUE)
|
if(($zip->open($filename)) !== TRUE)
|
||||||
{
|
{
|
||||||
return "Cant open '$filename' for reading<br>";
|
return lang("Cant open '%1' for %2", $filename, lang("reading"))."<br>\n";
|
||||||
}
|
}
|
||||||
self::remove_dir_content($dir); // removes the files-dir
|
self::remove_dir_content($dir); // removes the files-dir
|
||||||
$zip->extractTo($dir);
|
$zip->extractTo($dir);
|
||||||
@ -383,6 +387,7 @@ class db_backup
|
|||||||
if(!($f = fopen($name, 'rb')))
|
if(!($f = fopen($name, 'rb')))
|
||||||
{
|
{
|
||||||
return "Cant open $name for reading<br>";
|
return "Cant open $name for reading<br>";
|
||||||
|
return lang("Cant open '%1' for %2", $filename, lang("reading"))."<br>\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$table = False;
|
$table = False;
|
||||||
@ -520,7 +525,11 @@ class db_backup
|
|||||||
unlink($name);
|
unlink($name);
|
||||||
rmdir($dir.'/database_backup');
|
rmdir($dir.'/database_backup');
|
||||||
}
|
}
|
||||||
$this->db->transaction_commit();
|
if (!$this->db->transaction_commit())
|
||||||
|
{
|
||||||
|
return lang('Restore failed');
|
||||||
|
}
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -647,7 +656,7 @@ class db_backup
|
|||||||
if($res !== TRUE)
|
if($res !== TRUE)
|
||||||
{
|
{
|
||||||
//echo ' -> !$res<br>'; // !
|
//echo ' -> !$res<br>'; // !
|
||||||
return "Cant open '$filename'<br>";
|
return lang("Cant open '%1' for %2", $filename, lang("writing"))."<br>\n";
|
||||||
}
|
}
|
||||||
$file_list = $this->get_file_list($dir);
|
$file_list = $this->get_file_list($dir);
|
||||||
}
|
}
|
||||||
@ -694,7 +703,11 @@ class db_backup
|
|||||||
}
|
}
|
||||||
if(!$zippresent) // save without files
|
if(!$zippresent) // save without files
|
||||||
{
|
{
|
||||||
if ($this->backup_files) echo '<center>'."No file backup, needs ZipArchive or disabled<br>".'</center>';
|
if ($this->backup_files)
|
||||||
|
{
|
||||||
|
echo '<center>'.lang("Cant open %1, needs ZipArchive", $name)."<br>\n".'</center>';
|
||||||
|
}
|
||||||
|
|
||||||
fclose($f);
|
fclose($f);
|
||||||
if (file_exists($name)) unlink($name);
|
if (file_exists($name)) unlink($name);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -89,7 +89,7 @@ class setup_cmd_install extends setup_cmd
|
|||||||
{
|
{
|
||||||
ob_start(); // restore echos the table structure
|
ob_start(); // restore echos the table structure
|
||||||
}
|
}
|
||||||
$db_backup->restore($f,$this->charset);
|
$db_backup->restore($f,$this->charset,$this->backup);
|
||||||
fclose($f);
|
fclose($f);
|
||||||
|
|
||||||
if (!$this->verbose)
|
if (!$this->verbose)
|
||||||
|
@ -313,7 +313,7 @@ switch($GLOBALS['egw_info']['setup']['stage']['db'])
|
|||||||
if (is_resource($f = $db_backup->fopen_backup($_FILES['uploaded']['tmp_name'],true)))
|
if (is_resource($f = $db_backup->fopen_backup($_FILES['uploaded']['tmp_name'],true)))
|
||||||
{
|
{
|
||||||
echo '<p align="center">'.lang('restore started, this might take a few minutes ...')."</p>\n".str_repeat(' ',4096);
|
echo '<p align="center">'.lang('restore started, this might take a few minutes ...')."</p>\n".str_repeat(' ',4096);
|
||||||
$db_backup->restore($f,$_POST['convert_charset']);
|
$db_backup->restore($f,$_POST['convert_charset'],$_FILES['uploaded']['tmp_name']);
|
||||||
fclose($f);
|
fclose($f);
|
||||||
echo '<p align="center">'.lang('restore finished')."</p>\n";
|
echo '<p align="center">'.lang('restore finished')."</p>\n";
|
||||||
unlink($_FILES['uploaded']['tmp_name']);
|
unlink($_FILES['uploaded']['tmp_name']);
|
||||||
|
Loading…
Reference in New Issue
Block a user