1
0
mirror of https://github.com/flarum/core.git synced 2025-08-28 10:30:54 +02:00

Compare commits

..

15 Commits

Author SHA1 Message Date
StyleCI Bot
a286e2a829 Apply fixes from StyleCI 2022-11-21 13:28:11 +00:00
Clark Winkelmann
b015a66456 Enable conditional migrations through when callback 2022-11-21 14:27:44 +01:00
flarum-bot
e5d2b8cad9 Bundled output for commit f5c346f1c7
Includes transpiled JS/TS, and Typescript declaration files (typings).

[skip ci]
2022-11-20 12:08:32 +00:00
Clark Winkelmann
f5c346f1c7 chore: Indicate cross-origin request in generic error message (#3669)
* Indicate cross-origin request in generic error message
* Run javascript format
* Move text to beginning of error message
* Update framework/core/locale/core.yml

Co-authored-by: David Wheatley <hi@davwheat.dev>
2022-11-20 13:02:41 +01:00
flarum-bot
5bb0593bad Bundled output for commit 47d2053766
Includes transpiled JS/TS, and Typescript declaration files (typings).

[skip ci]
2022-11-19 22:30:32 +00:00
Ian Morland
47d2053766 feat: expose queue driver, schedule status (#3593)
* feat: expose queue driver, schedule status

* Apply fixes from StyleCI

* docblock

* fix inheritdoc

* Add info link for scheduler setup

* Remove unsed import

* fix: phpstan error

* Only show scheduler status when jobs are registered

* Apply fixes from StyleCI

* add ItemList priorities

* Add translations

* Include schedule status in info console cmd

* Apply fixes from StyleCI

* Move identifyX logic into shared 'ApplicationInfoProvider'

* Apply fixes from StyleCI

* uniform data layout

* inject queue

Co-authored-by: StyleCI Bot <bot@styleci.io>
2022-11-19 22:23:04 +00:00
Sami Mazouz
e0b9dcfbcd Merge branch 'release/v1.6.2'
# Conflicts:
#	framework/core/js/dist/admin.js
#	framework/core/js/dist/admin.js.map
#	framework/core/js/dist/forum.js
#	framework/core/js/dist/forum.js.map
#	framework/core/src/Foundation/Application.php
2022-11-18 23:24:43 +01:00
flarum-bot
543c5f2a2e Bundled output for commit 690de9ce0f
Includes transpiled JS/TS, and Typescript declaration files (typings).

[skip ci]
2022-11-18 21:16:57 +00:00
Sami Mazouz
690de9ce0f fix: evaluated page title content (#3684)
* fix: evaluated page title content
* chore: add comment
* chore: use DOMParser instead
* fix: use `innerHTML` for the actual value

Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
Co-authored-by: David Wheatley <hi@davwheat.dev>
2022-11-18 22:09:22 +01:00
Clark Winkelmann
50253a2eb8 fix: typo in Formatter extender docblock (#3676) 2022-11-17 15:47:09 +01:00
flarum-bot
92473c0967 Bundled output for commit 361234205c
Includes transpiled JS/TS, and Typescript declaration files (typings).

[skip ci]
2022-11-17 09:23:09 +00:00
Rafael Horvat
361234205c fix: add missing states exports to compat.ts (#3683) 2022-11-17 09:17:16 +00:00
flarum-bot
54798aaa47 Bundled output for commit fe5d543864
Includes transpiled JS/TS, and Typescript declaration files (typings).

[skip ci]
2022-11-16 23:26:37 +00:00
David Wheatley
fe5d543864 fix: post dropdown opens all dropdowns in .Post-actions (#3675) 2022-11-16 23:21:57 +00:00
Ian Morland
2517bc0f70 chore: set flarum version to 1.7.0 for dev 2022-11-16 20:59:51 +00:00
22 changed files with 393 additions and 137 deletions

View File

@@ -126,6 +126,9 @@ declare const _default: {
'helpers/listItems': typeof import("../common/helpers/listItems").default;
'resolvers/DefaultResolver': typeof import("../common/resolvers/DefaultResolver").default;
'states/PaginatedListState': typeof import("../common/states/PaginatedListState").default;
'states/AlertManagerState': typeof import("../common/states/AlertManagerState").default;
'states/ModalManagerState': typeof import("../common/states/ModalManagerState").default;
'states/PageState': typeof import("../common/states/PageState").default;
} & {
'utils/saveSettings': typeof saveSettings;
'utils/ExtensionData': typeof ExtensionData;

View File

@@ -232,6 +232,15 @@ export default class Application {
* By default, show an error alert, and log the error to the console.
*/
protected requestErrorCatch<ResponseType>(error: RequestError, customErrorHandler: FlarumRequestOptions<ResponseType>['errorHandler']): Promise<never>;
/**
* Used to modify the error message shown on the page to help troubleshooting.
* While not certain, a failing cross-origin request likely indicates a missing redirect to Flarum canonical URL.
* Because XHR errors do not expose CORS information, we can only compare the requested URL origin to the page origin.
*
* @param error
* @protected
*/
protected requestWasCrossOrigin(error: RequestError): boolean;
protected requestErrorDefaultHandler(e: unknown, isDebug: boolean, formattedErrors: string[]): void;
private showDebug;
/**

View File

@@ -79,6 +79,9 @@ import Fragment from './Fragment';
import DefaultResolver from './resolvers/DefaultResolver';
import PaginatedListState from './states/PaginatedListState';
import isObject from './utils/isObject';
import AlertManagerState from './states/AlertManagerState';
import ModalManagerState from './states/ModalManagerState';
import PageState from './states/PageState';
declare const _default: {
extend: any;
Session: typeof Session;
@@ -172,5 +175,8 @@ declare const _default: {
'helpers/listItems': typeof listItems;
'resolvers/DefaultResolver': typeof DefaultResolver;
'states/PaginatedListState': typeof PaginatedListState;
'states/AlertManagerState': typeof AlertManagerState;
'states/ModalManagerState': typeof ModalManagerState;
'states/PageState': typeof PageState;
};
export default _default;

View File

@@ -162,6 +162,9 @@ declare const _default: {
'helpers/listItems': typeof import("../common/helpers/listItems").default;
'resolvers/DefaultResolver': typeof import("../common/resolvers/DefaultResolver").default;
'states/PaginatedListState': typeof import("../common/states/PaginatedListState").default;
'states/AlertManagerState': typeof import("../common/states/AlertManagerState").default;
'states/ModalManagerState': typeof import("../common/states/ModalManagerState").default;
'states/PageState': typeof import("../common/states/PageState").default;
} & {
'utils/PostControls': {
controls(post: import("../common/models/Post").default, context: import("../common/Component").default<any, any>): import("../common/utils/ItemList").default<import("mithril").Children>;

2
framework/core/js/dist/admin.js generated vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
framework/core/js/dist/forum.js generated vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -5,6 +5,7 @@ import ItemList from '../../common/utils/ItemList';
import Dropdown from '../../common/components/Dropdown';
import Button from '../../common/components/Button';
import LoadingModal from './LoadingModal';
import LinkButton from '../../common/components/LinkButton';
export default class StatusWidget extends DashboardWidget {
className() {
@@ -30,9 +31,26 @@ export default class StatusWidget extends DashboardWidget {
</Dropdown>
);
items.add('version-flarum', [<strong>Flarum</strong>, <br />, app.forum.attribute('version')]);
items.add('version-php', [<strong>PHP</strong>, <br />, app.data.phpVersion]);
items.add('version-mysql', [<strong>MySQL</strong>, <br />, app.data.mysqlVersion]);
items.add('version-flarum', [<strong>Flarum</strong>, <br />, app.forum.attribute('version')], 100);
items.add('version-php', [<strong>PHP</strong>, <br />, app.data.phpVersion], 90);
items.add('version-mysql', [<strong>MySQL</strong>, <br />, app.data.mysqlVersion], 80);
if (app.data.schedulerStatus) {
items.add(
'schedule-status',
[
<span>
<strong>Scheduler</strong>{' '}
<LinkButton href="https://discuss.flarum.org/d/24118" external={true} target="_blank" icon="fas fa-info-circle" />
</span>,
<br />,
app.data.schedulerStatus,
],
70
);
}
items.add('queue-driver', [<strong>Queue Driver</strong>, <br />, app.data.queueDriver], 60);
items.add('session-driver', [<strong>Session Driver</strong>, <br />, app.data.sessionDriver], 50);
return items;
}

View File

@@ -553,7 +553,11 @@ export default class Application {
break;
default:
content = app.translator.trans('core.lib.error.generic_message');
if (this.requestWasCrossOrigin(error)) {
content = app.translator.trans('core.lib.error.generic_cross_origin_message');
} else {
content = app.translator.trans('core.lib.error.generic_message');
}
}
const isDebug: boolean = app.forum.attribute('debug');
@@ -577,6 +581,18 @@ export default class Application {
return Promise.reject(error);
}
/**
* Used to modify the error message shown on the page to help troubleshooting.
* While not certain, a failing cross-origin request likely indicates a missing redirect to Flarum canonical URL.
* Because XHR errors do not expose CORS information, we can only compare the requested URL origin to the page origin.
*
* @param error
* @protected
*/
protected requestWasCrossOrigin(error: RequestError): boolean {
return new URL(error.options.url, document.baseURI).origin !== window.location.origin;
}
protected requestErrorDefaultHandler(e: unknown, isDebug: boolean, formattedErrors: string[]): void {
if (e instanceof RequestError) {
if (isDebug && e.xhr) {

View File

@@ -84,6 +84,9 @@ import Fragment from './Fragment';
import DefaultResolver from './resolvers/DefaultResolver';
import PaginatedListState from './states/PaginatedListState';
import isObject from './utils/isObject';
import AlertManagerState from './states/AlertManagerState';
import ModalManagerState from './states/ModalManagerState';
import PageState from './states/PageState';
export default {
extend: extend,
@@ -171,4 +174,7 @@ export default {
'helpers/listItems': listItems,
'resolvers/DefaultResolver': DefaultResolver,
'states/PaginatedListState': PaginatedListState,
'states/AlertManagerState': AlertManagerState,
'states/ModalManagerState': ModalManagerState,
'states/PageState': PageState,
};

View File

@@ -97,7 +97,7 @@ export default abstract class Post<CustomAttrs extends IPostAttrs = IPostAttrs>
const $actions = this.$('.Post-actions');
const $controls = this.$('.Post-controls');
$actions.toggleClass('open', $controls.hasClass('open'));
$actions.toggleClass('openWithin', $controls.hasClass('open'));
}
/**

View File

@@ -322,7 +322,7 @@
vertical-align: top;
}
}
.Post:hover &, .Post:focus-within &, &.open {
.Post:hover &, .Post:focus-within &, &.openWithin {
opacity: 1;
}
}

View File

@@ -56,6 +56,11 @@ core:
clear_cache_button: Clear Cache
description: Your forum at a glance.
io_error_message: "Could not write to filesystem. Check your filesystem permissions and try again. Or try running from the command line."
status:
scheduler:
active: Active
inactive: Inactive
never-run: Never run
title: Dashboard
tools_button: Tools
@@ -550,6 +555,7 @@ core:
dependent_extensions_message: "Cannot disable {extension} until the following dependent extensions are disabled: {extensions}"
extension_initialiation_failed_message: "{extension} failed to initialize, check the browser console for further information."
generic_message: "Oops! Something went wrong. Please reload the page and try again."
generic_cross_origin_message: "Oops! Something went wrong during a cross-origin request. Please reload the page and try again."
missing_dependencies_message: "Cannot enable {extension} until the following dependencies are enabled: {extensions}"
not_found_message: The requested resource was not found.
payload_too_large_message: The request payload was too large.

View File

@@ -10,6 +10,7 @@
namespace Flarum\Admin\Content;
use Flarum\Extension\ExtensionManager;
use Flarum\Foundation\ApplicationInfoProvider;
use Flarum\Foundation\Config;
use Flarum\Frontend\Document;
use Flarum\Group\Permission;
@@ -54,6 +55,11 @@ class AdminPayload
*/
protected $config;
/**
* @var ApplicationInfoProvider
*/
protected $appInfo;
/**
* @param Container $container
* @param SettingsRepositoryInterface $settings
@@ -61,6 +67,7 @@ class AdminPayload
* @param ConnectionInterface $db
* @param Dispatcher $events
* @param Config $config
* @param ApplicationInfoProvider $appInfo
*/
public function __construct(
Container $container,
@@ -68,7 +75,8 @@ class AdminPayload
ExtensionManager $extensions,
ConnectionInterface $db,
Dispatcher $events,
Config $config
Config $config,
ApplicationInfoProvider $appInfo
) {
$this->container = $container;
$this->settings = $settings;
@@ -76,6 +84,7 @@ class AdminPayload
$this->db = $db;
$this->events = $events;
$this->config = $config;
$this->appInfo = $appInfo;
}
public function __invoke(Document $document, Request $request)
@@ -95,10 +104,17 @@ class AdminPayload
return array_keys($resourceDrivers);
}, $this->container->make('flarum.http.slugDrivers'));
$document->payload['phpVersion'] = PHP_VERSION;
$document->payload['mysqlVersion'] = $this->db->selectOne('select version() as version')->version;
$document->payload['phpVersion'] = $this->appInfo->identifyPHPVersion();
$document->payload['mysqlVersion'] = $this->appInfo->identifyDatabaseVersion();
$document->payload['debugEnabled'] = Arr::get($this->config, 'debug');
if ($this->appInfo->scheduledTasksRegistered()) {
$document->payload['schedulerStatus'] = $this->appInfo->getSchedulerStatus();
}
$document->payload['queueDriver'] = $this->appInfo->identifyQueueDriver();
$document->payload['sessionDriver'] = $this->appInfo->identifySessionDriver();
/**
* Used in the admin user list. Implemented as this as it matches the API in flarum/statistics.
* If flarum/statistics ext is enabled, it will override this data with its own stats.

View File

@@ -16,12 +16,12 @@ use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Foundation\Console\AssetsPublishCommand;
use Flarum\Foundation\Console\CacheClearCommand;
use Flarum\Foundation\Console\InfoCommand;
use Flarum\Foundation\Console\ScheduleRunCommand;
use Illuminate\Console\Scheduling\CacheEventMutex;
use Illuminate\Console\Scheduling\CacheSchedulingMutex;
use Illuminate\Console\Scheduling\EventMutex;
use Illuminate\Console\Scheduling\Schedule as LaravelSchedule;
use Illuminate\Console\Scheduling\ScheduleListCommand;
use Illuminate\Console\Scheduling\ScheduleRunCommand;
use Illuminate\Console\Scheduling\SchedulingMutex;
use Illuminate\Contracts\Container\Container;

View File

@@ -124,7 +124,22 @@ class Migrator
*/
protected function runUp($path, $file, Extension $extension = null)
{
$this->resolveAndRunClosureMigration($path, $file);
$migration = $this->resolve($path, $file);
// If a "when" callback in defined in a migration array, a falsy return value will cause the migration to skip
if (is_array($migration) && array_key_exists('when', $migration)) {
if (! call_user_func($migration['when'], $this->connection->getSchemaBuilder())) {
$this->note("<info>Skipped:</info> $file");
return;
}
}
try {
$this->runClosureMigration($migration);
} catch (MigrationKeyMissing $exception) {
throw $exception->withFile("$path/$file.php");
}
// Once we have run a migrations class, we will log that it was run in this
// repository so that we don't try to run it next time we do a migration
@@ -165,13 +180,18 @@ class Migrator
*
* @param string $path
* @param string $file
* @param string $path
* @param Extension $extension
* @param Extension|null $extension
* @return void
*/
protected function runDown($path, $file, Extension $extension = null)
{
$this->resolveAndRunClosureMigration($path, $file, 'down');
$migration = $this->resolve($path, $file);
try {
$this->runClosureMigration($migration, 'down');
} catch (MigrationKeyMissing $exception) {
throw $exception->withFile("$path/$file.php");
}
// Once we have successfully run the migration "down" we will remove it from
// the migration repository so it will be considered to have not been run
@@ -197,25 +217,6 @@ class Migrator
}
}
/**
* Resolves and run a migration and assign the filename to the exception if needed.
*
* @param string $path
* @param string $file
* @param string $direction
* @throws MigrationKeyMissing
*/
protected function resolveAndRunClosureMigration(string $path, string $file, string $direction = 'up')
{
$migration = $this->resolve($path, $file);
try {
$this->runClosureMigration($migration, $direction);
} catch (MigrationKeyMissing $exception) {
throw $exception->withFile("$path/$file.php");
}
}
/**
* Get all of the migration files in a given path.
*

View File

@@ -95,7 +95,7 @@ class Formatter implements ExtenderInterface, LifecycleInterface
* @param callable|string $callback
*
* The callback can be a closure or invokable class, and should accept:
* - \s9e\TextFormatter\Rendered $renderer
* - \s9e\TextFormatter\Renderer $renderer
* - mixed $context
* - string $xml: The xml to be rendered.
* - ServerRequestInterface $request. This argument MUST either be nullable, or omitted entirely.

View File

@@ -21,7 +21,7 @@ class Application
*
* @var string
*/
const VERSION = '1.6.2';
const VERSION = '1.7.0-dev';
/**
* The IoC container for the Flarum application.

View File

@@ -0,0 +1,212 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Foundation;
use Carbon\Carbon;
use Flarum\Locale\Translator;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\User\SessionManager;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Contracts\Queue\Queue;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use InvalidArgumentException;
use SessionHandlerInterface;
class ApplicationInfoProvider
{
/**
* @var SettingsRepositoryInterface
*/
protected $settings;
/**
* @var Translator
*/
protected $translator;
/**
* @var Schedule
*/
protected $schedule;
/**
* @var ConnectionInterface
*/
protected $db;
/**
* @var Config
*/
protected $config;
/**
* @var SessionManager
*/
protected $session;
/**
* @var SessionHandlerInterface
*/
protected $sessionHandler;
/**
* @var Queue
*/
protected $queue;
/**
* @param SettingsRepositoryInterface $settings
* @param Translator $translator
* @param Schedule $schedule
* @param ConnectionInterface $db
* @param Config $config
* @param SessionManager $session
* @param SessionHandlerInterface $sessionHandler
* @param Queue $queue
*/
public function __construct(
SettingsRepositoryInterface $settings,
Translator $translator,
Schedule $schedule,
ConnectionInterface $db,
Config $config,
SessionManager $session,
SessionHandlerInterface $sessionHandler,
Queue $queue
) {
$this->settings = $settings;
$this->translator = $translator;
$this->schedule = $schedule;
$this->db = $db;
$this->config = $config;
$this->session = $session;
$this->sessionHandler = $sessionHandler;
$this->queue = $queue;
}
/**
* Identify if any tasks are registered with the scheduler.
*
* @return bool
*/
public function scheduledTasksRegistered(): bool
{
return count($this->schedule->events()) > 0;
}
/**
* Gets the current status of the scheduler.
*
* @return string
*/
public function getSchedulerStatus(): string
{
$status = $this->settings->get('schedule.last_run');
if (! $status) {
return $this->translator->trans('core.admin.dashboard.status.scheduler.never-run');
}
// 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.status.scheduler.inactive');
}
/**
* Identify the queue driver in use.
*
* @return string
*/
public function identifyQueueDriver(): string
{
// Get class name
$queue = get_class($this->queue);
// Drop the namespace
$queue = Str::afterLast($queue, '\\');
// Lowercase the class name
$queue = strtolower($queue);
// Drop everything like queue SyncQueue, RedisQueue
$queue = str_replace('queue', '', $queue);
return $queue;
}
/**
* Identify the version of the database we are connected to.
*
* @return string
*/
public function identifyDatabaseVersion(): string
{
return $this->db->selectOne('select version() as version')->version;
}
/**
* Reports on the session driver in use based on three scenarios:
* 1. If the configured session driver is valid and in use, it will be returned.
* 2. If the configured session driver is invalid, fallback to the default one and mention it.
* 3. If the actual used driver (i.e `session.handler`) is different from the current one (configured or default), mention it.
*/
public function identifySessionDriver(): string
{
/*
* Get the configured driver and fallback to the default one.
*/
$defaultDriver = $this->session->getDefaultDriver();
$configuredDriver = Arr::get($this->config, 'session.driver', $defaultDriver);
$driver = $configuredDriver;
try {
// Try to get the configured driver instance.
// Driver instances are created on demand.
$this->session->driver($configuredDriver);
} catch (InvalidArgumentException $e) {
// An exception is thrown if the configured driver is not a valid driver.
// So we fallback to the default driver.
$driver = $defaultDriver;
}
/*
* Get actual driver name from its class name.
* And compare that to the current configured driver.
*/
// Get class name
$handlerName = get_class($this->sessionHandler);
// Drop the namespace
$handlerName = Str::afterLast($handlerName, '\\');
// Lowercase the class name
$handlerName = strtolower($handlerName);
// Drop everything like sessionhandler FileSessionHandler, DatabaseSessionHandler ..etc
$handlerName = str_replace('sessionhandler', '', $handlerName);
if ($driver !== $handlerName) {
return "$handlerName <comment>(Code override. Configured to <options=bold,underscore>$configuredDriver</>)</comment>";
}
if ($driver !== $configuredDriver) {
return "$driver <comment>(Fallback default driver. Configured to invalid driver <options=bold,underscore>$configuredDriver</>)</comment>";
}
return $driver;
}
/**
* Identifiy the current PHP version.
*
* @return string
*/
public function identifyPHPVersion(): string
{
return PHP_VERSION;
}
}

View File

@@ -12,16 +12,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\Settings\SettingsRepositoryInterface;
use Flarum\User\SessionManager;
use Illuminate\Contracts\Queue\Queue;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use InvalidArgumentException;
use PDO;
use SessionHandlerInterface;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Helper\TableStyle;
@@ -48,36 +42,22 @@ class InfoCommand extends AbstractCommand
protected $db;
/**
* @var Queue
* @var ApplicationInfoProvider
*/
private $queue;
/**
* @var SessionManager
*/
private $session;
/**
* @var SessionHandlerInterface
*/
private $sessionHandler;
private $appInfo;
public function __construct(
ExtensionManager $extensions,
Config $config,
SettingsRepositoryInterface $settings,
ConnectionInterface $db,
Queue $queue,
SessionManager $session,
SessionHandlerInterface $sessionHandler
ApplicationInfoProvider $appInfo
) {
$this->extensions = $extensions;
$this->config = $config;
$this->settings = $settings;
$this->db = $db;
$this->queue = $queue;
$this->session = $session;
$this->sessionHandler = $sessionHandler;
$this->appInfo = $appInfo;
parent::__construct();
}
@@ -98,10 +78,10 @@ class InfoCommand extends AbstractCommand
protected function fire()
{
$coreVersion = $this->findPackageVersion(__DIR__.'/../../../', Application::VERSION);
$this->output->writeln("<info>Flarum core $coreVersion</info>");
$this->output->writeln("<info>Flarum core:</info> $coreVersion");
$this->output->writeln('<info>PHP version:</info> '.PHP_VERSION);
$this->output->writeln('<info>MySQL version:</info> '.$this->identifyDatabaseVersion());
$this->output->writeln('<info>PHP version:</info> '.$this->appInfo->identifyPHPVersion());
$this->output->writeln('<info>MySQL version:</info> '.$this->appInfo->identifyDatabaseVersion());
$phpExtensions = implode(', ', get_loaded_extensions());
$this->output->writeln("<info>Loaded extensions:</info> $phpExtensions");
@@ -110,8 +90,13 @@ class InfoCommand extends AbstractCommand
$this->output->writeln('<info>Base URL:</info> '.$this->config->url());
$this->output->writeln('<info>Installation path:</info> '.getcwd());
$this->output->writeln('<info>Queue driver:</info> '.$this->identifyQueueDriver());
$this->output->writeln('<info>Session driver:</info> '.$this->identifySessionDriver());
$this->output->writeln('<info>Queue driver:</info> '.$this->appInfo->identifyQueueDriver());
$this->output->writeln('<info>Session driver:</info> '.$this->appInfo->identifySessionDriver());
if ($this->appInfo->scheduledTasksRegistered()) {
$this->output->writeln('<info>Scheduler status:</info> '.$this->appInfo->getSchedulerStatus());
}
$this->output->writeln('<info>Mail driver:</info> '.$this->settings->get('mail_driver', 'unknown'));
$this->output->writeln('<info>Debug mode:</info> '.($this->config->inDebugMode() ? '<error>ON</error>' : 'off'));
@@ -169,72 +154,4 @@ class InfoCommand extends AbstractCommand
return $fallback;
}
private function identifyQueueDriver(): string
{
// Get class name
$queue = get_class($this->queue);
// Drop the namespace
$queue = Str::afterLast($queue, '\\');
// Lowercase the class name
$queue = strtolower($queue);
// Drop everything like queue SyncQueue, RedisQueue
$queue = str_replace('queue', '', $queue);
return $queue;
}
private function identifyDatabaseVersion(): string
{
return $this->db->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION);
}
/**
* Reports on the session driver in use based on three scenarios:
* 1. If the configured session driver is valid and in use, it will be returned.
* 2. If the configured session driver is invalid, fallback to the default one and mention it.
* 3. If the actual used driver (i.e `session.handler`) is different from the current one (configured or default), mention it.
*/
private function identifySessionDriver(): string
{
/*
* Get the configured driver and fallback to the default one.
*/
$defaultDriver = $this->session->getDefaultDriver();
$configuredDriver = Arr::get($this->config, 'session.driver', $defaultDriver);
$driver = $configuredDriver;
try {
// Try to get the configured driver instance.
// Driver instances are created on demand.
$this->session->driver($configuredDriver);
} catch (InvalidArgumentException $e) {
// An exception is thrown if the configured driver is not a valid driver.
// So we fallback to the default driver.
$driver = $defaultDriver;
}
/*
* Get actual driver name from its class name.
* And compare that to the current configured driver.
*/
// Get class name
$handlerName = get_class($this->sessionHandler);
// Drop the namespace
$handlerName = Str::afterLast($handlerName, '\\');
// Lowercase the class name
$handlerName = strtolower($handlerName);
// Drop everything like sessionhandler FileSessionHandler, DatabaseSessionHandler ..etc
$handlerName = str_replace('sessionhandler', '', $handlerName);
if ($driver !== $handlerName) {
return "$handlerName <comment>(Code override. Configured to <options=bold,underscore>$configuredDriver</>)</comment>";
}
if ($driver !== $configuredDriver) {
return "$driver <comment>(Fallback default driver. Configured to invalid driver <options=bold,underscore>$configuredDriver</>)</comment>";
}
return $driver;
}
}

View File

@@ -0,0 +1,43 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Foundation\Console;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Contracts\Events\Dispatcher;
class ScheduleRunCommand extends \Illuminate\Console\Scheduling\ScheduleRunCommand
{
/**
* @var SettingsRepositoryInterface
*/
protected $settings;
/**
* {@inheritdoc}
*/
public function __construct(SettingsRepositoryInterface $settings)
{
parent::__construct();
$this->settings = $settings;
}
/**
* {@inheritdoc}
*/
public function handle(Schedule $schedule, Dispatcher $dispatcher, ExceptionHandler $handler)
{
parent::handle($schedule, $dispatcher, $handler);
$this->settings->set('schedule.last_run', $this->startedAt);
}
}