« Pardon our dust! | Main | ピタゴラスイッチ »

Why use the MT GUI when MySQL has a CLI?

I had 500 or so entries I needed to define a default category for. I did about 100 with the entry bulk change GUI but even that was abysmally slow. I figured this had to be stored in a table somewhere, so I started poking around the database to see what I would find. mt_entry indeed has a "category_id" , but it curiously turned out be NULL for every entry, even ones with a single, default category. I pried around for about an hour to no avail until I was saved by Google leading me to a post by Mike Kruckenberg on his blog about Movable Type categories. Turns out that MT abandoned that field a while ago in favor of a linking table for mt_entry and mt_category called "mt_placement" (like that name was obvious) which allowed for primary and secondary categories. So after a bit of learning, translating my Oracle SQL to the MySQL dialect, I came up with the following one-stop query to set a default category (17, determined by looking through mt_category) for just one blog's entries that didn't already have a category assignment. In case it saves anyone the hour or two of hair-pulling, here it is (but be sure to change the blog ID and category ID as appropriate for you):


INSERT INTO mt_placement (placement_entry_id, placement_blog_id, placement_category_id, placement_is_primary)
SELECT e.entry_id, 1, 17, 1
FROM mt_placement p RIGHT OUTER JOIN mt_entry e ON p.placement_entry_id = e.entry_id
WHERE e.entry_blog_id = 1
AND p.placement_is_primary IS NULL;

Note that this does not catch the screwball case where an entry has secondary categories but no primary category, and would still post a primary category for the entry. (I'm not sure if the MT software actually would allow such a condition to occur, however.)

TrackBack

TrackBack URL for this entry:
http://blog.truegeek.org/tg-tb.cgi/2244

Post a comment

About

This page contains a single entry from the blog posted on January 2, 2007 4:59 PM.

The previous post in this blog was Pardon our dust!.

The next post in this blog is ピタゴラスイッチ.

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.34