Hi,
I'd like to send private messages to a selected group of users. For this purpose I use a view with VBO and a Rules component action with this custom PHP code:
$recipients= array();
foreach ($selected_users as $recipient) {
$recipients[] = user_load($recipient->uid);
}
privatemsg_new_thread($recipients, $msg_subject, $msg_body, $options = array());
I've checked with dpm(); and all the variables looks correct according to the API documentation: $recipients
is an array of user objects, $msg_subject
is a plain text and $msg_body
is formatted text with 'full HTML' input format in my case.
But when I submit the action I got these error messages:
Notice: Array to string conversion _privatemsg_validate_message() (/var/www/drupal/sites/all/modules/privatemsg/privatemsg.module row 1860)
and
PDOException: SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1: INSERT INTO {pm_message} (subject, author, body, format, timestamp, has_tokens) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2_0, :db_insert_placeholder_2_1, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5); Array ( [:db_insert_placeholder_0] => My subject [:db_insert_placeholder_1] => 1 [:db_insert_placeholder_3] => filtered_html [:db_insert_placeholder_4] => 1463218925 [:db_insert_placeholder_5] => 0 [:db_insert_placeholder_2_0] => <p>My <strong>body </strong>text</p> [:db_insert_placeholder_2_1] => full_html ) _privatemsg_send() (/var/www/drupal/sites/all/modules/privatemsg/privatemsg.module row 1920).
As I said, all three input variables seems correct so I don't understand any of these messages: I don't know how the array to string issue should rise here and the second message looks more confusing for me: It seems to contain an extra placeholder ([:db_insert_placeholder_3] => filtered_html
).
Comments
Comment #2
oadaeh CreditAttribution: oadaeh as a volunteer commentedYou have an extra text area format in your query. You have both "full_html" and "filtered_html", and "filtered_html" is being used for "[:db_insert_placeholder_3]", which is going into the "timestamp" field, and the values after that are then all out of place.
I would take a look at what you are getting from Views/VBO for $msg_body and how you have the fields defined, to see if they line up and what you are expecting.
Comment #3
StG CreditAttribution: StG commentedActually, $msg_body and $msg_subject are not fields but parameters provided by this rule component:
Comment #4
oadaeh CreditAttribution: oadaeh as a volunteer commentedOkay. So maybe you need to modify what Rules is giving you. Take a look at what privatemsg_new_thread() expects (which may require reading through the function to see what is done with the data) and what Rules is providing and use your action to bridge the gap.
Comment #5
StG CreditAttribution: StG commentedI think I've figured it out: privatemsg_new_thread() needs a
$message->format
variable and if it's missing it uses the default text format of current user:Meanwhile the body parameter of the rule component also has a text format variable since it's a formated text. That's why I have an extra text area format value.
There's an other issue caused by the formatted text parameter: privatemsg_new_thread() expects a single value for
$body
but this parameter produces an array with$body['value'
] and$body['format']
variables.So I think two changes should be made in privatemsg_new_thread(), something like this (sorry, I can't create a proper patch):
and
Comment #6
ivnish CreditAttribution: ivnish commented