Skip to content

Commit

Permalink
LOYALIST-58 Boilerplate for migration
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobSanford committed Jul 11, 2024
1 parent 940fee6 commit 14bee3f
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 0 deletions.
10 changes: 10 additions & 0 deletions build/settings/settings.local.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@
*/

require_once DRUPAL_ROOT . '/sites/example.settings.local.php';

$databases['migrate']['default'] = array (
'database' => 'loyalist',
'username' => 'root',
'password' => 'import',
'host' => 'mysqlimport',
'port' => '3306',
'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
'driver' => 'mysql',
);
19 changes: 19 additions & 0 deletions custom/modules/loyalist_migrate/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "drupal/bnald_core",
"type": "drupal-module",
"description": "Migrate Loyalist content to Drupal 10",
"keywords": [
"Drupal"
],
"license": "GPL-2.0+",
"homepage": "https://www.drupal.org/project/loyalist_migrate",
"minimum-stability": "dev",
"support": {
"issues": "https://www.drupal.org/project/issues/loyalist_migrate",
"source": "http://cgit.drupalcode.org/loyalist_migrate"
},
"require": {
"drupal/migrate_tools": "^6",
"drupal/migrate_plus": "^6"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
id: 0_loyalist_migrate_loyalist_items
label: 'Loyalist Item'

migration_tags:
- Loyalist
- SQL

source:
plugin: loyalist_item
key: migrate
process:
title: title
field_accompanying_record: field_accompanying_record_value
field_issuing_body:
-
plugin: entity_generate
source: issuing_body_name
entity_type: taxonomy_term
bundle_key: vid
bundle: issuing_body
value_key: name

destination:
plugin: 'entity:node'
default_bundle: loyalist_record
9 changes: 9 additions & 0 deletions custom/modules/loyalist_migrate/loyalist_migrate.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: 'Loyalist Migration'
type: module
description: 'Migrate Loyalist content to Drupal 10.'
core_version_requirement: ^10
package: Migration
dependencies:
- migrate:migrate
- migrate_plus:migrate_plus
- migrate_tools:migrate_tools
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace Drupal\loyalist_migrate\Plugin\migrate\source;

use Drupal\migrate\Annotation\MigrateSource;
use Drupal\migrate\Plugin\migrate\source\SqlBase;
use Drupal\migrate\Row;

/**
* Migrates Loyalist Items.
*
* @MigrateSource(
* id = "loyalist_item",
* source_module = "loyalist_migrate",
* )
*/
class LoyalistItem extends SqlBase
{
/**
* {@inheritdoc}
*/
public function query()
{
$query = $this->select('node', 'n');
$query->condition('n.type', 'loyalist_record');
$query->join('field_data_field_accompanying_record', 'fac', 'n.nid = fac.entity_id AND fac.deleted = 0');
$query->join('field_data_field_issuing_body', 'fib', 'n.nid = fib.entity_id AND fib.deleted = 0');
$query->join('taxonomy_term_data', 'ttd', 'fib.field_issuing_body_tid = ttd.tid');

$query->addField('n', 'nid', 'nid');
$query->addField('n', 'title', 'title');
$query->addField('fac', 'field_accompanying_record_value', 'field_accompanying_record_value');
$query->addField('ttd', 'name', 'issuing_body_name');
return $query;
}

/**
* {@inheritdoc}
*/
public function fields()
{
// This maps the field from their name above to a destination field name that is specified in the process section. I generally keep them the same.
$fields = [
'title' => 'title',
'field_accompanying_record_value' => 'field_accompanying_record_value',
'issuing_body_name' => 'issuing_body_name',
];
return $fields;
}

/**
* {@inheritdoc}
*/
public function getIds()
{
return [
'nid' => [
'type' => 'integer',
'alias' => 'n',
],
];
}

/**
* {@inheritdoc}
*/
public function prepareRow(Row $row)
{
/*
Example of how to manipulate data using prepareRow.
We should generally use process plugins in the yaml definition instead.
$date = $row->getSourceProperty('date');
$time = $row->getSourceProperty('time');
$datetime = $date . 'T' . $time . ':00';
$row->setSourceProperty('datetime', $datetime);
*/
return parent::prepareRow($row);
}
}
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ services:
- "4113:8025"
networks:
- loyalist.lib.unb.ca
mysqlimport:
image: mysql:5.7
expose:
- "3306"
environment:
MYSQL_ROOT_PASSWORD: import
MYSQL_DATABASE: loyalist
networks:
- loyalist.lib.unb.ca
volumes:
- ./loyalist.sql:/docker-entrypoint-initdb.d/loyalist.sql
networks:
loyalist.lib.unb.ca:
name: loyalist.lib.unb.ca
Expand Down

0 comments on commit 14bee3f

Please sign in to comment.