コード例 #1
0
 /**
  * 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.');
 }
コード例 #2
0
ファイル: MigrateUploadTest.php プロジェクト: ddrozdik/dmaps
 /**
  * {@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);
 }
コード例 #3
0
 /**
  * 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());
 }
コード例 #4
0
 /**
  * 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);
 }
コード例 #5
0
 /**
  * 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;
 }
コード例 #6
0
 /**
  * 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)));
 }
コード例 #7
0
ファイル: MigrateManifest.php プロジェクト: atxajon/d8cafe
 /**
  * Drush execution method. Runs imports on the supplied manifest.
  */
 public function import()
 {
     /** @var \Drupal\migrate\MigrateTemplateStorage $template_storage */
     $template_storage = \Drupal::service('migrate.template_storage');
     $this->setupLegacyDb();
     $migration_ids = [];
     $migrations = [];
     foreach ($this->migrationList as $migration_info) {
         if (is_array($migration_info)) {
             // The migration is stored as the key in the info array.
             $migration_id = key($migration_info);
         } else {
             // If it wasn't an array then the info is just the migration_id.
             $migration_id = $migration_info;
         }
         $template = $template_storage->getTemplateByName($migration_id) ?: [];
         if (is_array($migration_info)) {
             // If there is some existing global overrides then we merge them in.
             if (isset($GLOBALS['config'][$migration_id])) {
                 $migration_info = NestedArray::mergeDeep($GLOBALS['config'][$migration_id], $migration_info);
             }
             $migration_info = NestedArray::mergeDeep($template, $migration_info);
         } else {
             $migration_info = $template;
         }
         if ($migration_info) {
             /** @var \Drupal\migrate\Entity\Migration[] $migrations */
             $migrations = \Drupal::service('migrate.migration_builder')->createMigrations([$migration_id => $migration_info]);
             foreach ($migrations as $migration) {
                 $migration_ids[] = $migration->id();
                 if (!Migration::load($migration->id())) {
                     $migration->save();
                 }
             }
             // We use these migration_ids to run migrations. If we didn't create
             // anything we pass it on and this will trigger non-existent migrations
             // messages or resolved by migration loading.
             // @todo this can return false positives in the non-existent migration
             // logic if the builder explicitly returned no results. For example, no
             // taxonomies will cause some things to be empty.
             if (!$migrations) {
                 $migration_ids[] = $migration_id;
             }
         }
     }
     // Load all the migrations at once so they're correctly ordered.
     foreach (Migration::loadMultiple($migration_ids) as $migration) {
         $executable = $this->executeMigration($migration);
         // Store all the migrations for later.
         $migrations[$migration->id()] = array('executable' => $executable, 'migration' => $migration, 'source' => $migration->get('source'), 'destination' => $migration->get('destination'));
     }
     // Warn the user if any migrations were not found.
     $nonexistent_migrations = array_diff($migration_ids, array_keys($migrations));
     if (count($nonexistent_migrations) > 0) {
         drush_log(dt('The following migrations were not found: @migrations', array('@migrations' => implode(', ', $nonexistent_migrations))), 'warning');
     }
     return $migrations;
 }
コード例 #8
0
 /**
  * Tests Drupal 6 view modes to Drupal 8 migration.
  */
 public function testViewModes()
 {
     // Test a new view mode.
     $view_mode = EntityViewMode::load('node.preview');
     $this->assertIdentical(FALSE, is_null($view_mode), 'Preview view mode loaded.');
     $this->assertIdentical('Preview', $view_mode->label(), 'View mode has correct label.');
     // Test the ID map.
     $this->assertIdentical(array('node', 'preview'), Migration::load('d6_view_modes')->getIdMap()->lookupDestinationID(array(1)));
 }
コード例 #9
0
 /**
  * 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')));
 }
コード例 #10
0
 /**
  * Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
  */
 public function testVocabularyField()
 {
     // Test that the field exists.
     $field_storage_id = 'node.tags';
     $field_storage = FieldStorageConfig::load($field_storage_id);
     $this->assertIdentical($field_storage_id, $field_storage->id());
     $settings = $field_storage->getSettings();
     $this->assertIdentical('taxonomy_term', $settings['target_type'], "Target type is correct.");
     $this->assertIdentical(array('node', 'tags'), Migration::load('d6_vocabulary_field')->getIdMap()->lookupDestinationID(array(4)), "Test IdMap");
 }
