You are here

function background_process_determine_and_save_default_service_host in Background Process 8

Same name and namespace in other branches
  1. 6 background_process.module \background_process_determine_and_save_default_service_host()
  2. 7 background_process.module \background_process_determine_and_save_default_service_host()

Implements to Determines the default service host.

3 calls to background_process_determine_and_save_default_service_host()
background_process_init in ./background_process.module
Implements hook_init().
background_process_settings_form_determine_submit in ./background_process.admin.inc
Implements Submit handler for determining default service host.
InitSubscriber::onEvent in src/EventSubscriber/InitSubscriber.php
Implements On Event.

File

./background_process.module, line 1251
This module implements a framework for calling funtions in the background.

Code

function background_process_determine_and_save_default_service_host() {
  $host = background_process_determine_default_service_host();
  if ($host) {
    global $base_url;
    drupal_set_message(t('Default service host determined at %base_url', [
      '%base_url' => _background_process_secure_url($host['base_url']),
    ]));
    if ($host['base_url'] === $base_url) {
      \Drupal::config('background_process.settings')
        ->clear('background_process_derived_default_host')
        ->save();
    }
    else {
      \Drupal::configFactory()
        ->getEditable('background_process.settings')
        ->set('background_process_derived_default_host', [
        'default' => $host,
      ])
        ->save();
      drupal_set_message(t('Default service host differs from base url (%base_url). If migrating database to other sites or environments, you will need to either run "Determine default service host" again, or configure the default service host manually through settings.php', [
        '%base_url' => $base_url,
      ]), 'warning');
    }
    return TRUE;
  }
  else {
    drupal_set_message(t('Could not determine default service host. Please configure background process in your settings.php'), 'error');
    return FALSE;
  }
}