You are here

function _quotes_update_taxonomy in Quotes 7

1 call to _quotes_update_taxonomy()
quotes_update_7001 in ./quotes.install
Update taxonomy or add a default vocabulary for quotes.

File

./quotes.install, line 456
Handles installation and updates for the quotes module.

Code

function _quotes_update_taxonomy($instance) {
  $revision_name = "field_revision_{$instance}";
  if (!db_table_exists($revision_name)) {
    return;
  }
  $query = db_select($revision_name, 'tr');
  $query
    ->addField('tr', 'deleted');
  $query
    ->addField('tr', 'entity_id', 'nid');
  $query
    ->addField('tr', 'revision_id', 'vid');
  $query
    ->addField('tr', 'language');
  $query
    ->addField('tr', 'delta');
  $query
    ->addField('tr', "{$instance}_tid", 'tid');
  $fields = $query
    ->condition('bundle', 'quotes')
    ->execute();
  if ($fields) {
    foreach ($fields as $record) {
      $field_name = 'taxonomy_quotes';
      $table_name = "field_data_{$field_name}";
      $revision_name = "field_revision_{$field_name}";
      $value_column = $field_name . '_tid';

      // Column names and values in field storage are the same for current and
      // revision.
      $columns = array(
        'entity_type',
        'entity_id',
        'revision_id',
        'bundle',
        'deleted',
        'language',
        'delta',
        $value_column,
      );
      $values = array(
        'node',
        $record->nid,
        $record->vid,
        'quotes',
        $record->deleted,
        LANGUAGE_NONE,
        $record->delta,
        $record->tid,
      );

      // Insert rows into the revision table.
      db_insert($revision_name)
        ->fields($columns)
        ->values($values)
        ->execute();

      // Insert rows into the table.
      db_insert($table_name)
        ->fields($columns)
        ->values($values)
        ->execute();
    }
    _update_7000_field_delete_instance($instance, 'node', 'quotes');
  }
}