You are here

function gardens_site_data_alert_send in Acquia Cloud Site Factory Connector 8.2

Same name and namespace in other branches
  1. 8 acsf_init/lib/sites/g/sites.inc \gardens_site_data_alert_send()

Alerts the Site Factory on possible sites.json issues.

Parameters

string $scope: The scope type. (Currently only 'sites_json' scope type is accepted by the Site Factory.)

string $issue_type: The issue type.

Return value

Acquia\SimpleRest\SimpleRestResponse The response.

2 calls to gardens_site_data_alert_send()
gardens_site_data_json_alert_flag_clear in acsf_init/lib/sites/g/sites.inc
Clears a 'sites.json alert' flag.
gardens_site_data_json_alert_flag_set in acsf_init/lib/sites/g/sites.inc
Tries to set a flag, marking that an issue with sites.json exists.

File

acsf_init/lib/sites/g/sites.inc, line 826
ACSF helper functions for Drupal's multi-site directory aliasing feature.

Code

function gardens_site_data_alert_send($scope, $issue_type) {

  // The SF REST API endpoint.
  $endpoint = 'site-api/v1/sf-alert';

  // The hosting site group name.
  $site = $_ENV['AH_SITE_GROUP'];

  // The hosting environment name.
  $env = $_ENV['AH_SITE_ENVIRONMENT'];

  // The fully qualified webnode name.
  $webnode = gethostname();
  try {
    $parameters = [
      'scope' => $scope,
      'data' => [
        'issue_type' => $issue_type,
        'site_group' => $site,
        'site_env' => $env,
        'server' => $webnode,
        // Instead of \Drupal::time()->getRequestTime() we're going to use
        // time() here because there is no definite usage of \Drupal at this
        // point in the bootstrap.
        // Rest of the code above also does a class_exists() check against
        // 'Drupal', probably due to the same reason.
        'timestamp' => time(),
      ],
    ];
    $creds = gardens_site_data_shared_creds_get($site, $env);
    $message = new SimpleRestMessage($site, $env);
    $response = $message
      ->send('POST', $endpoint, $parameters, $creds);
  } catch (Exception $e) {
    $error_message = sprintf('Sending alert to Site Factory failed: %s', $e
      ->getMessage());
    syslog(LOG_ERR, $error_message);
    $response = new SimpleRestResponse($endpoint, 500, [
      'message' => $error_message,
    ]);
  }
  return $response;
}