Commit 4f6c0c3f authored by Kristiaan Van den Eynde's avatar Kristiaan Van den Eynde
Browse files

Issue #3303321 by kristiaanvandeneynde: Drop 2.0.x upgrade path and update machine names

parent 1ae25fc3
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -4,9 +4,9 @@ dependencies:
  module:
    - 'group'
    - 'options'
id: 'group_content.group_roles'
id: 'group_relationship.group_roles'
field_name: 'group_roles'
entity_type: 'group_content'
entity_type: 'group_relationship'
type: 'entity_reference'
settings:
  target_type: 'group_role'
+15 −0
Original line number Diff line number Diff line
@@ -3,13 +3,13 @@ status: true
dependencies:
  module:
    - group
id: group_content
id: group_relationship
label: 'Group relationship'
type: 'canonical_entities:group_content'
pattern: 'group/[group_content:group:id]/[group_content:pretty-path-key]/[group_content:id]'
type: 'canonical_entities:group_relationship'
pattern: 'group/[group_relationship:group:id]/[group_relationship:pretty-path-key]/[group_relationship:id]'
selection_criteria: {  }
selection_logic: and
weight: -5
relationships:
  'group_content:langcode:language':
  'group_relationship:langcode:language':
    label: Language
+29 −29
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ langcode: en
status: true
dependencies:
  config:
    - field.storage.group_content.group_roles
    - field.storage.group_relationship.group_roles
  module:
    - group
    - user
@@ -83,9 +83,9 @@ display:
            group_roles: group_roles
            changed: changed
            created: created
            view_group_content: view_group_content
            edit_group_content: edit_group_content
            delete_group_content: delete_group_content
            view_group_relationship: view_group_relationship
            edit_group_relationship: edit_group_relationship
            delete_group_relationship: delete_group_relationship
            dropbutton: dropbutton
          info:
            name:
@@ -114,21 +114,21 @@ display:
              separator: ''
              empty_column: false
              responsive: ''
            view_group_content:
            view_group_relationship:
              sortable: false
              default_sort_order: asc
              align: ''
              separator: ''
              empty_column: false
              responsive: ''
            edit_group_content:
            edit_group_relationship:
              sortable: false
              default_sort_order: asc
              align: ''
              separator: ''
              empty_column: false
              responsive: ''
            delete_group_content:
            delete_group_relationship:
              sortable: false
              default_sort_order: asc
              align: ''
@@ -219,7 +219,7 @@ display:
          plugin_id: field
        group_roles:
          id: group_roles
          table: group_content__group_roles
          table: group_relationship__group_roles
          field: group_roles
          relationship: none
          group_type: group
@@ -344,7 +344,7 @@ display:
          multi_type: separator
          separator: ', '
          field_api_classes: false
          entity_type: group_content
          entity_type: group_relationship
          entity_field: changed
          plugin_id: field
        created:
@@ -411,13 +411,13 @@ display:
          multi_type: separator
          separator: ', '
          field_api_classes: false
          entity_type: group_content
          entity_type: group_relationship
          entity_field: created
          plugin_id: field
        view_group_content:
          id: view_group_content
        view_group_relationship:
          id: view_group_relationship
          table: group_relationship
          field: view_group_content
          field: view_group_relationship
          relationship: none
          group_type: group
          admin_label: 'View member link'
@@ -463,14 +463,14 @@ display:
          empty_zero: false
          hide_alter_empty: true
          text: 'View member'
          entity_type: group_content
          entity_type: group_relationship
          plugin_id: entity_link
          output_url_as_text: false
          absolute: false
        edit_group_content:
          id: edit_group_content
        edit_group_relationship:
          id: edit_group_relationship
          table: group_relationship
          field: edit_group_content
          field: edit_group_relationship
          relationship: none
          group_type: group
          admin_label: 'Edit member link'
@@ -516,12 +516,12 @@ display:
          empty_zero: false
          hide_alter_empty: true
          text: 'Edit member'
          entity_type: group_content
          entity_type: group_relationship
          plugin_id: entity_link_edit
        delete_group_content:
          id: delete_group_content
        delete_group_relationship:
          id: delete_group_relationship
          table: group_relationship
          field: delete_group_content
          field: delete_group_relationship
          relationship: none
          group_type: group
          admin_label: 'Remove member link'
