public static function batchUpdateGroupContentVisibility(Group $group, $new_type) {
    // Set it up as a batch. We need to update visibility.
    // Load all the GroupContentEntities from Post to Memberships to content.
    $entities = $group->getContentEntities();

    $posts = self::getPostsFromGroup($group);
    foreach ($posts as $pid => $post) {
      $entities[] = $post;
    }
    $memberships = $group->getMembers();
    foreach ($memberships as $member) {
      $entities[] = $member;
    }

    $num_operations = count($entities);
    $operations = [];

    // Update Memberships & ContentVisibility.
    // As per documentation each entity has it's own operation.
    for ($i = 0; $i < $num_operations; $i++) {
      $operations[] = [
        '\Drupal\social_group\GroupContentVisibilityUpdate::updateVisibility',
        [
          $entities[$i],
          $new_type,
        ],
      ];
    }

    // Provide all the operations and the finish callback to our batch.
    $batch = [
      'title' => t('Updating Group Content...'),
      'operations' => $operations,
      'finished' => '\Drupal\social_group\GroupContentVisibilityUpdate::updateVisibilityFinishedCallback',
    ];

    batch_set($batch);

    $group->set('type', $new_type);
    $group->save();
  }