A simple Drupal 7 to Drupal 8 Migration.
With its new prominent features, Drupal 8 will set the standards in terms of offering numerous ways to customise website content, display data on mobile devices and build API’s.
Due to the modern OOP (Object Oriented Programming) approach, it gives us a simpler migration process from its predecessor, with in-place content editing tools, along with a broad array of new themes.
21. class User extends FieldableEntity {
/**
* {@inheritdoc}
*/
public function query() {
return $this->select('users', 'u')
->fields('u')
->condition('u.uid', 0, '>');
}
22.
23. public function fields() {
$fields = [
'uid' => $this->t('User ID'),
'name' => $this->t('Username'),
];
return $fields;
}
User::fields are the source data you can use later in process section of the template.
24. /**
* Drupal 7 user source from database.
*
* @MigrateSource(
* id = "d7_user",
* source_module = "user"
* )
*/
class User extends FieldableEntity {
25. being confident of this, that he who began a
good work in you will carry it on to completion
until the day of Christ Jesus.
26. # mapping using the short notation (implicitly uses get process plugin)
# destination:source
process:
uid: uid
name: name
pass: pass
mail: mail
29. /**
* @MigrateProcessPlugin(
* id = "migration_lookup_neiu_current_vid"
* )
*/
class NeiuCurrentVid extends Get {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row
$row, $destination_property) {
$node = node_load($value);
return $node->getRevisionId();
}
}
30.
31. # syntax
drush migrate-upgrade --configure-only --legacy-root=<website root> --legacy-db-key=<DB
key> --migration-prefix=<Migration Prefix>
Where:
legacy-root is for example http://mywebsite.com
legacy-db-key is your source d6/d7 db export defined in settings.php
migration-prefix is any value that will be used as a prefix for the files generated for migration
32.
33.
34. process:
nid: tnid #remove this line
vid: vid #remove this line
uid:
#migration_lookup is used to get the new uid from a previous user migration
plugin: migration_lookup
migration: hub_d7_user #the migration id of the previous user migration
source: uid
37. 1. Import the source database and define the connections in settings.php
2. Generate the migration template files using migrate_upgrade module:
drush migrate-upgrade --configure-only --legacy-root=<website root> --legacy-db-key=<DB key>
--migration-prefix=<Migration Prefix>
3. Export the migration template files using drush config-export:
drush cex
*** We need to export because it only exists in DB prior to this. Exporting will give the files to edit.
4. Edit/Delete the migration templates files into your config directory as needed.
*** Ideally, you will just be migrating content, users and taxonomy. Configurations/content types can be manually created.
5. Reimport your changes using drush config-import:
drush cim
6. Visit admin/structure/migrate and execute migrations (or rollback) as needed.
Usually migrations are not as desired on the first run and edits to the custom plugin or template must be
made. You can execute rollback and retry. If migration template changes are needed, step 5 must be
executed for template changes to take effect.
38. 1. Migrate Tools contrib module for using drush to execute migrations.
2. Migrate Manifest contrib to group migrations in a manifest file.
3. Using stubs for migrating chicken or egg scenarios.