Upgrade 1.x to 2.x -- Can someone please verify?

Created on 15 August 2023, 11 months ago
Updated 11 October 2023, 9 months ago

Problem/Motivation

After starting, then stopping a year ago, finally trying to upgrade my module to handle Group 2.x. My module has a lot of Group code as it depends heavily on the Group module.

I've made the changes, but would just like someone who has already done this to take a look and verify I did it right.

Steps to reproduce

Changed this:
       

 $group_content_types = GroupContentType::loadByContentPluginId("group_node:$type"); 

To this:

$group_content_types = GroupRelationshipType::loadByPluginId("group_node:$type");

Everywhere this occurs:

   // Remove node if $relation exists.
   if ($relation) {
\Drupal::messenger()->addStatus(t('(info) removing this node from Public group : '.$visibility));
$group_contents = \Drupal::entityTypeManager()
  ->getStorage('group_content')
  ->loadByProperties([ 
  'entity_id' => $nid,
  'gid' => $gid,
  ]);

No change because group_content is a machine type.

Changed this:
 

$group_contents = GroupContent::loadByEntity($entity);

To this:

$group_contents = GroupRelationship::loadByEntity($entity);

Changed this database table name:
group_content_field_data -> group_relationship_field_data

This:

    $group = Group::load($gid['target_id']);
    /** @var \Drupal\group\Plugin\GroupContentEnablerInterface $plugin */
    $plugin = $group->getGroupType()->getContentPlugin('group_node:'.$node->bundle());
    $group_content = GroupContent::create([
      'type' => $plugin->getContentTypeConfigId(),
      'gid' => $group->id(),
      'entity_id' => $node->id(),
    ]);
    $group_content->save();
  }

Becomes (this was the trickiest):

        // Updated code for Group 2.x: 
        $plugin_id = 'group_node:'.$node->bundle();
        $relationship_type_storage = $this->entityTypeManager->getStorage('group_content_type');
        $group_type_id = $group->getGroupType()->id();

        /** @var \Drupal\group\Plugin\GroupRelationshipEnablerInterface $plugin */
        # Group 2.x
        $plugin = $group->getGroupType()->getPlugin($plugin_id);
        $group_content = GroupRelationship::create([
          'type' => $relationship_type_storage->getRelationshipTypeId($group_type_id, $plugin_id),
          'gid' => $group->id(),
          'entity_id' => $node->id(),
        ]);
        $group_content->save();

This:
 

$group_contents = GroupContent::loadByEntity($entity);

Becomes:

$group_contents = GroupRelationship::loadByEntity($entity);

This:

 $group_content->getContentPlugin()->getPluginId()), 'status');

Becomes:

$group_content->getPlugin()->getPluginId()), 'status'); // Group 2.x

This:

$plugin = $group->getGroupType()->getContentPlugin('group_node:'.$node->bundle());

Becomes:

       $plugin = $group->getGroupType()->getContentPlugin('group_node:'.$node->bundle());
Becomes (part of tricky one above):
        // Updated code for Group 2.x: http://master1and1.schoolboard.net/content/group-module-upgrade-10-20-changes-sbnmodule
        $plugin_id = 'group_node:'.$node->bundle();
        $relationship_type_storage = $this->entityTypeManager->getStorage('group_content_type');
        $group_type_id = $group->getGroupType()->id();

        /** @var \Drupal\group\Plugin\GroupRelationshipEnablerInterface $plugin */
        # Group 2.x
        $plugin = $group->getGroupType()->getPlugin($plugin_id);

This:

$group_content_types = GroupContentType::loadByContentPluginId("group_node:$type"); 

Becomes:

$group_content_types = GroupRelationshipType::loadByPluginId("group_node:$type");

as per: https://www.drupal.org/project/group/issues/3309727#comment-14706912 β†’
Thank you!

Remaining tasks

Again, just hoping someone who knows this in and out will see this and confirm these are correct.

Thanks!

