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

  • Published on
    25-May-2018

  • View
    222

  • Download
    7

Embed Size (px)

Transcript

<ul><li><p>How to go from non-Drupal to Drupal 8</p><p>The API migration route</p></li><li><p>About me Drupal developer</p><p> Web developer since 2007</p><p> Drupal for about 4 years</p><p> Bixal</p></li><li><p>Some issues Legacy systems</p><p> Firewalls and or VPNs</p><p> Very complex database architecture</p><p> No permission to access</p><p> Old databases and database engines</p><p> Not even having a database!</p><p> Content/data housed in different systems/places</p></li><li><p>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</p><p>OpenOffice.org Base Vertica</p></li><li><p>This is not a use in any situation method</p><p> Every situation needs to be analyzed</p><p> Migration from a DB dump might be better</p><p> Migration from CSV might be better</p><p> Always assess the situation</p></li><li><p>Migrate API Even though still experimental, </p><p>Migrate API is very powerful</p><p> 4 key components: id, source, process, destination</p><p> YAML-based</p></li><li><p>Migrate API contributed modules</p><p> Migrate Plus: Migration groups, more source, process and destination plugins, examples !</p><p> Migrate Tools: Drush commands: migrate-status, migrate-import, migrate-rollback, migrate-stop, and a few others</p></li><li><p>Source plugins SQL</p><p> URL (json, xml, soap)</p><p> CSV (migrate_source_csv)</p></li><li><p>Process plugins Process plugin: get</p><p> Constant values</p><p> Process plugin (abstract): dedupebase</p><p> Process plugin: addressfield (d7 addressfield to d8 address)</p><p> Process plugin: callback</p><p> Process plugin: concat</p><p> Process plugin: dedupe_entity</p><p> Process plugin: default_value</p><p> Process plugin: explode</p><p> Process plugin: extract</p><p> Process plugin: flatten</p><p> Process plugin: geofield_latlon (custom lat &amp; lon data to d8 geofield)</p><p> Process plugin: geofield_latlon (d7 geofield to d8 geofield)</p><p> Process plugin: iterator</p><p> Process plugin: machine_name</p><p> Process plugin: menu_link_parent</p><p> Process plugin: migration</p><p> Process plugin: route</p><p> Process plugin: skip_on_empty</p><p> Process plugin: skip_row_if_not_set</p><p> Process plugin: static map</p><p> Process plugin: substr</p><p> Your own process plugin!</p></li><li><p>Drupal Console Awesome tool</p><p> Must have for D8 development in general</p><p> https://drupalconsole.com/</p></li><li><p>And Symfony Console ! The seed of Drupal Console</p><p> A lot of similarities of course </p><p>$ bin/console</p></li><li><p>Symfony Console</p></li><li><p>Hands on !</p></li><li><p>Installing Symfony demo blog app</p><p> Installing Symfony first</p><p>$ 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</p><p> Installing Demo application</p><p>$ symfony demo</p></li><li><p>Symfony demo</p></li><li><p>This is what the Symfony blog application looks like</p></li><li><p>Creating a new controller in Symfony</p><p>$ bin/console generate:controller</p></li><li><p>generate:controller</p></li><li><p>Modifying AppBundle\Entity\Post.php Class</p><p> use \JsonSerializable;</p><p> class Post implements JsonSerializable</p><p>//function called when encoded with json_encode public function jsonSerialize() { return get_object_vars($this); }</p></li><li><p>Use JMSSerializerBundle to serialize Objects and then expose as json</p><p>http://jmsyst.com/bundles/JMSSerializerBundle</p><p>http://jmsyst.com/bundles/JMSSerializerBundle</p></li><li><p>Modifying JsonBlogController.php</p><p>class JsonBlogController extends Controller { /** * @Route("/blog", name="json_blog") */ public function jsonBlogAction() { $json_posts = $this-&gt;getDoctrine()-&gt;getRepository(Post::class)-&gt;findAll(); </p><p> $serializer = $this-&gt;get('jms_serializer'); $json_response = $serializer-&gt;serialize(array('data' =&gt; $json_posts),'json'); </p><p> $response = new Response(); $response-&gt;setContent($json_response); $response-&gt;headers-&gt;set('Content-Type', 'application/json'); </p><p> return $response; } } </p></li><li><p>Go to your new route !</p></li><li><p>You can use postman too</p></li><li><p>Installing DrupalInstalling Drupal 8 with drupal-composer</p><p>$ composer create-project drupal-composer/drupal-project:8.x-dev some-dir --stability dev --no-interaction </p></li><li><p>composer create-project</p></li><li><p>Creating our content type</p></li><li><p>Enable migrate API by installing the migrate module</p><p>$ drupal module:install migrate </p></li><li><p>Download and enable additional contributed modules</p><p>$ composer require drupal/migrate_plus $ drupal module:install migrate_tools </p></li><li><p>Creating a new migrate module</p><p>$ 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</p></li><li><p>generate:module</p></li><li><p>Create your migrate config folder structure</p></li><li><p>Create your yaml config import file: source</p><p>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 </p></li><li><p>Create your yaml config import file: source fields</p><p>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 </p></li><li><p>Create your yaml config import file: destination</p><p>destination: plugin: entity:node </p></li><li><p>Create your yaml config import file: process</p><p>process: </p><p> type: plugin: default_value default_value: symfony_blog_post </p><p> nid: id </p><p> langcode: plugin: default_value default_value: en </p><p> title: title </p><p> 'body/value': content 'body/format': plugin: default_value default_value: basic_html </p><p> created: plugin: date_to_timestamp source: date </p><p> changed: plugin: date_to_timestamp source: date </p><p> uid: plugin: default_value default_value: 1 </p></li><li><p>Creating a migrate dateprocess plugin</p><p>drupal generate:plugin:migrate:process</p></li><li><p>generate:plugin:migrate:process</p></li><li><p>DateToTimeStamp.phpnamespace Drupal\migrate_from_symfony\Plugin\migrate\process; </p><p>use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Row; </p><p>/** * Provides a 'DateToTimestamp' migrate process plugin. * * @MigrateProcessPlugin( * id = "date_to_timestamp" * ) */ class DateToTimestamp extends ProcessPluginBase { </p><p> /** * {@inheritdoc} */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { $timestamp = strtotime($value); return $timestamp; } } </p></li><li><p>Demo !Enabling modules and performing the migration</p></li><li><p>Bonus demo !You can rule the Galaxy with this new power!</p></li><li><p>Questions?</p></li><li><p>Thank You!</p><p> d.o. g3r4</p><p> twitter @_g3r4</p><p> gerardo.maldonado@bixal.com</p>mailto:gerardo.maldonado@bixal.com</li></ul>