コード例 #11
0
 /**
  * Tests dependencies on the migration of aggregator feeds & items.
  */
 public function testAggregatorMigrateDependencies()
 {
     /** @var \Drupal\migrate\entity\Migration $migration */
     $migration = Migration::load('d6_aggregator_item');
     $executable = new MigrateExecutable($migration, $this);
     $this->startCollectingMessages();
     $executable->import();
     $this->assertEqual($this->migrateMessages['error'], array(SafeMarkup::format('Migration @id did not meet the requirements. Missing migrations d6_aggregator_feed. requirements: d6_aggregator_feed.', array('@id' => $migration->id()))));
     $this->collectMessages = FALSE;
 }
コード例 #12
0
 /**
  * Tests that an exception is thrown when ImageCache is not installed.
  */
 public function testMissingTable()
 {
     $this->sourceDatabase->update('system')->fields(array('status' => 0))->condition('name', 'imagecache')->condition('type', 'module')->execute();
     try {
         Migration::load('d6_imagecache_presets')->getSourcePlugin()->checkRequirements();
         $this->fail('Did not catch expected RequirementsException.');
     } catch (RequirementsException $e) {
         $this->pass('Caught expected RequirementsException: ' . $e->getMessage());
     }
 }
コード例 #13
0
 /**
  * Tests that term associations are ignored when they belong to nodes which
  * were not migrated.
  */
 public function testSkipNonExistentNode()
 {
     // Node 2 is migrated by d6_node__story, but we need to pretend that it
     // failed, so record that in the map table.
     $this->mockFailure('d6_node__story', ['nid' => 2]);
     // d6_term_node__2 should skip over node 2 (a.k.a. revision 3) because,
     // according to the map table, it failed.
     $migration = Migration::load('d6_term_node__2');
     $this->executeMigration($migration);
     $this->assertNull($migration->getIdMap()->lookupDestinationId(['vid' => 3])[0]);
 }
コード例 #14
0
ファイル: MigrateUserTest.php プロジェクト: ddrozdik/dmaps
 /**
  * Tests the Drupal6 user to Drupal 8 migration.
  */
 public function testUser()
 {
     $users = Database::getConnection('default', 'migrate')->select('users', 'u')->fields('u')->condition('uid', 0, '>')->execute()->fetchAll();
     foreach ($users as $source) {
         // Get roles directly from the source.
         $rids = Database::getConnection('default', 'migrate')->select('users_roles', 'ur')->fields('ur', array('rid'))->condition('ur.uid', $source->uid)->execute()->fetchCol();
         $roles = array(RoleInterface::AUTHENTICATED_ID);
         $id_map = Migration::load('d6_user_role')->getIdMap();
         foreach ($rids as $rid) {
             $role = $id_map->lookupDestinationId(array($rid));
             $roles[] = reset($role);
         }
         /** @var \Drupal\user\UserInterface $user */
         $user = User::load($source->uid);
         $this->assertIdentical($source->uid, $user->id());
         $this->assertIdentical($source->name, $user->label());
         $this->assertIdentical($source->mail, $user->getEmail());
         $this->assertIdentical($source->created, $user->getCreatedTime());
         $this->assertIdentical($source->access, $user->getLastAccessedTime());
         $this->assertIdentical($source->login, $user->getLastLoginTime());
         $is_blocked = $source->status == 0;
         $this->assertIdentical($is_blocked, $user->isBlocked());
         // $user->getPreferredLangcode() might fallback to default language if the
         // user preferred language is not configured on the site. We just want to
         // test if the value was imported correctly.
         $this->assertIdentical($source->language, $user->preferred_langcode->value);
         $expected_timezone_name = $source->timezone_name ?: $this->config('system.date')->get('timezone.default');
         $this->assertIdentical($expected_timezone_name, $user->getTimeZone());
         $this->assertIdentical($source->init, $user->getInitialEmail());
         $this->assertIdentical($roles, $user->getRoles());
         // We have one empty picture in the data so don't try load that.
         if (!empty($source->picture)) {
             // Test the user picture.
             $file = File::load($user->user_picture->target_id);
             $this->assertIdentical(basename($source->picture), $file->getFilename());
         }
         // Use the API to check if the password has been salted and re-hashed to
         // conform to Drupal >= 7 for non-admin users.
         if ($user->id() != 1) {
             $this->assertTrue(\Drupal::service('password')->check($source->pass_plain, $user->getPassword()));
         }
     }
     // Rollback the migration and make sure everything is deleted but uid 1.
     (new MigrateExecutable($this->migration, $this))->rollback();
     $users = Database::getConnection('default', 'migrate')->select('users', 'u')->fields('u', ['uid'])->condition('uid', 0, '>')->execute()->fetchCol();
     foreach ($users as $uid) {
         $account = User::load($uid);
         if ($uid == 1) {
             $this->assertNotNull($account, 'User 1 was preserved after rollback');
         } else {
             $this->assertNull($account);
         }
     }
 }