@@ -567,7 +567,7 @@ display:
          empty_zero: false
          hide_alter_empty: true
          text: 'Remove member'
          entity_type: group_content
          entity_type: group_relationship
          plugin_id: entity_link_delete
        dropbutton:
          id: dropbutton
@@ -618,9 +618,9 @@ display:
          empty_zero: false
          hide_alter_empty: true
          fields:
            view_group_content: view_group_content
            edit_group_content: edit_group_content
            delete_group_content: delete_group_content
            view_group_relationship: view_group_relationship
            edit_group_relationship: edit_group_relationship
            delete_group_relationship: delete_group_relationship
            name: '0'
            group_roles: '0'
            changed: '0'
@@ -654,8 +654,8 @@ display:
          required: true
          group_content_plugins:
            group_membership: group_membership
          entity_type: group_content
          plugin_id: group_content_to_entity
          entity_type: group_relationship
      arguments:
        gid:
          id: gid
@@ -691,7 +691,7 @@ display:
          validate_options: {  }
          break_phrase: false
          not: false
          entity_type: group_content
          entity_type: group_relationship
          entity_field: gid
          plugin_id: numeric
      display_extenders: {  }
@@ -706,7 +706,7 @@ display:
        - url.query_args
        - user.group_permissions
      tags:
        - 'config:field.storage.group_content.group_roles'
        - 'config:field.storage.group_relationship.group_roles'
  page_1:
    display_plugin: page
    id: page_1
@@ -735,4 +735,4 @@ display:
        - url.query_args
        - user.group_permissions
      tags:
        - 'config:field.storage.group_content.group_roles'
        - 'config:field.storage.group_relationship.group_roles'
+5 −5
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ group.role.*:
        type: 'string'
        label: 'Group permission'

group_content_type:
group_relationship_type:
  type: 'config_entity'
  label: 'Group relationship type'
  mapping:
@@ -107,10 +107,10 @@ group_content_type:
      sequence:
        type: 'group_relation.config.[%key]'

# Follows the pattern group.content_type.GROUP_TYPE_ID-PLUGIN_ID.
# Follows the pattern group.content_type.GROUP_TYPE_ID-PLUGIN_ID-DERIVATIVE_ID.
group.content_type.*:
  type: 'group_content_type'
# Follows the pattern group.relationship_type.GROUP_TYPE_ID-PLUGIN_ID.
# Follows the pattern group.relationship_type.GROUP_TYPE_ID-PLUGIN_ID-DERIVATIVE_ID.
group.relationship_type.*:
  type: 'group_relationship_type'
  label: 'Group relationship type'

entity_reference_selection.group_type:group_role:
+1 −260
Original line number Diff line number Diff line
@@ -5,268 +5,9 @@
 * Install, update and uninstall functions for the group module.
 */

use Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\group\Entity\GroupRelationship;
use Drupal\group\Entity\GroupRelationshipType;
use Drupal\group\Entity\GroupTypeInterface;
use Drupal\group\PermissionScopeInterface;
use Drupal\user\RoleInterface;

/**
 * Implements hook_update_last_removed().
 */
function group_update_last_removed() {
  return 8023;
}

/**
 * Update class name and handler class names for group_content_type.
 */
function group_update_9201() {
  $definition_update_manager = \Drupal::entityDefinitionUpdateManager();

  // Update the class name and handlers for group_content_type.
  $new_handlers = \Drupal::entityTypeManager()->getDefinition('group_content_type')->getHandlerClasses();
  $entity_type = $definition_update_manager->getEntityType('group_content_type');
  $entity_type->setClass(GroupRelationshipType::class);
  $entity_type->set('handlers', $new_handlers);
  $definition_update_manager->updateEntityType($entity_type);
}

/**
 * Update class name and handler class names for group_content.
 */
