terça-feira, 7 de dezembro de 2021

How to migrate large ammount of data from Drupal 7 to Drupal 9 (or Drupal 8)

Everyone who works with development of websites faces with a common challenge of keeping the code updated. With Drupal it´s the same. Drupal 7 was widely used for several companies and institutions. Then Drupal 8 came with innovations and different ways of working using composer and symfony. Drupal 8 themes also changed they way it is built using twig templates. Now we are facing with Drupal 9 which improved the performance of the CMS and brings to the developer a better experience, clean code and more secure system. 

So, now we need to plan how to migrate a large ammount of data from a Drupal 7 to Drupal 9, ok? But, we all know that many modules that were used in Drupal 7 were not updated to Drupal 9. Also, the software architecture are not the same. 

Anyway, the first migration test were made using Migrate Drupal UI module. But, as expected, the migration didn´t work well because our Drupal Websites were built using a bunch of modules that are not compatible with Drupal 9. So, many data were not migrated. 

The second and best solution were plan the migration using views to export a JSON content and Feed Importer. Basically, the solution to export the content could also work well using Views Data Export using CSV or XML. But as I´m planning to work with JSON to spread data into multiple websites in my work I decided to use Views Data Export - JSON Support.
Step 1) Copy the taxonomy if it exist 

 - the first step was to export the taxonomy structure using views data export with CSV format (Drupal 7)
- Next step was to import the taxonomy structure using Taxonomy import (Drupal 9) 

 Step 2) Export the content in JSON format using Views Data Export - JSON Support 

 This seconde step was to prepare the JSON structure in Drupal 7 website. I have created a single view with data export format and configured to export JSON format. The fields were set with lowcase letters and no accent. Also, the images path and file path were set as a field. The body content were set to export in html format. This way, the solution to migrate the all the files was to copy the /files folder into the new drupal 9 website. This way, the path were kept the same. After finished the view with data export and set the URL to access it, we are able to download the content. 

Step 3) Create the content types in Drupal 9 structure 

In this step I have prepared the content type with the necessary fields and body content with full html set. We have created simple fields and also paragrapth fields. 

Step 4) Set the Feed Import module in Drupal 9 website 

This final step is related to the feed module which allows data to be importer. In this step, I have tried to import all the data from a specific content type in Drupal 7 but it was so much content that it caused a timeout error. So I decided to migrate data per year. But it also caused an error because of the large ammount of data. This way I download the JSON data first, instead of accessing the data from a URL. The first migration were done with 637 nodes from the year of 2020. After that I just checked with the files and images were copied into the Drupal 9 instance with the root folder /files. 

Step 5) Don´t forget to clean cache, rebuilt and refresh the database. Using drush you can do it easily. 

If you have experienced troubles during the migration of content from Drupal 7 to Drupal 9, don´t hesitate to contact me. My e-mail is keyneskanno at gmail dot com. Have a lot of fun!

Nenhum comentário: