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();
+ }
}
/**
Comment | File | Size | Author |
---|---|---|---|
#6 | common.inc_.drupal_get_schema_unprocessed.1.patch | 573 bytes | oadaeh |
#4 | common.inc_.drupal_get_schema_unprocessed.1.patch | 571 bytes | oadaeh |
#2 | common.inc_.drupal_get_schema_unprocessed.1.patch | 571 bytes | oadaeh |
#1 | common.inc_.drupal_get_schema_unprocessed.1.patch | 544 bytes | oadaeh |
includes.common.inc_.diff | 463 bytes | pillarsdotnet | |
Comments
Comment #1
oadaeh CreditAttribution: oadaeh commentedSomething similar is in 7.x. I created a patch based on that code.
Comment #2
oadaeh CreditAttribution: oadaeh commentedPatch created from the correct directory.
Comment #3
David_Rothstein CreditAttribution: David_Rothstein commentedLooks 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(
....Comment #4
oadaeh CreditAttribution: oadaeh commentedI totally missed what you were obviously saying. Sorry. Here's the corrected patch.
Comment #5
David_Rothstein CreditAttribution: David_Rothstein commentedCode 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.
Comment #6
oadaeh CreditAttribution: oadaeh commentedUpdated 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.
Comment #7
Gábor HojtsyThanks, committed.