Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m50s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 7m34s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m45s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 5m30s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m7s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 7m9s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m8s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m5s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 48s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m5s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
74 lines
2.3 KiB
PHP
74 lines
2.3 KiB
PHP
<?php
|
||
|
||
namespace App\Support;
|
||
|
||
use App\Models\Role;
|
||
use Illuminate\Encryption\Encrypter;
|
||
use Illuminate\Support\Facades\DB;
|
||
use Illuminate\Support\Facades\Schema;
|
||
|
||
/**
|
||
* Installationsstatus und Vorbereitung für den Web-Installer.
|
||
*/
|
||
class Installation
|
||
{
|
||
public static function isInstalled(): bool
|
||
{
|
||
$forced = config('inhaus.installed');
|
||
|
||
if ($forced !== null && $forced !== '') {
|
||
return filter_var($forced, FILTER_VALIDATE_BOOL);
|
||
}
|
||
|
||
if (is_file(storage_path('.installed')) || app()->environment('local')) {
|
||
return true;
|
||
}
|
||
|
||
// Markierung verloren (z. B. storage/ nach einem Umzug nicht mitkopiert)? Gibt es bereits
|
||
// ein Administrationskonto, ist das Portal eingerichtet – der Installer darf nie wieder öffnen.
|
||
static $checked = null;
|
||
|
||
if ($checked === null) {
|
||
try {
|
||
$checked = Schema::hasTable('role_user')
|
||
&& DB::table('role_user')->join('roles', 'roles.id', '=', 'role_user.role_id')->where('roles.slug', Role::ADMINISTRATION)->exists();
|
||
} catch (\Throwable) {
|
||
$checked = false; // noch keine Datenbank eingerichtet
|
||
}
|
||
|
||
if ($checked) {
|
||
@self::markInstalled();
|
||
}
|
||
}
|
||
|
||
return $checked;
|
||
}
|
||
|
||
public static function markInstalled(): void
|
||
{
|
||
file_put_contents(storage_path('.installed'), date(DATE_ATOM));
|
||
}
|
||
|
||
/**
|
||
* Frisch hochgeladene Installation: .env aus der Vorlage anlegen und einen
|
||
* Anwendungsschlüssel erzeugen – ohne Schlüssel funktionieren weder Sitzungen
|
||
* noch Cookies, also auch der Installer nicht.
|
||
*/
|
||
public static function prepareEnvironment(): void
|
||
{
|
||
$env = app()->environmentFilePath();
|
||
|
||
if (! is_file($env) && is_file(base_path('.env.example')) && is_writable(base_path())) {
|
||
$key = 'base64:'.base64_encode(Encrypter::generateKey(config('app.cipher', 'AES-256-CBC')));
|
||
|
||
copy(base_path('.env.example'), $env);
|
||
EnvFile::set($env, [
|
||
'APP_KEY' => $key,
|
||
'APP_ENV' => 'production',
|
||
'APP_DEBUG' => 'false',
|
||
]);
|
||
|
||
config(['app.key' => $key, 'app.env' => 'production', 'app.debug' => false]);
|
||
}
|
||
}
|
||
}
|