Sorry, geeky argot ahead.
Easy trick to mass-modify MT powered blogs content: start from the list-objects script (it is in the tools/ directory) and add regular expression based substitution.
So for example, suppose you moved all your images from the "images" directory to a "newimages".
You'll need an easy and consistent way to modify all the references in you content.
So let's copy our list-objects into a new script and call it regex-object:
# cp tools/list-objects tools/regex-objects
this gives us a good starting point to iterate through the blog's entries.
We can then modify the loop like:
#!/usr/bin/perl -w use strict;use lib 'lib', '../lib';
my %opts;
use Getopt::Long;
GetOptions("class=s", \my($class),
"id=i", \my($id),
"cols=s", \my($cols),
"config=s", \my($cfg));
$class or die "usage: $0 --class=[--id= ] [--cols= ] [--config= ]"; use MT;
my $mt = MT->new(defined $cfg ? (Config => $cfg) : ()) or die MT->errstr;eval "use $class;";
die "Error loading '$class': $@" if $@;my @args;
@args = ($id) if $id;
my $iter = $class->load_iter(@args) or
die "Load failed: " . $class->errstr;
$cols = $cols ? [ split /\s*,\s*/, $cols ] : $class->column_names;
print join(':', @$cols), "\n";
while (my $obj = $iter->()) {
my $text = $obj->column("text");
$text =~ s/src="\/images\//src="\/newimages\//g;
print "New Text: \n$text\n";
$obj->text($text);
$obj->save;
}
~
And well, this is just a simple proof of concept. I'm sure you can find even more interesting uses for this tool :)
I'm actually planning a little refactoring here and would like to spare you a few broken links ;)

Leave a comment