Finish implementing SqliteGateway

This commit is contained in:
Lewis Dale committed 2023-03-09 13:05:43 +00:00
1 parent adeb7a1b51
commit f85c48b4a9
2 files changed
+87 -16

No files matched your search

+26 -10
View File
@@ -33,14 +33,11 @@ class SqliteGateway extends WebmentionGatewayInterface {
public function get(int $id): ?Webmention
{
$sql = "SELECT * FROM webmentions;";
$statement = $this->connection->query($sql);
if ($statement == false) {
return null;
}
$sql = "SELECT * FROM webmentions WHERE id=:id LIMIT 1;";
$statement = $this->connection->prepare($sql);
$statement->execute(["id" => $id]);
$row = $statement->fetch(PDO::FETCH_ASSOC);
$statement->closeCursor();
if ($row) {
return new Webmention(
@@ -57,7 +54,24 @@ class SqliteGateway extends WebmentionGatewayInterface {
public function getByPost(string $post): array
{
return [];
$sql = "SELECT * FROM webmentions WHERE target=:post";
$statement = $this->connection->prepare($sql);
$statement->execute(["post" => $post]);
$mentions = [];
while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
$mentions[] = new Webmention(
$row["id"],
$row["target"],
$row["source"],
$row["content"],
$row["author"]
);
}
$statement->closeCursor();
return $mentions;
}
public function save(Webmention $webmention): ?int
@@ -78,8 +92,10 @@ class SqliteGateway extends WebmentionGatewayInterface {
public function delete(Webmention $webmention): void
{
throw new Exception("Method " . SqliteGateway::class . "::delete not implemented");
$sql = "DELETE FROM webmentions WHERE id=:id;";
$statement = $this->connection->prepare($sql);
$statement->execute(["id" => $webmention->id]);
$statement->closeCursor();
}
}
?>