コード例 #15
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('file');
     /** @var \Drupal\migrate\Entity\MigrationInterface $migration */
     $migration = Migration::load('d6_user_picture_file');
     $source = $migration->get('source');
     $source['site_path'] = 'core/modules/simpletest';
     $migration->set('source', $source);
     $this->executeMigration($migration);
 }
コード例 #16
0
ファイル: PathRedirectTest.php プロジェクト: isramv/camp-gdl
 /**
  * Tests the Drupal 6 path redirect to Drupal 8 migration.
  */
 public function testPathRedirect()
 {
     /** @var Redirect $redirect */
     $redirect = Redirect::load(5);
     $this->assertIdentical(Migration::load('d6_path_redirect')->getIdMap()->lookupDestinationID(array(5)), array($redirect->id()));
     $this->assertIdentical("/test/source/url", $redirect->getSourceUrl());
     $this->assertIdentical("base:test/redirect/url", $redirect->getRedirectUrl()->toUriString());
     $redirect = Redirect::load(7);
     $this->assertIdentical("/test/source/url2", $redirect->getSourceUrl());
     $this->assertIdentical("http://test/external/redirect/url?foo=bar&biz=buz", $redirect->getRedirectUrl()->toUriString());
 }
コード例 #17
0
 /**
  * Run the configured migrations.
  */
 public function import()
 {
     $log = new DrushLogMigrateMessage();
     foreach ($this->migrationList as $migration_id) {
         /** @var MigrationInterface $migration */
         $migration = Migration::load($migration_id);
         drush_print(dt('Upgrading !migration', ['!migration' => $migration_id]));
         $executable = new MigrateExecutable($migration, $log);
         // drush_op() provides --simulate support.
         drush_op([$executable, 'import']);
     }
 }
コード例 #18
0
 /**
  * Set up the relevant migrations for import from the provided database
  * connection.
  *
  * @param \Drupal\Core\Database\Database $database
  *   Database array representing the source Drupal database.
  * @param string $source_base_path
  *   Address of the source Drupal site (e.g., http://example.com/).
  *
  * @return array
  */
 protected function createMigrations(array $database, $source_base_path)
 {
     // Set up the connection.
     Database::addConnectionInfo('upgrade', 'default', $database);
     $connection = Database::getConnection('default', 'upgrade');
     if (!($drupal_version = $this->getLegacyDrupalVersion($connection))) {
         throw new \Exception($this->t('Source database does not contain a recognizable Drupal version.'));
     }
     $database_state['key'] = 'upgrade';
     $database_state['database'] = $database;
     $database_state_key = 'migrate_upgrade_' . $drupal_version;
     \Drupal::state()->set($database_state_key, $database_state);
     $version_tag = 'Drupal ' . $drupal_version;
     $template_storage = \Drupal::service('migrate.template_storage');
     $migration_templates = $template_storage->findTemplatesByTag($version_tag);
     foreach ($migration_templates as $id => $template) {
         $migration_templates[$id]['source']['database_state_key'] = $database_state_key;
         // Configure file migrations so they can find the files.
         if ($template['destination']['plugin'] == 'entity:file') {
             if ($source_base_path) {
                 // Make sure we have a single trailing slash.
                 $source_base_path = rtrim($source_base_path, '/') . '/';
                 $migration_templates[$id]['destination']['source_base_path'] = $source_base_path;
             }
         }
     }
     // Let the builder service create our migration configuration entities from
     // the templates, expanding them to multiple entities where necessary.
     /** @var \Drupal\migrate\MigrationBuilder $builder */
     $builder = \Drupal::service('migrate.migration_builder');
     $migrations = $builder->createMigrations($migration_templates);
     $migration_ids = [];
     foreach ($migrations as $migration) {
         try {
             if ($migration->getSourcePlugin() instanceof RequirementsInterface) {
                 $migration->getSourcePlugin()->checkRequirements();
             }
             if ($migration->getDestinationPlugin() instanceof RequirementsInterface) {
                 $migration->getDestinationPlugin()->checkRequirements();
             }
             // Don't try to resave migrations that already exist.
             if (!Migration::load($migration->id())) {
                 $migration->save();
             }
             $migration_ids[] = $migration->id();
         } catch (RequirementsException $e) {
         } catch (PluginNotFoundException $e) {
         }
     }
     // loadMultiple will sort the migrations in dependency order.
     return array_keys(Migration::loadMultiple($migration_ids));
 }
