Help - Search - Members - Calendar
Full Version: One Click "Scriptable" Rebuild
Movable Type Community Forum > Additional Resources > Tips and Tricks
mkelley
I want to create a way to rebuild one of my Movable Type by simply clicking on a bookmarklet or by setting up a scriptable link through something like Windows's built-in scheduler or cron under *nix.

I know when you click on "Rebuild Files" that button takes you to a popup that is actually

CODE
"mt.pl?mode=start_rebuild&blog_id=x .


If you select "rebuild all" it will flash a status of page rebuilds up and then change to this url

CODE
mt.pl?__mode=rebuild&blog_id=x&type=Individual,Daily,Monthly,index&next=3&offset=&limit=&total_entries=18&is_bm=&entry_id=&is_new=


So what I can see is that this script will rebuild blog_id x and the individual, daily, monthly, and index files. Then I can't follow it.... then it lists the total entries . I don't want anything fancy, just something I can click or assign to rebuild all of the files at once without having to enter the MT admin console.
xxAxel1xx
Got this from Brad Choate, this page in particular.  But, his version had to be run from the shell (which is a fine way to do it if you want to do cron stuff), but I wanted to run it from a browser.  So, I took his code (this is entirely Brad Choate's except for me changing it to be run from a browser) and turned it into this:

CODE
#!/usr/bin/perl -w
use strict;

# Usage: mt-rebuild.pl
# add this to your cron file to automate rebuilds. example:
#
#0 0 * * * /path/to/mtdir/mt-rebuild.pl
#
# The above will rebuild blog #1 at 12 AM (your server's time)

print "Content-type: text/html \n\n";

# INSERT YOUR BLOG ID BELOW
my $blog_id = 8; # blog id here
if (!$blog_id) {
   print STDERR "usage: mt-rebuild.pl (Blog ID)\n";
   exit 1;
}

my($MT_DIR);
BEGIN {
   if ($0 =~ m!(.*[/\\])!) {
       $MT_DIR = $1;
   } else {
       $MT_DIR = './';
   }
   unshift @INC, $MT_DIR . 'lib';
   unshift @INC, $MT_DIR . 'extlib';
}

require MT;

my $mt = MT->new(Config => $MT_DIR . 'mt.cfg',
                Directory => $MT_DIR);

require MT::Blog;

my $blog = MT::Blog->load($blog_id);

if (!$blog) {
   print STDERR "failed to load blog $blog_id\n";
   exit 1;
}

print "Rebuilding Blog: ".$blog->name."<br>\n";
print "Started: ".(localtime())."<br>\n";

$mt->rebuild(
  BlogID => $blog_id,
  EntryCallback => sub { print ' - ',$_[0]->title, '('.$_[0]->id.')', "<br>\n" }
);
print "Finished: ".(localtime())."<br>\n";


Just change the path to perl (if needed), change the blog id, and place this in your mt folder (wherever you keep mt.cgi).  You can call this whatever you want.  Then you just run it like any other file and it will print out what it's rebuilding.  It will rebuild your whole site.

Hope that helps,
Kyle
mkelley
I'll try it, thanks!
emsdc
I'm trying to think of a way that I can test whether I have this working properly, once I set it up. In my case, the automated rebuild is something that will only visibly affect my site about once per month, and I never know when that will be. I'm using it to make sure my "daily index" gets refreshed and shows a blank page when no entries have been posted for 24 hours. But that's a rare event, so I'm not sure how to test this. Ideas? Thanks...

ps I guess maybe I'll have to set up a hidden "daily index" and do a test that way by not posting anything to that index for 24 hours and seeing what happens... But is there any other way to test if this is working?
LisaJill
MTAdminLink might give you some ideas for doing this, as well... it has a rebuild option. =)
azemat
QUOTE (xxAxel1xx @ Nov 2 2002, 12:44 AM)
Got this from Brad Choate, this page in particular.  But, his version had to be run from the shell (which is a fine way to do it if you want to do cron stuff), but I wanted to run it from a browser.  So, I took his code (this is entirely Brad Choate's except for me changing it to be run from a browser) and turned it into this:

CODE
#!/usr/bin/perl -w
use strict;

# Usage: mt-rebuild.pl
# add this to your cron file to automate rebuilds. example:
#
#0 0 * * * /path/to/mtdir/mt-rebuild.pl
#
# The above will rebuild blog #1 at 12 AM (your server's time)

print "Content-type: text/html \n\n";

# INSERT YOUR BLOG ID BELOW
my $blog_id = 8; # blog id here
if (!$blog_id) {
   print STDERR "usage: mt-rebuild.pl (Blog ID)\n";
   exit 1;
}

my($MT_DIR);
BEGIN {
   if ($0 =~ m!(.*[/\\])!) {
       $MT_DIR = $1;
   } else {
       $MT_DIR = './';
   }
   unshift @INC, $MT_DIR . 'lib';
   unshift @INC, $MT_DIR . 'extlib';
}

require MT;

my $mt = MT->new(Config => $MT_DIR . 'mt.cfg',
                Directory => $MT_DIR);

require MT::Blog;

my $blog = MT::Blog->load($blog_id);

if (!$blog) {
   print STDERR "failed to load blog $blog_id\n";
   exit 1;
}

print "Rebuilding Blog: ".$blog->name."<br>\n";
print "Started: ".(localtime())."<br>\n";

$mt->rebuild(
  BlogID => $blog_id,
  EntryCallback => sub { print ' - ',$_[0]->title, '('.$_[0]->id.')', "<br>\n" }
);
print "Finished: ".(localtime())."<br>\n";


Just change the path to perl (if needed), change the blog id, and place this in your mt folder (wherever you keep mt.cgi).  You can call this whatever you want.  Then you just run it like any other file and it will print out what it's rebuilding.  It will rebuild your whole site.

Hope that helps,
Kyle

Thanks.

In this way, when i was Run this file, all Entries in my Blog was rebuild.
If i want, only Main Index Template was rebuild, What do i do?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.