Skip to content

Commit

Permalink
Merge pull request #27 from lingoda/12-avoid-double-insert
Browse files Browse the repository at this point in the history
12 - avoid double insert unique constraint exception
  • Loading branch information
jorisdugue authored Dec 7, 2020
2 parents 252a1ed + 12e9de6 commit b9de957
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Core/H5PSymfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Doctrine\ORM\Query\Expr;
use Doctrine\DBAL\Exception\ConnectionException;
use Doctrine\DBAL\Exception\TableNotFoundException;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;

class H5PSymfony implements \H5PFrameworkInterface
{
Expand Down Expand Up @@ -640,7 +641,11 @@ public function saveLibraryUsage($contentId, $librariesInUse)
$contentLibrary->setDependencyType($dependency['type']);
$this->manager->persist($contentLibrary);
}
$this->manager->flush();
try {
// avoid content libraries inserted at the same time from two diff requests
$this->manager->flush();
} catch (UniqueConstraintViolationException $exception) {
}
}

/**
Expand Down

0 comments on commit b9de957

Please sign in to comment.