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 [1]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.
Footnotes
↑1 | fileinfo_url = '%1$s' or fileinfo_url = '%1$s/') or (fileinfo_url like '%1$s/$escindex%%' |
---|
Leave a Reply