You are here

public function ContentHubCommonActions::requestToRepublishEntity in Acquia Content Hub 8.2

Request to republish an entity via Webhook.

Parameters

string $origin: Entity Origin.

string $type: Entity Type.

string $uuid: Entity UUID to republish.

array $dependencies: An array of dependency UUIDs.

Throws

\GuzzleHttp\Exception\GuzzleException

1 call to ContentHubCommonActions::requestToRepublishEntity()
ContentHubCommonActions::validateDocument in src/ContentHubCommonActions.php
Validate the expected number of retrieved entities.

File

src/ContentHubCommonActions.php, line 405

Class

ContentHubCommonActions
Common actions across the entirety of Content Hub.

Namespace

Drupal\acquia_contenthub

Code

public function requestToRepublishEntity(string $origin, string $type, string $uuid, array $dependencies) {
  $client = $this
    ->getClient();
  $webhook_url = $this
    ->getWebhookUrlFromClientOrigin($origin);
  if (!$webhook_url) {
    $message = sprintf('Could not find Webhook URL for origin = "%s". Request to re-export entity "%s/%s" could not be made.', $origin, $type, $uuid);
    $this->channel
      ->error($message);
    return;
  }
  $settings = $client
    ->getSettings();
  $cdf = [
    'uuid' => $uuid,
    'type' => $type,
    'dependencies' => $dependencies,
  ];
  $payload = [
    'status' => 'successful',
    'uuid' => $uuid,
    'crud' => 'republish',
    'initiator' => $settings
      ->getUuid(),
    'cdf' => $cdf,
  ];
  $response = $client
    ->request('post', $webhook_url, [
    'body' => json_encode($payload),
  ]);
  $message = $response
    ->getBody()
    ->getContents();
  $code = $response
    ->getStatusCode();
  if ($code == 200) {
    $this->channel
      ->info('@message', [
      '@message' => $message,
    ]);
  }
  else {
    $this->channel
      ->error(sprintf('Request to re-export entity failed. Response code = %s, Response message = "%s".', $code, $message));
  }
}