Rebuilding individual archives when pinged

I’ll be breaking my TrackBack pretty thoroughly for a bit, and then possibly breaking it for some people for a while, trying to persuade MT to rebuild my individual archive page for an entry when it gets pinged.

Update: unless I’m missing something, that didn’t take long.

The problem: when you receive a TrackBack ping, Movable Type needs to do everything it does with the ping before it sends a reply to the person who pinged you, so that it can tell them whether or not the ping worked. That sets a time limit on how much it can do, before their program decides that the ping has taken too long and gives up. So MT adds the ping to your database, rebuilds the RSS file for that entry’s pings, rebuilds all your index templates in case they have TrackBack counts in them, mails you a notification, and calls that good enough. It doesn’t try to rebuild archives, in case it takes too long to get that done, which is a problem for those of us who don’t like popups, and display our TrackBack pings on the individual archive page with the comments.

So far, the three solutions I’ve see are: my solution, which involves using PHP to include the output from the CGI program the popup calls, with the template stripped down to just the stuff I want included in the page; the direct solution of having PHP get the TrackBack data from your MySQL database without going through MT at all; one I haven’t seen done, using PHP to parse the RSS file of pings and include that in the page; or the manual solution of rebuilding yourself when you get an email TrackBack notification. The first three solutions are tolerable, but not very slick; the fourth is too much trouble to suit me, and is likely to get you pinged multiple times, if you aren’t there to rebuild when someone thinks their ping didn’t go through since they don’t see it on the page.

If you have a fair amount of faith in the speed of your rebuilds (or in your TrackBackers’ willingness to keep trying, or to let you know that there’s a problem), you can hack in support for rebuilding archives, or just rebuilding the individual entry page for the entry that was pinged. Fairly obviously, this isn’t a hack for the faint of heart.

First, you might want to save a backup copy of {your MT directory}/lib/MT/App/Trackback.pm, to save yourself the trouble of redownloading it when things go south. Then, look for the lines (starting at 199 in my copy):

    $app->rebuild_indexes( Blog => $blog )
        or return $app->_response(Error =>
            $app->translate("Rebuild failed: [_1]", $app->errstr));

and directly below that add:

    if ($tb->entry_id) {
      $app->rebuild_entry( Entry => $entry, BuildDependencies => 0 )
          or return $app->_response(Error =>
            $app->translate("Archive rebuild failed: [_1]", $app->errstr));
    }

That will rebuild all the archive files for the entry that was pinged, individual, date-based, and category, so if you have TrackBack counts in all of your archive types that’s probably what you want, but that’s the sort of rebuild that Ben expected would take long enough that pings would time out. If all you want is to rebuild the individual archive page for the entry, use:

    if ($tb->entry_id) {
      $app->_rebuild_entry_archive_type( Entry => $entry, ArchiveType => "Individual")
          or return $app->_response(Error =>
            $app->translate("Archive rebuild failed: [_1]", $app->errstr));
    }

and then post a message along the lines of:

I’m experimenting with rebuilding individual archives when an entry gets a TrackBack ping. If you have trouble pinging me, please let me know about it. Also, you might try setting a longer value for PingTimeout in your mt.cfg file.

and let me know how it works for you, and feel free to ping this entry mercilessly to see how it works for me.

66 Comments

Comment by Reverend Jim #
2002-12-18 22:32:33

I have the same problem. If you do figure out how to persuade it, please let us all know how you did it.

 
Comment by Mark #
2002-12-19 15:00:07

You can also do it with server-side includes, if your ISP allows them. In your .htaccess file, set

Options +Includes

Then in your individual archive template, put this where you want the inline trackbacks to go:

<MTEntryIfAllowPings>
<!–#include virtual=”<$MTCGIPath$><$MTTrackbackScript$>?__mode=view&entry_id=<$MTEntryID$>” –>
</MTEntryIfAllowPings>

Then change your trackback template so it just includes the actual stuff you want to display inline (i.e. it’s not a full web page anymore, so no HTML or HEAD tags, etc.)

