You are here

public function DeveloperController::delete in Apigee Edge 8

File

src/Entity/Controller/DeveloperController.php, line 184

Class

DeveloperController
Definition of the Developer controller service.

Namespace

Drupal\apigee_edge\Entity\Controller

Code

public function delete(string $entity_id) : EntityInterface {

  /** @var \Apigee\Edge\Api\Management\Entity\DeveloperInterface $entity */
  $entity = $this
    ->traitDelete($entity_id);

  // Invalidate app caches that belongs to this developer.
  // This is implementation probably overcomplicated,
  // we may optimize this later.
  foreach ([
    $entity
      ->getEmail(),
    $entity
      ->getDeveloperId(),
  ] as $owner) {
    $app_cache = $this->appCacheByOwnerFactory
      ->getAppCache($owner);
    $app_names = [];

    /** @var \Apigee\Edge\Api\Management\Entity\DeveloperAppInterface $app */
    foreach ($app_cache
      ->getEntities() as $app) {
      $app_names[] = $app
        ->getAppId();
    }
    $app_cache
      ->removeEntities($app_names);

    // App cache has cleared all app names that it knows about
    // but it could happen that there are some remaining app names in the
    // app name cache that has not be created by app cache.
    $app_name_cache = $this->appNameCacheByOwnerFactory
      ->getAppNameCache($owner);
    $app_name_cache
      ->removeIds($app_name_cache
      ->getIds());
  }
  return $entity;
}