updateArticle-Exceptions
This commit is contained in:
@@ -53,6 +53,11 @@ include_once 'php/controller/showArticle-controller.php';
|
|||||||
Bei der Validierung deiner Daten ist ein Fehler aufgetreten. Bitte versuche es erneut.
|
Bei der Validierung deiner Daten ist ein Fehler aufgetreten. Bitte versuche es erneut.
|
||||||
</p>
|
</p>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "unauthorized_access"): ?>
|
||||||
|
<p class="alert-message is-error">
|
||||||
|
Sie sind nicht berechtigt, diesen Beitrag zu bearbeiten.
|
||||||
|
</p>
|
||||||
|
<?php endif; ?>
|
||||||
<?php
|
<?php
|
||||||
unset($_SESSION["message"]);
|
unset($_SESSION["message"]);
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|||||||
$article->setTags($cleanedTags);
|
$article->setTags($cleanedTags);
|
||||||
$articleManager->updateArticle($id ,$article, $author);
|
$articleManager->updateArticle($id ,$article, $author);
|
||||||
} catch (Exception $e){
|
} catch (Exception $e){
|
||||||
$_SESSION["message"] = "internal_error";
|
$_SESSION["message"] = $e->getMessage();
|
||||||
header("location: ../../index.php?pfad=updateArticle");
|
header("location: ../../index.php?pfad=updateArticle");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ require_once "Article.php";
|
|||||||
|
|
||||||
class NotFoundException extends Exception {}
|
class NotFoundException extends Exception {}
|
||||||
class UnauthorizedAccessException extends Exception {}
|
class UnauthorizedAccessException extends Exception {}
|
||||||
|
class InternalServerErrorException extends Exception {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Die Klasse beinhaltet alle Methoden für die Operation mit den Artikel-Daten.
|
* Die Klasse beinhaltet alle Methoden für die Operation mit den Artikel-Daten.
|
||||||
@@ -33,6 +34,7 @@ interface ArticleManagerDAO
|
|||||||
* @param $author
|
* @param $author
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
|
* @throws InternalServerErrorException
|
||||||
* @throws NotFoundException
|
* @throws NotFoundException
|
||||||
* @throws UnauthorizedAccessException
|
* @throws UnauthorizedAccessException
|
||||||
* /
|
* /
|
||||||
|
|||||||
@@ -65,12 +65,12 @@ class LocalArticleManager implements ArticleManagerDAO {
|
|||||||
public function updateArticle($id, $article, $author)
|
public function updateArticle($id, $article, $author)
|
||||||
{
|
{
|
||||||
if (empty($article)) {
|
if (empty($article)) {
|
||||||
throw new InvalidArgumentException("Der Beitrag darf nicht leer sein.");
|
throw new InternalServerErrorException("internal_error");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Berechtigungsprüfung:
|
// Berechtigungsprüfung:
|
||||||
if ($article->getAuthor() !== $author) {
|
if ($article->getAuthor() !== $author) {
|
||||||
throw new UnauthorizedAccessException("Sie sind nicht berechtigt, diesen Artikel zu bearbeiten.");
|
throw new UnauthorizedAccessException("unauthorized_access");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Beitrag aktualisieren:
|
// Beitrag aktualisieren:
|
||||||
@@ -97,8 +97,7 @@ class LocalArticleManager implements ArticleManagerDAO {
|
|||||||
if ($updated) {
|
if ($updated) {
|
||||||
$this->saveArticle($articles);
|
$this->saveArticle($articles);
|
||||||
} else {
|
} else {
|
||||||
throw new NotFoundException("Ein Artikel mit der ID". $id . " wurde nicht gefunden.");
|
throw new NotFoundException("missing_id");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user