forked from laysense/laysense.cn
Reflow home shortcuts and support article deletion
This commit is contained in:
@@ -264,8 +264,8 @@ final class Repository
|
||||
];
|
||||
if ($id === null) {
|
||||
$query = $pdo->prepare('INSERT INTO articles
|
||||
(slug, title, summary, body, body_format, card, tags, status, published_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
|
||||
(id, slug, title, summary, body, body_format, card, tags, status, published_at, updated_at)
|
||||
VALUES (' . Database::NEXT_ARTICLE_ID . ', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
|
||||
$query->execute($values);
|
||||
$id = (int) $pdo->lastInsertId();
|
||||
} else {
|
||||
@@ -289,6 +289,22 @@ final class Repository
|
||||
});
|
||||
}
|
||||
|
||||
public function deleteArticle(int $id, int $version): void
|
||||
{
|
||||
Database::write(function (PDO $pdo) use ($id, $version): void {
|
||||
// Keep the original seed slug even if the article has been renamed.
|
||||
$deletions = $pdo->prepare('INSERT INTO article_deletions (slug, article_id)
|
||||
SELECT slug, id FROM articles WHERE id = :id
|
||||
UNION ALL SELECT slug, article_id FROM article_redirects WHERE article_id = :id
|
||||
ON CONFLICT (slug) DO UPDATE SET article_id = excluded.article_id');
|
||||
$deletions->execute(['id' => $id]);
|
||||
|
||||
$delete = $pdo->prepare('DELETE FROM articles WHERE id = ? AND version = ?');
|
||||
$delete->execute([$id, $version]);
|
||||
self::checkVersion($delete->rowCount());
|
||||
});
|
||||
}
|
||||
|
||||
public function sitemapArticles(): iterable
|
||||
{
|
||||
$query = $this->pdo->query("SELECT slug, updated_at FROM articles WHERE status = 'published'
|
||||
|
||||
Reference in New Issue
Block a user