how to go from non-drupal to drupal 8 - bixal · installing drupal 8 with drupal-composer ......
Post on 25-May-2018
314 Views
Preview:
TRANSCRIPT
How to go from non-Drupal to Drupal 8
The API migration route
About me• Drupal developer
• Web developer since 2007
• Drupal for about 4 years
• Bixal
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
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
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
Migrate API• Even though still experimental,
Migrate API is very powerful
• 4 key components: id, source, process, destination
• YAML-based
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
Source plugins• SQL
• URL (json, xml, soap)
• CSV (migrate_source_csv)
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!
Drupal Console• Awesome tool
• Must have for D8 development in general
• https://drupalconsole.com/
And… Symfony Console !• The seed of Drupal Console
• A lot of similarities of course
$ bin/console
Symfony Console
Hands on !
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
Symfony demo
This is what the Symfony blog application looks like
Creating a new controller in Symfony
$ bin/console generate:controller
generate:controller
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); }
Use JMSSerializerBundle to serialize Objects and then expose as json
http://jmsyst.com/bundles/JMSSerializerBundle
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; } }
Go to your new route !
You can use postman too
Installing DrupalInstalling Drupal 8 with drupal-composer
$ composer create-project drupal-composer/drupal-project:8.x-dev some-dir --stability dev --no-interaction
composer create-project
Creating our content type
Enable migrate API by installing the migrate module
$ drupal module:install migrate
Download and enable additional contributed modules
$ composer require drupal/migrate_plus $ drupal module:install migrate_tools
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
generate:module
Create your migrate config folder structure
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
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
Create your yaml config import file: destination
destination: plugin: entity:node
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
Creating a migrate dateprocess plugin
drupal generate:plugin:migrate:process
generate:plugin:migrate:process
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; } }
Demo !Enabling modules and performing the migration
Bonus demo !You can rule the Galaxy with this new power!
Questions?
Thank You!
• d.o. g3r4
• twitter @_g3r4
• gerardo.maldonado@bixal.com
top related