Search the web
Sign In
New User? Sign Up
mt-dev · Movable Type Developers
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want your group to be featured on the Yahoo! Groups website? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Upgrading custom object for my plugin   Message List  
Reply | Forward Message #2085 of 2112 |
Re: [mt-dev] Upgrading custom object for my plugin

Jesse,

Its hard to be specific since you haven't posted any code but...

I don't think the MT api will remove the column. It is pretty good
add schema changes to add or modify existing columns, but I don't
think there is any logic in there to remove a column (but I am not
100% sure).

That said, since the new column is getting added, the remaining item is:

> * for each Object, retrieve it and:
> - login to our web service to get the proper api_key
> - update the new column with the key

And for this, your are correct, an upgrade function is the way to go.
I can't comment on what isn't working for you, of course.

Here's an example from one my plugins:

snippet from my .pl file, to register the upgrade function"

'upgrade_functions' => {
'import_images' => {
version_limit => 1.231, # runs for schema_version < 1.231 --
plugin version 1.5x
updater => {
type => 'author',
label => 'Importing author photos...',
condition => sub { !$_[0]->userpic_asset_id },
code => '$UserProfile::UserProfiles::Pro::Util::import_images',
}
},
},

and the function itself:

sub import_images {
my ($author) = @_;
return if $author->userpic_asset_id;

...code here to import image, create asset, etc. (you api
fetching stuff would go here)

# now update the object
$author->userpic_asset_id($asset->id)
or MT->log("Error adding asset to author: " . $author->errstr);
$author->save;
}

As you work on it, try to log any errors to the MT activity log, or to
STDERR, as that can help identify issues along the way...

Hope this helps,

Mark



On Thu, Aug 28, 2008 at 2:02 PM, jesse <jessedp@...> wrote:


> Hello all. I'm putting out an updated version of our MT plugin and am having
> some issues with the upgrade scripts b/c I need to up the schema version.
> For the DB table change, I "simply" want to drop one column (a password
> field) and add another (an api key field). Because of that, I need to do
> something like this:
>
> * add the new column to the table
> * for each Object, retrieve it and:
> - login to our web service to get the proper api_key
> - update the new column with the key
> * drop the column from the table
>
> Honestly, I sincerely doubt anyone using this has actually set this up on
> more than one blog, so even adding/dropping the column during the "for each"
> would likely be fine, though I would rather do it right just in case.
>
> I've been trying to accomplish this using the "upgrade_functions" param when
> I init my plugin as shown here:
>
>
>
http://www.movabletype.org/documentation/developer/movable-type-registry-referen\
ce.html

>
> Of course I've also updated my Custom Object's "install_properties",
> removing the one field & adding the other.
>
> So far the upgrade script is running, but this is all I see:
> ---
> * Upgrading table for mailchimp_list records...
> * Plugin 'MailChimp Subscribe Form' upgraded successfully to version 1.1
> (schema version 1.1).
> ---
> From what I can tell, my "updater" "code" is not being run at all. When I
> check the db table, I can see that the new column is added, but the old
> column is not being removed. Given that result, I'm pretty sure I could hack
> in some code to clean things up in my plugin code, but I'd really rather do
> it the right way.
>
> I've really tried digging through some other plugins and the core MT code,
> and am just not having any luck figuring this out.
>
> Oh, also, I'm running MT 4.1.
>
> Any help or suggestions anyone can provide would be greatly appreciated.
>
> thanks,
>
>
> jesse
>
>



Thu Aug 28, 2008 5:41 pm

bsakamano
Offline Offline
Send Email Send Email

Forward
Message #2085 of 2112 |
Expand Messages Author Sort by Date

Hello all. I'm putting out an updated version of our MT plugin and am having some issues with the upgrade scripts b/c I need to up the schema version. For the...
jesse
jessedp23
Offline Send Email
Aug 28, 2008
5:03 pm

Jesse, Its hard to be specific since you haven't posted any code but... I don't think the MT api will remove the column. It is pretty good add schema changes...
Mark Carey
bsakamano
Offline Send Email
Aug 28, 2008
5:41 pm

Thanks for the reply, Mark. Sorry for not posting code, but I had literally followed the example on the page I referenced to the tee. Anywho, here's my ...
jesse
jessedp23
Offline Send Email
Aug 28, 2008
6:15 pm

... This is correct, it must match the object type you have defined. Each object passing the "condition" will get passed to the "code" function, so your first...
Mark Carey
bsakamano
Offline Send Email
Aug 28, 2008
7:25 pm

Turns out I wasn't paying attention to the ever so important placement of a closing brace, so my entire upgrade_functions section was not in the registry...
jesse
jessedp23
Offline Send Email
Aug 28, 2008
7:49 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help