Comment by Thomas #
2003-08-19 14:05:34

oh cool , it works – thanks tom

 
 
Comment by Phil Ringnalda #
2002-12-19 20:24:44

Yeah, including the cgi works, but it doesn’t please me anymore like it did when I first started using it. It’s not pretty, and worse yet it’s standing in the way of my being able to treat TrackBacks as remote comments, intermingled with the local comments in the right chronological order. We’ll see whether my Perl lack-of-skillz are up to the task (especially since I half finished it in August and then forgot everything I’d done when I realized I’d need the archives to rebuild), but that’s what I’ve got in mind. So far, looks like it’s working okay: thanks to some reshuffling and rebuilding that got me repinged, plus some new pings, I’ve gotten a half-dozen without any reports that I’m unpingable. Fingers are crossed.

 
Comment by Mark Paschal #
2002-12-24 13:13:51

Oops:

TrackBacks

Warning: Failed opening ’http://philringnalda.com/mt/mt-tb.cgi?__mode=view&entry_id=2421’ for inclusion (include_path=’.:/home/.quin/philor/philringnalda.com/phplib/pear:/home/.quin/philor/philringnalda.com/phplib/pear/PEAR’) in /home/.quin/philor/philringnalda.com/archives/002421.php on line 197

 
Comment by Mark Paschal #
2002-12-24 13:15:22

Only now not so much.

 
Comment by Phil Ringnalda #
2002-12-24 13:30:05

NightmareHost identified a vulnerability in their MySQL servers yesterday, so they’ve been making them safe by making them unavailable: chances are you caught a moment when PHP couldn’t include the CGI because the CGI couldn’t do jack because it couldn’t connect to the DB. That’s my guess anyway. So far I haven’t heard from anyone that a ping failed, though Ghu knows everything else around here is failing off and on.

 
Comment by Phil Ringnalda #
2002-12-24 13:39:30

Oh, that ping did more-or-less fail, didn’t it? Just noticed that it didn’t build the TrackBack RSS file or send the email notification, which means that it died while rebuilding (not unusual with NightmareHost, though, the way it’ll sometimes die instantly when you post a comment or save an entry. Too bad I’m too lazy to move out.)

 
Comment by Mark Paschal #
2002-12-24 16:15:03

Well, it posted here as far as I could tell. Can’t really tell from this end.

 
Comment by Phil Ringnalda #
2002-12-24 16:29:45

It’s not still in the ”URLs to ping” textarea for the entry? I can’t figure any way that it could fail to build or email without returning an error to you or timing out, so MT should still be patiently waiting for you to save that entry again, at which point it’ll try to ping again.

 
Comment by jh #
2003-01-19 05:49:34

Duh… I turned on TrackBack auto-discovery and then went ahead and manually added the URL to be pinged. So you were pung twice. Sorry, I get it now. Honest.

-jh

 
Comment by Joshua Kaufman #
2003-02-14 06:49:09

Phil: same hack for 2.51?

Thanks.

 
Comment by Joshua Kaufman #
2003-02-14 06:52:04

Also, slightly related, did you have to add a hack so that your TrackBacks and Comments intermingle as they do on this post. I’m talking about how you list a trackback, another trackback, then a comment, then another trackback. How does that work? Thanks again.

 
Comment by Phil Ringnalda #
2003-02-14 07:35:24

Joshua: I’m not sure yet. I foolishly didn’t put this post in my MT Hacks category, which is where I look after an upgrade, so I didn’t check last night, and this morning (which is no-time-to-spare morning), I just noticed that my comment RSS feeds have the closing tag of a CDATA section after the comment body (without the opening tag), so they are rather completely broken. With a little luck, I’ll get that this morning, and check/fix this tonight.

Meantime, no, the intermingled comments and trackbacks are just Adam Kalsey’s SimpleComments plugin – no hacking, just drop in a plugin and change a couple of tags around a bit.

 
Comment by Phil Ringnalda #
2003-02-14 23:22:45

