array( 'description' => t('View the devel information for Solr searches. Raw data is returned by Solr meaning that sensitive data could be exposed that would normally be protected by various access control systems.'), 'title' => t('Access Solr Devel Information'), 'restrict access' => TRUE, ), ); } /** * Implements hook_menu(). */ function solr_devel_menu() { $items = array(); $items['admin/config/search/solr_devel'] = array( 'title' => 'Solr Devel settings', 'description' => 'Configure debugging settings for Solr searches.', 'page callback' => 'drupal_get_form', 'page arguments' => array('solr_devel_settings_form'), 'file' => 'solr_devel.admin.inc', 'access arguments' => array('view solr_devel information'), ); $items['node/%node/devel/solr'] = array( 'title' => 'Solr Index', 'page callback' => 'solr_devel_node_overview_page', 'page arguments' => array(1), 'access arguments' => array('view solr_devel information'), 'type' => MENU_LOCAL_TASK, 'file' => 'solr_devel.pages.inc', ); $items['node/%node/devel/solr/%solr_devel_environment/entity'] = array( 'title' => 'Solr Entity Analysis', 'page callback' => 'solr_devel_node_entity_analysis_page', 'page arguments' => array(1, 4), 'access arguments' => array('view solr_devel information'), 'type' => MENU_LOCAL_TASK, 'file' => 'solr_devel.pages.inc', ); $items['node/%node/devel/solr/%solr_devel_environment/document'] = array( 'title' => 'Solr Document Analysis', 'page callback' => 'solr_devel_node_document_analysis_page', 'page arguments' => array(1, 4), 'access arguments' => array('view solr_devel information'), 'type' => MENU_LOCAL_TASK, 'file' => 'solr_devel.pages.inc', ); $items['node/%node/devel/solr/%solr_devel_environment/query'] = array( 'title' => 'Solr Query Analysis', 'page callback' => 'drupal_get_form', 'page arguments' => array('solr_devel_node_query_analysis_form', 1, 4), 'access arguments' => array('view solr_devel information'), 'type' => MENU_LOCAL_TASK, 'file' => 'solr_devel.pages.inc', ); $items['node/%node/devel/solr/%solr_devel_environment/queue'] = array( 'title' => 'Solr Queue Analysis', 'page callback' => 'solr_devel_node_queue_analysis_page', 'page arguments' => array(1, 4), 'access arguments' => array('view solr_devel information'), 'type' => MENU_LOCAL_TASK, 'file' => 'solr_devel.pages.inc', ); return $items; } /** * Implements hook_menu_alter(). */ function solr_devel_menu_alter(&$items) { unset($items['node/%node/devel/apachesolr']); } /** * Implements hook_solr_devel_environment_info(). */ function apachesolr_solr_devel_environment_info() { $info = array(); foreach (apachesolr_load_all_environments() as $env_id => $environment) { $info['apachesolr:' . $env_id] = array( 'label' => 'Apache Solr: ' . $environment['name'], 'adapter' => 'Drupal_SolrDevel_Adapter_ApacheSolr', 'adapter options' => array('env_id' => $env_id), ); } return $info; } /** * Gets environment info. * * @return array * An array of environment info. */ function solr_devel_get_environment_info() { $environments = array(); foreach (module_invoke_all('solr_devel_environment_info') as $name => $info) { $environments[$name] = $info + array( 'name' => $name, 'label' => $name, 'adapter options' => array(), ); } return $environments; } /** * Loads an environment. * * @param string $id * The unique identifier of the environment. * * @return array|FALSE * The environment definition, FALE if not available. */ function solr_devel_environment_load($id) { $environments = solr_devel_get_environment_info(); return isset($environments[$id]) ? $environments[$id] : FALSE; } /** * Loads an adapter from an environment definition. * * @param array $environment * The environment definition as returned by solr_devel_environment_load(). * * @return Drupal_SolrDevel_Adapter * The adapter instance. */ function solr_devel_adapter_load(array $environment) { return new $environment['adapter']($environment['label'], $environment['adapter options']); } /** * Implements hook_apachesolr_query_alter(). */ function solr_devel_apachesolr_query_alter(DrupalSolrQueryInterface $query) { $force = &drupal_static('solr_devel_force_query_alter', FALSE); if ($force || (variable_get('solr_devel:debug_queries', 0) && user_access('view solr_devel information'))) { // Add the Solr debug parameter. $query->addParam('debugQuery', 'on'); // Store the searcher so we can get the active searchers later. $searchers = &drupal_static('solr_devel_apachesolr_searchers', array()); $searchers[] = $query->getSearcher(); } } /** * Implements hook_block_info(). */ function solr_devel_block_info() { $blocks = array(); $blocks['query_debug'] = array( 'info' => 'Solr Devel: Query Debugger', 'cache' => DRUPAL_NO_CACHE, ); return $blocks; } /** * Implements hook_block_view(). */ function solr_devel_block_view($delta = '') { if ('query_debug' == $delta) { $debug = array(); // Iterate over searchers and gather debug data for all of them. $searchers = &drupal_static('solr_devel_apachesolr_searchers', array()); foreach ($searchers as $searcher) { if ($response = apachesolr_static_response_cache($searcher)) { // Get the debug output, initialize request array. $debug[$searcher]['debug'] = $response->debug; $debug[$searcher]['request'] = array( 'method' => '', 'uri' => '', 'parseduri' => array(), ); // Parse the request, check whether GET or POST was issued. $pattern = '@(GET|POST)\s+(.*)\s+(?:HTTP/1.[01])@s'; if (preg_match_all($pattern, $response->request, $matches)) { $debug[$searcher]['request'] = array( 'method' => $matches[1][0], 'uri' => $matches[2][0], 'parseduri' => parse_url($matches[2][0]), ); // Parses query string into an array. Note that drupal_parse_url() // strips params such as 'q', so we use native PHP functions instead. if (!empty($debug[$searcher]['request']['parseduri']['query'])) { $query = &$debug[$searcher]['request']['parseduri']['query']; parse_str($query, $query); } } } } // If we have debug information, display. if ($debug) { return array( 'subject' => t('Solr query debugger'), 'content' => kprint_r($debug, TRUE), ); } } }