コード例 #19
0
 /**
  * Tests the migrated comment types.
  */
 public function testMigration()
 {
     $this->assertEntity('comment_node_page', 'Basic page comment');
     $this->assertEntity('comment_node_article', 'Article comment');
     $this->assertEntity('comment_node_blog', 'Blog entry comment');
     $this->assertEntity('comment_node_book', 'Book page comment');
     $this->assertEntity('comment_node_forum', 'Forum topic comment');
     $this->assertEntity('comment_node_test_content_type', 'Test content type comment');
     // Validate that the source count and processed count match up.
     /** @var \Drupal\migrate\Entity\MigrationInterface $migration */
     $migration = Migration::load('d7_comment_type');
     $this->assertIdentical($migration->getSourcePlugin()->count(), $migration->getIdMap()->processedCount());
 }
コード例 #20
0
 /**
  * Tests the Drupal 6 upload settings to Drupal 8 entity form display migration.
  */
 public function testUploadEntityFormDisplay()
 {
     $display = EntityFormDisplay::load('node.page.default');
     $component = $display->getComponent('upload');
     $this->assertIdentical('file_generic', $component['type']);
     $display = EntityFormDisplay::load('node.story.default');
     $component = $display->getComponent('upload');
     $this->assertIdentical('file_generic', $component['type']);
     // Assure this doesn't exist.
     $display = EntityFormDisplay::load('node.article.default');
     $component = $display->getComponent('upload');
     $this->assertTrue(is_null($component));
     $this->assertIdentical(array('node', 'page', 'default', 'upload'), Migration::load('d6_upload_entity_form_display')->getIdMap()->lookupDestinationID(array('page')));
 }
コード例 #21
0
 /**
  * Tests the Drupal 6 upload settings to Drupal 8 field instance migration.
  */
 public function testUploadFieldInstance()
 {
     $field = FieldConfig::load('node.page.upload');
     $settings = $field->getSettings();
     $this->assertIdentical('node.page.upload', $field->id());
     $this->assertIdentical('jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp', $settings['file_extensions']);
     $this->assertIdentical('1MB', $settings['max_filesize']);
     $this->assertIdentical(TRUE, $settings['description_field']);
     $field = FieldConfig::load('node.story.upload');
     $this->assertIdentical('node.story.upload', $field->id());
     // Shouldn't exist.
     $field = FieldConfig::load('node.article.upload');
     $this->assertTrue(is_null($field));
     $this->assertIdentical(array('node', 'page', 'upload'), Migration::load('d6_upload_field_instance')->getIdMap()->lookupDestinationID(array('page')));
 }
コード例 #22
0
 /**
  * Executes all user migrations.
  *
  * @param bool $include_pictures
  *   If TRUE, migrates user pictures.
  */
 protected function migrateUsers($include_pictures = TRUE)
 {
     $this->executeMigrations(['d6_filter_format', 'd6_user_role']);
     if ($include_pictures) {
         $this->installEntitySchema('file');
         $this->executeMigrations(['d6_file', 'd6_user_picture_file', 'user_picture_field', 'user_picture_field_instance', 'user_picture_entity_display', 'user_picture_entity_form_display']);
     } else {
         // These are optional dependencies of d6_user, but we don't need them if
         // we're not migrating user pictures.
         Migration::load('d6_user_picture_file')->delete();
         Migration::load('user_picture_entity_display')->delete();
         Migration::load('user_picture_entity_form_display')->delete();
     }
     $this->executeMigration('d6_user');
 }
コード例 #23
0
 /**
  * Run the configured migrations.
  */
 public function import()
 {
     static::$messages = new DrushLogMigrateMessage();
     if (drush_get_option('debug')) {
         \Drupal::service('event_dispatcher')->addListener(MigrateEvents::IDMAP_MESSAGE, [get_class(), 'onIdMapMessage']);
     }
     foreach ($this->migrationList as $migration_id) {
         /** @var MigrationInterface $migration */
         $migration = Migration::load($migration_id);
         drush_print(dt('Upgrading @migration', ['@migration' => $migration_id]));
         $executable = new MigrateExecutable($migration, static::$messages);
         // drush_op() provides --simulate support.
         drush_op([$executable, 'import']);
     }
 }
