Skip to content

Commit

Permalink
Merge pull request #172 from shlinkio/develop
Browse files Browse the repository at this point in the history
Release 8.2.0
  • Loading branch information
acelaya authored Sep 18, 2022
2 parents 38e418f + 34a1060 commit c3b0d1e
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 10 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ 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).

## [8.2.0] - 2022-09-18
### Added
* Added config option to enable/disable trailing slashes support.
* Added new script to make sure first API key is generated after successfully installing Shlink.

### Changed
* *Nothing*

### Deprecated
* *Nothing*

### Removed
* *Nothing*

### Fixed
* *Nothing*


## [8.1.0] - 2022-08-08
### Added
* *Nothing*
Expand Down
14 changes: 14 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
'URL shortener > Append extra path' => Config\Option\UrlShortener\AppendExtraPathConfigOption::class,
'URL shortener > Multi-segment slugs'
=> Config\Option\UrlShortener\EnableMultiSegmentSlugsConfigOption::class,
'URL shortener > Trailing slashes' => Config\Option\UrlShortener\EnableTrailingSlashConfigOption::class,
'Webhooks > List' => Config\Option\Visit\VisitsWebhooksConfigOption::class,
'Webhooks > Orphan visits' => Config\Option\Visit\OrphanVisitsWebhooksConfigOption::class,
'GeoLite2 license key' => Config\Option\UrlShortener\GeoLiteLicenseKeyConfigOption::class,
Expand Down Expand Up @@ -128,6 +129,7 @@
Config\Option\UrlShortener\AutoResolveTitlesConfigOption::class => InvokableFactory::class,
Config\Option\UrlShortener\AppendExtraPathConfigOption::class => InvokableFactory::class,
Config\Option\UrlShortener\EnableMultiSegmentSlugsConfigOption::class => InvokableFactory::class,
Config\Option\UrlShortener\EnableTrailingSlashConfigOption::class => InvokableFactory::class,
Config\Option\Redis\RedisServersConfigOption::class => InvokableFactory::class,
Config\Option\Redis\RedisSentinelServiceConfigOption::class => InvokableFactory::class,
Config\Option\Redis\RedisPubSubConfigOption::class => InvokableFactory::class,
Expand Down Expand Up @@ -230,30 +232,42 @@
'initMessage' => 'Initializing database...',
'errorMessage' => 'Error generating database.',
'failOnError' => true,
'printOutput' => false,
],
InstallationCommand::DB_MIGRATE->value => [
'command' => 'vendor/doctrine/migrations/bin/doctrine-migrations.php migrations:migrate',
'initMessage' => 'Updating database...',
'errorMessage' => 'Error updating database.',
'failOnError' => true,
'printOutput' => false,
],
InstallationCommand::ORM_PROXIES->value => [
'command' => 'vendor/doctrine/orm/bin/doctrine.php orm:generate-proxies',
'initMessage' => 'Generating proxies...',
'errorMessage' => 'Error generating proxies.',
'failOnError' => true,
'printOutput' => false,
],
InstallationCommand::ORM_CLEAR_CACHE->value => [
'command' => 'vendor/doctrine/orm/bin/doctrine.php orm:clear-cache:metadata',
'initMessage' => 'Clearing entities cache...',
'errorMessage' => 'Error clearing entities cache.',
'failOnError' => false,
'printOutput' => false,
],
InstallationCommand::GEOLITE_DOWNLOAD_DB->value => [
'command' => null, // Disabled by default, to avoid dependency on consumer (Shlink)
'initMessage' => 'Downloading GeoLite2 db file...',
'errorMessage' => 'Error downloading GeoLite2 db.',
'failOnError' => false,
'printOutput' => false,
],
InstallationCommand::API_KEY_GENERATE->value => [
'command' => null, // Disabled by default, to avoid dependency on consumer (Shlink)
'initMessage' => 'Generating first API key...',
'errorMessage' => 'Error generating first API key.',
'failOnError' => false,
'printOutput' => true,
],
],
],
Expand Down
25 changes: 25 additions & 0 deletions src/Config/Option/UrlShortener/EnableTrailingSlashConfigOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Shlinkio\Shlink\Installer\Config\Option\UrlShortener;

use Shlinkio\Shlink\Installer\Config\Option\BaseConfigOption;
use Symfony\Component\Console\Style\StyleInterface;

