You are here

function drush_acsf_theme_notify in Acquia Cloud Site Factory Connector 8

Command callback: Sends a theme change notification to the Factory.

File

acsf_theme/acsf_theme.drush.inc, line 30
Provides drush commands for theme change notifications.

Code

function drush_acsf_theme_notify($scope) {
  $event = drush_get_option('event', 'modify');
  $nid = drush_get_option('nid');
  $theme = drush_get_option('theme');

  // Do most of the validation locally to avoid depending on the validation at
  // the endpoint.
  if (empty($scope)) {
    return drush_set_error(dt('The scope argument is required. Possible values are "theme", "site", "group", or "global".'));
  }
  if (!in_array($scope, [
    'theme',
    'site',
    'group',
    'global',
  ])) {
    return drush_set_error(dt('The scope argument must be either "theme", "site", "group", or "global".'));
  }
  if (!in_array($event, [
    'create',
    'modify',
    'delete',
  ])) {
    return drush_set_error(dt('Event type not supported. Possible values are "create", "modify", or "delete".'));
  }
  if ($scope === 'theme' && empty($theme)) {
    return drush_set_error(dt('The --theme option must be passed for "theme" scope notifications.'));
  }
  if ($scope === 'group' && empty($nid)) {
    return drush_set_error(dt('The --nid option must be passed for "group" scope notifications.'));
  }
  $response = \Drupal::service('acsf.theme_notification')
    ->sendNotification($scope, $event, $nid, $theme, NULL, FALSE);

  // AcsfMessageRest always returns a 500 error code if there was a problem
  // calling the REST API.
  if ($response['code'] === 500) {
    drush_log($response['data']['message'], 'error');
  }
  else {
    drush_log($response['data']['message'], 'success');
  }
}