fix restoring 1.8 database gave "Duplicate entry" error by mapping that (again) to InvalidSql exception (was changed due to PHP 8)

This commit is contained in:
ralf 2023-06-30 10:00:47 +02:00
parent 3cfdca0ae9
commit 95ba35bfeb
2 changed files with 7 additions and 4 deletions

View File

@ -819,7 +819,10 @@ class Db
catch(\mysqli_sql_exception $e) {
if (!($reconnect && $this->Type == 'mysql' && ($e->getCode() == 2006 || $e->getMessage() === 'MySQL server has gone away')))
{
if ($e->getCode() == 1064) // You have an error in your SQL syntax
if (in_array($e->getCode(), [
1064, // You have an error in your SQL syntax
1062, // Duplicate entry
]))
{
throw new Db\Exception\InvalidSql($e->getMessage(), $e->getCode(), $e);
}

View File

@ -691,7 +691,7 @@ class Backup
}
/**
* Insert multiple rows ignoring doublicate entries
* Insert multiple rows ignoring duplicate entries
*
* @param string $table
* @param array $rows
@ -704,14 +704,14 @@ class Backup
}
catch(Exception\InvalidSql $e)
{
// try inserting them one by one, ignoring doublicates
// try inserting them one by one, ignoring duplicates
foreach($rows as $data)
{
try {
$this->db->insert($table, $data, False, __LINE__, __FILE__, false, false, $schema);
}
catch(Exception\InvalidSql $e) {
echo "<p>".$e->getMessage()."</p>\n";
echo "<p>$table: ".$e->getMessage()." ignored</p>\n";
}
}
}