diff --git a/CHANGELOG.md b/CHANGELOG.md index 4336c93d..24bd6df0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,12 +7,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this ## [Unreleased] ### Added * [#869](https://github.com/shlinkio/shlink/issues/869) Added support for Mercure Hub 0.10. +* [#833](https://github.com/shlinkio/shlink/issues/833) Added support to connect through unix socket when using an external MySQL, MariaDB or Postgres database. + + It can be provided during the installation, or as the `DB_UNIX_SOCKET` env var for the docker image. ### Changed * [#912](https://github.com/shlinkio/shlink/issues/912) Changed error templates to be plain html files, removing the dependency on `league/plates` package. ### Deprecated * [#917](https://github.com/shlinkio/shlink/issues/917) Deprecated `/{shortCode}/qr-code/{size}` URL, in favor of providing the size in the query instead, `/{shortCode}/qr-code?size={size}`. +* [#924](https://github.com/shlinkio/shlink/issues/924) Deprecated mechanism to provide config options to the docker image through volumes. Use the env vars instead as a direct replacement. ### Removed * *Nothing* diff --git a/composer.json b/composer.json index caf5e5dd..d8479f51 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "laminas/laminas-paginator": "^2.8", "laminas/laminas-servicemanager": "^3.4", "laminas/laminas-stdlib": "^3.2", - "lcobucci/jwt": "^4.0@beta", + "lcobucci/jwt": "^4.0", "league/uri": "^6.2", "lstrojny/functional-php": "^1.9", "mezzio/mezzio": "^3.2", @@ -52,7 +52,7 @@ "shlinkio/shlink-config": "^1.0", "shlinkio/shlink-event-dispatcher": "^1.4", "shlinkio/shlink-importer": "^2.0.1", - "shlinkio/shlink-installer": "^5.1.0", + "shlinkio/shlink-installer": "^5.2.0", "shlinkio/shlink-ip-geolocation": "^1.5", "symfony/console": "^5.1", "symfony/filesystem": "^5.1", diff --git a/config/autoload/installer.global.php b/config/autoload/installer.global.php index ba0b8332..a04d874b 100644 --- a/config/autoload/installer.global.php +++ b/config/autoload/installer.global.php @@ -14,6 +14,7 @@ return [ Option\Database\DatabasePortConfigOption::class, Option\Database\DatabaseUserConfigOption::class, Option\Database\DatabasePasswordConfigOption::class, + Option\Database\DatabaseUnixSocketConfigOption::class, Option\Database\DatabaseSqlitePathConfigOption::class, Option\Database\DatabaseMySqlOptionsConfigOption::class, Option\UrlShortener\ShortDomainHostConfigOption::class, diff --git a/docker/README.md b/docker/README.md index 2cc0b5b9..c7627d7f 100644 --- a/docker/README.md +++ b/docker/README.md @@ -157,6 +157,7 @@ This is the complete list of supported env vars: * **mysql** or **maria** -> `3306` * **postgres** -> `5432` * **mssql** -> `1433` +* `DB_UNIX_SOCKET`: Alternatively to the `DB_HOST`, you can provide this to connect through unix sockets when using `mysql`, `maria` or `postgres` drivers. * `DISABLE_TRACK_PARAM`: The name of a query param that can be used to visit short URLs avoiding the visit to be tracked. This feature won't be available if not value is provided. * `DELETE_SHORT_URL_THRESHOLD`: The amount of visits on short URLs which will not allow them to be deleted. Defaults to `15`. * `VALIDATE_URLS`: Boolean which tells if shlink should validate a status 20x is returned (after following redirects) when trying to shorten a URL. Defaults to `false`. @@ -215,7 +216,11 @@ docker run \ shlinkio/shlink:stable ``` -## Provide config via volumes +## [DEPRECATED] Provide config via volumes + +> As of v2.5.0, providing config through volumes is deprecated, and no new options will be added anymore. Use env vars instead. +> +> Support for config options through volumes will be removed in Shlink v3.0.0 Rather than providing custom configuration via env vars, it is also possible ot provide config files in json format. diff --git a/docker/config/shlink_in_docker.local.php b/docker/config/shlink_in_docker.local.php index c4502b7c..c6d7f69e 100644 --- a/docker/config/shlink_in_docker.local.php +++ b/docker/config/shlink_in_docker.local.php @@ -34,6 +34,7 @@ $helper = new class { public function getDbConfig(): array { $driver = env('DB_DRIVER'); + $isMysql = contains(['maria', 'mysql'], $driver); if ($driver === null || $driver === 'sqlite') { return [ 'driver' => 'pdo_sqlite', @@ -41,7 +42,7 @@ $helper = new class { ]; } - $driverOptions = ! contains(['maria', 'mysql'], $driver) ? [] : [ + $driverOptions = ! $isMysql ? [] : [ // 1002 -> PDO::MYSQL_ATTR_INIT_COMMAND 1002 => 'SET NAMES utf8', // 1000 -> PDO::MYSQL_ATTR_USE_BUFFERED_QUERY @@ -52,9 +53,10 @@ $helper = new class { 'dbname' => env('DB_NAME', 'shlink'), 'user' => env('DB_USER'), 'password' => env('DB_PASSWORD'), - 'host' => env('DB_HOST'), + 'host' => env('DB_HOST', $driver === 'postgres' ? env('DB_UNIX_SOCKET') : null), 'port' => env('DB_PORT', self::DB_PORTS_MAP[$driver]), 'driverOptions' => $driverOptions, + 'unix_socket' => $isMysql ? env('DB_UNIX_SOCKET') : null, ]; } diff --git a/module/Core/src/Config/SimplifiedConfigParser.php b/module/Core/src/Config/SimplifiedConfigParser.php index aebeb2c3..b578799b 100644 --- a/module/Core/src/Config/SimplifiedConfigParser.php +++ b/module/Core/src/Config/SimplifiedConfigParser.php @@ -15,6 +15,7 @@ use function Functional\contains; use function Functional\reduce_left; use function uksort; +/** @deprecated */ class SimplifiedConfigParser { private const SIMPLIFIED_CONFIG_MAPPING = [ diff --git a/module/Core/src/Paginator/Adapter/ShortUrlRepositoryAdapter.php b/module/Core/src/Paginator/Adapter/ShortUrlRepositoryAdapter.php index f395412c..59d48a82 100644 --- a/module/Core/src/Paginator/Adapter/ShortUrlRepositoryAdapter.php +++ b/module/Core/src/Paginator/Adapter/ShortUrlRepositoryAdapter.php @@ -19,12 +19,6 @@ class ShortUrlRepositoryAdapter implements AdapterInterface $this->params = $params; } - /** - * Returns a collection of items for a page. - * - * @param int $offset Page offset - * @param int $itemCountPerPage Number of items per page - */ public function getItems($offset, $itemCountPerPage): array // phpcs:ignore { return $this->repository->findList( @@ -37,15 +31,6 @@ class ShortUrlRepositoryAdapter implements AdapterInterface ); } - /** - * Count elements of an object - * @link http://php.net/manual/en/countable.count.php - * @return int The custom count as an integer. - *

