* Admin/Setup: ignoring doublicate rows from old backups

This commit is contained in:
Ralf Becker 2014-11-13 11:52:28 +00:00
parent fab4618bc6
commit f6ec2dc563

View File

@ -575,7 +575,7 @@ class db_backup
{
if ($rows) // flush pending rows of last table
{
$this->db->insert($table,$rows,False,__LINE__,__FILE__,false,false,$this->schemas[$table]);
$this->insert_multiple($table, $rows, $this->schemas[$table]);
}
$rows = array();
$table = substr($line,7);
@ -631,7 +631,7 @@ class db_backup
$rows[] = $data;
if (count($rows) == $insert_n_rows)
{
$this->db->insert($table,$rows,False,__LINE__,__FILE__,false,false,$this->schemas[$table]);
$this->insert_multiple($table, $rows, $this->schemas[$table]);
$rows = array();
}
}
@ -645,7 +645,12 @@ class db_backup
}
else
{
$this->db->insert($table,$data,False,__LINE__,__FILE__,false,false,$this->schemas[$table]);
try {
$this->db->insert($table,$data,False,__LINE__,__FILE__,false,false,$this->schemas[$table]);
}
catch(egw_exception_db_invalid_sql $e) {
echo "<p>".$e->getMessage()."</p>\n";
}
}
}
else
@ -658,7 +663,7 @@ class db_backup
}
if ($rows) // flush pending rows
{
$this->db->insert($table,$rows,False,__LINE__,__FILE__,false,false,$this->schemas[$table]);
$this->insert_multiple($table, $rows, $this->schemas[$table]);
}
// updated the sequences, if the DB uses them
foreach($this->schemas as $table => $schema)
@ -675,6 +680,33 @@ class db_backup
return $n;
}
/**
* Insert multiple rows ignoring doublicate entries
*
* @param string $table
* @param array $rows
* @param array $schema
*/
private function insert_multiple($table, array $rows, array $schema)
{
try {
$this->db->insert($table, $rows, False, __LINE__, __FILE__, false, false, $schema);
}
catch(egw_exception_db_invalid_sql $e)
{
// try inserting them one by one, ignoring doublicates
foreach($rows as $data)
{
try {
$this->db->insert($table, $data, False, __LINE__, __FILE__, false, false, $schema);
}
catch(egw_exception_db_invalid_sql $e) {
echo "<p>".$e->getMessage()."</p>\n";
}
}
}
}
/**
* Removes a dir, no matter whether it is empty or full
*