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


Important note: Due to a flood of spam, I've set the comment filter to mercilessly delete comments that mention the names of certain high-end designer fashion items. So don't mention anything like that if you want your comment to survive.


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

Ken

About Ken

Gary

About Gary

Joel

Article Syndication

Libertarian-ish

Hit & Run
Cataloguing every inch of our daily slide down the slippery slope towards a more totalitarian state.
Virgina Postrel
Author, columnist, and famous kidney doner.
The Agitator
Radley Balko, libertarian at large.
Nobody's Business
A blog about negative liberty.
Ravings of a Feral Genius
The one, the only, Jennifer.
Honest Courtesan
Notes from a retired call girl.

Bloggy Goodness

Duly Noted
Yet another Lindsay Beyerstein blog.
InstaPundit
Law professor, author, columnist, music engineer, the founding father of the blogosphere.
StrategyPage
News and commentary on all things military.
Last One Speaks
A complicated woman with simple tastes.
Ethics Alarms
Jack Marshall at large.

War on Drugs

StoptheDrugWar.org
Taking the drug war debate to the blogosphere
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.
The D'Alliance
The Drug Policy Alliance blog.
Vigil for Lost Promise
A counterweight to the DEA's exploitive site.

Blawgs

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
Probable Cause
The legal blog with the really low standard of review.
Unwashed Advocate
Former Military Underdog
Indefensible
David Feige, creator of Raising the Bar and former public defender.
Koehler Law Blog
Don't be fooled by how pretty it is
Not Guilty
A lawyer in search of a clue.
Norm Pattis
Norm will fight for you!
The Legal Satyricon
Entertainment and First Amendment Law
Gamso - For the Defense
An Ohio criminal defense lawyer
Criminal Defense
It's like a criminal defense blog, but from Florida
ECILCrime
East Central Illinois criminal defense.
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. [review]
Seeking Justice
Tom McKenna, Virginia prosecutor on a mission from God.
The Volokh Conspiracy
Smart legal experts.
D.A. Confidential
Making prosecutors seem just like normal lawyers
Crime and Consequences Blog
Because we're just not punishing people enough
Graham Lawyer Blog
Interesting writing about the law.
New York Personal Injury Law Blog
Better than you'd think from the SEO-friendly name
West Virginia Criminal Law Blog
Also better than you'd think from the SEO-friendly name
South Carolina Criminal Defense Blog
And one more that's better than you'd think from the SEO-friendly name

Geek Stuff

Schneier on Security
Smart thinking about computers and other security problems.
The Daily WTF
Crazy stories about bad things inside computer software and how they got there.
xkcd
Extremely geeky comics.
Google Blogoscoped
Smart writing about search engine technology.
The Altruist
Agony Unleashed in EVE Online.

Economics

Steven Landsburg
The Armchair Economist
Greg Mankiw's Blog
Aurhor of the most popular macroeconomics textbook
Marginal Revolution
Everything happens in the margins
Megan McArdle
Business and economics

Photography

Strobist
How to light everything in the world with speedlights
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.

Chicagoland

Leslie's Omnibus
I have no idea what this blog is about.
Marathon Pundit
John Ruberry runs, drives, and blogs.

Media

Eric Zorn
Possibly the Chicago Tribune's first blogger.
Miss Manners
A marvelous writer and deeper than you think.
Roger Ebert's Journal
A great writer and a useful film critic.

Resources

WolframAlpha
Data + Computation = Fun Knowledge.
Institute for Justice
A merry band of libertarian litigators.
EFF: Bloggers
The Electronic Frontier Foundation's page for bloggers.
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

Web Rings

Credits

Copyright  ©  2002-2011 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

Claim Your Avvo Profile