You are here

function i18nblocks_update_1 in Internationalization 5.2

Same name and namespace in other branches
  1. 5.3 i18nblocks/i18nblocks.install \i18nblocks_update_1()
  2. 5 i18nblocks/i18nblocks.install \i18nblocks_update_1()
  3. 6 i18nblocks/i18nblocks.install \i18nblocks_update_1()

Update: move old variable to new tables

File

i18nblocks/i18nblocks.install, line 50

Code

function i18nblocks_update_1() {
  $ret = array();
  require_once drupal_get_path('module', 'i18nblocks') . '/i18nblocks.module';
  require_once drupal_get_path('module', 'i18n') . '/i18n.module';

  // Create the tables if updating from previous version
  i18nblocks_install();

  // Move old data from variables into new tables
  $languages = i18n_supported_languages();
  if ($number = variable_get('i18nblocks_number', 0)) {
    for ($delta = 1; $delta <= $number; $delta++) {
      if ($block = variable_get('i18nblocks_' . $delta, NULL)) {
        $update = update_sql("INSERT INTO {i18n_blocks}(delta) VALUES('" . db_escape_string($delta) . "')");
        $ret[] = $update;
        $metablock = array();
        if ($update['success']) {
          $metablock['delta'] = $delta;
        }
        $metablock['info'] = isset($block['name']) ? $block['name'] : '';
        $metablock['i18nblocks'] = array();
        foreach (array_keys($languages) as $lang) {
          if (isset($block[$lang]) && isset($block[$lang]['module']) && isset($block[$lang]['delta'])) {
            $metablock['i18nblocks'][$lang] = $block[$lang]['module'] . ':' . $block[$lang]['delta'];
          }
        }
      }
      i18nblocks_save($metablock);
    }
    drupal_set_message('The i18nblocks have been updated. Please, review your block settings.');
  }
  return $ret;
}