Make WordPress Core

Opened 16 years ago

Closed 15 years ago

#8252 closed defect (bug) (fixed)

WXR import is broken and tags are not imported for posts correctly

Reported by: kaankivilcim's profile kaankivilcim Owned by: tott's profile tott
Milestone: 2.7 Priority: high
Severity: major Version: 2.7
Component: Import Keywords: wxr import, tags, 2.7-beta3, has_patch
Focuses: Cc:

Description

As of upgrading to 2.7-beta3 the WXR import functionality within WP is broken.

While the import appears to work correctly, when you explore the tags for the blog you'll see that all of the legit tags are present but not associated with any posts. Instead of associating the legit tags with the posts there's an identical number of numeric tags created that are associated with the posts. See the attached screenshot for what I mean as it's hard to explain.

To replicate this:

1) Install a clean installation of WP 2.7-beta3

2) Login, create a post with some text in the title and body. Assign a few random tags to the post and assign the post to a new category

3) Export the entire blog to a file, save the file

4) Delete all the database tables for this installation

5) Reinstall WP 2.7-beta3

6) Login, import the WXR file you exported previously

7) Go to manage the Tags and see with your own eyes the issue

The WXR file exported appears to be fine, it's the import process which is breaking.

I've also posted this to the forums here:

http://wordpress.org/support/topic/218112?replies=1

Attachments (2)

import-tags.jpg (53.1 KB) - added by kaankivilcim 16 years ago.
int_aware_trim.diff (1.4 KB) - added by tott 16 years ago.
patch against revision 9797

Download all attachments as: .zip

Change History (13)

#1 @mrmist
16 years ago

Confirming this against an export from 2.6.3. Tags looks fine in the xml file.

Tags are associated with posts, but imported only as numeric values.

#2 @ryan
16 years ago

This happened before in #5330.

#3 @tott
16 years ago

  • Keywords added
  • Owner set to tott
  • Status changed from new to assigned

@tott
16 years ago

patch against revision 9797

#4 @tott
16 years ago

  • Keywords has_patch added; removed
  • Resolution set to fixed
  • Status changed from assigned to closed

the problem is caused by wp-includes/post.php line 1680.

$tags = array_map('trim', $tags);

This causes that arrays with tag_ids are converted to strings which then get treated as tags by wp_set_object_terms.

I added a small helper function in function.php which returns the integer instead of the trimmed string.

#5 @ryan
15 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

It's not resolved until committed.

#6 @ryan
15 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [9803]) Remove trim. fixes #8252

#7 @ryan
15 years ago

Removed the trim.

#8 @tott
15 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Not sure if removing the trim will work best as whitespaces in comma seperated tags will still be there then.

In a tag string like

tag1, tag2, tag3

The spaces in around the tags will be preserved. Not sure if its filtered at some other place already. But Putting the trim around the whole $tags string will only trim from the beginning and end of this whole string with comma seperated tags.

In general this should not be a problem as things should get filtered on other places, but under some cirumstances it might cause trouble. For example I could reproduce one scenario where adding a post with comma seperated list of tags always the first tag in the list had a space appended when I checked it in the database.

#9 @DD32
15 years ago

Not sure if its filtered at some other place already.

The function which inserts the term strips whitespace too.

#10 @tott
15 years ago

Still the issue with appended space for first tag in a comma seperated tag list is there. I was able to reproduce it.

#11 @ryan
15 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

That trim snuck in recently as part of some notice fixes. If we want it we should address it in a separate ticket opened against 2.8. We've had to remove tag trimming in a few places because it can break things and I don't want to retest this stuff for 2.7.

Note: See TracTickets for help on using tickets.