You are here

function fontyourface_update_7201 in @font-your-face 7.2

Distinct subsets from tags using an extra 'type' column.

File

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

Code

function fontyourface_update_7201() {
  views_invalidate_cache();

  // Add new column to schema.
  $schema = fontyourface_7200_schema();
  db_add_field('fontyourface_tag', 'type', $schema['fontyourface_tag']['fields']['type']);

  // Convert existing Google Fonts tags to subsets
  $query = db_select('fontyourface_tag', 't');
  $query
    ->innerJoin('fontyourface_tag_font', 'tf', 'tf.tid = t.tid');
  $query
    ->innerJoin('fontyourface_font', 'f', 'f.fid = tf.fid');
  $query
    ->distinct();
  $result = $query
    ->fields('t', array(
    'tid',
  ))
    ->condition('f.provider', 'google_fonts_api')
    ->execute();
  foreach ($result as $font) {
    db_update('fontyourface_tag')
      ->fields(array(
      'type' => 'subset',
    ))
      ->condition('tid', $font->tid)
      ->execute();
  }

  // foreach
}