Merge branch 'CSRF' into dev

This commit is contained in:
2026-07-19 21:14:01 +02:00
23 changed files with 376 additions and 81 deletions
+9 -48
View File
@@ -63,12 +63,9 @@ class DatabaseArticleManager implements ArticleManagerDAO {
VALUES (:title, :content, :author, :category, :tags);";
$command = $db->prepare($sql);
if (!$command) {
throw new InternalServerErrorException("internal_error");
}
// Verknüpft die übergebenen Parameter exakt mit den SQL-Platzhaltern
$success = $command->execute([
$command->execute([
":title" => $title,
":content" => $content,
":author" => $author,
@@ -76,14 +73,10 @@ class DatabaseArticleManager implements ArticleManagerDAO {
":tags" => $tags
]);
if (!$success) {
throw new InternalServerErrorException("internal_error");
}
return intval($db->lastInsertId());
} catch (PDOException $e) {
throw new InternalServerErrorException($e->getMessage());
throw new InternalServerErrorException("internal_error");
}
}
@@ -106,11 +99,8 @@ class DatabaseArticleManager implements ArticleManagerDAO {
WHERE id = :id;";
$command = $db->prepare($sql);
if (!$command) {
throw new InternalServerErrorException("internal_error");
}
$success = $command->execute([
$command->execute([
":id" => $id,
":title" => $article->getTitle(),
":content" => $article->getContent(),
@@ -120,7 +110,7 @@ class DatabaseArticleManager implements ArticleManagerDAO {
]);
// rowCount() prüft, ob eine Zeile mit dieser ID existierte und geändert werden konnte
if (!$success || $command->rowCount() === 0) {
if ($command->rowCount() === 0) {
// Falls die ID nicht existiert, prüfen wir, ob sie überhaupt da ist
if (!$this->getArticle($id)) {
throw new NotFoundException("missing_id");
@@ -148,13 +138,7 @@ class DatabaseArticleManager implements ArticleManagerDAO {
$sql = "DELETE FROM articles WHERE id = :id;";
$command = $db->prepare($sql);
if (!$command) {
throw new InternalServerErrorException("internal_error");
}
if (!$command->execute([":id" => $id])) {
throw new InternalServerErrorException("internal_error");
}
$command->execute([":id" => $id]);
} catch (PDOException $exc) {
throw new InternalServerErrorException("internal_error");
}
@@ -167,10 +151,6 @@ class DatabaseArticleManager implements ArticleManagerDAO {
$sql = "SELECT * FROM articles WHERE id = :id;";
$command = $db->prepare($sql);
if (!$command) {
throw new InternalServerErrorException("internal_error");
}
$command->execute([":id" => $id]);
$row = $command->fetch(PDO::FETCH_ASSOC);
@@ -202,10 +182,6 @@ class DatabaseArticleManager implements ArticleManagerDAO {
$sql = "SELECT * FROM articles;";
$command = $db->query($sql);
if (!$command) {
throw new InternalServerErrorException("internal_error");
}
$rows = $command->fetchAll(PDO::FETCH_ASSOC);
$articles = [];
@@ -234,10 +210,6 @@ class DatabaseArticleManager implements ArticleManagerDAO {
$sql = "SELECT * FROM articles WHERE author = :author;";
$command = $db->prepare($sql);
if (!$command) {
throw new InternalServerErrorException("internal_error");
}
$command->execute([":author" => $author]);
$rows = $command->fetchAll(PDO::FETCH_ASSOC);
$filteredArticles = [];
@@ -270,10 +242,6 @@ class DatabaseArticleManager implements ArticleManagerDAO {
$sql = "SELECT * FROM articles WHERE category = :category;";
$command = $db->prepare($sql);
if (!$command) {
throw new InternalServerErrorException("internal_error");
}
$command->execute([":category" => $category]);
$rows = $command->fetchAll(PDO::FETCH_ASSOC);
$filteredArticles = [];
@@ -310,7 +278,7 @@ class DatabaseArticleManager implements ArticleManagerDAO {
try {
$db = $this->getConnection();
$sql = "SELECT id, title, content, author, category, tags, created
FROM articles
WHERE title LIKE :keyword
@@ -318,20 +286,14 @@ class DatabaseArticleManager implements ArticleManagerDAO {
OR tags LIKE :keyword;";
$command = $db->prepare($sql);
if (!$command) {
throw new InternalServerErrorException("internal_error");
}
// Wildcards für die SQL-Suche hinzufügen
// Wildcards für die Suche hinzufügen
$searchParam = '%' . $cleankeyword . '%';
$success = $command->execute([
$command->execute([
":keyword" => $searchParam
]);
if (!$success) {
throw new InternalServerErrorException("internal_error");
}
$rows = $command->fetchAll(PDO::FETCH_ASSOC);
$filteredArticles = [];
@@ -358,7 +320,6 @@ class DatabaseArticleManager implements ArticleManagerDAO {
}
}
/**
* Holt alle User-IDs, die einen bestimmten Beitrag geliked haben.
*