Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I have a custom Drupal 6 module (based on this issue) that puts some custom date and time formats into the date_format_types table and then can be accessed from /admin/settings/date-time/formats. This works nicely but I'd like to remove these from that table if the module gets uninstalled.

In my module's .install file, I tried this code:

<?php

/**
 * Implementation of hook_uninstall().
 */
function eventdates_custom_uninstall() {
  db_query("DELETE FROM {date_format_types} WHERE type LIKE 'eventdates_custom_date_%'");
}

This does not seem to work and the entries that had been added do not get removed from the date_format_types table when I uninstall the module but I am pretty sure I have the query correct. enter image description here

share|improve this question

1 Answer

up vote 4 down vote accepted

% is used as the placeholder marker for D6 queries, so you need to escape it with another %:

db_query("DELETE FROM {date_format_types} WHERE type LIKE 'eventdates_custom_date_%%'");

As a test I just added the following to the date_format_types table:

enter image description here

And then ran this query from the devel/php page:

db_query("DELETE FROM {date_format_types} WHERE type LIKE 'eventdates_custom_date_%%'");

And both rows were deleted:

enter image description here

share|improve this answer
I tried that and it didn't work, made sure to clear cache after I updated the code. Just as a test I did this in MySQL and it worked fine: DELETE FROM date_format_types` WHERE type LIKE 'eventdates_custom_date_%'` Not sure what else I am doing wrong. Thanks. – Danny Englander Dec 7 '12 at 16:20
@DannyEnglander I've updated the answer with a successful test I just tried out. Can you try running similar code manually and see if it works. At least that will determine whether it's the query failing, or the program execution not getting into your hook_uninstall() function – Clive Dec 7 '12 at 16:28
Yes, that method worked so that means I am doing something wrong on my end with the way I have my module set up. I will have to troubleshoot that somehow. Thanks. – Danny Englander Dec 7 '12 at 16:36
One interesting thing I just noticed, based on drupal.org/node/123825#comment-1125357 I also needed to go to admin/build/modules/uninstall and click uninstall for my module and then the data was removed from the table. That seems odd, why would you need to take that extra step? – Danny Englander Dec 7 '12 at 17:22
Actually, this implies that's correct, the data only gets removed after you disable and "uninstall" the module. api.drupal.org/api/drupal/developer%21hooks%21install.php/… So it seems like the method I am using will not be invoked when the module is simply disabled. I guess this makes sense in a lot of ways... – Danny Englander Dec 7 '12 at 17:28
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.