-
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-44 Begin migrate Blog nodes, title/body fields
- Loading branch information
Showing
2 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...yalist_migrate/config/install/migrate_plus.migration.1_loyalist_migrate_loyalist_blog.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,32 @@ | ||
id: 1_loyalist_migrate_loyalist_blog | ||
label: 'Loyalist Blog Posts' | ||
|
||
migration_tags: | ||
- Loyalist | ||
- SQL | ||
|
||
source: | ||
plugin: loyalist_blog | ||
key: migrate | ||
|
||
process: | ||
nid: nid | ||
vid: vid | ||
status: status | ||
created: created | ||
changed: changed | ||
promote: promote | ||
sticky: sticky | ||
title: | ||
plugin: callback | ||
callable: trim | ||
source: title | ||
'body/format': | ||
plugin: default_value | ||
default_value: wysiwyg | ||
'body/value': body_value | ||
'body/summary': body_summary | ||
|
||
destination: | ||
plugin: 'entity:node' | ||
default_bundle: blog_post |
93 changes: 93 additions & 0 deletions
93
custom/modules/loyalist_migrate/src/Plugin/migrate/source/BlogPost.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,93 @@ | ||
<?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 Blog Posts. | ||
* | ||
* @MigrateSource( | ||
* id = "loyalist_blog", | ||
* source_module = "loyalist_migrate", | ||
* ) | ||
*/ | ||
class BlogPost extends SqlBase | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function query() | ||
{ | ||
$query = $this->select('node', 'n'); | ||
$query->condition('n.type', 'blog'); | ||
$query->addField('n', 'nid', 'nid'); | ||
$query->addField('n', 'vid', 'vid'); | ||
$query->addField('n', 'title', 'title'); | ||
$query->addField('n', 'status', 'status'); | ||
$query->addField('n', 'created', 'created'); | ||
$query->addField('n', 'changed', 'changed'); | ||
$query->addField('n', 'promote', 'promote'); | ||
$query->addField('n', 'sticky', 'sticky'); | ||
$query->leftJoin('field_data_body', 'fb', 'n.nid = fb.entity_id AND fb.deleted = 0'); | ||
$query->addField('fb', 'body_value', 'body_value'); | ||
$query->addField('fb', 'body_summary', 'body_summary'); | ||
|
||
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 = [ | ||
'nid' => 'nid', | ||
'vid' => 'vid', | ||
'title' => 'title', | ||
'status' => 'status', | ||
'created' => 'created', | ||
'changed' => 'changed', | ||
'promote' => 'promote', | ||
'sticky' => 'sticky', | ||
'body_value' => 'body_value', | ||
'body_summary' => 'body_summary', | ||
]; | ||
|
||
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); | ||
} | ||
} |