1 (edited by KeyDog 2008-12-24 12:31)

Topic: Uninstall Code For Extensions - Uninstall Instructions Dropping Table

I'm adding the following table creation code:

   

 <install>
     <![CDATA[
                // Adding SQL statement / creating table /installation code
            $schema = array(
                'FIELDS'        => array(
                        'id'            => array(
                        'datatype'        => 'SERIAL',
                        'allow_null'    => false
                    ),
                    'cat_name'        => array(
                        'datatype'        => 'VARCHAR(80)',
                        'allow_null'    => false,
                        'default'        => '\'New Category\''
                    ),
                    'disp_position'    => array(
                        'datatype'        => 'INT(10)',
                        'allow_null'    => false,
                        'default'        => '0'
                    )
                ),
                'PRIMARY KEY'    => array('id')
            );
            $forum_db->create_table('categories', $schema);        
        ]]>  
    </install>

How does the uninstall need to look like; I know one has to reverse everything above. But what does that specifically look like in my case. (Or maybe point me to a link or literature on the subject)

      <uninstall><![CDATA[
        // Uninstallation code
            $query = array(
            'DELETE'    => '?????',
            'WHERE'    => '????? in (\'New Category\'')',
            );
            $forum_db->create_table('categories', $schema);
    ]]></uninstall>

Appreciate any pointers, as always.

2 (edited by KeyDog 2008-12-24 12:39)

Re: Uninstall Code For Extensions - Uninstall Instructions Dropping Table

<uninstall><![CDATA[
    // Uninstallation code
    if ($forum_db->table_exists('categories'))
        $forum_db->drop_table('categories');
]]></uninstall>

does this look right ?  ^^ or do I need anything changed in my specific case?

So in my manifest.xml it will now look like this:

    <install>
     <![CDATA[
                // Adding SQL statement / creating table /installation code
            $schema = array(
                'FIELDS'        => array(
                        'id'            => array(
                        'datatype'        => 'SERIAL',
                        'allow_null'    => false
                    ),
                    'cat_name'        => array(
                        'datatype'        => 'VARCHAR(80)',
                        'allow_null'    => false,
                        'default'        => '\'New Category\''
                    ),
                    'disp_position'    => array(
                        'datatype'        => 'INT(10)',
                        'allow_null'    => false,
                        'default'        => '0'
                    )
                ),
                'PRIMARY KEY'    => array('id')
            );
            $forum_db->create_table('categories', $schema);        
        ]]>  
    </install>
    <uninstall><![CDATA[
    // Uninstallation code
    if ($forum_db->table_exists('categories'))
        $forum_db->drop_table('categories');
    ]]></uninstall>

Re: Uninstall Code For Extensions - Uninstall Instructions Dropping Table

Use the uninstall section of pun_pm as an example.

Re: Uninstall Code For Extensions - Uninstall Instructions Dropping Table

    // Delete extension options from the config
    $query = array(
        'DELETE'    => 'config',
        'WHERE'     => 'conf_name in (\'o_pun_pm_outbox_size\', \'o_pun_pm_inbox_size\', \'o_pun_pm_show_new_count\', \'o_pun_pm_show_global_link\')',
    );
    $forum_db->query_build($query) or error(__FILE__, __LINE__);
    
    $forum_db->drop_table('pun_pm_messages');
    
    $forum_db->drop_field('users', 'pun_pm_new_messages');
    $forum_db->drop_field('users', 'pun_pm_long_subject');

        ]]></uninstall>

(just putting this in to remind me)