class EnableTrailingSlashConfigOption extends BaseConfigOption
{
public function getEnvVar(): string
{
return 'SHORT_URL_TRAILING_SLASH';
}

public function ask(StyleInterface $io, array $currentOptions): bool
{
return $io->confirm(
'Do you want to support trailing slashes in short URLs? (https://doma.in/foo and https://doma.in/foo/ '
. 'will be considered the same)',
false,
);
}
}
14 changes: 9 additions & 5 deletions src/Service/InstallationCommandsRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function execPhpCommand(string $name, SymfonyStyle $io): bool
'initMessage' => $initMessage,
'errorMessage' => $errorMessage,
'failOnError' => $failOnError,
'printOutput' => $printOutput,
] = $commandConfig;
$io->write($initMessage);

Expand All @@ -54,15 +55,18 @@ public function execPhpCommand(string $name, SymfonyStyle $io): bool
);

$process = $this->processHelper->run($io, $command);
if (! $failOnError || $process->isSuccessful()) {
$isSuccessful = ! $failOnError || $process->isSuccessful();

if ($isSuccessful) {
$io->writeln(' <info>Success!</info>');
return true;
} elseif (! $io->isVerbose()) {
$io->error(sprintf('%s. Run this command with -vvv to see specific error info.', $errorMessage));
}

if (! $io->isVerbose()) {
$io->error(sprintf('%s. Run this command with -vvv to see specific error info.', $errorMessage));
if ($printOutput) {
$io->text($process->getOutput());
}

return false;
return $isSuccessful;
}
}
2 changes: 2 additions & 0 deletions src/Util/InstallationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ enum InstallationCommand: string
case ORM_PROXIES = 'orm_proxies';
case ORM_CLEAR_CACHE = 'orm_clear_cache';
case GEOLITE_DOWNLOAD_DB = 'geolite_download_db';
case API_KEY_GENERATE = 'api_key_generate';

public const POST_INSTALL_COMMANDS = [
self::DB_CREATE_SCHEMA,
self::DB_MIGRATE,
self::ORM_PROXIES,
self::GEOLITE_DOWNLOAD_DB,
self::API_KEY_GENERATE,
];
public const POST_UPDATE_COMMANDS = [
self::DB_MIGRATE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,16 @@ public function returnsExpectedEnvVar(): void
/** @test */
public function expectedQuestionIsAsked(): void
{
$expectedAnswer = true;
$io = $this->prophesize(StyleInterface::class);
$confirm = $io->confirm(
'Do you want Shlink to resolve the short URL title based on the long URL\'s title tag (if any)? '
. 'Otherwise, it will be kept empty unless explicitly provided.',
false,
)->willReturn(
$expectedAnswer,
);
)->willReturn(true);

$answer = $this->configOption->ask($io->reveal(), []);

self::assertEquals($expectedAnswer, $answer);
self::assertTrue($answer);
$confirm->shouldHaveBeenCalledOnce();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace ShlinkioTest\Shlink\Installer\Config\Option\UrlShortener;

use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Shlinkio\Shlink\Installer\Config\Option\UrlShortener\EnableTrailingSlashConfigOption;
use Symfony\Component\Console\Style\StyleInterface;

class EnableTrailingSlashConfigOptionTest extends TestCase
{
use ProphecyTrait;

private EnableTrailingSlashConfigOption $configOption;

public function setUp(): void
{
$this->configOption = new EnableTrailingSlashConfigOption();
}

/** @test */
public function returnsExpectedEnvVar(): void
{
self::assertEquals('SHORT_URL_TRAILING_SLASH', $this->configOption->getEnvVar());
}

/** @test */
public function expectedQuestionIsAsked(): void
{
$io = $this->prophesize(StyleInterface::class);
$confirm = $io->confirm(
'Do you want to support trailing slashes in short URLs? (https://doma.in/foo and https://doma.in/foo/ '
. 'will be considered the same)',
false,
)->willReturn(true);

$answer = $this->configOption->ask($io->reveal(), []);

self::assertTrue($answer);
$confirm->shouldHaveBeenCalledOnce();
}
}
1 change: 1 addition & 0 deletions test/Service/InstallationCommandsRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private function buildCommands(array $names): array
'initMessage' => sprintf('%s_init', $name),
'errorMessage' => sprintf('%s_error', $name),
'failOnError' => $name === 'foo',
'printOutput' => false,
]));
}

Expand Down

0 comments on commit c3b0d1e

Please sign in to comment.