You are here

function dna_summary in Devel 7

Same name and namespace in other branches
  1. 5 devel_node_access.module \dna_summary()
  2. 6 devel_node_access.module \dna_summary()

Page callback for the Devel node access summary.

1 string reference to 'dna_summary'
devel_node_access_menu in ./devel_node_access.module
Implements hook_menu().

File

./devel_node_access.module, line 148
Functions for debugging node access permissions.

Code

function dna_summary() {

  // warn user if they have any entries that could grant access to all nodes
  $output = '';
  $result = db_query('SELECT DISTINCT realm FROM {node_access} WHERE nid = 0 AND gid = 0');
  $rows = array();
  foreach ($result as $row) {
    $rows[] = array(
      $row->realm,
    );
  }
  if (!empty($rows)) {
    $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'),
    );
    $output .= theme('table', array(
      'header' => $headers,
      'rows' => $rows,
    ));
    $access_granted_to_all_nodes = TRUE;
  }

  // how many nodes are not represented in the node_access table
  $num = 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')
    ->fetchField();
  if ($num) {
    $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');
  $rows = array();
  foreach ($result as $row) {
    $rows[] = array(
      $row->realm,
    );
  }
  if (!empty($rows)) {
    $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'),
    );
    $output .= theme('table', array(
      'header' => $headers,
      'rows' => $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');
  $rows = array();
  foreach ($result as $row) {
    $rows[] = array(
      $row->realm,
      array(
        'data' => $row->node_count,
        'align' => 'center',
      ),
    );
  }
  if (!empty($rows)) {
    $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'),
    );
    $output .= theme('table', array(
      'header' => $headers,
      'rows' => $rows,
      'caption' => 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');
  $rows = array();
  foreach ($result as $row) {

    // no Views yet:

    //$rows[] = array(l($row->realm, "devel/node_access/view/$row->realm"),
    $rows[] = array(
      $row->realm,
      array(
        'data' => $row->node_count,
        'align' => 'center',
      ),
    );
  }
  if (!empty($rows)) {
    $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'),
    );
    $output .= theme('table', array(
      'header' => $headers,
      'rows' => $rows,
      'caption' => t('Protected Nodes'),
    ));
  }
  return $output;
}