I am trying to create a rule sends an email on account creation for a specific type of account. The conditions are not being used for debugging. The issue I am having is the email is sent twice!

It is a very simple triggered rule, that does not use any rule sets. The rule is exported here:

array (
  'rules' => 
  array (
    'rules_26' => 
    array (
      '#type' => 'rule',
      '#set' => 'event_user_insert',
      '#label' => 'Free Trial -- Initial Email {triggered}',
      '#active' => 1,
      '#weight' => '8',
      '#categories' => 
      array (
      ),
      '#status' => 'custom',
      '#conditions' => 
      array (
        0 => 
        array (
          '#weight' => 9,
          '#info' => 
          array (
            'label' => 'User has role(s)',
            'arguments' => 
            array (
              'user' => 
              array (
                'type' => 'user',
                'label' => 'User',
              ),
            ),
            'module' => 'User',
          ),
          '#name' => 'rules_condition_user_hasrole',
          '#settings' => 
          array (
            'roles' => 
            array (
              0 => 8,
            ),
            'operation' => 'OR',
            '#argument map' => 
            array (
              'user' => 'account',
            ),
          ),
          '#type' => 'condition',
        ),
      ),
      '#actions' => 
      array (
        1 => 
        array (
          '#type' => 'action',
          '#settings' => 
          array (
            'from' => 'info@integrafx.com',
            'subject' => 'Welcome to your Free Trial',
            'message' => 'Free trial text goes here.


Thank you,
IntegraFX',
            '#argument map' => 
            array (
              'user' => 'account',
            ),
          ),
          '#name' => 'rules_action_mail_to_user',
          '#info' => 
          array (
            'label' => 'Send a mail to a user',
            'arguments' => 
            array (
              'user' => 
              array (
                'type' => 'user',
                'label' => 'Recipient',
              ),
            ),
            'module' => 'System',
            'eval input' => 
            array (
              0 => 'subject',
              1 => 'message',
              2 => 'from',
            ),
          ),
          '#weight' => 10,
        ),
      ),
      '#version' => 6003,
    ),
  ),
)

Also, I have another rule that is set to display a message to a user on log-in, this rule does utilize a rule set. I am having a similar issue in that the rule runs twice, displaying two copies of the same message on log-in. Code:

array (
  'rules' => 
  array (
    'rules_38' => 
    array (
      '#type' => 'rule',
      '#set' => 'event_user_login',
      '#label' => 'Free Trial -- Display remaining time to user',
      '#active' => 1,
      '#weight' => '0',
      '#categories' => 
      array (
      ),
      '#status' => 'custom',
      '#conditions' => 
      array (
      ),
      '#actions' => 
      array (
        1 => 
        array (
          '#weight' => 0,
          '#info' => 
          array (
            'arguments' => 
            array (
              'user_a' => 
              array (
                'label' => 'User A',
                'type' => 'user',
              ),
              'date_a' => 
              array (
                'label' => 'Date A',
                'type' => 'date',
              ),
            ),
            'label' => 'Free Trial -- Display Time Remaining',
            'status' => 'custom',
            'categories' => 
            array (
            ),
            'module' => 'Rule Sets',
            'base' => 'rules_action_invoke_set',
            'set' => 'rules_display_trail_remaining_to_user',
          ),
          '#name' => 'rules_action_invoke_set_rules_display_trail_remaining_to_user',
          '#settings' => 
          array (
            'date_a' => '<? echo time(m-d-Y) ?>',
            '#argument map' => 
            array (
              'user_a' => 'account',
            ),
            '#eval input' => 
            array (
              'rules_input_evaluator_php' => 
              array (
                'date_a' => 
                array (
                ),
              ),
            ),
          ),
          '#type' => 'action',
        ),
      ),
      '#version' => 6003,
    ),
  ),
)

Any advice you can give would be greatly appreciated.

Thank you,
Chance

Comments

fago’s picture

Component: Rules Core » Rules Engine
Category: bug » support

I guess somehow on your system the hook_user op == 'login' is invoked twice, that way the rules are evaluated twice. Try whether the problem exists on a clean install without any modules, if not try deactivating modules till you find the module causing the bug.

Grayside’s picture

I have a ruleset in which each rule was exported twice. It appears that _dot_notifications_rules_defaults() gets one array for the entire rulesset export, but that rulesset contains each individual rule twice, in order, as though the rules were processed twice for export. Deleting the excess rules from the code seems to work just fine as a fix, until the next time I want to update anyway.

It also shows up cleanly in the Rules Admin interface--with two of each rule.

I have recently exported a triggered rule, and it worked seemlessly.

mitchell’s picture

Status: Active » Closed (fixed)