Just tested this because I realized this was a potential problem, and hook_schema() does get called when uninstalling a module.
This is a problem if someone would use the Search API (or any other module using exportable entities) and later wanted to uninstall it, but would also before disable the Entity API module. The result would be a fatal error, as entity_exportable_schema_fields() would then be missing. Therefore, even if this isn't as practical as the current solution, I think modules must directly write the field data in their schema hooks, and that should also be documented.
If you have some other suggestion for this, I'd be glad to hear it.

CommentFileSizeAuthor
#5 entity_schema_fields.patch2.33 KBfago
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

amitaibu’s picture

I think it's the same as #1099812: Docs on how to prevent fatal error when using entity_exportable_schema_fields() from hook_update_N() -- and indeed the solution is not to use entity_exportable_schema_fields(), but to copy it.

drunken monkey’s picture

Copy it and replace the ENTITY_CUSTOM constant, now that I think about it.
Even though the default value shouldn't matter while uninstalling, it still prevents a notice.

fago’s picture

Indeed, that's problem. I guess the helper becomes useless then :(

fago’s picture

Title: hook_schema() is called during uninstall » remove entity_exportable_schema_fields() from hook_schema() implementations
Priority: Normal » Major
fago’s picture

Status: Active » Needs review
FileSize
2.33 KB

Patch attached. Please review.

Note that I left the function there, so that modules making use of it right now don't suddenly break.

drunken monkey’s picture

Status: Needs review » Reviewed & tested by the community

Looks alright to me.

fago’s picture

Status: Reviewed & tested by the community » Fixed

thanks, committed.

sun’s picture

Status: Fixed » Needs work
+++ b/entity.module
@@ -590,14 +590,21 @@ function _entity_modules_get_default_types($modules) {
+ * Warning: Do not call this function in your module's hook_schema()
+ * implementation or update functions. It is not safe to call functions of
+ * dependencies at this point. Instead of calling the function, just copy over
+ * the content.
+ * For more details see the issue http://drupal.org/node/1122812.
  */
 function entity_exportable_schema_fields($module_col = 'module', $status_col = 'status') {

If you don't want others to call this function, then rename it to a private function. That will not only make clear that no one should call it, but also prevent anyone from not updating potential calling code.

Powered by Dreditor.

fago’s picture

Status: Needs work » Fixed

As noted above:
>Note that I left the function there, so that modules making use of it right now don't suddenly break.

That way we prevent an update and dependency nightmare for user. So for now, I think it is best to stay with the name.

drunken monkey’s picture

I agree with Wolfgang, the function shouldn't be removed nor renamed, at least for now.
We could issue a PHP notice when the function is called, though, to bring it to the attention of developers, while leaving users (virtually) unharmed.

Status: Fixed » Closed (fixed)

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