1

I have created an activity log using the Message module. It is about Statuses module (for which I'm using the DEV version). When someone comments on a status update, the activity is logged, but it should be logged for the status update owner and not the current user.

Currently, when I create the rules action "Create new entity" in the rules setup, the only replacement pattern available in the data selector for "User for which to log" is 'site:current-user'. Here I want 'status:status-sender' and not 'site:current-user'. The owner of the status update must receive the notification and not the user who commented.

Message export

{
  "name" : "status_comments",
  "description" : "Status comments",
  "argument_keys" : [ "@status_comments_user" ],
  "argument" : [],
  "category" : "message_type",
  "data" : {
    "token options" : { "clear" : 0 },
    "purge" : { "override" : 0, "enabled" : 0, "quota" : "", "days" : "" }
  },
  "language" : "",
  "arguments" : null,
  "message_text" : { "und" : [
      {
        "value" : "@status_comments_user commented on your status",
        "format" : "plain_text",
        "safe_value" : "@status_comments_user commented on your status"
      }
    ]
  },
  "rdf_mapping" : []
}

Rules export

{ "rules_posted_statuses_comment" : {
    "LABEL" : "Posted a statuses comment",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "statuses" ],
    "REQUIRES" : [ "fbss_comments_rules", "rules" ],
    "ON" : { "fbss_comments_save" : [] },
    "IF" : [ { "NOT fbss_comments_rules_on_own" : { "comment" : [ "comment" ] } } ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "message",
            "param_type" : "status_comments",
            "param_user" : [ "site:current-user" ]
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      },
      { "data_set" : {
          "data" : [ "entity-created:arguments:status-comments-user" ],
          "value" : "[comment:commenter]"
        }
      }
    ]
  }
}

Note: This is strange because I have another message type with the event "user saves a status" and in its rules action, it shows all replacement patterns for statuses in data selectors

1

Looks like you're starting to hit the limits of the most recent (beta2) release of the Statuses module. Have a look at this variation of a custom rule, which is included in Comment nr 13 of issue nr 1693620:

{ "rules_user_commented_on_status" : {
    "LABEL" : "User commented on a status",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "Statuses" ],
    "REQUIRES" : [ "fbss_rules", "rules", "fbss_comments_rules" ],
    "ON" : [ "fbss_comments_save" ],
    "DO" : [
      { "fbss_rules_load_action" : {
          "USING" : { "sid" : [ "comment:sid" ] },
          "PROVIDE" : { "status_loaded" : { "status_loaded" : "Loaded status" } }
        }
      },
      { "mail" : {
          "to" : "[status-loaded:sender:mail]",
          "subject" : "[comment:commenter:name] commented on your status",
          "message" : "Hi [status-loaded:sender:name],\r\n\r\n[comment:commenter:name] commented on your status [status-loaded:message-formatted]\r\n\r\n\r\nRegards,\r\n[site:name]"
        }
      }
    ]
  }
}

Even though this is not really the rule you're looking for, pay attention to the "to" field in the eMail being constructed. That to-field uses token ...sender:mail, which is close to the uid (I believe) of the "sender".

That very same comment in that issue also includes a patch (which I believe is committed to the current DEV version), clearly an improvement (not a bug fix ...) because it makes extra data available for subsequent Rules processing. This patch appears to be a prereq for the above rule to work: I tried to import that rule in a site using the beta2 version, but that import failed (and "I" do not want to use a DEV version, even using beta-versions is exceptional to me).

I suggest you either try to apply that patch in your current setup, or switch to the DEV version of that module. After you do so, continue with these extra steps:

  • Try to import that same eMail example, so that you have a sample rule that is close to what you'll need.
  • Expand your own rule, to also add such "load action" and then check if you have a similar token like that [status-loaded:sender:mail], which in your case should become something like [status-loaded:sender:name] or [status-loaded:sender:uid].

If you get that import of the eMail sample to work, then I would assume (have not tested it myself and leave that to you) that this comination of your rule with part of the eMail sample here is what you're looking for:

{ "rules_posted_statuses_comment" : {
"LABEL" : "Posted a statuses comment",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"TAGS" : [ "statuses" ],
"REQUIRES" : [ "fbss_comments_rules", "fbss_rules", "rules" ],
"ON" : { "fbss_comments_save" : [] },
"IF" : [ { "NOT fbss_comments_rules_on_own" : { "comment" : [ "comment" ] } } ],
"DO" : [
  { "fbss_rules_load_action" : {
      "USING" : { "sid" : [ "comment:sid" ] },
      "PROVIDE" : { "status_loaded" : { "status_loaded" : "Loaded status" } }
    }
  },
  { "entity_query" : {
      "USING" : {
        "type" : "user",
        "property" : "uid",
        "value" : [ "status-loaded:sender" ],
        "limit" : "1"
      },
      "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }
    }
  },
  { "entity_create" : {
      "USING" : {
        "type" : "message",
        "param_type" : "status_comments",
        "param_user" : [ "entity-fetched:0" ]
      },
      "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
    }
  },
  { "data_set" : {
      "data" : [ "entity-created:arguments:status-comments-user" ],
      "value" : "[comment:commenter]"
    }
  }
]

} }

Note the status-loaded:sender in the above rule! Which should be a token you can use because of the very first Rules Action added now.

Disclaimer: I have NOT (repeat NOT) tested this last rule (since I never use DEV versions of a module). Though chances are that by copy/pasting relevant parts of your original (exported) rule and the (exported) eMail rule it does work as it should.

Note: I'm about sure that the integrity check you got (when trying to import my updated rule, as you wrote in a comment to this answer) is because "status-loaded:sender" is not returned as a "User entity". While the Message module wants/expects the "param_user" to be a "User entity".

You might be able to "convert" that "status-loaded:sender", by adding a Rules Action "Fetch entity by property", whereas you would use "status-loaded:sender" as the property to do so. The entity type to be fetched should be, for sure, a "user" entity (not a "message"!). This Rules Action should be inserted after the first "fbss_rules_load_action".

The result of performing that extra Rules Action is then an actual "user entity" (a real entity), and that is what you might then use for that "param_user" (which should avoid the integrity check error).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.