You are here

public function DeployServiceRestJSON::deploy in Deploy - Content Staging 7.3

Same name and namespace in other branches
  1. 7.2 plugins/DeployServiceRestJSON.inc \DeployServiceRestJSON::deploy()

Deploy all entities in the $iterator. This method should only move entities over to the endpoint and create unpublished revisions (if supported). The 'publish' method is responsible for publishing all successfully deployed entities.

Parameters

Traverable $iterator: This will usually be an object of a subclass of DeployAggregatorBase

Overrides DeployServiceRest::deploy

See also

DeployService::publish()

File

plugins/DeployServiceRestJSON.inc, line 15
JSON REST client for deploying entities.

Class

DeployServiceRestJSON
Class for deploying to a REST server using JSON

Code

public function deploy(Traversable $iterator) {
  foreach ($iterator as $entity) {
    $json_data = drupal_json_encode($entity);
    $this->config['headers']['Content-Type'] = 'application/json';

    // TODO: Consider making the resource path configurable.
    $url = $this->config['url'] . '/' . $entity->__metadata['uri'] . '.json';

    // Temporary hack for the built-in PHP 5.4 web server that doesn't route
    // filenames correctly.
    // TODO: See if we can remove the .json suffix for all server. The
    // Content-Type header should be enough in most (all?) cases.
    if (php_sapi_name() == 'cli-server') {
      $url = $this->config['url'] . '/' . $entity->__metadata['uri'];
    }
    $this
      ->httpRequest($url, 'PUT', $json_data);
  }
}