- *

- * The return value is cast to an integer. - * @since 5.1.0 - */ public function count(): int { return $this->repository->countList( diff --git a/module/Core/src/Repository/ShortUrlRepository.php b/module/Core/src/Repository/ShortUrlRepository.php index 27dac54b..95e50f40 100644 --- a/module/Core/src/Repository/ShortUrlRepository.php +++ b/module/Core/src/Repository/ShortUrlRepository.php @@ -33,15 +33,9 @@ class ShortUrlRepository extends EntityRepository implements ShortUrlRepositoryI ?DateRange $dateRange = null ): array { $qb = $this->createListQueryBuilder($searchTerm, $tags, $dateRange); - $qb->select('DISTINCT s'); - - // Set limit and offset - if ($limit !== null) { - $qb->setMaxResults($limit); - } - if ($offset !== null) { - $qb->setFirstResult($offset); - } + $qb->select('DISTINCT s') + ->setMaxResults($limit) + ->setFirstResult($offset); // In case the ordering has been specified, the query could be more complex. Process it if ($orderBy !== null && $orderBy->hasOrderField()) { @@ -147,7 +141,7 @@ class ShortUrlRepository extends EntityRepository implements ShortUrlRepositoryI WHERE s.shortCode = :shortCode AND (s.domain IS NULL OR d.authority = :domain) ORDER BY s.domain {$ordering} -DQL; + DQL; $query = $this->getEntityManager()->createQuery($dql); $query->setMaxResults(1) @@ -220,9 +214,8 @@ DQL; } if ($meta->hasValidUntil()) { $qb->andWhere($qb->expr()->eq('s.validUntil', ':validUntil')) - ->setParameter('validUntil', $meta->getValidUntil()); + ->setParameter('validUntil', $meta->getValidUntil()); } - if ($meta->hasDomain()) { $qb->join('s.domain', 'd') ->andWhere($qb->expr()->eq('d.authority', ':domain'))