#!/usr/bin/perl -w # # pingToRebuild.cgi by Mark Paschal # 1.0, 25 January 2003 # # Asks Movable Type to rebuild a blog's indexes, when pinged with a # weblogs.com-style ping from a particular Movable Type blog. # # # Copyright 2003 Mark Paschal # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. # # The ID of the weblog that pings this CGI. my $fromBlogID = 4; # The ID of the weblog to rebuild. my $toBlogID = 2; # The name of a template to rebuild, if you want to only build one template. # (This feature not actually tested.) my $template = undef; unshift @INC, './lib', './extlib'; use XMLRPC::Transport::HTTP; require MT; XMLRPC::Transport::HTTP::CGI -> dispatch_to('weblogUpdates') -> handle; package weblogUpdates; sub ping { my ($class, $weblogName, $weblogUrl) = @_; my $mt = MT->new; # Is this the 'from' blog pinging us? my $fromBlog = MT::Blog->load($fromBlogID); unless(defined($fromBlog)) { return {flerror => 1, message => "Couldn't get the blog object for the expected pinger: ". MT::Blog->errstr}; }; unless($fromBlog->name eq $weblogName and $fromBlog->site_url eq $weblogUrl) { return {flerror => 1, message => "($weblogName, $weblogUrl) isn't allowed to rebuild this weblog; only (". $fromBlog->name .", ". $fromBlog->site_url .")"}; }; if(defined($template)) { my $tmplObj = MT::Template->load(blog_id => $toBlogID, name => $template); unless(defined($tmplObj)) { return {flerror => 1, message => "Couldn't get the requested template object: ". MT::Template->errstr}; }; unless(defined($mt->rebuild_indexes(BlogID => $toBlogID, Template => $tmplObj, Force => 1))) { return {flerror => 1, message => "Couldn't rebuild indexes: ". $mt->errstr}; }; } else { unless(defined($mt->rebuild_indexes(BlogID => $toBlogID))) { return {flerror => 1, message => "Couldn't rebuild indexes: ". $mt->errstr}; }; }; return {flerror => 0, message => "I rebuilt the indexes. Yay me!"}; }