diff -u b/core/modules/migrate_drupal/tests/fixtures/drupal7.php b/core/modules/migrate_drupal/tests/fixtures/drupal7.php --- b/core/modules/migrate_drupal/tests/fixtures/drupal7.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php @@ -41494,7 +41494,7 @@ )) ->values(array( 'name' => 'search_active_modules', - 'value' => 'a:2:{s:4:"node";s:4:"node";s:4:"user";i:0;}', + 'value' => 'a:2:{s:4:"node";s:4:"node";s:4:"user";s:4:"user";}', )) ->values(array( 'name' => 'search_and_or_limit', @@ -41555,7 +41555,7 @@ )) ->values(array( 'name' => 'search_active_modules', - 'value' => 'a:2:{s:4:"node";s:4:"node";s:4:"user";s:4:"user";}', + 'value' => 'a:2:{s:4:"node";s:4:"node";s:4:"user";i:0;}', )) ->values(array( 'name' => 'search_and_or_limit', diff -u b/core/modules/search/migration_templates/d7_search_page_status.yml b/core/modules/search/migration_templates/d7_search_page_status.yml --- b/core/modules/search/migration_templates/d7_search_page_status.yml +++ b/core/modules/search/migration_templates/d7_search_page_status.yml @@ -5,7 +5,11 @@ source: plugin: d7_search_page_status process: - module_exists: module_exists + module_exists: + - + plugin: skip_on_empty + method: row + source: module_exists module: module status: status destination: diff -u b/core/modules/search/src/Plugin/migrate/destination/d7/SearchPageStatus.php b/core/modules/search/src/Plugin/migrate/destination/d7/SearchPageStatus.php --- b/core/modules/search/src/Plugin/migrate/destination/d7/SearchPageStatus.php +++ b/core/modules/search/src/Plugin/migrate/destination/d7/SearchPageStatus.php @@ -7,10 +7,13 @@ namespace Drupal\search\Plugin\migrate\destination\d7; +use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\migrate\Row; use Drupal\migrate\Entity\MigrationInterface; use Drupal\migrate\Plugin\migrate\destination\DestinationBase; use Drupal\search\Entity\SearchPage; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Destination for search page status. @@ -22,22 +25,57 @@ * id = "d7_search_page_status" * ) */ -class SearchPageStatus extends DestinationBase { +class SearchPageStatus extends DestinationBase implements ContainerFactoryPluginInterface { + + /** + * The module handler. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + + /** + * Constructs a BlockedIP object. + * + * @param array $configuration + * Plugin configuration. + * @param string $plugin_id + * The plugin ID. + * @param mixed $plugin_definition + * The plugin definiiton. + * @param \Drupal\migrate\Entity\MigrationInterface $migration + * The current migration. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler service. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, ModuleHandlerInterface $module_handler) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $migration); + $this->moduleHandler = $module_handler; + } /** * {@inheritdoc} */ - public function import(Row $row, array $old_destination_id_values = array()) { + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $migration, + $container->get('module_handler') + ); + } - // Config name is constructed as _search, which probably - // only works for the Node and User module. - $id = $row->getDestinationProperty('module') . '_search'; - /** @var \Drupal\search\Entity\SearchPage $search_page */ - $search_page = SearchPage::load($id); - if (!$row->getDestinationProperty('module_exists')) { - $search_page->delete(); - } - else { + /** + * {@inheritdoc} + */ + public function import(Row $row, array $old_destination_id_values = array()) { + if ($this->moduleHandler->moduleExists($row->getDestinationProperty('module'))) { + // Config name is constructed as _search, which probably + // only works for the Node and User module. + $id = $row->getDestinationProperty('module') . '_search'; + /** @var \Drupal\search\Entity\SearchPage $search_page */ + $search_page = SearchPage::load($id); if ($row->getDestinationProperty('status')) { $search_page->enable()->save(); } diff -u b/core/modules/search/src/Tests/Migrate/d7/MigrateSearchPageStatusTest.php b/core/modules/search/src/Tests/Migrate/d7/MigrateSearchPageStatusTest.php --- b/core/modules/search/src/Tests/Migrate/d7/MigrateSearchPageStatusTest.php +++ b/core/modules/search/src/Tests/Migrate/d7/MigrateSearchPageStatusTest.php @@ -7,7 +7,6 @@ namespace Drupal\search\Tests\Migrate\d7; -use Drupal\Core\Database\Database; use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase; use Drupal\search\Entity\SearchPage; @@ -21,20 +20,22 @@ /** * {@inheritdoc} */ - public static $modules = array('node', 'search'); + public static $modules = ['search']; /** * {@inheritdoc} */ protected function setUp() { parent::setUp(); - $this->installConfig(['search']); + } /** * Tests migrating Drupal 7 search status to Drupal 8 search status. */ public function testSearchStatus() { + $this->enableModules(['node']); + $this->installConfig(['search']); $this->executeMigration('d7_search_page_status'); /** @var \Drupal\search\Entity\SearchPage $search_page */ $id = 'node_search'; @@ -47,15 +48,11 @@ } /** - * Tests that search status is only migrated for enabled modules. + * Tests that search status is only migrated for modules enabled on + * destination site. */ public function testModuleExists() { - Database::getConnection('default', 'migrate') - ->update('system') - ->fields(array('status' => '0')) - ->condition('name', 'node') - ->execute(); - + $this->installConfig(['search']); $this->executeMigration('d7_search_page_status'); /** @var \Drupal\search\Entity\SearchPage $search_page */ $id = 'node_search';