* Admin/Setup: ignoring doublicate rows from old backups

This commit is contained in:
Ralf Becker 2014-11-13 11:51:49 +00:00
parent 8f713fe2f1
commit debe67be86

View File

@ -575,7 +575,7 @@ class db_backup
{ {
if ($rows) // flush pending rows of last table 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(); $rows = array();
$table = substr($line,7); $table = substr($line,7);
@ -631,7 +631,7 @@ class db_backup
$rows[] = $data; $rows[] = $data;
if (count($rows) == $insert_n_rows) 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(); $rows = array();
} }
} }
@ -645,7 +645,12 @@ class db_backup
} }
else 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 else
@ -658,7 +663,7 @@ class db_backup
} }
if ($rows) // flush pending rows 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 // updated the sequences, if the DB uses them
foreach($this->schemas as $table => $schema) foreach($this->schemas as $table => $schema)
@ -675,6 +680,33 @@ class db_backup
return $n; 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 * Removes a dir, no matter whether it is empty or full
* *