diff --git a/core/modules/node/config/node.search.yml b/core/modules/node/config/node.search.yml new file mode 100644 index 0000000..5aa4eb4 --- /dev/null +++ b/core/modules/node/config/node.search.yml @@ -0,0 +1,5 @@ +rank: + promote: '0' + recent: '0' + relevance: '0' + sticky: '0' diff --git a/core/modules/node/node.install b/core/modules/node/node.install index 12a6945..246d8ba 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -421,12 +421,6 @@ function node_uninstall() { config('language.settings')->clear('node. ' . $type . '.language.default_configuration')->save(); } - // Delete node search ranking variables. - variable_del('node_rank_relevance'); - variable_del('node_rank_sticky'); - variable_del('node_rank_promote'); - variable_del('node_rank_recent'); - // Delete remaining general module variables. state()->delete('node.node_access_needs_rebuild'); variable_del('node_admin_theme'); @@ -707,6 +701,21 @@ function node_update_8013() { } /** + * Moves node search rank variables to node.search settings. + */ +function node_update_8014() { + update_variables_to_config('node.search', array( + 'node_rank_relevance' => 'rank.relevance', + 'node_rank_sticky' => 'rank.sticky', + 'node_rank_promote' => 'rank.promote', + 'node_rank_recent' => 'rank.recent', + 'node_rank_comments' => 'rank.comments', + 'node_rank_views' => 'rank.views', + )); +} + + +/** * @} End of "addtogroup updates-7.x-to-8.x" * The next series of updates should start at 9000. */ diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 90f9bc5..556f501 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1260,8 +1260,10 @@ function node_permission() { function _node_rankings(SelectExtender $query) { if ($ranking = module_invoke_all('ranking')) { $tables = &$query->getTables(); + $ranks = config('node.search')->get('rank'); foreach ($ranking as $rank => $values) { - if ($node_rank = variable_get('node_rank_' . $rank, 0)) { + if (!empty($ranks[$rank])) { + $node_rank = $ranks[$rank]; // If the table defined in the ranking isn't already joined, then add it. if (isset($values['join']) && !isset($tables[$values['join']['alias']])) { $query->addJoin($values['join']['type'], $values['join']['table'], $values['join']['alias'], $values['join']['on']); @@ -1311,6 +1313,7 @@ function node_search_status() { /** * Implements hook_search_admin(). + * @see node_search_admin_submit() */ function node_search_admin() { // Output form for defining rank factor weights. @@ -1319,24 +1322,38 @@ function node_search_admin() { '#title' => t('Content ranking'), ); $form['content_ranking']['#theme'] = 'node_search_admin'; + $form['content_ranking']['#tree'] = TRUE; $form['content_ranking']['info'] = array( '#value' => '' . t('The following numbers control which properties the content search should favor when ordering the results. Higher numbers mean more influence, zero means the property is ignored. Changing these numbers does not require the search index to be rebuilt. Changes take effect immediately.') . '' ); // Note: reversed to reflect that higher number = higher ranking. $options = drupal_map_assoc(range(0, 10)); + $ranks = config('node.search')->get('rank'); foreach (module_invoke_all('ranking') as $var => $values) { - $form['content_ranking']['factors']['node_rank_' . $var] = array( + $form['content_ranking']['factors'][$var] = array( '#title' => $values['title'], '#type' => 'select', '#options' => $options, - '#default_value' => variable_get('node_rank_' . $var, 0), + '#default_value' => isset($ranks[$var]) ? $ranks[$var] : 0, ); } + + $form['#submit'][] = 'node_search_admin_submit'; + return $form; } /** + * Submit callback for search admin form callback. + */ +function node_search_admin_submit($form, &$form_state) { + config('node.search') + ->set('rank', $form_state['values']['content_ranking']['factors']) + ->save(); +} + +/** * Implements hook_search_execute(). */ function node_search_execute($keys = NULL, $conditions = NULL) { diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php index a57e483..faa8deb 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php @@ -92,9 +92,11 @@ function testRankings() { // Test each of the possible rankings. foreach ($node_ranks as $node_rank) { // Disable all relevancy rankings except the one we are testing. + $ranks = array(); foreach ($node_ranks as $var) { - variable_set('node_rank_' . $var, $var == $node_rank ? 10 : 0); + $ranks[$var] = $var == $node_rank ? 10 : 0; } + config('node.search')->set('rank', $ranks)->save(); // Do the search and assert the results. $set = node_search_execute('rocks'); @@ -149,10 +151,8 @@ function testHTMLRankings() { $this->refreshVariables(); // Disable all other rankings. - $node_ranks = array('sticky', 'promote', 'recent', 'comments', 'views'); - foreach ($node_ranks as $node_rank) { - variable_set('node_rank_' . $node_rank, 0); - } + $ranks = array('sticky' => 0, 'promote' => 0, 'recent' => 0, 'comments' => 0, 'views' => 0); + config('node.search')->set('rank', $ranks)->save(); $set = node_search_execute('rocks'); // Test the ranking of each tag. @@ -219,11 +219,8 @@ function testDoubleRankings() { // Set up for ranking sticky and lots of comments; make sure others are // disabled. - $node_ranks = array('sticky', 'promote', 'relevance', 'recent', 'comments', 'views'); - foreach ($node_ranks as $var) { - $value = ($var == 'sticky' || $var == 'comments') ? 10 : 0; - variable_set('node_rank_' . $var, $value); - } + $ranks = array('sticky' => 10, 'promote' => 0, 'relevance' => 0, 'recent' => 0, 'comments' => 10, 'views' => 0); + config('node.search')->set('rank', $ranks)->save(); // Do the search and assert the results. $set = node_search_execute('rocks'); diff --git a/core/modules/search/search.api.php b/core/modules/search/search.api.php index 1e431a5..48889a2 100644 --- a/core/modules/search/search.api.php +++ b/core/modules/search/search.api.php @@ -144,7 +144,7 @@ function hook_search_admin() { // Note: reversed to reflect that higher number = higher ranking. $options = drupal_map_assoc(range(0, 10)); - $ranks = config('node.settings')->get('search_rank'); + $ranks = config('node.search')->get('rank'); foreach (module_invoke_all('ranking') as $var => $values) { $form['content_ranking']['factors'][$var] = array( '#title' => $values['title'], diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php index ea6d6aa..8208815 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php @@ -99,6 +99,12 @@ public function testVariableUpgrade() { 'recursion_limit' => 42, ); + $expected_config['node.search'] = array( + 'rank.promote' => 10, + 'rank.views' => 5, + 'rank.comments' => -2, + ); + foreach ($expected_config as $file => $values) { $config = config($file); $this->verbose(print_r($config->get(), TRUE)); diff --git a/core/modules/system/tests/upgrade/drupal-7.system.database.php b/core/modules/system/tests/upgrade/drupal-7.system.database.php index 061540b..0b23612 100644 --- a/core/modules/system/tests/upgrade/drupal-7.system.database.php +++ b/core/modules/system/tests/upgrade/drupal-7.system.database.php @@ -114,7 +114,19 @@ ->values(array( 'name' => 'password_count_log2', 'value' => 'i:42;', -)) + )) +->values(array( + 'name' => 'node_rank_promote', + 'value' => 'i:10;', + )) +->values(array( + 'name' => 'node_rank_views', + 'value' => 'i:5;', + )) +->values(array( + 'name' => 'node_rank_comments', + 'value' => 'i:-2;', + )) ->values(array( 'name' => 'actions_max_stack', 'value' => 'i:42;',