You are here

function fontyourface_update_6200 in @font-your-face 6.2

Same name and namespace in other branches
  1. 7 fontyourface.install \fontyourface_update_6200()

Implements hook_update_N().

File

./fontyourface.install, line 203
Adds fontyourface tables for tracking fonts.

Code

function fontyourface_update_6200() {
  $return = array();

  // Get old fonts
  $old_fonts = array();
  $old_fonts_sql = 'SELECT * FROM {fontyourface}';
  $old_font_results = db_query($old_fonts_sql);
  while ($old_font = db_fetch_object($old_font_results)) {
    $old_fonts[] = $old_font;
  }

  // while
  // Drop old table.
  db_drop_table($return, 'fontyourface');

  // Drop provider tables from old version (may not all be there).
  if (db_table_exists('fontsquirrel_group')) {
    db_drop_table($return, 'fontsquirrel_group');
  }

  // if
  if (db_table_exists('kernest')) {
    db_drop_table($return, 'kernest');
  }

  // if
  if (db_table_exists('typekit_api_variant')) {
    db_drop_table($return, 'typekit_api_variant');
  }

  // if
  // Add tables.
  $schema = fontyourface_6200_schema();
  db_create_table($return, 'fontyourface_font', $schema['fontyourface_font']);
  db_create_table($return, 'fontyourface_tag', $schema['fontyourface_tag']);
  db_create_table($return, 'fontyourface_tag_font', $schema['fontyourface_tag_font']);
  drupal_get_schema('fontyourface_font', TRUE);
  drupal_get_schema('fontyourface_tag', TRUE);
  drupal_get_schema('fontyourface_tag_font', TRUE);

  // Import from any used providers.
  $used_providers = array();
  foreach ($old_fonts as $old_font) {
    $used_providers[$old_font->provider] = TRUE;
  }

  // foreach
  $used_providers = array_keys($used_providers);
  foreach ($used_providers as $used_provider) {
    $import_function = $used_provider . '_fontyourface_import';
    if (function_exists($import_function)) {
      $import_function();
    }

    // if
  }

  // foreach
  // Re-enable fonts.
  foreach ($old_fonts as $old_font) {
    $new_fonts = fontyourface_get_fonts("provider = '" . $old_font->provider . "' AND name = '" . $old_font->name . "'");
    if (count($new_fonts) > 0) {
      $new_font = $new_fonts[0];
      fontyourface_enable_font($new_font);
      fontyourface_set_css_selector($new_font, $old_font->css);
    }

    // if
  }

  // foreach
  return $return;
}