diff --git a/core/includes/config.inc b/core/includes/config.inc index 8c2772b..a137988 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -18,6 +18,9 @@ function config_get_config_directory() { if ($test_prefix = drupal_valid_test_ua()) { $path = conf_path() . '/files/simpletest/config_' . $test_prefix; + if (!file_exists($path)) { + mkdir($path); + } } else { $path = conf_path() . '/files/' . $config_directory_name; diff --git a/core/modules/node/node.module b/core/modules/node/node.module index be60e48..7fbfa0c 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -2765,7 +2765,7 @@ function node_page_view($node) { * Implements hook_update_index(). */ function node_update_index() { - $limit = (int)variable_get('search_cron_limit', 100); + $limit = (int) config('search.settings')->get('cron_limit'); $result = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex <> 0 ORDER BY d.reindex ASC, n.nid ASC", 0, $limit, array(), array('target' => 'slave')); diff --git a/core/modules/search/config/search.settings.xml b/core/modules/search/config/search.settings.xml new file mode 100644 index 0000000..6a38405 --- /dev/null +++ b/core/modules/search/config/search.settings.xml @@ -0,0 +1,28 @@ + + + 3 + 1 + + + node + user + + 7 + 100 + node + 0 + +

25

+

18

+

15

+

12

+
9
+
6
+ 3 + 3 + 3 + 3 + 3 + 10 +
+
diff --git a/core/modules/search/search.admin.inc b/core/modules/search/search.admin.inc index fda14ee..b6b23f0 100644 --- a/core/modules/search/search.admin.inc +++ b/core/modules/search/search.admin.inc @@ -50,13 +50,18 @@ function _search_get_module_names() { * @see search_admin_reindex_submit() */ function search_admin_settings($form) { + $config = config('search.settings'); + // Collect some stats $remaining = 0; $total = 0; - foreach (variable_get('search_active_modules', array('node', 'user')) as $module) { - if ($status = module_invoke($module, 'search_status')) { - $remaining += $status['remaining']; - $total += $status['total']; + $active_modules = $config->get('active_modules'); + if (!empty($active_modules)) { + foreach ($active_modules as $module) { + if ($status = module_invoke($module, 'search_status')) { + $remaining += $status['remaining']; + $total += $status['total']; + } } } @@ -77,7 +82,7 @@ function search_admin_settings($form) { $form['indexing_throttle']['search_cron_limit'] = array( '#type' => 'select', '#title' => t('Number of items to index per cron run'), - '#default_value' => variable_get('search_cron_limit', 100), + '#default_value' => $config->get('cron_limit'), '#options' => $items, '#description' => t('The maximum number of items indexed in each pass of a cron maintenance task. If necessary, reduce the number of items to prevent timeouts and memory errors while indexing.', array('@cron' => url('admin/reports/status'))) ); @@ -92,7 +97,7 @@ function search_admin_settings($form) { $form['indexing_settings']['minimum_word_size'] = array( '#type' => 'textfield', '#title' => t('Minimum word length to index'), - '#default_value' => variable_get('minimum_word_size', 3), + '#default_value' => $config->get('minimum_word_size'), '#size' => 5, '#maxlength' => 3, '#description' => t('The number of characters a word has to be to be indexed. A lower setting means better search result ranking, but also a larger database. Each search query must contain at least one keyword that is this size (or longer).') @@ -100,7 +105,7 @@ function search_admin_settings($form) { $form['indexing_settings']['overlap_cjk'] = array( '#type' => 'checkbox', '#title' => t('Simple CJK handling'), - '#default_value' => variable_get('overlap_cjk', TRUE), + '#default_value' => $config->get('overlap_cjk'), '#description' => t('Whether to apply a simple Chinese/Japanese/Korean tokenizer based on overlapping sequences. Turn this off if you want to use an external preprocessor for this instead. Does not affect other languages.') ); @@ -113,14 +118,14 @@ function search_admin_settings($form) { '#type' => 'checkboxes', '#title' => t('Active modules'), '#title_display' => 'invisible', - '#default_value' => variable_get('search_active_modules', array('node', 'user')), + '#default_value' => $active_modules, '#options' => $module_options, '#description' => t('Choose which search modules are active from the available modules.') ); $form['active']['search_default_module'] = array( '#title' => t('Default search module'), '#type' => 'radios', - '#default_value' => variable_get('search_default_module', 'node'), + '#default_value' => $config->get('default_module'), '#options' => $module_options, '#description' => t('Choose which search module is the default.') ); @@ -128,10 +133,12 @@ function search_admin_settings($form) { $form['#submit'][] = 'search_admin_settings_submit'; // Per module settings - foreach (variable_get('search_active_modules', array('node', 'user')) as $module) { - $added_form = module_invoke($module, 'search_admin'); - if (is_array($added_form)) { - $form = array_merge($form, $added_form); + if (!empty($active_modules)) { + foreach ($active_modules as $module) { + $added_form = module_invoke($module, 'search_admin'); + if (is_array($added_form)) { + $form = array_merge($form, $added_form); + } } } @@ -156,13 +163,21 @@ function search_admin_settings_validate($form, &$form_state) { * Form submission handler for search_admin_settings(). */ function search_admin_settings_submit($form, &$form_state) { + $config = config('search.settings'); // If these settings change, the index needs to be rebuilt. - if ((variable_get('minimum_word_size', 3) != $form_state['values']['minimum_word_size']) || - (variable_get('overlap_cjk', TRUE) != $form_state['values']['overlap_cjk'])) { + if (($config->get('minimum_word_size') != $form_state['values']['minimum_word_size']) || ($config->get('overlap_cjk') != $form_state['values']['overlap_cjk'])) { + $config->set('minimum_word_size', $form_state['values']['minimum_word_size']); + $config->set('overlap_cjk', $form_state['values']['overlap_cjk']); drupal_set_message(t('The index will be rebuilt.')); search_reindex(); } - $current_modules = variable_get('search_active_modules', array('node', 'user')); + if ($config->get('cron_limit') != $form_state['values']['search_cron_limit']) { + $config->set('cron_limit', $form_state['values']['search_cron_limit']); + } + if ($config->get('default_module') != $form_state['values']['search_default_module']) { + $config->set('default_module', $form_state['values']['search_default_module']); + } + $current_modules = $config->get('active_modules'); // Check whether we are resetting the values. if ($form_state['triggering_element']['#value'] == t('Reset to defaults')) { $new_modules = array('node', 'user'); @@ -170,10 +185,16 @@ function search_admin_settings_submit($form, &$form_state) { else { $new_modules = array_filter($form_state['values']['search_active_modules']); } - if (array_diff($current_modules, $new_modules)) { + if ($current_modules != $new_modules) { + $enabled_modules = array(); + foreach ($new_modules as $module) { + $enabled_modules[$module] = $module; + } + $config->set('active_modules', $enabled_modules); drupal_set_message(t('The active search modules have been changed.')); variable_set('menu_rebuild_needed', TRUE); } + $config->save(); } /** diff --git a/core/modules/search/search.api.php b/core/modules/search/search.api.php index 534c1e8..cac8509 100644 --- a/core/modules/search/search.api.php +++ b/core/modules/search/search.api.php @@ -69,7 +69,7 @@ function sample_search_conditions_callback($keys) { if (!empty($_REQUEST['sample_search_keys'])) { $conditions['sample_search_keys'] = $_REQUEST['sample_search_keys']; } - if ($force_keys = variable_get('sample_search_force_keywords', '')) { + if ($force_keys = config('search.settings')->get('sample_force_keywords')) { $conditions['sample_search_force_keywords'] = $force_keys; } return $conditions; @@ -326,15 +326,16 @@ function hook_search_preprocess($text) { * When implementing this hook, your module should index content items that * were modified or added since the last run. PHP has a time limit * for cron, though, so it is advisable to limit how many items you index - * per run using variable_get('search_cron_limit') (see example below). Also, - * since the cron run could time out and abort in the middle of your run, you - * should update your module's internal bookkeeping on when items have last - * been indexed as you go rather than waiting to the end of indexing. + * per run using config('search.settings')->get('cron_limit') (see + * example below). Also, * since the cron run could time out and abort in the + * middle of your run, you * should update your module's internal bookkeeping on + * when items have last * been indexed as you go rather than waiting to the end + * of indexing. * * @ingroup search */ function hook_update_index() { - $limit = (int)variable_get('search_cron_limit', 100); + $limit = (int) config('search.settings')->get('cron_limit'); $result = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex <> 0 ORDER BY d.reindex ASC, n.nid ASC", 0, $limit); diff --git a/core/modules/search/search.extender.inc b/core/modules/search/search.extender.inc index 73f7836..61d815b 100644 --- a/core/modules/search/search.extender.inc +++ b/core/modules/search/search.extender.inc @@ -196,7 +196,7 @@ class SearchQuery extends SelectExtender { // Classify tokens. $or = FALSE; $warning = ''; - $limit_combinations = variable_get('search_and_or_limit', 7); + $limit_combinations = config('search.settings')->get('and_or_limit'); // The first search expression does not count as AND. $and_count = -1; $or_count = 0; @@ -319,7 +319,7 @@ class SearchQuery extends SelectExtender { $split = explode(' ', $word); foreach ($split as $s) { $num = is_numeric($s); - if ($num || drupal_strlen($s) >= variable_get('minimum_word_size', 3)) { + if ($num || drupal_strlen($s) >= config('search.settings')->get('minimum_word_size')) { if (!isset($this->words[$s])) { $this->words[$s] = $s; $num_new_scores++; @@ -345,11 +345,11 @@ class SearchQuery extends SelectExtender { $this->parseSearchExpression(); if (count($this->words) == 0) { - form_set_error('keys', format_plural(variable_get('minimum_word_size', 3), 'You must include at least one positive keyword with 1 character or more.', 'You must include at least one positive keyword with @count characters or more.')); + form_set_error('keys', format_plural(config('search.settings')->get('minimum_word_size'), 'You must include at least one positive keyword with 1 character or more.', 'You must include at least one positive keyword with @count characters or more.')); return FALSE; } if ($this->expressionsIgnored) { - drupal_set_message(t('Your search used too many AND/OR expressions. Only the first @count terms were included in this search.', array('@count' => variable_get('search_and_or_limit', 7))), 'warning'); + drupal_set_message(t('Your search used too many AND/OR expressions. Only the first @count terms were included in this search.', array('@count' => config('search.settings')->get('and_or_limit', 7))), 'warning'); } $this->executedFirstPass = TRUE; diff --git a/core/modules/search/search.install b/core/modules/search/search.install index c450f05..d5e2348 100644 --- a/core/modules/search/search.install +++ b/core/modules/search/search.install @@ -6,15 +6,6 @@ */ /** - * Implements hook_uninstall(). - */ -function search_uninstall() { - variable_del('minimum_word_size'); - variable_del('overlap_cjk'); - variable_del('search_cron_limit'); -} - -/** * Implements hook_schema(). */ function search_schema() { @@ -153,3 +144,22 @@ function search_schema() { return $schema; } + +/** + * Update search module to use the configuration system. + */ +function search_update_8000() { + config_install_default_config('search'); + + $config_mapping = array( + 'sample_force_keywords' => 'sample_search_force_keywords', + 'active_modules' => 'search_active_modules', + 'and_or_limit' => 'search_and_or_limit', + 'cron_limit' => 'search_cron_limit', + 'default_module' => 'search_default_module', + 'embedded_form_submitted' => 'search_embedded_form_submitted', + 'tag_weights' => 'search_tag_weights', + ); + + update_variables_to_config('search.settings', $config_mapping); +} diff --git a/core/modules/search/search.module b/core/modules/search/search.module index 587ef43..adeda37 100644 --- a/core/modules/search/search.module +++ b/core/modules/search/search.module @@ -275,7 +275,7 @@ function search_get_info($all = FALSE) { return $search_hooks; } - $active = variable_get('search_active_modules', array('node', 'user')); + $active = config('search.settings')->get('active_modules'); return array_intersect_key($search_hooks, array_flip($active)); } @@ -287,7 +287,7 @@ function search_get_info($all = FALSE) { */ function search_get_default_module_info() { $info = search_get_info(); - $default = variable_get('search_default_module', 'node'); + $default = config('search.settings')->get('default_module'); if (isset($info[$default])) { return $info[$default]; } @@ -365,7 +365,7 @@ function search_cron() { // to date. drupal_register_shutdown_function('search_update_totals'); - foreach (variable_get('search_active_modules', array('node', 'user')) as $module) { + foreach (config('search.settings')->get('active_modules') as $module) { // Update word index module_invoke($module, 'update_index'); } @@ -426,7 +426,7 @@ function search_simplify($text) { search_invoke_preprocess($text); // Simple CJK handling - if (variable_get('overlap_cjk', TRUE)) { + if (config('search.settings')->get('overlap_cjk')) { $text = preg_replace_callback('/[' . PREG_CLASS_CJK . ']+/u', 'search_expand_cjk', $text); } @@ -480,7 +480,7 @@ function search_simplify($text) { * Tokenized text, starting and ending with a space character. */ function search_expand_cjk($matches) { - $min = variable_get('minimum_word_size', 3); + $min = config('search.settings')->get('minimum_word_size'); $str = $matches[0]; $length = drupal_strlen($str); // If the text is shorter than the minimum word size, don't tokenize it. @@ -559,7 +559,7 @@ function search_invoke_preprocess(&$text) { * @ingroup search */ function search_index($sid, $module, $text) { - $minimum_word_size = variable_get('minimum_word_size', 3); + $minimum_word_size = config('search.settings')->get('minimum_word_size'); // Link matching global $base_url; @@ -568,19 +568,7 @@ function search_index($sid, $module, $text) { // Multipliers for scores of words inside certain HTML tags. The weights are stored // in a variable so that modules can overwrite the default weights. // Note: 'a' must be included for link ranking to work. - $tags = variable_get('search_tag_weights', array( - 'h1' => 25, - 'h2' => 18, - 'h3' => 15, - 'h4' => 12, - 'h5' => 9, - 'h6' => 6, - 'u' => 3, - 'b' => 3, - 'i' => 3, - 'strong' => 3, - 'em' => 3, - 'a' => 10)); + $tags = config('search.settings')->get('tag_weights'); // Strip off all ignored tags to speed up processing, but insert space before/after // them to keep word boundaries. diff --git a/core/modules/search/search.test b/core/modules/search/search.test index 8b67b0b..88e5e99 100644 --- a/core/modules/search/search.test +++ b/core/modules/search/search.test @@ -51,7 +51,9 @@ class SearchMatchTestCase extends SearchWebTestCase { * Set up a small index of items to test against. */ function _setup() { - variable_set('minimum_word_size', 3); + $search_config = config('search.settings'); + $search_config->set('minimum_word_size', 3); + $search_config->save(); for ($i = 1; $i <= 7; ++$i) { search_index($i, SEARCH_TYPE, $this->getText($i)); @@ -305,7 +307,7 @@ class SearchPageText extends SearchWebTestCase { // Test a search input exceeding the limit of AND/OR combinations to test // the Denial-of-Service protection. - $limit = variable_get('search_and_or_limit', 7); + $limit = config('search.settings')->get('and_or_limit'); $keys = array(); for ($i = 0; $i < $limit + 1; $i++) { $keys[] = $this->randomName(3); @@ -1218,7 +1220,9 @@ class SearchKeywordsConditions extends SearchWebTestCase { // Login with sufficient privileges. $this->drupalLogin($this->searching_user); // Test with all search modules enabled. - variable_set('search_active_modules', array('node' => 'node', 'user' => 'user', 'search_extra_type' => 'search_extra_type')); + $search_config = config('search.settings'); + $search_config->set('active_modules', array('node' => 'node', 'user' => 'user', 'search_extra_type' => 'search_extra_type')); + $search_config->save(); menu_rebuild(); } @@ -1696,8 +1700,10 @@ class SearchTokenizerTestCase extends SearchWebTestCase { function testTokenizer() { // Set the minimum word size to 1 (to split all CJK characters) and make // sure CJK tokenizing is turned on. - variable_set('minimum_word_size', 1); - variable_set('overlap_cjk', TRUE); + $search_config = config('search.settings'); + $search_config->set('minimum_word_size', 1); + $search_config->set('overlap_cjk', TRUE); + $search_config->save(); $this->refreshVariables(); // Create a string of CJK characters from various character ranges in @@ -1782,8 +1788,10 @@ class SearchTokenizerTestCase extends SearchWebTestCase { function testNoTokenizer() { // Set the minimum word size to 1 (to split all CJK characters) and make // sure CJK tokenizing is turned on. - variable_set('minimum_word_size', 1); - variable_set('overlap_cjk', TRUE); + $search_config = config('search.settings'); + $search_config->set('minimum_word_size', 1); + $search_config->set('overlap_cjk', TRUE); + $search_config->save(); $this->refreshVariables(); $letters = 'abcdefghijklmnopqrstuvwxyz'; @@ -1856,7 +1864,9 @@ class SearchEmbedForm extends SearchWebTestCase { // Set up a dummy initial count of times the form has been submitted. $this->submit_count = 12; - variable_set('search_embedded_form_submitted', $this->submit_count); + $search_config = config('search.settings'); + $search_config->set('embedded_form_submitted', $this->submit_count); + $search_config->save(); $this->refreshVariables(); } @@ -1869,7 +1879,7 @@ class SearchEmbedForm extends SearchWebTestCase { array('name' => 'John'), t('Send away')); $this->assertText(t('Test form was submitted'), 'Form message appears'); - $count = variable_get('search_embedded_form_submitted', 0); + $count = config('search.settings')->get('embedded_form_submitted'); $this->assertEqual($this->submit_count + 1, $count, 'Form submission count is correct'); $this->submit_count = $count; @@ -1880,7 +1890,7 @@ class SearchEmbedForm extends SearchWebTestCase { array('name' => 'John'), t('Send away')); $this->assertText(t('Test form was submitted'), 'Form message appears'); - $count = variable_get('search_embedded_form_submitted', 0); + $count = config('search.settings')->get('embedded_form_submitted'); $this->assertEqual($this->submit_count + 1, $count, 'Form submission count is correct'); $this->submit_count = $count; @@ -1890,7 +1900,7 @@ class SearchEmbedForm extends SearchWebTestCase { array('keys' => 'foo'), t('Search')); $this->assertNoText(t('Test form was submitted'), 'Form message does not appear'); - $count = variable_get('search_embedded_form_submitted', 0); + $count = config('search.settings')->get('embedded_form_submitted'); $this->assertEqual($this->submit_count, $count, 'Form submission count is correct'); $this->submit_count = $count; } @@ -1911,6 +1921,7 @@ class SearchPageOverride extends SearchWebTestCase { } function setUp() { + $search_config = config('search.settings'); parent::setUp(array('search_extra_type')); // Login as a user that can create and search content. @@ -1918,7 +1929,8 @@ class SearchPageOverride extends SearchWebTestCase { $this->drupalLogin($this->search_user); // Enable the extra type module for searching. - variable_set('search_active_modules', array('node' => 'node', 'user' => 'user', 'search_extra_type' => 'search_extra_type')); + $search_config->set('active_modules', array('node' => 'node', 'user' => 'user', 'search_extra_type' => 'search_extra_type')); + $search_config->save(); menu_rebuild(); } diff --git a/core/modules/search/tests/search_embedded_form.module b/core/modules/search/tests/search_embedded_form.module index 4845796..9a16bf9 100644 --- a/core/modules/search/tests/search_embedded_form.module +++ b/core/modules/search/tests/search_embedded_form.module @@ -30,7 +30,7 @@ function search_embedded_form_menu() { * @see search_embedded_form_form_submit(). */ function search_embedded_form_form($form, &$form_state) { - $count = variable_get('search_embedded_form_submitted', 0); + $count = config('search.settings')->get('embedded_form_submitted'); $form['name'] = array( '#type' => 'textfield', @@ -56,8 +56,10 @@ function search_embedded_form_form($form, &$form_state) { * Submit handler for search_embedded_form_form(). */ function search_embedded_form_form_submit($form, &$form_state) { - $count = variable_get('search_embedded_form_submitted', 0) + 1; - variable_set('search_embedded_form_submitted', $count); + $search_config = config('search.settings'); + $count = $search_config->get('embedded_form_submitted') + 1; + $search_config->set('embedded_form_submitted', $count); + $search_config->save(); drupal_set_message(t('Test form was submitted')); }