You are here

public function ClientFactory::updateClientCdf in Acquia Content Hub 8.2

Update Client CDF.

Return value

bool TRUE if successful; FALSE otherwise.

Throws

\ReflectionException

1 call to ClientFactory::updateClientCdf()
ClientFactory::getClient in src/Client/ClientFactory.php
Instantiates the content hub client.

File

src/Client/ClientFactory.php, line 284

Class

ClientFactory
Instantiates an Acquia ContentHub Client object.

Namespace

Drupal\acquia_contenthub\Client

Code

public function updateClientCdf() {

  /** @var \Acquia\ContentHubClient\CDF\ClientCDFObject $remote_cdf */
  $remote_cdf = $this->client
    ->getEntity($this->settings
    ->getUuid());

  // Don't update the ClientCDF if the remote object matches the local one.
  if ($remote_cdf instanceof ClientCDFObject && $remote_cdf
    ->getAttribute('hash') && $remote_cdf
    ->getAttribute('hash')
    ->getValue()['und'] === $this->clientCDFObject
    ->getAttribute('hash')
    ->getValue()['und']) {
    return TRUE;
  }

  // Send the clientCDFObject because it doesn't exist in CH yet or doesn't
  // match what exists in CH today.
  $response = $this->client
    ->putEntities($this->clientCDFObject);
  if ($response
    ->getStatusCode() === 202) {
    return TRUE;
  }
  else {
    $this->loggerFactory
      ->get('acquia_contenthub')
      ->debug('Updating clientCDF failed with http status %error', [
      '%error' => $response
        ->getStatusCode(),
    ]);
    return FALSE;
  }
}