lcatlett
3/29/2018 - 7:22 PM

Content Hub Site and Environment Override Sample Factory Hook

Content Hub Site and Environment Override Sample Factory Hook

<?php

/**
 * @file
 * Setup BLT utility variables, include required files.
 */

use Acquia\Blt\Robo\Config\ConfigInitializer;
use Drupal\Component\Utility\Bytes;
use Drupal\Core\DrupalKernel;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;

/**
 * Host detection.
 */
if (!empty($_SERVER['HTTP_X_FORWARDED_HOST'])) {
  $forwarded_host = $_SERVER['HTTP_X_FORWARDED_HOST'];
}
elseif (!empty($_SERVER['HTTP_HOST'])) {
  $forwarded_host = $_SERVER['HTTP_HOST'];
}
else {
  $forwarded_host = NULL;
}

$server_protocol = empty($_SERVER['HTTPS']) ? 'http' : 'https';
$forwarded_protocol = !empty($_ENV['HTTP_X_FORWARDED_PROTO']) ? $_ENV['HTTP_X_FORWARDED_PROTO'] : $server_protocol;

/*******************************************************************************
 * Environment detection.
 ******************************************************************************/

$ah_env = isset($_ENV['AH_SITE_ENVIRONMENT']) ? $_ENV['AH_SITE_ENVIRONMENT'] : NULL;
$ah_group = isset($_ENV['AH_SITE_GROUP']) ? $_ENV['AH_SITE_GROUP'] : NULL;
$is_ah_env = (bool) $ah_env;
$is_ah_prod_env = ($ah_env == 'prod' || $ah_env == '01live');
$is_ah_stage_env = ($ah_env == 'test' || $ah_env == '01test');
$is_ah_preview_env = ($ah_env == 'preview' || $ah_env == '01preview');
$is_ah_dev_cloud = (!empty($_SERVER['HTTP_HOST']) && strstr($_SERVER['HTTP_HOST'], 'devcloud'));
$is_ah_dev_env = (preg_match('/^dev[0-9]*$/', $ah_env) || $ah_env == '01dev');
$is_acsf = (!empty($ah_group) && file_exists("/mnt/files/$ah_group.$ah_env/files-private/sites.json"));
$acsf_db_name = $is_acsf ? $GLOBALS['gardens_site_settings']['conf']['acsf_db_name'] : NULL;
$is_local_env = !$is_ah_env;
$is_dealerdev = (!empty($_SERVER['HTTP_HOST']) && strstr($_SERVER['HTTP_HOST'], 'dealerdev'));
$is_sitemaster = (!empty($_SERVER['HTTP_HOST']) && strstr($_SERVER['HTTP_HOST'], 'sitemaster'));


/**
 * @file
 * Contains Acquia Lift and Content Hub configuration.
 */
if ($is_ah_env && $is_dealerdev) {
  switch ($ah_env) {
    case '01live':
      
      //Acquia Lift Module Settings
      $config['acquia_lift.settings']['credential']['account_id'] = ''; // Customer Account ID
      $config['acquia_lift.settings']['credential']['site_id'] = ''; // Customer Site ID
      $config['acquia_lift.settings']['credential']['content_origin'] = ''; // Limit deployable content to a Site by its Content Hub Origin ID
      $config['acquia_lift.settings']['advanced']['content_replacement_mode'] = 'trusted'; // Default slot content replacement mode
      //Acquia Content Hub Module Settings
      $config['acquia_contenthub.admin_settings']['api_key'] = ''; // Customer Content Hub API Key
      $config['acquia_contenthub.admin_settings']['secret_key'] = ''; // Customer Content Hub Secret Key
      $config['acquia_contenthub.admin_settings']['client_name'] = ''; // Customer Site ID
      $config['acquia_contenthub.admin_settings']['origin'] = ''; // Content Hub Origin ID (UUID)
      break;
    case '01test':
      //Acquia Lift Module Settings
      $config['acquia_lift.settings']['credential']['account_id'] = ''; // Customer Account ID
      $config['acquia_lift.settings']['credential']['site_id'] = ''; // Customer Site ID
      $config['acquia_lift.settings']['credential']['content_origin'] = ''; // Limit deployable content to a Site by its Content Hub Origin ID
      $config['acquia_lift.settings']['advanced']['content_replacement_mode'] = 'trusted'; // Default slot content replacement mode
      //Acquia Content Hub Module Settings
      $config['acquia_contenthub.admin_settings']['api_key'] = ''; // Customer Content Hub API Key
      $config['acquia_contenthub.admin_settings']['secret_key'] = ''; // Customer Content Hub Secret Key
      $config['acquia_contenthub.admin_settings']['client_name'] = ''; // Customer Site ID
      $config['acquia_contenthub.admin_settings']['origin'] = ''; // Content Hub Origin ID (UUID)
      break;
    case '01dev':
      //Acquia Lift Module Settings
      $config['acquia_lift.settings']['credential']['account_id'] = ''; // Customer Account ID
      $config['acquia_lift.settings']['credential']['site_id'] = ''; // Customer Site ID
      $config['acquia_lift.settings']['credential']['content_origin'] = ''; // Limit deployable content to a Site by its Content Hub Origin ID
      $config['acquia_lift.settings']['advanced']['content_replacement_mode'] = 'trusted'; // Default slot content replacement mode
      //Acquia Content Hub Module Settings
      $config['acquia_contenthub.admin_settings']['api_key'] = ''; // Customer Content Hub API Key
      $config['acquia_contenthub.admin_settings']['secret_key'] = ''; // Customer Content Hub Secret Key
      $config['acquia_contenthub.admin_settings']['client_name'] = ''; // Customer Site ID
      $config['acquia_contenthub.admin_settings']['origin'] = ''; // Content Hub Origin ID (UUID)
      break;
  }
}

