Deleting a row from the db when Deleting 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

Deleting a row from the db when Deleting Data

Post by david63 »

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!

I now no longer support any of my extensions but they will start to become available here
User avatar
Kailey
Community Team Leader
Community Team Leader
Posts: 3732
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay
Contact:

Re: Deleting a row from the db when Deleting Data

Post by Kailey »

Row or column?
Kailey Snay - Community Team Leader
Knowledge Base | Documentation | Community rules

If you have any questions about the rules/customs of this website, feel free to send me a PM.
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: Deleting a row from the db when Deleting Data

Post by david63 »

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!

I now no longer support any of my extensions but they will start to become available here
User avatar
Kailey
Community Team Leader
Community Team Leader
Posts: 3732
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay
Contact:

Re: Deleting a row from the db when Deleting Data

Post by Kailey »

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 Snay - Community Team Leader
Knowledge Base | Documentation | Community rules

If you have any questions about the rules/customs of this website, feel free to send me a PM.
User avatar
AlfredoRamos
Recognised Extension Developer
Posts: 1302
Joined: Wed Dec 25, 2013 9:06 pm
Location: /dev/null
Name: Alfredo
Contact:

Re: Deleting a row from the db when Deleting Data

Post by AlfredoRamos »

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
Some of my phpBB extensions:
:chart_with_upwards_trend: SEO Metadata | Image Markdown | :shield: hCaptcha
:trophy: Check out all my validated extensions :trophy:

:penguin: Arch Linux user | Linux Boards :penguin:
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: Deleting a row from the db when Deleting Data

Post by david63 »

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!

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

Return to “Extension Writers Discussion”