MT5 lastn comments bug hack

Once again, I have had to hack Movable Type’s Perl source code to fix an error they made. The <mt:Comments> tag that loops through the comments takes an argument “lastn” which is supposed to tell it how many of the most recent comments to retrieve. But instead of retrieving the n most recent comments, MT was retrieving the n oldest comments! Exactly the opposite of what it was supposed to do!

This bug has been known to the MT community for quite awhile. Apparently, it cropped up in version 4.3, and here we are in version 5 and it’s still there! I didn’t see anyone with any good hacks to fix it, so I figured this one out myself. I do dislike hacking the source code (I have said this before), but when you gotta, you gotta.

I added a single line of Perl code to

/lib/MT/Template/Tags/Comment.pm

at around line 301. This hack fixed the problem:

if ($so) {
    $args{'direction'} = $so;
} else {
    $args{'direction'} = 'descend';
}

## Added this line to fix bug:
$args{'direction'} = 'descend';

my $cmts = $e->comments(\%terms, \%args);
my $offset = $args->{offset} || 0;
...

Sorry if these techie posts bore you. They bore me. But I have to blog them, if only to remember everything I did. I have to re-do all of my hacks if I update the software.

Permalink
Category:
Topic: ,

Comments on this entry:

There are 4 comments on this entry.
#1
1 Feb 2010
5:37 PM

Looks good on my Android phone. I’ll check it out when I get home from my walk to the (closed) butcher shop.

#2
1 Feb 2010
5:40 PM

But why are you walking to the closed butcher shop? Is it a breaking-and-entering kind of thing?

#3
1 Feb 2010
6:30 PM

It had no reason to be closed.

I walked there to buy some meat. Annoying.

#4
6 Apr 2010
3:20 AM

Instead of hacking the code, you could just provide a sort order. I had the same bug, but modified my template so that instead of this:

| last by ,

I had this:

| last by ,

Worked like a charm!

Leave a comment

(Thanks for reading all the way to the bottom.)

Sean Gleeson is an artist, developer, writer, teacher, statesman, and family man in Oklahoma City, Oklahoma.

See full profile.

Sean Gleeson Sean Gleeson