Fixed some problem (Typo?) in Drupal MassMailer module

I spent quite some valuable minutes trying to find out why the MassMailer module of Drupal wasn’t able to access the SavedSearches of the ContactManager module.
I saw the debug SQL query which was causing an error. It went like:

Table 'contact_search' doesn't exist query: SELECT name, sid FROM contact_search WHERE type = 'search' ORDER BY name in ...../includes/database.mysql.inc on line 66.

I kept ignoring the above message until I was sure i was not making some stupid mistake.
I tried disabling & re-enabling the ContactManager module, hoping it would create the table.

Then I fired up phpMyAdmin to find out that the table didn’t exist alright. But I saw that there was another table ‘contact_manager_search’ which had precisely the structure and data that the SQL query was fired up to for.

Should I rename the table?
Made a copy of the ‘contact_manager_search’ table with the name ‘contact_search’ and tested the MassMailer module. No errors, was working fine. But this wasn’t a fix. If I create more SavedSearch entries then it won’t get reflected in this duplicate table.

So then I opened up the module code, read up a bit on how Drupal Modules are written etc. Was expecting to see a system of internal APIs or atleast shared module variables for modules to operate with each other’s data. But was a little surprised to find raw SQL queries (not really raw in the absolute sense, but raw in the sense of inter-module communication - since direct access to the table was being made, though database portability etc are maintaned).

Well, to cut a long story short, it turned out I just had to do some text-replace operations on the massmailer.module file:
So

$result = db_query('SELECT name, sid FROM {contact_search} WHERE type = \'%s\' ORDER BY name', 'search');

was changed to

$result = db_query('SELECT name, sid FROM {contact_manager_search} WHERE type = \'%s\' ORDER BY name', 'search');

Strange. Simple.

Post a Comment