From debe67be86717ebed89527da3188fd67efe87fca Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 13 Nov 2014 11:51:49 +0000 Subject: [PATCH] * Admin/Setup: ignoring doublicate rows from old backups --- phpgwapi/inc/class.db_backup.inc.php | 40 +++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/phpgwapi/inc/class.db_backup.inc.php b/phpgwapi/inc/class.db_backup.inc.php index d349ce4dbd..9bc4563fc8 100644 --- a/phpgwapi/inc/class.db_backup.inc.php +++ b/phpgwapi/inc/class.db_backup.inc.php @@ -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 "

".$e->getMessage()."

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

".$e->getMessage()."

\n"; + } + } + } + } + /** * Removes a dir, no matter whether it is empty or full *