In admin/rules/trigger, I have cloned the default trigger "Send welcome message with privatemsg when a new user is created".
I have enabled the clone but not otherwise made any other changes.

I expected a welcome private message to be sent to the new user.

Instead, when I tested the feature and tried to register a new account, upon submitting the register form, I got a blank page in return. Reloading the page showed the following errors:

warning: Attempt to assign property of non-object in privatemsg.module on line 2781.
warning: Attempt to assign property of non-object in privatemsg.module on line 2782.

Apparently no message was sent.

It may be relevant to note that new users must be approved by an administrator. New user accounts are blocked by default. Maybe there could be a trigger for when a user logs in for the very first time?

Presently, the very simple feature that worked very well with the Drupal 5 version became very complicated to set up and enable in 6--2 and is not working at all.

Comments

Berdir’s picture

Status: Active » Postponed (maintainer needs more info)

This should work just fine, there is even a default rule that is pre-configured to do just this. It doesn't matter if the user is blocked, just make sure he has the permission to receive private messages.

Export your rule and post it here so that I can try to reproduce.

jennifer.chang’s picture

Status: Postponed (maintainer needs more info) » Active

Thank you for looking into it.

I experienced the bug on the live site and I could reproduce locally, after enabling rules and privatemsg for the first time. I don't see the 'receive private message' permission, but authenticated users have the 'read private message' and 'write private message' permissions. Same problem.

I *had* used the pre-configured role. On one site I edited it and when I enabled and saved it, I noticed the machine name was conveniently altered. On the other site, I used the 'clone' button and beside enabling it, I didn't do any specific change.

Here is the exported rule:

array (
  'rules' => 
  array (
    'rules_emsg_welcome_message_cloned' => 
    array (
      '#type' => 'rule',
      '#set' => 'event_user_insert',
      '#label' => '(clone) Send welcome message with privatemsg when a new user is created',
      '#active' => 1,
      '#weight' => '0',
      '#status' => 'custom',
      '#conditions' => 
      array (
      ),
      '#actions' => 
      array (
        1 => 
        array (
          '#type' => 'action',
          '#settings' => 
          array (
            'username' => '',
            'userid' => '1',
            '#argument map' => 
            array (
              'user_loaded' => 'admin_user',
            ),
          ),
          '#name' => 'rules_action_load_user',
          '#info' => 
          array (
            'label' => 'Load a user account',
            'new variables' => 
            array (
              'admin_user' => 
              array (
                'label' => 'Admin User (uid 1)',
                'label callback' => false,
                'type' => 'user',
              ),
            ),
            'module' => 'User',
          ),
          '#weight' => -10,
        ),
        0 => 
        array (
          '#info' => 
          array (
            'label' => 'Send a message',
            'arguments' => 
            array (
              'subject' => 
              array (
                'type' => 'string',
                'label' => 'Subject',
              ),
              'body' => 
              array (
                'type' => 'string',
                'label' => 'Body text',
              ),
              'recipient' => 
              array (
                'type' => 'user',
                'label' => 'Recipient',
              ),
            ),
            'module' => 'Privatemsg',
          ),
          '#name' => 'privatemsg_rules_new',
          '#settings' => 
          array (
            'subject' => 'Welcome!',
            'body' => 'Hey < ?php $account->name; ? >, welcome on our site!',
            '#argument map' => 
            array (
              'recipient' => 'account',
              'author' => 'admin_user',
            ),
            '#eval input' => 
            array (
              'rules_input_evaluator_php' => 
              array (
                'body' => 
                array (
                  0 => 'account',
                ),
              ),
            ),
          ),
          '#type' => 'action',
          '#weight' => 0,
        ),
      ),
      '#version' => 6003,
      '#categories' => 
      array (
      ),
    ),
  ),
)

On the local / test site, I got even more errors than I had when I first tested on the live site:

    Notice: Trying to get property of non-object in privatemsg_rules_new() (line 386 of privatemsg_rules.rules.inc).
    Notice: Trying to get property of non-object in privatemsg_user_access() (line 271 of privatemsg.module).
    Notice: Trying to get property of non-object in privatemsg_user_access() (line 271 of privatemsg.module).
    Warning: Attempt to assign property of non-object in privatemsg_recipient_format() (line 2782 of privatemsg.module).
    Notice: Trying to get property of non-object in privatemsg_recipient_format() (line 2783 of privatemsg.module).
    Warning: Attempt to assign property of non-object in privatemsg_recipient_format() (line 2783 of privatemsg.module).
    Notice: Trying to get property of non-object in privatemsg_recipient_format() (line 2785 of privatemsg.module).

I tried to debug the first of those error and inserted some calls to dpm() at the start of the first function:


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

Both $recipient and $author are expected to be objects, Unexpectedly, it's not the $recipient that caused problems (at least at this stage) but the $author (i.e. user/1) who is not an object representing a user but an array representing the message:

author =>
   ... (Array, 4 elements)
        subject (String, 8 characters ) Welcome!
        body (String, 26 characters ) Hey , welcome on our site!
        #argument map (Array, 2 elements)
        #eval input (Array, 1 element)
            rules_input_evaluator_php (Array, 1 element) 

At this stage, I got stuck because I didn't manage to figure out who was the calling function.

That's all I've got.

jennifer.chang’s picture

P.S.
Above, I inserted some spaces in the PHP tags, because they were messing with the formatting of the comment within this issue.

'body' => 'Hey < ?php $account->name; ? >, welcome on our site!'

Mobo’s picture

Hi I get the exact same error. Really hope that we can find a fix !
Thanks
Mobo

jennifer.chang’s picture

@Berdir: have you been able to reproduce with the requested info that I provided?

konordo’s picture

Same issues too. I made it working by building the rule from scratch, instead of using the pre-configured one that comes with the module (The author does not appear to be a user object, as jennifer.chang says above).
I understand this is not really helpfull, sorry for that - I will try to come back to it if time allows.

oadaeh’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

This issue is being closed because it is against a branch for a version of Drupal that is no longer supported.
If you feel that this issue is still valid, feel free to re-open and update it (and any possible patch) to work with the 7.x-1.x branch (bug fixes only) or the 7.x-2.x branch.
Thank you.