Help - Search - Members - Calendar
Full Version: Rebuild Multiple/All Blogs
Movable Type Community Forum > Additional Resources > Tips and Tricks
thescribe
Any way to set this feature up on future versions?  Where I can update all my blogs (or better yet, multiple blogs) that are on the same site with one click.
nefarious
I second that. Please!

Those of us that are misusing the product as a content manager would really appreciate it wink.gif
ndns
I wonder if you could misuse MTRebuild to do that? wink.gif

I would be interested to hear if that works for either of you or not. Good luck.
almuhajabah
According to this it should work.
ndns
Yes, I understand the documentation and all. From what I have read, though, you would either have to run it as a cron or by logging in with shell access.

Is it possible to just navigate your browser to http://www.example.com/mt/mt-rebuild.pl and have the script do it's thing that way?
charle97
why would you need to rebuild blogs like that?
ndns
One scenario that I can think of is that your site is composed of multiple blogs. The templates for each blog are the same, linked to a file. You update that file and want the changes to take effect on all of the blogs it is linked to.
charle97
if you have ssi or php available, you can output the relevant content from each blog and then use include statements to build the page's content.
girlie
There's a script in this thread to run a rebuild from the browser - it's for a single blog only, though.

Can anyone write the Perl code to loop through all blogs? wink.gif
ndns
Awesome, girlie. Thanks for the link. Sorry I didn't search first. sad.gif
bakken
Hope this will help others with this same problem--I'm using MT to run a website, more as a Content Mangement System than a single blog, so I have several blogs that all need to use the same templates. I just took the perl script that girlie linked above and copied everything but the last line

CODE
print "Finished: ".(localtime())."<br>\n";


for each blog. What I ended up with was one long file of this script repeating, and I just changed the blog number after I pasted the script. At the end of the scirpt, I made sure that the
CODE
print "Finished: ".(localtime())."<br>\n";
was tagged on to the end.

Initial testing shows that it works and it works fast when I enter changes to an index template. I'll keep working with it.

Here's an example for 2 blogs, note the repeating code and all that is changed is the blog id number.

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 = 1; # 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" }
);
#!/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 = 2; # 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" }
);
ndns
Nice job, bakken. Only one thing...
CODE
print "Finished: ".(localtime())."<br>\n";

...was not tacked onto the end like you said. Can it just be added at the very end of the code you posted or is there something that needs to come before it?
-lc-
I've been wanting to do this and noticed no one has ever gotten a good answer here how to go about doing it. So I am going to try to tackle it myself.

I'm studying the rebuild_confirm.tmpl template to see if I can hack it to add "Rebuild all blogs" as an option.

I also know about this http://www.pyrojection.com/rebuild.html
and this http://www.mplode.com/tima/files/mt-plugins#mt-rebuild

anything else I've missed that might give me some ideas?

I'm open for suggestions and ways to approach this...

Thanks for any help!
maddy
Topics merged. smile.gif
-lc-
I now have a web based script available for beta testing to rebuild all blogs from the rebuild button:

http://www.movabletype.org/support/index.p...ST&f=14&t=27300
nolageek
QUOTE (charle97 @ Aug 30 2003, 04:47 PM)
if you have ssi or php available, you can output the relevant content from each blog and then use include statements to build the page's content.

Well, This works untill you start linking to archives of your sub-blogs. At snoship.org I use a separate blog for the Main Site, another for Talk of the Town, and another for Movers and Shakers. (This makes it easier for the people who admin it. I don't want to deal with teaching them about categories and such. Plus this way I can expand on these sections later)

I use MTOtherBlog & MTInclude to pull the header/footer/sidebar templates from the main Blog. Plus use PHP include to pull the various data from the other blogs.

The problem is that once I change the header or footer I have to rebuild each separate blog.

Vincent
-lc-
I wanted to post that I have now created a perl script to rebuild all blogs that does browser output! smile.gif Yay!

This is due with great thanks to bakken and Timothy Appnel (tima) who's scripts I studied carefully and hacked up a bit...

I'm still making the output pretty and consistant to the mini-rebuild window that MT makes. It can be triggered by a bookmark or by a simple hack to the rebuild_confirm.tmpl template to add a "rebuild ALL blogs"

I'm also encountering a severe browser limitation for realtime output (which is why I suspect the rebuild scripts so far have been shell driven mostly). Seems that server-push technology never came about since IE never supported it. So you get this big pause while it rebuilds, and you get rebuild report at the end. Trying to find a workaround for that.

But if anyone is desperate, I have a MT-REBUILD-ALL.pl immediately available... wink.gif
-lc-
I now have solved the server push problem with some fancy dhtml to do a pull from the cgi. I also have integrated it with the MT rebuild dialog.

If anyone is wanted to beta test this "mt-rebuild-all" script, I think I am ready for some gineau pigs tongue.gif

Works great on the two sites I have tested so far.

see here for more info:
mt-rebuild-all.cgi on MT forums
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.