I have a Triggered Rule where one action is to send a Private Message.

When the rule is triggered, it works with some users and not others.

I have created one user which always receives the Private Message, and a second one which does not.

The only error I have found is this, after I execute a Rule Set, which in turn triggers the Triggered Rule:

"Recipient type pet_registration is not correctly implemented"

Also, the user which does not receive the Private Message does receive email notification of the private message.

And, this is for more than one Rule Set.

Is there some setting required for a user to receive Private Messages? I can not find that setting.

Also, there is one Private Message actioned by a Triggered Rule when a node is created, and the user receives that, but it is not sent to the Inbox. It can be found in the All Messages box. The "Recipient Type" error appears there also.

Thank you.

Comments

berdir’s picture

Status: Active » Needs review
StatusFileSize
new884 bytes

Hm.

Privatemsg uses the type property to detect the type of recipient. By default, it's user but Privatemsg also allows to send messages to roles and other groups of users.

It seems that your user objects seem to have the type property set already, and to something that is not a valid recipient type.

Can you try the attached patch?

Can you send messages to those users manually?

itserich’s picture

I tried the patch by inserting the lines manually, so am not sure I did it correctly.

It appears only one new line is active: "+ $recipient->type = 'user';"

When inserted, the error message does not appear, but the message is also not received by the two users, including the user which previously received messages.

A message sent manually is received.

I do have a lot of modules, so there could be a conflict. If you would like admin access to the site let me know.

Thank you for the quick response.

berdir’s picture

Did you add it with the + or without? It should be without...

itserich’s picture

Thank you, yes, without the +, that is about the limit of my understanding of how to patch.

The user for which it works is older than the user for which it does not work, perhaps something has happened to not allow it to work newer users, but that is a pure guess.

There are a lot of modules, including Messaging & Notifications, and how mail works within Drupal has always been confusing to me, so could be a conflict.

berdir’s picture

Well, do you have any idea where the string "pet_registration" is coming from?

You could for example search your sites/all/modules folder for that string.

itserich’s picture

Version: » 6.x-1.x-dev

Pet Registration is a node type, it is a missing pet web site.

berdir’s picture

No idea.

Can you try to install devel.module and then add the following line of code directly above the one you added from the patch?

dpm($recipient);

That should then print a debug thing with all information that is attached to that user. Is there a type property? Are there any differences between users to which you can send messages and those you can't?

itserich’s picture

With the code changes to this:

function privatemsg_rules_new($subject, $body, $recipient, $author) {
  rules_log(t('Writing new message with subject %subject to %user from %author', array('%subject' => $subject, '%user' => $recipient->name, '%author' => $author->name)));

<?php
dpm($recipient);
?> 

  $recipient->type = 'user';
  $result = privatemsg_new_thread(array($recipient), $subject, $body, array('author' => $author));

I get this error message:

Parse error: syntax error, unexpected '<' in /home/petnotic/public_html/sites/all/modules/privatemsg/privatemsg_rules/privatemsg_rules.rules.inc on line 387

With line 387 being

/php

Have not found a common point to the users, it is a small sample size so far.

However, the accounts I have found which work are older accounts, and when I create a new account it does not work.

berdir’s picture

yeah, I only added the < ?php / ? > lines for highlighting, you only need to add the single line of actual code.

itserich’s picture

This is the result of dpm($recipient);

" Called from /home/petnotic/public_html/sites/all/modules/privatemsg/privatemsg_rules/privatemsg_rules.rules.inc, line 387 "

I ran the rule on two nodes written by two users and one was received and the other not.

Also, the Sent Messages tabs shows the message was sent to both users.

I don't know what the differences could be with the users. Both have Default send method as Drupal mail and Enable Private Messages.

Neither has "Receive email notification for incoming private messages"

itserich’s picture

This is from the one which worked:

... (Object) stdClass
uid (String, 1 characters ) 1
mail (String, 19 characters ) erich@petnotice.com
mode (String, 1 characters ) 0
sort (String, 1 characters ) 0
threshold (String, 1 characters ) 0
theme (String, 0 characters )
signature (String, 0 characters )
signature_format (String, 1 characters ) 0
created (String, 10 characters ) 1278855199
access (String, 10 characters ) 1299208730
login (String, 10 characters ) 1299180510
status (String, 1 characters ) 1
timezone (String, 6 characters ) -21600
language (String, 0 characters )
picture (String, 0 characters )
init (String, 21 characters ) human@missingpups.com
data (String, 343 characters ) a:9:{s:7:"contact";i:0;s:28:"notifications_comm...
timezone_name (String, 15 characters ) America/Chicago
contact (Integer) 0
notifications_comment_notify (String, 1 characters ) 1
messaging_default (String, 4 characters ) mail | (Callback) mail();
notifications_send_interval (String, 3 characters ) 900
notifications_auto (Integer) 0
endure_misery (Integer) 0
form_build_id (String, 37 characters ) form-442b141ea4e000da1d0be5535f2208a9
mailalias (String, 20 characters ) erich@dmicapital.com
mimemail_textonly (Integer) 0

And from the one which did not:


... (Object) stdClass
uid (String, 3 characters ) 379
name (String, 7 characters ) itsjohn
mail (String, 20 characters ) erich@dmicapital.com
mode (String, 1 characters ) 0
sort (String, 1 characters ) 0
threshold (String, 1 characters ) 0
theme (String, 0 characters )
signature (String, 0 characters )
signature_format (String, 1 characters ) 0
created (String, 10 characters ) 1299161186
access (String, 10 characters ) 1299208396
login (String, 10 characters ) 1299161585
status (String, 1 characters ) 1
timezone (String, 6 characters ) -21600
language (String, 2 characters ) en
picture (String, 0 characters )
init (String, 20 characters ) erich@dmicapital.com
data (String, 11979 characters ) a:119:{s:4:"type";s:16:"pet_registration";s:7:"...
timezone_name (String, 15 characters ) America/Chicago
type (String, 16 characters ) pet_registration
changed (String, 0 characters )
title (String, 3 characters ) ant
date (String, 0 characters )
promote (Boolean) FALSE
sticky (Boolean) FALSE
preview (String, 7 characters ) Preview
save_edit (String, 27 characters ) Save &amp; Continue Editing
form_build_id (String, 37 characters ) form-6bd161860afc474ce9505bc3b0fa3a10
comment (String, 1 characters ) 2

berdir’s picture

type (String, 16 characters ) pet_registration

Yeah, so something *does* set the type, probably during the registration, I guess that's why old users work and new users don't.

Can you try the updated patch, that should really fix it...

itserich’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev
Status: Needs review » Closed (fixed)

Thank you Berdir. It does work.

The Email Notification of Private Messages is a great way to make sure email is not missed.

Thank you so much for your quick and detailed help.

berdir’s picture

Status: Closed (fixed) » Needs review

Let's keep this open for now.

Will likely commit the patch. It's really a special case but fixing it doesn't cost us much and makes it a bit more error-prone.

rfay’s picture

#12, but posted against 6.x-2.x instead of 6.x-1.x (It applies cleanly on 6.x-2.x)

rfay’s picture

Yay!

berdir’s picture

D'oh!

berdir’s picture

Status: Needs review » Fixed

Commited.

Status: Fixed » Closed (fixed)

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