I have a module that uses mailsystem. My hook_enable() looks like this:

<?php
  mailsystem_set
(
    array(
     
'my_module_name' => array(
       
'format' => 'TheMailSystemName',
      ),
    )
  );
?>

When I first enable that module, mailsystem cleverly creates a new wrapper class called TheMailSystemName__DefaultMailSystemName into sites/default/files/mailsystem as TheMailSystemName__DefaultMailSystemName.mail.inc in order to use TheMailSystemName's format() method, but DefaultMailSystemName's mail() method. Pretty awesome so far.

I also have this code in my hook_disable() for my module:

<?php
  mailsystem_clear
(
    array(
     
'my_module_name' => array(
       
'format' => 'TheMailSystemName',
      ),
    )
  );
?>

If I disable my module, and I re-enable it. I get a sad "The website encountered an unexpected error. Please try again later." message. Even though there is that message, the module does enable successfully, but the mail_system variable that this module is working with does not get setup correctly. When I go to /admin/config/system/mailsystem I do not see my module associated with the newly-written TheMailSystemName__DefaultMailSystemName class, and I have to set it up via the GUI in there.

What am I doing wrong?

Thanks!

Files: 
CommentFileSizeAuthor
#5 mailsystem.1359482.5.patch731 bytestobiasb

Comments

Component:Module compatibility» Code

This is a bug :)
SQL request for cleaning registry are prepared but never executed.

In the mailsystem.module file find

<?php
    db_delete
('registry_file')
      ->
condition($file_condition);
   
db_delete('registry')->condition(
     
db_or()->condition($class_condition)
      ->
condition($file_condition)
    );
?>

and replace it by
<?php
    db_delete
('registry_file')
      ->
condition($file_condition)
      ->
execute();
   
db_delete('registry')->condition(
     
db_or()->condition($class_condition)
      ->
condition($file_condition)
    )->
execute();
?>

Sorry but I cannot provide a proper patch for the moment.
I hope this will help.

Wow, I had notifications disabled on drupal.org so I'm just now seeing this! Code changes applied. Thanks DuaelFr!

You are welcome :)
Cannot mark the issue as fixed or need review as there is no dev version of the module but in my case it was working well.

Version:7.x-2.30» 7.x-2.x-dev
Status:Active» Needs review
StatusFileSize
new731 bytes

Here is the patch for the bug ;-)

Priority:Normal» Major
Status:Needs review» Reviewed & tested by the community

Patch looks good. As registry cleanup is fairly important, bumping this to major.