prepareUpdate example

'destid1' => 'destination_value_' . $status,
        'source_row_status' => $status,
        'rollback_action' => MigrateIdMapInterface::ROLLBACK_DELETE,
        'hash' => '',
      ];
    }

    // Assert that test values exist.     $this->queryResultTest($this->getIdMapContents()$expected_results);

    // Mark all rows as STATUS_NEEDS_UPDATE.     $id_map->prepareUpdate();

    // Update expected results.     foreach ($expected_results as $key => $value) {
      $expected_results[$key]['source_row_status'] = MigrateIdMapInterface::STATUS_NEEDS_UPDATE;
    }
    // Assert that updated expected values match.     $this->queryResultTest($this->getIdMapContents()$expected_results);
  }

  /** * Tests the destroy method. * * Scenarios to test for: * - No errors. * - One error. * - Multiple errors. */
    // current high water mark.     $this->sourceDatabase->update('high_water_node')
      ->fields([
        'title' => 'Item 3 updated',
        'changed' => 4,
      ])
      ->condition('title', 'Item 3')
      ->execute();

    // Set all rows as needing an update.     $id_map = $this->getMigration('high_water_test')->getIdMap();
    $id_map->prepareUpdate();

    $this->executeMigration('high_water_test');

    // Item with lower high water should be updated.     $this->assertNodeExists('Item 1 updated');
    $this->assertNodeDoesNotExist('Item 1');

    // Item with equal high water should be updated.     $this->assertNodeExists('Item 2 updated');
    $this->assertNodeDoesNotExist('Item 2');

    
// Item without name changes should not be updated.     $this->assertTermExists('name', 'Item 2');

    // Item with field changes should be updated.     $this->assertTermExists('description', 'Text item 3 updated');
    $this->assertTermDoesNotExist('description', 'Text item 3');

    // Item without field changes should not be updated.     $this->assertTermExists('description', 'Text item 4');

    // Test hashes again after forcing all rows to be re-imported.     $id_map->prepareUpdate();

    // Execute migration again.     $this->executeMigration('track_changes_test');

    for ($i = 1; $i < 5; $i++) {
      $row = $id_map->getRowBySource(['tid' => $i]);
      $newer_hash[$i] = $row['hash'];
    }
    $this->assertEquals($new_hash[1]$newer_hash[1]);
    $this->assertEquals($new_hash[2]$newer_hash[2]);
    $this->assertEquals($new_hash[3]$newer_hash[3]);
    
$this->assertTrue($config->isLanguageAlterable());

    // Test that menus are not alterable when the i18nmenu is not enabled.     $this->sourceDatabase->update('system')
      ->fields(['status' => 0])
      ->condition('name', 'i18nmenu')
      ->execute();

    /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
    $migration = $this->getMigration('d6_language_content_menu_settings');
    // Indicate we're rerunning a migration that's already run.     $migration->getIdMap()->prepareUpdate();
    $this->executeMigration($migration);

    $config = ContentLanguageSettings::load('menu_link_content.menu_link_content');
    $this->assertInstanceOf(ContentLanguageSettings::class$config);
    $this->assertSame('menu_link_content', $config->getTargetEntityTypeId());
    $this->assertSame('menu_link_content', $config->getTargetBundle());
    $this->assertSame(LanguageInterface::LANGCODE_SITE_DEFAULT, $config->getDefaultLangcode());
    $this->assertFalse($config->isLanguageAlterable());
  }

}
// Test that we can re-import using the EntitySearchPage destination.     Database::getConnection('default', 'migrate')
      ->update('variable')
      ->fields(['value' => serialize(4)])
      ->condition('name', 'node_rank_comments')
      ->execute();

    /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
    $migration = $this->getMigration('d7_search_page');
    // Indicate we're rerunning a migration that's already run.     $migration->getIdMap()->prepareUpdate();
    $this->executeMigration($migration);
    $configuration['rankings']['comments'] = 4;
    $this->assertEntity('node_search', 'node', TRUE, $configuration);

    // Test that a configurable search without a configuration imports. Do this     // by removing the node rankings from the source database.     Database::getConnection('default', 'migrate')
      ->delete('variable')
      ->condition('name', 'node_rank_%', 'LIKE')
      ->execute();

    
