diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index 48bb5a4..28faff5 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -394,6 +394,15 @@ function comment_update_8004() { } /** + * Moves variable node_rank_comments to config node.settings.search_rank.comments. + */ +function comment_update_8005() { + update_variables_to_config('node.settings', array( + 'node_rank_comments' => 'search_rank.comments', + )); +} + +/** * @} End of "addtogroup updates-7.x-to-8.x". * The next series of updates should start at 9000. */ diff --git a/core/modules/node/config/node.settings.yml b/core/modules/node/config/node.settings.yml index 9562864..77fea07 100644 --- a/core/modules/node/config/node.settings.yml +++ b/core/modules/node/config/node.settings.yml @@ -1 +1,6 @@ items_per_page: '10' +search_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..4f527f0 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,30 @@ function node_update_8013() { } /** + * Moves variables node_rank_relevance, node_rank_sticky, node_rank_promote and + * node_rank_recent to config node.settings.search_rank. + */ +function node_update_8014() { + $oldprefix = 'node_rank_'; + $newprefix = 'search_rank.'; + $oldpfxlen = strlen($oldprefix); + + $rank_variables = db_select('variable', 'v') + ->fields('v', array('name')) + ->condition('v.name', db_like($oldprefix) . '%', 'LIKE') + ->execute() + ->fetchCol(); + + $config = array(); + foreach ($rank_variables as $rank_variable) { + $config[$rank_variable] = substr_replace($rank_variable, $newprefix, 0, $oldpfxlen); + } + + update_variables_to_config('node.settings', $config); +} + + +/** * @} 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..4754d8d 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.settings')->get('search_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.settings')->get('search_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.settings') + ->set('search_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..9eabd95 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.settings')->set('search_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.settings')->set('search_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.settings')->set('search_rank', $ranks)->save(); // Do the search and assert the results. $set = node_search_execute('rocks'); diff --git a/core/modules/statistics/statistics.install b/core/modules/statistics/statistics.install index 5f2b7dd..9d5d526 100644 --- a/core/modules/statistics/statistics.install +++ b/core/modules/statistics/statistics.install @@ -173,3 +173,12 @@ function statistics_update_8002() { 'statistics_day_timestamp' => 'statistics.day_timestamp', )); } + +/** + * Moves variable node_rank_views to config node.settings.search_rank.views. + */ +function statistics_update_8003 { + update_variables_to_config('node.settings', array( + 'node_rank_views' => 'search_rank.views', + )); +} 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..094ad3f 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,11 @@ public function testVariableUpgrade() { 'recursion_limit' => 42, ); + $expected_config['node.settings'] = array( + 'search_rank.promote' => 10, + 'search_rank.custom_from_contrib' => 5, + ); + 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..1216536 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,15 @@ ->values(array( 'name' => 'password_count_log2', 'value' => 'i:42;', -)) + )) +->values(array( + 'name' => 'node_rank_promote', + 'value' => 'i:10;', + )) +->values(array( + 'name' => 'node_rank_custom_from_contrib', + 'value' => 'i:5;', + )) ->values(array( 'name' => 'actions_max_stack', 'value' => 'i:42;',