You are here

function memcache_admin_menu in Memcache API and Integration 6

Same name and namespace in other branches
  1. 5.2 memcache_admin/memcache_admin.module \memcache_admin_menu()
  2. 5 memcache_admin/memcache_admin.module \memcache_admin_menu()
  3. 7 memcache_admin/memcache_admin.module \memcache_admin_menu()

Implementation of hook_menu().

File

memcache_admin/memcache_admin.module, line 31

Code

function memcache_admin_menu() {
  if (module_exists('memcache') && module_exists('admin_menu')) {

    // This is a workaround for issue #1807914. When both admin_menu and
    // memcache modules are enabled, there is a crossover with
    // hook_admin_menu().
    $backtrace = debug_backtrace(FALSE, 1);
    if (isset($backtrace[0]['file']) && stripos($backtrace[0]['file'], '/admin_menu/') !== FALSE) {

      // The function has been called by the admin_menu module.
      return array();
    }
  }
  $items['admin/settings/memcache'] = array(
    'title' => 'Memcache',
    'description' => 'Show or hide memcache statistics at the bottom of each page.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'memcache_admin_admin_settings',
    ),
    'access arguments' => array(
      'administer site configuration',
    ),
  );
  $items['admin/reports/memcache'] = array(
    'title' => 'Memcache statistics',
    'description' => "View statistics for all configured memcache servers.",
    'page callback' => 'memcache_admin_stats',
    'access arguments' => array(
      'access memcache statistics',
    ),
    'weight' => 1,
  );
  $memcache_servers = variable_get('memcache_servers', array(
    '127.0.0.1:11211' => 'default',
  ));
  $clusters = array();
  foreach ($memcache_servers as $server => $cluster) {
    $clusters[$cluster]['servers'][] = $server;
    $clusters[$cluster]['bin'] = _memcache_admin_get_bin_for_cluster($cluster);
  }
  $count = 0;
  foreach ($clusters as $cluster => $cluster_info) {
    if ($cluster_info['bin']) {
      if (empty($current_cluster)) {
        $current_cluster = arg(3);
        if (empty($current_cluster)) {
          $current_cluster = $cluster;
        }
      }
      $items['admin/reports/memcache/' . $cluster] = array(
        'title' => $cluster,
        'type' => $count == 0 ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
        'page callback' => 'memcache_admin_stats',
        'page arguments' => array(
          $cluster,
        ),
        'access arguments' => array(
          'access memcache statistics',
        ),
        'weight' => $count++,
      );
      foreach ($cluster_info['servers'] as $server) {
        $items["admin/reports/memcache/{$cluster}/{$server}"] = array(
          'title' => check_plain($server),
          'type' => MENU_CALLBACK,
          'page callback' => 'memcache_admin_stats_raw',
          'page arguments' => array(
            $cluster,
            $server,
          ),
          'access arguments' => array(
            'access memcache statistics',
          ),
        );
        foreach (memcache_admin_stats_types($cluster) as $type) {
          $items["admin/reports/memcache/{$cluster}/{$server}/{$type}"] = array(
            'type' => MENU_CALLBACK,
            'page callback' => 'memcache_admin_stats_raw',
            'page arguments' => array(
              $cluster,
              $server,
              $type,
            ),
            'title' => $type,
            'access arguments' => array(
              'access memcache statistics',
            ),
          );
        }
      }
    }
  }
  return $items;
}