WordPress.org

Forums

[IMPORTANT] Movabletype Importer Patch for WordPress 2.0 (20 posts)

  1. cubex
    Member
    Posted 9 years ago #

    First of all, I'm very sorry for not doing this completely right. Trac didn't let me in at all, FreeNode is down so I can't ask you guys what to do. I decided to post this patch anyway.

    There are a few problems with the current MT importer in WordPress 2.0:
    - Comments are inserted to database but without a comment_approved status. This causes WP to ignore them.

    - Pings permissions aren't inserted correctly. Pings are *always allowed. (Wrong variable name $post_allow_pings)

    - A new author is created with "subscriber" permissions on each import. (Tiny bug related to using $this->newauthornames[$j] instead of $this->newauthornames[$this->j]

    - <!--more--> tag is *always* because wp_kses_split2 says is "seriously malformed" :) I added a low-priority filter as a workaround.

    I guess that's it. Here's the patch if you're interested:

    Index: mt.php
    ===================================================================
    --- mt.php (revision 3378)
    +++ mt.php (working copy)
    @@ -54,7 +54,7 @@
    if (!(in_array($author, $this->mtnames))) { //a new mt author name is found
    ++ $this->j;
    $this->mtnames[$this->j] = $author; //add that new mt author name to an array
    - $user_id = username_exists($this->newauthornames[$j]); //check if the new author name defined by the user is a pre-existing wp user
    + $user_id = username_exists($this->newauthornames[$this->j]); //check if the new author name defined by the user is a pre-existing wp user
    if (!$user_id) { //banging my head against the desk now.
    if ($newauthornames[$this->j] == 'left_blank') { //check if the user does not want to change the authorname
    $user_id = wp_create_user($author, $pass);
    @@ -200,7 +200,7 @@
    preg_match("|-----nEXTENDED BODY:(.*)|s", $post, $extended);
    $extended = trim($extended[1]);
    if ('' != $extended)
    - $extended = "n<!--more-->n$extended";
    + $extended = "n%%%%more%%%%n$extended";
    $post = preg_replace("|(-----nEXTENDED BODY:.*)|s", '', $post);

    // Now for the main body
    @@ -243,11 +243,11 @@
    $post_convert_breaks = $value;
    break;
    case 'ALLOW PINGS' :
    - $post_allow_pings = trim($meta[2][0]);
    - if ($post_allow_pings == 1) {
    - $post_allow_pings = 'open';
    + $ping_status = trim($meta[2][0]);
    + if ($ping_status == 1) {
    + $ping_status = 'open';
    } else {
    - $post_allow_pings = 'closed';
    + $ping_status = 'closed';
    }
    break;
    case 'PRIMARY CATEGORY' :
    @@ -319,9 +319,12 @@

    $comment_content = $wpdb->escape(trim($comment));
    $comment_content = str_replace('-----', '', $comment_content);
    +
    + $comment_approved = 1;
    +
    // Check if it's already there
    if (!comment_exists($comment_author, $comment_date)) {
    - $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content');
    + $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_approved');
    $commentdata = wp_filter_comment($commentdata);
    wp_insert_comment($commentdata);
    $num_comments++;
    @@ -366,10 +369,12 @@
    $comment_content = "<strong>$ping_title</strong>nn$comment_content";

    $comment_type = 'trackback';
    -
    +
    + $comment_approved = 1;
    +
    // Check if it's already there
    if (!comment_exists($comment_author, $comment_date)) {
    - $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_type');
    + $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_type', 'comment_approved');
    $commentdata = wp_filter_comment($commentdata);
    wp_insert_comment($commentdata);
    $num_pings++;
    @@ -423,6 +428,12 @@
    }
    }

    +// Kses removes <!--more-->. Here's a nasty workaround :)
    +function mt_import_more_filter($data) {
    + return str_replace('%%%%more%%%%', '<!--more-->', $data);
    +}
    +add_filter('content_save_pre', 'mt_import_more_filter', 100);
    +
    $mt_import = new MT_Import();

    register_importer('mt', 'Movable Type', __('Import posts and comments from your Movable Type blog'), array ($mt_import, 'dispatch'));

  2. Kafkaesqui

    Posted 9 years ago #

    Patches are best submitted here:

    http://trac.wordpress.org/

    Large blocks of code intended for the forums are best posted here (and then linked to):

    http://paste.uni.cc/

  3. cubex
    Member
    Posted 9 years ago #

    I'm sorry about this. I tried logging in to Trac but it didn't accept my forum username and password, I'm not really sure why. If anybody has a working Trac account, please submit this patch for me.

    Anyway, here's the link to the diff, in case you want to download it: http://pastebin.com/482508

  4. gusterlover6
    Member
    Posted 9 years ago #

    Does it matter which line I put this patch on? Or just the mt.php file? I'd really like to fix my comment problem, thanks in advance.

  5. Ryan Boren
    WordPress Dev
    Posted 9 years ago #

    Try this updated version of import/mt.php. This doesn't integrate the "more" fix. That will be fixed in kses. This should fix the comment problems though. Thanks cubex.

  6. gusterlover6
    Member
    Posted 9 years ago #

    Hmmm, I still don't have any comments listed, but thanks.

  7. duncanf
    Member
    Posted 9 years ago #

    Many thanks for posting this - I did think I was going mad when my comments weren't showing up even though WP listed them in the import.

    I've replaced mt.php with your patched version, but I am getting the error:

    Cannot redeclare class mt_import in /home/blogname/public_html/wp/wp-admin/import/mt.php on line 3

    On the main Import page. Any ideas?

  8. duncanf
    Member
    Posted 9 years ago #

    Just to address my previous comment - I fixed the problem. It was simply a schoolboy error of renaming the original mt.php to mt-old.php for safe-keeping. WP obviously tries to initialise all files in this directory, hence the class conflict.

    I can confirm that this patch works great and MT's comments are now imported. The duplicate author creation problem also seems to have been fixed.

    Many thanks for this patch, cubex.

  9. djblurb
    Member
    Posted 9 years ago #

    So you have to reimport your MT entries? What a pain.

  10. gusterlover6
    Member
    Posted 9 years ago #

    Hooray! They work after I deleted the old ones and re-imported them. Thank you so much.

  11. bhw
    Member
    Posted 9 years ago #

    This looks like it's going to work. Thank you so much for the patch. I was horrified to see that none of my comments had been imported, even though the import message said they were.

    The biggest annoyances:

    --As a new WP user, I had no idea where to delete all the newly imported posts so I could start over. The Manage page doesn't seem to let you delete posts in batches, just one at a time. (Is that right?) I finally saw that I could delete the posts by deleting the user name associated with them.

    --In retrospect, it would be great (new feature alert!) if the import tool would give you the option of overwriting previously imported posts, so that you wouldn't have to delete the posts to import a "newer" version of them with the same title.

    --When recreating the user name and reimporting the posts, the numbering for the user names and posts started where it left off the last time. So on a completely new installation of WP, I was up to user ID 12 (I chopped my MT export file to bits for the import, and a new user was created for each file import) and my first post starting with #400-something. So I asked my web host to blow my installation and db away and do a fresh install. I'd just like it to start off a clean and logical.

    That said, the import looks to be pretty darn simple. I've been waiting to migrate from MT for a while -- the improved import feature was just what I've been waiting for.

    Thanks again for the patch ....

  12. morgspace
    Member
    Posted 9 years ago #

    Hi

    I'm getting the same "Fatal error: Cannot redeclare class mt_import in ../wp-admin/import/mt.php on line 3" problem that duncanf had, but I
    - just downloaded WordPress 2.0 from WordPress.org today (I'm a new user although I have some familiarity with PHP and MySQL)
    - tried to import from TypePad (=MovableType) for the first time
    - have relocated all other files in the import directory so that they're no longer in wp-admin or any subdirectory of wp-admin

    The guidance on importing from MovableType here: http://codex.wordpress.org/Importing_from_Movable_Type_to_WordPress refers to a different file, import-mt.php, which has presumably been replaced in the new version of WordPress?

    Current user comments here: http://wordpress.org/support/topic/54526?replies=6 suggest that I'm not alone.

    Any ideas?

  13. cubex
    Member
    Posted 9 years ago #

    WP2 has a completely different import system than WP1, so it doesn't have the import-mt.php anymore. What I found out is that mt.php.

    Just so you know, this patch has a workaround for a kses bug. It's *not* the correct way to do it, but I figured I shouldn't be messing around with kses.

    I think WP team has already fixed the bugs in MT imported, you should probably be using the latest from SVN instead of applying this patch:
    http://svn.automattic.com/wordpress/trunk/wp-admin/import/mt.php

    If the kses bug is fixed, then you won't lose your <!--more--> tags anymore. Like I said, my fix was a nasty workaround :)

  14. morgspace
    Member
    Posted 9 years ago #

    Thanks for the comment, but I still get the redeclaration error.

    My WP2.0 install is clean - the first time that I've used it. I've made a few modifications on the presentation side, but that only affects files in wp-content.

    This is bugging me a little - I'd have shifted over from TypePad by now if it worked...

    I'm running PHP 4.3.11 - anyone know if this makes any difference?

  15. Ali_ix
    Member
    Posted 9 years ago #

    The Comments Status and comment count fixed in new version ?

  16. Lenium
    Member
    Posted 9 years ago #

    And could you please tell me how I should delete 760 enteries to reimport?! is there an option to delete all posts at the same time?

  17. tomeppy
    Member
    Posted 9 years ago #

    I'm having this exact same problem. Has anyone come up with a fix?

  18. html2006
    Member
    Posted 9 years ago #

    I am interquartile has understood it, thanks, it is very useful.

  19. j0hnt3l4d
    Member
    Posted 9 years ago #

    I am still having numerous issues. Are there any other patches to the mt.php file? I am running PHP 4.2.2.

  20. j0hnt3l4d
    Member
    Posted 9 years ago #

    Okay, I will try to submit this to the codex, but I was able to correct the issue by changing the line
    include(ABSPATH . "wp-admin/import/$importer.php");
    to
    include_once(ABSPATH . "wp-admin/import/$importer.php");.
    What I don't understand is how this works for everyone else. Is it something with my version of PHP?

Topic Closed

This topic has been closed to new replies.

About this Topic