Reset Basename Script

This script is for Movable Type users that want to start over from scratch with their basenames. It's useful for cases like where you expand the basename from 40 characters to 100 and want to create a new, harmonized set of basenames for a consistent approach across your site. As is always the case in this sort of situation, there is no warranty, there is no claim that this script works 100% to description, and I shall not even shed crocodile tears for your blog if you uncomment those lines at the bottom, run it without backing up your database and everything falls apart.

use strict;
use lib ('./lib/', './extlib');
use MT::Entry;
use MT::Util;

my @entries = MT::Entry->load({});

foreach my $entry (@entries)
{
        my $basename = $entry->basename();
        $entry->basename(undef);
        my $newname = MT::Util::make_unique_basename($entry);
        if ($newname eq "$basename\_1") { $newname = $basename; }
        $entry->basename($newname);
    
    ##Enable this ONLY when you are ready to make the change!!!!
        #$entry->save();
        print "$basename\t" . $entry->basename() . "\n";
}
 

One quick note, to specify a blog, put blog_id => X where X is the blog id number of the blog you wish to target on your installation of Movable Type inside the {} brackets in the load statement at the top.

No TrackBacks

TrackBack URL: http://www.codemonkeyramblings.com/mt/mt-tb.cgi/1339

3 Comments

So, I'm curious and I'm a little daft. What does one do with thi script?

Put it in the root of your MT installation, and it will spit out a list of your old basenames and new basenames to the command line. If you take out the comments at the bottom of the script, it will save the changes to the database.

I had run this script successfully on a prior version. But now when I'm trying to use it on MT Pro 4.261, the following error appears:

Can't locate object method "instance" via package "MT::ObjectDriverFactory" at lib//MT/Object.pm line 862.

Any ideas?

Leave a comment

March 2010

Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Recent Entries

A window into the totalitarian mind of the left on freedom of religion
From Digg: Me: I'm not going to hold my breath waiting for the same liberal democrats who shriek about the…
Google's lossy compiler
Google's closure compiler service gets a little too frisky under ADVANCED_OPTIMIZATIONS. Original code: With advanced optimizations enabled, it was able…
The three purposes of the federal income tax law
Businesses will spend about 3.4 billion man-hours and individuals about 1.7 billion hours figuring out their taxes this year.…

Subscribe

Advertisements

OpenID accepted here Learn more about OpenID