Commit 8bbcc6a3 authored by Robert Mason's avatar Robert Mason
Browse files

Issue #3244882 by MrDaleSmith: Deleting user with active license causes error.

parent 9dc81fcd
Loading
Loading
Loading
Loading
+7 −6
Changes for src/Plugin/Commerce/LicenseType/OgRole.php: 7 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -228,7 +228,7 @@ class OgRole extends LicenseTypeBase implements
   */
  public function revokeLicense(LicenseInterface $license) {
    // Get the owner of the license, and grant them the role in the group.
    $owner = $license->getOwner();
    if ($owner = $license->getOwner()) {
      $licensed_group = $license->license_og_group->entity;
      $licensed_role = $license->license_og_role->entity;

@@ -239,7 +239,8 @@ class OgRole extends LicenseTypeBase implements

      if (empty($membership)) {
        // Something's deleted the membership from beneath us: log a warning.
      \Drupal::logger('commerce_license_og_role')->error("Attempted to revoke license ID @license-id, but no membership for the @group-type group @group-id was found.", [
        \Drupal::logger('commerce_license_og_role')
          ->error("Attempted to revoke license ID @license-id, but no membership for the @group-type group @group-id was found.", [
            '@license-id' => $license->id(),
            '@group-type' => $licensed_group->getEntityTypeId(),
            '@group-id' => $licensed_group->id(),
@@ -252,9 +253,6 @@ class OgRole extends LicenseTypeBase implements
        // If the role is plain membership, delete the membership.
        // TODO: consider moving the membership to 'blocked'.
        $membership->delete();

      // Remove the reference to the deleted membership.
      $license->set('license_og_membership', NULL);
      }
      else {
        // If the role is a custom role, revoke it.
@@ -263,10 +261,13 @@ class OgRole extends LicenseTypeBase implements
        // behaviour be configurable via a field on the license?
        $membership->revokeRole($licensed_role);
        $membership->save();
      }
    }

    // TODO: consider whether to keep or delete the reference to the
    // membership.
    }
    // Remove the reference to the deleted membership.
    $license->set('license_og_membership', NULL);
  }

  /**