-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the group migration to migrate into taxonomy term and to migra…
- Loading branch information
Keegan Rankin
committed
Aug 5, 2024
1 parent
50bed2e
commit 47661bd
Showing
2 changed files
with
102 additions
and
31 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
67 changes: 67 additions & 0 deletions
67
web/profiles/pece/modules/pece_migrate/src/Plugin/migrate/source/GroupNode.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,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 = []; | ||
} | ||
} |