Skip to content

Instantly share code, notes, and snippets.

@neclimdul
Created September 27, 2018 17:31
Show Gist options
  • Save neclimdul/f16220aac76e25beba8e0fe97c12b40f to your computer and use it in GitHub Desktop.
Save neclimdul/f16220aac76e25beba8e0fe97c12b40f to your computer and use it in GitHub Desktop.
d6_node_flag
id: d6_flags
label: D6 Flag Migration
source:
plugin: d6_flag_bookmarks
constants:
dest_type: node
flag_id: resource_content_flag
global: 0
process:
id: fcid
flag_id: 'constants/flag_id'
entity_type: 'constants/dest_type'
global: 'constants/global'
entity_id:
plugin: migration_lookup
migration: d6_node
source: content_id
uid:
plugin: migration_lookup
migration: d6_user
source: uid
destination:
plugin: entity:flagging
migration_dependencies:
required:
- d6_user
- d6_node
<?php
namespace Drupal\my_migration\Plugin\migrate\source;
use Drupal\migrate\Plugin\migrate\source\SqlBase;
/**
* Migrate flags from d6 -> d8.
*
* @MigrateSource(
* id = "d6_flag_bookmarks",
* source_module = "flag"
* )
*/
class D6FlagBookmarks extends SqlBase {
/**
* {@inheritdoc}
*/
public function fields() {
return [
'fcid' => $this->t('Flag id id'),
'content_id' => $this->t('Content(node) id'),
'uid' => $this->t('Flagging user'),
'timestamp' => $this->t('timestamp of the flag'),
];
}
/**
* {@inheritdoc}
*/
public function getIds() {
return [
'fcid' => [
'type' => 'integer',
],
];
}
/**
* @return \Drupal\Core\Database\Query\SelectInterface
*/
public function query() {
$query = $this->select('flag_content', 'f');
$query->fields('f', [
'fcid',
'content_id',
'uid',
'timestamp'
]);
$query->orderBy('fcid', 'asc');
$query->join('node', 'n', 'n.nid = f.content_id');
if ($this->configuration['content_type']) {
$query->where('n.type = :content_type', [
'content_type' => $this->configuration['content_type'],
]);
}
return $query;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment