Browse Source
Try to catch the unique constraint violation on migrating the data
Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/5242/head
Joas Schilling
5 years ago
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
1 changed files with
18 additions and
1 deletions
-
lib/Migration/Version10000Date20201015134000.php
|
|
|
@ -26,10 +26,12 @@ declare(strict_types=1); |
|
|
|
namespace OCA\Talk\Migration; |
|
|
|
|
|
|
|
use Closure; |
|
|
|
use Doctrine\DBAL\Exception\UniqueConstraintViolationException; |
|
|
|
use Doctrine\DBAL\Types\Types; |
|
|
|
use OCA\Talk\Model\Attendee; |
|
|
|
use OCA\Talk\Participant; |
|
|
|
use OCP\AppFramework\Utility\ITimeFactory; |
|
|
|
use OCP\DB\Exception; |
|
|
|
use OCP\DB\ISchemaWrapper; |
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder; |
|
|
|
use OCP\IDBConnection; |
|
|
|
@ -220,7 +222,22 @@ class Version10000Date20201015134000 extends SimpleMigrationStep { |
|
|
|
->setParameter('last_mention_message', (int) $row['last_mention_message'], IQueryBuilder::PARAM_INT) |
|
|
|
; |
|
|
|
|
|
|
|
$insert->execute(); |
|
|
|
try { |
|
|
|
$insert->execute(); |
|
|
|
} catch (\Exception $e) { |
|
|
|
if (get_class($e) === UniqueConstraintViolationException::class) { |
|
|
|
// UniqueConstraintViolationException before 21
|
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
if (get_class($e) === Exception::class |
|
|
|
// Exception with 21 and later
|
|
|
|
&& $e->getReason() === Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
throw $e; |
|
|
|
} |
|
|
|
} |
|
|
|
$result->closeCursor(); |
|
|
|
} |
|
|
|
|