You are here

public function ContentHubConnectionManager::unregister in Acquia Content Hub 8.2

Unregisters the client.

Parameters

\Drupal\acquia_contenthub\Event\AcquiaContentHubUnregisterEvent $event: ACH unregister event.

Return value

bool TRUE if unregister is successful, FALSE otherwise.

Throws

\Exception

File

src/ContentHubConnectionManager.php, line 267

Class

ContentHubConnectionManager
Responsible for connection management actions.

Namespace

Drupal\acquia_contenthub

Code

public function unregister(AcquiaContentHubUnregisterEvent $event) : bool {
  $this
    ->initialize();
  $this->settings = $this->client
    ->getSettings();
  $success = $this
    ->unregisterWebhook($event, TRUE);
  if (!$success) {
    $this->logger
      ->error('Some error occurred during webhook deletion.');
    return FALSE;
  }
  $client_uuid = empty($event
    ->getOriginUuid()) ? $this->settings
    ->getUuid() : $event
    ->getOriginUuid();
  $client_name = $event
    ->getClientName();
  $resp = $this->client
    ->deleteClient($client_uuid);
  if ($resp instanceof ResponseInterface && $resp
    ->getStatusCode() !== Response::HTTP_OK) {
    $this->logger
      ->error('Could not delete client: @e_message', [
      '@e_message' => $resp
        ->getReasonPhrase(),
    ]);
    return FALSE;
  }
  $this->logger
    ->notice('Successfully unregistered client @client', [
    '@client' => $client_name,
  ]);

  // If origin is set, then we unregister a different site, do not delete
  // the config on this.
  if (!$event
    ->getOriginUuid()) {
    $this
      ->getContentHubConfig()
      ->delete();
  }
  return TRUE;
}