Tables defined on hook_schema are created automatically, is not necessary to create them on hook_enable or hook_install. Same applies for removing tables on hook_uninstall.
So, those functions can be removed: http://cgit.drupalcode.org/sandbox-AnnaSan-2503695/tree/smartest.install...
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | 2507635-1-removed-unnecessary-hooks.patch | 1.26 KB | David Hernández |
Comments
Comment #1
David Hernández commentedComment #2
fran seva commented@David Hernández I think the hook_uninstall is necessary but should be that way:
This is the only way to make a real module delete, I mean, remove all database stored content.
Comment #3
David Hernández commentedFrom the API: https://api.drupal.org/api/drupal/modules%21system%21system.api.php/func...
Database tables defined by hook_schema() will be removed automatically.
So, I think it is not really necessary.
Comment #4
fran seva commented@David Hernández yeah!
You were right, sorry I think what I was saying happened in D6 :S
The patch is good for me.
Comment #5
gabrielhruiz commentedI think that hook_enable() it's interesting. For example, if you have a new version of the module and this version is linked to a new table in our data base, this table will not be added when you re-install the new version. In my opinion hook_enable() allows that this is possible. This is true?
Comment #6
fran seva commentedIf you need to update a table, add data to a table or create a table in a new version, it should be used the hook_update_N [1] that allow update a installed module.
As user, when a new module version is lunch I expect just download the code and execute update.php to check if the module needs database update.
@gabrielhruiz can you check if [1] is what you need? I think is the drupal way to implement what you said in #5
[1] https://api.drupal.org/api/drupal/modules%21system%21system.api.php/func...
Comment #7
gabrielhruiz commentedYou're right. Now I have everything clear, Thanks.
I tested the patch and it's okey for me too.
Comment #8
David Hernández commentedWhen altering a table, it should be done in two places:
Comment #10
anabsanchez commented