πŸ‡ΈπŸ‡ͺSweden @Kevin N

Account created on 15 July 2016, almost 8 years ago
#

Recent comments

πŸ‡ΈπŸ‡ͺSweden Kevin N

I had the same issue when upgrading from 1.x to 2.2.2.

Note that the site only used this patch menus, so you might need to tweaks som stuff.
And as always, try this on a dev environment first.

It was solved with the following steps:

  1. First run the function below to:
    1. Create a temporary table to store the menus (group content), (only content need to recreate them is stored).
    2. Temporarily store the menus (group content) in a new table
    3. Remove the menus (group content).
    4. Undo what the patch created (thanks to @safetypin)
      1. function custom_module_pre_upgrade() {
          $database = \Drupal::database();
        
          // Create temporary table for group_content__entity_id_str.
          $database->query("CREATE TABLE temporary_group_menu (
            group_id int(11) UNSIGNED NOT NULL,
            group_content_id int(11) UNSIGNED NOT NULL,
            menu_id_str varchar(255) NOT NULL
          )");
        
          // Copy data from group_content__entity_id_str to temporary_group_menu.
          $database->query("
            INSERT INTO temporary_group_menu (group_id, group_content_id, menu_id_str)
            SELECT gcfd.gid, gceis.entity_id, gceis.entity_id_str_target_id
            FROM group_content__entity_id_str AS gceis
            JOIN group_content_field_data AS gcfd ON gceis.entity_id = gcfd.id
          ");
        
          // Delete all group content from temporary_group_menu.
          $result = $database->query("
            SELECT group_content_id FROM temporary_group_menu
          ");
          foreach ($result as $row) {
            $group_content_id = $row->group_content_id;
            $group_content = \Drupal\group\Entity\GroupContent::load($group_content_id);
            $group_content->delete();
          }
        
          // We need to re-add the entity_id column to group_content_field_data.
          // Get data from the table that the patch added ('group_content__entity_id').
          $database->query("ALTER TABLE group_content_field_data ADD entity_id INT(11);");
          $database->query("
            UPDATE group_content_field_data
            JOIN group_content__entity_id ON group_content_field_data.id = group_content__entity_id.entity_id
            SET group_content_field_data.entity_id = group_content__entity_id.entity_id_target_id;
          ");
        
          // Now, we can remove all the messed up config, from the old field.
          $database->query("DELETE FROM key_value WHERE name='group_content.field_schema_data.entity_id';");
          $database->query("DELETE FROM key_value WHERE name='group_content.field_schema_data.entity_id_str';");
          $database->query("DROP TABLE group_content__entity_id;");
          $database->query("DROP TABLE group_content__entity_id_str;");
          $database->query("DELETE FROM key_value WHERE name='group_content.field_storage_definitions';");
        }
        
  2. Remove the patch and update group to version 2.x (2.2.2 in my case)
  3. Run the function below to:
    1. Recreate the menus (as group relationships)
    2. Remove the temporary table
    function custom_module_post_upgrade() {
      $database = \Drupal::database();
    
      // Recreate group menus.
      $result = $database->query("SELECT group_id, menu_id_str FROM temporary_group_menu");
      foreach ($result as $row) {
        $gid = $row->group_id;
        $menu_id = $row->menu_id_str;
        $group = \Drupal::entityTypeManager()->getStorage('group')->load($gid);
        $menu = \Drupal::entityTypeManager()->getStorage('menu')->load($menu_id);
    
        if (!$group || !$menu) {
          continue;
        }
    
        $group->addRelationship($menu, 'group_menu:menu');
      }
    
      // Delete table since we don't need it anymore.
      $database->query("DROP TABLE temporary_group_menu;");
    }
    
πŸ‡ΈπŸ‡ͺSweden Kevin N

Adding the diff here for easy patching until this gets merged.

πŸ‡ΈπŸ‡ͺSweden Kevin N

The 3.0.0-alpha2 version have made som changed to how i handles group relationship ids.
I remade the patch with only the "edit->update" changes.

πŸ‡ΈπŸ‡ͺSweden Kevin N

Noticed an issue with the patch at #25 so i made an update for it (This is for 6.0.0-rc1)

πŸ‡ΈπŸ‡ͺSweden Kevin N

Seems like this issue is ready to be merged. Or is something blocking a merge?

Im currently working on a D10 upgrade so it would be very nice with a merge of this if possible :)
(Assuming it's working, but based on the comments this seems to be the case).

πŸ‡ΈπŸ‡ͺSweden Kevin N

Did another quick tweak of the patch for 6.0.2 support.
Haven't tested it more than to see that linking views still work locally.

πŸ‡ΈπŸ‡ͺSweden Kevin N

I did a quick update of the patch for 6.0.0-rc1, haven't tested it much, but it seems to work.

Production build 0.69.0 2024