.module files are not currently included during a modules installation. Although this is manageable for individual modules, it becomes a larger issue when you are try to create a complex installation file.

Attached is a simple patch to include a modules .module file before hook_install is called.

CommentFileSizeAuthor
#3 include.module.patch625 bytesmikejoconnor
include.module.patch633 bytesmikejoconnor

Comments

mikejoconnor’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch failed testing.

mikejoconnor’s picture

StatusFileSize
new625 bytes

Recreated the patch

damien tournoud’s picture

Status: Needs work » Needs review
moshe weitzman’s picture

FYI, I think we have the same issue for update functions. This looks like a good patch to me. Lets get more feedback.

damien tournoud’s picture

Status: Needs review » Reviewed & tested by the community

I got bitten by this one too. Let's get this in.

webchick’s picture

Status: Reviewed & tested by the community » Needs review

I'm not sure about this change.

We use hook_requirements() to verify that pre-requisites exist prior to enabling a module and loading all of its code. For example, if I'm building ExternalLibrary module which requires ExternalLibrary.php to be in the includes directory, in hook_requirements() I can check to make sure that this is there *before* Drupal will load the .module code. Otherwise, I have to wrap all of my function calls to ExternalLibrary.php in my .module file within ugly function_exists() calls. Puke.

Can someone verify that this continues to work (denying the enabling of a module during hook_requirements() op install even when the .module contains functions that are not defined) even with this patch?

sun’s picture

Status: Needs review » Reviewed & tested by the community

I quickly discussed with Damien in IRC, and the point is: the .module file has always been special... it makes sense to keep it this way.

If your module unconditionally tries to load additional files that do not ship with the module itself, that code should either run not in the global scope, or simply check for its existence.

Additionally, _drupal_install_module() is altered here, which only runs after any requirements have been met.

dries’s picture

I'm delegating this patch to webchick because of comment #7. Her call.

dww’s picture

@webchick: Your module only has to conditionally check for the external file(s) in functions that you plan to invoke (directly or indirectly) inside hook_install() and hook_enable(). Simply including foo.module doesn't mean every code path in there is going to be evaluated. This should go in.

webchick’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs documentation

Ok, this was all I was asking for in #7, which looks like it wasn't clear:

example.info:

name = Example
description = Example
core = 7.x
files[] = example.install
files[] = example.module

example.install:


function example_requirements($phase) {
  $t = get_t();
  $requirements['dummy'] = array(
      'title' => $t('Dummy'),
      'value' => $t('Dummy failure: the banana library is not loaded.'),
      'severity' => REQUIREMENT_ERROR,
    );
  return $requirements;
}

example.module:

banana();

And making sure that fatal errors didn't spew everywhere when it was enabled.

But in the process of writing that, I just went ahead and did it, and confirmed that the error is caught before it includes the .module file. Committed to HEAD.

Please document in the 6.x => 7.x upgrade docs that people no longer need to do include this manually.

rfay’s picture

Assigned: Unassigned » rfay
rfay’s picture

Sorry, @webchick, I'm ready to document but can't quite follow what you said. You say in #11 "Please document in the 6.x => 7.x upgrade docs that people no longer need to do include this manually".

What is it that people no longer need to do manually? Thanks.

webchick’s picture

rfay, what I meant was an entry entitled like ".module file available during install" "In the past, in order to call a module's functions during any hooks within its .install file, you would have to have code like "include drupal_get('module', 'foo') .'/foo.module'; As of Drupal 7, the .module file and its functions are available in .install, once the hook_requirements() checks are satisfied."

rfay’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)
Issue tags: -Needs documentation

Automatically closed -- issue fixed for 2 weeks with no activity.