hook_schema() not getting uninstalled when module is disabled
I have installed a schema for a custom module which creates the table w开发者_Go百科hen I enable the module. But when I disable the module, the table still remains. I am using the following code for uninstall:
function sample2_install() {
if(!db_table_exists('contact')){
drupal_install_schema('sample2');
}
}
function sample2_uninstall() {
drupal_uninstall_schema('sample2');
}
Why is the table not getting uninstalled?
The difference here is between disabling and uninstalling. Disabling keeps the module settings ready to go whenever it gets reinabled. Uninstalling purges everything until it is re-enabled.
hook_uninstall()
only gets called when you fully uninstall the module.
hook_disable()
gets called when you only disable it.
You could call drupal_uninstall_schema()
if inside of hook_disable()
, but I don't recommend that. It would mean that all your data gets deleted when you disable the module — generally uninstalling is when you would want to completely delete everything.
精彩评论