Email change on user

This commit is contained in:
2024-07-27 02:52:24 +02:00
parent 683b6020b7
commit 12f7176467
6 changed files with 86 additions and 25 deletions
+20 -2
View File
@@ -118,6 +118,10 @@ class Post implements JsonSerializable
{
$db = Database::getInstance();
$db->beginTransaction();
$failed = [];
$reason = [];
if (!empty($content)) {
$content = substr(trim($content), 0, 250);
@@ -125,11 +129,25 @@ class Post implements JsonSerializable
$stmt->bindValue(":CON", nl2br(htmlspecialchars($content)));
$stmt->bindValue(":ID", $this->id);
try {
if (!$stmt->execute()) throw ApiError::failedUpdate(["content"]);
if (!$stmt->execute()) {
$failed = ["content"];
$reason = ["generic"];
}
} catch (Exception $e) {
throw ApiError::failedUpdate(["content"]);
$failed = ["content"];
if ($e->getCode() === "23000") {
$pdoErr = $stmt->errorInfo()[1];
$reason = ["SQL: $pdoErr"];
} else $reason = ["{$e->getCode()}"];
}
}
if ($failed !== null) {
$db->rollBack();
throw ApiError::failedUpdate($failed, $reason);
}
$db->commit();
return Post::getByID($this->id);
}