diff --git a/core/modules/search/config/search.settings.yml b/core/modules/search/config/search.settings.yml index b09ce57..1d0124f 100644 --- a/core/modules/search/config/search.settings.yml +++ b/core/modules/search/config/search.settings.yml @@ -1,6 +1,6 @@ active_plugins: - - node_search - - user_search + node_search: node_search + user_search: user_search and_or_limit: '7' default_plugin: node_search index: diff --git a/core/modules/search/lib/Drupal/search/SearchPluginManager.php b/core/modules/search/lib/Drupal/search/SearchPluginManager.php index c8d5ef3..3821791 100644 --- a/core/modules/search/lib/Drupal/search/SearchPluginManager.php +++ b/core/modules/search/lib/Drupal/search/SearchPluginManager.php @@ -85,7 +85,8 @@ public function getActiveIndexingPlugins() { */ public function getActiveDefinitions() { $active_definitions = array(); - $active_plugins = array_flip($this->configFactory->get('search.settings')->get('active_plugins')); + $active_config = $this->configFactory->get('search.settings')->get('active_plugins'); + $active_plugins = $active_config ? array_flip($active_config) : array(); foreach ($this->getDefinitions() as $plugin_id => $definition) { if (isset($active_plugins[$plugin_id])) { $active_definitions[$plugin_id] = $definition; diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchUpgradePathTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchUpgradePathTest.php new file mode 100644 index 0000000..b8ed362 --- /dev/null +++ b/core/modules/search/lib/Drupal/search/Tests/SearchUpgradePathTest.php @@ -0,0 +1,49 @@ + 'Search module upgrade test', + 'description' => 'Upgrade tests for search module configuration and tables.', + 'group' => 'Search', + ); + } + + public function setUp() { + // Path to the database dump files. + $this->databaseDumpFiles = array( + drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.bare.standard_all.database.php.gz', + drupal_get_path('module', 'search') . '/tests/upgrade/drupal-7.search.database.php', + ); + parent::setUp(); + } + + /** + * Tests to see if search configuration and tables were upgraded. + */ + public function testSearchUpgrade() { + $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.'); + $this->assertFalse(db_table_exists('search_node_links'), 'search_node_links table was dropped.'); + $config = \Drupal::config('search.settings'); + // The starting databse has user module as the only active search. + $this->assertEqual($config->get('active_plugins'), array('user_search' => 'user_search')); + $exists = db_query('SELECT 1 FROM {variable} WHERE name = :name', array(':name' => 'search_active_modules'))->fetchField(); + $this->assertFalse($exists, 'The search_active_modules variable was deleted by the update'); + // The starting databse has user module as the default. + $this->assertEqual($config->get('default_plugin'), 'user_search'); + } + +} diff --git a/core/modules/search/search.install b/core/modules/search/search.install index 0cb52d3..824a624 100644 --- a/core/modules/search/search.install +++ b/core/modules/search/search.install @@ -129,6 +129,9 @@ function search_schema() { * @ingroup config_upgrade */ function search_update_8000() { + // Run this first so the config is sure to be empty. + _search_update_8000_modules_mapto_plugins(array('user' => 'user_search', 'node' => 'node_search')); + $active_plugins = \Drupal::config('search.settings')->get('active_plugins'); update_variables_to_config('search.settings', array( 'minimum_word_size' => 'index.minimum_word_size', 'overlap_cjk' => 'index.overlap_cjk', @@ -136,23 +139,29 @@ function search_update_8000() { 'search_tag_weights' => 'index.tag_weights', 'search_and_or_limit' => 'and_or_limit', )); - _search_update_8000_modules_mapto_plugins(array('user' => 'user_search', 'node' => 'node_search')); + // update_variables_to_config() merges in all the default values from the YAML + // file, so we need re-save the list of active plugins we found. + \Drupal::config('search.settings')->set('active_plugins', $active_plugins)->save(); } /** * Update search module variables to plugin IDs. + * + * This function may also be called by contributed modules that implement a + * search plugin that is an update of a hook_search_info() implementation. */ function _search_update_8000_modules_mapto_plugins(array $map) { $active_modules = update_variable_get('search_active_modules', array('node', 'user')); - $config = config('search.settings'); + $config = \Drupal::config('search.settings'); $active_plugins = $config->get('active_plugins'); foreach($active_modules as $idx => $module) { if (isset($map[$module])) { - $active_plugins[] = $map[$module]; + $plugin_id = $map[$module]; + $active_plugins[$plugin_id] = $plugin_id; unset($active_modules[$idx]); } } - $config->set('active_plugins', array_unique($active_plugins)); + $config->set('active_plugins', $active_plugins); if ($active_modules) { update_variable_set('search_active_modules', $active_modules); } @@ -164,7 +173,9 @@ function _search_update_8000_modules_mapto_plugins(array $map) { $config->set('default_plugin', $map[$default_module]); update_variable_del('search_default_module'); } + $config->save(); } + /** * Adds the langcode field and indexes to {search_dataset} and {search_index}. */ diff --git a/core/modules/search/tests/upgrade/drupal-7.search.database.php b/core/modules/search/tests/upgrade/drupal-7.search.database.php new file mode 100644 index 0000000..5dade9d --- /dev/null +++ b/core/modules/search/tests/upgrade/drupal-7.search.database.php @@ -0,0 +1,26 @@ +fields(array( + 'name', + 'value', + )) + ->values(array( + 'name' => 'search_active_modules', + 'value'=> 'a:1:{s:4:"user";s:4:"user";}', + )) + ->values(array( + 'name' => 'search_default_module', + 'value'=> 's:4:"user";', + )) + ->execute();