July 16, 2009

Another Fight With Movable Type

So there I was, writing a short post about something, when I needed to embed an image. I cliecked the "Insert Image" button in my Movable Type blogging software, uploaded the image, and...it wouldn't let me create a thumbnail image.

Thumbnailing is done by the Perl Image::Magick module and, sure enough, when I checked Movable Type's listing of the status of Perl modules, it displayed an error:

Image::Magick

Your server does not have Image::Magick installed, or Image::Magick requires another module that is not installed. This module is needed if you would like to be able to create thumbnails of uploaded images. Please consult the installation instructions for help in installing Image::Magick.

I logged a trouble ticket with my hosting service, and in a few minutes Diego had re-installed Image::Magick. He said it passed all the tests, and I'm inclined to believe him, but it didn't fix my problem.

It was time to poke around in the guts of Movable Type to see if I could find anything that could cause this. First, however, I decided to upgrade to the latest version of Movable Type. Why tinker with an old version which I'd only be replacing anyway? Besides, the upgrade might fix the problem.

So I downloaded MT version 4.261, dumped it into the appropriate directory, and ran the upgrade script. Everything worked fine. Or so it seemed.

A few minutes later, I noticed that if I clicked through to the permalink on one of my posts, I got an error message instead of the blog content. E.g.:

Page not found - /archives/2009/07/still_searching_for_that_elusi.html

Not good. Nobody could comment, or even read an article that they'd found by searching.

Now I logged a trouble ticket with Movable Type. The response was surprisingly fast, and included a couple of suggestions...which didn't actually help fix the problem.

Meanwhile, I tried restoring the old version of the PHP page rendering engine, since that's what was spitting out the error message. Ta Da! Everything worked fine again.

I downloaded both the old and new PHP rendering directories and did a diff across all the files. Then I probed for the problem by first swapping in groups of new files until I found the problem in the database code. Then I swapped in individual database code files until I had narrowed it down to the "/php/lib/mtdb_base.php" file.

Finally, I swapped in bits of new code until I found the problem in the resolve_url() function. The highlighted line is the bad one:

    function &resolve_url($path, $blog_id) {
        $path = preg_replace('!/$!', '', $path);
        $path = $this->escape($path);
        $blog_id = intval($blog_id);
        # resolve for $path -- one of:
        #      /path/to/file.html
        #      /path/to/index.html
        #      /path/to/
        #      /path/to
        global $mt;
        $index = $this->escape($mt->config('IndexBasename'));
        $escindex = $this->escape($index);
        foreach ( array($path, urldecode($path), urlencode($path)) as $p ) {
            $sql = "
                select *
                  from mt_blog, mt_template, mt_fileinfo
                  left outer join mt_templatemap on templatemap_id = fileinfo_templatemap_id
                 where fileinfo_blog_id = $blog_id
                       and ((fileinfo_url = '%1\$s' or fileinfo_url = '%1\$s/') or (fileinfo_url like '%1\$s/$escindex%%'))
                   and blog_id = fileinfo_blog_id
                   and template_id = fileinfo_template_id
                   and template_identifier != 'backup'
                 order by length(fileinfo_url) asc
            ";
            $rows = $this->get_results(sprintf($sql,$p), ARRAY_A);
            if ($rows) {
                break;
            }
        }
        $path = $p;
        if (!$rows) return null;

        $found = false;
        foreach ($rows as $row) {
            $fiurl = $row['fileinfo_url'];
            if ($fiurl == $path) {
                $found = true;
                break;
            }
            if ($fiurl == "$path/") {
                $found = true;
                break;
            }
            $ext = $row['blog_file_extension'];
            if (!empty($ext)) $ext = '.' . $ext;
            if ($fiurl == ($path.'/'.$index.$ext)) {
                $found = true; break;
            }
            if ($found) break;
        }
        if (!$found) return null;
        $data = array();
        foreach ($row as $key => $value) {
            if (preg_match('/^([a-z]+)/', $key, $matches)) {
                $data[$matches[1]][$key] = $value;
            }
        }
        $this->_blog_id_cache[$data['blog']['blog_id']] =& $data['blog'];
        return $data;
    }

I don't really know what that line does, or why, but removing it fixed the problem and didn't seem to break anything else (that was obvious). Problem solved.

[Update: Movable type has let me know that the best solution is to change the line in red to read

and template_type != 'backup'

I tried it, and that did the trick.]

Of course, none of this fixed my original problem. Image::Magick still didn't work.

I just gave up. It turns out Movable Type can use alternative graphics libraries, so I switched to one of those.

I never did finish the original post.

Leave a comment

About this Entry

This page contains a single entry by Mark Draughn published on July 16, 2009 12:15 AM.

Still Searching For That Elusive Chicago Criminal Defense Blogger was the previous entry in this blog.

Chitika is the next entry in this blog.

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

Find us on Facebook

Unless you request otherwise, we will assume all messages are for publication and attribution.

Red links are Not Safe For Work NSFW.

Mark

About Mark

PGP key

Visit Mark on MySpace

Joel

About Joel

Visit Joel at twincitiescarry.com

Gary

About Gary

Article Syndication

Bloggy Goodness

Hit&Run
Cataloguing every inch of our daily slide down the slippery slope towards a more totalitarian state.
Reason
Free markets and free minds.
Virgina Postrel
Author, columnist, brings depth to the simplest subjects.
InstaPundit
Law professor, author, columnist, music engineer, the founding father of the blogosphere.
Marginal Revolution
Smart economists.
StrategyPage
News and commentary on all things military.
Google Blogoscoped
Smart writing about search technology.
Majikthise
Your basic working philosopher.
The Agitator
Radley Balko, libertarian at large.
Nobody's Business
Pro-Liberty. Anti-Nannies.
A Stitch in Haste
Kip Esquire, lawyer, investment banker, and full-time pop scholar.
Ravings of a Feral Genius
The one, the only, Jennifer.

War on Drugs

StoptheDrugWar.org
Taking the drug war debate to the blogosphere
Vice Squad
Vice, in all its forms. [review]
DrugWar Rant
More reasons every week for hating the War on Drugs.
DUI Blog
The road to hell is paved with good intentions and patrolled by Mothers Against Drunk Driving.
Last One Speaks
Injustice in the war on drugs.
The D'Alliance
The Drug Policy Alliance blog.
Vigil for Lost Promise
A counterweight to the DEA's exploitive site.

Chicagoland

BlogNetNews.com/Illinois
The Illinois blogosphere's front page.
Leslie's Omnibus
I have no idea what this blog is about.
Marathon Pundit
John Ruberry runs, drives, and blogs.
The So-Called "Austin Mayor" Blog
Just a tad to the left of my usual tastes, but always very interesting.

Blawgs

Indefensible
David Feige, creator of Raising the Bar and former public defender.
a Public Defender
Rants, explanations, and complaints from a public defender.
Simple Justice
Rants, explanations, and complaints from a private lawyer.
Defending People
The art and science of criminal defense trial lawyering
26th St. Bar Association
Chicago criminal defense.
ECILCrime
East Central Illinois criminal defense.
Austin Criminal Defense Lawyer
A decent blawg despite the SEO-friendly name.
Underdog Blog
Criminal defense, politics, and God only knows what else.
CrimLaw
A big, goofy, ballcap-wearing prosecutor who even likes dogs. [review]
Blonde Justice
Funny stories about criminal defense.
Crime & Federalism
Legal analysis and bitching about federalism issues. [review]
Seeking Justice
Tom McKenna, Virginia prosecutor on a mission from God.
Woman of the Law
Defendin', datin', drinkin'.
Prosecutor Post-Script
Sarena Straus, author and former Bronx D.A.
The Volokh Conspiracy
Smart legal experts.
Iowa Champion
Iowa criminal defense
The Legal Satyricon
Entertainment and First Amendment Law

Media

Eric Zorn
Real blogging at the Chicago Tribune, with real blogging software.
Miss Manners
A marvelous writer and deeper than you think.

Photography

iN-PUBLiC.com
Very cool modern street photography.
Digital Photography Review
Detailed reviews of digital cameras and vicious forum debates too.
Ken Rockwell
Strong opinions about photography.
Dan Heller
Photographs and the business of photography.
Bert P. Krages II
Photography and the law.

Resources

Institute for Justice
A merry band of libertarian litigators.
Bird Flu Breaking News
A bird flu news and blog aggregator.
EFF: Bloggers
The Electronic Frontier Foundation's page for bloggers.
Citizen ICAM
Map of recent criminal activity in Chicago. [review]
CIA World Factbook
A brief summary about every nation.
Wikipedia
The mostly-useful encyclopedia of everything.
Current Impact Risks
It has to happen some day.

Gone But Not Forgotten

Peter McWilliams
Ain't Nobody's Business If You Do

Credits

Copyright  ©  2002-2007 Mark Draughn. All rights reserved.

Site developed by
Draughn Software Corporation

Powered by Movable Type 4.261
Version 4.261

Downtown Host

Social networking tags courtesy of the Sociotags for Movable Type plugin by Ole Wolf.

Chicago lakefront image by Ken Gibson.

Admin

Valid XHTML 1.0 Transitional

Valid CSS

ICRA

Statistics

Adorama