diff --git a/core/modules/search/migration_templates/d6_search_page.yml b/core/modules/search/migration_templates/search_page.yml similarity index 86% rename from core/modules/search/migration_templates/d6_search_page.yml rename to core/modules/search/migration_templates/search_page.yml index f509d8c18b8..8ddc02acfbc 100644 --- a/core/modules/search/migration_templates/d6_search_page.yml +++ b/core/modules/search/migration_templates/search_page.yml @@ -1,7 +1,8 @@ -id: d6_search_page +id: search_page label: Search page configuration migration_tags: - Drupal 6 + - Drupal 7 source: plugin: variable variables: @@ -20,6 +21,6 @@ process: path: 'constants/path' plugin: 'constants/plugin' 'configuration/rankings': - plugin: d6_search_configuration_rankings + plugin: search_configuration_rankings destination: plugin: entity:search_page diff --git a/core/modules/search/src/Plugin/migrate/process/SearchConfigurationRankings.php b/core/modules/search/src/Plugin/migrate/process/SearchConfigurationRankings.php new file mode 100644 index 00000000000..d18e6039eaa --- /dev/null +++ b/core/modules/search/src/Plugin/migrate/process/SearchConfigurationRankings.php @@ -0,0 +1,38 @@ +getSource() as $name => $rank) { + if (substr($name, 0, 10) == 'node_rank_' && is_numeric($rank)) { + $return[substr($name, 10)] = $rank; + } + } + return $return; + } + +} diff --git a/core/modules/search/src/Tests/Migrate/d6/MigrateSearchPageTest.php b/core/modules/search/src/Tests/Migrate/d6/MigrateSearchPageTest.php index 3f4710094e4..8f04775d7a3 100644 --- a/core/modules/search/src/Tests/Migrate/d6/MigrateSearchPageTest.php +++ b/core/modules/search/src/Tests/Migrate/d6/MigrateSearchPageTest.php @@ -28,7 +28,7 @@ class MigrateSearchPageTest extends MigrateDrupal6TestBase { */ protected function setUp() { parent::setUp(); - $this->executeMigration('d6_search_page'); + $this->executeMigration('search_page'); } /** @@ -42,6 +42,8 @@ class MigrateSearchPageTest extends MigrateDrupal6TestBase { $configuration = $search_page->getPlugin()->getConfiguration(); $this->assertIdentical($configuration['rankings'], array( 'comments' => 5, + 'promote' => 0, + 'recent' => 0, 'relevance' => 2, 'sticky' => 8, 'views' => 1, @@ -58,7 +60,7 @@ class MigrateSearchPageTest extends MigrateDrupal6TestBase { /** @var \Drupal\migrate\Entity\MigrationInterface $migration */ $migration = \Drupal::entityManager() ->getStorage('migration') - ->loadUnchanged('d6_search_page'); + ->loadUnchanged('search_page'); // Indicate we're rerunning a migration that's already run. $migration->getIdMap()->prepareUpdate(); $this->executeMigration($migration); diff --git a/core/modules/search/src/Tests/Migrate/d7/MigrateSearchPageTest.php b/core/modules/search/src/Tests/Migrate/d7/MigrateSearchPageTest.php new file mode 100644 index 00000000000..4781dbcba5f --- /dev/null +++ b/core/modules/search/src/Tests/Migrate/d7/MigrateSearchPageTest.php @@ -0,0 +1,74 @@ +executeMigration('search_page'); + } + + /** + * Tests Drupal 7 search ranking to Drupal 8 search page entity migration. + */ + public function testSearchPage() { + $id = 'node_search'; + /** @var \Drupal\search\Entity\SearchPage $search_page */ + $search_page = SearchPage::load($id); + $this->assertIdentical($id, $search_page->id()); + $configuration = $search_page->getPlugin()->getConfiguration(); + $expected_rankings = array( + 'comments' => 0, + 'promote' => 0, + 'relevance' => 2, + 'sticky' => 0, + 'views' => 0, + ); + $this->assertIdentical($expected_rankings, $configuration['rankings']); + $this->assertIdentical('node', $search_page->getPath()); + + // Test that we can re-import using the EntitySearchPage destination. + Database::getConnection('default', 'migrate') + ->update('variable') + ->fields(array('value' => serialize(4))) + ->condition('name', 'node_rank_comments') + ->execute(); + + /** @var \Drupal\migrate\Entity\MigrationInterface $migration */ + $migration = \Drupal::entityManager() + ->getStorage('migration') + ->loadUnchanged('search_page'); + // Indicate we're rerunning a migration that's already run. + $migration->getIdMap()->prepareUpdate(); + $this->executeMigration($migration); + + $configuration = SearchPage::load($id)->getPlugin()->getConfiguration(); + $this->assertIdentical(4, $configuration['rankings']['comments']); + } + +}