Thursday, December 22, 2016

Migration Tutorial: Taxonomy Migration from Drupal 7 to Drupal 8

Taxonomy consists with Vocabulary and Terms.
While migrating Taxonomy Terms we've to consider few basic settings. Like whether our destination database (drupal 8 instance) is already containing some old data or not. Whether we need to rollback post migration ... If we follow migration strategy and develop our code based on that we can easily achieve that.
Here we'll be introduced with dedupe_entity . It's a process plugin with two configuration keys and these are entity_type and field. It'll rename the field value automatically while already exist. This facility is available from Migrate Module. For more detail please refer here.

Here you can find an working example of Taxonomy - Term - Vocabulary migration working copy.
Please refer the Github code for that.

Migration of Vocabulary:
Migration of Vocabulary is done with these files below.
migrate_custom\src\Plugin\migrate\source\Vocabulary.php
migrate_custom\config\install\migrate_plus.migration.custom_taxonomy_vocabulary.yml

Please refer Vocabulary.php for code reference.
In .yml file we'll define four definitions as required i.e. id, source, process, destination.
So the .yml file will look like this -
id: custom_taxonomy_vocabulary
label: Drupal 7 taxonomy vocabularies
migration_group: custom
dependencies:
  enforced:
    module:
      - migrate_custom
source:
  plugin: custom_taxonomy_vocabulary
process:
  vid:
    -
      plugin: machine_name
      source: machine_name
    -
      plugin: dedupe_entity
      entity_type: taxonomy_vocabulary
      field: vid
      length: 32
  label: name
  name: name
  description: description
  hierarchy: hierarchy
  module: module
  weight: weight
destination:
  plugin: entity:taxonomy_vocabulary

Here the significant plugin in process is "dedupe_entity". This Ensures value is not duplicated against an entity field (Taxonomy). If the value is foo and there is already an entity where the field value is foo, then the plugin will return foo1. For more detail please refer core/modules/migrate/src/Plugin/migrate/process/DedupeEntity.php

Migration of Terms:
migrate_custom\src\Plugin\migrate\source\Term.php

migrate_custom\config\install\migrate_plus.migration.custom_taxonomy_term.yml

Here in Term.php we fetch Term data from 'taxonomy_term_data' and do the needful process before setting the source property.
id: custom_taxonomy_term
label: Drupal 7 taxonomy terms
migration_group: custom
dependencies:
  enforced:
    module:
      - migrate_custom
source:
  plugin: custom_taxonomy_term
process:
  tid: tid
  vid:
    plugin: migration
    migration: custom_taxonomy_vocabulary
    source: vid
  name: name
  description: description
  weight: weight
  parent:
#    -
#      plugin: skip_on_empty
#      source: parent
    -
      plugin: migration
      migration: custom_taxonomy_term
  changed: timestamp
destination:
  plugin: entity:taxonomy_term
migration_dependencies:
  required:
    - custom_taxonomy_vocabulary


Tuesday, December 20, 2016

Configuring UBUNTU 14.04 for WWW root directory from /var/www/html to /home/user/Public

This is very very basic topic but still we need this while configure our new Ubuntu system. Our Public profile gets encrypted thats why its more secure to www/html . I always prefer to use Public folder to setup local development website.

We need to follow these steps below to set this.

sudo gedit /etc/apache2/sites-available/000-default.conf

and change these lines
DocumentRoot /var/www/html to DocumentRoot /home/user/Public
Here set "user" accordingly.
Then search for

<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

and change to

<Directory /home/user/Public>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

and save it.
Now restart apache server to get the changes.

sudo service apache2 restart

-- Thats it.