本文整理汇总了PHP中Drupal\migrate\Entity\Migration类的典型用法代码示例。如果您正苦于以下问题:PHP Migration类的具体用法?PHP Migration怎么用?PHP Migration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Migration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCalculateDependencies
/**
* @covers ::calculateDependencies
*/
public function testCalculateDependencies()
{
$fixture_migrations = ['d6_node__article' => 'd6_node', 'd6_node__page' => 'd6_node', 'd6_variables' => 'd6_variables'];
foreach ($fixture_migrations as $id => $template) {
$values = ['id' => $id, 'template' => $template, 'source' => ['plugin' => 'empty'], 'destination' => ['plugin' => 'null'], 'migration_tags' => []];
Migration::create($values)->save();
}
$values = ['migration_dependencies' => ['required' => ['d6_node:*', 'd6_variables']], 'source' => ['plugin' => 'empty'], 'destination' => ['plugin' => 'null']];
$migration = new Migration($values, 'migration');
$expected = ['migrate.migration.d6_node__article', 'migrate.migration.d6_node__page', 'migrate.migration.d6_variables'];
$migration->calculateDependencies();
$this->assertEquals($expected, $migration->getDependencies()['config']);
}
示例2: assertEntity
/**
* Asserts various aspects of a migration entity.
*
* @param string $id
* The migration ID.
* @param string $label
* The label.
*/
protected function assertEntity($id, $label)
{
$migration = Migration::load($id);
$this->assertTrue($migration instanceof Migration);
$this->assertIdentical($id, $migration->Id());
$this->assertIdentical($label, $migration->label());
}
示例3: testStubWithWeightMapping
/**
* Tests creation of stubs when weight is mapped.
*/
public function testStubWithWeightMapping()
{
// Create a vocabulary via migration for the terms to reference.
$vocabulary_data_rows = [['id' => '1', 'name' => 'tags']];
$ids = ['id' => ['type' => 'integer']];
$config = ['id' => 'vocabularies', 'migration_tags' => ['Stub test'], 'source' => ['plugin' => 'embedded_data', 'data_rows' => $vocabulary_data_rows, 'ids' => $ids], 'process' => ['vid' => 'id', 'name' => 'name'], 'destination' => ['plugin' => 'entity:taxonomy_vocabulary']];
$vocabulary_migration = Migration::create($config);
$vocabulary_executable = new MigrateExecutable($vocabulary_migration, $this);
$vocabulary_executable->import();
// We have a term referencing an unmigrated parent, forcing a stub to be
// created.
$term_data_rows = [['id' => '1', 'vocab' => '1', 'name' => 'music', 'parent' => '2']];
$ids = ['id' => ['type' => 'integer']];
$config = ['id' => 'terms', 'migration_tags' => ['Import and rollback test'], 'source' => ['plugin' => 'embedded_data', 'data_rows' => $term_data_rows, 'ids' => $ids], 'process' => ['tid' => 'id', 'vid' => 'vocab', 'name' => 'name', 'weight' => 'weight', 'parent' => ['plugin' => 'migration', 'migration' => 'terms', 'source' => 'parent']], 'destination' => ['plugin' => 'entity:taxonomy_term'], 'migration_dependencies' => ['required' => ['vocabularies']]];
$term_migration = Migration::create($config);
$term_migration->save();
$term_executable = new MigrateExecutable($term_migration, $this);
$term_executable->import();
// Load the referenced term, which should exist as a stub.
/** @var \Drupal\Core\Entity\ContentEntityBase $stub_entity */
$stub_entity = Term::load(2);
$this->assertTrue($stub_entity, 'Stub successfully created');
if ($stub_entity) {
$this->assertIdentical(count($stub_entity->validate()), 0, 'Stub is a valid entity');
}
}
示例4: buildMigrations
/**
* {@inheritdoc}
*/
public function buildMigrations(array $template)
{
$migration = Migration::create($template);
$source_plugin = $migration->getSourcePlugin();
// The source plugin will throw RequirementsException if CCK is not enabled,
// in which case there is nothing else for us to do.
if ($source_plugin instanceof RequirementsInterface) {
try {
$source_plugin->checkRequirements();
} catch (RequirementsException $e) {
return [$migration];
}
}
// Loop through every field that will be migrated.
foreach ($source_plugin as $field) {
$field_type = $field->getSourceProperty('type');
// Each field type should only be processed once.
if (in_array($field_type, $this->processedFieldTypes)) {
continue;
} elseif ($this->cckPluginManager->hasDefinition($field_type)) {
$this->processedFieldTypes[] = $field_type;
// Allow the cckfield plugin to alter the migration as necessary so that
// it knows how to handle fields of this type.
$this->cckPluginManager->createInstance($field_type, [], $migration)->{$this->configuration['cck_plugin_method']}($migration);
}
}
return [$migration];
}
示例5: testNode
/**
* Test node migration from Drupal 6 to 8.
*/
public function testNode()
{
$node = Node::load(1);
$this->assertIdentical('1', $node->id(), 'Node 1 loaded.');
$this->assertIdentical('und', $node->langcode->value);
$this->assertIdentical('test', $node->body->value);
$this->assertIdentical('test', $node->body->summary);
$this->assertIdentical('filtered_html', $node->body->format);
$this->assertIdentical('story', $node->getType(), 'Node has the correct bundle.');
$this->assertIdentical('Test title', $node->getTitle(), 'Node has the correct title.');
$this->assertIdentical('1388271197', $node->getCreatedTime(), 'Node has the correct created time.');
$this->assertIdentical(FALSE, $node->isSticky());
$this->assertIdentical('1', $node->getOwnerId());
$this->assertIdentical('1420861423', $node->getRevisionCreationTime());
/** @var \Drupal\node\NodeInterface $node_revision */
$node_revision = \Drupal::entityManager()->getStorage('node')->loadRevision(1);
$this->assertIdentical('Test title', $node_revision->getTitle());
$this->assertIdentical('1', $node_revision->getRevisionAuthor()->id(), 'Node revision has the correct user');
// This is empty on the first revision.
$this->assertIdentical(NULL, $node_revision->revision_log->value);
// Test that we can re-import using the EntityContentBase destination.
$connection = Database::getConnection('default', 'migrate');
$connection->update('node_revisions')->fields(array('title' => 'New node title', 'format' => 2))->condition('vid', 1)->execute();
$connection->delete('content_field_test_two')->condition('delta', 1)->execute();
$migration = Migration::load('d6_node__story');
$this->executeMigration($migration);
$node = Node::load(1);
$this->assertIdentical('New node title', $node->getTitle());
// Test a multi-column fields are correctly upgraded.
$this->assertIdentical('test', $node->body->value);
$this->assertIdentical('full_html', $node->body->format);
}
示例6: overview
/**
* Displays a listing of migration messages.
*
* Messages are truncated at 56 chars.
*
* @return array
* A render array as expected by drupal_render().
*/
public function overview($migration_group, $migration)
{
$rows = [];
$classes = static::getLogLevelClassMap();
/** @var MigrationInterface $migration */
$migration = Migration::load($migration);
$source_id_field_names = array_keys($migration->getSourcePlugin()->getIds());
$column_number = 1;
foreach ($source_id_field_names as $source_id_field_name) {
$header[] = ['data' => $source_id_field_name, 'field' => 'sourceid' . $column_number++, 'class' => [RESPONSIVE_PRIORITY_MEDIUM]];
}
$header[] = ['data' => $this->t('Severity level'), 'field' => 'level', 'class' => [RESPONSIVE_PRIORITY_LOW]];
$header[] = ['data' => $this->t('Message'), 'field' => 'message'];
$message_table = $migration->getIdMap()->messageTableName();
$query = $this->database->select($message_table, 'm')->extend('\\Drupal\\Core\\Database\\Query\\PagerSelectExtender')->extend('\\Drupal\\Core\\Database\\Query\\TableSortExtender');
$query->fields('m');
$result = $query->limit(50)->orderByHeader($header)->execute();
foreach ($result as $message_row) {
$column_number = 1;
foreach ($source_id_field_names as $source_id_field_name) {
$column_name = 'sourceid' . $column_number++;
$row[$column_name] = $message_row->{$column_name};
}
$row['level'] = $message_row->level;
$row['message'] = $message_row->message;
$row['class'] = [Html::getClass('migrate-message-' . $message_row->level), $classes[$message_row->level]];
$rows[] = $row;
}
$build['message_table'] = ['#type' => 'table', '#header' => $header, '#rows' => $rows, '#attributes' => ['id' => $message_table, 'class' => [$message_table]], '#empty' => $this->t('No messages for this migration.')];
$build['message_pager'] = ['#type' => 'pager'];
return $build;
}
示例7: buildMigrations
/**
* {@inheritdoc}
*/
public function buildMigrations(array $template)
{
$migrations = [];
// Read all field instance definitions in the source database.
$fields = array();
foreach ($this->getSourcePlugin('d7_field_instance', $template['source']) as $field) {
$info = $field->getSource();
$fields[$info['entity_type']][$info['bundle']][$info['field_name']] = $info;
}
foreach ($this->getSourcePlugin('d7_node_type', $template['source']) as $node_type) {
$bundle = $node_type->getSourceProperty('type');
$values = $template;
$values['id'] .= '__' . $bundle;
$values['label'] = $this->t('@label (@type)', ['@label' => $values['label'], '@type' => $node_type->getSourceProperty('name')]);
$values['source']['node_type'] = $bundle;
$migration = Migration::create($values);
if (isset($fields['node'][$bundle])) {
foreach ($fields['node'][$bundle] as $field => $data) {
if ($this->cckPluginManager->hasDefinition($data['type'])) {
$this->getCckPlugin($data['type'])->processCckFieldValues($migration, $field, $data);
} else {
$migration->setProcessOfProperty($field, $field);
}
}
}
$migrations[] = $migration;
}
return $migrations;
}
示例8: testNodeType
/**
* Tests Drupal 6 node type to Drupal 8 migration.
*/
public function testNodeType()
{
$id_map = Migration::load('d6_node_type')->getIdMap();
// Test the test_page content type.
$node_type_page = NodeType::load('test_page');
$this->assertIdentical('test_page', $node_type_page->id(), 'Node type test_page loaded');
$this->assertIdentical(TRUE, $node_type_page->displaySubmitted());
$this->assertIdentical(FALSE, $node_type_page->isNewRevision());
$this->assertIdentical(DRUPAL_OPTIONAL, $node_type_page->getPreviewMode());
$this->assertIdentical($id_map->lookupDestinationID(array('test_page')), array('test_page'));
// Test we have a body field.
$field = FieldConfig::loadByName('node', 'test_page', 'body');
$this->assertIdentical('This is the body field label', $field->getLabel(), 'Body field was found.');
// Test the test_story content type.
$node_type_story = NodeType::load('test_story');
$this->assertIdentical('test_story', $node_type_story->id(), 'Node type test_story loaded');
$this->assertIdentical(TRUE, $node_type_story->displaySubmitted());
$this->assertIdentical(FALSE, $node_type_story->isNewRevision());
$this->assertIdentical(DRUPAL_OPTIONAL, $node_type_story->getPreviewMode());
$this->assertIdentical($id_map->lookupDestinationID(array('test_story')), array('test_story'));
// Test we don't have a body field.
$field = FieldConfig::loadByName('node', 'test_story', 'body');
$this->assertIdentical(NULL, $field, 'No body field found');
// Test the test_event content type.
$node_type_event = NodeType::load('test_event');
$this->assertIdentical('test_event', $node_type_event->id(), 'Node type test_event loaded');
$this->assertIdentical(TRUE, $node_type_event->displaySubmitted());
$this->assertIdentical(TRUE, $node_type_event->isNewRevision());
$this->assertIdentical(DRUPAL_OPTIONAL, $node_type_event->getPreviewMode());
$this->assertIdentical($id_map->lookupDestinationID(array('test_event')), array('test_event'));
// Test we have a body field.
$field = FieldConfig::loadByName('node', 'test_event', 'body');
$this->assertIdentical('Body', $field->getLabel(), 'Body field was found.');
}
示例9: testEmbeddedData
/**
* Tests the embedded_data source plugin.
*/
public function testEmbeddedData()
{
$data_rows = [['key' => '1', 'field1' => 'f1value1', 'field2' => 'f2value1'], ['key' => '2', 'field1' => 'f1value2', 'field2' => 'f2value2']];
$ids = ['key' => ['type' => 'integer']];
$config = ['id' => 'sample_data', 'migration_tags' => ['Embedded data test'], 'source' => ['plugin' => 'embedded_data', 'data_rows' => $data_rows, 'ids' => $ids], 'process' => [], 'destination' => ['plugin' => 'null']];
$migration = Migration::create($config);
$source = $migration->getSourcePlugin();
// Validate the plugin returns the source data that was provided.
$results = [];
/** @var Row $row */
foreach ($source as $row) {
$data_row = $row->getSource();
// The "data" row returned by getSource() also includes all source
// configuration - we remove it so we see only the data itself.
unset($data_row['plugin']);
unset($data_row['data_rows']);
unset($data_row['ids']);
$results[] = $data_row;
}
$this->assertIdentical($results, $data_rows);
// Validate the public APIs.
$this->assertIdentical($source->count(), count($data_rows));
$this->assertIdentical($source->getIds(), $ids);
$expected_fields = ['key' => 'key', 'field1' => 'field1', 'field2' => 'field2'];
$this->assertIdentical($source->fields(), $expected_fields);
}
示例10: buildMigrations
/**
* {@inheritdoc}
*/
public function buildMigrations(array $template)
{
$migrations = [];
$fields = [];
foreach ($this->getSourcePlugin('d7_field_instance', $template['source']) as $field) {
$entity_type = $field->getSourceProperty('entity_type');
$bundle = $field->getSourceProperty('bundle');
$field_name = $field->getSourceProperty('field_name');
$fields[$entity_type][$bundle][$field_name] = $field->getSource();
}
foreach ($this->getSourcePlugin('d7_node_type', $template['source']) as $node_type) {
$bundle = $node_type->getSourceProperty('type');
$values = $template;
$values['id'] .= '__' . $bundle;
$values['label'] = $this->t('@label (@type)', ['@label' => $values['label'], '@type' => $node_type->getSourceProperty('name')]);
$values['source']['node_type'] = $bundle;
$migration = Migration::create($values);
if (isset($fields['node'][$bundle])) {
foreach (array_keys($fields['node'][$bundle]) as $field) {
$migration->setProcessOfProperty($field, $field);
}
}
$migrations[] = $migration;
}
return $migrations;
}
示例11: testUserRole
/**
* Tests user role migration.
*/
public function testUserRole()
{
/** @var \Drupal\migrate\entity\Migration $migration */
$id_map = Migration::load('d6_user_role')->getIdMap();
$rid = 'anonymous';
$anonymous = Role::load($rid);
$this->assertIdentical($rid, $anonymous->id());
$this->assertIdentical(array('migrate test anonymous permission', 'use text format filtered_html'), $anonymous->getPermissions());
$this->assertIdentical(array($rid), $id_map->lookupDestinationId(array(1)));
$rid = 'authenticated';
$authenticated = Role::load($rid);
$this->assertIdentical($rid, $authenticated->id());
$this->assertIdentical(array('migrate test authenticated permission', 'use text format filtered_html'), $authenticated->getPermissions());
$this->assertIdentical(array($rid), $id_map->lookupDestinationId(array(2)));
$rid = 'migrate_test_role_1';
$migrate_test_role_1 = Role::load($rid);
$this->assertIdentical($rid, $migrate_test_role_1->id());
$this->assertIdentical(array('migrate test role 1 test permission', 'use text format full_html', 'use text format php_code'), $migrate_test_role_1->getPermissions());
$this->assertIdentical(array($rid), $id_map->lookupDestinationId(array(3)));
$rid = 'migrate_test_role_2';
$migrate_test_role_2 = Role::load($rid);
$this->assertIdentical(array('migrate test role 2 test permission', 'use PHP for settings', 'administer contact forms', 'skip comment approval', 'edit own blog content', 'edit any blog content', 'delete own blog content', 'delete any blog content', 'create forum content', 'delete any forum content', 'delete own forum content', 'edit any forum content', 'edit own forum content', 'administer nodes', 'access content overview', 'use text format php_code'), $migrate_test_role_2->getPermissions());
$this->assertIdentical($rid, $migrate_test_role_2->id());
$this->assertIdentical(array($rid), $id_map->lookupDestinationId(array(4)));
$rid = 'migrate_test_role_3_that_is_long';
$migrate_test_role_3 = Role::load($rid);
$this->assertIdentical($rid, $migrate_test_role_3->id());
$this->assertIdentical(array($rid), $id_map->lookupDestinationId(array(5)));
}
示例12: buildMigrations
/**
* {@inheritdoc}
*/
public function buildMigrations(array $template)
{
$migrations = [];
// Read all CCK field instance definitions in the source database.
$fields = array();
foreach ($this->getSourcePlugin('d6_field_instance', $template['source']) as $field) {
$info = $field->getSource();
$fields[$info['type_name']][$info['field_name']] = $info;
}
foreach ($this->getSourcePlugin('d6_node_type', $template['source']) as $row) {
$node_type = $row->getSourceProperty('type');
$values = $template;
$values['id'] = $template['id'] . '__' . $node_type;
$label = $template['label'];
$values['label'] = $this->t("@label (@type)", ['@label' => $label, '@type' => $node_type]);
$values['source']['node_type'] = $node_type;
$migration = Migration::create($values);
if (isset($fields[$node_type])) {
foreach ($fields[$node_type] as $field => $info) {
if ($this->cckPluginManager->hasDefinition($info['type'])) {
$this->getCckPlugin($info['type'])->processCckFieldValues($migration, $field, $info);
} else {
$migration->setProcessOfProperty($field, $field);
}
}
}
$migrations[] = $migration;
}
return $migrations;
}
示例13: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->installEntitySchema('file');
$this->installEntitySchema('node');
$this->installSchema('file', ['file_usage']);
$this->installSchema('node', ['node_access']);
$id_mappings = array('d6_file' => array());
// Create new file entities.
for ($i = 1; $i <= 3; $i++) {
$file = File::create(array('fid' => $i, 'uid' => 1, 'filename' => 'druplicon.txt', 'uri' => "public://druplicon-{$i}.txt", 'filemime' => 'text/plain', 'created' => 1, 'changed' => 1, 'status' => FILE_STATUS_PERMANENT));
$file->enforceIsNew();
file_put_contents($file->getFileUri(), 'hello world');
// Save it, inserting a new record.
$file->save();
$id_mappings['d6_file'][] = array(array($i), array($i));
}
$this->prepareMigrations($id_mappings);
$this->migrateContent();
// Since we are only testing a subset of the file migration, do not check
// that the full file migration has been run.
$migration = Migration::load('d6_upload');
$migration->set('requirements', []);
$this->executeMigration($migration);
}
示例14: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$id_mappings = array('d6_node:*' => array(array(array(0), array(0))));
$this->prepareMigrations($id_mappings);
$migrations = Migration::loadMultiple(['d6_term_node:*']);
array_walk($migrations, [$this, 'executeMigration']);
}
示例15: testVocabularyEntityFormDisplay
/**
* Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
*/
public function testVocabularyEntityFormDisplay()
{
// Test that the field exists.
$component = EntityFormDisplay::load('node.page.default')->getComponent('tags');
$this->assertIdentical('options_select', $component['type']);
$this->assertIdentical(20, $component['weight']);
// Test the Id map.
$this->assertIdentical(array('node', 'article', 'default', 'tags'), Migration::load('d6_vocabulary_entity_form_display')->getIdMap()->lookupDestinationID(array(4, 'article')));
}