if ($is_ah_env && $is_sitemaster) {
  switch ($ah_env) {
    case '01live':
      //Acquia Lift Module Settings
      $config['acquia_lift.settings']['credential']['account_id'] = ''; // Customer Account ID
      $config['acquia_lift.settings']['credential']['site_id'] = ''; // Customer Site ID
      $config['acquia_lift.settings']['credential']['content_origin'] = ''; // Limit deployable content to a Site by its Content Hub Origin ID
      $config['acquia_lift.settings']['advanced']['content_replacement_mode'] = 'trusted'; // Default slot content replacement mode
      //Acquia Content Hub Module Settings
      $config['acquia_contenthub.admin_settings']['api_key'] = ''; // Customer Content Hub API Key
      $config['acquia_contenthub.admin_settings']['secret_key'] = ''; // Customer Content Hub Secret Key
      $config['acquia_contenthub.admin_settings']['client_name'] = ''; // Customer Site ID
      $config['acquia_contenthub.admin_settings']['origin'] = ''; // Content Hub Origin ID (UUID)
      break;
    case '01test':
      //Acquia Lift Module Settings
      $config['acquia_lift.settings']['credential']['account_id'] = ''; // Customer Account ID
      $config['acquia_lift.settings']['credential']['site_id'] = ''; // Customer Site ID
      $config['acquia_lift.settings']['credential']['content_origin'] = ''; // Limit deployable content to a Site by its Content Hub Origin ID
      $config['acquia_lift.settings']['advanced']['content_replacement_mode'] = 'trusted'; // Default slot content replacement mode
      //Acquia Content Hub Module Settings
      $config['acquia_contenthub.admin_settings']['api_key'] = ''; // Customer Content Hub API Key
      $config['acquia_contenthub.admin_settings']['secret_key'] = ''; // Customer Content Hub Secret Key
      $config['acquia_contenthub.admin_settings']['client_name'] = ''; // Customer Site ID
      $config['acquia_contenthub.admin_settings']['origin'] = ''; // Content Hub Origin ID (UUID)
      break;
    case '01dev':
      //Acquia Lift Module Settings
      $config['acquia_lift.settings']['credential']['account_id'] = ''; // Customer Account ID
      $config['acquia_lift.settings']['credential']['site_id'] = ''; // Customer Site ID
      $config['acquia_lift.settings']['credential']['content_origin'] = ''; // Limit deployable content to a Site by its Content Hub Origin ID
      $config['acquia_lift.settings']['advanced']['content_replacement_mode'] = 'trusted'; // Default slot content replacement mode
      //Acquia Content Hub Module Settings
      $config['acquia_contenthub.admin_settings']['api_key'] = ''; // Customer Content Hub API Key
      $config['acquia_contenthub.admin_settings']['secret_key'] = ''; // Customer Content Hub Secret Key
      $config['acquia_contenthub.admin_settings']['client_name'] = ''; // Customer Site ID
      $config['acquia_contenthub.admin_settings']['origin'] = ''; // Content Hub Origin ID (UUID)
      break;
  }
}


// Disable Content Hub in Local development environment

if ($is_local_env) {
  $config['acquia_lift.settings']['credential']['account_id'] = 'local';
  $config['acquia_contenthub.admin_settings']['origin'] = 'Not connected';
}