function group_update_9202() {
  $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
  $last_installed_schema_repository = \Drupal::service('entity.last_installed_schema.repository');
  assert($last_installed_schema_repository instanceof EntityLastInstalledSchemaRepositoryInterface);

  // Update the class name and handlers for group_content.
  $new_handlers = \Drupal::entityTypeManager()->getDefinition('group_content')->getHandlerClasses();
  $entity_type = $definition_update_manager->getEntityType('group_content');
  $entity_type->setClass(GroupRelationship::class);
  $entity_type->set('handlers', $new_handlers);

  // Instead of using the entity definition update manager, we immediately write
  // these changes as they would otherwise trigger a data migration and choke on
  // the fact that the old storage class no longer exists.
  $last_installed_schema_repository->setLastInstalledDefinition($entity_type);
}

/**
 * Update group_content DB table, fields and indexes.
 */
function group_update_9203(&$sandbox) {
  $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
  $last_installed_schema_repository = \Drupal::service('entity.last_installed_schema.repository');
  assert($last_installed_schema_repository instanceof EntityLastInstalledSchemaRepositoryInterface);

  // Update the database tables.
  $entity_type = $definition_update_manager->getEntityType('group_content');
  $entity_type->set('base_table', 'group_relationship');
  $entity_type->set('data_table', 'group_relationship_field_data');

  // Add the plugin_id and group_type field.
  $field_storage_definitions = $last_installed_schema_repository->getLastInstalledFieldStorageDefinitions('group_content');
  $field_storage_definitions['plugin_id'] = BaseFieldDefinition::create('string')
    ->setName('plugin_id')
    ->setTargetEntityTypeId('group_content')
    ->setTargetBundle(NULL)
    ->setLabel(t('Plugin ID'))
    ->setRequired(TRUE)
    ->setReadOnly(TRUE)
    ->setInitialValue('TEMP')
    ->setProvider('group');

  $field_storage_definitions['group_type'] = BaseFieldDefinition::create('entity_reference')
    ->setName('group_type')
    ->setTargetEntityTypeId('group_content')
    ->setTargetBundle(NULL)
    ->setLabel(t('Group type'))
    ->setSetting('target_type', 'group_type')
    ->setRequired(TRUE)
    ->setReadOnly(TRUE)
    ->setInitialValue('TEMP')
    ->setProvider('group');

  // Update the fields and regenerate indexes, the correct initial values will
  // be retrieved from GroupRelationshipStorage::restore().
  $definition_update_manager->updateFieldableEntityType($entity_type, $field_storage_definitions, $sandbox);
}

/**
 * Remove the 'bypass group access' permission from all roles.
 */
function group_update_9204() {
  $config_factory = \Drupal::configFactory();
  foreach ($config_factory->listAll('user.role.') as $config_name) {
    $role = $config_factory->getEditable($config_name);
    $role->set('permissions', array_values(array_diff($role->get('permissions'), ['bypass group access'])));
    $role->save(TRUE);
  }
}

/**
 * Convert group roles with the 'administer group' permission to admin roles.
 */
function group_update_9205() {
  $config_factory = \Drupal::configFactory();
  foreach ($config_factory->listAll('group.role.') as $config_name) {
    $role = $config_factory->getEditable($config_name);
    if (in_array('administer group', $role->get('permissions'), TRUE)) {
      $role->set('permissions', []);
      $role->set('admin', TRUE);
    }
    else {
      $role->set('admin', FALSE);
    }
    $role->save(TRUE);
  }
}

/**
 * Convert synchronized group roles to new scope and target_role structure.
 */
