diff --git a/apachesolr.admin.inc b/apachesolr.admin.inc index 063810c..a0cb1a7 100644 --- a/apachesolr.admin.inc +++ b/apachesolr.admin.inc @@ -97,7 +97,7 @@ function apachesolr_environment_edit_form(&$form_state, $environment = NULL) { if (empty($environment)) { $environment = array(); } - $environment += array('env_id' => '', 'name' => '', 'url' => '', 'service_class' => '', 'conf' => array()); + $environment += array('env_id' => '', 'name' => '', 'url' => '', 'conf' => array('service_class' => '')); $form['url'] = array( '#type' => 'textfield', @@ -131,7 +131,7 @@ function apachesolr_environment_edit_form(&$form_state, $environment = NULL) { ); $form['service_class'] = array( '#type' => 'value', - '#value' => $environment['service_class'], + '#value' => $environment['conf']['service_class'], ); $form['conf'] = array( '#tree' => TRUE, @@ -340,7 +340,7 @@ function apachesolr_settings(&$form_state) { // want to check the statusses of any environment $class = ''; if (empty($form_state['input'])) { - $class = apachesolr_server_status($data['url'], $data['service_class']) ? 'ok' : 'error'; + $class = apachesolr_server_status($data['url'], $data['conf']['service_class']) ? 'ok' : 'error'; } $headers = array( @@ -446,7 +446,7 @@ function apachesolr_status_page($environment = NULL) { } // Check for availability - if (!apachesolr_server_status($environment['url'], $environment['service_class'])) { + if (!apachesolr_server_status($environment['url'], $environment['conf']['service_class'])) { drupal_set_message(t('The server seems to be unavailable. Please verify the server settings at the settings page', array('!settings_page' => url("admin/settings/apachesolr/settings/{$environment['env_id']}/edit", array('query' => drupal_get_destination())))), 'warning'); return ''; } diff --git a/apachesolr.install b/apachesolr.install index 0c32cf9..76516ac 100644 --- a/apachesolr.install +++ b/apachesolr.install @@ -72,8 +72,8 @@ function apachesolr_install() { apachesolr_search_mlt_save_block(array('name' => t('More like this'))); // Insert our default environment - db_query("INSERT INTO {apachesolr_environment} (env_id, name, url, service_class) - VALUES ('%s', '%s', '%s', '%s')", array('solr', 'localhost server', 'http://localhost:8983/solr', '')); + db_query("INSERT INTO {apachesolr_environment} (env_id, name, url) + VALUES ('%s', '%s', '%s', '%s')", array('solr', 'localhost server', 'http://localhost:8983/solr')); // Initialize the entities to index. We enable all node types by default $env_id = apachesolr_default_environment(); @@ -150,13 +150,6 @@ function apachesolr_schema() { 'length' => 1000, 'not null' => TRUE, ), - 'service_class' => array( - 'description' => 'Optional class name to use for connection', - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '' - ), ), 'primary key' => array('env_id'), ); @@ -307,4 +300,13 @@ function apachesolr_update_6301() { db_add_index($ret, $table, 'bundle_changed', array('bundle', 'changed')); } return $ret; -} \ No newline at end of file +} + +/** + * Remove status from the key. + */ +function apachesolr_update_6302() { + $ret = array(); + db_drop_field($ret, 'apachesolr_environment', 'service_class'); + return $ret; +} diff --git a/apachesolr.module b/apachesolr.module index 13d925a..a8fd0b7 100644 --- a/apachesolr.module +++ b/apachesolr.module @@ -1091,19 +1091,21 @@ function apachesolr_get_solr($env_id = NULL, $reset = FALSE) { // @Todo // Extra service classes should include their file on their own responsability if (isset($environments[$env_id])) { - $class = $environments[$env_id]['service_class']; + $class_info = isset($environments[$env_id]['conf']['service_class']) ? $environments[$env_id]['conf']['service_class'] : NULL; - if (empty($solr_cache[$env_id])) { - // Use the default class if none is specified. + // Use the default class if none is specified. + if (!is_array($class_info) && !isset($class_info['class'])) { $class_info = variable_get('apachesolr_service_class', array( 'file' => 'Drupal_Apache_Solr_Service', 'module' => 'apachesolr', 'class' => 'DrupalApacheSolrService')); - - if (!class_exists($class) && isset($class_info['file']) && isset($class_info['module'])) { - module_load_include('php', $class_info['module'], $class_info['file']); - $class = $class_info['class']; - } + } + if (!class_exists($class_info['class']) && isset($class_info['file']) && isset($class_info['module'])) { + module_load_include('php', $class_info['module'], $class_info['file']); + } + $class = $class_info['class']; + + if (empty($solr_cache[$env_id])) { // Takes advantage of auto-loading. $solr = new $class($environments[$env_id]['url'], $env_id); $solr_cache[$env_id] = $solr; @@ -1250,7 +1252,7 @@ function apachesolr_environment_clone($env_id) { // Remove any unexpected fields. // @todo - get this from the schema?. $environment = array_intersect_key($environment, $default); - $query = "INSERT INTO {apachesolr_environment} (env_id, name, url, service_class) VALUES ('%s', '%s', '%s', '%s')"; + $query = "INSERT INTO {apachesolr_environment} (env_id, name, url) VALUES ('%s', '%s', '%s')"; db_query($query, $environment); // Update the environment variables (if any). @@ -1296,7 +1298,7 @@ function apachesolr_create_unique_id($existing, $id) { function apachesolr_environment_save($environment) { static $environments; static $solr_cache; - $default = array('env_id' => NULL, 'name' => '', 'url' => '', 'service_class' => '', 'conf' => array()); + $default = array('env_id' => NULL, 'name' => '', 'url' => '', 'conf' => array()); $old_environment = apachesolr_environment_load($environment['env_id']); $is_new = FALSE; @@ -1308,12 +1310,12 @@ function apachesolr_environment_save($environment) { // @todo - get this from the schema?. $environment = array_intersect_key($environment, $default); if ($is_new) { - $query = "INSERT INTO {apachesolr_environment} (env_id, name, url, service_class) VALUES ('%s', '%s', '%s', '%s')"; - db_query($query, array($environment['env_id'], $environment['name'], $environment['url'], $environment['service_class'])); + $query = "INSERT INTO {apachesolr_environment} (env_id, name, url) VALUES ('%s', '%s', '%s')"; + db_query($query, array($environment['env_id'], $environment['name'], $environment['url'])); } else { - $query = "UPDATE {apachesolr_environment} SET name = '%s', url = '%s', service_class = '%s' WHERE env_id = '%s'"; - db_query($query, array($environment['name'], $environment['url'], $environment['service_class'], $environment['env_id'])); + $query = "UPDATE {apachesolr_environment} SET name = '%s', url = '%s' WHERE env_id = '%s'"; + db_query($query, array($environment['name'], $environment['url'], $environment['env_id'])); } $conf = isset($environment['conf']) ? $environment['conf'] : array(); // Update the environment variables (if any). @@ -1376,21 +1378,21 @@ function apachesolr_environment_variable_del($env_id, $name) { * * @return boolean TRUE if the server can be pinged, FALSE otherwise. */ -function apachesolr_server_status($url, $class = NULL) { +function apachesolr_server_status($url, $class_info = NULL) { static $status = array(); - // @Todo // Extra service classes should include their file on their own responsability // Use the default class if none is specified. - $class_info = variable_get('apachesolr_service_class', array( - 'file' => 'Drupal_Apache_Solr_Service', - 'module' => 'apachesolr', - 'class' => 'DrupalApacheSolrService')); - if (!class_exists($class) && isset($class_info['file']) && isset($class_info['module'])) { - $class = $class_info['class']; + if (!is_array($class_info) && !isset($class_info['class'])) { + $class_info = variable_get('apachesolr_service_class', array( + 'file' => 'Drupal_Apache_Solr_Service', + 'module' => 'apachesolr', + 'class' => 'DrupalApacheSolrService')); + } + if (!class_exists($class_info['class']) && isset($class_info['file']) && isset($class_info['module'])) { module_load_include('php', $class_info['module'], $class_info['file']); } - + $class = $class_info['class']; $key = $url . '|' . $class; // Static store insures we don't ping the server more than once per page load. if (!isset($status[$key])) {