From cebb1f27f5a6f86e55dab027d6330d0739dc52aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Klabbers?= Date: Tue, 31 Dec 2024 17:17:21 +0100 Subject: [PATCH 1/5] wip --- .../core/src/Admin/AdminServiceProvider.php | 1 + .../Middleware/GatherDebugInformation.php | 43 +++++++++ .../Foundation/ApplicationInfoProvider.php | 17 ++-- .../src/Foundation/Console/InfoCommand.php | 89 ++----------------- .../Info/Concerns/PackageVersionFromPath.php | 32 +++++++ .../Foundation/Info/Renderer/CliRenderer.php | 46 ++++++++++ .../src/Foundation/Info/RendererInterface.php | 17 ++++ framework/core/src/Foundation/Info/Report.php | 37 ++++++++ .../Foundation/Info/Section/CoreVersion.php | 21 +++++ .../src/Foundation/Info/Section/Debug.php | 26 ++++++ .../Info/Section/EnabledExtensions.php | 33 +++++++ .../src/Foundation/Info/Section/Features.php | 59 ++++++++++++ .../core/src/Foundation/Info/Section/PHP.php | 27 ++++++ .../src/Foundation/Info/SectionInterface.php | 8 ++ 14 files changed, 369 insertions(+), 87 deletions(-) create mode 100644 framework/core/src/Admin/Middleware/GatherDebugInformation.php create mode 100644 framework/core/src/Foundation/Info/Concerns/PackageVersionFromPath.php create mode 100644 framework/core/src/Foundation/Info/Renderer/CliRenderer.php create mode 100644 framework/core/src/Foundation/Info/RendererInterface.php create mode 100644 framework/core/src/Foundation/Info/Report.php create mode 100644 framework/core/src/Foundation/Info/Section/CoreVersion.php create mode 100644 framework/core/src/Foundation/Info/Section/Debug.php create mode 100644 framework/core/src/Foundation/Info/Section/EnabledExtensions.php create mode 100644 framework/core/src/Foundation/Info/Section/Features.php create mode 100644 framework/core/src/Foundation/Info/Section/PHP.php create mode 100644 framework/core/src/Foundation/Info/SectionInterface.php diff --git a/framework/core/src/Admin/AdminServiceProvider.php b/framework/core/src/Admin/AdminServiceProvider.php index 92f187a579..7181baec0b 100644 --- a/framework/core/src/Admin/AdminServiceProvider.php +++ b/framework/core/src/Admin/AdminServiceProvider.php @@ -63,6 +63,7 @@ public function register(): void HttpMiddleware\ReferrerPolicyHeader::class, HttpMiddleware\ContentTypeOptionsHeader::class, Middleware\DisableBrowserCache::class, + Middleware\GatherDebugInformation::class, ]; }); diff --git a/framework/core/src/Admin/Middleware/GatherDebugInformation.php b/framework/core/src/Admin/Middleware/GatherDebugInformation.php new file mode 100644 index 0000000000..c6329d7ee4 --- /dev/null +++ b/framework/core/src/Admin/Middleware/GatherDebugInformation.php @@ -0,0 +1,43 @@ +settings->get('core.debug.web_user'); + $currentUser = get_current_user(); + if ($user !== $currentUser) { + $this->settings->set( + "core.web_user", + $currentUser + ); + } + + // Read the opcache situation, this is only visible in web. + $opcache = $this->settings->get('core.debug.opcache_enabled'); + $opcacheStatus = function_exists('opcache_get_configuration') + && opcache_get_configuration() !== false; + if ($opcache !== $opcacheStatus) { + $this->settings->set( + 'core.debug.opcache_enabled', + $opcacheStatus + ); + } + + return $handler->handle($request); + } +} diff --git a/framework/core/src/Foundation/ApplicationInfoProvider.php b/framework/core/src/Foundation/ApplicationInfoProvider.php index 7bdbec5085..8f2b38facc 100644 --- a/framework/core/src/Foundation/ApplicationInfoProvider.php +++ b/framework/core/src/Foundation/ApplicationInfoProvider.php @@ -40,18 +40,21 @@ public function scheduledTasksRegistered(): bool return count($this->schedule->events()) > 0; } - public function getSchedulerStatus(): string + public function getSchedulerStatus(bool $translated = true): string { $status = $this->settings->get('schedule.last_run'); - if (! $status) { - return $this->translator->trans('core.admin.dashboard.status.scheduler.never-run'); + $key = match(true) { + ! $status => 'never-run', + Carbon::parse($status) > Carbon::now()->subMinutes(5) => 'active', + default => 'inactive' + }; + + if ($translated) { + return $this->translator->trans("core.admin.dashboard.status.scheduler.$key"); } - // If the schedule has not run in the last 5 minutes, mark it as inactive. - return Carbon::parse($status) > Carbon::now()->subMinutes(5) - ? $this->translator->trans('core.admin.dashboard.status.scheduler.active') - : $this->translator->trans('core.admin.dashboard.status.scheduler.inactive'); + return $key; } public function identifyQueueDriver(): string diff --git a/framework/core/src/Foundation/Console/InfoCommand.php b/framework/core/src/Foundation/Console/InfoCommand.php index 06b9c6e791..35c6d1cb57 100644 --- a/framework/core/src/Foundation/Console/InfoCommand.php +++ b/framework/core/src/Foundation/Console/InfoCommand.php @@ -14,7 +14,10 @@ use Flarum\Foundation\Application; use Flarum\Foundation\ApplicationInfoProvider; use Flarum\Foundation\Config; +use Flarum\Foundation\Info\Renderer\CliRenderer; +use Flarum\Foundation\Info\Report; use Flarum\Settings\SettingsRepositoryInterface; +use Illuminate\Contracts\Container\Container; use Illuminate\Database\ConnectionInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\Table; @@ -23,11 +26,7 @@ class InfoCommand extends AbstractCommand { public function __construct( - protected ExtensionManager $extensions, - protected Config $config, - protected SettingsRepositoryInterface $settings, - protected ConnectionInterface $db, - protected ApplicationInfoProvider $appInfo + protected Container $container ) { parent::__construct(); } @@ -41,83 +40,13 @@ protected function configure(): void protected function fire(): int { - $coreVersion = $this->findPackageVersion(__DIR__.'/../../../', Application::VERSION); - $this->output->writeln("Flarum core: $coreVersion"); + $report = new Report( + new CliRenderer($this->output), + $this->container + ); - $this->output->writeln('PHP version: '.$this->appInfo->identifyPHPVersion()); - $this->output->writeln(''.$this->appInfo->identifyDatabaseDriver().' version: '.$this->appInfo->identifyDatabaseVersion()); - - $phpExtensions = implode(', ', get_loaded_extensions()); - $this->output->writeln("Loaded extensions: $phpExtensions"); - - $this->getExtensionTable()->render(); - - $this->output->writeln('Base URL: '.$this->config->url()); - $this->output->writeln('Installation path: '.getcwd()); - $this->output->writeln('Queue driver: '.$this->appInfo->identifyQueueDriver()); - $this->output->writeln('Session driver: '.$this->appInfo->identifySessionDriver()); - - if ($this->appInfo->scheduledTasksRegistered()) { - $this->output->writeln('Scheduler status: '.$this->appInfo->getSchedulerStatus()); - } - - $this->output->writeln('Mail driver: '.$this->settings->get('mail_driver', 'unknown')); - $this->output->writeln('Debug mode: '.($this->config->inDebugMode() ? 'ON' : 'off')); - - if ($this->config->inDebugMode()) { - $this->output->writeln(''); - $this->error( - "Don't forget to turn off debug mode! It should never be turned on in a production system." - ); - } + $report->render(); return Command::SUCCESS; } - - private function getExtensionTable(): Table - { - $table = (new Table($this->output)) - ->setHeaders([ - ['Flarum Extensions'], - ['ID', 'Version', 'Commit'] - ])->setStyle( - (new TableStyle)->setCellHeaderFormat('%s') - ); - - foreach ($this->extensions->getEnabledExtensions() as $extension) { - $table->addRow([ - $extension->getId(), - $extension->getVersion(), - $this->findPackageVersion($extension->getPath()) - ]); - } - - return $table; - } - - /** - * Try to detect a package's exact version. - * - * If the package seems to be a Git version, we extract the currently - * checked out commit using the command line. - */ - private function findPackageVersion(string $path, ?string $fallback = null): ?string - { - if (file_exists("$path/.git")) { - $cwd = getcwd(); - chdir($path); - - $output = []; - $status = null; - exec('git rev-parse HEAD 2>&1', $output, $status); - - chdir($cwd); - - if ($status == 0) { - return isset($fallback) ? "$fallback ($output[0])" : $output[0]; - } - } - - return $fallback; - } } diff --git a/framework/core/src/Foundation/Info/Concerns/PackageVersionFromPath.php b/framework/core/src/Foundation/Info/Concerns/PackageVersionFromPath.php new file mode 100644 index 0000000000..04418f73ef --- /dev/null +++ b/framework/core/src/Foundation/Info/Concerns/PackageVersionFromPath.php @@ -0,0 +1,32 @@ +&1', $output, $status); + + chdir($cwd); + + if ($status == 0) { + return isset($fallback) ? "$fallback ($output[0])" : $output[0]; + } + } + + return $fallback; + } +} diff --git a/framework/core/src/Foundation/Info/Renderer/CliRenderer.php b/framework/core/src/Foundation/Info/Renderer/CliRenderer.php new file mode 100644 index 0000000000..c622a44113 --- /dev/null +++ b/framework/core/src/Foundation/Info/Renderer/CliRenderer.php @@ -0,0 +1,46 @@ +output->writeln("$title"); + } + + public function keyValue(string $key, mixed $value): void + { + $this->output->writeln("$key: $value"); + } + + public function table(array $headers, array $rows): void + { + $table = (new Table($this->output)) + ->setHeaders($headers)->setStyle( + (new TableStyle)->setCellHeaderFormat('%s') + ); + + foreach ($rows as $row) { + $table->addRow($row); + } + + $table->render(); + } + + public function open(): void + { + } + + public function close(): void + { + } +} diff --git a/framework/core/src/Foundation/Info/RendererInterface.php b/framework/core/src/Foundation/Info/RendererInterface.php new file mode 100644 index 0000000000..b0aee439b3 --- /dev/null +++ b/framework/core/src/Foundation/Info/RendererInterface.php @@ -0,0 +1,17 @@ +sections; + + $this->renderer->open(); + + foreach($sections as &$section) { + $section = $this->container->make($section); + + $section($this->renderer); + } + + $this->renderer->close(); + } +} diff --git a/framework/core/src/Foundation/Info/Section/CoreVersion.php b/framework/core/src/Foundation/Info/Section/CoreVersion.php new file mode 100644 index 0000000000..c8e2dad40c --- /dev/null +++ b/framework/core/src/Foundation/Info/Section/CoreVersion.php @@ -0,0 +1,21 @@ +keyValue( + 'Flarum Core', + $this->findPackageVersion(__DIR__.'/../../../../', Application::VERSION) + ); + } +} diff --git a/framework/core/src/Foundation/Info/Section/Debug.php b/framework/core/src/Foundation/Info/Section/Debug.php new file mode 100644 index 0000000000..51cadd617b --- /dev/null +++ b/framework/core/src/Foundation/Info/Section/Debug.php @@ -0,0 +1,26 @@ +keyValue( + 'Debug mode', + $this->config->inDebugMode() ? 'on' : 'off' + ); + + if ($this->config->inDebugMode()) { + $renderer->heading("Debug mode should not be enabled in production; this will cause javascript and stylesheets to be recompiled on each visit."); + } + } +} diff --git a/framework/core/src/Foundation/Info/Section/EnabledExtensions.php b/framework/core/src/Foundation/Info/Section/EnabledExtensions.php new file mode 100644 index 0000000000..2f04e6a7cd --- /dev/null +++ b/framework/core/src/Foundation/Info/Section/EnabledExtensions.php @@ -0,0 +1,33 @@ +extensions->getEnabledExtensions()) + ->map(fn (Extension $extension) => [ + $extension->getId(), + $this->findPackageVersion($extension->getPath(), $extension->getVersion()) + ]) + ->toArray(); + + $renderer->table([ + ['Flarum Extensions'], + ['ID', 'Version'] + ], $rows); + } +} diff --git a/framework/core/src/Foundation/Info/Section/Features.php b/framework/core/src/Foundation/Info/Section/Features.php new file mode 100644 index 0000000000..e4f1d3dc5a --- /dev/null +++ b/framework/core/src/Foundation/Info/Section/Features.php @@ -0,0 +1,59 @@ +keyValue( + 'Scheduler required', + $this->appInfo->scheduledTasksRegistered() ? 'yes' : 'no' + ); + + $renderer->keyValue( + 'Scheduler status', + $this->appInfo->getSchedulerStatus(translated: false) + ); + + $renderer->keyValue( + 'Queue driver', + $this->appInfo->identifyQueueDriver() + ); + + $renderer->keyValue( + 'Session driver', + $this->appInfo->identifySessionDriver() + ); + + $renderer->keyValue( + 'Mail driver', + $this->mail() + ); + } + + protected function mail() + { + $driver = $this->container->make('mail.driver'); + $configured = $this->container->make('flarum.mail.configured_driver'); + + if ($driver instanceof NullDriver) { + $configured .= " (not active)"; + } + + return $configured; + } +} diff --git a/framework/core/src/Foundation/Info/Section/PHP.php b/framework/core/src/Foundation/Info/Section/PHP.php new file mode 100644 index 0000000000..974fc7e404 --- /dev/null +++ b/framework/core/src/Foundation/Info/Section/PHP.php @@ -0,0 +1,27 @@ +keyValue( + 'PHP version', + $this->appInfo->identifyPHPVersion() + ); + + $renderer->keyValue( + 'PHP extensions', + implode(', ', get_loaded_extensions()) + ); + } +} diff --git a/framework/core/src/Foundation/Info/SectionInterface.php b/framework/core/src/Foundation/Info/SectionInterface.php new file mode 100644 index 0000000000..7bb14db3ad --- /dev/null +++ b/framework/core/src/Foundation/Info/SectionInterface.php @@ -0,0 +1,8 @@ + Date: Tue, 31 Dec 2024 16:18:03 +0000 Subject: [PATCH 2/5] Apply fixes from StyleCI --- .../src/Admin/Middleware/GatherDebugInformation.php | 9 ++++++++- .../core/src/Foundation/ApplicationInfoProvider.php | 2 +- .../core/src/Foundation/Console/InfoCommand.php | 8 -------- .../Info/Concerns/PackageVersionFromPath.php | 7 +++++++ .../src/Foundation/Info/Renderer/CliRenderer.php | 10 +++++++++- .../core/src/Foundation/Info/RendererInterface.php | 8 +++++++- framework/core/src/Foundation/Info/Report.php | 13 ++++++++++--- .../src/Foundation/Info/Section/CoreVersion.php | 7 +++++++ .../core/src/Foundation/Info/Section/Debug.php | 9 ++++++++- .../Foundation/Info/Section/EnabledExtensions.php | 7 +++++++ .../core/src/Foundation/Info/Section/Features.php | 12 +++++++++--- framework/core/src/Foundation/Info/Section/PHP.php | 7 +++++++ .../core/src/Foundation/Info/SectionInterface.php | 7 +++++++ 13 files changed, 87 insertions(+), 19 deletions(-) diff --git a/framework/core/src/Admin/Middleware/GatherDebugInformation.php b/framework/core/src/Admin/Middleware/GatherDebugInformation.php index c6329d7ee4..ac5fa9de8d 100644 --- a/framework/core/src/Admin/Middleware/GatherDebugInformation.php +++ b/framework/core/src/Admin/Middleware/GatherDebugInformation.php @@ -1,5 +1,12 @@ settings->set( - "core.web_user", + 'core.web_user', $currentUser ); } diff --git a/framework/core/src/Foundation/ApplicationInfoProvider.php b/framework/core/src/Foundation/ApplicationInfoProvider.php index 8f2b38facc..764ea0e098 100644 --- a/framework/core/src/Foundation/ApplicationInfoProvider.php +++ b/framework/core/src/Foundation/ApplicationInfoProvider.php @@ -44,7 +44,7 @@ public function getSchedulerStatus(bool $translated = true): string { $status = $this->settings->get('schedule.last_run'); - $key = match(true) { + $key = match (true) { ! $status => 'never-run', Carbon::parse($status) > Carbon::now()->subMinutes(5) => 'active', default => 'inactive' diff --git a/framework/core/src/Foundation/Console/InfoCommand.php b/framework/core/src/Foundation/Console/InfoCommand.php index 35c6d1cb57..d26f1a2a68 100644 --- a/framework/core/src/Foundation/Console/InfoCommand.php +++ b/framework/core/src/Foundation/Console/InfoCommand.php @@ -10,18 +10,10 @@ namespace Flarum\Foundation\Console; use Flarum\Console\AbstractCommand; -use Flarum\Extension\ExtensionManager; -use Flarum\Foundation\Application; -use Flarum\Foundation\ApplicationInfoProvider; -use Flarum\Foundation\Config; use Flarum\Foundation\Info\Renderer\CliRenderer; use Flarum\Foundation\Info\Report; -use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Contracts\Container\Container; -use Illuminate\Database\ConnectionInterface; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Helper\Table; -use Symfony\Component\Console\Helper\TableStyle; class InfoCommand extends AbstractCommand { diff --git a/framework/core/src/Foundation/Info/Concerns/PackageVersionFromPath.php b/framework/core/src/Foundation/Info/Concerns/PackageVersionFromPath.php index 04418f73ef..bc61113d36 100644 --- a/framework/core/src/Foundation/Info/Concerns/PackageVersionFromPath.php +++ b/framework/core/src/Foundation/Info/Concerns/PackageVersionFromPath.php @@ -1,5 +1,12 @@ renderer->open(); - foreach($sections as &$section) { + foreach ($sections as &$section) { $section = $this->container->make($section); $section($this->renderer); diff --git a/framework/core/src/Foundation/Info/Section/CoreVersion.php b/framework/core/src/Foundation/Info/Section/CoreVersion.php index c8e2dad40c..0c9b5b6925 100644 --- a/framework/core/src/Foundation/Info/Section/CoreVersion.php +++ b/framework/core/src/Foundation/Info/Section/CoreVersion.php @@ -1,5 +1,12 @@ config->inDebugMode()) { - $renderer->heading("Debug mode should not be enabled in production; this will cause javascript and stylesheets to be recompiled on each visit."); + $renderer->heading('Debug mode should not be enabled in production; this will cause javascript and stylesheets to be recompiled on each visit.'); } } } diff --git a/framework/core/src/Foundation/Info/Section/EnabledExtensions.php b/framework/core/src/Foundation/Info/Section/EnabledExtensions.php index 2f04e6a7cd..e912fc12af 100644 --- a/framework/core/src/Foundation/Info/Section/EnabledExtensions.php +++ b/framework/core/src/Foundation/Info/Section/EnabledExtensions.php @@ -1,5 +1,12 @@ container->make('flarum.mail.configured_driver'); if ($driver instanceof NullDriver) { - $configured .= " (not active)"; + $configured .= ' (not active)'; } return $configured; diff --git a/framework/core/src/Foundation/Info/Section/PHP.php b/framework/core/src/Foundation/Info/Section/PHP.php index 974fc7e404..718d7388fe 100644 --- a/framework/core/src/Foundation/Info/Section/PHP.php +++ b/framework/core/src/Foundation/Info/Section/PHP.php @@ -1,5 +1,12 @@ Date: Tue, 31 Dec 2024 17:57:29 +0100 Subject: [PATCH 3/5] additions --- .../Middleware/GatherDebugInformation.php | 9 ++++--- framework/core/src/Foundation/Info/Report.php | 2 ++ .../src/Foundation/Info/Section/Database.php | 27 +++++++++++++++++++ .../src/Foundation/Info/Section/Features.php | 4 ++- .../core/src/Foundation/Info/Section/PHP.php | 12 +++++++-- .../src/Foundation/Info/Section/Webserver.php | 22 +++++++++++++++ 6 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 framework/core/src/Foundation/Info/Section/Database.php create mode 100644 framework/core/src/Foundation/Info/Section/Webserver.php diff --git a/framework/core/src/Admin/Middleware/GatherDebugInformation.php b/framework/core/src/Admin/Middleware/GatherDebugInformation.php index ac5fa9de8d..2e4dc518b4 100644 --- a/framework/core/src/Admin/Middleware/GatherDebugInformation.php +++ b/framework/core/src/Admin/Middleware/GatherDebugInformation.php @@ -29,18 +29,19 @@ public function process(Request $request, Handler $handler): Response $currentUser = get_current_user(); if ($user !== $currentUser) { $this->settings->set( - 'core.web_user', + "core.debug.web_user", $currentUser ); } // Read the opcache situation, this is only visible in web. - $opcache = $this->settings->get('core.debug.opcache_enabled'); + // Cli has opcache disabled by default. + $opcache = $this->settings->get('core.debug.opcache'); $opcacheStatus = function_exists('opcache_get_configuration') - && opcache_get_configuration() !== false; + && opcache_get_configuration() !== false ? 'on' : 'off'; if ($opcache !== $opcacheStatus) { $this->settings->set( - 'core.debug.opcache_enabled', + 'core.debug.opcache', $opcacheStatus ); } diff --git a/framework/core/src/Foundation/Info/Report.php b/framework/core/src/Foundation/Info/Report.php index 1ca8147e3d..37f0fa8811 100644 --- a/framework/core/src/Foundation/Info/Report.php +++ b/framework/core/src/Foundation/Info/Report.php @@ -16,8 +16,10 @@ class Report protected array $sections = [ Section\CoreVersion::class, Section\PHP::class, + Section\Database::class, Section\EnabledExtensions::class, Section\Features::class, + Section\Webserver::class, Section\Debug::class, ]; diff --git a/framework/core/src/Foundation/Info/Section/Database.php b/framework/core/src/Foundation/Info/Section/Database.php new file mode 100644 index 0000000000..0d6fa39181 --- /dev/null +++ b/framework/core/src/Foundation/Info/Section/Database.php @@ -0,0 +1,27 @@ +keyValue( + 'Database driver', + $this->appInfo->identifyDatabaseDriver() + ); + + $renderer->keyValue( + 'Database version', + $this->appInfo->identifyDatabaseVersion() + ); + } +} diff --git a/framework/core/src/Foundation/Info/Section/Features.php b/framework/core/src/Foundation/Info/Section/Features.php index b5fdd7d6f4..6034f875d9 100644 --- a/framework/core/src/Foundation/Info/Section/Features.php +++ b/framework/core/src/Foundation/Info/Section/Features.php @@ -13,12 +13,14 @@ use Flarum\Foundation\Info\RendererInterface; use Flarum\Foundation\Info\SectionInterface; use Flarum\Mail\NullDriver; +use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Contracts\Container\Container; class Features implements SectionInterface { public function __construct( protected ApplicationInfoProvider $appInfo, + protected SettingsRepositoryInterface $settings, protected Container $container ) { } @@ -54,7 +56,7 @@ public function __invoke(RendererInterface $renderer): void protected function mail() { $driver = $this->container->make('mail.driver'); - $configured = $this->container->make('flarum.mail.configured_driver'); + $configured = $this->settings->get('mail_driver'); if ($driver instanceof NullDriver) { $configured .= ' (not active)'; diff --git a/framework/core/src/Foundation/Info/Section/PHP.php b/framework/core/src/Foundation/Info/Section/PHP.php index 718d7388fe..05928ee7ec 100644 --- a/framework/core/src/Foundation/Info/Section/PHP.php +++ b/framework/core/src/Foundation/Info/Section/PHP.php @@ -12,11 +12,14 @@ use Flarum\Foundation\ApplicationInfoProvider; use Flarum\Foundation\Info\RendererInterface; use Flarum\Foundation\Info\SectionInterface; +use Flarum\Settings\SettingsRepositoryInterface; class PHP implements SectionInterface { - public function __construct(protected ApplicationInfoProvider $appInfo) - { + public function __construct( + protected ApplicationInfoProvider $appInfo, + protected SettingsRepositoryInterface $settings + ) { } public function __invoke(RendererInterface $renderer): void @@ -30,5 +33,10 @@ public function __invoke(RendererInterface $renderer): void 'PHP extensions', implode(', ', get_loaded_extensions()) ); + + $renderer->keyValue( + 'PHP OpCache', + $this->settings->get('core.debug.opcache') ?? 'visit admin to identify' + ); } } diff --git a/framework/core/src/Foundation/Info/Section/Webserver.php b/framework/core/src/Foundation/Info/Section/Webserver.php new file mode 100644 index 0000000000..9721978cf2 --- /dev/null +++ b/framework/core/src/Foundation/Info/Section/Webserver.php @@ -0,0 +1,22 @@ +keyValue( + 'Web user', + $this->settings->get('core.debug.web_user') ?? 'visit admin to identify' + ); + } +} From 8dd9455f686f5226e35b23acb583f476ae45470f Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Tue, 31 Dec 2024 16:58:29 +0000 Subject: [PATCH 4/5] Apply fixes from StyleCI --- .../core/src/Admin/Middleware/GatherDebugInformation.php | 2 +- framework/core/src/Foundation/Info/Section/Database.php | 7 +++++++ framework/core/src/Foundation/Info/Section/Webserver.php | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/framework/core/src/Admin/Middleware/GatherDebugInformation.php b/framework/core/src/Admin/Middleware/GatherDebugInformation.php index 2e4dc518b4..39096485e0 100644 --- a/framework/core/src/Admin/Middleware/GatherDebugInformation.php +++ b/framework/core/src/Admin/Middleware/GatherDebugInformation.php @@ -29,7 +29,7 @@ public function process(Request $request, Handler $handler): Response $currentUser = get_current_user(); if ($user !== $currentUser) { $this->settings->set( - "core.debug.web_user", + 'core.debug.web_user', $currentUser ); } diff --git a/framework/core/src/Foundation/Info/Section/Database.php b/framework/core/src/Foundation/Info/Section/Database.php index 0d6fa39181..f2c5fa46f5 100644 --- a/framework/core/src/Foundation/Info/Section/Database.php +++ b/framework/core/src/Foundation/Info/Section/Database.php @@ -1,5 +1,12 @@ Date: Mon, 24 Feb 2025 22:28:31 +0100 Subject: [PATCH 5/5] wip: clean up --- .../Middleware/GatherDebugInformation.php | 31 ++++++++++++++----- .../Foundation/Info/Renderer/CliRenderer.php | 2 +- framework/core/src/Foundation/Info/Report.php | 2 +- .../{Webserver.php => ServiceUsers.php} | 21 ++++++++++--- 4 files changed, 41 insertions(+), 15 deletions(-) rename framework/core/src/Foundation/Info/Section/{Webserver.php => ServiceUsers.php} (53%) diff --git a/framework/core/src/Admin/Middleware/GatherDebugInformation.php b/framework/core/src/Admin/Middleware/GatherDebugInformation.php index 39096485e0..af70266459 100644 --- a/framework/core/src/Admin/Middleware/GatherDebugInformation.php +++ b/framework/core/src/Admin/Middleware/GatherDebugInformation.php @@ -23,29 +23,44 @@ public function __construct(protected SettingsRepositoryInterface $settings) public function process(Request $request, Handler $handler): Response { - // Read current web user, so we can compare that against CLI executions, - // these often cause file permission issues. + $this->upsertWebUser(); + + $this->upsertOpCacheStatus(); + + return $handler->handle($request); + } + + /** + * Read current web user, so we can compare that against CLI executions, + * these often cause file permission issues. + */ + public function upsertWebUser(): void + { $user = $this->settings->get('core.debug.web_user'); $currentUser = get_current_user(); + if ($user !== $currentUser) { $this->settings->set( 'core.debug.web_user', $currentUser ); } + } - // Read the opcache situation, this is only visible in web. - // Cli has opcache disabled by default. + /** + * Read the opcache situation, this is only visible in web. + * Cli has opcache disabled by default. + */ + public function upsertOpCacheStatus(): void + { $opcache = $this->settings->get('core.debug.opcache'); - $opcacheStatus = function_exists('opcache_get_configuration') - && opcache_get_configuration() !== false ? 'on' : 'off'; + $opcacheStatus = function_exists('opcache_get_configuration') && opcache_get_configuration() !== false ? 'on' : 'off'; + if ($opcache !== $opcacheStatus) { $this->settings->set( 'core.debug.opcache', $opcacheStatus ); } - - return $handler->handle($request); } } diff --git a/framework/core/src/Foundation/Info/Renderer/CliRenderer.php b/framework/core/src/Foundation/Info/Renderer/CliRenderer.php index 51108f5b02..1d206027fa 100644 --- a/framework/core/src/Foundation/Info/Renderer/CliRenderer.php +++ b/framework/core/src/Foundation/Info/Renderer/CliRenderer.php @@ -22,7 +22,7 @@ public function __construct(protected OutputInterface $output) public function heading(string $title): void { - $this->output->writeln("$title"); + $this->output->writeln("$title"); } public function keyValue(string $key, mixed $value): void diff --git a/framework/core/src/Foundation/Info/Report.php b/framework/core/src/Foundation/Info/Report.php index 37f0fa8811..25aa527383 100644 --- a/framework/core/src/Foundation/Info/Report.php +++ b/framework/core/src/Foundation/Info/Report.php @@ -19,8 +19,8 @@ class Report Section\Database::class, Section\EnabledExtensions::class, Section\Features::class, - Section\Webserver::class, Section\Debug::class, + Section\ServiceUsers::class, ]; public function __construct( diff --git a/framework/core/src/Foundation/Info/Section/Webserver.php b/framework/core/src/Foundation/Info/Section/ServiceUsers.php similarity index 53% rename from framework/core/src/Foundation/Info/Section/Webserver.php rename to framework/core/src/Foundation/Info/Section/ServiceUsers.php index caa126bf99..dd23d6e889 100644 --- a/framework/core/src/Foundation/Info/Section/Webserver.php +++ b/framework/core/src/Foundation/Info/Section/ServiceUsers.php @@ -13,7 +13,7 @@ use Flarum\Foundation\Info\SectionInterface; use Flarum\Settings\SettingsRepositoryInterface; -class Webserver implements SectionInterface +class ServiceUsers implements SectionInterface { public function __construct(protected SettingsRepositoryInterface $settings) { @@ -21,9 +21,20 @@ public function __construct(protected SettingsRepositoryInterface $settings) public function __invoke(RendererInterface $renderer): void { - $renderer->keyValue( - 'Web user', - $this->settings->get('core.debug.web_user') ?? 'visit admin to identify' - ); + $rows = [ + ['Web user', $this->settings->get('core.debug.web_user') ?? 'visit admin to identify'] + ]; + + if (php_sapi_name() === 'cli') { + $rows[] = [ + 'Current user', + posix_getpwuid(posix_geteuid())['name'] + ]; + } + + $renderer->table([ + ['Service/process users'], + ['Type', 'User'] + ], $rows); } }