From aca89f9abe393e4b03f8c7473b3ac4470bec1560 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 7 Apr 2018 08:21:34 +0200 Subject: [PATCH 1/5] Updated links to doctrine CLI scripts to avoid depending on symlinks --- module/CLI/src/Command/Install/InstallCommand.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module/CLI/src/Command/Install/InstallCommand.php b/module/CLI/src/Command/Install/InstallCommand.php index 06f1be93..80f0a2c7 100644 --- a/module/CLI/src/Command/Install/InstallCommand.php +++ b/module/CLI/src/Command/Install/InstallCommand.php @@ -134,7 +134,7 @@ class InstallCommand extends Command if (! $this->isUpdate) { $this->io->write('Initializing database...'); if (! $this->runCommand( - 'php vendor/bin/doctrine orm:schema-tool:create', + 'php vendor/doctrine/orm/bin/doctrine orm:schema-tool:create', 'Error generating database.', $output )) { @@ -145,7 +145,7 @@ class InstallCommand extends Command // Run database migrations $this->io->write('Updating database...'); if (! $this->runCommand( - 'php vendor/bin/doctrine-migrations migrations:migrate', + 'php vendor/doctrine/migrations/bin/doctrine-migrations migrations:migrate', 'Error updating database.', $output )) { @@ -155,7 +155,7 @@ class InstallCommand extends Command // Generate proxies $this->io->write('Generating proxies...'); if (! $this->runCommand( - 'php vendor/bin/doctrine orm:generate-proxies', + 'php vendor/doctrine/orm/bin/doctrine orm:generate-proxies', 'Error generating proxies.', $output )) { From b3e25f28fdfa289cce91e1d40d12762cbeec7d54 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 7 Apr 2018 08:25:01 +0200 Subject: [PATCH 2/5] Added v1.8.1 to changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 114abffc..1f62669f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ### 1.8.1 +**Bugs:** + +* [140: Installation failed. Warning thrown while trying to include doctrine script](https://github.com/shlinkio/shlink/issues/140) + +### 1.8.0 + **Features** * [125: Implement a path which returns a 1px image instead of a redirection](https://github.com/shlinkio/shlink/issues/125) From 91d350b12fea4ba577471f712e6c8193da9bbda4 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 7 Apr 2018 08:31:03 +0200 Subject: [PATCH 3/5] Removed path workaround in PathVersionMiddleware and simplified code --- .../autoload/middleware-pipeline.global.php | 2 +- .../src/Middleware/PathVersionMiddleware.php | 17 +++------------ .../Middleware/PathVersionMiddlewareTest.php | 21 +++---------------- 3 files changed, 7 insertions(+), 33 deletions(-) diff --git a/config/autoload/middleware-pipeline.global.php b/config/autoload/middleware-pipeline.global.php index dad75c13..afdd78ef 100644 --- a/config/autoload/middleware-pipeline.global.php +++ b/config/autoload/middleware-pipeline.global.php @@ -21,7 +21,7 @@ return [ 'priority' => 11, ], 'pre-routing-rest' => [ -// 'path' => '/rest', + 'path' => '/rest', 'middleware' => [ PathVersionMiddleware::class, ], diff --git a/module/Rest/src/Middleware/PathVersionMiddleware.php b/module/Rest/src/Middleware/PathVersionMiddleware.php index f8fc0113..40de9af1 100644 --- a/module/Rest/src/Middleware/PathVersionMiddleware.php +++ b/module/Rest/src/Middleware/PathVersionMiddleware.php @@ -18,27 +18,16 @@ class PathVersionMiddleware implements MiddlewareInterface * @param RequestHandlerInterface $handler * * @return Response + * @throws \InvalidArgumentException */ public function process(Request $request, RequestHandlerInterface $handler): Response { $uri = $request->getUri(); $path = $uri->getPath(); - // TODO Workaround... Do not process the request if it does not start with rest - if (\strpos($path, '/rest') !== 0) { - return $handler->handle($request); - } - // If the path does not begin with the version number, prepend v1 by default for BC compatibility purposes - if (\strpos($path, '/rest/v') !== 0) { - $parts = \explode('/', $path); - // Remove the first empty part and the rest part - \array_shift($parts); - \array_shift($parts); - // Prepend the version prefix - \array_unshift($parts, '/rest/v1'); - - $request = $request->withUri($uri->withPath(\implode('/', $parts))); + if (\strpos($path, '/v') !== 0) { + $request = $request->withUri($uri->withPath('/v1' . $uri->getPath())); } return $handler->handle($request); diff --git a/module/Rest/test/Middleware/PathVersionMiddlewareTest.php b/module/Rest/test/Middleware/PathVersionMiddlewareTest.php index e024c128..ae483abf 100644 --- a/module/Rest/test/Middleware/PathVersionMiddlewareTest.php +++ b/module/Rest/test/Middleware/PathVersionMiddlewareTest.php @@ -30,22 +30,7 @@ class PathVersionMiddlewareTest extends TestCase */ public function whenVersionIsProvidedRequestRemainsUnchanged() { - $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/rest/v2/foo')); - - $delegate = $this->prophesize(RequestHandlerInterface::class); - $process = $delegate->handle($request)->willReturn(new Response()); - - $this->middleware->process($request, $delegate->reveal()); - - $process->shouldHaveBeenCalled(); - } - - /** - * @test - */ - public function whenPathDoesNotStartWithRestRemainsUnchanged() - { - $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/foo')); + $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/v2/foo')); $delegate = $this->prophesize(RequestHandlerInterface::class); $process = $delegate->handle($request)->willReturn(new Response()); @@ -60,14 +45,14 @@ class PathVersionMiddlewareTest extends TestCase */ public function versionOneIsPrependedWhenNoVersionIsDefined() { - $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/rest/bar/baz')); + $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/bar/baz')); $delegate = $this->prophesize(RequestHandlerInterface::class); $delegate->handle(Argument::type(Request::class))->will(function (array $args) use ($request) { $req = \array_shift($args); Assert::assertNotSame($request, $req); - Assert::assertEquals('/rest/v1/bar/baz', $req->getUri()->getPath()); + Assert::assertEquals('/v1/bar/baz', $req->getUri()->getPath()); return new Response(); }); From b4ded374e99e50f2ed5d53542f8d43de8286adea Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 7 Apr 2018 08:32:06 +0200 Subject: [PATCH 4/5] Updated changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f62669f..2f4ed213 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ### 1.8.1 +**Tasks** + +* [141: Remove workaround used in PathVersionMiddleware](https://github.com/shlinkio/shlink/issues/141) + **Bugs:** * [140: Installation failed. Warning thrown while trying to include doctrine script](https://github.com/shlinkio/shlink/issues/140) From 8793a67ce9ddd85faba79407364d8ed7f3bb4e2e Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 7 Apr 2018 08:37:41 +0200 Subject: [PATCH 5/5] Reduced the number of includes by pointing to dcotrine scripts with extension --- data/infra/database/.gitignore | 0 data/infra/nginx/.gitignore | 0 module/CLI/src/Command/Install/InstallCommand.php | 6 +++--- 3 files changed, 3 insertions(+), 3 deletions(-) mode change 100644 => 100755 data/infra/database/.gitignore mode change 100644 => 100755 data/infra/nginx/.gitignore diff --git a/data/infra/database/.gitignore b/data/infra/database/.gitignore old mode 100644 new mode 100755 diff --git a/data/infra/nginx/.gitignore b/data/infra/nginx/.gitignore old mode 100644 new mode 100755 diff --git a/module/CLI/src/Command/Install/InstallCommand.php b/module/CLI/src/Command/Install/InstallCommand.php index 80f0a2c7..7c2ef2e2 100644 --- a/module/CLI/src/Command/Install/InstallCommand.php +++ b/module/CLI/src/Command/Install/InstallCommand.php @@ -134,7 +134,7 @@ class InstallCommand extends Command if (! $this->isUpdate) { $this->io->write('Initializing database...'); if (! $this->runCommand( - 'php vendor/doctrine/orm/bin/doctrine orm:schema-tool:create', + 'php vendor/doctrine/orm/bin/doctrine.php orm:schema-tool:create', 'Error generating database.', $output )) { @@ -145,7 +145,7 @@ class InstallCommand extends Command // Run database migrations $this->io->write('Updating database...'); if (! $this->runCommand( - 'php vendor/doctrine/migrations/bin/doctrine-migrations migrations:migrate', + 'php vendor/doctrine/migrations/bin/doctrine-migrations.php migrations:migrate', 'Error updating database.', $output )) { @@ -155,7 +155,7 @@ class InstallCommand extends Command // Generate proxies $this->io->write('Generating proxies...'); if (! $this->runCommand( - 'php vendor/doctrine/orm/bin/doctrine orm:generate-proxies', + 'php vendor/doctrine/orm/bin/doctrine.php orm:generate-proxies', 'Error generating proxies.', $output )) {