1

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.

2
  • 1
    Can you confirm that both the .install file and the hooks are named properly and are consistent with the .module file? That is the only time I have seen this happen.
    – mpdonadio
    Sep 1 '11 at 21:06
  • @MPD I created a new module and changed the name(s) such that I now have: temp.info temp.module temp_menu() temp_views_data() temp.install temp_install() temp_schema() temp_uninstall() Still no go
    – SMTF
    Sep 2 '11 at 21:40
2

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.

1
  • Manual removal of the row in the {system} should not be necessary, an uninstallation (on the separate local task) should have the same effect.
    – Berdir
    Oct 2 '11 at 23:59
0

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.

3
  • Alright I should have mentioned that I have installed and uninstalled the module several times. Also I didn't try to install the module without an install file.
    – SMTF
    Sep 1 '11 at 20:44
  • 2
    SMTF -- try deleting the row describing the module from your system table, then enable your module again. Manually calling the functions shouldn't work (in other words, that undefined function error is correct. I can't help much more than that without seeing your .install file.
    – Entendu
    Sep 1 '11 at 21:13
  • @Entendu That's a good idea; unfortunately it didn't solve the problem (which surprised me).
    – SMTF
    Sep 2 '11 at 21:44
0

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!

0

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');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.