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();
+  }
}
/**
Files: 
CommentFileSizeAuthor
#6 common.inc_.drupal_get_schema_unprocessed.1.patch573 bytesoadaeh
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch common.inc_.drupal_get_schema_unprocessed.1_2.patch.
[ View ]
#4 common.inc_.drupal_get_schema_unprocessed.1.patch571 bytesoadaeh
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch common.inc_.drupal_get_schema_unprocessed.1_1.patch.
[ View ]
#2 common.inc_.drupal_get_schema_unprocessed.1.patch571 bytesoadaeh
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch common.inc_.drupal_get_schema_unprocessed.1_0.patch.
[ View ]
#1 common.inc_.drupal_get_schema_unprocessed.1.patch544 bytesoadaeh
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch common.inc_.drupal_get_schema_unprocessed.1.patch.
[ View ]
includes.common.inc_.diff463 bytespillarsdotnet
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch includes.common.inc_.diff.
[ View ]

Comments

Version:6.3» 6.x-dev
StatusFileSize
new544 bytes
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch common.inc_.drupal_get_schema_unprocessed.1.patch.
[ View ]

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

StatusFileSize
new571 bytes
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch common.inc_.drupal_get_schema_unprocessed.1_0.patch.
[ View ]

Patch created from the correct directory.

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 (....

Status:Needs work» Needs review
StatusFileSize
new571 bytes
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch common.inc_.drupal_get_schema_unprocessed.1_1.patch.
[ View ]

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

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.

StatusFileSize
new573 bytes
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch common.inc_.drupal_get_schema_unprocessed.1_2.patch.
[ View ]

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.

Status:Reviewed & tested by the community» Fixed

Thanks, committed.

Status:Fixed» Closed (fixed)

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