You are here

function download_count_update_7300 in Download Count 7.3

Alter download count table.

File

./download_count.install, line 163
Installation code for the download_count module.

Code

function download_count_update_7300() {

  // We do not want to create type field again after module installation.
  if (!db_field_exists('download_count', 'type')) {

    // Create type field.
    $spec = array(
      'description' => 'The name of the entity type to which the file was attached when downloaded.',
      'type' => 'varchar',
      'length' => 64,
      'not null' => TRUE,
      'default' => '',
    );
    db_add_field('download_count', 'type', $spec);

    // Enter value to type field.
    // In 6 version there we were storing node ids from where file has been
    // downloaded.
    // Hence, setting type field value to node for all entries.
    $rows_updated = db_update('download_count')
      ->fields(array(
      'type' => 'node',
    ))
      ->execute();
    drupal_set_message(t('Download types set for') . ' ' . $rows_updated . ' ' . t('rows'));
  }

  // There will be no nid field after module installation.
  if (!db_field_exists('download_count', 'id') && db_field_exists('download_count', 'nid')) {

    // Alter nid field of download_count table.
    db_change_field('download_count', 'nid', 'id', array(
      'description' => 'The name of the entity type to which the file was attached when downloaded.',
      'type' => 'varchar',
      'length' => 64,
      'not null' => TRUE,
      'default' => '',
    ), array(
      'indexes' => array(
        'dc_fid' => array(
          'fid',
        ),
        'dc_uid' => array(
          'uid',
        ),
        'dc_type' => array(
          'type',
        ),
        'dc_id' => array(
          'id',
        ),
        'dc_ip' => array(
          'ip_address',
        ),
        'dc_timestamp' => array(
          'timestamp',
        ),
        'dc_fid_type_id' => array(
          'fid',
          'type',
          'id',
        ),
      ),
    ));
  }
}