Yes, exactly the same hack to rebuild archives when pinged for 2.6 – even the line numbers are unchanged.

 
Comment by Anonymous #
2003-03-03 09:43:44

Worked like a charm! Woohoo!!

Damn. Just realized I didn’t ask permission to use the code, which obviously is copyrighted. My mistake. ;-)

Muchas gracias. Merci beaucoup. etc, etc.

Comment by Liz Lawley #
2003-03-03 09:44:56

Ooops. Following a link and then hitting ”back” apparently wipes out the contact info. Didn’t mean to post anonymously…

Comment by Phil Ringnalda #
2003-03-03 10:47:43

Since that’s how most of my anonymous comments come about (my own and other people’s), it would probably be worthwhile sticking a ”Did you really mean to post anonymously?” page into the process. Most people who really mean it will come up with a Dear Abby-style name anyway, so it shouldn’t catch many of them, just us when we don’t notice that we aren’t remembered. Hmmm. I don’t think the comment error template gets used for anything else if you allow anonymous comments, so it might not even be too involved a hack – if everything’s blank, return the error template with ”Anonymous” filled in for the name.

 
 
Comment by Phil Ringnalda #
2003-03-03 13:01:57

You’re welcome!

I have considered the licensing issue, but it just hasn’t seemed like it would be that much fun to write the Trivial Software Hack License myself, and none of the existing Free licenses actually say what I want – use it however you want, modify it as you please, no warranty, redistribute modifications as you like but distribute the original by link rather than by copying, to cut down on confusing versioning problems. Free redistribution of chunks of code big enough to deserve version numbers isn’t much of a problem, since people have a way of finding out whether they are getting a current copy, but if a dozen people post the actual hack rather than a link, and then I realize there’s a typo or it would be ten times faster with a tiny change, someone searching for it has to figure out that they should look for the canonical version rather than using any random copy. And since everyone that I know of who has ever used any of my hacks has behaved exactly as I would want them to behave, without any prompting from me, I’ve resisted writing a formal license. (Plus, <whispered>strictly speaking, by redistributing modified chunks of MT’s code, I’m actually violating its license, so any license I put on it would probably be invalid anyway</whispered>.)

Comment by Liz Lawley #
2003-03-03 15:44:01

And since everyone that I know of who has ever used any of my hacks has behaved exactly as I would want them to behave, without any prompting from me, I’ve resisted writing a formal license.

Ah…but would you be likely to know about the ones who didn’t behave that way? :-)

At any rate, it was oh-so-nice to find something that did exactly what I needed, worked as advertised, and didn’t break anything in the process. Not a common occurrence for me when it comes to computers (or children, for that matter).

 
 
 
Comment by THomas #
2003-08-13 23:33:21

Thanks for the ’Manual Trackback’ script idea

 
Comment by bomber0 #
2003-08-15 04:35:46

It worked !! Thanks ~

 
Comment by Andrea #
2003-08-30 02:31:36

thanks for the cool script

 
Comment by Michael Croft #
2003-11-15 11:13:41

Excellent hack. Since I’m also avoiding duplicate trackback pings, the notification failure is not such a big deal, because the dup doesn’t show up.

I wish we could spawn off asyncronous rebuilds or a callback function for pings so we didn’t have to wait. I may look at that, but Perl isn’t my first language…

 
Comment by Martin Roell #
2004-02-04 01:40:52

The hack first did not work for me. Then I figured out that the problem was the mt-blacklist plugin: When it was running, checking a trackback against the list and rebuilding the entry took too much time and the script was terminated by the webserver resulting in the pinged entry not being rebuilded. Deactivating mt-blacklist solved the problem.

Comment by Timothy Quinn #
2004-02-17 03:25:37

Thanx Martin, I had the same problem. But how can you make it work with the mt-blacklist plugin?

 
 
Comment by Joshua Kaufman #
2004-06-18 17:45:38

Is this needed in MT 3.0D? Same files?

Comment by Phil Ringnalda #
2004-06-18 18:37:29