You are here

public function GatsbyPreview::triggerRefresh in Gatsby Live Preview & Incremental Builds 8

Same name and namespace in other branches
  1. 2.0.x src/GatsbyPreview.php \Drupal\gatsby\GatsbyPreview::triggerRefresh()

Triggers Gatsby refresh endpoint.

Parameters

string $preview_callback_url: The Gatsby URL to refresh.

object $json: Optional JSON object to post to the server.

string $path: The path used to trigger the refresh endpoint.

1 call to GatsbyPreview::triggerRefresh()
GatsbyPreview::gatsbyUpdate in src/GatsbyPreview.php
Triggers the refreshing of Gatsby preview and incremental builds.

File

src/GatsbyPreview.php, line 186

Class

GatsbyPreview
Defines a class for generating Gatsby based previews.

Namespace

Drupal\gatsby

Code

public function triggerRefresh($preview_callback_url, $json = FALSE, $path = "") {

  // If the URL has a comma it means multiple end points need to be called.
  if (stripos($preview_callback_url, ',')) {
    $urls = array_map('trim', explode(',', $preview_callback_url));
    foreach ($urls as $url) {
      $this
        ->triggerRefresh($url, $json, $path);
    }
    return;
  }
  $data = [
    'timeout' => 1,
  ];
  if ($json) {
    $data['json'] = $json;
  }
  try {
    $this->httpClient
      ->post($preview_callback_url . $path, $data);
  } catch (ConnectException $e) {

    // This is maintained for the legacy callback URL only.
    // Do nothing as no response is returned from the preview server.
  } catch (\Exception $e) {
    $this->logger
      ->error($e
      ->getMessage());
  }
}