If remove the user who wasn't removed from Licesnes. Next time remove the license of the user from Licenses. It will show error

Error: Call to a member function removeRole() on null in Drupal\commerce_license\Plugin\Commerce\LicenseType\Role->revokeLicense() (line 70 of /var/websites/ascmus_org/web/modules/contrib/commerce_license/src/Plugin/Commerce/LicenseType/Role.php)

Add code in "/src/Plugin/Commerce/LicenseType/Role.php"

  public function revokeLicense(LicenseInterface $license) {
    // Get the role ID that this license grants.
    $role_id = $license->license_role->first()->target_id;

    // Get the owner of the license and remove that role.
    $owner = $license->getOwner();
+    // Skip if the owner doesn't exist
+    if (empty($owner)) {
+      return;
+    }
    $owner->removeRole($role_id);

    $owner->save();

    // TODO: Log this, as it's something admins should see?
  }

Comments

sevenfish created an issue. See original summary.

mohit.bansal623’s picture

Status: Active » Needs review
StatusFileSize
new572 bytes
mohit.bansal623’s picture

StatusFileSize
new654 bytes
mohit.bansal623’s picture

StatusFileSize
new692 bytes
mohit.bansal623’s picture

StatusFileSize
new2.23 KB

As per the error, I have fixed the issue. The class has been moved to a new directory. From Kernel it has been moved to Traits.
Applying the patch for the same.

Status: Needs review » Needs work

The last submitted patch, 5: 3191749-5.patch, failed testing. View results

jsacksick’s picture

Status: Needs work » Closed (outdated)

This should be fixed in dev (See #3194917: Licenses should leverage the EntityOwnerTrait), now that we leverage the Commerce EntityOwnerTrait, an owner is always returned.