fix page creation validation and persistence

Validate required page fields and localized translations, detect route collisions, and save pages and translations atomically with rollback on failure. Report creation errors while preserving submitted form values, safely encode Alpine.js values, and add English and German error messages. Return null for failed inserts and add page persistence tests.
This commit is contained in:
2026-11-24 22:40:52 +01:00
parent 3160f377d1
commit 8251f883e6
8 changed files with 641 additions and 43 deletions
+23
View File
@@ -133,6 +133,29 @@ class DB
return $stmt->execute($parameters);
}
/**
* Run the callback inside a database transaction, rolling back false results and exceptions.
*/
public function transaction(callable $callback): mixed
{
$this->pdo->beginTransaction();
try {
$result = $callback();
if ($result === false) {
$this->pdo->rollBack();
return false;
}
$this->pdo->commit();
return $result;
} catch (\Throwable $exception) {
if ($this->pdo->inTransaction()) {
$this->pdo->rollBack();
}
throw $exception;
}
}
function tableExists(string $table): bool
{
$tableName = $_ENV['DATABASE_PREFIX'] . phpb_remove_non_alpha_numeric($table);