diff --git a/includes/simplenews.mail.inc b/includes/simplenews.mail.inc index f3eaede..4cc44d9 100644 --- a/includes/simplenews.mail.inc +++ b/includes/simplenews.mail.inc @@ -214,6 +214,12 @@ function simplenews_send_source(SimplenewsSourceInterface $source) { * @ingroup spool */ function simplenews_mail_spool($limit = SIMPLENEWS_UNLIMITED, array $conditions = array()) { + + // Ensure lock available on mail spool process + if (!lock_acquire('simplenews_mail_spool')) { + return FALSE; + } + $check_counter = 0; // Send pending messages from database cache. @@ -309,8 +315,11 @@ function simplenews_mail_spool($limit = SIMPLENEWS_UNLIMITED, array $conditions variable_set('simplenews_last_sent', $count_success); simplenews_revert_user(); + lock_release('simplenews_mail_spool'); return $count_success; } + // Release lock + lock_release('simplenews_mail_spool'); } /** diff --git a/simplenews_rules/simplenews_rules.rules.inc b/simplenews_rules/simplenews_rules.rules.inc index d4c9086..bbe0fbf 100755 --- a/simplenews_rules/simplenews_rules.rules.inc +++ b/simplenews_rules/simplenews_rules.rules.inc @@ -229,7 +229,10 @@ function simplenews_rules_action_unsubscribe($args, $settings) { */ function simplenews_rules_action_subscription_delete($args, $settings) { if (!empty($args['mail']) && !empty($args['tid'])){ - simplenews_subscription_delete(array('mail' => $args['mail'], 'tid' => $args['tid'])); + $subscriber = simplenews_subscriber_load_by_mail($args['mail']); + if ($subscriber) { + simplenews_subscription_delete(array('snid' => $subscriber->snid, 'tid' => $args['tid'])); + } } }