fix(import): null out orphan category references (FK safe)
Build and Deploy / verify (push) Successful in 1m0s
Build and Deploy / deploy (push) Successful in 33s

This commit is contained in:
2026-09-07 19:55:19 +00:00
parent 66ce4bce0a
commit e0c709ad5c
+7 -1
View File
@@ -254,8 +254,14 @@ class SablogImport extends Command
$status = (int) $row['visible'] === 1 ? 'published' : 'draft';
$dateline = ($ts = (int) $row['dateline']) > 0 ? date('Y-m-d H:i:s', $ts) : now()->toDateTimeString();
// 老库存在已删除分类的孤儿文章;目标列可空,置 null
$categoryId = (int) $row['cid'] ?: null;
if ($categoryId !== null && ! DB::table('categories')->where('id', $categoryId)->exists()) {
$categoryId = null;
}
DB::table('posts')->updateOrInsert(['id' => (int) $row['articleid']], [
'category_id' => (int) $row['cid'] ?: null,
'category_id' => $categoryId,
'user_id' => (int) $row['uid'] ?: null,
'title' => $row['title'],
'slug' => $slug,