コード例 #24
0
 /**
  * Tests the Drupal 6 date formats to Drupal 8 migration.
  */
 public function testDateFormats()
 {
     $short_date_format = DateFormat::load('short');
     $this->assertIdentical('\\S\\H\\O\\R\\T m/d/Y - H:i', $short_date_format->getPattern());
     $medium_date_format = DateFormat::load('medium');
     $this->assertIdentical('\\M\\E\\D\\I\\U\\M D, m/d/Y - H:i', $medium_date_format->getPattern());
     $long_date_format = DateFormat::load('long');
     $this->assertIdentical('\\L\\O\\N\\G l, F j, Y - H:i', $long_date_format->getPattern());
     // Test that we can re-import using the EntityDateFormat destination.
     Database::getConnection('default', 'migrate')->update('variable')->fields(array('value' => serialize('\\S\\H\\O\\R\\T d/m/Y - H:i')))->condition('name', 'date_format_short')->execute();
     \Drupal::database()->truncate(Migration::load('d6_date_formats')->getIdMap()->mapTableName())->execute();
     $migration = \Drupal::entityManager()->getStorage('migration')->loadUnchanged('d6_date_formats');
     $this->executeMigration($migration);
     $short_date_format = DateFormat::load('short');
     $this->assertIdentical('\\S\\H\\O\\R\\T d/m/Y - H:i', $short_date_format->getPattern());
 }
コード例 #25
0
 /**
  * Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
  */
 public function testVocabularyFieldInstance()
 {
     // Test that the field exists.
     $field_id = 'node.article.tags';
     $field = FieldConfig::load($field_id);
     $this->assertIdentical($field_id, $field->id(), 'Field instance exists on article bundle.');
     // Test the page bundle as well.
     $field_id = 'node.page.tags';
     $field = FieldConfig::load($field_id);
     $this->assertIdentical($field_id, $field->id(), 'Field instance exists on page bundle.');
     $settings = $field->getSettings();
     $this->assertIdentical('default:taxonomy_term', $settings['handler'], 'The handler plugin ID is correct.');
     $this->assertIdentical(['tags'], $settings['handler_settings']['target_bundles'], 'The target_bundle handler setting is correct.');
     $this->assertIdentical(TRUE, $settings['handler_settings']['auto_create'], 'The "auto_create" setting is correct.');
     $this->assertIdentical(array('node', 'article', 'tags'), Migration::load('d6_vocabulary_field_instance')->getIdMap()->lookupDestinationID(array(4, 'article')));
 }
コード例 #26
0
 /**
  * Run the configured migrations.
  */
 public function import()
 {
     $log = new DrushLogMigrateMessage();
     foreach ($this->migrationList as $migration_id) {
         /** @var MigrationInterface $migration */
         $migration = Migration::load($migration_id);
         drush_print(dt('Upgrading @migration', ['@migration' => $migration_id]));
         $executable = new MigrateExecutable($migration, $log);
         // drush_op() provides --simulate support.
         drush_op([$executable, 'import']);
         // @todo Remove when https://www.drupal.org/node/2598696 is released.
         if ($migration_id == 'd6_user' || $migration_id == 'd7_user') {
             $table = 'migrate_map_' . $migration_id;
             db_merge($table)->key(['sourceid1' => 1])->fields(['destid1' => -1])->execute();
         }
     }
 }
コード例 #27
0
ファイル: MigrateNodeTest.php プロジェクト: frankcr/sftw8
 /**
  * Execute the migration a second time.
  *
  * @param array $new_row
  *   An optional row to be inserted into the id map.
  *
  * @return string
  *   The new title in the source for vid 3.
  */
 protected function rerunMigration($new_row = [])
 {
     $title = $this->randomString();
     $migration = Migration::load('d6_node__story');
     $source_connection = Database::getConnection('default', 'migrate');
     $source_connection->update('node_revisions')->fields(array('title' => $title, 'format' => 2))->condition('vid', 3)->execute();
     $table_name = $migration->getIdMap()->mapTableName();
     $default_connection = \Drupal::database();
     $default_connection->truncate($table_name)->execute();
     if ($new_row) {
         $hash = $migration->getIdMap()->getSourceIDsHash(['nid' => $new_row['sourceid1']]);
         $new_row['source_ids_hash'] = $hash;
         $default_connection->insert($table_name)->fields($new_row)->execute();
     }
     $this->executeMigration($migration);
     return $title;
 }
