Hello,

I want to make an OG group private by using a custom php code action in Rules, as I did not find an action for this purpose.
The table is og and the field og_private for the group node has to be set to 1 for the group to be private.

Rules says the variable $node_added_empresa is available.

This is the code I am trying with, unsuccessfully.

global $node_added_empresa;
$sql="UPDATE {og} SET `og_private` = '1' WHERE {og}.`nid` = "$node_added_empresa->nid";
$result = db_query($sql);

Please help.

Comments

nevets’s picture

What triggers the rule?

Why not just set the group settings so the group is private by default?

Enrique.Ruiz’s picture

Because I am using OG as an access control system.
I am letting my users create groups, and all of them have to be automatically made private using rules.

Enrique.Ruiz’s picture

I am new to PHP so I do not know if I am using the variable properly.
I tried with a token but it was not working. ( I save the node inmediately in rules first fot it to get a nid)
Please help.

Enrique.Ruiz’s picture

Fixed. I failed doing it with PHP, as I am new to it, and I didn't get much help.

So I created a new OG action called 'Make group private' based on an existing one. I included this in the og_actions module.

adding this:

    'og_make_group_private_action' => array(
        'type' => 'node',
        'description' => t('Make group private'),
        'behavior' => array('changes_node_property'), // For Views Bulk Operations module
        'configurable' => FALSE,
        'hooks' => array(
          'nodeapi' => array('insert', 'update'),
        ),
       ),

and this:

/**
 * Action to make a group private. Requires actions.module.
 */
function og_make_group_private_action($node, $context) {
  if (!isset($node->og_groups)) {
    $node->og_private = 1;
    watchdog('action', 'Set group %id to private.', array('%id' => intval($node->nid)));
  }
}