Posted by pillarsdotnet on July 10, 2008 at 4:15pm
| Project: | Drupal core |
| Version: | 6.x-dev |
| Component: | install system |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
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();
+ }
}
/**| Attachment | Size | Status | Test result | Operations |
|---|---|---|---|---|
| includes.common.inc_.diff | 463 bytes | Idle | FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch includes.common.inc_.diff. | View details |
Comments
#1
Something similar is in 7.x. I created a patch based on that code.
#2
Patch created from the correct directory.
#3
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(....#4
I totally missed what you were obviously saying. Sorry. Here's the corrected patch.
#5
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.
#6
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.
#7
Thanks, committed.
#8
Automatically closed -- issue fixed for 2 weeks with no activity.