- Posts: 2
COMMUNITY FORUM
Duplicate tags when importing Joomla content
- Hedgy
-
Topic Author
- Offline
- New Member
Less
More
4 years 6 months ago #177263
by Hedgy
Duplicate tags when importing Joomla content was created by Hedgy
I have an issue when importing joomla content to K2.
It seems for every tag it finds it creates a new tag, even if the tag already existed.
Because of this I'm getting a lot of duplicate tags. And going to the tag-url will only show one item.
Is there a way to solve this? I tried looking for a way to merge the tags but can't find one.
I tried reinstalling K2 to reimport the articles, but I get the same issue
K2 version: v2.10.3
Joomla version: 3.9.22
It seems for every tag it finds it creates a new tag, even if the tag already existed.
Because of this I'm getting a lot of duplicate tags. And going to the tag-url will only show one item.
Is there a way to solve this? I tried looking for a way to merge the tags but can't find one.
I tried reinstalling K2 to reimport the articles, but I get the same issue
K2 version: v2.10.3
Joomla version: 3.9.22
Please Log in or Create an account to join the conversation.
- JoomlaWorks
-
- Offline
- Admin
Less
More
4 years 6 months ago - 4 years 6 months ago #177286
by JoomlaWorks
Replied by JoomlaWorks on topic Duplicate tags when importing Joomla content
The K2 importer merges both tags and meta keywords and converts them to K2 tags.
However I see we have a bug in the code that decides how these are filtered and converted to tags.
Please test the following if you can. Edit the file /administrator/components/com_k2/models/items.php and replace these lines github.com/getk2/k2/blob/master/administrator/components/com_k2/models/items.php#L1413-L1431 with this:
This should filter the tags correctly before importing them.
Let me know.
However I see we have a bug in the code that decides how these are filtered and converted to tags.
Please test the following if you can. Edit the file /administrator/components/com_k2/models/items.php and replace these lines github.com/getk2/k2/blob/master/administrator/components/com_k2/models/items.php#L1413-L1431 with this:
// Check if the tag exists already
$query = "SELECT id FROM #__k2_tags WHERE name=".$db->Quote($itemTag);
$db->setQuery($query);
$id = $db->loadResult();
if ($id) {
$query = "INSERT INTO #__k2_tags_xref (`id`, `tagID`, `itemID`) VALUES (NULL, {$id}, {$K2Item->id})";
} else {
$K2Tag = JTable::getInstance('K2Tag', 'Table');
$K2Tag->name = $itemTag;
$K2Tag->published = 1;
$K2Tag->store();
$tags[] = $K2Tag;
$query = "INSERT INTO #__k2_tags_xref (`id`, `tagID`, `itemID`) VALUES (NULL, {$K2Tag->id}, {$K2Item->id})";
}
$db->setQuery($query);
$db->query();
This should filter the tags correctly before importing them.
Let me know.
Last edit: 4 years 6 months ago by JoomlaWorks.
Please Log in or Create an account to join the conversation.
- Hedgy
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 2
4 years 6 months ago #177325
by Hedgy
Replied by Hedgy on topic Duplicate tags when importing Joomla content
That fixed it! Thank you :)
Please Log in or Create an account to join the conversation.
- JoomlaWorks
-
- Offline
- Admin
Less
More
4 years 6 months ago #177333
by JoomlaWorks
Replied by JoomlaWorks on topic Duplicate tags when importing Joomla content
Great, I'll merge the change for K2 v2.10.4.
Please Log in or Create an account to join the conversation.