fix(import): use sablog_articles.keywords for tags instead of sablog_tags.aids
This commit is contained in:
@@ -318,9 +318,25 @@ class SablogImport extends Command
|
||||
{
|
||||
$legacyMap = [];
|
||||
$count = 0;
|
||||
foreach ($this->rows('tags') as $row) {
|
||||
$tagName = trim($row['tag']);
|
||||
if (! $tagName) {
|
||||
|
||||
// 正确的标签来源:sablog_articles.keywords(每篇文章的关键词字段)
|
||||
// 而不是 sablog_tags.aids(那个映射是错的/过时的)
|
||||
foreach ($this->rows('articles') as $row) {
|
||||
$keywords = trim((string) ($row['keywords'] ?? ''));
|
||||
if ($keywords === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$postId = (int) $row['articleid'];
|
||||
$post = Post::find($postId);
|
||||
if (! $post) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// keywords 是逗号分隔的标签名
|
||||
$tagNames = array_filter(array_map('trim', explode(',', $keywords)));
|
||||
foreach ($tagNames as $tagName) {
|
||||
if ($tagName === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -331,11 +347,9 @@ class SablogImport extends Command
|
||||
$tag->save();
|
||||
}
|
||||
|
||||
$legacyMap[(int) $row['tagid']] = $tag->id;
|
||||
$legacyMap[$tagName] = $tag->id;
|
||||
|
||||
foreach (explode(',', (string) $row['aids']) as $aid) {
|
||||
$post = Post::find((int) trim($aid));
|
||||
if ($post && ! $post->tags()->where('tags.id', $tag->id)->exists()) {
|
||||
if (! $post->tags()->where('tags.id', $tag->id)->exists()) {
|
||||
$post->tags()->attach($tag->id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user