mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-07 08:34:42 +01:00
* Setup/Admin: restoring 10 rows per sql statement to speed up restore
This commit is contained in:
parent
ec8eedce63
commit
c3e0a2ab15
@ -341,10 +341,11 @@ class db_backup
|
||||
* @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)
|
||||
* @param int $insert_n_rows=10 how many rows to insert in one sql statement
|
||||
*
|
||||
* @returns An empty string or an error message in case of failure.
|
||||
*/
|
||||
function restore($f,$convert_to_system_charset=true,$filename='',$protect_system_config=true)
|
||||
function restore($f,$convert_to_system_charset=true,$filename='',$protect_system_config=true, $insert_n_rows=10)
|
||||
{
|
||||
@set_time_limit(0);
|
||||
ini_set('auto_detect_line_endings',true);
|
||||
@ -462,6 +463,11 @@ class db_backup
|
||||
}
|
||||
if (substr($line,0,7) == 'table: ')
|
||||
{
|
||||
if ($rows) // flush pending rows of last table
|
||||
{
|
||||
$this->db->insert($table,$rows,False,__LINE__,__FILE__,false,false,$this->schemas[$table]);
|
||||
}
|
||||
$rows = array();
|
||||
$table = substr($line,7);
|
||||
|
||||
$cols = self::csv_split($line=fgets($f)); ++$n;
|
||||
@ -501,7 +507,19 @@ class db_backup
|
||||
{
|
||||
$data = translation::convert($data,$charset);
|
||||
}
|
||||
$this->db->insert($table,$data,False,__LINE__,__FILE__,false,false,$this->schemas[$table]);
|
||||
if ($insert_n_rows > 1)
|
||||
{
|
||||
$rows[] = $data;
|
||||
if (count($rows) == $insert_n_rows)
|
||||
{
|
||||
$this->db->insert($table,$rows,False,__LINE__,__FILE__,false,false,$this->schemas[$table]);
|
||||
$rows = array();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->insert($table,$data,False,__LINE__,__FILE__,false,false,$this->schemas[$table]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -511,6 +529,10 @@ class db_backup
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($rows) // flush pending rows
|
||||
{
|
||||
$this->db->insert($table,$rows,False,__LINE__,__FILE__,false,false,$this->schemas[$table]);
|
||||
}
|
||||
// updated the sequences, if the DB uses them
|
||||
foreach($this->schemas as $table => $schema)
|
||||
{
|
||||
|
@ -1787,7 +1787,25 @@ class egw_db
|
||||
$table = self::$tablealiases[$table];
|
||||
}
|
||||
$inputarr = false;
|
||||
if ($use_prepared_statement && $this->Link_ID->_bindInputArray) // eg. MaxDB
|
||||
if (isset($data[0]) && is_array($data[0])) // multiple data rows
|
||||
{
|
||||
if ($where) throw new egw_exception_wrong_parameter('Can NOT use $where together with multiple data rows in $data!');
|
||||
|
||||
$sql = "$cmd INTO $table ";
|
||||
foreach($data as $k => $d)
|
||||
{
|
||||
if (!$k)
|
||||
{
|
||||
$sql .= $this->column_data_implode(',',$d,'VALUES',true,$table_def['fd']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql .= ",\n(".$this->column_data_implode(',',$d,false,true,$table_def['fd']).')';
|
||||
}
|
||||
}
|
||||
$sql .= $sql_append;
|
||||
}
|
||||
elseif ($use_prepared_statement && $this->Link_ID->_bindInputArray) // eg. MaxDB
|
||||
{
|
||||
$this->Link_ID->Param(false); // reset param-counter
|
||||
$cols = array_keys($data);
|
||||
|
@ -186,8 +186,9 @@ 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);
|
||||
$start = time();
|
||||
$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));
|
||||
$setup_tpl->set_var('error_msg',lang("backup '%1' restored",$file).' ('.(time()-$start).' s)');
|
||||
if ($run_in_egw)
|
||||
{
|
||||
// updating the backup
|
||||
|
Loading…
Reference in New Issue
Block a user