You are here

function front_page_update_6200 in Front Page 6.2

Update 6200 - Add table if not already added, transfer data into the table and correct special notice times.

File

./front_page.install, line 78
Install, update and uninstall functions for the front page module.

Code

function front_page_update_6200() {
  $ret = array();
  if (!db_table_exists('front_page')) {
    $schema = drupal_get_schema_unprocessed('front_page');
    _drupal_initialize_schema('front_page', $schema);
    if (isset($schema['front_page'])) {
      db_create_table($ret, 'front_page', $schema['front_page']);
    }

    // need to add front page data from variables table to new table.
    $formats = filter_formats();
    $formats = drupal_map_assoc(array_keys($formats));
    $default_format = array_shift($formats);
    $php_format = db_result(db_query("SELECT format FROM {filter_formats} WHERE name='PHP code'"));
    if (empty($php_format)) {
      $php_format = $default_format;
    }
    $roles = user_roles();
    foreach ($roles as $rid => $role_name) {
      $mode = variable_get('front_' . $rid . '_type', '');
      if (!empty($mode)) {
        switch ($mode) {
          case 'themed':
          case 'full':
            $data = variable_get('front_' . $rid . '_text', '');
            $format = $default_format;
            if (variable_get('front_' . $rid . '_php', 0)) {
              $format = $php_format;
            }
            break;
          case 'redirect':
          case 'alias':
            $data = variable_get('front_' . $rid . '_redirect', '');
            $format = '';
            break;
          default:
            $mode = '';
            $format = '';
            $data = '';
            break;
        }
        $weight = $rid * -1;
        $ret[] = update_sql("INSERT INTO {front_page} (rid, mode, data, filter_format, weight) VALUES ({$rid}, '{$mode}', '{$data}', '{$format}', {$weight})");
        variable_del('front_' . $rid . '_type');
        variable_del('front_' . $rid . '_text');
        variable_del('front_' . $rid . '_php');
        variable_del('front_' . $rid . '_redirect');
      }
    }
  }
  if (variable_get('site_frontpage', 'node') == 'front_page') {
    variable_set('site_frontpage', 'node');
  }
  return $ret;
}