You are here

function memcache_admin_menu in Memcache API and Integration 5

Same name and namespace in other branches
  1. 5.2 memcache_admin/memcache_admin.module \memcache_admin_menu()
  2. 6 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($may_cache) {
  $items = array();
  if ($may_cache) {
    $items[] = array(
      'path' => 'admin/settings/memcache',
      'title' => t('Memcache'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'memcache_admin_admin_settings',
      ),
      'access' => user_access('administer site configuration'),
      'type' => MENU_NORMAL_ITEM,
    );
    $items[] = array(
      'path' => 'admin/logs/memcache',
      'callback' => 'memcache_admin_stats',
      'title' => t('Memcache status'),
      'access' => user_access('access memcache statistics'),
      'description' => t("View the statistics for this site's memcache and generate new settings."),
      'weight' => 1,
    );
  }
  else {
    if (arg(0) == 'admin' && arg(1) == 'logs' && arg(2) == 'memcache') {
      $memache_servers = variable_get('memcache_servers', array());
      $clusters = array();
      foreach ($memache_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[] = array(
            'path' => 'admin/logs/memcache/' . $cluster,
            'type' => $count == 0 ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
            'callback' => 'memcache_admin_stats',
            'callback arguments' => array(
              $cluster,
            ),
            'title' => $cluster,
            'access' => user_access('access memcache statistics'),
            'weight' => $count,
          );
          $count++;
          if ($cluster == $current_cluster) {
            $sub_count = 0;
            foreach (array(
              'default',
              'reset',
              'malloc',
              'maps',
              'slabs',
              'items',
              'sizes',
            ) as $type) {
              $items[] = array(
                'path' => 'admin/logs/memcache/' . $cluster . '/' . $type,
                'type' => $type == 'default' ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
                'callback' => 'memcache_admin_stats',
                'callback arguments' => array(
                  $cluster,
                  $type,
                ),
                'title' => $type,
                'access' => user_access('access memcache statistics'),
                'weight' => $sub_count,
              );
              $sub_count++;
            }
          }
        }
      }
    }
  }
  return $items;
}