Refactor saveJsonFile function in index.php and wiki.php to include JSON_INVALID_UTF8_SUBSTITUTE flag for better handling of invalid UTF-8 characters. Enhanced error messages for file saving failures to include the file name, improving debugging and user guidance.
This commit is contained in:
@@ -76,14 +76,17 @@ function loadJsonFile(string $file, array $default): array
|
|||||||
|
|
||||||
function saveJsonFile(string $file, array $data): void
|
function saveJsonFile(string $file, array $data): void
|
||||||
{
|
{
|
||||||
$json = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
$json = json_encode(
|
||||||
|
$data,
|
||||||
|
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE
|
||||||
|
);
|
||||||
if ($json === false) {
|
if ($json === false) {
|
||||||
throw new RuntimeException('Konfiguration konnte nicht kodiert werden.');
|
throw new RuntimeException('Konfiguration konnte nicht kodiert werden.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$written = @file_put_contents($file, $json, LOCK_EX);
|
$written = @file_put_contents($file, $json, LOCK_EX);
|
||||||
if ($written === false) {
|
if ($written === false) {
|
||||||
throw new RuntimeException('Konfiguration konnte nicht gespeichert werden. Bitte Dateirechte prüfen.');
|
throw new RuntimeException('Konfiguration konnte nicht gespeichert werden: ' . $file . ' (Dateirechte prüfen).');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
15
wiki.php
15
wiki.php
@@ -72,11 +72,18 @@ function loadJsonFile(string $file, array $default): array
|
|||||||
|
|
||||||
function saveJsonFile(string $file, array $data): void
|
function saveJsonFile(string $file, array $data): void
|
||||||
{
|
{
|
||||||
file_put_contents(
|
$json = json_encode(
|
||||||
$file,
|
$data,
|
||||||
json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
|
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE
|
||||||
LOCK_EX
|
|
||||||
);
|
);
|
||||||
|
if ($json === false) {
|
||||||
|
throw new RuntimeException('Konfiguration konnte nicht kodiert werden.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$written = @file_put_contents($file, $json, LOCK_EX);
|
||||||
|
if ($written === false) {
|
||||||
|
throw new RuntimeException('Konfiguration konnte nicht gespeichert werden: ' . $file . ' (Dateirechte prüfen).');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isAdminLoggedIn(): bool
|
function isAdminLoggedIn(): bool
|
||||||
|
|||||||
Reference in New Issue
Block a user