foreach ($user_register_map as $map) {
      // Tests migration of user_register = 1       Database::getConnection('default', 'migrate')
        ->update('variable')
        ->fields(['value' => serialize($map[0])])
        ->condition('name', 'user_register')
        ->execute();

      /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
      $migration = $this->getMigration('d6_user_settings');
      // Indicate we're rerunning a migration that's already run.       $migration->getIdMap()->prepareUpdate();
      $this->executeMigration($migration);
      $form = $this->container->get('form_builder')->getForm(AccountSettingsForm::create($this->container));
      $this->assertSame($map[1]$form['registration_cancellation']['user_register']['#value']);
    }
  }

}
foreach ($user_register_map as $map) {
      // Tests migration of user_register = 1.       Database::getConnection('default', 'migrate')
        ->update('variable')
        ->fields(['value' => serialize($map[0])])
        ->condition('name', 'user_register')
        ->execute();

      /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
      $migration = $this->getMigration('d7_user_settings');
      // Indicate we're rerunning a migration that's already run.       $migration->getIdMap()->prepareUpdate();
      $this->executeMigration($migration);
      $form = $this->container->get('form_builder')->getForm(AccountSettingsForm::create($this->container));
      $this->assertSame($map[1]$form['registration_cancellation']['user_register']['#value']);
    }
  }

}
$tree = \Drupal::service('book.manager')->bookTreeAllData(4);
    $this->assertSame('4', $tree['49990 Node 4 4']['link']['nid']);
    $this->assertSame('5', $tree['49990 Node 4 4']['below']['50000 Node 5 5']['link']['nid']);
    $this->assertSame('6', $tree['49990 Node 4 4']['below']['50000 Node 5 5']['below']['50000 Node 6 6']['link']['nid']);
    $this->assertSame('7', $tree['49990 Node 4 4']['below']['50000 Node 5 5']['below']['50000 Node 7 7']['link']['nid']);
    $this->assertSame([]$tree['49990 Node 4 4']['below']['50000 Node 5 5']['below']['50000 Node 6 6']['below']);
    $this->assertSame([]$tree['49990 Node 4 4']['below']['50000 Node 5 5']['below']['50000 Node 7 7']['below']);

    // Set the d6_book migration to update and re run the migration.     $id_map = $this->migration->getIdMap();
    $id_map->prepareUpdate();
    $this->executeMigration('d6_book');
  }

}
// Test that we can re-import using the EntitySearchPage destination.     Database::getConnection('default', 'migrate')
      ->update('variable')
      ->fields(['value' => serialize(4)])
      ->condition('name', 'node_rank_comments')
      ->execute();

    /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
    $migration = $this->getMigration('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->assertSame(4, $configuration['rankings']['comments']);

    // Test that a configurable search without a configuration imports. Do this     // by removing the node rankings from the source database.     Database::getConnection('default', 'migrate')
      ->delete('variable')
      ->condition('name', 'node_rank_%', 'LIKE')
      ->execute();

    
$this->assertSame('4', $nodes[6]->book['bid']);
    $this->assertSame('4', $nodes[6]->book['pid']);

    $tree = \Drupal::service('book.manager')->bookTreeAllData(4);
    $this->assertSame('4', $tree['49990 is - The thing about Firefly 4']['link']['nid']);
    $this->assertSame('6', $tree['49990 is - The thing about Firefly 4']['below']['50000 Comments are closed :-( 6']['link']['nid']);
    $this->assertSame('2', $tree['49990 is - The thing about Firefly 4']['below']['50000 Comments are closed :-( 6']['below']['50000 The thing about Deep Space 9 2']['link']['nid']);
    $this->assertSame([]$tree['49990 is - The thing about Firefly 4']['below']['50000 Comments are closed :-( 6']['below']['50000 The thing about Deep Space 9 2']['below']);

    // Set the d7_book migration to update and re run the migration.     $id_map = $this->migration->getIdMap();
    $id_map->prepareUpdate();
    $this->executeMigration('d7_book');
  }

}
Home | Imprint | This part of the site doesn't use cookies.