Deleting a row from the db when Deleting Data

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
david63
Jr. Extension Validator
Posts: 14724
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Deleting a row from the db when Deleting Data

Post by david63 » Sun May 06, 2018 1:58 pm

I need to delete a row from a table when the extension's data is deleted - the mechanics of which are not the problem.

What I am unsure of is where to put the function (ext.php?) and is there a specific function that I should use?
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
kinerity
Community Team Member
Community Team Member
Posts: 1888
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Truscott
Contact:

Re: Deleting a row from the db when Deleting Data

Post by kinerity » Sun May 06, 2018 4:24 pm

Row or column?
Kailey Truscott - Community Team

User avatar
david63
Jr. Extension Validator
Posts: 14724
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Deleting a row from the db when Deleting Data

Post by david63 » Sun May 06, 2018 4:28 pm

kinerity wrote:
Sun May 06, 2018 4:24 pm
Row or column?
Row - column would not be a problem.

(Actually it is in the title ;) )
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
kinerity
Community Team Member
Community Team Member
Posts: 1888
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Truscott
Contact:

Re: Deleting a row from the db when Deleting Data

Post by kinerity » Sun May 06, 2018 4:36 pm

Just wanted to verify. You may have to do this in the disable/purge step in ext.php because there's no drop_rows in the migration object. Something simple like

Code: Select all

$sql = 'DELETE FROM ' . your_table . '
    WHERE unique_value = ' . your_unique_value;
$this->db->sql_query($sql);
I'm sure you thought of that though.
Kailey Truscott - Community Team

User avatar
AbaddonOrmuz
Registered User
Posts: 389
Joined: Wed Dec 25, 2013 9:06 pm
Location: /dev/null
Name: Alfredo Ramos
Contact:

Re: Deleting a row from the db when Deleting Data

Post by AbaddonOrmuz » Sun May 06, 2018 8:06 pm

You can use a migration for that, using a custom function within revert_data()
The revert_data() method is optional and can be used to undo data changes. Normally, the revert_data() method is automatically reverted during a purge step, reversing any of the changes introduced by the migration tools. Using the revert_data() method is only needed to perform additional changes during an extension’s uninstall, such as performing a custom functions.
https://area51.phpbb.com/docs/dev/3.2.x ... ta-changes
https://area51.phpbb.com/docs/dev/3.2.x ... tml#custom
https://area51.phpbb.com/docs/dev/3.2.x ... evert-data
A proudly user of Arch Linux :: /r/sddm_themes

User avatar
david63
Jr. Extension Validator
Posts: 14724
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Deleting a row from the db when Deleting Data

Post by david63 » Mon May 07, 2018 10:18 am

AbaddonOrmuz wrote:
Sun May 06, 2018 8:06 pm
You can use a migration for that, using a custom function within revert_data()
Thanks - that was it. I was forgetting the "custom function" part. :oops:
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: canonknipser and 7 guests