Skip to content

Commit

Permalink
Update the group migration to migrate into taxonomy term and to migra…
Browse files Browse the repository at this point in the history
…te group members from memberships

Ref #462 #448
  • Loading branch information
Keegan Rankin committed Aug 5, 2024
1 parent 50bed2e commit 47661bd
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,44 @@ migration_tags:
migration_group: pece
label: 'Migrate Group'
source:
plugin: v1_node
plugin: v1_group_node
node_type: pece_group
process:
nid: nid
vid: vid
uid: node_uid
title: title
type:
# nid: nid
name: title
vid:
plugin: default_value
default_value: group
path/pathauto:
plugin: default_value
default_value: 0
path/alias: alias
body/format:
plugin: default_value
default_value: html
body/value:
plugin: extract
source: body
index:
- 0
- value
default: ''
body/summary:
plugin: extract
source: body
index:
- 0
- summary
default: ''
field_pece_geolocation: locations
field_group_subst_logic: field_pece_substantive_logic
default_value: groups
# uid: node_uid
# title: title
# type:
# plugin: default_value
# default_value: group
# path/pathauto:
# plugin: default_value
# default_value: 0
# path/alias: alias
# body/format:
# plugin: default_value
# default_value: html
# body/value:
# plugin: extract
# source: body
# index:
# - 0
# - value
# default: ''
# body/summary:
# plugin: extract
# source: body
# index:
# - 0
# - summary
# default: ''
# field_pece_geolocation: locations
field_substantive_logic: field_pece_substantive_logic
field_group_members: d7_group_members
destination:
plugin: 'entity_complete:node'
plugin: 'entity:taxonomy_term'
translations: true
migration_dependencies: null
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* @file
* Contains \Drupal\pece_migrate\Plugin\migrate\source\GroupNode.
*/
namespace Drupal\pece_migrate\Plugin\migrate\source;
// use Drupal\migrate\Row;

use Drupal\migrate\Row;
use Drupal\node\Plugin\migrate\source\d7\NodeComplete as D7Node;
// use Drupal\Tests\Component\Annotation\Doctrine\Ticket\Doctrine\ORM\Entity;
// use Exception;

/**
* Gets all node revisions from the source, including translation revisions.
*
* @MigrateSource(
* id = "v1_group_node",
* source_module = "node"
* )
*/
class GroupNode extends D7Node {

const ROLE_RESEARCHER = 'researcher';
const ROLE_CONTRIBUTOR = 'contributor';

protected $groupMembers = [];

/**
* {@inheritdoc}
*/
public function fields() {
$fields = parent::fields() + ['alias' => $this->t('Path alias')];
$fields += ['d7_group_members' => $this->t('Group members')];
// $fields += ['permission_by_group_view' => $this->t('Permission by group')];
// $fields += ['permission_by_user_view' => $this->t('Permission by user')];
// $fields += ['permission_by_role_view' => $this->t('Permission by role')];
// $fields += ['permission_all_user_view' => $this->t('Permission for all users')];
return $fields;
}

public function prepareRow(Row $row) {
$gid = $row->getSourceProperty('nid');

// Query to get user IDs based on group membership.
$subquery = $this->select('og_membership', 'ogm')
->fields('ogm', array('etid'))
->condition('ogm.entity_type', 'user')
->condition('ogm.gid', $gid);

// Get all users who are members of group
$users = $this->select('users', 'u')
->fields('u', array('uid'))
->condition('u.uid', $subquery, 'IN')
->execute()
->fetchCol();

foreach ($users as $key => $item) {
$this->groupMembers[] = [
'target_id' => $item
];
}

$row->setSourceProperty('d7_group_members', $this->groupMembers);
$this->groupMembers = [];
}
}

0 comments on commit 47661bd

Please sign in to comment.