When uninstalling a module that does not implement a hook_schema function (particularly, when module_invoke(module, 'schema') returns a non-array), the following warning is shown:

warning: Invalid argument supplied for foreach() in /var/www/drupal6/includes/common.inc on line 3115.

The problem is that the drupal_get_schema_unprocessed() function expects module_invoke($module,'schema') to return an array. If the module hook is unimplemented (for example, in a module that has no need to define a database table) then the return value will be NULL rather than the expected array.

The obvious solution is to explicitly check for NULL, or better yet, a non-array, and substitute with an empty array.

A simple patch follows:

--- orig/drupal-6.3/includes/common.inc 2008-07-09 17:48:27.000000000 -0400
+++ patched/drupal-6.3/includes/common.inc  2008-07-10 12:05:14.000000000 -0400
@@ -3150,9 +3150,12 @@
   if (!is_null($table) && isset($schema[$table])) {
     return $schema[$table];
   }
-  else {
+  elseif (is_array($schema)) {
     return $schema;
   }
+  else {
+    return array();
+  }
 }

 /**
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

oadaeh’s picture

Version: 6.3 » 6.x-dev
FileSize
544 bytes

Something similar is in 7.x. I created a patch based on that code.

oadaeh’s picture

Patch created from the correct directory.

David_Rothstein’s picture

Status: Needs review » Needs work

Looks like the D7 change went in as part of the big patch at #306151: Automatically install/uninstall schema, and it definitely seems like a reasonable backport to me.

The code looks good but the first line has a { where it should have a (....

oadaeh’s picture

Status: Needs work » Needs review
FileSize
571 bytes

I totally missed what you were obviously saying. Sorry. Here's the corrected patch.

David_Rothstein’s picture

Status: Needs review » Reviewed & tested by the community

Code looks fine, so I'll mark it RTBC (but with the caveat that I haven't actually applied the patch and tested it).

In theory http://drupal.org/coding-standards suggests using "elseif" rather than "else if" but that's not really applied consistently in Drupal 6 anyway (only Drupal 7), so no big deal.

oadaeh’s picture

Updated patch to account for the recent Drupal 6 releases. Also makes elseif one word and adds a blank line before the return statement, which is how many of the other functions in that file operate.

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, committed.

Status: Fixed » Closed (fixed)

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