mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-22 15:13:59 -06:00
Removed transactionality when dispatching async events, as they run in different processes with different db connections
This commit is contained in:
parent
6f62d62909
commit
c7a621cb31
17
CHANGELOG.md
17
CHANGELOG.md
@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).
|
||||
|
||||
## [Unreleased]
|
||||
### Added
|
||||
* *Nothing*
|
||||
|
||||
### Changed
|
||||
* *Nothing*
|
||||
|
||||
### Deprecated
|
||||
* *Nothing*
|
||||
|
||||
### Removed
|
||||
* *Nothing*
|
||||
|
||||
### Fixed
|
||||
* [#1210](https://github.com/shlinkio/shlink/issues/1210) Fixed real time updates not being notified.
|
||||
|
||||
|
||||
## [2.9.1] - 2021-10-11
|
||||
### Added
|
||||
* *Nothing*
|
||||
|
@ -18,7 +18,7 @@
|
||||
"akrabat/ip-address-middleware": "^2.0",
|
||||
"cakephp/chronos": "^2.2",
|
||||
"cocur/slugify": "^4.0",
|
||||
"doctrine/migrations": "^3.2",
|
||||
"doctrine/migrations": "^3.2 <3.3",
|
||||
"doctrine/orm": "^2.9",
|
||||
"endroid/qr-code": "^4.2",
|
||||
"geoip2/geoip2": "^2.11",
|
||||
|
@ -71,7 +71,7 @@ class CreateDatabaseCommand extends AbstractDatabaseCommand
|
||||
$databases = $schemaManager->listDatabases();
|
||||
$shlinkDatabase = $this->regularConn->getDatabase();
|
||||
|
||||
if (! contains($databases, $shlinkDatabase)) {
|
||||
if ($shlinkDatabase !== null && ! contains($databases, $shlinkDatabase)) {
|
||||
$schemaManager->createDatabase($shlinkDatabase);
|
||||
}
|
||||
}
|
||||
|
@ -69,11 +69,9 @@ class VisitsTracker implements VisitsTrackerInterface
|
||||
}
|
||||
|
||||
$visit = $createVisit($visitor->normalizeForTrackingOptions($this->options));
|
||||
$this->em->transactional(function () use ($visit, $visitor): void {
|
||||
$this->em->persist($visit);
|
||||
$this->em->flush();
|
||||
$this->em->persist($visit);
|
||||
$this->em->flush();
|
||||
|
||||
$this->eventDispatcher->dispatch(new UrlVisited($visit->getId(), $visitor->getRemoteAddress()));
|
||||
});
|
||||
$this->eventDispatcher->dispatch(new UrlVisited($visit->getId(), $visitor->getRemoteAddress()));
|
||||
}
|
||||
}
|
||||
|
@ -29,10 +29,6 @@ class VisitsTrackerTest extends TestCase
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->em = $this->prophesize(EntityManager::class);
|
||||
$this->em->transactional(Argument::any())->will(function (array $args) {
|
||||
[$callback] = $args;
|
||||
return $callback();
|
||||
});
|
||||
|
||||
$this->eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
|
||||
$this->options = new TrackingOptions();
|
||||
@ -52,7 +48,6 @@ class VisitsTrackerTest extends TestCase
|
||||
$this->visitsTracker->{$method}(...$args);
|
||||
|
||||
$persist->shouldHaveBeenCalledOnce();
|
||||
$this->em->transactional(Argument::cetera())->shouldHaveBeenCalledOnce();
|
||||
$this->em->flush()->shouldHaveBeenCalledOnce();
|
||||
$this->eventDispatcher->dispatch(Argument::type(UrlVisited::class))->shouldHaveBeenCalled();
|
||||
}
|
||||
@ -68,7 +63,6 @@ class VisitsTrackerTest extends TestCase
|
||||
$this->visitsTracker->{$method}(...$args);
|
||||
|
||||
$this->eventDispatcher->dispatch(Argument::cetera())->shouldNotHaveBeenCalled();
|
||||
$this->em->transactional(Argument::cetera())->shouldNotHaveBeenCalled();
|
||||
$this->em->persist(Argument::cetera())->shouldNotHaveBeenCalled();
|
||||
$this->em->flush()->shouldNotHaveBeenCalled();
|
||||
}
|
||||
@ -92,7 +86,6 @@ class VisitsTrackerTest extends TestCase
|
||||
$this->visitsTracker->{$method}(Visitor::emptyInstance());
|
||||
|
||||
$this->eventDispatcher->dispatch(Argument::cetera())->shouldNotHaveBeenCalled();
|
||||
$this->em->transactional(Argument::cetera())->shouldNotHaveBeenCalled();
|
||||
$this->em->persist(Argument::cetera())->shouldNotHaveBeenCalled();
|
||||
$this->em->flush()->shouldNotHaveBeenCalled();
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ class HealthAction extends AbstractRestAction
|
||||
public function handle(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$connected = $this->em->getConnection()->ping();
|
||||
$connected = $this->em->getConnection()->isConnected();
|
||||
} catch (Throwable) {
|
||||
$connected = false;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ class HealthActionTest extends TestCase
|
||||
/** @test */
|
||||
public function passResponseIsReturnedWhenConnectionSucceeds(): void
|
||||
{
|
||||
$ping = $this->conn->ping()->willReturn(true);
|
||||
$ping = $this->conn->isConnected()->willReturn(true);
|
||||
|
||||
/** @var JsonResponse $resp */
|
||||
$resp = $this->action->handle(new ServerRequest());
|
||||
@ -54,7 +54,7 @@ class HealthActionTest extends TestCase
|
||||
/** @test */
|
||||
public function failResponseIsReturnedWhenConnectionFails(): void
|
||||
{
|
||||
$ping = $this->conn->ping()->willReturn(false);
|
||||
$ping = $this->conn->isConnected()->willReturn(false);
|
||||
|
||||
/** @var JsonResponse $resp */
|
||||
$resp = $this->action->handle(new ServerRequest());
|
||||
@ -74,7 +74,7 @@ class HealthActionTest extends TestCase
|
||||
/** @test */
|
||||
public function failResponseIsReturnedWhenConnectionThrowsException(): void
|
||||
{
|
||||
$ping = $this->conn->ping()->willThrow(Exception::class);
|
||||
$ping = $this->conn->isConnected()->willThrow(Exception::class);
|
||||
|
||||
/** @var JsonResponse $resp */
|
||||
$resp = $this->action->handle(new ServerRequest());
|
||||
|
Loading…
Reference in New Issue
Block a user