Cross posting this from Message subscribe email frequency as this project appears to be more active... I feel like I am probably missing something in how to get all the pieces working together, but I can't get the digests to send. I've got:
Message 7.x-1.9
Message notify 7.x-2.5
Message subscribe 7.x-1.0-rc1+8-dev
Message digest 7.x-1.0-beta4
Message subscribe email frequency 7.x-1.0

I've enabled the subscribe_node and email_node flags and limited them to certain content types. I then edited the "comment insert" message type email template and the immediate notification of comments works fine. With digest and subscribe email frequency enabled, I see the field on the edit account page, but changing the values doesn't prevent the immediate notification from going out. As mentioned on the project page for Message subscribe email frequency, I don't have a default message notifier set in the message subscribe settings.

Not sure if it is related, but I had a rule to redirect to the user page after update (from the user edit page) and it has stopped working now that I've got all the message modules enabled and the subscribe email frequency field on the user account.

Any help would be very appreciated!

Comments

willowdigit’s picture

I just battled with both modules as well, and after a lengthy debugging session I discovered what I think are potential flaws in both modules. My conclusion is as follows:

message_digest\plugins\notifier\abstract.inc, public function agregate()

$start is set to the $interval (1 day or 1 week) prior to now:
$start = strtotime('-' . $interval);

This is the query that gets message digest entries (all entries larger than $start):
$query->condition('timestamp', $start, '>');

Should this query not rather grab all entries that are smaller than $start?
$query->condition('timestamp', $start, '<');

Then coming to the message_subscribe_email_frequency.module:

function message_subscribe_email_frequency_message_subscribe_get_subscribers_alter(&$uids, $values) {
  if (empty($uids)) {
    // Nobody is subscribed to the content.
    return;
  }

  // Get the frequency setting for any users subscribed to the content.
  // We don't use the Field API to get these values as we want to get the
  // settings for all the users with a single query.
  $query = "
    SELECT
      entity_id, message_subscribe_email_freq_value
    FROM
      {field_data_message_subscribe_email_freq}
    WHERE
      deleted != 1
    AND
      entity_id IN (:entity_ids)
  ";

  $result = db_query($query, array(':entity_ids' => array_keys($uids)))->fetchAll();

  foreach ($result as $row) {
    // Add notifier based on frequency selected by user.
    $frequency = $row->message_subscribe_email_freq_value;
    // Unset the notifier if the user has chosen to never receive email
    // notifications for subscribed content.
    if ($frequency == MESSAGE_SUBSCRIBE_EMAIL_FREQUENCY_NEVER) {
      unset($uids[$row->entity_id]['notifiers']['email']);
    }
    // We only change the frequency if the user should have been emailed in the
    // first place but does not want to receive the email immediately.
    if (isset($uids[$row->entity_id]['notifiers']['email']) && $frequency != 'email') {
      unset($uids[$row->entity_id]['notifiers']['email']);
      $uids[$row->entity_id]['notifiers'][$frequency] = $frequency;
    }
  }
}

Does this code make sense? Having followed the module's instructions, I removed all default notifiers. But then $uids[$row->entity_id]['notifiers'] has no value, and it is not set to anything at all.

So I replaced it with this:

function message_subscribe_email_frequency_message_subscribe_get_subscribers_alter(&$uids, $values) {
  if (empty($uids)) {
    // Nobody is subscribed to the content.
    return;
  }

  // Get the frequency setting for any users subscribed to the content.
  // We don't use the Field API to get these values as we want to get the
  // settings for all the users with a single query.
  $query = "
    SELECT
      entity_id, message_subscribe_email_freq_value
    FROM
      {field_data_message_subscribe_email_freq}
    WHERE
      deleted != 1
    AND
      entity_id IN (:entity_ids)
  ";

  $result = db_query($query, array(':entity_ids' => array_keys($uids)))->fetchAll();

  foreach ($result as $row) {
    // Add notifier based on frequency selected by user.
    $frequency = $row->message_subscribe_email_freq_value;
    if (isset($frequency) && $frequency != MESSAGE_SUBSCRIBE_EMAIL_FREQUENCY_NEVER) {
      $uids[$row->entity_id]['notifiers'][$frequency] = $frequency;
    }
  }
}

And so far everything seems to work.

nwom’s picture

Project: Message Digest » Message Subscribe Email Frequency
Version: 7.x-1.0-beta4 » 7.x-1.x-dev
Component: Documentation » Code
Status: Active » Needs review
StatusFileSize
new1.16 KB

@WillowDigit: Thank you so much for your work on this! Without your comment, I would have never gotten all of this to work.

There is already a patch that fixes the Message Digest problem here: #2238833: Incompatibilities with message queue logic means some digested messages may never get sent.

And for Message Subscribe Frequency, I have made a patch based on the work from #1. I will also move this issue to the respective project page.

Please review :)