6

Solution: Ayesh K provides the correct answer below.


What is required to get a custom module to appear in uninstall list? I thought all you had to do was specify a database schema in hook_schema(), but I've done so and my module does not appear in the uninstall list. Currently my module consists of the following code in the .install file:

<?php

/**
 * Table schema definition for the Events Sponsors module.
 */
function event_sponsors_schema() {
    $schema['event_sponsors_sponsors'] = array(
        'description' => 'A collection of event sponsors.',
        'fields' => array(
            'id' => array(
                'type' => 'serial',
                'not null' => TRUE,
                'unsigned' => TRUE,
                'description' => "Unique ID for the sponsor.",
            ),
            'name' => array(
                'type' => 'varchar',
                'length' => '255',
                'not null' => TRUE,
                'description' => 'The name of the sponsor.',
            ),
        ),
        'primary key' => array('id'),
        'unique keys' => array(
            'id' => array('id'),
        ),
    );

    $schema['event_sponsors_sponsor_relations'] = array(
        'description' => 'Maintains sponsor and node relations.',
        'fields' => array(
            'sid' => array(
                'type' => 'int',
                'not null' => TRUE,
                'unsigned' => TRUE,
                'description' => 'The sponsor ID, as can be found in the sponsors table.',
            ),
            'nid' => array(
                'type' => 'int',
                'not null' => TRUE,
                'unsigned' => TRUE,
                'description' => 'The node ID as can be found in the node table.',
            ),
            'ordinal' => array(
                'type' => 'int',
                'not null' => TRUE,
                'unsigned' => TRUE,
                'description' => 'The order this sponsor appears alongside the node.',
            ),
        ),
        'primary keys' => array('sid','nid'),
        'unique keys' => array(
            'sid' => array('sid'),
            'nid' => array('nid'),
        ),
    );

    return $schema;
}

Any insight is appreciated.

2
  • 1
    AFAIK after you disable the module, it will apear in uninstall list Commented Jan 28, 2013 at 14:00
  • 4
    You just need to install the module (if not done already) and disable it; it will appear in the uninstall list (even if it doesn't have a .install file).
    – AjitS
    Commented Jan 28, 2013 at 14:00

3 Answers 3

5

For Drupal 6, you needed to install/uninstall schema using hook_install and hook_uninstall.

This is not necessary for Drupal 7.

Module will appear in uninstall list if both of these conditions are met:

  • module implements hook_schema OR hook_uninstall in its .install file.
  • module was enabled once and now is in disabled status.

If the only purpose of hook_uninstall is to uninstall the schema, you do not need a hook_uninstall function. For variable_del(), etc: you need. If you have any of these and module has data in the site already, you will see the uninstall check box.

1

Use hook_uninstall() like this way.
variables must not undefined.

function mymodule_uninstall() {
  variable_del('mymodule_var');
  variable_del('mymodule_var2');
}
-1

A very simple solution for newbies like me in drupal 7.

You can't uninstall a module when it's running or active. So try, to disable your module first and it should appear to uninstall list afterwards.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.