Skip to content

Commit

Permalink
Issue #3490462: Fix social_group_flexible_group_update_130003 update.
Browse files Browse the repository at this point in the history
  • Loading branch information
rochek03 committed Dec 3, 2024
1 parent f1d838e commit 8820ec9
Showing 1 changed file with 11 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
use Drupal\Core\Config\FileStorage;
use Drupal\group\Entity\GroupInterface;
use Drupal\group\Entity\GroupRoleInterface;
use Drupal\group\GroupMembership;
use Drupal\social_group\Entity\Group;
use Drupal\user\Entity\User;
use Drupal\user\UserInterface;

/**
Expand Down Expand Up @@ -145,39 +142,32 @@ function social_group_flexible_group_update_130002(): void {
* Displays a message about results to user after the update has completed.
*/
function social_group_flexible_group_update_130003(array &$sandbox): string {
if (!isset($sandbox['progress'])) {
$db = \Drupal::database();

// Fetch users with group_admin role that should be updated.
$query = $db->select('group_content__group_roles', 'gcgr');
$query->addField('gcgr', 'entity_id');
$query->addField('grfd', 'entity_id', 'uid');
$query->addField('grfd', 'gid');
$query->condition('gcgr.group_roles_target_id', 'flexible_group-group_admin');
$storage = \Drupal::entityTypeManager()->getStorage('group_content');

$query->join('group_relationship_field_data', 'grfd', 'grfd.id = gcgr.entity_id');
if (!isset($sandbox['progress'])) {
$query = $storage->getQuery()
->accessCheck(FALSE)
->condition('plugin_id', 'group_membership')
->condition('group_roles', ['flexible_group-group_admin'], 'IN');

$sandbox['ids'] = $query->execute()->fetchAllAssoc('entity_id');
$sandbox['ids'] = $query->execute();

$sandbox['max'] = count($sandbox['ids']);
$sandbox['progress'] = 0;
}
$items = array_slice($sandbox['ids'], $sandbox['progress'], 25);
foreach ($items as $item) {
$updated = FALSE;
$account = User::load($item->uid);
$group = Group::load($item->gid);
/** @var \Drupal\group\Entity\GroupRelationship $group_relationship */
$group_relationship = $storage->load($item);
$account = $group_relationship->getOwner();
$group = $group_relationship->getGroup();
$manager_role = 'flexible_group-group_manager';

/** @var \Drupal\group\GroupMembership $membership */
$membership = $group->getMember($account);

if (
$membership instanceof GroupMembership &&
$account instanceof UserInterface &&
$group instanceof GroupInterface
) {
$group_relationship = $membership->getGroupRelationship();
$member_assigned_roles = array_column($group_relationship->get('group_roles')->getValue(), 'target_id');

// Apply group role update only for SM/CM role.
Expand Down

0 comments on commit 8820ec9

Please sign in to comment.