You are here

function dna_summary in Devel 5

Same name and namespace in other branches
  1. 6 devel_node_access.module \dna_summary()
  2. 7 devel_node_access.module \dna_summary()
1 string reference to 'dna_summary'
devel_node_access_menu in ./devel_node_access.module

File

./devel_node_access.module, line 86
This module gives developers feedback as to what their node_access table contains, and which nodes are protected or visible to the public.

Code

function dna_summary() {

  // Warn user if they have any entries that could grant access to all nodes
  $result = db_query('SELECT DISTINCT realm FROM {node_access} WHERE nid=0 AND gid=0');
  if (db_num_rows($result)) {
    $output .= '<h3>' . t('Access Granted to All Nodes (All Users)') . "</h3>\n";
    $output .= '<p>' . t('Your node_access table contains entries that may be granting all users access to all nodes.  Depending on which access control module(s) you use, you may want to delete these entries.  If you are not using an access control module, you should probably leave these entries as is.') . "</p>\n";
    $headers = array(
      t('realm'),
    );
    $rows = array();
    while ($row = db_fetch_object($result)) {
      $rows[] = array(
        $row->realm,
      );
    }
    $output .= theme_table($headers, $rows);
    $access_granted_to_all_nodes = TRUE;
  }

  // how many nodes are not represented in the node_access table
  $result = db_fetch_object(db_query('SELECT COUNT(n.nid) as num_nodes FROM {node} n LEFT JOIN {node_access} na ON n.nid = na.nid WHERE na.nid IS NULL'));
  if ($num = $result->num_nodes) {
    $output .= '<h3>' . t('Legacy Nodes') . "</h3>\n";
    $output .= '<p>' . t('You have !num nodes in your node table which are not represented in your node_access table.  If you have an access control module installed, these nodes may be hidden from all users.  This could be caused by publishing nodes before enabling the access control module.  If this is the case, manually updating each node should add it to the node_access table and fix the problem.', array(
      '!num' => l($num, 'devel/node_access/view/NULL'),
    )) . "</p>\n";
    if (!empty($access_granted_to_all_nodes)) {
      $output .= '<p>' . t('This issue may be masked by the one above, so look into the former first.') . "</p>\n";
    }
  }
  else {
    $output .= '<h3>' . t('All Nodes Represented') . "</h3>\n";
    $output .= '<p>' . t('All nodes are represented in the node_access table.') . "</p>\n";
  }

  // a similar warning to the one above, but slightly more specific
  $result = db_query('SELECT DISTINCT realm FROM {node_access} WHERE nid = 0 AND gid <> 0');
  if (db_num_rows($result)) {
    $output .= '<h3>' . t('Access Granted to All Nodes (Some Users)') . "</h3>\n";
    $output .= '<p>' . t('Your node_access table contains entries that may be granting some users access to all nodes.  This may be perfectly normal, depending on which access control module(s) you use.') . "</p>\n";
    $headers = array(
      t('realm'),
    );
    $rows = array();
    while ($row = db_fetch_object($result)) {
      $rows[] = array(
        $row->realm,
      );
    }
    $output .= theme_table($headers, $rows);
  }

  // find specific nodes which may be visible to all users
  $result = db_query('SELECT DISTINCT realm, COUNT(DISTINCT nid) as node_count FROM {node_access} WHERE gid=0 AND nid > 0 GROUP BY realm');
  if (db_num_rows($result)) {
    $output .= '<h3>' . t('Access Granted to Some Nodes') . "</h3>\n";
    $output .= '<p>' . t('The following realms appear to grant all users access to some specific nodes.  This may be perfectly normal, if some of your content is available to the public.') . "</p>\n";
    $headers = array(
      t('realm'),
      t('public nodes'),
    );
    $rows = array();
    while ($row = db_fetch_object($result)) {
      $rows[] = array(
        $row->realm,
        array(
          'data' => $row->node_count,
          'align' => 'center',
        ),
      );
    }
    $output .= theme_table($headers, $rows, array(), t('Public Nodes'));
  }

  // find specific nodes protected by node_access table
  $result = db_query('SELECT DISTINCT realm, COUNT(DISTINCT nid) as node_count FROM {node_access} WHERE gid <> 0 AND nid > 0 GROUP BY realm');
  if (db_num_rows($result)) {
    $output .= '<h3>' . t('Summary by Realm') . "</h3>\n";
    $output .= '<p>' . t('The following realms grant limited access to some specific nodes.') . "</p>\n";
    $headers = array(
      t('realm'),
      t('private nodes'),
    );
    $rows = array();
    while ($row = db_fetch_object($result)) {
      $rows[] = array(
        l($row->realm, "devel/node_access/view/{$row->realm}"),
        array(
          'data' => $row->node_count,
          'align' => 'center',
        ),
      );
    }
    $output .= theme_table($headers, $rows, array(), t('Protected Nodes'));
  }
  return $output;
}