<?php

/**
 * @file
 * Provides any required installation or upgrade path requirements.
 */

/**
 * Implementation of hook_schema().
 */
function disqus_schema() {
  $schema = array();
  $schema['disqus'] = array(
    'fields' => array(
      'did' => array(
        'type' => 'serial',
        'not null' => TRUE,
      ),
      'nid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'status' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array('did'),
    'indexes' => array(
      'nid' => array('nid'),
      'status' => array('status'),
    ),
  );
  return $schema;
}

/**
 * Implements hook_uninstall().
 */
function disqus_uninstall() {
  $variables = array(
    'disqus_combination_widget_colortheme',
    'disqus_combination_widget_defaulttabview',
    'disqus_combination_widget_excerpt_length',
    'disqus_combination_widget_hide_mods',
    'disqus_combination_widget_items',
    'disqus_developer',
    'disqus_domain',
    'disqus_inherit_login',
    'disqus_localization',
    'disqus_location',
    'disqus_logo',
    'disqus_nodetypes',
    'disqus_popular_threads_items',
    'disqus_publickey',
    'disqus_recent_comments_avatarsize',
    'disqus_recent_comments_excerpt_length',
    'disqus_recent_comments_items',
    'disqus_recent_comments_showavatars',
    'disqus_secretkey',
    'disqus_sso',
    'disqus_top_commenters_avatarsize',
    'disqus_top_commenters_hide_mods',
    'disqus_top_commenters_items',
    'disqus_top_commenters_showavatars',
    'disqus_use_site_logo',
    'disqus_weight',
  );
  foreach ($variables as $variable) {
    variable_del($variable);
  }
}

/**
 * Updates from Drupal 6 to 7.
 */
function disqus_update_7000() {
  // Nothing.
}

/**
 * Updates Disqus with support for toggling comments per node.
 */
function disqus_update_7001() {
  if (!db_table_exists('disqus')) {
    drupal_install_schema('disqus');
  }
}


/**
 * Remove deprecated variable.
 */
function disqus_update_7002() {
  variable_del('disqus_userapikey');
}
