From 92b6aa49fb6c322cc21c03f5820bd30dda5fb71a Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sun, 16 Feb 2025 23:11:04 +0100 Subject: [PATCH 01/18] Use a dedicated database_url parameter for tests --- app/config/parameters_test.yml | 1 + app/config/tests/parameters_test.mysql.yml | 1 + app/config/tests/parameters_test.pgsql.yml | 1 + app/config/tests/parameters_test.sqlite.yml | 1 + tests/Command/InstallCommandTest.php | 2 +- 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/config/parameters_test.yml b/app/config/parameters_test.yml index e9a3b6c80..0b2068d30 100644 --- a/app/config/parameters_test.yml +++ b/app/config/parameters_test.yml @@ -1,2 +1,3 @@ parameters: database_path: "%kernel.project_dir%/data/db/wallabag%wallabag_dbname_suffix%.sqlite" + database_url: '%env(resolve:DATABASE_URL)%' diff --git a/app/config/tests/parameters_test.mysql.yml b/app/config/tests/parameters_test.mysql.yml index 6e1a87b79..d52c9a6e9 100644 --- a/app/config/tests/parameters_test.mysql.yml +++ b/app/config/tests/parameters_test.mysql.yml @@ -1,2 +1,3 @@ parameters: env(DATABASE_URL): mysql://root:root@127.0.0.1:3306/wallabag?charset=utf8mb4 + database_url: '%env(resolve:DATABASE_URL)%' diff --git a/app/config/tests/parameters_test.pgsql.yml b/app/config/tests/parameters_test.pgsql.yml index 8a3d0498e..73df12da0 100644 --- a/app/config/tests/parameters_test.pgsql.yml +++ b/app/config/tests/parameters_test.pgsql.yml @@ -1,2 +1,3 @@ parameters: env(DATABASE_URL): postgres://wallabag:wallabagrocks@localhost/wallabag?charset=utf8 + database_url: '%env(resolve:DATABASE_URL)%' diff --git a/app/config/tests/parameters_test.sqlite.yml b/app/config/tests/parameters_test.sqlite.yml index 3082dffed..e34c642e4 100644 --- a/app/config/tests/parameters_test.sqlite.yml +++ b/app/config/tests/parameters_test.sqlite.yml @@ -1,2 +1,3 @@ parameters: env(DATABASE_URL): sqlite:///%kernel.project_dir%/data/db/wallabag%wallabag_dbname_suffix%.sqlite?charset=utf8 + database_url: '%env(resolve:DATABASE_URL)%' diff --git a/tests/Command/InstallCommandTest.php b/tests/Command/InstallCommandTest.php index 9e89e30c1..42e153b52 100644 --- a/tests/Command/InstallCommandTest.php +++ b/tests/Command/InstallCommandTest.php @@ -38,7 +38,7 @@ class InstallCommandTest extends WallabagTestCase /** @var Connection $connection */ $connection = $this->getTestClient()->getContainer()->get(ManagerRegistry::class)->getConnection(); - $originalDatabaseUrl = $this->getTestClient()->getContainer()->getParameter('env(DATABASE_URL)'); + $originalDatabaseUrl = $this->getTestClient()->getContainer()->getParameter('database_url'); $dbnameSuffix = $this->getTestClient()->getContainer()->getParameter('wallabag_dbname_suffix'); $tmpDatabaseName = 'wallabag_' . bin2hex(random_bytes(5)); From 10618103b6651e6390573c883ac15b29a7399009 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Wed, 15 Jan 2025 23:09:02 +0100 Subject: [PATCH 02/18] Reset DATABASE_URL to original one in InstallCommandTest --- tests/Command/InstallCommandTest.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/Command/InstallCommandTest.php b/tests/Command/InstallCommandTest.php index 42e153b52..18f7aaccd 100644 --- a/tests/Command/InstallCommandTest.php +++ b/tests/Command/InstallCommandTest.php @@ -19,6 +19,8 @@ use Wallabag\Command\InstallCommand; class InstallCommandTest extends WallabagTestCase { + private string $originalDatabaseUrl; + public static function setUpBeforeClass(): void { // disable doctrine-test-bundle @@ -38,14 +40,14 @@ class InstallCommandTest extends WallabagTestCase /** @var Connection $connection */ $connection = $this->getTestClient()->getContainer()->get(ManagerRegistry::class)->getConnection(); - $originalDatabaseUrl = $this->getTestClient()->getContainer()->getParameter('database_url'); + $this->originalDatabaseUrl = $this->getTestClient()->getContainer()->getParameter('database_url'); $dbnameSuffix = $this->getTestClient()->getContainer()->getParameter('wallabag_dbname_suffix'); $tmpDatabaseName = 'wallabag_' . bin2hex(random_bytes(5)); if ($connection->getDatabasePlatform() instanceof SqlitePlatform) { - $tmpDatabaseUrl = str_replace('wallabag' . $dbnameSuffix . '.sqlite', $tmpDatabaseName . $dbnameSuffix . '.sqlite', $originalDatabaseUrl); + $tmpDatabaseUrl = str_replace('wallabag' . $dbnameSuffix . '.sqlite', $tmpDatabaseName . $dbnameSuffix . '.sqlite', $this->originalDatabaseUrl); } else { - $tmpDatabaseUrl = (string) (new Uri($originalDatabaseUrl))->withPath($tmpDatabaseName); + $tmpDatabaseUrl = (string) (new Uri($this->originalDatabaseUrl))->withPath($tmpDatabaseName); } putenv("DATABASE_URL=$tmpDatabaseUrl"); @@ -67,9 +69,8 @@ class InstallCommandTest extends WallabagTestCase /** @var Connection $connection */ $connection = $this->getTestClient()->getContainer()->get(ManagerRegistry::class)->getConnection(); - if ($connection->getDatabasePlatform() instanceof SqlitePlatform) { - // Remove the real environnement variable - putenv('DATABASE_URL'); + if ($connection->getDatabasePlatform() instanceof SqlitePlatform) {// Remove the real environnement variable + putenv('DATABASE_URL=' . $this->originalDatabaseUrl); $databasePath = parse_url($databaseUrl, \PHP_URL_PATH); @@ -80,8 +81,7 @@ class InstallCommandTest extends WallabagTestCase $testDatabaseName = $connection->getDatabase(); $connection->close(); - // Remove the real environnement variable - putenv('DATABASE_URL'); + putenv('DATABASE_URL=' . $this->originalDatabaseUrl); // Create a new client to avoid the error: // Transaction commit failed because the transaction has been marked for rollback only. From 982e25ceb6dab842c4dd2070428177c3c7014c29 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sat, 11 Jan 2025 04:56:01 +0100 Subject: [PATCH 03/18] Load parameters.yml from the kernel --- app/AppKernel.php | 4 ++++ app/config/config.yml | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/AppKernel.php b/app/AppKernel.php index 0e9d62e4b..699a7ee79 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -67,6 +67,10 @@ class AppKernel extends Kernel public function registerContainerConfiguration(LoaderInterface $loader) { + if (file_exists($this->getProjectDir() . '/app/config/parameters.yml')) { + $loader->load($this->getProjectDir() . '/app/config/parameters.yml'); + } + $loader->load($this->getProjectDir() . '/app/config/config_' . $this->getEnvironment() . '.yml'); $loader->load(function (ContainerBuilder $container) { diff --git a/app/config/config.yml b/app/config/config.yml index 77d792221..242db19b2 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -1,5 +1,4 @@ imports: - - { resource: parameters.yml } - { resource: security.yml } - { resource: services.yml } - { resource: wallabag.yml } From 016b04bac699cf73f09186806e13b7cb195621c7 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Wed, 15 Jan 2025 22:56:13 +0100 Subject: [PATCH 04/18] Process database parameters only when parameters.yml exists --- app/AppKernel.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/AppKernel.php b/app/AppKernel.php index 699a7ee79..e954ffa85 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -79,9 +79,11 @@ class AppKernel extends Kernel $container->addObjectResource($this); }); - $loader->load(function (ContainerBuilder $container) { - $this->processDatabaseParameters($container); - }); + if (file_exists($this->getProjectDir() . '/app/config/parameters.yml')) { + $loader->load(function (ContainerBuilder $container) { + $this->processDatabaseParameters($container); + }); + } } protected function build(ContainerBuilder $container) From bcafb8cbbc8a54e6876c6660807ac6b34bba1b70 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sat, 11 Jan 2025 01:11:34 +0100 Subject: [PATCH 05/18] Add backward compatibility layer from existing parameters --- app/AppKernel.php | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/app/AppKernel.php b/app/AppKernel.php index e954ffa85..a9fd84f1f 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -81,6 +81,7 @@ class AppKernel extends Kernel if (file_exists($this->getProjectDir() . '/app/config/parameters.yml')) { $loader->load(function (ContainerBuilder $container) { + $this->loadEnvVarsFromParameters($container); $this->processDatabaseParameters($container); }); } @@ -91,6 +92,53 @@ class AppKernel extends Kernel $container->addCompilerPass(new ImportCompilerPass()); } + private function loadEnvVarsFromParameters(ContainerBuilder $container) + { + $this->setEnvVarFromParameter($container, 'DATABASE_DRIVER', 'database_driver'); + $this->setEnvVarFromParameter($container, 'DATABASE_HOST', 'database_host'); + $this->setEnvVarFromParameter($container, 'DATABASE_PORT', 'database_port'); + $this->setEnvVarFromParameter($container, 'DATABASE_NAME', 'database_name'); + $this->setEnvVarFromParameter($container, 'DATABASE_USER', 'database_user'); + $this->setEnvVarFromParameter($container, 'DATABASE_PASSWORD', 'database_password'); + $this->setEnvVarFromParameter($container, 'DATABASE_PATH', 'database_path'); + $this->setEnvVarFromParameter($container, 'DATABASE_TABLE_PREFIX', 'database_table_prefix'); + $this->setEnvVarFromParameter($container, 'DATABASE_SOCKET', 'database_socket'); + $this->setEnvVarFromParameter($container, 'DATABASE_CHARSET', 'database_charset'); + + $this->setEnvVarFromParameter($container, 'DOMAIN_NAME', 'domain_name'); + $this->setEnvVarFromParameter($container, 'SERVER_NAME', 'server_name'); + $this->setEnvVarFromParameter($container, 'MAILER_DSN', 'mailer_dsn'); + $this->setEnvVarFromParameter($container, 'LOCALE', 'locale'); + $this->setEnvVarFromParameter($container, 'SECRET', 'secret'); + + $this->setEnvVarFromParameter($container, 'TWOFACTOR_SENDER', 'twofactor_sender'); + $this->setEnvVarFromParameter($container, 'FOSUSER_REGISTRATION', 'fosuser_registration'); + $this->setEnvVarFromParameter($container, 'FOSUSER_CONFIRMATION', 'fosuser_confirmation'); + $this->setEnvVarFromParameter($container, 'FOS_OAUTH_SERVER_ACCESS_TOKEN_LIFETIME', 'fos_oauth_server_access_token_lifetime'); + $this->setEnvVarFromParameter($container, 'FOS_OAUTH_SERVER_REFRESH_TOKEN_LIFETIME', 'fos_oauth_server_refresh_token_lifetime'); + $this->setEnvVarFromParameter($container, 'FROM_EMAIL', 'from_email'); + + $this->setEnvVarFromParameter($container, 'RABBITMQ_HOST', 'rabbitmq_host'); + $this->setEnvVarFromParameter($container, 'RABBITMQ_PORT', 'rabbitmq_port'); + $this->setEnvVarFromParameter($container, 'RABBITMQ_USER', 'rabbitmq_user'); + $this->setEnvVarFromParameter($container, 'RABBITMQ_PASSWORD', 'rabbitmq_password'); + $this->setEnvVarFromParameter($container, 'RABBITMQ_PREFETCH_COUNT', 'rabbitmq_prefetch_count'); + + $this->setEnvVarFromParameter($container, 'REDIS_SCHEME', 'redis_scheme'); + $this->setEnvVarFromParameter($container, 'REDIS_HOST', 'redis_host'); + $this->setEnvVarFromParameter($container, 'REDIS_PORT', 'redis_port'); + $this->setEnvVarFromParameter($container, 'REDIS_PATH', 'redis_path'); + $this->setEnvVarFromParameter($container, 'REDIS_PASSWORD', 'redis_password'); + + $this->setEnvVarFromParameter($container, 'SENTRY_DSN', 'sentry_dsn'); + } + + private function setEnvVarFromParameter(ContainerBuilder $container, string $envVar, string $parameter) + { + $_ENV[$envVar] = $_SERVER[$envVar] = (string) $container->getParameter($parameter); + $container->setParameter('env(' . $envVar . ')', (string) $container->getParameter($parameter)); + } + private function processDatabaseParameters(ContainerBuilder $container) { switch ($container->getParameter('database_driver')) { From e16a676989068a66c8482829b8483b0fb1c11f4c Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sat, 18 Jan 2025 13:39:31 +0100 Subject: [PATCH 06/18] Define DATABASE_URL env var in AppKernel --- app/AppKernel.php | 40 ++++++++++++++++++++++++++++++++-------- app/config/config.yml | 1 - 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/app/AppKernel.php b/app/AppKernel.php index a9fd84f1f..7770ffd50 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -82,7 +82,7 @@ class AppKernel extends Kernel if (file_exists($this->getProjectDir() . '/app/config/parameters.yml')) { $loader->load(function (ContainerBuilder $container) { $this->loadEnvVarsFromParameters($container); - $this->processDatabaseParameters($container); + $this->defineDatabaseUrlEnvVar($container); }); } } @@ -139,7 +139,7 @@ class AppKernel extends Kernel $container->setParameter('env(' . $envVar . ')', (string) $container->getParameter($parameter)); } - private function processDatabaseParameters(ContainerBuilder $container) + private function defineDatabaseUrlEnvVar(ContainerBuilder $container) { switch ($container->getParameter('database_driver')) { case 'pdo_mysql': @@ -155,15 +155,39 @@ class AppKernel extends Kernel throw new RuntimeException('Unsupported database driver: ' . $container->getParameter('database_driver')); } - $container->setParameter('database_scheme', $scheme); + $user = $container->getParameter('database_user'); + $password = $container->getParameter('database_password'); + $host = $container->getParameter('database_host'); + $port = $container->getParameter('database_port'); + $name = $container->getParameter('database_name'); if ('sqlite' === $scheme) { - $container->setParameter('database_name', $container->getParameter('database_path')); + $name = $container->getParameter('database_path'); } - $container->setParameter('database_user', (string) $container->getParameter('database_user')); - $container->setParameter('database_password', (string) $container->getParameter('database_password')); - $container->setParameter('database_port', (string) $container->getParameter('database_port')); - $container->setParameter('database_socket', (string) $container->getParameter('database_socket')); + $url = $scheme . '://' . $user . ':' . $password . '@' . $host; + + if ($port) { + $url .= ':' . $port; + } + + $url .= '/' . $name; + + $query = []; + + if ($container->getParameter('database_socket')) { + $query['unix_socket'] = $container->getParameter('database_socket'); + } + + if ($container->getParameter('database_charset')) { + $query['charset'] = $container->getParameter('database_charset'); + } + + if ([] !== $query) { + $url .= '?' . http_build_query($query); + } + + $_ENV['DATABASE_URL'] = $_SERVER['DATABASE_URL'] = $url; + $container->setParameter('env(DATABASE_URL)', $url); } } diff --git a/app/config/config.yml b/app/config/config.yml index 242db19b2..bd50ab95f 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -5,7 +5,6 @@ imports: parameters: craue_config.cache_adapter.class: Craue\ConfigBundle\CacheAdapter\SymfonyCacheComponentAdapter - env(DATABASE_URL): '%database_scheme%://%database_user%:%database_password%@%database_host%:%database_port%/%database_name%?unix_socket=%database_socket%&charset=%database_charset%' framework: #esi: ~ From 647312205161ac1a5751c2b5f8363422b89aea24 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sun, 16 Feb 2025 23:56:59 +0100 Subject: [PATCH 07/18] Use a dedicated domain_name parameter for tests --- app/config/config_test.yml | 1 + app/config/parameters_test.yml | 1 + app/config/tests/parameters_test.mysql.yml | 1 + app/config/tests/parameters_test.pgsql.yml | 1 + app/config/tests/parameters_test.sqlite.yml | 1 + 5 files changed, 5 insertions(+) diff --git a/app/config/config_test.yml b/app/config/config_test.yml index 3ad233351..20b92f01f 100644 --- a/app/config/config_test.yml +++ b/app/config/config_test.yml @@ -6,6 +6,7 @@ imports: parameters: fosuser_registration: true wallabag_dbname_suffix: '_test' + domain_name: '%env(DOMAIN_NAME)%' framework: test: ~ diff --git a/app/config/parameters_test.yml b/app/config/parameters_test.yml index 0b2068d30..9f9f812a2 100644 --- a/app/config/parameters_test.yml +++ b/app/config/parameters_test.yml @@ -1,3 +1,4 @@ parameters: database_path: "%kernel.project_dir%/data/db/wallabag%wallabag_dbname_suffix%.sqlite" database_url: '%env(resolve:DATABASE_URL)%' + domain_name: '%env(DOMAIN_NAME)%' diff --git a/app/config/tests/parameters_test.mysql.yml b/app/config/tests/parameters_test.mysql.yml index d52c9a6e9..3e825114d 100644 --- a/app/config/tests/parameters_test.mysql.yml +++ b/app/config/tests/parameters_test.mysql.yml @@ -1,3 +1,4 @@ parameters: env(DATABASE_URL): mysql://root:root@127.0.0.1:3306/wallabag?charset=utf8mb4 database_url: '%env(resolve:DATABASE_URL)%' + domain_name: '%env(DOMAIN_NAME)%' diff --git a/app/config/tests/parameters_test.pgsql.yml b/app/config/tests/parameters_test.pgsql.yml index 73df12da0..0bf594828 100644 --- a/app/config/tests/parameters_test.pgsql.yml +++ b/app/config/tests/parameters_test.pgsql.yml @@ -1,3 +1,4 @@ parameters: env(DATABASE_URL): postgres://wallabag:wallabagrocks@localhost/wallabag?charset=utf8 database_url: '%env(resolve:DATABASE_URL)%' + domain_name: '%env(DOMAIN_NAME)%' diff --git a/app/config/tests/parameters_test.sqlite.yml b/app/config/tests/parameters_test.sqlite.yml index e34c642e4..5b1b89787 100644 --- a/app/config/tests/parameters_test.sqlite.yml +++ b/app/config/tests/parameters_test.sqlite.yml @@ -1,3 +1,4 @@ parameters: env(DATABASE_URL): sqlite:///%kernel.project_dir%/data/db/wallabag%wallabag_dbname_suffix%.sqlite?charset=utf8 database_url: '%env(resolve:DATABASE_URL)%' + domain_name: '%env(DOMAIN_NAME)%' From 2db9ee2ba750d2c04d08d59178d0f34694599853 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sat, 11 Jan 2025 02:49:42 +0100 Subject: [PATCH 08/18] Install Symfony DotEnv --- composer.json | 1 + composer.lock | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3a4839a6f..c681991ee 100644 --- a/composer.json +++ b/composer.json @@ -122,6 +122,7 @@ "symfony/dependency-injection": "^5.4.35", "symfony/doctrine-bridge": "^5.4.35", "symfony/dom-crawler": "^5.4.35", + "symfony/dotenv": "^5.4.35", "symfony/error-handler": "^5.4.35", "symfony/event-dispatcher": "^5.4.35", "symfony/event-dispatcher-contracts": "^2.5.2", diff --git a/composer.lock b/composer.lock index b24a2372a..786c81fd3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a85056bec7fa90b9be4aa16c34464c0e", + "content-hash": "275616311733b2f623c48eda835def87", "packages": [ { "name": "babdev/pagerfanta-bundle", @@ -9569,6 +9569,77 @@ ], "time": "2024-10-22T13:05:35+00:00" }, + { + "name": "symfony/dotenv", + "version": "v5.4.48", + "source": { + "type": "git", + "url": "https://github.com/symfony/dotenv.git", + "reference": "08013403089c8a126c968179179b817a552841ab" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/dotenv/zipball/08013403089c8a126c968179179b817a552841ab", + "reference": "08013403089c8a126c968179179b817a552841ab", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/deprecation-contracts": "^2.1|^3" + }, + "require-dev": { + "symfony/console": "^4.4|^5.0|^6.0", + "symfony/process": "^4.4|^5.0|^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Dotenv\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Registers environment variables from a .env file", + "homepage": "https://symfony.com", + "keywords": [ + "dotenv", + "env", + "environment" + ], + "support": { + "source": "https://github.com/symfony/dotenv/tree/v5.4.48" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-11-27T09:33:00+00:00" + }, { "name": "symfony/error-handler", "version": "v5.4.46", From ad84d2b13b6c30cbf9b52f1075f11bc8efa32773 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Mon, 17 Feb 2025 00:16:18 +0100 Subject: [PATCH 09/18] Load .env file --- .env | 34 ++++++++++++++++++++++++++++++++++ bin/console | 39 +++++++++++++++++++++++++++------------ phpunit.xml.dist | 2 +- tests/bootstrap.php | 3 +++ web/app.php | 8 +++++++- web/app_dev.php | 9 ++++++++- 6 files changed, 80 insertions(+), 15 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 000000000..48b2b1cdd --- /dev/null +++ b/.env @@ -0,0 +1,34 @@ +SECRET="ch4n63m31fy0uc4n" +LOCALE=en + +SERVER_NAME="Your wallabag instance" +DOMAIN_NAME=http://127.0.0.1:8000 + +DATABASE_URL=sqlite:///%kernel.project_dir%/data/db/wallabag.sqlite?charset=utf8 +#DATABASE_URL=mysql://root:wallaroot@mariadb:3306/wallabag?charset=utf8mb4 +#DATABASE_URL=postgres://wallabag:wallapass@postgres:5432/wallabag?charset=utf8 +DATABASE_TABLE_PREFIX=wallabag_ + +FOSUSER_REGISTRATION=false +FOSUSER_CONFIRMATION=true + +FOS_OAUTH_SERVER_ACCESS_TOKEN_LIFETIME=3600 +FOS_OAUTH_SERVER_REFRESH_TOKEN_LIFETIME=1209600 +TWOFACTOR_SENDER=no-reply@wallabag.org + +MAILER_DSN=smtp://127.0.0.1 +FROM_EMAIL=wallabag@example.com + +RABBITMQ_HOST=rabbitmq +RABBITMQ_PORT=5672 +RABBITMQ_USER=guest +RABBITMQ_PASSWORD=guest + +REDIS_SCHEME=tcp +REDIS_HOST=redis +REDIS_PORT=6379 +REDIS_PATH= +REDIS_PASSWORD= +RABBITMQ_PREFETCH_COUNT=10 + +SENTRY_DSN= diff --git a/bin/console b/bin/console index c480603e1..4220603b1 100755 --- a/bin/console +++ b/bin/console @@ -3,25 +3,40 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Input\ArgvInput; +use Symfony\Component\Dotenv\Dotenv; use Symfony\Component\ErrorHandler\Debug; -// if you don't want to setup permissions the proper way, just uncomment the following PHP line -// read https://symfony.com/doc/current/setup.html#checking-symfony-application-configuration-and-setup -// for more information -//umask(0000); +if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) { + echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL; +} set_time_limit(0); -require __DIR__.'/../vendor/autoload.php'; +require dirname(__DIR__).'/vendor/autoload.php'; -$input = new ArgvInput(); -$env = $input->getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: 'dev', true); -$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption('--no-debug', true) && $env !== 'prod'; - -if ($debug) { - Debug::enable(); +if (!class_exists(Application::class) || !class_exists(Dotenv::class)) { + throw new LogicException('You need to add "symfony/framework-bundle" and "symfony/dotenv" as Composer dependencies.'); } -$kernel = new AppKernel($env, $debug); +$input = new ArgvInput(); +if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) { + putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env); +} + +if ($input->hasParameterOption('--no-debug', true)) { + putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0'); +} + +(new Dotenv())->bootEnv(dirname(__DIR__).'/.env'); + +if ($_SERVER['APP_DEBUG']) { + umask(0000); + + if (class_exists(Debug::class)) { + Debug::enable(); + } +} + +$kernel = new AppKernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); $application = new Application($kernel); $application->run($input); diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a40fd7fee..4ba67d281 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -19,7 +19,7 @@ - + diff --git a/tests/bootstrap.php b/tests/bootstrap.php index fad77b3bb..ec499e475 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,10 +1,13 @@ bootEnv(dirname(__DIR__) . '/.env'); + (new Filesystem())->remove(__DIR__ . '/../var/cache/test'); if (!isPartialRun()) { diff --git a/web/app.php b/web/app.php index 3427e133e..71a628bfd 100644 --- a/web/app.php +++ b/web/app.php @@ -1,10 +1,16 @@ bootEnv(dirname(__DIR__) . '/.env'); + +$kernel = new AppKernel($_SERVER['APP_ENV'], (bool )$_SERVER['APP_DEBUG']); //$kernel = new AppCache($kernel); // When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter diff --git a/web/app_dev.php b/web/app_dev.php index d3b01d8e8..2e7e0ed5e 100644 --- a/web/app_dev.php +++ b/web/app_dev.php @@ -1,5 +1,6 @@ bootEnv(dirname(__DIR__) . '/.env'); + Debug::enable(); -$kernel = new AppKernel('dev', true); +$kernel = new AppKernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send(); From 7cd46cb29291230a668be336ad06e035a14f8747 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sat, 11 Jan 2025 01:50:41 +0100 Subject: [PATCH 10/18] Use environment variables in config files --- app/config/config.yml | 62 +++++++++++++++++++------------------- app/config/config_prod.yml | 2 +- app/config/security.yml | 2 +- app/config/services.yml | 20 ++++++------ app/config/wallabag.yml | 2 +- 5 files changed, 44 insertions(+), 44 deletions(-) diff --git a/app/config/config.yml b/app/config/config.yml index bd50ab95f..0215be6bc 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -10,9 +10,9 @@ framework: #esi: ~ translator: enabled: true - fallback: "%locale%" + fallback: "%env(LOCALE)%" default_path: '%kernel.project_dir%/translations' - secret: "%secret%" + secret: "%env(SECRET)%" router: resource: "%kernel.project_dir%/app/config/routing.yml" strict_requirements: ~ @@ -20,7 +20,7 @@ framework: csrf_protection: ~ validation: enable_annotations: true - default_locale: "%locale%" + default_locale: "%env(LOCALE)%" trusted_hosts: ~ session: # handler_id set to null will use default session handler from php.ini @@ -30,10 +30,10 @@ framework: fragments: ~ http_method_override: true assets: - base_url: '%domain_name%' + base_url: '%env(DOMAIN_NAME)%' json_manifest_path: '%kernel.project_dir%/web/build/manifest.json' mailer: - dsn: "%mailer_dsn%" + dsn: "%env(MAILER_DSN)%" http_client: scoped_clients: download_images.client: @@ -58,8 +58,8 @@ twig: form_themes: - "@SpiriitFormFilter/Form/form_div_layout.html.twig" globals: - wallabag_url: '%domain_name%' - registration_enabled: '%fosuser_registration%' + wallabag_url: '%env(DOMAIN_NAME)%' + registration_enabled: '%env(bool:FOSUSER_REGISTRATION)%' # Doctrine Configuration doctrine: @@ -82,7 +82,7 @@ doctrine: alias: Wallabag stof_doctrine_extensions: - default_locale: "%locale%" + default_locale: "%env(LOCALE)%" translation_fallback: true orm: default: @@ -190,9 +190,9 @@ fos_user: user_class: Wallabag\Entity\User registration: confirmation: - enabled: "%fosuser_confirmation%" + enabled: "%env(bool:FOSUSER_CONFIRMATION)%" from_email: - address: "%from_email%" + address: "%env(FROM_EMAIL)%" sender_name: wallabag service: mailer: Wallabag\Mailer\UserMailer @@ -206,8 +206,8 @@ fos_oauth_server: service: user_provider: fos_user.user_provider.username_email options: - refresh_token_lifetime: "%fos_oauth_server_refresh_token_lifetime%" - access_token_lifetime: "%fos_oauth_server_access_token_lifetime%" + refresh_token_lifetime: "%env(FOS_OAUTH_SERVER_REFRESH_TOKEN_LIFETIME)%" + access_token_lifetime: "%env(FOS_OAUTH_SERVER_ACCESS_TOKEN_LIFETIME)%" scheb_two_factor: trusted_device: @@ -220,12 +220,12 @@ scheb_two_factor: google: enabled: true - issuer: "%server_name%" + issuer: "%env(SERVER_NAME)%" template: "Authentication/form.html.twig" email: enabled: true - sender_email: "%twofactor_sender%" + sender_email: "%env(TWOFACTOR_SENDER)%" digits: 6 template: "Authentication/form.html.twig" mailer: Wallabag\Mailer\AuthCodeMailer @@ -237,10 +237,10 @@ rulerz: old_sound_rabbit_mq: connections: default: - host: "%rabbitmq_host%" - port: "%rabbitmq_port%" - user: "%rabbitmq_user%" - password: "%rabbitmq_password%" + host: "%env(RABBITMQ_HOST)%" + port: "%env(int:RABBITMQ_PORT)%" + user: "%env(RABBITMQ_USER)%" + password: "%env(RABBITMQ_PASSWORD)%" vhost: / lazy: true producers: @@ -318,7 +318,7 @@ old_sound_rabbit_mq: queue_options: name: 'wallabag.import.pocket' callback: wallabag.consumer.amqp.pocket - qos_options: {prefetch_count: "%rabbitmq_prefetch_count%"} + qos_options: {prefetch_count: "%env(int:RABBITMQ_PREFETCH_COUNT)%"} import_readability: connection: default exchange_options: @@ -327,7 +327,7 @@ old_sound_rabbit_mq: queue_options: name: 'wallabag.import.readability' callback: wallabag.consumer.amqp.readability - qos_options: {prefetch_count: "%rabbitmq_prefetch_count%"} + qos_options: {prefetch_count: "%env(int:RABBITMQ_PREFETCH_COUNT)%"} import_instapaper: connection: default exchange_options: @@ -336,7 +336,7 @@ old_sound_rabbit_mq: queue_options: name: 'wallabag.import.instapaper' callback: wallabag.consumer.amqp.instapaper - qos_options: {prefetch_count: "%rabbitmq_prefetch_count%"} + qos_options: {prefetch_count: "%env(int:RABBITMQ_PREFETCH_COUNT)%"} import_pinboard: connection: default exchange_options: @@ -345,7 +345,7 @@ old_sound_rabbit_mq: queue_options: name: 'wallabag.import.pinboard' callback: wallabag.consumer.amqp.pinboard - qos_options: {prefetch_count: "%rabbitmq_prefetch_count%"} + qos_options: {prefetch_count: "%env(int:RABBITMQ_PREFETCH_COUNT)%"} import_delicious: connection: default exchange_options: @@ -354,7 +354,7 @@ old_sound_rabbit_mq: queue_options: name: 'wallabag.import.delicious' callback: wallabag.consumer.amqp.delicious - qos_options: {prefetch_count: "%rabbitmq_prefetch_count%"} + qos_options: {prefetch_count: "%env(int:RABBITMQ_PREFETCH_COUNT)%"} import_wallabag_v1: connection: default exchange_options: @@ -363,7 +363,7 @@ old_sound_rabbit_mq: queue_options: name: 'wallabag.import.wallabag_v1' callback: wallabag.consumer.amqp.wallabag_v1 - qos_options: {prefetch_count: "%rabbitmq_prefetch_count%"} + qos_options: {prefetch_count: "%env(int:RABBITMQ_PREFETCH_COUNT)%"} import_wallabag_v2: connection: default exchange_options: @@ -372,7 +372,7 @@ old_sound_rabbit_mq: queue_options: name: 'wallabag.import.wallabag_v2' callback: wallabag.consumer.amqp.wallabag_v2 - qos_options: {prefetch_count: "%rabbitmq_prefetch_count%"} + qos_options: {prefetch_count: "%env(int:RABBITMQ_PREFETCH_COUNT)%"} import_elcurator: connection: default exchange_options: @@ -381,7 +381,7 @@ old_sound_rabbit_mq: queue_options: name: 'wallabag.import.elcurator' callback: wallabag.consumer.amqp.elcurator - qos_options: {prefetch_count: "%rabbitmq_prefetch_count%"} + qos_options: {prefetch_count: "%env(int:RABBITMQ_PREFETCH_COUNT)%"} import_omnivore: connection: default exchange_options: @@ -390,7 +390,7 @@ old_sound_rabbit_mq: queue_options: name: 'wallabag.import.omnivore' callback: wallabag.consumer.amqp.omnivore - qos_options: {prefetch_count: "%rabbitmq_prefetch_count%"} + qos_options: {prefetch_count: "%env(int:RABBITMQ_PREFETCH_COUNT)%"} import_firefox: connection: default exchange_options: @@ -399,7 +399,7 @@ old_sound_rabbit_mq: queue_options: name: 'wallabag.import.firefox' callback: wallabag.consumer.amqp.firefox - qos_options: {prefetch_count: "%rabbitmq_prefetch_count%"} + qos_options: {prefetch_count: "%env(int:RABBITMQ_PREFETCH_COUNT)%"} import_chrome: connection: default exchange_options: @@ -408,7 +408,7 @@ old_sound_rabbit_mq: queue_options: name: 'wallabag.import.chrome' callback: wallabag.consumer.amqp.chrome - qos_options: {prefetch_count: "%rabbitmq_prefetch_count%"} + qos_options: {prefetch_count: "%env(int:RABBITMQ_PREFETCH_COUNT)%"} import_shaarli: connection: default exchange_options: @@ -417,7 +417,7 @@ old_sound_rabbit_mq: queue_options: name: 'wallabag.import.shaarli' callback: wallabag.consumer.amqp.shaarli - qos_options: {prefetch_count: "%rabbitmq_prefetch_count%"} + qos_options: {prefetch_count: "%env(int:RABBITMQ_PREFETCH_COUNT)%"} import_pocket_html: connection: default exchange_options: @@ -426,7 +426,7 @@ old_sound_rabbit_mq: queue_options: name: 'wallabag.import.pocket_html' callback: wallabag.consumer.amqp.pocket_html - qos_options: {prefetch_count: "%rabbitmq_prefetch_count%"} + qos_options: {prefetch_count: "%env(int:RABBITMQ_PREFETCH_COUNT)%"} fos_js_routing: routes_to_expose: diff --git a/app/config/config_prod.yml b/app/config/config_prod.yml index 709af4551..b8a1cb556 100644 --- a/app/config/config_prod.yml +++ b/app/config/config_prod.yml @@ -21,4 +21,4 @@ monolog: type: console sentry: - dsn: "%sentry_dsn%" + dsn: "%env(SENTRY_DSN)%" diff --git a/app/config/security.yml b/app/config/security.yml index b05e54b01..e5f24fe71 100644 --- a/app/config/security.yml +++ b/app/config/security.yml @@ -45,7 +45,7 @@ security: anonymous: true remember_me: - secret: "%secret%" + secret: "%env(SECRET)%" lifetime: 31536000 path: / domain: ~ diff --git a/app/config/services.yml b/app/config/services.yml index 09eb22729..24082bb66 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -15,15 +15,15 @@ services: $projectDir: '%kernel.project_dir%' $debug: '%kernel.debug%' $defaultLocale: '%kernel.default_locale%' - $wallabagUrl: '%domain_name%' - $tablePrefix: "%database_table_prefix%" + $wallabagUrl: '%env(DOMAIN_NAME)%' + $tablePrefix: "%env(DATABASE_TABLE_PREFIX)%" $encryptionKeyPath: "%wallabag.site_credentials.encryption_key_path%" $fetchingErrorMessageTitle: "%wallabag.fetching_error_message_title%" $fetchingErrorMessage: '%wallabag.fetching_error_message%' $languages: '%wallabag.languages%' $lifeTime: '%wallabag.cache_lifetime%' $logoPath: 'web/img/appicon/apple-touch-icon-152.png' - $registrationEnabled: '%fosuser_registration%' + $registrationEnabled: '%env(bool:FOSUSER_REGISTRATION)%' $restrictedAccess: '@=service(''craue_config'').get(''restricted_access'')' $senderEmail: "%scheb_two_factor.email.sender_email%" $senderName: "%scheb_two_factor.email.sender_name%" @@ -187,7 +187,7 @@ services: Wallabag\Event\Subscriber\SchemaAdapterSubscriber: arguments: - $databaseTablePrefix: "%database_table_prefix%" + $databaseTablePrefix: "%env(DATABASE_TABLE_PREFIX)%" tags: - { name: doctrine.event_subscriber } @@ -249,11 +249,11 @@ services: Predis\Client: arguments: $parameters: - scheme: '%redis_scheme%' - host: '%redis_host%' - port: '%redis_port%' - path: '%redis_path%' - password: '%redis_password%' + scheme: '%env(REDIS_SCHEME)%' + host: '%env(REDIS_HOST)%' + port: '%env(int:REDIS_PORT)%' + path: '%env(REDIS_PATH)%' + password: '%env(REDIS_PASSWORD)%' Wallabag\Event\Subscriber\SQLiteCascadeDeleteSubscriber: tags: @@ -269,7 +269,7 @@ services: Wallabag\Command\InstallCommand: arguments: - $databaseDriver: '%database_driver%' + $databaseDriver: '%env(DATABASE_DRIVER)%' $defaultSettings: '%wallabag.default_internal_settings%' $defaultIgnoreOriginInstanceRules: '%wallabag.default_ignore_origin_instance_rules%' diff --git a/app/config/wallabag.yml b/app/config/wallabag.yml index 3cc1b15c1..bfce9c197 100644 --- a/app/config/wallabag.yml +++ b/app/config/wallabag.yml @@ -25,7 +25,7 @@ parameters: el: 'Ελληνικά' gl: 'Galego' wallabag.items_on_page: 12 - wallabag.language: '%locale%' + wallabag.language: '%env(LOCALE)%' wallabag.feed_limit: 50 wallabag.reading_speed: 200 wallabag.cache_lifetime: 10 From bc1b42a3f70bfedd9dbca12c47c3b85573a5ce18 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Mon, 17 Feb 2025 21:40:34 +0100 Subject: [PATCH 11/18] Use DATABASE_URL directly in InstallCommand --- app/AppKernel.php | 1 - app/config/services.yml | 2 +- src/Command/InstallCommand.php | 24 ++++++++++++++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/AppKernel.php b/app/AppKernel.php index 7770ffd50..9212be758 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -94,7 +94,6 @@ class AppKernel extends Kernel private function loadEnvVarsFromParameters(ContainerBuilder $container) { - $this->setEnvVarFromParameter($container, 'DATABASE_DRIVER', 'database_driver'); $this->setEnvVarFromParameter($container, 'DATABASE_HOST', 'database_host'); $this->setEnvVarFromParameter($container, 'DATABASE_PORT', 'database_port'); $this->setEnvVarFromParameter($container, 'DATABASE_NAME', 'database_name'); diff --git a/app/config/services.yml b/app/config/services.yml index 24082bb66..e13bb92bb 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -269,7 +269,7 @@ services: Wallabag\Command\InstallCommand: arguments: - $databaseDriver: '%env(DATABASE_DRIVER)%' + $databaseUrl: '%env(DATABASE_URL)%' $defaultSettings: '%wallabag.default_internal_settings%' $defaultIgnoreOriginInstanceRules: '%wallabag.default_ignore_origin_instance_rules%' diff --git a/src/Command/InstallCommand.php b/src/Command/InstallCommand.php index b9a2590dc..8f6c76187 100644 --- a/src/Command/InstallCommand.php +++ b/src/Command/InstallCommand.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\Exception\DriverException; use Doctrine\DBAL\Platforms\MySQLPlatform; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Platforms\SqlitePlatform; +use Doctrine\DBAL\Tools\DsnParser; use Doctrine\Migrations\Metadata\Storage\TableMetadataStorageConfiguration; use Doctrine\ORM\EntityManagerInterface; use FOS\UserBundle\Event\UserEvent; @@ -41,17 +42,17 @@ class InstallCommand extends Command private EventDispatcherInterface $dispatcher; private UserManagerInterface $userManager; private TableMetadataStorageConfiguration $tableMetadataStorageConfiguration; - private string $databaseDriver; + private string $databaseUrl; private array $defaultSettings; private array $defaultIgnoreOriginInstanceRules; - public function __construct(EntityManagerInterface $entityManager, EventDispatcherInterface $dispatcher, UserManagerInterface $userManager, TableMetadataStorageConfiguration $tableMetadataStorageConfiguration, string $databaseDriver, array $defaultSettings, array $defaultIgnoreOriginInstanceRules) + public function __construct(EntityManagerInterface $entityManager, EventDispatcherInterface $dispatcher, UserManagerInterface $userManager, TableMetadataStorageConfiguration $tableMetadataStorageConfiguration, string $databaseUrl, array $defaultSettings, array $defaultIgnoreOriginInstanceRules) { $this->entityManager = $entityManager; $this->dispatcher = $dispatcher; $this->userManager = $userManager; $this->tableMetadataStorageConfiguration = $tableMetadataStorageConfiguration; - $this->databaseDriver = $databaseDriver; + $this->databaseUrl = $databaseUrl; $this->defaultSettings = $defaultSettings; $this->defaultIgnoreOriginInstanceRules = $defaultIgnoreOriginInstanceRules; @@ -103,13 +104,24 @@ class InstallCommand extends Command $status = 'OK!'; $help = ''; - if (!\extension_loaded($this->databaseDriver)) { + /** @see \Doctrine\DBAL\DriverManager::$driverSchemeAliases */ + $params = (new DsnParser([ + 'mysql' => 'pdo_mysql', + 'mysql2' => 'pdo_mysql', // Amazon RDS, for some weird reason + 'postgres' => 'pdo_pgsql', + 'postgresql' => 'pdo_pgsql', + 'pgsql' => 'pdo_pgsql', + 'sqlite' => 'pdo_sqlite', + 'sqlite3' => 'pdo_sqlite', + ]))->parse($this->databaseUrl); + + if (!\extension_loaded($params['driver'])) { $fulfilled = false; $status = 'ERROR!'; - $help = 'Database driver "' . $this->databaseDriver . '" is not installed.'; + $help = 'Database driver "' . $params['driver'] . '" is not installed.'; } - $rows[] = [\sprintf($label, $this->databaseDriver), $status, $help]; + $rows[] = [\sprintf($label, $params['driver']), $status, $help]; // testing if connection to the database can be established $label = 'Database connection'; From 64e9ae12ae77c90de6d1181e9f961db5e1e619b4 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Mon, 17 Feb 2025 21:45:17 +0100 Subject: [PATCH 12/18] Remove database env vars that are covered by DATABASE_URL --- app/AppKernel.php | 8 -------- docker/mariadb/env | 7 ------- docker/php/env.example | 7 ------- docker/postgres/env | 7 ------- 4 files changed, 29 deletions(-) diff --git a/app/AppKernel.php b/app/AppKernel.php index 9212be758..a4f2c1d26 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -94,15 +94,7 @@ class AppKernel extends Kernel private function loadEnvVarsFromParameters(ContainerBuilder $container) { - $this->setEnvVarFromParameter($container, 'DATABASE_HOST', 'database_host'); - $this->setEnvVarFromParameter($container, 'DATABASE_PORT', 'database_port'); - $this->setEnvVarFromParameter($container, 'DATABASE_NAME', 'database_name'); - $this->setEnvVarFromParameter($container, 'DATABASE_USER', 'database_user'); - $this->setEnvVarFromParameter($container, 'DATABASE_PASSWORD', 'database_password'); - $this->setEnvVarFromParameter($container, 'DATABASE_PATH', 'database_path'); $this->setEnvVarFromParameter($container, 'DATABASE_TABLE_PREFIX', 'database_table_prefix'); - $this->setEnvVarFromParameter($container, 'DATABASE_SOCKET', 'database_socket'); - $this->setEnvVarFromParameter($container, 'DATABASE_CHARSET', 'database_charset'); $this->setEnvVarFromParameter($container, 'DOMAIN_NAME', 'domain_name'); $this->setEnvVarFromParameter($container, 'SERVER_NAME', 'server_name'); diff --git a/docker/mariadb/env b/docker/mariadb/env index 8c8a01fd3..3438f93f9 100644 --- a/docker/mariadb/env +++ b/docker/mariadb/env @@ -1,9 +1,2 @@ MYSQL_ROOT_PASSWORD=wallaroot MYSQL_DATABASE=wallabag -DATABASE_DRIVER=pdo_mysql -DATABASE_HOST=mariadb -DATABASE_PORT=3306 -DATABASE_NAME=wallabag -DATABASE_USER=root -DATABASE_PASSWORD=wallaroot -DATABASE_CHARSET=utf8mb4 diff --git a/docker/php/env.example b/docker/php/env.example index 1eff4bcee..70319de03 100644 --- a/docker/php/env.example +++ b/docker/php/env.example @@ -1,10 +1,3 @@ -DATABASE_DRIVER=pdo_sqlite -DATABASE_HOST=127.0.0.1 -DATABASE_PORT=~ -DATABASE_NAME=symfony -DATABASE_USER=root -DATABASE_PASSWORD=~ -DATABASE_PATH='"%kernel.project_dir%/data/db/wallabag.sqlite"' DOMAIN_NAME=http://localhost:8000 SECRET=ch4n63m31fy0uc4n PHP_SESSION_SAVE_PATH=tcp://redis:6379?database=2 diff --git a/docker/postgres/env b/docker/postgres/env index 5d9761861..90d2260f7 100644 --- a/docker/postgres/env +++ b/docker/postgres/env @@ -1,10 +1,3 @@ POSTGRES_USER=wallabag POSTGRES_PASSWORD=wallapass POSTGRES_DB=wallabag -DATABASE_HOST=postgres -DATABASE_PORT=5432 -DATABASE_NAME=wallabag -DATABASE_USER=wallabag -DATABASE_PASSWORD=wallapass -DATABASE_DRIVER=pdo_pgsql -DATABASE_PATH=null From 06a05ed88a6a0c948c052547319db627e7be4ef8 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Mon, 17 Feb 2025 22:14:19 +0100 Subject: [PATCH 13/18] Remove parameters.yml and related files --- .github/ISSUE_TEMPLATE/2-bug-report.md | 33 +++++++++- .github/workflows/coding-standards.yml | 2 +- .github/workflows/continuous-integration.yml | 9 ++- .gitignore | 3 - app/config/config_test.yml | 2 +- app/config/parameters.yml.dist | 65 -------------------- app/config/parameters_test.yml | 4 -- app/config/tests/.env.mysql | 1 + app/config/tests/.env.pgsql | 1 + app/config/tests/.env.sqlite | 1 + app/config/tests/parameters_test.mysql.yml | 4 -- app/config/tests/parameters_test.pgsql.yml | 4 -- app/config/tests/parameters_test.sqlite.yml | 4 -- composer-dependency-analyser.php | 1 - composer.json | 5 -- composer.lock | 59 +----------------- docker/php/config/parameters.yml | 50 --------------- docker/php/entrypoint.sh | 1 - docker/php/env.example | 2 - templates/Static/about.html.twig | 1 - 20 files changed, 40 insertions(+), 212 deletions(-) delete mode 100644 app/config/parameters.yml.dist delete mode 100644 app/config/parameters_test.yml create mode 100644 app/config/tests/.env.mysql create mode 100644 app/config/tests/.env.pgsql create mode 100644 app/config/tests/.env.sqlite delete mode 100644 app/config/tests/parameters_test.mysql.yml delete mode 100644 app/config/tests/parameters_test.pgsql.yml delete mode 100644 app/config/tests/parameters_test.sqlite.yml delete mode 100644 docker/php/config/parameters.yml diff --git a/.github/ISSUE_TEMPLATE/2-bug-report.md b/.github/ISSUE_TEMPLATE/2-bug-report.md index 70705d61a..bcbc1b827 100644 --- a/.github/ISSUE_TEMPLATE/2-bug-report.md +++ b/.github/ISSUE_TEMPLATE/2-bug-report.md @@ -17,7 +17,7 @@ Installation: How did you install wallabag? Using git clone, the docker image, a PHP version: The version of PHP you are using OS: The host running wallabag Database: The storage system your instance is using (SQLite, MySQL/MariaDB or PostgreSQL) with the version -Parameters: Paste the content of your app/config/parameters.yml (hide sensitive stuff if you want) +Parameters: Put the content of your environment variables (hide sensitive stuff if you want) --> ### Environment @@ -29,10 +29,37 @@ Parameters: Paste the content of your app/config/parameters.yml (hide sensitiv * **Parameters**:
- My app/config/parameters.yml is: + My environment variables are: ``` - PASTE HERE + LOCALE= + + # Make sure to hide username and password below, if any + DATABASE_URL= + DATABASE_TABLE_PREFIX= + + FOSUSER_REGISTRATION= + FOSUSER_CONFIRMATION= + + FOS_OAUTH_SERVER_ACCESS_TOKEN_LIFETIME= + FOS_OAUTH_SERVER_REFRESH_TOKEN_LIFETIME= + TWOFACTOR_SENDER= + + # Make sure to hide username and password below, if any + MAILER_DSN= + FROM_EMAIL= + + RABBITMQ_HOST= + RABBITMQ_PORT= + + REDIS_SCHEME= + REDIS_HOST= + REDIS_PORT= + REDIS_PATH= + RABBITMQ_PREFETCH_COUNT= + + # Make sure to hide username and password below, if any + SENTRY_DSN= ```
diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index cf6a0f5dd..3b4571433 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -40,7 +40,7 @@ jobs: run: | sudo systemctl start mysql.service sudo mysql -u root -proot -h 127.0.0.1 -e "CREATE DATABASE wallabag_test" - cp app/config/tests/parameters_test.mysql.yml app/config/parameters_test.yml + cp app/config/tests/.env.mysql .env.test.local - name: "Install dependencies with Composer" id: composer-install diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 67c50c8cf..83f1aa380 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -89,7 +89,7 @@ jobs: run: yarn build:dev - name: "Prepare database configuration" - run: cp app/config/tests/parameters_test.${{ matrix.database }}.yml app/config/parameters_test.yml + run: cp app/config/tests/.env.${{ matrix.database }} .env.test.local - name: "Run PHPUnit" run: "php bin/phpunit -v" @@ -140,8 +140,7 @@ jobs: - name: "Remove database prefix" run: | - pip install --user yq - yq -Y --in-place '.parameters.database_table_prefix = ""' app/config/parameters.yml.dist + sed -i 's/DATABASE_TABLE_PREFIX=wallabag_/DATABASE_TABLE_PREFIX=/' .env - name: "Setup MySQL" if: "${{ matrix.database == 'mysql' }}" @@ -169,7 +168,7 @@ jobs: run: yarn build:dev - name: "Prepare database configuration" - run: cp app/config/tests/parameters_test.${{ matrix.database }}.yml app/config/parameters_test.yml + run: cp app/config/tests/.env.${{ matrix.database }} .env.test.local - name: "Run PHPUnit" run: "php bin/phpunit -v" @@ -235,7 +234,7 @@ jobs: run: yarn build:dev - name: "Prepare database configuration" - run: cp app/config/tests/parameters_test.${{ matrix.database }}.yml app/config/parameters_test.yml + run: cp app/config/tests/.env.${{ matrix.database }} .env.test.local - name: "Run PHPUnit" run: "php bin/phpunit -v" diff --git a/.gitignore b/.gitignore index b8f1c6f8f..41c2a8ad1 100644 --- a/.gitignore +++ b/.gitignore @@ -17,9 +17,6 @@ phpunit.xml compose.override.yaml -# Parameters -/app/config/parameters.yml - # Managed by Composer /vendor/ diff --git a/app/config/config_test.yml b/app/config/config_test.yml index 20b92f01f..a9bb06a65 100644 --- a/app/config/config_test.yml +++ b/app/config/config_test.yml @@ -1,11 +1,11 @@ imports: - { resource: config_dev.yml } - - { resource: parameters_test.yml } - { resource: services_test.yml } parameters: fosuser_registration: true wallabag_dbname_suffix: '_test' + database_url: '%env(resolve:DATABASE_URL)%' domain_name: '%env(DOMAIN_NAME)%' framework: diff --git a/app/config/parameters.yml.dist b/app/config/parameters.yml.dist deleted file mode 100644 index db23ba4d6..000000000 --- a/app/config/parameters.yml.dist +++ /dev/null @@ -1,65 +0,0 @@ -# This file is a "template" of what your parameters.yml file should look like -parameters: - # Uncomment these settings or manually update your parameters.yml - # to use Docker Compose - # - # database_driver: %env.database_driver% - # database_host: %env.database_host% - # database_port: %env.database_port% - # database_name: %env.database_name% - # database_user: %env.database_user% - # database_password: %env.database_password% - - database_driver: pdo_mysql - database_host: 127.0.0.1 - database_port: ~ - database_name: wallabag - database_user: root - database_password: ~ - # For SQLite, database_path should be "%kernel.project_dir%/data/db/wallabag.sqlite" - database_path: null - database_table_prefix: wallabag_ - database_socket: null - # with PostgreSQL and SQLite, you must set "utf8" - database_charset: utf8mb4 - - domain_name: https://your-wallabag-instance.wallabag.org - server_name: "Your wallabag instance" - - mailer_dsn: smtp://127.0.0.1 - - locale: en - - # A secret key that's used to generate certain security-related tokens - secret: CHANGE_ME_TO_SOMETHING_SECRET_AND_RANDOM - - # two factor stuff - twofactor_sender: no-reply@wallabag.org - - # fosuser stuff - fosuser_registration: false - fosuser_confirmation: true - - # how long the access token should live in seconds for the API - fos_oauth_server_access_token_lifetime: 3600 - # how long the refresh token should life in seconds for the API - fos_oauth_server_refresh_token_lifetime: 1209600 - - from_email: no-reply@wallabag.org - - # RabbitMQ processing - rabbitmq_host: localhost - rabbitmq_port: 5672 - rabbitmq_user: guest - rabbitmq_password: guest - rabbitmq_prefetch_count: 10 - - # Redis processing - redis_scheme: tcp - redis_host: localhost - redis_port: 6379 - redis_path: null - redis_password: null - - # sentry logging - sentry_dsn: ~ diff --git a/app/config/parameters_test.yml b/app/config/parameters_test.yml deleted file mode 100644 index 9f9f812a2..000000000 --- a/app/config/parameters_test.yml +++ /dev/null @@ -1,4 +0,0 @@ -parameters: - database_path: "%kernel.project_dir%/data/db/wallabag%wallabag_dbname_suffix%.sqlite" - database_url: '%env(resolve:DATABASE_URL)%' - domain_name: '%env(DOMAIN_NAME)%' diff --git a/app/config/tests/.env.mysql b/app/config/tests/.env.mysql new file mode 100644 index 000000000..742ef5bbc --- /dev/null +++ b/app/config/tests/.env.mysql @@ -0,0 +1 @@ +DATABASE_URL=mysql://root:root@127.0.0.1:3306/wallabag?charset=utf8mb4 diff --git a/app/config/tests/.env.pgsql b/app/config/tests/.env.pgsql new file mode 100644 index 000000000..d7a3a0f8b --- /dev/null +++ b/app/config/tests/.env.pgsql @@ -0,0 +1 @@ +DATABASE_URL=postgres://wallabag:wallabagrocks@localhost/wallabag?charset=utf8 diff --git a/app/config/tests/.env.sqlite b/app/config/tests/.env.sqlite new file mode 100644 index 000000000..12f18d778 --- /dev/null +++ b/app/config/tests/.env.sqlite @@ -0,0 +1 @@ +DATABASE_URL=sqlite:///%kernel.project_dir%/data/db/wallabag%wallabag_dbname_suffix%.sqlite?charset=utf8 diff --git a/app/config/tests/parameters_test.mysql.yml b/app/config/tests/parameters_test.mysql.yml deleted file mode 100644 index 3e825114d..000000000 --- a/app/config/tests/parameters_test.mysql.yml +++ /dev/null @@ -1,4 +0,0 @@ -parameters: - env(DATABASE_URL): mysql://root:root@127.0.0.1:3306/wallabag?charset=utf8mb4 - database_url: '%env(resolve:DATABASE_URL)%' - domain_name: '%env(DOMAIN_NAME)%' diff --git a/app/config/tests/parameters_test.pgsql.yml b/app/config/tests/parameters_test.pgsql.yml deleted file mode 100644 index 0bf594828..000000000 --- a/app/config/tests/parameters_test.pgsql.yml +++ /dev/null @@ -1,4 +0,0 @@ -parameters: - env(DATABASE_URL): postgres://wallabag:wallabagrocks@localhost/wallabag?charset=utf8 - database_url: '%env(resolve:DATABASE_URL)%' - domain_name: '%env(DOMAIN_NAME)%' diff --git a/app/config/tests/parameters_test.sqlite.yml b/app/config/tests/parameters_test.sqlite.yml deleted file mode 100644 index 5b1b89787..000000000 --- a/app/config/tests/parameters_test.sqlite.yml +++ /dev/null @@ -1,4 +0,0 @@ -parameters: - env(DATABASE_URL): sqlite:///%kernel.project_dir%/data/db/wallabag%wallabag_dbname_suffix%.sqlite?charset=utf8 - database_url: '%env(resolve:DATABASE_URL)%' - domain_name: '%env(DOMAIN_NAME)%' diff --git a/composer-dependency-analyser.php b/composer-dependency-analyser.php index a83b8247d..5199c8ee8 100644 --- a/composer-dependency-analyser.php +++ b/composer-dependency-analyser.php @@ -21,7 +21,6 @@ $config 'ergebnis/composer-normalize', 'friendsofphp/php-cs-fixer', 'friendsoftwig/twigcs', - 'incenteev/composer-parameter-handler', 'j0k3r/graby-site-config', 'laminas/laminas-code', 'lcobucci/jwt', diff --git a/composer.json b/composer.json index c681991ee..a0fb18610 100644 --- a/composer.json +++ b/composer.json @@ -77,7 +77,6 @@ "friendsofsymfony/user-bundle": "^3.2.1", "guzzlehttp/psr7": "^2.6.2", "html2text/html2text": "^4.3.1", - "incenteev/composer-parameter-handler": "^2.2", "j0k3r/graby": "^2.4.5", "j0k3r/graby-site-config": "^1.0", "javibravo/simpleue": "^2.1", @@ -223,9 +222,6 @@ "sort-packages": true }, "extra": { - "incenteev-parameters": { - "file": "app/config/parameters.yml" - }, "public-dir": "web", "symfony": { "allow-contrib": true, @@ -240,7 +236,6 @@ "@post-cmd" ], "post-cmd": [ - "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters", "bin/console cache:clear --no-warmup", "bin/console assets:install web --symlink --relative" ] diff --git a/composer.lock b/composer.lock index 786c81fd3..f77445ba9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "275616311733b2f623c48eda835def87", + "content-hash": "14496bc12cd56950bd548fb244a8c769", "packages": [ { "name": "babdev/pagerfanta-bundle", @@ -4159,63 +4159,6 @@ }, "time": "2021-07-21T13:50:14+00:00" }, - { - "name": "incenteev/composer-parameter-handler", - "version": "v2.2.0", - "source": { - "type": "git", - "url": "https://github.com/Incenteev/ParameterHandler.git", - "reference": "90bffce926e96b365579a2ef024aab457f4b80c5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Incenteev/ParameterHandler/zipball/90bffce926e96b365579a2ef024aab457f4b80c5", - "reference": "90bffce926e96b365579a2ef024aab457f4b80c5", - "shasum": "" - }, - "require": { - "php": ">=7.4", - "symfony/yaml": "^5.4 || ^6.0 || ^7.0" - }, - "require-dev": { - "composer/composer": "^2.0@dev", - "phpspec/prophecy-phpunit": "^2.1", - "phpunit/phpunit": "^9.6", - "symfony/filesystem": "^5.4 || ^6.0 || ^7.0", - "symfony/phpunit-bridge": "^6.4.1 || ^7.0.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.x-dev" - } - }, - "autoload": { - "psr-4": { - "Incenteev\\ParameterHandler\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Christophe Coevoet", - "email": "stof@notk.org" - } - ], - "description": "Composer script handling your ignored parameter file", - "homepage": "https://github.com/Incenteev/ParameterHandler", - "keywords": [ - "parameters management" - ], - "support": { - "issues": "https://github.com/Incenteev/ParameterHandler/issues", - "source": "https://github.com/Incenteev/ParameterHandler/tree/v2.2.0" - }, - "time": "2023-12-09T10:31:14+00:00" - }, { "name": "j0k3r/graby", "version": "2.4.5", diff --git a/docker/php/config/parameters.yml b/docker/php/config/parameters.yml deleted file mode 100644 index 249a0258d..000000000 --- a/docker/php/config/parameters.yml +++ /dev/null @@ -1,50 +0,0 @@ -parameters: - database_driver: ${DATABASE_DRIVER:-pdo_sqlite} - database_host: ${DATABASE_HOST:-127.0.0.1} - database_port: ${DATABASE_PORT:-~} - database_name: ${DATABASE_NAME:-symfony} - database_user: ${DATABASE_USER:-root} - database_password: ${DATABASE_PASSWORD:-~} - database_path: ${DATABASE_PATH:-"%kernel.project_dir%/data/db/wallabag.sqlite"} - database_table_prefix: ${DATABASE_TABLE_PREFIX:-wallabag_} - database_socket: ${DATABASE_SOCKET:-~} - database_charset: ${DATABASE_CHARSET:-utf8} - - domain_name: ${DOMAIN_NAME:-https://www.example.com} - server_name: ${SERVER_NAME:-"Your wallabag instance"} - - mailer_dsn: ${MAILER_DSN:-"smtp://127.0.0.1"} - - locale: ${LOCALE:-en} - - # A secret key that's used to generate certain security-related tokens - secret: ${SECRET:-~} - - # two factor stuff - twofactor_sender: ${TWOFACTOR_SENDER:-no-reply@wallabag.org} - - # fosuser stuff - fosuser_registration: ${FOSUSER_REGISTRATION:-false} - fosuser_confirmation: ${FOSUSER_CONFIRMATION:-true} - - fos_oauth_server_access_token_lifetime: ${FOS_OAUTH_SERVER_ACCESS_TOKEN_LIFETIME:-3600} - fos_oauth_server_refresh_token_lifetime: ${FOS_OAUTH_SERVER_REFRESH_TOKEN_LIFETIME:-1209600} - - from_email: ${FROM_EMAIL:-wallabag@example.com} - - # RabbitMQ processing - rabbitmq_host: ${RABBITMQ_HOST:-rabbitmq} - rabbitmq_port: ${RABBITMQ_PORT:-5672} - rabbitmq_user: ${RABBITMQ_USER:-guest} - rabbitmq_password: ${RABBITMQ_PASSWORD:-guest} - rabbitmq_prefetch_count: ${RABBITMQ_PREFETCH_COUNT:-10} - - # Redis processing - redis_scheme: ${REDIS_SCHEME:-tcp} - redis_host: ${REDIS_HOST:-redis} - redis_port: ${REDIS_PORT:-6379} - redis_path: ${REDIS_PATH:-~} - redis_password: ${REDIS_PASSWORD:-~} - - # Sentry - sentry_dsn: ${SENTRY_DSN:-~} diff --git a/docker/php/entrypoint.sh b/docker/php/entrypoint.sh index e147ed311..038954fda 100755 --- a/docker/php/entrypoint.sh +++ b/docker/php/entrypoint.sh @@ -1,6 +1,5 @@ #!/bin/sh envsubst < /opt/wallabag/config/wallabag-php.ini > /usr/local/etc/php/conf.d/wallabag-php.ini -envsubst < /opt/wallabag/config/parameters.yml > /var/www/html/app/config/parameters.yml exec "$@" diff --git a/docker/php/env.example b/docker/php/env.example index 70319de03..7b09edb02 100644 --- a/docker/php/env.example +++ b/docker/php/env.example @@ -1,5 +1,3 @@ -DOMAIN_NAME=http://localhost:8000 -SECRET=ch4n63m31fy0uc4n PHP_SESSION_SAVE_PATH=tcp://redis:6379?database=2 PHP_SESSION_HANDLER=redis TRUSTED_PROXIES=0.0.0.0/0 diff --git a/templates/Static/about.html.twig b/templates/Static/about.html.twig index 02805405b..399d00876 100644 --- a/templates/Static/about.html.twig +++ b/templates/Static/about.html.twig @@ -100,7 +100,6 @@ hoa/visitorBSD-3-Clause hoa/zformatBSD-3-Clause htmlawed/htmlawedGPL-2.0+ or LGPL-3.0 - incenteev/composer-parameter-handlerMIT j0k3r/grabyMIT j0k3r/graby-site-configPublic domain j0k3r/php-readabilityApache-2.0 From cbd37b2fe27c2cb0eebe5832e08ef96cb43232e0 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Tue, 18 Feb 2025 00:04:52 +0100 Subject: [PATCH 14/18] Make install command uses PHP globals for DATABASE_URL --- tests/Command/InstallCommandTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Command/InstallCommandTest.php b/tests/Command/InstallCommandTest.php index 18f7aaccd..ca25ba0e6 100644 --- a/tests/Command/InstallCommandTest.php +++ b/tests/Command/InstallCommandTest.php @@ -50,7 +50,7 @@ class InstallCommandTest extends WallabagTestCase $tmpDatabaseUrl = (string) (new Uri($this->originalDatabaseUrl))->withPath($tmpDatabaseName); } - putenv("DATABASE_URL=$tmpDatabaseUrl"); + $_ENV['DATABASE_URL'] = $_SERVER['DATABASE_URL'] = $tmpDatabaseUrl; if ($connection->getDatabasePlatform() instanceof PostgreSQLPlatform) { // PostgreSQL requires that the database exists before connecting to it @@ -64,13 +64,13 @@ class InstallCommandTest extends WallabagTestCase protected function tearDown(): void { - $databaseUrl = getenv('DATABASE_URL'); + $databaseUrl = $_SERVER['DATABASE_URL']; /** @var Connection $connection */ $connection = $this->getTestClient()->getContainer()->get(ManagerRegistry::class)->getConnection(); if ($connection->getDatabasePlatform() instanceof SqlitePlatform) {// Remove the real environnement variable - putenv('DATABASE_URL=' . $this->originalDatabaseUrl); + $_ENV['DATABASE_URL'] = $_SERVER['DATABASE_URL'] = $this->originalDatabaseUrl; $databasePath = parse_url($databaseUrl, \PHP_URL_PATH); @@ -81,7 +81,7 @@ class InstallCommandTest extends WallabagTestCase $testDatabaseName = $connection->getDatabase(); $connection->close(); - putenv('DATABASE_URL=' . $this->originalDatabaseUrl); + $_ENV['DATABASE_URL'] = $_SERVER['DATABASE_URL'] = $this->originalDatabaseUrl; // Create a new client to avoid the error: // Transaction commit failed because the transaction has been marked for rollback only. From 163c3773cb6ed617614c5987868e2054f471b59e Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Tue, 18 Feb 2025 00:50:08 +0100 Subject: [PATCH 15/18] Replace dbname suffix by explicit test database names --- .env.test | 3 +++ app/config/config_test.yml | 2 -- app/config/tests/.env.sqlite | 2 +- tests/Command/InstallCommandTest.php | 21 +++++++++++++++------ 4 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 .env.test diff --git a/.env.test b/.env.test new file mode 100644 index 000000000..c604b65a8 --- /dev/null +++ b/.env.test @@ -0,0 +1,3 @@ +DATABASE_URL=sqlite:///%kernel.project_dir%/data/db/wallabag_test.sqlite?charset=utf8 +#DATABASE_URL=mysql://root:wallaroot@mariadb:3306/wallabag_test?charset=utf8mb4 +#DATABASE_URL=postgres://wallabag:wallapass@postgres:5432/wallabag_test?charset=utf8 diff --git a/app/config/config_test.yml b/app/config/config_test.yml index a9bb06a65..5a2adb377 100644 --- a/app/config/config_test.yml +++ b/app/config/config_test.yml @@ -4,7 +4,6 @@ imports: parameters: fosuser_registration: true - wallabag_dbname_suffix: '_test' database_url: '%env(resolve:DATABASE_URL)%' domain_name: '%env(DOMAIN_NAME)%' @@ -25,7 +24,6 @@ web_profiler: doctrine: dbal: - dbname_suffix: '%wallabag_dbname_suffix%' # for MySQL and PostgreSQL use_savepoints: true orm: diff --git a/app/config/tests/.env.sqlite b/app/config/tests/.env.sqlite index 12f18d778..672ce6818 100644 --- a/app/config/tests/.env.sqlite +++ b/app/config/tests/.env.sqlite @@ -1 +1 @@ -DATABASE_URL=sqlite:///%kernel.project_dir%/data/db/wallabag%wallabag_dbname_suffix%.sqlite?charset=utf8 +DATABASE_URL=sqlite:///%kernel.project_dir%/data/db/wallabag.sqlite?charset=utf8 diff --git a/tests/Command/InstallCommandTest.php b/tests/Command/InstallCommandTest.php index ca25ba0e6..294536d73 100644 --- a/tests/Command/InstallCommandTest.php +++ b/tests/Command/InstallCommandTest.php @@ -41,11 +41,18 @@ class InstallCommandTest extends WallabagTestCase $connection = $this->getTestClient()->getContainer()->get(ManagerRegistry::class)->getConnection(); $this->originalDatabaseUrl = $this->getTestClient()->getContainer()->getParameter('database_url'); - $dbnameSuffix = $this->getTestClient()->getContainer()->getParameter('wallabag_dbname_suffix'); - $tmpDatabaseName = 'wallabag_' . bin2hex(random_bytes(5)); + $tmpDatabaseName = 'wallabag_test_' . bin2hex(random_bytes(5)); if ($connection->getDatabasePlatform() instanceof SqlitePlatform) { - $tmpDatabaseUrl = str_replace('wallabag' . $dbnameSuffix . '.sqlite', $tmpDatabaseName . $dbnameSuffix . '.sqlite', $this->originalDatabaseUrl); + $tmpDatabaseName = $this->getTestClient()->getContainer()->getParameter('kernel.project_dir') . '/data/db/' . $tmpDatabaseName . '.sqlite'; + + /** @see \Doctrine\DBAL\Tools\DsnParser::parse */ + $url = preg_replace('#^((?:pdo-)?sqlite3?):///#', '$1://localhost/', $this->originalDatabaseUrl); + + $tmpDatabaseUrl = (string) (new Uri($url))->withPath($tmpDatabaseName); + + // Add back the leading "/" that was removed by withPath, and remove the "localhost" part + $tmpDatabaseUrl = str_replace('//localhost', '///', $tmpDatabaseUrl); } else { $tmpDatabaseUrl = (string) (new Uri($this->originalDatabaseUrl))->withPath($tmpDatabaseName); } @@ -54,8 +61,7 @@ class InstallCommandTest extends WallabagTestCase if ($connection->getDatabasePlatform() instanceof PostgreSQLPlatform) { // PostgreSQL requires that the database exists before connecting to it - $tmpTestDatabaseName = $tmpDatabaseName . $dbnameSuffix; - $connection->executeQuery('CREATE DATABASE ' . $tmpTestDatabaseName); + $connection->executeQuery('CREATE DATABASE ' . $tmpDatabaseName); } // The environnement has been changed, recreate the client in order to update connection @@ -72,7 +78,10 @@ class InstallCommandTest extends WallabagTestCase if ($connection->getDatabasePlatform() instanceof SqlitePlatform) {// Remove the real environnement variable $_ENV['DATABASE_URL'] = $_SERVER['DATABASE_URL'] = $this->originalDatabaseUrl; - $databasePath = parse_url($databaseUrl, \PHP_URL_PATH); + /** @see \Doctrine\DBAL\Tools\DsnParser::parse */ + $url = preg_replace('#^((?:pdo-)?sqlite3?):///#', '$1://localhost/', $databaseUrl); + + $databasePath = parse_url($url, \PHP_URL_PATH); if (file_exists($databasePath)) { unlink($databasePath); From 738e95615a53ac05995124c330a3e722e76cd5c9 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sun, 16 Feb 2025 23:12:52 +0100 Subject: [PATCH 16/18] Expect that user registration is always enabled in tests --- .env.test | 1 + app/config/config_test.yml | 2 +- tests/Controller/Api/WallabagRestControllerTest.php | 6 ------ tests/Controller/SecurityControllerTest.php | 7 ------- 4 files changed, 2 insertions(+), 14 deletions(-) diff --git a/.env.test b/.env.test index c604b65a8..57c5e2134 100644 --- a/.env.test +++ b/.env.test @@ -1,3 +1,4 @@ DATABASE_URL=sqlite:///%kernel.project_dir%/data/db/wallabag_test.sqlite?charset=utf8 #DATABASE_URL=mysql://root:wallaroot@mariadb:3306/wallabag_test?charset=utf8mb4 #DATABASE_URL=postgres://wallabag:wallapass@postgres:5432/wallabag_test?charset=utf8 +FOSUSER_REGISTRATION=true diff --git a/app/config/config_test.yml b/app/config/config_test.yml index 5a2adb377..b68e0fde8 100644 --- a/app/config/config_test.yml +++ b/app/config/config_test.yml @@ -3,7 +3,7 @@ imports: - { resource: services_test.yml } parameters: - fosuser_registration: true + fosuser_registration: '%env(FOSUSER_REGISTRATION)%' database_url: '%env(resolve:DATABASE_URL)%' domain_name: '%env(DOMAIN_NAME)%' diff --git a/tests/Controller/Api/WallabagRestControllerTest.php b/tests/Controller/Api/WallabagRestControllerTest.php index d73115cd6..429fb037f 100644 --- a/tests/Controller/Api/WallabagRestControllerTest.php +++ b/tests/Controller/Api/WallabagRestControllerTest.php @@ -41,12 +41,6 @@ class WallabagRestControllerTest extends WallabagApiTestCase // create a new client instead of using $this->client to be sure client isn't authenticated $client = $this->createUnauthorizedClient(); - if (!$client->getContainer()->getParameter('fosuser_registration')) { - $this->markTestSkipped('fosuser_registration is not enabled.'); - - return; - } - $client->getContainer()->get(Config::class)->set('api_user_registration', 1); $client->request('GET', '/api/info'); diff --git a/tests/Controller/SecurityControllerTest.php b/tests/Controller/SecurityControllerTest.php index 3ff4c57bf..0de59a668 100644 --- a/tests/Controller/SecurityControllerTest.php +++ b/tests/Controller/SecurityControllerTest.php @@ -85,13 +85,6 @@ class SecurityControllerTest extends WallabagTestCase public function testEnabledRegistration() { $client = $this->getTestClient(); - - if (!$client->getContainer()->getParameter('fosuser_registration')) { - $this->markTestSkipped('fosuser_registration is not enabled.'); - - return; - } - $client->followRedirects(); $client->request('GET', '/register'); $this->assertStringContainsString('registration.submit', $client->getResponse()->getContent()); From efbc8e795954581aefce14c8837bc75a53f580e5 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Tue, 18 Feb 2025 01:11:01 +0100 Subject: [PATCH 17/18] Add deprecation notice about parameters.yml file --- app/AppKernel.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/AppKernel.php b/app/AppKernel.php index a4f2c1d26..d9d90b0c9 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -69,6 +69,8 @@ class AppKernel extends Kernel { if (file_exists($this->getProjectDir() . '/app/config/parameters.yml')) { $loader->load($this->getProjectDir() . '/app/config/parameters.yml'); + + @trigger_error('The "app/config/parameters.yml" file is deprecated and will not be supported in a future version. Move your configuration to environment variables and remove the file.', \E_USER_DEPRECATED); } $loader->load($this->getProjectDir() . '/app/config/config_' . $this->getEnvironment() . '.yml'); From 28224fe54385ed52b8d0f2990e366c300209cf4c Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Tue, 18 Feb 2025 01:30:13 +0100 Subject: [PATCH 18/18] Add PHPStan bootstrap file to load .env file --- phpstan.neon | 2 ++ tests/phpstan-bootstrap.php | 7 +++++++ 2 files changed, 9 insertions(+) create mode 100644 tests/phpstan-bootstrap.php diff --git a/phpstan.neon b/phpstan.neon index ae2046019..36be686e6 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,6 +6,8 @@ parameters: paths: - src - tests + bootstrapFiles: + - tests/phpstan-bootstrap.php symfony: container_xml_path: %rootDir%/../../../var/cache/dev/AppKernelDevDebugContainer.xml diff --git a/tests/phpstan-bootstrap.php b/tests/phpstan-bootstrap.php new file mode 100644 index 000000000..7336a19b1 --- /dev/null +++ b/tests/phpstan-bootstrap.php @@ -0,0 +1,7 @@ +bootEnv(dirname(__DIR__) . '/.env');