You are here

public function VariablesController::getVariablesData in Acquia Connector 8

Same name and namespace in other branches
  1. 8.2 src/Controller/VariablesController.php \Drupal\acquia_connector\Controller\VariablesController::getVariablesData()
  2. 3.x src/Controller/VariablesController.php \Drupal\acquia_connector\Controller\VariablesController::getVariablesData()

Get all system variables.

Return value

string Variables values keyed by the variable name.

File

src/Controller/VariablesController.php, line 123

Class

VariablesController
Class MappingController.

Namespace

Drupal\acquia_connector\Controller

Code

public function getVariablesData() {

  // Send SPI definition timestamp to see if the site needs updates.
  $data = [
    'acquia_spi_def_timestamp' => $this
      ->state()
      ->get('acquia_spi_data.def_timestamp', 0),
  ];
  $variables = [
    'acquia_spi_send_node_user',
    'acquia_spi_admin_priv',
    'acquia_spi_send_watchdog',
    'acquia_spi_use_cron',
    'cache_backends',
    'cache_default_class',
    'cache_inc',
    'cron_safe_threshold',
    'googleanalytics_cache',
    'error_level',
    'preprocess_js',
    'page_cache_maximum_age',
    'block_cache',
    'preprocess_css',
    'page_compression',
    'cron_last',
    'clean_url',
    'redirect_global_clean',
    'theme_zen_settings',
    'site_offline',
    'site_name',
    'user_register',
    'user_signatures',
    'user_admin_role',
    'user_email_verification',
    'user_cancel_method',
    'filter_fallback_format',
    'dblog_row_limit',
    'date_default_timezone',
    'file_default_scheme',
    'install_profile',
    'maintenance_mode',
    'update_last_check',
    'site_default_country',
    'acquia_spi_saved_variables',
    'acquia_spi_set_variables_automatic',
    'acquia_spi_ignored_set_variables',
    'acquia_spi_set_variables_override',
    'http_response_debug_cacheability_headers',
  ];
  $spi_def_vars = $this
    ->state()
    ->get('acquia_spi_data.def_vars', []);
  $waived_spi_def_vars = $this
    ->state()
    ->get('acquia_spi_data.def_waived_vars', []);

  // Merge hard coded $variables with vars from SPI definition.
  foreach ($spi_def_vars as $var_name => $var) {
    if (!in_array($var_name, $waived_spi_def_vars) && !in_array($var_name, $variables)) {
      $variables[] = $var_name;
    }
  }
  foreach ($variables as $name) {
    try {
      $data[$name] = $this
        ->getVariableValue($name);
    } catch (\UnexpectedValueException $e) {

      // Variable does not exist.
    }
  }

  // Unset waived vars so they won't be sent to NSPI.
  foreach ($data as $var_name => $var) {
    if (in_array($var_name, $waived_spi_def_vars)) {
      unset($data[$var_name]);
    }
  }

  // Collapse to JSON string to simplify transport.
  return Json::encode($data);
}