You are here

function eu_cookie_compliance_update_7013 in EU Cookie Compliance (GDPR Compliance) 7

Same name and namespace in other branches
  1. 7.2 eu_cookie_compliance.install \eu_cookie_compliance_update_7013()

Add any missing defaults to sites with i18n or domain settings enabled.

File

./eu_cookie_compliance.install, line 521
Installation file.

Code

function eu_cookie_compliance_update_7013() {

  // Get defaults.
  $default_settings = _eu_cookie_compliance_get_popup_default_setting();

  // Add any missing configuration defaults to the regular variable.
  $updated_settings = variable_get('eu_cookie_compliance', array()) + $default_settings;
  variable_set('eu_cookie_compliance', $updated_settings);

  // Set any missing configuration variables for all languages.
  if (module_exists('i18n_variable')) {
    $languages = language_list();
    foreach (array_keys($languages) as $langcode) {
      $settings = i18n_variable_get('eu_cookie_compliance', $langcode);
      if (!empty($settings)) {
        $updated_settings = $settings + $default_settings;
        variable_realm_set('language', $langcode, 'eu_cookie_compliance', $updated_settings, FALSE);
      }
    }
  }

  // Set any missing configuration variables for all domains.
  if (module_exists('domain_settings') && module_exists('domain_conf')) {
    $domains = domain_domains();
    foreach ($domains as $domain_data) {
      $domain_id = $domain_data['domain_id'];

      // Check whether we have eu_cookie_compliance or eu_cookie_compliance_en.
      $all_domain_settings = domain_conf_data_get($domain_id);
      $key = FALSE;
      if (array_key_exists('eu_cookie_compliance', $all_domain_settings)) {
        $key = 'eu_cookie_compliance';
      }
      else {
        if (array_key_exists('eu_cookie_compliance_' . language_default('language'), $all_domain_settings)) {
          $key = 'eu_cookie_compliance_' . language_default('language');
        }
      }
      if ($key) {
        $settings = domain_conf_variable_get($domain_id, $key);
        $updated_settings = $settings + $default_settings;
        domain_conf_variable_save($domain_id, 'eu_cookie_compliance', $updated_settings);
      }
    }
  }
}