You are here

function eu_cookie_compliance_update_7017 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_7017()

Migrate categories from string to array.

File

./eu_cookie_compliance.install, line 643
Installation file.

Code

function eu_cookie_compliance_update_7017() {
  $settings = variable_get('eu_cookie_compliance', array());
  $categories = $settings['cookie_categories'];
  if (!is_array($categories)) {

    // Split the string by new line and pipes and transform into array.
    $categories = _eu_cookie_compliance_extract_category_key_label_description($categories);
    $categories = _migrate_cookie_categories_to_separate_structure($categories, $settings);
  }

  // Store categories in a new variable.
  variable_set('eu_cookie_compliance_categories', $categories);

  // Remove legacy values from main variable.
  unset($settings['cookie_categories']);
  unset($settings['fix_first_cookie_category']);
  variable_set('eu_cookie_compliance', $settings);
  if (module_exists('i18n_variable')) {
    $languages = language_list();
    foreach (array_keys($languages) as $langcode) {
      $settings = variable_realm_get('language', $langcode, 'eu_cookie_compliance', array());
      $categories = $settings['cookie_categories'];
      if (!is_array($categories)) {

        // Split the string by new line and pipes and transform into array.
        $categories = _eu_cookie_compliance_extract_category_key_label_description($categories);
        $categories = _migrate_cookie_categories_to_separate_structure($categories, $settings);
      }

      // Store categories in a new variable.
      variable_realm_set('language', $langcode, 'eu_cookie_compliance_categories', $categories, FALSE);

      // Remove legacy values from main variable.
      unset($settings['cookie_categories']);
      unset($settings['fix_first_cookie_category']);
      variable_realm_set('language', $langcode, 'eu_cookie_compliance', $settings, FALSE);
    }
  }

  // Set 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'];
      $settings = domain_conf_variable_get($domain_id, 'eu_cookie_compliance');
      $categories = $settings['cookie_categories'];
      if (!is_array($categories)) {

        // Split the string by new line and pipes and transform into array.
        $categories = _eu_cookie_compliance_extract_category_key_label_description($categories);
        $categories = _migrate_cookie_categories_to_separate_structure($categories, $settings);
      }

      // Store categories in a new variable.
      domain_conf_variable_save($domain_id, 'eu_cookie_compliance_categories', $categories);

      // Remove legacy values from main variable.
      unset($settings['cookie_categories']);
      unset($settings['fix_first_cookie_category']);
      domain_conf_variable_save($domain_id, 'eu_cookie_compliance', $settings);
    }
  }
}