Issue #2569245 by quietone, phenaproxima: [D7] Migrate search pages
parent
e882762b06
commit
b904c4b375
|
@ -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
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\search\Plugin\migrate\process\SearchConfigurationRankings.
|
||||
*/
|
||||
|
||||
namespace Drupal\search\Plugin\migrate\process;
|
||||
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Generate configuration rankings.
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "search_configuration_rankings"
|
||||
* )
|
||||
*/
|
||||
class SearchConfigurationRankings extends ProcessPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Generate the configuration rankings.
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
$return = array();
|
||||
foreach ($row->getSource() as $name => $rank) {
|
||||
if (substr($name, 0, 10) == 'node_rank_' && is_numeric($rank)) {
|
||||
$return[substr($name, 10)] = $rank;
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\search\Tests\Migrate\d7\MigrateSearchPageTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\search\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
use Drupal\search\Entity\SearchPage;
|
||||
|
||||
/**
|
||||
* Upgrade search rank settings to search.page.*.yml.
|
||||
*
|
||||
* @group migrate_drupal_7
|
||||
*/
|
||||
class MigrateSearchPageTest extends MigrateDrupal7TestBase {
|
||||
|
||||
/**
|
||||
* The modules to be enabled during the test.
|
||||
*
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('node', 'search');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->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']);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue