Migrating from Ghost CMS to Drupal Using the Migration Suite

Migrating from Ghost CMS to Drupal Using the Migration Suite

Migrating from one CMS to another can be a daunting task, especially when dealing with different data structures and functionalities. However, Drupal’s powerful Migration Suite simplifies the process, making it more streamlined and efficient. In this article, we’ll walk you through the steps to migrate from Ghost CMS to Drupal, using JSON data directly, complete with a practical code example.

Why Migrate to Drupal?

Drupal offers a robust and flexible framework for building sophisticated websites. It is highly customizable, secure, and scalable, making it a preferred choice for many organizations. If you’re considering moving from Ghost CMS to Drupal, you’re on the right path to leverage a more versatile platform.

Prerequisites

Before you begin, ensure you have the following:

  • A Drupal 9 or 10 installation.
  • Composer installed on your local machine.
  • Access to your Ghost CMS data in JSON format.

Step-by-Step Migration Guide

1. Set Up Your Drupal Environment

First, make sure your Drupal environment is set up and ready. Install the necessary migration modules using Composer:

composer require drupal/migrate_tools drupal/migrate_plus        

Enable the modules:

drush en migrate_tools migrate_plus        


2. Export Your Ghost CMS Data

Export your Ghost CMS data into a JSON format. Ghost provides an export feature that outputs your data in JSON, which we'll use for the migration process.

3. Create a Migration Module

Create a custom migration module in Drupal. In your modules/custom directory, create a folder named ghost_migration and inside it, create the following files:

  • ghost_migration.info.yml
  • ghost_migration.install
  • migrations/ghost_migration_content.yml
  • src/Plugin/migrate/source/GhostJson.php

ghost_migration.info.yml

name: 'Ghost Migration'
type: module
description: 'Migrate content from Ghost CMS to Drupal.'
core_version_requirement: ^9 || ^10
package: Custom
dependencies:
  - migrate_tools
  - migrate_plus
        


ghost_migration.install

<?php

/**
 * Implements hook_install().
 */
function ghost_migration_install() {
  \Drupal::service('plugin.manager.migration')->createInstance('ghost_migration_content')->import();
}
        

4. Define the Migration Source Plugin

Create the migration source plugin file: src/Plugin/migrate/source/GhostJson.php.

src/Plugin/migrate/source/GhostJson.php

<?php

namespace Drupal\ghost_migration\Plugin\migrate\source;

use Drupal\migrate\MigrateException;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\MigrateSourceInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row;
use Drupal\migrate_source_json\Plugin\migrate\source\Json;

/**
 * Source plugin for retrieving data from a Ghost JSON file.
 *
 * @MigrateSource(
 *   id = "ghost_json"
 * )
 */
class GhostJson extends Json {

  /**
   * {@inheritdoc}
   */
  public function prepareRow(Row $row) {
    // Process the row data if needed.
    return parent::prepareRow($row);
  }
}
        


5. Define the Migration Configuration

Create the migration configuration file: migrations/ghost_migration_content.yml.

migrations/ghost_migration_content.yml

id: ghost_migration_content
label: 'Ghost CMS to Drupal Content Migration'
migration_group: default
source:
  plugin: ghost_json
  data_fetcher_plugin: file
  data_parser_plugin: json
  item_selector: '/posts'
  path: 'modules/custom/ghost_migration/data/ghost_content.json'
  ids:
    - id
process:
  title: title
  body/value: markdown
  body/format:
    plugin: default_value
    default_value: 'basic_html'
  created:
    plugin: callback
    callable: strtotime
    source: published_at
destination:
  plugin: entity:node
  default_bundle: article
dependencies: {  }
        


6. Prepare Your Data

Place your JSON data file in the data folder inside your custom module directory (modules/custom/ghost_migration/data/ghost_content.json).

7. Run the Migration

Use Drush to run the migration:

drush migrate-import ghost_migration_content        


This command will import your content from the Ghost CMS JSON file into Drupal as nodes of type 'article'.

Conclusion

Migrating from Ghost CMS to Drupal using the Migration Suite is a straightforward process when broken down into manageable steps. By leveraging JSON data directly, we can efficiently move content and maintain the integrity of the data. Follow this guide to ensure a smooth transition and start enjoying the benefits of Drupal’s robust platform.

Feel free to reach out if you have any questions or need further assistance with your Drupal migration projects.

Deepesh Arora

Sr. Software Engineer at Srijan Technologies Drupal 7, 8,9 10

8 个月

Informative

回复

要查看或添加评论,请登录

Lakshman Kumar Pandey的更多文章

社区洞察

其他会员也浏览了