The private module works great if you install it before you create any content. You can do some easy SQL to update the current nodes to reflect the new module being installed, but the average user cannot do this. So I propose an addition to the node operations under the admininstrate content menu. The code I am suggesting to add to this module is below, it just needs to be added to the end of the module (don't include the <php and the ?> tags).


/**
 * Implementation of hook_node_operations().
 */
function private_node_operations() {
  $operations = array(
    'mark_as_private' => array(
      'label' => t('Mark nodes as private'),
      'callback' => 'private_node_mark_private',
    ),
    'mark_as_public' => array(
      'label' => t('Mark nodes as public'),
      'callback' => 'private_node_mark_public',
    ),
  );
  return $operations;
}

/**
 * Callback for 'Mark as private' node operation
 */
function private_node_mark_private($nids) {
  foreach ($nids as $nid) {
    if (db_num_rows(db_query("SELECT private FROM {private} WHERE nid = %d", $nid)) > 0) {
      db_query('UPDATE {private} SET private = %d WHERE nid = %d', 1, $nid);
    } else {
      db_query('INSERT INTO {private} (nid, private) VALUES (%d, %d)', $nid, 1);
    }
  }
}

/**
 * Callback for 'Mark as public' node operation
 */
function private_node_mark_public($nids) {
  foreach ($nids as $nid) {
    if (db_num_rows(db_query("SELECT private FROM {private} WHERE nid = %d", $nid)) > 0) {
      db_query('UPDATE {private} SET private = %d WHERE nid = %d', 0, $nid);
    } else {
      db_query('INSERT INTO {private} (nid, private) VALUES (%d, %d)', $nid, 0);
    }
  }
}

Comments

greggles’s picture

Title: Hook into node operations » Hook into node operations & set default during install
Version: 5.x-1.0 » 6.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new1.97 KB

Providing node operations is almost always a good thing, so I agree with that (views bulk operations...!)

I also think that this should set an explicit default to public when it is installed.

So, the attached patch updates these node_operations for 6.x style so that they don't use the db_num_rows patch and also adds a default of public.

dwees’s picture

Did I really write this? God this issue is old, I'm glad someone is picking this up, I don't even remember using the private module.

Dave

eaton’s picture

Status: Needs review » Fixed

Committed to the D6 branch. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.