Question

My latest module does not seem to be loading .install when enabled. Here's the rundown:

I have a .module file implementing hook_menu() and hook_views_data().

Both appear to work fine, after enabling the module: navigating to the menu path works as expected and my new views base type is present.

I have a .install file implementing hook_install() hook_uninstall() and hook_schema()

None of the functions in the install file appear to run. The new tables are not present after enabling and there are no errors logged.

If I manually call the functions in the .install file with devel THEN I get an undefined error. I can only assume that the install file is not being loaded.

Running the .install file through the command line PHP interpreter doesn't bring up any syntactic errors.

I'm at a loss to explain why the file is not loaded into scope when the module is enabled.

I'd appreciate any assistance.

Was it helpful?

Solution

Turns out it was an error in hook schema() unfortunately the function failed more or less silently. For example :

'description' => array(
                'type' => 'varchar',
                'size' => 'normal',
                'not null' => TRUE,
                'description' => 'Description of vaule type.',
        ),

Failed.

'description' => array(
                'type' => 'varchar',
                'size' => 'normal',
                'length' => 255, 
                'not null' => TRUE, 
                'default' => '',
                'description' => 'Description of vaule type.',
        ),

Worked.

The problem was exacerbated by my mistakenly assumed notion that disabling and re-enabling a module would trigger the install, rather then the removal of the module from the system table.

Thanks again to everyone who provided feedback.

OTHER TIPS

If you added the install file after you enabled the module: disable the module, uninstall the module, then enable the module.

hook_install() is only executed the first time a module is enabled and if it is enabled after being uninstalled.

Just want to add this answer for future reference as my .install file wasn't loading and it took me a while to figure out what was wrong, so hopefully this can save someone some pain!

I had defined some update functions, e.g. hook_update_7101 but when I navigated to update.php it was saying 'no pending updates'. I added some debug statements and discovered that my functions weren't showing up when the call to get_defined_functions() was made (this is a php function). It was like PHP wasn't aware of the update functions.

It turns out that there were two versions of my module in Drupal. One at /sites/all/modules and another at /sites/sitename/modules. So the older version of the module at sites/sitename was overriding my newer version at sites/all.

So bottom line:

Check whether there are 2 versions of your module - one at sites/all/modules and another at sites/sitename/modules

I removed the older version of the module form /sites/sitename and the updates appeared as expected!

The installation file is only loaded during the installation, update process or to check the module requirements. Loading files on demand (when they're needed) saves the time for execution, memory and overall performance.

To include the install file of your module, you've to include it first, for example:

module_load_include('install', 'my_module');
Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top