function group_update_9206() {
  $config_factory = \Drupal::configFactory();

  $synchronized_role_ids = [];
  foreach ($config_factory->listAll('user.role.') as $role_config_name) {
    $role_id = $config_factory->get($role_config_name)->get('id');

    // We never synced any roles to anonymous or authenticated.
    if ($role_id === RoleInterface::ANONYMOUS_ID || $role_id === RoleInterface::AUTHENTICATED_ID) {
      continue;
    }

    $synchronized_role_ids[] = $role_id;
  }

  // Nothing to update if we had no user defined global roles.
  if (empty($synchronized_role_ids)) {
    return;
  }

  foreach ($config_factory->listAll('group.type.') as $group_type_config_name) {
    $group_type_id = $config_factory->get($group_type_config_name)->get('id');

    foreach ($synchronized_role_ids as $role_id) {
      // Copied the group role ID logic directly from the GroupRoleSynchronizer
      // class because that class has been removed in favor of the new roles.
      $machine_name_max_length = EntityTypeInterface::ID_MAX_LENGTH - GroupTypeInterface::ID_MAX_LENGTH - 1;
      $machine_name = substr(md5('group_role_sync.' . $role_id), 0, $machine_name_max_length);
      $group_role_id = "$group_type_id-$machine_name";

      // Delete the synchronized role if they had no rights.
      $group_role = $config_factory->getEditable('group.role.' . $group_role_id);
      if (!$group_role->get('admin') && empty($group_role->get('permissions'))) {
        $group_role->delete();
      }
      // Otherwise update the group role to use the new keys.
      else {
        $group_role->set('scope', PermissionScopeInterface::OUTSIDER_ID);
        $group_role->set('global_role', $role_id);

        // Clear the old keys and save.
        $group_role->clear('permissions_ui');
        $group_role->clear('internal');
        $group_role->clear('audience');
        $group_role->save(TRUE);
      }
    }
  }
}

/**
 * Convert default group roles to new scope and target_role structure.
 */
function group_update_9207() {
  $config_factory = \Drupal::configFactory();

  $group_role_info = [
    'anonymous' => [
      'scope' => PermissionScopeInterface::OUTSIDER_ID,
      'global_role' => RoleInterface::ANONYMOUS_ID,
    ],
    'outsider' => [
      'scope' => PermissionScopeInterface::OUTSIDER_ID,
      'global_role' => RoleInterface::AUTHENTICATED_ID,
    ],
    'member' => [
      'scope' => PermissionScopeInterface::INSIDER_ID,
      'global_role' => RoleInterface::AUTHENTICATED_ID,
    ],
  ];

  // Update anonymous, outsider and member.
  foreach ($config_factory->listAll('group.type.') as $group_type_config_name) {
    $group_type_id = $config_factory->get($group_type_config_name)->get('id');

    foreach ($group_role_info as $group_role_suffix => $info) {
      $group_role_id = "$group_type_id-$group_role_suffix";

      // We do not delete the default roles, even if they have no rights.
      $group_role = $config_factory->getEditable('group.role.' . $group_role_id);
      $group_role->set('scope', $info['scope']);
      $group_role->set('global_role', $info['global_role']);

      // Clear the old keys and save.
      $group_role->clear('permissions_ui');
      $group_role->clear('internal');
      $group_role->clear('audience');
      $group_role->save(TRUE);
    }
  }
}

/**
 * Convert user created group roles to new scope and target_role structure.
 */
function group_update_9208() {
  $config_factory = \Drupal::configFactory();

  foreach ($config_factory->listAll('group.role.') as $config_name) {
    // Now that we've updated synchronized and default roles, any role that
    // still has the old properties is a user generated one. So skip the rest.
    if (empty($config_factory->get($config_name)->get('audience'))) {
      continue;
    }

    // We do not delete the user created roles, even if they have no rights.
    $group_role = $config_factory->getEditable($config_name);
    $group_role->set('scope', PermissionScopeInterface::INDIVIDUAL_ID);

    // Clear the old keys and save.
    $group_role->clear('permissions_ui');
    $group_role->clear('internal');
    $group_role->clear('audience');
    $group_role->save(TRUE);
  }
}

/**
 * Remove label and description from relationship types.
 */
function group_update_9209() {
  $config_factory = \Drupal::configFactory();

  foreach ($config_factory->listAll('group.content_type.') as $config_name) {
    $relationship_type = $config_factory->getEditable($config_name);
    $relationship_type->clear('label');
    $relationship_type->clear('description');
    $relationship_type->save(TRUE);
  }
}

/**
 * Introduce the group_config_wrapper entity type.
 */
function group_update_9210() {
  $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
  if (!$definition_update_manager->getEntityType('group_config_wrapper')) {
    $entity_type = \Drupal::entityTypeManager()->getDefinition('group_config_wrapper');
    $definition_update_manager->installEntityType($entity_type);
  }
  return 9210;
}
Loading