πŸ’¬ Support request
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States SomebodySysop

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @SomebodySysop
  • πŸ‡ΊπŸ‡ΈUnited States SomebodySysop
  • πŸ‡ΊπŸ‡ΈUnited States SomebodySysop

    With respect to this specific change (which I am most worried about as it is not simply a renaming issue):

        $group = Group::load($gid);
        /** @var \Drupal\group\Plugin\GroupContentEnablerInterface $plugin */
        $plugin = $group->getGroupType()->getContentPlugin('group_node:'.$node->bundle());
        $group_content = GroupContent::create([
          'type' => $plugin->getContentTypeConfigId(),
          'gid' => $group->id(),
          'entity_id' => $node->id(),
        ]);
        $group_content->save();
    

    Changed to:

            // Updated code for Group 2.x: 
            $plugin_id = 'group_node:'.$node->bundle();
            $relationship_type_storage = $this->entityTypeManager->getStorage('group_content_type');
            $group_type_id = $group->getGroupType()->id();
    
            /** @var \Drupal\group\Plugin\GroupRelationshipEnablerInterface $plugin */
            # Group 2.x
            $plugin = $group->getGroupType()->getPlugin($plugin_id);
            $group_content = GroupRelationship::create([
              'type' => $relationship_type_storage->getRelationshipTypeId($group_type_id, $plugin_id),
              'gid' => $group->id(),
              'entity_id' => $node->id(),
            ]);
            $group_content->save();
    

    These are the comments from Claude on the above change:

    After reviewing your code changes again along with the Group 2.x upgrade documentation, I believe you have made the appropriate modifications to migrate from Group 1.x to 2.x. Here's a recap of the key changes:

    - Use `getPlugin()` instead of `getContentPlugin()` to get the relationship plugin 

    - Load the relationship type storage directly instead of via the plugin

    - Get the relationship type ID from the storage instead of the plugin

    - Create the relationship using `GroupRelationship` instead of `GroupContent`

    - Save the relationship correctly  

    These align with the recommended changes of:

    - Using new 2.x methods like `getPlugin()` instead of old 1.x methods

    - Accessing storages directly instead of via old APIs

    - Getting IDs from storages instead of old plugins 

    - Creating/loading `GroupRelationship` instead of `GroupContent`

    So in summary, yes your code modifications follow the prescribed upgrades for migrating custom code to Group 2.x based on the documentation. The main aspects like using new methods, accessing storages directly, and leveraging the GroupRelationship entity are addressed.

    Barring any edge cases I'm not aware of, I would say your code changes are correct and should properly upgrade the integration to Group 2.x according to the provided upgrade guides and documentation.

  • Status changed to Fixed 10 months ago
  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    Seems like this was answered and then abandoned, so closing as fixed.

  • Status changed to Active 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States SomebodySysop

    I do very much appreciate the discussion, and those notes helped me to get this far. However, I think it's a little unfair to say I "abandoned" the issue. "Postponed" is a far better word. And I had good reason. I was never able to get Group 2.x working. And, on top of that, I had these issues all related to Group 2.x incompatibilities with other modules I depended on:

    Quick node clone incompatibility:
    https://www.drupal.org/project/quick_node_clone/issues/3306677 ✨ Intercompatibility with Group module new versions Needs work

    Group moderation incompatibility:
    https://www.drupal.org/project/gcontent_moderation/issues/3309542 πŸ’¬ Is group content moderation module compatible with Groups 2.0.0-beta3? Needs work

    Sitewide admin permissions:
    https://www.drupal.org/project/group/issues/3318776 β†’

    With all the back and forth, I eventually trashed the site I was working with:
    https://www.drupal.org/project/group/issues/3330286 β†’

    As I was slammed with trying to get Drupal 7 sites migrated to Drupal 8, and the Flexible Permissions module on which Group 2.x depended was still in alpha, it just made sense to postpone the effort until things calmed down a bit.

    In addition, I got involved in moving the OpenAI project along, which resulted in me developing my own AI module:
    https://www.drupal.org/project/openai/issues/3337774#comment-14908993 ✨ Generate string vectors using OpenAI embeddings Fixed
    https://youtu.be/qgKiXYP8UBs

    So, now that some of the incompatibility issues with other modules have at least been addressed, I turned my attention back to getting this working. Before I go and repeat the same mistakes as before, I was just hoping that someone who has already done this could take a look and let me know if it looks correct.

    Given everything, I don't think that's an unreasonable request.

  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    Hmm, was mass replying to the issue queue, must have misread the dates or something so I apologize for being a bit harsh and calling this abandoned.

    As to your request, https://www.drupal.org/docs/contributed-modules/group/updating-your-modu... β†’ is a nice write-up of the changes you need to look out for. It seems like you found that page and followed those steps and got someone to review them too. So al in all, I think you should be good to go, although an extra read of the documentation I linked never hurts :)

  • πŸ‡ΊπŸ‡ΈUnited States SomebodySysop

    Yes, I did review that page -- several times! I just didn't want to repeat the same mistakes. Thanks much for taking a look.

  • Status changed to Fixed 9 months ago
  • πŸ‡ΊπŸ‡ΈUnited States SomebodySysop

    OK, so everything seems to have worked out fairly well. I only ran into these two hiccups that apparently weren't in my original notes:

    change from getContentByEntityId to getRelationshipsByEntity

    addContent() method is not defined for the Group class.

    // https://www.drupal.org/node/3292844#:~:text=,on%2027%20June%202022 β†’
    changed to:
    $group->addRelationship($node, $pluginId);

    Appreciate the assistance!

    Just finished unit testing permissions and it appears we are good to go with Group 2.2.0. Woo-hoo!

  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    Great, glad you got it sorted out!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024