diff --git a/apachesolr.admin.inc b/apachesolr.admin.inc index 86c9857..d653fe1 100644 --- a/apachesolr.admin.inc +++ b/apachesolr.admin.inc @@ -367,8 +367,7 @@ function apachesolr_settings(array $form, array &$form_state) { $confs['index'] = array( 'class' => 'operation', 'data' => l(t('Index'), - 'admin/config/search/apachesolr/settings/' . $data['env_id'] . '/index', - array('query' => array('destination' => current_path())) + 'admin/config/search/apachesolr/settings/' . $data['env_id'] . '/index' ), ); $ops['edit'] = array( @@ -608,12 +607,12 @@ function apachesolr_status_page($environment = array()) { ); $write_status = apachesolr_environment_variable_get($env_id, 'apachesolr_read_only', APACHESOLR_READ_WRITE); - if (($write_status == APACHESOLR_READ_WRITE) && $env_id == apachesolr_default_environment()) { + if ($write_status == APACHESOLR_READ_WRITE) { $output['index_action_form'] = drupal_get_form('apachesolr_index_action_form', $env_id); $output['index_config_form'] = drupal_get_form('apachesolr_index_config_form', $env_id); } else { - drupal_set_message(t('Options for deleting and re-indexing are not available. This could be because the index is read-only or you are not viewing the default environment. This can be changed on the settings page', array('!settings_page' => url('admin/config/search/apachesolr/settings/' . $env_id . '/edit', array('query' => drupal_get_destination())))), 'warning'); + drupal_set_message(t('Options for deleting and re-indexing are not available because the index is read-only. This can be changed on the settings page', array('!settings_page' => url('admin/config/search/apachesolr/settings/' . $env_id . '/edit', array('query' => drupal_get_destination())))), 'warning'); } return $output; @@ -959,11 +958,12 @@ function apachesolr_index_action_form_reset_submit(array $form, array &$form_sta function apachesolr_index_action_form_cron_submit(array $form, array &$form_state) { if (!empty($form_state['build_info']['args'][0])) { $env_id = $form_state['build_info']['args'][0]; + $form_state['redirect'] = 'admin/config/search/apachesolr/settings/' . $env_id . '/index'; } else { $env_id = apachesolr_default_environment(); + $form_state['redirect'] = 'admin/config/search/apachesolr'; } - $form_state['redirect'] = 'admin/config/search/apachesolr'; apachesolr_cron($env_id); drupal_set_message(t('Apachesolr cron succesfully executed')); } @@ -997,11 +997,12 @@ function apachesolr_index_action_form_remaining_confirm(array $form, array &$for function apachesolr_index_action_form_remaining_confirm_submit(array $form, array &$form_state) { if (!empty($form_state['build_info']['args'][0]['env_id'])) { $env_id = $form_state['build_info']['args'][0]['env_id']; + $form_state['redirect'] = 'admin/config/search/apachesolr/settings/' . $env_id . '/index'; } else { $env_id = apachesolr_default_environment(); + $form_state['redirect'] = 'admin/config/search/apachesolr'; } - $form_state['redirect'] = 'admin/config/search/apachesolr'; apachesolr_index_batch_index_remaining($env_id); } @@ -1034,14 +1035,15 @@ function apachesolr_index_action_form_reset_confirm(array $form, array &$form_st function apachesolr_index_action_form_reset_confirm_submit(array $form, array &$form_state) { if (!empty($form_state['build_info']['args'][0]['env_id'])) { $env_id = $form_state['build_info']['args'][0]['env_id']; + $form_state['redirect'] = 'admin/config/search/apachesolr/settings/' . $env_id . '/index'; } else { $env_id = apachesolr_default_environment(); + $form_state['redirect'] = 'admin/config/search/apachesolr'; } module_load_include('inc', 'apachesolr', 'apachesolr.index'); apachesolr_index_mark_for_reindex($env_id); drupal_set_message(t('All the content on your site is queued for indexing. You can wait for it to be indexed during cron runs, or you can manually reindex it.')); - $form_state['redirect'] = 'admin/config/search/apachesolr'; } /** @@ -1073,16 +1075,16 @@ function apachesolr_index_action_form_delete_confirm(array $form, array &$form_s function apachesolr_index_action_form_delete_confirm_submit(array $form, array &$form_state) { if (!empty($form_state['build_info']['args'][0]['env_id'])) { $env_id = $form_state['build_info']['args'][0]['env_id']; + $form_state['redirect'] = 'admin/config/search/apachesolr/settings/' . $env_id . '/index'; } else { $env_id = apachesolr_default_environment(); + $form_state['redirect'] = 'admin/config/search/apachesolr'; } // Rebuild our tracking table. module_load_include('inc', 'apachesolr', 'apachesolr.index'); apachesolr_index_delete_index($env_id); drupal_set_message(t('The index has been deleted.')); - - $form_state['redirect'] = 'admin/config/search/apachesolr'; } /** diff --git a/apachesolr.index.inc b/apachesolr.index.inc index db31908..252c1de 100644 --- a/apachesolr.index.inc +++ b/apachesolr.index.inc @@ -146,9 +146,7 @@ function apachesolr_index_status($env_id) { $last_entity_id = $last_index_position['last_entity_id']; $last_changed = $last_index_position['last_changed']; - // Find the next batch of entities to index for this entity type. Note that - // for ordering we're grabbing the oldest first and then ordering by ID so - // that we get a definitive order. + // Find the remaining entities to index for this entity type. $query = db_select($table, 'aie') ->condition('aie.bundle', $bundles) ->condition('aie.status', 1) @@ -882,6 +880,13 @@ function apachesolr_index_node_solr_reindex($env_id, $bundle = NULL) { $indexer_table = apachesolr_get_indexer_table('node'); $transaction = db_transaction(); try { + $indexable_bundles = apachesolr_get_index_bundles($env_id, 'node'); + + if ($bundle && !empty($indexable_bundles) && !in_array($bundle, $indexable_bundles)) { + // The bundle specified is not in the indexable bundles list. + return NULL; + } + // Leave status 0 rows - those need to be // removed from the index later. $delete = db_delete($indexer_table); @@ -890,16 +895,12 @@ function apachesolr_index_node_solr_reindex($env_id, $bundle = NULL) { if (!empty($bundle)) { $delete->condition('bundle', $bundle); } + elseif (!empty($indexable_bundles)) { + $delete->condition('bundle', $indexable_bundles, 'IN'); + } $delete->execute(); - $indexable_bundles = apachesolr_get_index_bundles($env_id, 'node'); - - if ($bundle && !empty($indexable_bundles) && !in_array($bundle, $indexable_bundles)) { - // The bundle specified is not in the indexable bundles list. - return NULL; - } - $select = db_select('node', 'n'); $select->condition('status', 1); $select->addExpression("'node'", 'entity_type'); @@ -1250,7 +1251,7 @@ function apachesolr_userreference_indexing_callback($entity, $field_name, $index /** * Indexing callback for entityreference fields. - * + * * @param object $entity * @param string $field_name * @param string $index_key diff --git a/apachesolr.module b/apachesolr.module index cee6cbb..a4d3cec 100644 --- a/apachesolr.module +++ b/apachesolr.module @@ -898,67 +898,76 @@ function apachesolr_get_last_index_updated($env_id) { } /** - * We run the indexing process only for the default environment * Implements hook_cron(). + * Runs the indexing process on all writable environments or just a given environment. */ function apachesolr_cron($env_id = NULL) { + $environments = array(); if (empty($env_id)) { - $env_id = apachesolr_default_environment(); + $environments = array_keys(apachesolr_load_all_environments()); } - // Indexes in read-only mode do not change the index, so will not update, delete, or optimize during cron. - if (apachesolr_environment_variable_get($env_id, 'apachesolr_read_only', APACHESOLR_READ_WRITE) == APACHESOLR_READ_ONLY) { - return NULL; + else { + $environments[] = $env_id; } + module_load_include('inc', 'apachesolr', 'apachesolr.index'); - // For every entity type that requires extra validation - foreach (entity_get_info() as $type => $info) { - $bundles = apachesolr_get_index_bundles($env_id, $type); + // Optimize the index (by default once a day). + $optimize_interval = variable_get('apachesolr_optimize_interval', 60 * 60 * 24); + $last = variable_get('apachesolr_last_optimize', 0); + $time = REQUEST_TIME; - // If we're not checking any bundles of this entity type, just skip them all. - if (empty($bundles)) { + foreach($environments as $env_id) { + // Indexes in read-only mode do not change the index, so will not update, delete, or optimize during cron. + if (apachesolr_environment_variable_get($env_id, 'apachesolr_read_only', APACHESOLR_READ_WRITE) == APACHESOLR_READ_ONLY) { continue; } - if (isset($info['apachesolr']['cron_check'])) { - $callback = $info['apachesolr']['cron_check']; - call_user_func($callback); - } - } + // For every entity type that requires extra validation + foreach (entity_get_info() as $type => $info) { + $bundles = apachesolr_get_index_bundles($env_id, $type); - try { - $solr = apachesolr_get_solr($env_id); - // Optimize the index (by default once a day). - $optimize_interval = variable_get('apachesolr_optimize_interval', 60 * 60 * 24); - $last = variable_get('apachesolr_last_optimize', 0); - $time = REQUEST_TIME; - if ($optimize_interval && ($time - $last > $optimize_interval)) { - $solr->optimize(false, FALSE); - variable_set('apachesolr_last_optimize', $time); - apachesolr_set_last_index_updated($env_id, $time); + // If we're not checking any bundles of this entity type, just skip them all. + if (empty($bundles)) { + continue; + } + + if (isset($info['apachesolr']['cron_check'])) { + $callback = $info['apachesolr']['cron_check']; + call_user_func($callback); + } } - // Only clear the cache if the index changed. - // TODO: clear on some schedule if running multi-site. - $updated = apachesolr_get_last_index_updated($env_id); - if ($updated > 0) { - $solr->clearCache(); - // Re-populate the luke cache. - $solr->getLuke(); - // TODO: an admin interface for setting this. Assume for now 5 minutes. - if ($time - $updated >= variable_get('apachesolr_cache_delay', 300)) { - // Clear the updated flag. - apachesolr_set_last_index_updated($env_id); + + try { + $solr = apachesolr_get_solr($env_id); + if ($optimize_interval && ($time - $last > $optimize_interval)) { + $solr->optimize(FALSE, FALSE); + variable_set('apachesolr_last_optimize', $time); + apachesolr_set_last_index_updated($env_id, $time); + } + // Only clear the cache if the index changed. + // TODO: clear on some schedule if running multi-site. + $updated = apachesolr_get_last_index_updated($env_id); + if ($updated > 0) { + $solr->clearCache(); + // Re-populate the luke cache. + $solr->getLuke(); + // TODO: an admin interface for setting this. Assume for now 5 minutes. + if ($time - $updated >= variable_get('apachesolr_cache_delay', 300)) { + // Clear the updated flag. + apachesolr_set_last_index_updated($env_id); + } } } - } - catch (Exception $e) { - watchdog('Apache Solr', nl2br(check_plain($e->getMessage())) . ' in apachesolr_cron', NULL, WATCHDOG_ERROR); - } + catch (Exception $e) { + watchdog('Apache Solr', nl2br(check_plain($e->getMessage())) . ' in apachesolr_cron', NULL, WATCHDOG_ERROR); + } - // We can safely process the apachesolr_cron_limit nodes at a time without a - // timeout or out of memory error. - $limit = variable_get('apachesolr_cron_limit', 50); - apachesolr_index_entities($env_id, $limit); + // We can safely process the apachesolr_cron_limit nodes at a time without a + // timeout or out of memory error. + $limit = variable_get('apachesolr_cron_limit', 50); + apachesolr_index_entities($env_id, $limit); + } } /**