コード例 #28
0
 /**
  * Tests the Drupal 6 taxonomy vocabularies to Drupal 8 migration.
  */
 public function testTaxonomyVocabulary()
 {
     for ($i = 0; $i < 3; $i++) {
         $j = $i + 1;
         $vocabulary = Vocabulary::load("vocabulary_{$j}_i_{$i}_");
         $this->assertIdentical(Migration::load('d6_taxonomy_vocabulary')->getIdMap()->lookupDestinationID(array($j)), array($vocabulary->id()));
         $this->assertIdentical("vocabulary {$j} (i={$i})", $vocabulary->label());
         $this->assertIdentical("description of vocabulary {$j} (i={$i})", $vocabulary->getDescription());
         $this->assertIdentical($i, $vocabulary->getHierarchy());
         $this->assertIdentical(4 + $i, $vocabulary->get('weight'));
     }
     $vocabulary = Vocabulary::load('vocabulary_name_much_longer_than');
     $this->assertIdentical('vocabulary name much longer than thirty two characters', $vocabulary->label());
     $this->assertIdentical('description of vocabulary name much longer than thirty two characters', $vocabulary->getDescription());
     $this->assertIdentical(3, $vocabulary->getHierarchy());
     $this->assertIdentical(7, $vocabulary->get('weight'));
 }
コード例 #29
0
    /**
     * Tests the Drupal 6 menu to Drupal 8 migration.
     */
    public function testMenu()
    {
        $navigation_menu = Menu::load('navigation');
        $this->assertIdentical('navigation', $navigation_menu->id());
        $this->assertIdentical('Navigation', $navigation_menu->label());
        $expected = <<<EOT
The navigation menu is provided by Drupal and is the main interactive menu for any site. It is usually the only menu that contains personalized links for authenticated users, and is often not even visible to anonymous users.
EOT;
        $this->assertIdentical($expected, $navigation_menu->getDescription());
        // Test that we can re-import using the ConfigEntityBase destination.
        Database::getConnection('default', 'migrate')->update('menu_custom')->fields(array('title' => 'Home Navigation'))->condition('menu_name', 'navigation')->execute();
        $migration = Migration::load('menu');
        \Drupal::database()->truncate($migration->getIdMap()->mapTableName())->execute();
        $this->executeMigration($migration);
        $navigation_menu = Menu::load('navigation');
        $this->assertIdentical('Home Navigation', $navigation_menu->label());
    }
コード例 #30
0
ファイル: MigrateManifest.php プロジェクト: Wylbur/eight
 /**
  * Drush execution method. Runs imports on the supplied manifest.
  */
 public function import()
 {
     /** @var \Drupal\migrate\MigrateTemplateStorage $template_storage */
     $template_storage = \Drupal::service('migrate.template_storage');
     $this->setupLegacyDb();
     $migration_ids = [];
     $migrations = [];
     foreach ($this->migrationList as $migration_info) {
         if (is_array($migration_info)) {
             // The migration is stored as the key in the info array.
             $migration_id = key($migration_info);
         } else {
             // If it wasn't an array then the info is just the migration_id.
             $migration_id = $migration_info;
         }
         $migration_ids[] = $migration_id;
         $template = $template_storage->getTemplateByName($migration_id) ?: [];
         if (is_array($migration_info)) {
             // If there is some existing global overrides then we merge them in.
             if (isset($GLOBALS['config'][$migration_id])) {
                 $migration_info = NestedArray::mergeDeep($GLOBALS['config'][$migration_id], $migration_info);
             }
             $migration_info = NestedArray::mergeDeep($template, $migration_info);
         } else {
             $migration_info = $template;
         }
         if ($migration_info && !Migration::load($migration_id)) {
             $migration = Migration::create($migration_info);
             $migration->save();
         }
     }
     // Load all the migrations at once so they're correctly ordered.
     foreach (entity_load_multiple('migration', $migration_ids) as $migration) {
         $executable = $this->executeMigration($migration);
         // Store all the migrations for later.
         $migrations[$migration->id()] = array('executable' => $executable, 'migration' => $migration, 'source' => $migration->get('source'), 'destination' => $migration->get('destination'));
     }
     // Warn the user if any migrations were not found.
     $nonexistent_migrations = array_diff($migration_ids, array_keys($migrations));
     if (count($nonexistent_migrations) > 0) {
         drush_log(dt('The following migrations were not found: !migrations', array('!migrations' => implode(', ', $nonexistent_migrations))), 'warning');
     }
     return $migrations;
 }