forked from laysense/laysense.cn
Reflow home shortcuts and support article deletion
This commit is contained in:
@@ -10,6 +10,10 @@ use Throwable;
|
||||
|
||||
final class Database
|
||||
{
|
||||
// Avoid reusing a deleted ID that may still be open in an editing form.
|
||||
public const NEXT_ARTICLE_ID = 'MAX(COALESCE((SELECT MAX(id) FROM articles), 0),
|
||||
COALESCE((SELECT MAX(article_id) FROM article_deletions), 0)) + 1';
|
||||
|
||||
private static ?PDO $connection = null;
|
||||
|
||||
public static function connect(): PDO
|
||||
@@ -94,8 +98,10 @@ final class Database
|
||||
$category->execute([$slug, $name]);
|
||||
}
|
||||
$article = $pdo->prepare("INSERT OR IGNORE INTO articles
|
||||
(slug, title, summary, body, body_format, card, tags, status, published_at, updated_at, legacy_path)
|
||||
SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? WHERE NOT EXISTS (SELECT 1 FROM article_redirects WHERE slug = ?)");
|
||||
(id, slug, title, summary, body, body_format, card, tags, status, published_at, updated_at, legacy_path)
|
||||
SELECT " . self::NEXT_ARTICLE_ID . ", ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
||||
WHERE NOT EXISTS (SELECT 1 FROM article_redirects WHERE slug = ?)
|
||||
AND NOT EXISTS (SELECT 1 FROM article_deletions WHERE slug = ?)");
|
||||
$link = $pdo->prepare('INSERT INTO article_category_links (article_id, category_slug) VALUES (?, ?)');
|
||||
foreach ($seed['articles'] as $item) {
|
||||
$format = $item['body_format'] ?? 'markdown';
|
||||
@@ -104,7 +110,7 @@ final class Database
|
||||
$item['slug'], $item['title'], $item['summary'] ?? '',
|
||||
$format === 'html' ? Html::sanitize($item['body']) : $item['body'], $format,
|
||||
self::json($item['card'] ?? []), self::json($item['tags'] ?? []),
|
||||
$item['status'] ?? 'published', $date, $date ?? gmdate(DATE_ATOM), $item['legacy'] ?? null, $item['slug'],
|
||||
$item['status'] ?? 'published', $date, $date ?? gmdate(DATE_ATOM), $item['legacy'] ?? null, $item['slug'], $item['slug'],
|
||||
]);
|
||||
if ($article->rowCount() === 1) {
|
||||
$id = $pdo->lastInsertId();
|
||||
|
||||
Reference in New Issue
Block a user