revert_data()

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

revert_data()

Post by david63 »

I know with an extension that when the "Delete data" is run the extension will try to remove the update_data() that is in the migration file and that there is the option to control what is removed by using the revert_data() function.

So I have a two part question:

1. If there is a revert_data() function present will it only delete the data in that function or will it carry out the delete from the update_data() function but overwrite that by what is in the revert_data() function - in other words if I have a revert_data() function do I have to put everything in there?

2. How do I test to ensure that a module is empty before I try to remove it. For example if I create a module, say, array('module.add', array('acp', 'ACP_CAT_USERGROUP', 'ACP_MY_MODULE')) into which I then add further modules from more than one extension (the "top level" would be created in each extension if necessary) when the delete data comes along for one of the extensions it will give an error if there is still another item in the "top level" module.
David
Remember: You only know what you know and - you don't know what you don't know!

I now no longer support any of my extensions but they will start to become available here
User avatar
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5861
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman

Re: revert_data()

Post by MattF »

1. An update_data() method will always be reverted (or attempted). The revert_data method is only for things the migrator can't automatically revert, such as custom methods. So no, you don't have to put everything in it, just new custom methods to revert your update_data()'s custom methods.

2. Write a query to check if your "parent" module has any "children". The way to know if it has children is if right_id - left_id > 1 is true. Empty would mean that code evaluates to false.
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
User avatar
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5861
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman

Re: revert_data()

Post by MattF »

For example:

Code: Select all

'SELECT module_id
FROM ' . $this->table_prefix . "modules
    WHERE module_class = 'acp'
        AND module_langname = 'ACP_MY_MODULE'
        AND right_id - left_id > 1";
$result = $this->db->sql_query($sql);
$module_id = (int) $this->db->sql_fetchfield('module_id');
$this->db->sql_freeresult($result);

// return true if module is empty, false if has children
return (bool) !$module_id;
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: revert_data()

Post by david63 »

Thanks - I was hoping that it would have been something a bit easier such as "if not empty" or some such.
David
Remember: You only know what you know and - you don't know what you don't know!

I now no longer support any of my extensions but they will start to become available here
Post Reply

Return to “Extension Writers Discussion”