fix(import): dedupe tags via Tag::findFromString (name is JSON translatable)
This commit is contained in:
@@ -340,7 +340,9 @@ class SablogImport extends Command
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tag = Tag::query()->where('name', $tagName)->where('type', 'post')->first();
|
// spatie/tags 的 name 是 JSON 翻译字段,直接 where('name', ...) 匹配不到,
|
||||||
|
// 必须用 findFromString(内部按 locale 查询 JSON 键),否则每次导入都重复建标签
|
||||||
|
$tag = Tag::findFromString($tagName, 'post');
|
||||||
if (! $tag) {
|
if (! $tag) {
|
||||||
$tag = new Tag(['name' => $tagName, 'type' => 'post']);
|
$tag = new Tag(['name' => $tagName, 'type' => 'post']);
|
||||||
$tag->slug = SlugGenerator::make($tagName, 'tags', 'slug', fallback: 'tag-'.crc32($tagName));
|
$tag->slug = SlugGenerator::make($tagName, 'tags', 'slug', fallback: 'tag-'.crc32($tagName));
|
||||||
|
|||||||
Reference in New Issue
Block a user