Skip to content

Commit

Permalink
Merge pull request #168 from shlinkio/develop
Browse files Browse the repository at this point in the history
Release 8.0.0
  • Loading branch information
acelaya authored Aug 4, 2022
2 parents 92f8093 + 116ab5d commit 9cb7de5
Show file tree
Hide file tree
Showing 133 changed files with 592 additions and 893 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ on:
jobs:
ci:
uses: shlinkio/github-actions/.github/workflows/php-lib-ci.yml@main
with:
with-php-eight: false
secrets:
INFECTION_BADGE_API_KEY: ${{ secrets.INFECTION_BADGE_API_KEY }}
32 changes: 18 additions & 14 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,29 @@ 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).

## [7.1.0] - 2022-04-23
## [8.0.0] - 2022-08-04
### Added
* [#157](https://github.com/shlinkio/shlink-installer/issues/157) Added support for the timezone config option.
* [#162](https://github.com/shlinkio/shlink-installer/issues/162) Added support for the redis pub/sub config option.
* [#166](https://github.com/shlinkio/shlink-installer/issues/166) Added support for the multi-segment slugs config option.

### Changed
* *Nothing*

### Deprecated
* *Nothing*

### Removed
* [#161](https://github.com/shlinkio/shlink-installer/issues/161) Dropped support for PHP 8.0
* [#151](https://github.com/shlinkio/shlink-installer/issues/151) Removed compatibility with config path approach. Only env vars are supported now.

### Fixed
* *Nothing*


## [7.1.0] - 2022-04-23
### Added
* [#157](https://github.com/shlinkio/shlink-installer/issues/157) Added support for the timezone config option.

### Changed
* *Nothing*

Expand All @@ -31,9 +47,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
### Changed
* *Nothing*

### Changed
* *Nothing*

### Deprecated
* *Nothing*

Expand All @@ -51,9 +64,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
### Changed
* *Nothing*

### Changed
* *Nothing*

### Deprecated
* *Nothing*

Expand All @@ -68,9 +78,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
### Added
* [#143](https://github.com/shlinkio/shlink-installer/issues/143) Reworked how config options are "persisted", switching from regular config to an env var map.

### Changed
* *Nothing*

### Changed
* Dropped support for Symfony 5.
* Updated to infection 0.26, enabling HTML reports.
Expand All @@ -94,9 +101,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
* Added support for openswoole.
* Added "round block size" config option for QR codes.

### Changed
* *Nothing*

### Changed
* Updated to phpstan 1.0

Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,19 @@ It is possible to overwrite those commands via configuration too, using a syntax

declare(strict_types=1);

use Shlinkio\Shlink\Installer\Util\InstallationCommand;

return [

'installer' => [
'installation_commands' => [
'db_create_schema' => [
InstallationCommand::DB_CREATE_SCHEMA->value => [
'command' => 'bin/shlink shlink:db:create',
],
'db_migrate' => [
InstallationCommand::DB_MIGRATE->value => [
'command' => 'bin/some-script some:command',
],
'orm_proxies' => [
InstallationCommand::ORM_PROXIES->value => [
'command' => '-v', // Just print PHP version
],
],
Expand Down
22 changes: 11 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@
}
],
"require": {
"php": "^8.0",
"php": "^8.1",
"laminas/laminas-config": "^3.7",
"laminas/laminas-config-aggregator": "^1.7",
"laminas/laminas-servicemanager": "^3.11.2",
"laminas/laminas-stdlib": "^3.7",
"laminas/laminas-config-aggregator": "^1.8",
"laminas/laminas-servicemanager": "^3.16",
"laminas/laminas-stdlib": "^3.11",
"lstrojny/functional-php": "^1.17",
"shlinkio/shlink-config": "^1.6",
"symfony/console": "^6.0",
"symfony/filesystem": "^6.0",
"symfony/process": "^6.0"
"symfony/console": "^6.1",
"symfony/filesystem": "^6.1",
"symfony/process": "^6.1"
},
"require-dev": {
"devster/ubench": "^2.0",
"infection/infection": "^0.26",
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/phpstan": "^1.5",
"phpstan/phpstan": "^1.8",
"phpunit/phpunit": "^9.5",
"roave/security-advisories": "dev-master",
"shlinkio/php-coding-standard": "~2.2.0",
"symfony/var-dumper": "^6.0"
"shlinkio/php-coding-standard": "~2.3.0",
"symfony/var-dumper": "^6.1"
},
"autoload": {
"psr-4": {
Expand All @@ -56,7 +56,7 @@
"test": "phpdbg -qrr vendor/bin/phpunit --order-by=random --testdox --colors=always",
"test:ci": "@test --coverage-clover=build/clover.xml --coverage-xml=build/coverage-xml --log-junit=build/junit.xml",
"test:pretty": "@test --coverage-html build/coverage-html",
"infect": "infection --threads=4 --min-msi=90 --log-verbosity=default --only-covered --only-covering-test-cases",
"infect": "infection --threads=4 --min-msi=85 --log-verbosity=default --only-covered --only-covering-test-cases",
"infect:ci": "@infect --coverage=build --skip-initial-tests",
"infect:show": "@infect --show-mutations",
"infect:show:ci": "@infect --show-mutations --coverage=build",
Expand Down
8 changes: 4 additions & 4 deletions config/config.local.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ return [

'installer' => [
'installation_commands' => [
InstallationCommand::DB_CREATE_SCHEMA => [
InstallationCommand::DB_CREATE_SCHEMA->value => [
'command' => '-v', // Just print PHP version
],
InstallationCommand::DB_MIGRATE => [
InstallationCommand::DB_MIGRATE->value => [
'command' => null, // Skip
],
InstallationCommand::ORM_PROXIES => [
InstallationCommand::ORM_PROXIES->value => [
'command' => '-v', // Just print PHP version
],
InstallationCommand::ORM_CLEAR_CACHE => [
InstallationCommand::ORM_CLEAR_CACHE->value => [
'command' => '-v', // Just print PHP version
],
],
Expand Down
15 changes: 10 additions & 5 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
'URL shortener > Auto resolve titles'
=> Config\Option\UrlShortener\AutoResolveTitlesConfigOption::class,
'URL shortener > Append extra path' => Config\Option\UrlShortener\AppendExtraPathConfigOption::class,
'URL shortener > Multi-segment slugs'
=> Config\Option\UrlShortener\EnableMultiSegmentSlugsConfigOption::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 @@ -93,6 +95,7 @@
'INTEGRATIONS' => [
'Redis > servers' => Config\Option\Redis\RedisServersConfigOption::class,
'Redis > sentinels service' => Config\Option\Redis\RedisSentinelServiceConfigOption::class,
'Redis > Pub/sub enabled' => Config\Option\Redis\RedisPubSubConfigOption::class,
Config\Option\Mercure\EnableMercureConfigOption::class,
'Mercure > Public URL' => Config\Option\Mercure\MercurePublicUrlConfigOption::class,
'Mercure > Internal URL' => Config\Option\Mercure\MercureInternalUrlConfigOption::class,
Expand Down Expand Up @@ -124,8 +127,10 @@
Config\Option\UrlShortener\ShortDomainSchemaConfigOption::class => InvokableFactory::class,
Config\Option\UrlShortener\AutoResolveTitlesConfigOption::class => InvokableFactory::class,
Config\Option\UrlShortener\AppendExtraPathConfigOption::class => InvokableFactory::class,
Config\Option\UrlShortener\EnableMultiSegmentSlugsConfigOption::class => InvokableFactory::class,
Config\Option\Redis\RedisServersConfigOption::class => InvokableFactory::class,
Config\Option\Redis\RedisSentinelServiceConfigOption::class => InvokableFactory::class,
Config\Option\Redis\RedisPubSubConfigOption::class => InvokableFactory::class,
Config\Option\Visit\VisitsWebhooksConfigOption::class => ConfigAbstractFactory::class,
Config\Option\Visit\OrphanVisitsWebhooksConfigOption::class => ConfigAbstractFactory::class,
Config\Option\Worker\TaskWorkerNumConfigOption::class => ConfigAbstractFactory::class,
Expand Down Expand Up @@ -220,31 +225,31 @@
'enabled_options' => null,

'installation_commands' => [
InstallationCommand::DB_CREATE_SCHEMA => [
InstallationCommand::DB_CREATE_SCHEMA->value => [
'command' => 'vendor/doctrine/orm/bin/doctrine.php orm:schema-tool:create',
'initMessage' => 'Initializing database...',
'errorMessage' => 'Error generating database.',
'failOnError' => true,
],
InstallationCommand::DB_MIGRATE => [
InstallationCommand::DB_MIGRATE->value => [
'command' => 'vendor/doctrine/migrations/bin/doctrine-migrations.php migrations:migrate',
'initMessage' => 'Updating database...',
'errorMessage' => 'Error updating database.',
'failOnError' => true,
],
InstallationCommand::ORM_PROXIES => [
InstallationCommand::ORM_PROXIES->value => [
'command' => 'vendor/doctrine/orm/bin/doctrine.php orm:generate-proxies',
'initMessage' => 'Generating proxies...',
'errorMessage' => 'Error generating proxies.',
'failOnError' => true,
],
InstallationCommand::ORM_CLEAR_CACHE => [
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,
],
InstallationCommand::GEOLITE_DOWNLOAD_DB => [
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.',
Expand Down
4 changes: 0 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>

<exclude>
<file>./src/Util/PathCollection.php</file>
</exclude>
</whitelist>
</filter>
</phpunit>
13 changes: 8 additions & 5 deletions src/Command/AbstractInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$importedConfig = $this->resolvePreviousConfig($io);
if ($this->isUpdate()) {
$this->assetsHandler->importShlinkAssetsFromPath($io, $importedConfig->importPath());
$this->assetsHandler->importShlinkAssetsFromPath($io, $importedConfig->importPath);
}
$config = $this->configGenerator->generateConfigInteractively($io, $importedConfig->importedConfig());
$configArray = Utils::normalizeAndKeepEnvVarKeys($config->toArray());
$config = $this->configGenerator->generateConfigInteractively($io, $importedConfig->importedConfig);
$normalizedConfig = Utils::normalizeAndKeepEnvVarKeys($config);

// Generate config params files
$this->configWriter->toFile(ShlinkAssetsHandler::GENERATED_CONFIG_PATH, $configArray, false);
$this->configWriter->toFile(ShlinkAssetsHandler::GENERATED_CONFIG_PATH, $normalizedConfig, false);
$io->text('<info>Custom configuration properly generated!</info>');
$io->newLine();

Expand All @@ -77,7 +77,10 @@ private function execPostInstallCommands(SymfonyStyle $io): bool
? InstallationCommand::POST_UPDATE_COMMANDS
: InstallationCommand::POST_INSTALL_COMMANDS;

return every($commands, fn (string $commandName) => $this->commandsRunner->execPhpCommand($commandName, $io));
return every(
$commands,
fn (InstallationCommand $command) => $this->commandsRunner->execPhpCommand($command->value, $io),
);
}

abstract protected function isUpdate(): bool;
Expand Down
7 changes: 3 additions & 4 deletions src/Command/SetOptionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Generator;
use Laminas\Config\Writer\WriterInterface;
use Shlinkio\Shlink\Config\Collection\PathCollection;
use Shlinkio\Shlink\Installer\Config\ConfigOptionsManagerInterface;
use Shlinkio\Shlink\Installer\Config\Option\ConfigOptionInterface;
use Shlinkio\Shlink\Installer\Exception\InvalidShlinkPathException;
Expand Down Expand Up @@ -81,9 +80,9 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int

/** @var ConfigOptionInterface $plugin */
$plugin = $this->optionsManager->get($this->groups[$optionTitle]);
$answers = new PathCollection(include $this->generatedConfigPath);
$answers->setValueInPath($plugin->ask($io, $answers), [$plugin->getEnvVar()]);
$this->configWriter->toFile($this->generatedConfigPath, $answers->toArray(), false);
$answers = include $this->generatedConfigPath;
$answers[$plugin->getEnvVar()] = $plugin->ask($io, $answers);
$this->configWriter->toFile($this->generatedConfigPath, $answers, false);
$this->assetsHandler->dropCachedConfigIfAny($io);

$io->success('Configuration properly updated');
Expand Down
13 changes: 6 additions & 7 deletions src/Config/ConfigGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Shlinkio\Shlink\Installer\Config;

use Shlinkio\Shlink\Config\Collection\PathCollection;
use Shlinkio\Shlink\Installer\Config\Option\ConfigOptionInterface;
use Shlinkio\Shlink\Installer\Config\Option\DependentConfigOptionInterface;
use Symfony\Component\Console\Style\StyleInterface;
Expand All @@ -20,16 +19,16 @@
class ConfigGenerator implements ConfigGeneratorInterface
{
public function __construct(
private ConfigOptionsManagerInterface $configOptionsManager,
private array $configOptionsGroups,
private ?array $enabledOptions,
private readonly ConfigOptionsManagerInterface $configOptionsManager,
private readonly array $configOptionsGroups,
private readonly ?array $enabledOptions,
) {
}

public function generateConfigInteractively(StyleInterface $io, array $previousConfig): PathCollection
public function generateConfigInteractively(StyleInterface $io, array $previousConfig): array
{
$pluginsGroups = $this->resolveAndSortOptions();
$answers = new PathCollection($previousConfig);
$answers = $previousConfig;
$alreadyRenderedTitles = [];

// FIXME Improve code quality on these nested loops
Expand All @@ -47,7 +46,7 @@ public function generateConfigInteractively(StyleInterface $io, array $previousC
$io->title($title);
}

$answers->setValueInPath($plugin->ask($io, $answers), [$plugin->getEnvVar()]);
$answers[$plugin->getEnvVar()] = $plugin->ask($io, $answers);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/Config/ConfigGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

namespace Shlinkio\Shlink\Installer\Config;

use Shlinkio\Shlink\Config\Collection\PathCollection;
use Symfony\Component\Console\Style\StyleInterface;

interface ConfigGeneratorInterface
{
public function generateConfigInteractively(StyleInterface $io, array $previousConfig): PathCollection;
public function generateConfigInteractively(StyleInterface $io, array $previousConfig): array;
}
3 changes: 1 addition & 2 deletions src/Config/Option/AbstractSwooleDependentConfigOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Shlinkio\Shlink\Installer\Config\Option;

use Closure;
use Shlinkio\Shlink\Config\Collection\PathCollection;

abstract class AbstractSwooleDependentConfigOption extends BaseConfigOption
{
Expand All @@ -16,7 +15,7 @@ public function __construct(callable $swooleInstalled)
$this->swooleInstalled = Closure::fromCallable($swooleInstalled);
}

public function shouldBeAsked(PathCollection $currentOptions): bool
public function shouldBeAsked(array $currentOptions): bool
{
return ($this->swooleInstalled)() && parent::shouldBeAsked($currentOptions);
}
Expand Down
17 changes: 4 additions & 13 deletions src/Config/Option/BaseConfigOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,12 @@

namespace Shlinkio\Shlink\Installer\Config\Option;

use Shlinkio\Shlink\Config\Collection\PathCollection;
use function array_key_exists;

abstract class BaseConfigOption implements ConfigOptionInterface, WithDeprecatedConfigOption
abstract class BaseConfigOption implements ConfigOptionInterface
{
public function shouldBeAsked(PathCollection $currentOptions): bool
public function shouldBeAsked(array $currentOptions): bool
{
$envVarPath = [$this->getEnvVar()];

// If the config contains the deprecated path, set its value in the new path, and unset the deprecated one
$deprecatedPath = $this->getDeprecatedPath();
if ($currentOptions->pathExists($deprecatedPath)) {
$currentOptions->setValueInPath($currentOptions->getValueInPath($deprecatedPath), $envVarPath);
$currentOptions->unsetPath($deprecatedPath);
}

return ! $currentOptions->pathExists($envVarPath);
return ! array_key_exists($this->getEnvVar(), $currentOptions);
}
}
Loading

0 comments on commit 9cb7de5

Please sign in to comment.