Mass-editing MT blog entry contents

| | Comments (0) | TrackBacks (0)

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 ;)

0 TrackBacks

Listed below are links to blogs that reference this entry: Mass-editing MT blog entry contents.

TrackBack URL for this entry: http://bru.bzaar.net/mt/mt-tr4ckm3.fcgi/726

Leave a comment

Find recent content on the main index or look in the archives to find all content.

Recent Activity

Today

  • Bru tweeted, "congrats to @hrheingold !"
  • Bru tweeted, "that was, sore kara."
  • Bru tweeted, "slre ,a"
  • Bru saved the link Rails Plugin: dynamically_tags
  • Bru tweeted, "@mazphd congrats!"
  • Bru tweeted, "ephemeral javascript time"

Wednesday

  • Bru tweeted, "@waugaman no prob, just send over your email (maybe in a dm)"
  • Bru tweeted, "introduced http://wakeme.at, my experiment with FireEagle, in a long-ish blogpost: http://tinyurl.com/64dq8t"
  • Bru tweeted, "hmm... looks like my Movable Type instance on Dreamhost fell into Internal Server Error hell. :-/"
  • Bru tweeted, "hmm... looks like my Movable Type instance on Dreamhost fell into Internal Server Error hell. :-/"
  • Bru tweeted, "going back to my slicehost playground after what seems a long while"
  • Bru tweeted, "going back to my slicehost playground after what seems a long while"
  • Bru tweeted, "srsly intense day. and only 2 coffee shots. yay!"
  • Bru tweeted, "srsly intense day. and only 2 coffee shots. yay!"
  • Bru tweeted, "retweeting: speak rails? Headshift wants you. DM, send pidgeons, smoke signals, just get in touch."
  • Bru tweeted, "retweeting: speak rails? Headshift wants you. DM, send pidgeons, smoke signals, just get in touch."
  • Bru saved the link Social network popularity around the world
  • Bru tweeted, "feels like a bottleneck"
  • Bru tweeted, "feels like a bottleneck"
  • Bru tweeted, "it's engine war o'clock here in the office"

Pages

Powered by Movable Type 4.2-en