You are here

function drush_acsf_report_complete_async_process in Acquia Cloud Site Factory Connector 8

Command callback. Reports process completion back to the factory.

File

./acsf.drush.inc, line 361
Provides drush commands for site related operations.

Code

function drush_acsf_report_complete_async_process() {
  $data = unserialize(drush_get_option('data', NULL));
  if (empty($data->callback) || empty($data->object_id) || empty($data->acsf_path)) {
    drush_set_error('Data error', dt('Requires serialized object in --data argument with $data->callback and $data->object_id populated.'));
    exit(1);
  }

  // Since this does not bootstrap drupal fully, we need to manually require the
  // classes necessary to send a message to the Factory.
  require_once $data->acsf_path . '/src/AcsfConfig.php';
  require_once $data->acsf_path . '/src/AcsfConfigDefault.php';
  require_once $data->acsf_path . '/src/AcsfConfigIncompleteException.php';
  require_once $data->acsf_path . '/src/AcsfConfigMissingCredsException.php';
  require_once $data->acsf_path . '/src/AcsfMessage.php';
  require_once $data->acsf_path . '/src/AcsfMessageEmptyResponseException.php';
  require_once $data->acsf_path . '/src/AcsfMessageFailedResponseException.php';
  require_once $data->acsf_path . '/src/AcsfMessageFailureException.php';
  require_once $data->acsf_path . '/src/AcsfMessageMalformedResponseException.php';
  require_once $data->acsf_path . '/src/AcsfMessageRest.php';
  require_once $data->acsf_path . '/src/AcsfMessageResponse.php';
  require_once $data->acsf_path . '/src/AcsfMessageResponseRest.php';
  $arguments = [
    'wid' => $data->object_id,
    'signal' => 1,
    'state' => isset($data->state) ? $data->state : NULL,
    'data' => $data,
  ];
  try {

    // We do not have a Drupal bootstrap at this point, so we need to use
    // AcsfConfigDefault to obtain the shared credentials.
    $config = new AcsfConfigDefault();
    $message = new AcsfMessageRest('POST', $data->callback, $arguments, $config);
    $message
      ->send();
  } catch (AcsfMessageFailedResponseException $e) {
    syslog(LOG_ERR, 'Unable to contact the factory via AcsfMessage.');
  }
}