DocumentNotFoundException -> NotfoundException
This commit is contained in:
parent
a6454c0d83
commit
81ffc6b3c5
3 changed files with 12 additions and 5 deletions
|
@ -64,7 +64,7 @@ class PileDB
|
||||||
/**
|
/**
|
||||||
* Fetch pile document as an associative array.
|
* Fetch pile document as an associative array.
|
||||||
*
|
*
|
||||||
* @throws DocumentNotFoundException when document isn't found.
|
* @throws NotFoundException when document isn't found.
|
||||||
*/
|
*/
|
||||||
public function fetchDoc($id)
|
public function fetchDoc($id)
|
||||||
{
|
{
|
||||||
|
@ -72,7 +72,7 @@ class PileDB
|
||||||
$stmt_doc->bindValue(":id", $id, SQLITE3_INTEGER);
|
$stmt_doc->bindValue(":id", $id, SQLITE3_INTEGER);
|
||||||
$doc = $stmt_doc->execute()->fetchArray(SQLITE3_ASSOC);
|
$doc = $stmt_doc->execute()->fetchArray(SQLITE3_ASSOC);
|
||||||
if ($doc == false) {
|
if ($doc == false) {
|
||||||
throw new DocumentNotFoundException();
|
throw new NotFoundException();
|
||||||
}
|
}
|
||||||
$doc["HTMLDescription"] = $this->pd->text($doc["Description"]);
|
$doc["HTMLDescription"] = $this->pd->text($doc["Description"]);
|
||||||
|
|
||||||
|
@ -201,11 +201,18 @@ class PileDB
|
||||||
return $stmt->execute()->fetchArray(SQLITE3_ASSOC);
|
return $stmt->execute()->fetchArray(SQLITE3_ASSOC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Fetches tag as associative array.
|
||||||
|
* @throws NotFoundException
|
||||||
|
*/
|
||||||
public function fetchTag($tag)
|
public function fetchTag($tag)
|
||||||
{
|
{
|
||||||
$stmt = $this->db->prepare("SELECT * FROM Tags WHERE ID == :tag");
|
$stmt = $this->db->prepare("SELECT * FROM Tags WHERE ID == :tag");
|
||||||
$stmt->bindValue(":tag", $tag, SQLITE3_INTEGER);
|
$stmt->bindValue(":tag", $tag, SQLITE3_INTEGER);
|
||||||
$tag = $stmt->execute()->fetchArray(SQLITE3_ASSOC);
|
$tag = $stmt->execute()->fetchArray(SQLITE3_ASSOC);
|
||||||
|
if ($tag == false) {
|
||||||
|
throw new NotFoundException();
|
||||||
|
}
|
||||||
$tag["HTMLDescription"] = $this->pd->text($tag["Description"]);
|
$tag["HTMLDescription"] = $this->pd->text($tag["Description"]);
|
||||||
return $tag;
|
return $tag;
|
||||||
}
|
}
|
||||||
|
@ -257,7 +264,7 @@ class PileDB
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DocumentNotFoundException extends Exception
|
class NotFoundException extends Exception
|
||||||
{
|
{
|
||||||
// noop
|
// noop
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ $page = new Template();
|
||||||
if (isset($_GET["item"])) {
|
if (isset($_GET["item"])) {
|
||||||
try {
|
try {
|
||||||
$doc = $db->fetchDoc($_GET["item"]);
|
$doc = $db->fetchDoc($_GET["item"]);
|
||||||
} catch (DocumentNotFoundException $e) {
|
} catch (NotFoundException $e) {
|
||||||
http_response_code(404);
|
http_response_code(404);
|
||||||
$page->text = "Document not found.";
|
$page->text = "Document not found.";
|
||||||
$page->redirect = "/";
|
$page->redirect = "/";
|
||||||
|
|
|
@ -9,7 +9,7 @@ require '_util/PileDB.php';
|
||||||
$db = new PileDB();
|
$db = new PileDB();
|
||||||
try {
|
try {
|
||||||
$doc = $db->fetchDoc($_GET["id"]);
|
$doc = $db->fetchDoc($_GET["id"]);
|
||||||
} catch (DocumentNotFoundException $e) {
|
} catch (NotFoundException $e) {
|
||||||
http_response_code(404);
|
http_response_code(404);
|
||||||
$page->text = "Document not found.";
|
$page->text = "Document not found.";
|
||||||
$page->redirect = "/";
|
$page->redirect = "/";
|
||||||
|
|
Loading…
Reference in a new issue