mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Reduced duplication in ApiKeyRepository
This commit is contained in:
parent
f5138385be
commit
c841e57db5
@ -12,17 +12,17 @@ class ApiKeyRepository extends EntitySpecificationRepository implements ApiKeyRe
|
||||
{
|
||||
public function createInitialApiKey(string $apiKey): void
|
||||
{
|
||||
$this->getEntityManager()->wrapInTransaction(function () use ($apiKey): void {
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
$amountOfApiKeys = $qb->select('COUNT(a.id)')
|
||||
$em = $this->getEntityManager();
|
||||
$em->wrapInTransaction(function () use ($apiKey, $em): void {
|
||||
$amountOfApiKeys = $em->createQueryBuilder()->select('COUNT(a.id)')
|
||||
->from(ApiKey::class, 'a')
|
||||
->getQuery()
|
||||
->setLockMode(LockMode::PESSIMISTIC_WRITE)
|
||||
->getSingleScalarResult();
|
||||
|
||||
if ($amountOfApiKeys === 0) {
|
||||
$this->getEntityManager()->persist(ApiKey::fromKey($apiKey));
|
||||
$this->getEntityManager()->flush();
|
||||
$em->persist(ApiKey::fromKey($apiKey));
|
||||
$em->flush();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user