Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions app/Checks/AdminUserCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Checks;

use App\Models\Role;
use App\Models\User;
use Spatie\Health\Checks\Check;
use Spatie\Health\Checks\Result;
use Throwable;

class AdminUserCheck extends Check
{
/**
* Verify that at least one root administrator account exists.
*/
public function run(): Result
{
$result = Result::make()->meta([
'remediation' => trans('installer.health.admin.remediation'),
]);

try {
return User::role(Role::ROOT_ADMIN)->exists()
? $result->ok(trans('installer.health.admin.passed'))
: $result->failed(trans('installer.health.admin.failed'));
} catch (Throwable $exception) {
return $result->failed(trans('installer.health.admin.exception', [
'error' => $exception->getMessage(),
]));
}
}
}
35 changes: 35 additions & 0 deletions app/Checks/ApplicationKeyCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Checks;

use Illuminate\Encryption\Encrypter;
use Spatie\Health\Checks\Check;
use Spatie\Health\Checks\Result;

class ApplicationKeyCheck extends Check
{
/**
* Verify that the configured application key supports the selected cipher.
*/
public function run(): Result
{
$key = config('app.key');
$cipher = config('app.cipher', 'AES-256-CBC');

if (is_string($key) && str_starts_with($key, 'base64:')) {
$key = base64_decode(substr($key, 7), true);
}

$passed = is_string($key)
&& is_string($cipher)
&& Encrypter::supported($key, $cipher);

$result = Result::make()->meta([
'remediation' => trans('installer.health.app_key.remediation'),
]);

return $passed
? $result->ok(trans('installer.health.app_key.passed'))
: $result->failed(trans('installer.health.app_key.failed'));
}
}
55 changes: 55 additions & 0 deletions app/Checks/DatabaseExtensionCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace App\Checks;

use App\Enums\DatabaseDriver;
use Spatie\Health\Checks\Check;
use Spatie\Health\Checks\Result;

class DatabaseExtensionCheck extends Check
{
protected DatabaseDriver|string $driver = DatabaseDriver::SQLite;

/**
* Select the database driver whose PHP extension should be checked.
*/
public function driver(DatabaseDriver|string $driver): self
{
$this->driver = $driver;

return $this;
}

/**
* Verify that the configured database driver is supported and available.
*/
public function run(): Result
{
$driver = is_string($this->driver) ? DatabaseDriver::tryFrom($this->driver) : $this->driver;

if ($driver === null) {
return Result::make()
->meta([
'driver' => $this->driver,
'remediation' => trans('installer.health.database_extension.unsupported_remediation'),
])
->failed(trans('installer.health.database_extension.unsupported', ['driver' => $this->driver]));
}

$extension = $driver->requiredExtension();
$passed = extension_loaded($extension);

$result = Result::make()->meta([
'driver' => $driver->value,
'extension' => $extension,
'remediation' => trans('installer.health.extensions.remediation'),
]);

return $passed
? $result->ok(trans('installer.health.database_extension.passed', ['extension' => $extension]))
: $result->failed(trans('installer.health.database_extension.failed', [
'driver' => $driver->getLabel(),
'extension' => $extension,
]));
}
}
23 changes: 23 additions & 0 deletions app/Checks/InstallationFlagCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Checks;

use Spatie\Health\Checks\Check;
use Spatie\Health\Checks\Result;

class InstallationFlagCheck extends Check
{
/**
* Verify that the Panel is marked as installed.
*/
public function run(): Result
{
$result = Result::make()->meta([
'remediation' => trans('installer.health.installed.remediation'),
]);

return config('app.installed')
? $result->ok(trans('installer.health.installed.passed'))
: $result->failed(trans('installer.health.installed.failed'));
}
}
43 changes: 43 additions & 0 deletions app/Checks/MigrationsCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Checks;

use Illuminate\Database\Migrations\Migrator;
use Spatie\Health\Checks\Check;
use Spatie\Health\Checks\Result;
use Throwable;

class MigrationsCheck extends Check
{
/**
* Create a migration health check using the configured migrator.
*/
public function __construct(private readonly Migrator $migrator) {}

/**
* Verify that the migration repository exists and has no pending migrations.
*/
public function run(): Result
{
$result = Result::make()->meta([
'remediation' => trans('installer.health.migrations.remediation'),
]);

try {
if (!$this->migrator->repositoryExists()) {
return $result->failed(trans('installer.health.migrations.repository_missing'));
}

$files = $this->migrator->getMigrationFiles(database_path('migrations'));
$pending = array_diff(array_keys($files), $this->migrator->getRepository()->getRan());

return $pending === []
? $result->ok(trans('installer.health.migrations.passed'))
: $result->failed(trans('installer.health.migrations.failed', ['count' => count($pending)]));
} catch (Throwable $exception) {
return $result->failed(trans('installer.health.migrations.exception', [
'error' => $exception->getMessage(),
]));
}
}
}
70 changes: 70 additions & 0 deletions app/Checks/PhpExtensionsCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace App\Checks;

