mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-23 07:33:58 -06:00
Add missing default value for short url visits count
This commit is contained in:
parent
054eb42613
commit
6fbb5a380d
@ -28,6 +28,7 @@ return static function (ClassMetadata $metadata, array $emConfig): void {
|
||||
$builder->createField('count', Types::BIGINT)
|
||||
->columnName('count')
|
||||
->option('unsigned', true)
|
||||
->option('default', 1)
|
||||
->build();
|
||||
|
||||
$builder->createField('slotId', Types::INTEGER)
|
||||
|
@ -108,17 +108,20 @@ final readonly class ShortUrlVisitsCountPreFlushListener
|
||||
// For engines without a specific UPSERT syntax, do a regular locked select followed by an insert or update
|
||||
$qb = $conn->createQueryBuilder();
|
||||
$qb->select('id')
|
||||
->from('short_url_visits_counts')
|
||||
->where($qb->expr()->and(
|
||||
$qb->expr()->eq('short_url_id', ':short_url_id'),
|
||||
$qb->expr()->eq('potential_bot', ':potential_bot'),
|
||||
$qb->expr()->eq('slot_id', ':slot_id'),
|
||||
))
|
||||
->setParameter('short_url_id', $shortUrlId)
|
||||
->setParameter('potential_bot', $potentialBot)
|
||||
->setParameter('slot_id', $slotId)
|
||||
->forUpdate()
|
||||
->setMaxResults(1);
|
||||
->from('short_url_visits_counts')
|
||||
->where($qb->expr()->and(
|
||||
$qb->expr()->eq('short_url_id', ':short_url_id'),
|
||||
$qb->expr()->eq('potential_bot', ':potential_bot'),
|
||||
$qb->expr()->eq('slot_id', ':slot_id'),
|
||||
))
|
||||
->setParameter('short_url_id', $shortUrlId)
|
||||
->setParameter('potential_bot', $potentialBot)
|
||||
->setParameter('slot_id', $slotId)
|
||||
->setMaxResults(1);
|
||||
|
||||
if ($conn->getDatabasePlatform()::class === SQLServerPlatform::class) {
|
||||
$qb->forUpdate();
|
||||
}
|
||||
|
||||
$resultSet = $qb->executeQuery()->fetchOne();
|
||||
$writeQb = ! $resultSet
|
||||
@ -130,17 +133,17 @@ final readonly class ShortUrlVisitsCountPreFlushListener
|
||||
'slot_id' => ':slot_id',
|
||||
])
|
||||
: $conn->createQueryBuilder()
|
||||
->update('short_url_visits_counts')
|
||||
->set('count', 'count + 1')
|
||||
->where($qb->expr()->and(
|
||||
$qb->expr()->eq('short_url_id', ':short_url_id'),
|
||||
$qb->expr()->eq('potential_bot', ':potential_bot'),
|
||||
$qb->expr()->eq('slot_id', ':slot_id'),
|
||||
));
|
||||
->update('short_url_visits_counts')
|
||||
->set('count', 'count + 1')
|
||||
->where($qb->expr()->and(
|
||||
$qb->expr()->eq('short_url_id', ':short_url_id'),
|
||||
$qb->expr()->eq('potential_bot', ':potential_bot'),
|
||||
$qb->expr()->eq('slot_id', ':slot_id'),
|
||||
));
|
||||
|
||||
$writeQb->setParameter('short_url_id', $shortUrlId)
|
||||
->setParameter('potential_bot', $potentialBot)
|
||||
->setParameter('slot_id', $slotId)
|
||||
->executeStatement();
|
||||
->setParameter('potential_bot', $potentialBot)
|
||||
->setParameter('slot_id', $slotId)
|
||||
->executeStatement();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user