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
|
public function createInitialApiKey(string $apiKey): void
|
||||||
{
|
{
|
||||||
$this->getEntityManager()->wrapInTransaction(function () use ($apiKey): void {
|
$em = $this->getEntityManager();
|
||||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
$em->wrapInTransaction(function () use ($apiKey, $em): void {
|
||||||
$amountOfApiKeys = $qb->select('COUNT(a.id)')
|
$amountOfApiKeys = $em->createQueryBuilder()->select('COUNT(a.id)')
|
||||||
->from(ApiKey::class, 'a')
|
->from(ApiKey::class, 'a')
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->setLockMode(LockMode::PESSIMISTIC_WRITE)
|
->setLockMode(LockMode::PESSIMISTIC_WRITE)
|
||||||
->getSingleScalarResult();
|
->getSingleScalarResult();
|
||||||
|
|
||||||
if ($amountOfApiKeys === 0) {
|
if ($amountOfApiKeys === 0) {
|
||||||
$this->getEntityManager()->persist(ApiKey::fromKey($apiKey));
|
$em->persist(ApiKey::fromKey($apiKey));
|
||||||
$this->getEntityManager()->flush();
|
$em->flush();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user