feat: Enhance installation process with path state checks and error reporting
This commit is contained in:
@@ -36,6 +36,11 @@ function scripts_installer_lock_path(): string
|
||||
return scripts_saas_app_path() . DIRECTORY_SEPARATOR . '.installer.lock';
|
||||
}
|
||||
|
||||
function scripts_parent_directory(string $path): string
|
||||
{
|
||||
return dirname($path);
|
||||
}
|
||||
|
||||
function scripts_string_contains(string $haystack, string $needle): bool
|
||||
{
|
||||
if (function_exists('str_contains')) {
|
||||
@@ -157,6 +162,46 @@ function scripts_write_env_file(array $values, ?string $targetPath = null): stri
|
||||
return $targetPath;
|
||||
}
|
||||
|
||||
function scripts_path_writable_state(string $path): array
|
||||
{
|
||||
$exists = file_exists($path);
|
||||
$parent = scripts_parent_directory($path);
|
||||
$targetWritable = $exists ? is_writable($path) : false;
|
||||
$parentWritable = is_dir($parent) ? is_writable($parent) : false;
|
||||
|
||||
return [
|
||||
'path' => $path,
|
||||
'exists' => $exists,
|
||||
'readable' => $exists ? is_readable($path) : false,
|
||||
'writable' => $exists ? $targetWritable : $parentWritable,
|
||||
'target_writable' => $targetWritable,
|
||||
'parent' => $parent,
|
||||
'parent_exists' => is_dir($parent),
|
||||
'parent_writable' => $parentWritable,
|
||||
];
|
||||
}
|
||||
|
||||
function scripts_path_state_label(array $state): string
|
||||
{
|
||||
if (!$state['parent_exists']) {
|
||||
return 'Elternordner fehlt';
|
||||
}
|
||||
|
||||
if ($state['exists'] && $state['target_writable']) {
|
||||
return 'beschreibbar';
|
||||
}
|
||||
|
||||
if (!$state['exists'] && $state['parent_writable']) {
|
||||
return 'anlegbar';
|
||||
}
|
||||
|
||||
if ($state['exists']) {
|
||||
return 'nicht beschreibbar';
|
||||
}
|
||||
|
||||
return 'nicht anlegbar';
|
||||
}
|
||||
|
||||
function scripts_format_env_value(string $value): string
|
||||
{
|
||||
if ($value === '') {
|
||||
|
||||
@@ -56,6 +56,9 @@ $errors = [];
|
||||
$executedMigrations = [];
|
||||
$bundlePath = is_file(scripts_bundle_output_path()) ? scripts_bundle_output_path() : null;
|
||||
$locked = scripts_installer_is_locked();
|
||||
$envPathState = scripts_path_writable_state(scripts_env_path());
|
||||
$lockPathState = scripts_path_writable_state(scripts_installer_lock_path());
|
||||
$bundlePathState = scripts_path_writable_state(scripts_bundle_output_path());
|
||||
|
||||
if ($requestMethod === 'POST' && !$locked) {
|
||||
$csrf = (string) ($_POST['csrf'] ?? '');
|
||||
@@ -118,7 +121,8 @@ if ($requestMethod === 'POST' && !$locked) {
|
||||
if (scripts_string_contains($message, 'pdo_sqlsrv')) {
|
||||
$errors[] = 'Migrationen konnten nicht direkt ueber PHP ausgefuehrt werden. Bitte `pdo_sqlsrv` pruefen oder das SQL-Bundle manuell importieren.';
|
||||
} elseif (scripts_string_contains($message, '.env')) {
|
||||
$errors[] = 'Die Konfiguration konnte nicht gespeichert werden. Bitte Schreibrechte pruefen.';
|
||||
$errors[] = 'Die Konfiguration konnte nicht gespeichert werden. Zielpfad: ' . scripts_env_path();
|
||||
$errors[] = 'Status fuer .env: ' . scripts_path_state_label($envPathState) . '. Elternordner: ' . $envPathState['parent'];
|
||||
} else {
|
||||
$errors[] = 'Die Installation konnte nicht abgeschlossen werden. Bitte Eingaben, DB-Zugang und Dateirechte pruefen.';
|
||||
}
|
||||
@@ -439,9 +443,15 @@ function h(string $value): string
|
||||
<li>PHP Version: <code><?= h(PHP_VERSION) ?></code></li>
|
||||
<li>.env.example: <code><?= is_file(scripts_env_example_path()) ? 'vorhanden' : 'fehlt' ?></code></li>
|
||||
<li>.env: <code><?= is_file(scripts_env_path()) ? 'vorhanden' : 'fehlt' ?></code></li>
|
||||
<li>.env Status: <code><?= h(scripts_path_state_label($envPathState)) ?></code></li>
|
||||
<li>.env Zielpfad: <code><?= h($envPathState['path']) ?></code></li>
|
||||
<li>.env Elternordner: <code><?= h($envPathState['parent']) ?></code></li>
|
||||
<li>.env Elternordner beschreibbar: <code><?= $envPathState['parent_writable'] ? 'ja' : 'nein' ?></code></li>
|
||||
<li>pdo_sqlsrv: <code><?= extension_loaded('pdo_sqlsrv') ? 'aktiv' : 'nicht geladen' ?></code></li>
|
||||
<li>Installer-Lock: <code><?= $locked ? 'aktiv' : 'offen' ?></code></li>
|
||||
<li>Lock-Datei Status: <code><?= h(scripts_path_state_label($lockPathState)) ?></code></li>
|
||||
<li>Bundle-Pfad: <code><?= h(scripts_bundle_output_path()) ?></code></li>
|
||||
<li>Bundle-Ziel Status: <code><?= h(scripts_path_state_label($bundlePathState)) ?></code></li>
|
||||
</ul>
|
||||
|
||||
<?php if ($bundlePath !== null): ?>
|
||||
|
||||
Reference in New Issue
Block a user