« Changes here at CN | Main | A rough weekend »

Fixing Movable Type's non-permanent permalinks

Almost no one will care about this post, so please feel free to ignore it before you read any further. It describes a solution I found for an annoying bug in Moveable Type's web publishing software. I'm posting it here because I'm sure there are others out there who will struggle with the same problem, so hopefully they can find the solution here through some quick Googling.

So anyway, I was porting my blog to a different server, using MoveableType's import/export routines to transfer all my posts. The import/export feature worked great... except for the fact that it did not preserve entry IDs. When the old posts were brought into the new site, they were assigned an entry ID rather arbitrarily, via an auto-increment function. Generally speaking, all my posts were now assigned a different entry ID than they had on the old site. A consequence of this is that it broke essentially every link to my site that exists on the Internet. That is not good.

Fortunately, a fix proved to be pretty easy. So easy, in fact, that it's astonishing that Movable Type hasn't incorporated it into its more recent versions. Anyway, here's how you go about doing it. The good thing about Movable Type is that you get all the source code for it, so that you can hack it in cool ways like this.

First you have to fix the export routine on your old MT installation. Find the CMS.pm library file (usually located in the App directory under lib) and get ready to add a couple of lines of code. Don't pay much attention to the lines numbers here, because those will vary from version to version. Find a place in the code that looks something like this:

2959 AUTHOR: <$MTEntryAuthor$>
2960 TITLE: <$MTEntryTitle$>
2961 STATUS: <$MTEntryStatus$>
2962 ALLOW COMMENTS: <$MTEntryFlag flag="allow_comments"$>
2963 CONVERT BREAKS: <$MTEntryFlag flag="convert_breaks"$>
2964 ALLOW PINGS: <$MTEntryFlag flag="allow_pings"$>
2965 PRIMARY CATEGORY: <$MTEntryCategory$>

and add a line for the entry ID to make it look like this:

2959 AUTHOR: <$MTEntryAuthor$>
2960 ID: <$MTEntryID$>
2961 TITLE: <$MTEntryTitle$>
2962 STATUS: <$MTEntryStatus$>
2963 ALLOW COMMENTS: <$MTEntryFlag flag="allow_comments"$>
2964 CONVERT BREAKS: <$MTEntryFlag flag="convert_breaks"$>
2965 ALLOW PINGS: <$MTEntryFlag flag="allow_pings"$>
2966 PRIMARY CATEGORY: <$MTEntryCategory$>

Save your changes and close the file, and you're done fixing the export routine. Easy, right?

Now go to the MT installation on the new server and edit the same file, CMS.pm. Find the following chunk of code:

7446 } elsif ($key eq 'TITLE') {
7447 $entry->title($val);
7448 } elsif ($key eq 'DATE') {
7449 my $date = $app->_convert_date($val) or return;
7450 $entry->created_on($date);

and make it look like this:

7446 } elsif ($key eq 'TITLE') {
7447 $entry->title($val);
7448 } elsif ($key eq 'ID') {
7449 $entry->id($val);

7450 } elsif ($key eq 'DATE') {
7451 my $date = $app->_convert_date($val) or return;
7452 $entry->created_on($date);

Now just run the import and export routines as specified in the manual. All should be well.


1001001 SOS
1001001 In distress...

Your "hack" worked beautifully with MT 3.2.

In 3.3, however, the CMS.pm file has changed considerably. So I do not know where to paste your piece of code. Any suggestions?

Zurich, Switzerland


Evidently the place where this code resides varies greatly from version to version. I just found an even older MT installation of mine (3.121) and I notice that in *that*
case the export routine was found in a library called ImportExport.pm, which existed one level up from CMS.pm in the directory structure.

Now I don't know the details of your installation, but if you have shell access, you
would probably be able to grep through all of your library files to find the right place.

I would search for the string "sub export". That should probably indicate
which library contains the export routine, and the layout therein should be somewhat similar to
what I had in my post.

Let me know if you have any more questions. If we can figure this out, I can update my original post. I didn't realize at the time how very version-specific my fix was. I wish
MT wouldn't move stuff around so much. ;-)

Good luck.

HeVXea hi nice site thanks http://peace.com

uGp0iF fw831f64td9glse934dkjga

great read.

ok, as you said, i decided to ignore it, lol, jk, good read.

Post a comment