[development] Doing hook_update_N() when module is installed

Randy Fay randy at randyfay.com
Fri Nov 13 19:08:06 UTC 2009


Thanks for your comments on this!

While you're right that the original intent of hook_install() is to do a *
schema* setup and the original intent of hook_update_N() it to update that
when change occur down the line, they are both actually and widely used to
set up the Drupal configuration in non-schema ways so that it's ready for
the module.  You yourself mentioned in a later message a variable_set()
which is a configuration change, not a schema change.

I *think* that the reality is that these two functions are often used in a
variety of ways to make sure configuration is correct for the current
version of the module, not just in terms of schema.

You mention the idea of setting up something for cron to do... but that
would be a privately implemented hook_update_N, woudn't it?

In my case, which is a bit extreme, I'm writing a module whose only job is
to do one-off configuration changes to staging*.drupal.org. There are 10 of
these machines, and their configuration is slightly different from
Drupal.org, but they are occasionally reinstalled with D.o's database. That
means that the install needs to work to set the config correctly, and also
that when a config change is introduced, hook_update_N (or a similar
technique) needs to take care of it. We're trying to avoid reconfiguring
everywhere.

As others have mentioned, this pattern is quite common.

A valuable discussion. I'm interested in hearing more.

-Randy



On Fri, Nov 13, 2009 at 11:00 AM, Earnie Boyd
<earnie at users.sourceforge.net>wrote:

> On Thu, 12 Nov 2009 Randy Fay wrote:
>
>  I keep learning every day - and I'm glad to know about hook_enable(),
>> which
>> I didn't know about.
>>
>> I don't think it answers my question, though, since I'm concerned about
>> taking actions at install time, which would be hook_install(). And in my
>> particular case, the install actions are the same as the set of
>> hook_update_N(). The only way I know to include all those in
>> hook_install()
>> is either to duplicate code or to make a runner function. Both ugly.
>>
>>
> Why would hook_update_N be the same as hook_install?  The hook_install is
> for installing the database as described in the hook_schema.  The
> hook_update_N is reserved for schema changes.  The hook_enable can be used
> to execute your ``runner function'' as long as the ``runner function'' isn't
> modifying the database schema.  You need to be more specific with what
> you're doing in hook_install and hook_update_N.  You may also be interested
> in hook_requirements.
>
> --
> Earnie
> -- http://r-feed.com/           -- http://for-my-kids.com/
> -- http://www.4offer.biz/       -- http://give-me-an-offer.com/
>
>
>


-- 
Randy Fay
Drupal Development, troubleshooting, and debugging
randy at randyfay.com
+1  970.462.7450
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20091113/53b70f38/attachment.html 


More information about the development mailing list