You are here

public function DeployServicesClient::unpublish in Deploy Services Client 7

Performs a request to unpublish an entity on the endpoint.

This only works on entities that have a 'status' property indicating the publication status (e.g., nodes). Using this method on other entities can cause problems, and therefore an exception will be thrown in the case where an entity without a 'status' property is provided.

Parameters

EntityMetadataWrapper $entity: The entity object to unpublish. Construct this by calling entity_metadata_wrapper() on a normal Drupal entity.

Throws

DeployServiceException

File

./deploy_services_client.client.inc, line 219
Defines a Services client class which communicates with Deployment endpoints.

Class

DeployServicesClient
Class which defines a Services client based on a Deployment endpoint.

Code

public function unpublish(EntityMetadataWrapper $entity) {

  // Replace IDs with UUIDs before sending. (This also has the effect of
  // getting a fresh copy of the entity, which may not match the provided
  // object. It's not clear if that's what we want, but it shouldn't be too
  // bad since the entity is being unpublished on the endpoint anyway.)
  $entities_to_send = entity_uuid_load($entity
    ->type(), array(
    $entity->uuid
      ->value(),
  ));
  $entity_to_send = reset($entities_to_send);

  // Bail out if we don't have a status property.
  if (!isset($entity_to_send->status)) {
    throw new DeployServiceException(t('Entity of type "@type" with UUID "@uuid" did not have a "status" property and could not be unpublished.', array(
      '@type' => $entity
        ->type(),
      '@uuid' => $entity->uuid
        ->value(),
    )));
  }

  // Set the status to unpublished and send the request.
  // @todo: We'd like to return something here to indicate success or
  //   failure, but it's not clear what to return.
  $entity_to_send->status = 0;
  $json_data = drupal_json_encode($entity_to_send);
  $this
    ->entityRequest($entity, 'PUT', $json_data);
}