Try to catch the unique constraint violation on migrating the data

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2021-02-23 08:42:42 +01:00
Родитель 1010839c5a
Коммит 466067ae3c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 7076EA9751AACDDA
1 изменённых файлов: 18 добавлений и 1 удалений

Просмотреть файл

@ -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();
}