use App\Enums\DatabaseDriver;
use Spatie\Health\Checks\Check;
use Spatie\Health\Checks\Result;

class PhpExtensionsCheck extends Check
{
public const REQUIRED_EXTENSIONS = [
'bcmath',
'curl',
'gd',
'intl',
'json',
'mbstring',
'pdo',
'xml',
'zip',
];

/** @var string[] */
protected array $requiredExtensions = self::REQUIRED_EXTENSIONS;

/**
* Override the PHP extensions required by this check.
*
* @param string[] $extensions
*/
public function requireExtensions(array $extensions): self
{
$this->requiredExtensions = $extensions;

return $this;
}

/**
* Verify the required PHP and PDO extensions are loaded.
*/
public function run(): Result
{
$missing = array_values(array_filter(
$this->requiredExtensions,
fn (string $extension) => !extension_loaded($extension),
));

$databaseExtensions = array_unique(array_map(
fn (DatabaseDriver $driver) => $driver->requiredExtension(),
DatabaseDriver::cases(),
));

$hasDatabaseExtension = array_filter($databaseExtensions, extension_loaded(...)) !== [];

if (!$hasDatabaseExtension) {
$missing[] = implode(', ', $databaseExtensions);
}

$result = Result::make()->meta([
'missing' => implode(', ', $missing),
'remediation' => trans('installer.health.extensions.remediation'),
]);

return $missing === []
? $result->ok(trans('installer.health.extensions.passed'))
: $result->failed(trans('installer.health.extensions.failed', [
'extensions' => implode(', ', $missing),
]));
}
}
61 changes: 61 additions & 0 deletions app/Checks/PhpVersionCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace App\Checks;

use Spatie\Health\Checks\Check;
use Spatie\Health\Checks\Result;

class PhpVersionCheck extends Check
{
public const MINIMUM_VERSION = '8.3.0';

protected string $minimumVersion = self::MINIMUM_VERSION;

protected string $currentVersion = PHP_VERSION;

/**
* Override the minimum supported PHP version.
*/
public function minimumVersion(string $version): self
{
$this->minimumVersion = $version;

return $this;
}

/**
* Override the current PHP version for evaluation.
*/
public function currentVersion(string $version): self
{
$this->currentVersion = $version;

return $this;
}

/**
* Verify that the current PHP version meets the minimum requirement.
*/
public function run(): Result
{
$passed = version_compare($this->currentVersion, $this->minimumVersion, '>=');

$result = Result::make()
->meta([
'current' => $this->currentVersion,
'minimum' => $this->minimumVersion,
'remediation' => trans('installer.health.php.remediation', ['minimum' => $this->minimumVersion]),
])
->shortSummary($this->currentVersion);

return $passed
? $result->ok(trans('installer.health.php.passed', [
'current' => $this->currentVersion,
'minimum' => $this->minimumVersion,
]))
: $result->failed(trans('installer.health.php.failed', [
'current' => $this->currentVersion,
'minimum' => $this->minimumVersion,
]));
}
}
53 changes: 53 additions & 0 deletions app/Checks/WritablePathsCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace App\Checks;

use Spatie\Health\Checks\Check;
use Spatie\Health\Checks\Result;

class WritablePathsCheck extends Check
{
/** @var string[]|null */
protected ?array $paths = null;

/**
* Override the filesystem paths that must be writable.
*
* @param string[] $paths
*/
public function paths(array $paths): self
{
$this->paths = $paths;

return $this;
}

/**
* Verify that every required installer path is writable.
*/
public function run(): Result
{
$paths = $this->paths ?? [
storage_path(),
base_path('bootstrap/cache'),
file_exists(base_path('.env')) ? base_path('.env') : base_path(),
];

$notWritable = array_values(array_filter(
$paths,
fn (string $path) => !is_writable($path),
));

$result = Result::make()->meta([
'paths' => implode(', ', $paths),
'not_writable' => implode(', ', $notWritable),
'remediation' => trans('installer.health.paths.remediation'),
]);

return $notWritable === []
? $result->ok(trans('installer.health.paths.passed'))
: $result->failed(trans('installer.health.paths.failed', [
'paths' => implode(', ', $notWritable),
]));
}
}
Loading
Loading