1

We have a flag for nodes called subscribe_og.

From this point in time users will click that flag to join, or leave, a group.

If you are not a member of the group, the flag says 'Join'. If you are a member the flag says 'leave'.

Old members of a group currently see 'leave' as they have not clicked the flag.

Is it possible to use Views and Rules to generate a list of group members, check if they have have activated the node flag, and if not, activate the node flag for them?

I had a little look at Rules Components and came up with this, which seems to do nothing.

    { "rules_gerw" : {
    "LABEL" : "gerw",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "flag", "og" ],
    "IF" : [
      { "NOT flag_flagged_node" : {
          "flag" : "subscribe_og",
          "node" : [ "site:og-context--node" ],
          "flagging_user" : [ "site:current-user" ]
        }
      },
      { "AND" : [
          { "og_user_in_group" : {
              "account" : [ "site:current-user" ],
              "group" : [ "site:og-context--node" ],
              "states" : { "value" : { "1" : "1" } }
            }
          }
        ]
      }
    ],
    "DO" : [
      { "flag_flagnode" : {
          "flag" : "subscribe_og",
          "node" : [ "site:og-context--node" ],
          "flagging_user" : [ "site:current-user" ],
          "permission_check" : "1"
        }
      }
    ]
  }
}
1

Step 1: Fix your rules Component

The "... seems to do nothing ..."-part of your question, is like a variation of "it doesn't work" ... which is extremely hard to debug without access to your site.

However, what I find bizarre about your Rules Component is:

  1. You're using token site:og-context--node, but there is nothing in your rule that assigns a value to it. So wild guess: it's value is blank or something like that. If my guess is correct, then your rule "works as implemented, ie "it is doing nothing", because not both Rules Conditions are satisfied.
  2. It is related to user = site:current-user. So you've to be a bit lucky to have this Rules Condition satisfied (it depends if the current user is yes or no member of some group which might be blank).

What I think is needed, at a minimum, is that you use appropriate parameters for this Rules Component, actually for all of your tokens you're using that start with site:.

To do so, have a look at this improved version of your Rules Component. The main difference with yours is that I introduced 2 parameters, and replaced all site:

{ "rules_using_parameters" : {
    "LABEL" : "A Rules component using parameters",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "flag", "og" ],
    "USES VARIABLES" : {
      "flagging_user" : { "label" : "Flagging user", "type" : "user" },
      "node_to_flag" : { "label" : "Node to be flagged", "type" : "node" }
    },
    "IF" : [
      { "NOT flag_flagged_node" : {
          "flag" : "subscribe_og",
          "node" : [ "node-to-flag" ],
          "flagging_user" : [ "flagging-user" ]
        }
      },
      { "AND" : [
          { "og_user_in_group" : {
              "account" : [ "flagging-user" ],
              "group" : [ "node-to-flag" ],
              "states" : { "value" : { "1" : "1" } }
            }
          }
        ]
      }
    ],
    "DO" : [
      { "flag_flagnode" : {
          "flag" : "subscribe_og",
          "node" : [ "node-to-flag" ],
          "flagging_user" : [ "flagging-user" ],
          "permission_check" : "1"
        }
      }
    ]
  }
}

You should be able to just copy the exported rule above, and simply import this Rules Component in your own environment.

After you did this, navigate to admin/config/workflow/rules/components in your own site, and then use the hyperlink "execute" to qa-test it in your own site. After you use that link, use the button that says Switch to direct input mode. Then you'll be able to enter some Node to be flagged. Use a similar technique to specify the Flagging and hit the Execute mode.

If both Rules Conditions are satisfied, then the node you selected will be marked as flagged by the user you specified.

So please do some QA-testing of this variation of your rule. And make sure to select accurate testcase (different from your own userid, aka site:current-user).

And if this QA-testing results in "... it still does nothing ...", then perform appropriate Rules debugging, as explained in my answer to "How can I display the value of a variable inside a condition?".

Move on to Step 2 after your QA-testing is completed (and you're sure the rule works as designed).

Step 2: Let VBO do the bulk of the work

This step is pretty easy ... Just create an appropriate view of all your nodes to be processed, and transform it into a Views Bulk Operations view. The clue to what you want VBO to do as an operation is ... you guessed it: Execute the Rules Component from Step 1.

If you're not familiar with how to do so, have a look at the video about Using Rules components with VBO". If you want even more, then also watch the subsequent "Using Rules components with more than one parameter" video.

Attention: to process many nodes at once is quite a challenge (memory requirements, etc). Therefor you might want to also watch the video about "More details about VBO settings" ... Before you are tempted to use VBO for processing them all at once ...

Happy VBO-ing while Rules-ing!

  • Yay, we are up and running. In the View, I set the Bulk Operation to Enqueue the operation instead of executing it directly, then we run it in Cron and it works. Right now, I set all the nodes to be checked then I manually type in a User ID. Is there a way for the Rule to use a list of users instead of a single user? – studiocomms Dec 6 '16 at 13:52
  • @studiocomms sorry your prior comment slipped my mind. Do you mean that using what I suggested here does work for you now, though you had to adapt VBO settting with that enqueue? Also, I don't really understand the "Right now, ... single user?" part of your last comment. Can you try again? Or maybe this is like a followup-question or so that you may want to post as a new question (which gives us more "room" to phrase the question, and possible answers)? – Pierre.Vriens Dec 9 '16 at 12:01

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.