Page 1 of 1

Deleting a row from the db when Deleting Data

Posted: Sun May 06, 2018 1:58 pm
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?

Re: Deleting a row from the db when Deleting Data

Posted: Sun May 06, 2018 4:24 pm
by kinerity
Row or column?

Re: Deleting a row from the db when Deleting Data

Posted: Sun May 06, 2018 4:28 pm
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 ;) )

Re: Deleting a row from the db when Deleting Data

Posted: Sun May 06, 2018 4:36 pm
by kinerity
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.

Re: Deleting a row from the db when Deleting Data

Posted: Sun May 06, 2018 8:06 pm
by AbaddonOrmuz
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

Re: Deleting a row from the db when Deleting Data

Posted: Mon May 07, 2018 10:18 am
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: