how to go from non-drupal to drupal 8 - bixal · installing drupal 8 with drupal-composer ......

42
How to go from non-Drupal to Drupal 8 The API migration route

Upload: duongtu

Post on 25-May-2018

307 views

Category:

Documents


8 download

TRANSCRIPT

Page 1: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

How to go from non-Drupal to Drupal 8

The API migration route

Page 2: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

About me• Drupal developer

• Web developer since 2007

• Drupal for about 4 years

• Bixal

Page 3: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Some issues• Legacy systems

• Firewalls and or VPNs

• Very complex database architecture

• No permission to access

• Old databases and database engines

• Not even having a database!

• Content/data housed in different systems/places

Page 4: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Because of all of these !4th Dimension HSQLDB OracleAdabas D IBM DB2 Oracle Rdb for OpenVMSAlpha Five IBM Lotus Approach PanoramaApache Derby IBM DB2 Express-C Pervasive PSQLAster Data Infobright PolyhedraAmazon Aurora Informix PostgreSQLAltibase Ingres Postgres Plus Advanced ServerCA Datacom InterBase Progress SoftwareCA IDMS InterSystems Caché RDM EmbeddedClarion LibreOffice Base RDM ServerClickHouse Linter R:BaseClustrix MariaDB SAND CDBMSCSQL MaxDB SAP HANACUBRID MemSQL SAP Sybase Adaptive Server EnterpriseDataEase Microsoft Access SAP Sybase IQDatabase Management Library Microsoft Jet Database Engine SQL AnywhereDataphor Microsoft SQL Server ScimoreDBdBase Microsoft SQL Server Express solidDBDerby aka Java DB SQL Azure (Cloud SQL Server) SQLBaseEmpress Embedded Database Microsoft Visual FoxPro SQLiteEXASolution Mimer SQL SQream DBEnterpriseDB MonetDB Sybase Advantage Database ServereXtremeDB mSQL TeradataFileMaker Pro MySQL TiberoFirebird Netezza TimesTenFrontBase NexusDB TrafodionGoogle Fusion Tables NonStop SQL txtSQLGreenplum NuoDB Unisys RDMS 2200GroveSite Openbase UniDataH2 OpenLink Virtuoso (Open Source Edition) UniVerseHelix database OpenLink Virtuoso Universal Server Vectorwise

OpenOffice.org Base Vertica

Page 5: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

This is not a “use in any situation” method

• Every situation needs to be analyzed

• Migration from a DB dump might be better

• Migration from CSV might be better

• Always assess the situation

Page 6: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Migrate API• Even though still experimental,

Migrate API is very powerful

• 4 key components: id, source, process, destination

• YAML-based

Page 7: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Migrate API contributed modules

• Migrate Plus: Migration groups, more source, process and destination plugins, examples !

• Migrate Tools: Drush commands: migrate-status, migrate-import, migrate-rollback, migrate-stop, and a few others

Page 8: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Source plugins• SQL

• URL (json, xml, soap)

• CSV (migrate_source_csv)

Page 9: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Process plugins• Process plugin: get

• Constant values

• Process plugin (abstract): dedupebase

• Process plugin: addressfield (d7 addressfield to d8 address)

• Process plugin: callback

• Process plugin: concat

• Process plugin: dedupe_entity

• Process plugin: default_value

• Process plugin: explode

• Process plugin: extract

• Process plugin: flatten

• Process plugin: geofield_latlon (custom lat & lon data to d8 geofield)

• Process plugin: geofield_latlon (d7 geofield to d8 geofield)

• Process plugin: iterator

• Process plugin: machine_name

• Process plugin: menu_link_parent

• Process plugin: migration

• Process plugin: route

• Process plugin: skip_on_empty

• Process plugin: skip_row_if_not_set

• Process plugin: static map

• Process plugin: substr

• Your own process plugin!

Page 10: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Drupal Console• Awesome tool

• Must have for D8 development in general

• https://drupalconsole.com/

Page 11: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

And… Symfony Console !• The seed of Drupal Console

• A lot of similarities of course

$ bin/console

Page 12: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Symfony Console

Page 13: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Hands on !

Page 14: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Installing Symfony demo blog app

• Installing Symfony first

