I'm thinking that something like the following would be a good thing for many modules to have:

<?php
/**
 * Implimentation of hook_init
 *
 * Ensures the database table is available on startup.
 * Prevents getting ugly errors on first run.
 * Just an enhancement step to make installation easier and automatic.
 * ... should really be in some run-once code.
 * @author .dan. dan[at]coders.co.nz
 */
function event_init(){
  $module = 'event';
  if(
      (! variable_get($module.'_db_initialized',FALSE))
      &&
      ($filepath = drupal_get_path('module',$module)."/$module.mysql")
    ){
      $queries = explode(";",file_get_contents($filepath));
      foreach($queries as $query){
        if(trim($query)){
          db_query($query);
        }
      variable_set($module.'_db_initialized',true);
    }
  }
}
?>

It's not needed but it's nice.

Comments

killes@www.drop.org’s picture

Status: Active » Closed (won't fix)

This is extremely non-nice and will never be added to any module I maintain:

- the init hook is called even on cached pages
- to execute the hook, you need to load the whole event module
- this will slow your site down
- for every page view
- and just for some ease of installation?
- I'd rather prefer you don't use the module if you cannot install it as it is. Or use CivicSpace or get a hosted installation.

dman’s picture

I am totally aware that hook_init is the wrong place to put it, hence my post over here saying we need a hook_setup()
http://drupal.org/node/33203
Even so, the 'slowing down' is only for the duration of one if( variable_get() )

I said 'something like' because I'm not putting this forward as a verbatim patch. Just a possible direction for improvement.

I suggested it for this module, because the last few I installed failed gracefully with a useful message, while this one just crashed the whole page. Rather than just say how sucky that was, I suggested a practical way to stop the module from crashing.

I'm obviously capable of installing each and every MYSQL snippet myself the long way, but I've got multiple sites to deploy to, clients to support, documentation to write, and this would save a few steps, especially when automating the installs.

I thought I was being constructive. One thing about many of the modules here is that they are a little lightweight on testing their environment is as expected. Feedback from people who are installing on different systems may bring to light a few points the developer takes for granted.

Sorry you don't want me to use the thing at all...