You are here

function front_page_update_7200 in Front Page 7.2

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

File

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

Code

function front_page_update_7200() {
  if (!db_table_exists('front_page')) {
    $schema = drupal_get_schema_unprocessed('front_page');
    _drupal_schema_initialize($schema, 'front_page', FALSE);
    if (isset($schema['front_page'])) {
      db_create_table('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 = isset($formats['php_code']) ? 'php_code' : $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;
        db_merge('front_page')
          ->key(array(
          'rid' => $rid,
        ))
          ->fields(array(
          'mode' => $mode,
          'data' => $data,
          'filter_format' => $format,
          'weight' => $weight,
        ))
          ->execute();
        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');
  }
}