$ sudo mkdir -p /usr/local/bin $ sudo curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony $ sudo chmod a+x /usr/local/bin/symfony

• Installing Demo application

$ symfony demo

Page 15: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Symfony demo

Page 16: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

This is what the Symfony blog application looks like

Page 17: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Creating a new controller in Symfony

$ bin/console generate:controller

Page 18: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

generate:controller

Page 19: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Modifying AppBundle\Entity\Post.php Class

• use \JsonSerializable;

• class Post implements JsonSerializable

//function called when encoded with json_encode public function jsonSerialize() { return get_object_vars($this); }

Page 20: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Use JMSSerializerBundle to serialize Objects and then expose as json

http://jmsyst.com/bundles/JMSSerializerBundle

Page 21: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Modifying JsonBlogController.php

class JsonBlogController extends Controller { /** * @Route("/blog", name="json_blog") */ public function jsonBlogAction() { $json_posts = $this->getDoctrine()->getRepository(Post::class)->findAll();

$serializer = $this->get('jms_serializer'); $json_response = $serializer->serialize(array('data' => $json_posts),'json');

$response = new Response(); $response->setContent($json_response); $response->headers->set('Content-Type', 'application/json');

return $response; } }

Page 22: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Go to your new route !

Page 23: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

You can use postman too

Page 24: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Installing DrupalInstalling Drupal 8 with drupal-composer

$ composer create-project drupal-composer/drupal-project:8.x-dev some-dir --stability dev --no-interaction

Page 25: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

composer create-project

Page 26: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Creating our content type

Page 27: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Enable migrate API by installing the migrate module

$ drupal module:install migrate

Page 28: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Download and enable additional contributed modules

$ composer require drupal/migrate_plus $ drupal module:install migrate_tools

Page 29: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Creating a new migrate module

$ drupal generate:module --module="Migrate from Symfony" --machine-name="migrate_from_symfony" --module-path="/modules/custom" --description="This module migrates from an endpoint on symfony" --core="8.x" --package="Custom" --module-file --composer

Page 30: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

generate:module

Page 31: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Create your migrate config folder structure

Page 32: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Create your yaml config import file: source

dependencies: module: - node enforced: module: - migrate_from_symfony id: symfony_posts migration_group: blog source: plugin: url data_fetcher_plugin: http data_parser_plugin: json urls: http://symfony.govcon/en/json/blog item_selector: data

Page 33: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Create your yaml config import file: source fields

fields: - name: id label: "Id" selector: id - name: title label: "Title" selector: title - name: slug label: "Slug" selector: slug - name: summary label: "Summary" selector: summary - name: content label: "Content" selector: content - name: date label: "Date" selector: /publishedAt/date ids: id: type: integer

Page 34: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Create your yaml config import file: destination

destination: plugin: entity:node

Page 35: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Create your yaml config import file: process

process:

type: plugin: default_value default_value: symfony_blog_post

nid: id

langcode: plugin: default_value default_value: en

title: title

'body/value': content 'body/format': plugin: default_value default_value: basic_html

created: plugin: date_to_timestamp source: date

changed: plugin: date_to_timestamp source: date

uid: plugin: default_value default_value: 1

Page 36: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Creating a migrate dateprocess plugin

drupal generate:plugin:migrate:process

Page 37: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

generate:plugin:migrate:process

Page 38: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

DateToTimeStamp.phpnamespace Drupal\migrate_from_symfony\Plugin\migrate\process;

use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Row;

/** * Provides a 'DateToTimestamp' migrate process plugin. * * @MigrateProcessPlugin( * id = "date_to_timestamp" * ) */ class DateToTimestamp extends ProcessPluginBase {

/** * {@inheritdoc} */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { $timestamp = strtotime($value); return $timestamp; } }

Page 39: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Demo !Enabling modules and performing the migration

Page 40: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Bonus demo !You can rule the Galaxy with this new power!

Page 41: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Questions?

Page 42: How to go from non-Drupal to Drupal 8 - Bixal · Installing Drupal 8 with drupal-composer ... namespace Drupal\migrate_from_symfony\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase;

Thank You!

• d.o. g3r4

• twitter @_g3r4

[email protected]