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

  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:

  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!

CommentFileSizeAuthor
#5 mailsystem.1359482.5.patch731 bytestobiasb
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

enrique.delgado’s picture

Component: Module compatibility » Code
DuaelFr’s picture

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

In the mailsystem.module file find

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

and replace it by

    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.

enrique.delgado’s picture

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

DuaelFr’s picture

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.

tobiasb’s picture

Version: 7.x-2.30 » 7.x-2.x-dev
Status: Active » Needs review
FileSize
731 bytes

Here is the patch for the bug ;-)

Les Lim’s picture

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

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

das-peter’s picture

Updates on this? Patch is RTBC quite long now :)

  • Nafes committed 8c2f4f6 on 7.x-2.x authored by tobiasb
    Issue #1359482 by tobiasb: Error enabling modules that use mailsystem in...
Nafes’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Thank you for the patch, tobiasb!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.