Drupal to Contentstack

In this section, we'll cover the exporter tools that have been built to assist our customers who plan to migrate their existing content from Drupal to Contentstack. By the end of this section, you will be able to perform the migration of your content into Contentstack in an efficient manner.

Step 1 - Export Content from Drupal

The export tool allows you to export content from Drupal using MySQL queries and makes it possible to import it into Contentstack. Using this project, you can easily export Content types (Article, Page, and Custom content types), Users, Tags, and Vocabularies from Drupal that can be later imported into Contentstack.

To do so, you need to perform the steps given below:

  1. Download the exporter utility tool: To export your content from Drupal, you need to first download the exporter utility tool from GitHub. This exporter utility tool consists of modules that will help you to download your content from Drupal and save it in JSON format in your file system. JSON format makes it easier to import data into Contentstack.
  2. Install Node modules: Node.js modules plays an essential part in the effective working of the exporter utility tool. Using Node.js package manager (npm) the essential modules of the exporter utility tool will extract content into your file system.
  3. To install the node modules that are necessary for exporting the content into your file system, open a terminal, navigate to the root folder of the exporter utility tool, and run the command given below:

    npm install
  1. Add configuration details: Before we start extracting our content, we need to make certain changes in the configuration file of the exporter utility tool. So, open the 'index.json' file within the 'config' folder of the exporter utility tool and add the following configuration details:
  2. "host":"<<mysql host>>",
    "user":"<<mysql username>>",
    "password":"<<mysql password>>",
    "database":"<<mysql database of Drupal>>"

    In the above configuration details, you need to provide the MySQL host, username, and password, and also provide the name of the Drupal database content.

    Next, your files and assets need to be available and accessible through the internet. For this purpose, you must define a key named 'drupal_base_url' in the 'index.json' file for the exporter to create it.

    drupal_base_url: http://example_hostname.com

    Also, in order to be able to properly map the Drupal content types to the Contentstack content types, their names should be identical. For example: if the name of a content type in Drupal is 'Blog', then the name of content type in Contentstack should be 'Blog' too.

  1. Export modules After the configuration, you are now ready to export content from Contentstack. On the basis of your requirement, you can either perform a complete export of the content or you can export specific modules via their name or their ID.
    • To export the entire content, run the command given below:
    • npm run export

      This command will extract data of authors, assets, categories, and posts from the downloaded XML file and convert them in JSON files that is supported in Contentstack. These files are stored in the path mentioned in the 'data' key in the 'config/index.js' file.

    • To export specific modules of your content, run the command given below:
    • npm run export {module-name}

      When exporting modules individually, make sure you follow the module sequence as given below, for example, before exporting posts, you must have had exported assets, authors, and categories:

      • query
      • contenttypes
      • assets
      • authors
      • vocabulary
      • taxonomy
      • page
    • Modules that you wish to export separately or those that have failed to export (the details of these modules are recorded in the error log or in the failed.json file) can be installed with the help of their IDs. These IDs will be stored as comma-separated values in the failed.json file.

    Now, to export the modules, you need to provide the absolute path of the file that stores the IDs, when running the following command in a terminal:

    npm run export <<module name>>

    You can find the 'success' and 'error' logs of the export process under libs/utils/logs. The successfully run processes are recorded under 'success' and the processes that face errors will be recorded under 'errors'.

    The logs for failed assets are recorded in 'failed.json' and is stored under the 'master' folder located where your exported data resides.

    Note: The exporter utility tool can be used to extract only the latest published version of an entry.

  1. Copy schema: Copy the 'contentType' folder from your exporter utility folder and place it in the path mentioned in the 'data' key within the 'config/index.js' file. The 'contentType' folder consists of the basic schema of content types which will help you to migrate your data.

The latest published content will be exported in JSON format and stored at the location provided in the 'index.json' configuration file from where you can later import the data into Contentstack.

Limitations of the utility

Some of the limitations of the utility include the following:

  • Currently, this exporter utility supports Drupal version 7 only (migration script for Drupal version 8 will be released soon).
  • When exporting the content from Drupal, the internal links provided within the content will not be updated.

Now, refer the next section to learn how to import the exported content into Contentstack.

Step 2 - Import Content into Contentstack

The exported content is now ready to be imported into  Contentstack. This content will be in JSON format and stored at the location provided in the 'index.json' configuration file from where you can later import the data into Contentstack.

To import the content, follow the steps mentioned in the Import Content into Contentstack document.

Was this article helpful?