Fixing Broken Archive Links After MT4 Upgrade

Tonight I realized that the upgrade I did from MovableType 3 to MovableType 4 broke any and all links to my old articles once I had rebuilt my blog. The problem lies in the configuration option named “Basename Length” under Preferences->Blog Settings->Entries in MT4. The default value in MT4 is 30, whereas the default setting in MT3 was 15. Now I thought I could easily fix this by changing the value to 15 in MT4 and republishing my site, but that didn’t work. So instead I wrote this little PHP script to make copies of all my old archives articles and truncate the filenames to 15 characters. Now thinking about it, what I should have done - instead of making copies of the files, is create files with truncated filenames but that contain a PHP Header() directive that points at the current article with the 30 character filename. Anyway, here’s the script I wrote. Maybe it will help someone else. Be sure to CHMOD -R a+w archives/* before you run the script so that the script has permissions to create the new files. Then make sure you put the permissions back to what they should be when you’re done.

<?php


function changeext($directory, $verbose = false) {
$num = 0;
if($curdir = opendir($directory)) {
while($file = readdir($curdir)) {
if($file != '.' && $file != '..') {

$srcfile = $directory . '/' . $file;
$string  = "$file";
$str     = strlen($ext1);
$str++;
$newfile = substr($string, 0, 15);
$newfile = $newfile.'.php';
$dstfile = $directory . '/' . $newfile;

if (eregi("\.php",$file)&&(strlen($file)>19)) {
($srcfile, $dstfile);
//echo "copy $srcfile, $dstfile“;
}

if(is_dir($srcfile)) {
$num += changeext($srcfile, $verbose);
}
}
}
closedir($curdir);
}
return $num;
}

changeext(’archives’,  ‘false’);

?>

0 Responses to “Fixing Broken Archive Links After MT4 Upgrade”


  1. No Comments

Leave a Reply