Gotcha in the upgrade_functions plugin argument

Plugins these days can, and often do, store their own data in their own custom object classes. The MT::Plugin class makes it very easy to set all that up for each plugin, along with versioning the overall data storage scheme for the plugin and allowing for routines to be run upon upgrading.

Here is an example cribbed from the documentation:

schema_version => 1.1,
object_classes => [ 'MyPlugin::Foo', 'MyPlugin::Bar' ],
upgrade_functions => {
    'my_plugin_fix_field_a' => {
        version_limit => 1.1,   # runs for schema_version < 1.1
        code => \&plugin_field_a_fixer
    }
}

Now, while I will readily admit this was very much a faulty assumption on my part, I thought that the keys of that upgrade_functions hash only needed to be unique within the plugin itself.

I was wrong. Very wrong.

The keys of that hash need to be unique within the entire MT installation. That means they cannot be the same as any of the core upgrade functions or any upgrade functions that other plugins might define. It look me about half an hour to track that one down.

Looking back on it now, it makes sense. Template tags, junk filters, text filters, and so forth all need to be unique within the system as well, so it being the same for upgrade functions really is not that surprising when you think about it.

So, I am publicly introducing the first of my plugin development best practices: Always prepend the name of the plugin to any key in the upgrade_functions hash argument.

Yes, this is pretty much what plugin authors do already with template tags (e.g. MTPluginNameTag), but it can't hurt to have this spelled out explicitly for upgrade_functions as well.

Leave a comment

About Me

I am a software developer for Six Apart living outside of Baltimore, MD. I have written a number of plugins for Movable Type, including the award winning MultiBlog, which has (as of MT 4) been integrated into the base application....
More...

Recent Entries

  • The Olympics Make Me Want To Complete Again

    Every time the Olympics come around (most the summer ones) I always start to delude myself into thinking I could complete once again in the...

  • Minimalist plugins are fun!

    Last night I whipped up one of the smallest plugins I’ve ever written. It is so small in fact that I was able to stuff...

  • Feedburner Widget on MT News

    Movable Type News A WordPress 2.5 Upgrade Guide: And of course there are lots of third-party plugins for the MT dashboard, to integrate statistics and...

  • AD&D Monster Stats for the Presidential Canditates

    Charles Stross (scifi author, D&D nerd, and former perl columnist) posted Politics as she is Played with 3d6: The recent death of Gary Gygax, who...

  • Feedburner Widget 0.3

    At this point, I am really tempted to drop the ‘Widget’ from the name of the plugin, since it is doing so much more...

Close