-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LOYALIST-58 Boilerplate for migration
- Loading branch information
1 parent
940fee6
commit 14bee3f
Showing
6 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...alist_migrate/config/install/migrate_plus.migration.0_loyalist_migrate_loyalist_items.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
80 changes: 80 additions & 0 deletions
80
custom/modules/loyalist_migrate/src/Plugin/migrate/source/LoyalistItem.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters