You are here

function xmlsitemap_user_update_6100 in XML sitemap 6

Implementation of hook_update_N().

File

xmlsitemap_user/xmlsitemap_user.install, line 103
Installation file for XML sitemap user.

Code

function xmlsitemap_user_update_6100() {
  $ret = array();
  if (db_table_exists('xmlsitemap_user')) {
    if (db_column_exists('xmlsitemap_user', 'pid')) {
      $result = array();
      @db_drop_index($result, 'xmlsitemap_user', 'pid');
      if ($result[0]['success']) {
        $ret = $result[0];
      }
      db_drop_field($ret, 'xmlsitemap_user', 'pid');
    }
    if (db_column_exists('xmlsitemap_user', 'uid')) {
      $result = array();
      @db_drop_primary_key($result, 'xmlsitemap_user');
      if ($result[0]['success']) {
        $ret[] = $result[0];
      }
      db_change_field($ret, 'xmlsitemap_user', 'uid', 'uid', array(
        'description' => 'The user ID.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ), array(
        'primary key' => array(
          'uid',
        ),
      ));
    }
    if (db_column_exists('xmlsitemap_user', 'last_changed')) {
      db_change_field($ret, 'xmlsitemap_user', 'last_changed', 'changed', array(
        'description' => 'The Unix timestamp of the last change.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ));
    }
    else {
      if (db_column_exists('xmlsitemap_user', 'changed')) {
        db_change_field($ret, 'xmlsitemap_user', 'changed', 'changed', array(
          'description' => 'The Unix timestamp of the last change.',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0,
        ));
      }
      else {
        db_add_field($ret, 'xmlsitemap_user', 'changed', array(
          'description' => 'The Unix timestamp of the last change.',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0,
        ));
      }
    }
    if (!db_column_exists('xmlsitemap_user', 'comments')) {
      db_add_field($ret, 'xmlsitemap_user', 'comments', array(
        'description' => 'The number of comments authored from the user.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ));
    }
    $ret[] = update_sql("UPDATE {xmlsitemap_user}\n      SET priority_override = -2.0\n      WHERE priority_override IS NULL");
    db_change_field($ret, 'xmlsitemap_user', 'priority_override', 'priority_override', array(
      'description' => 'The priority of the term in the sitemap.',
      'type' => 'float',
      'not null' => TRUE,
      'default' => -2.0,
    ));
  }
  else {
    db_create_table($ret, 'xmlsitemap_user', array(
      'description' => 'The base table for xmlsitemap_user.',
      'fields' => array(
        'uid' => array(
          'description' => 'The user ID.',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0,
        ),
        'changed' => array(
          'description' => 'The Unix timestamp of the last change.',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0,
        ),
        'previously_changed' => array(
          'description' => 'The Unix timestamp of the previous change.',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0,
        ),
        'comments' => array(
          'description' => 'The number of comments authored from the user.',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0,
        ),
        'priority_override' => array(
          'description' => 'The priority of the term in the sitemap.',
          'type' => 'float',
          'not null' => TRUE,
          'default' => -2.0,
        ),
      ),
      'primary key' => array(
        'uid',
      ),
    ));
  }
  if (db_table_exists('xmlsitemap_user_role')) {
    if (db_column_exists('xmlsitemap_user_role', 'pid')) {
      $result = array();
      @db_drop_index($result, 'xmlsitemap_user_role', 'pid');
      if ($result[0]['success']) {
        $ret = $result[0];
      }
      db_drop_field($ret, 'xmlsitemap_user_role', 'pid');
    }
    $result = array();
    @db_drop_primary_key($result, 'xmlsitemap_user_role');
    if ($result[0]['success']) {
      $ret[] = $result[0];
    }
    db_change_field($ret, 'xmlsitemap_user_role', 'rid', 'rid', array(
      'description' => 'The role ID.',
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
    ), array(
      'primary key' => array(
        'rid',
      ),
    ));
    $ret[] = update_sql("UPDATE {xmlsitemap_user_role}\n      SET priority = 0.5\n      WHERE priority IS NULL");
    db_change_field($ret, 'xmlsitemap_user_role', 'priority', 'priority', array(
      'description' => t('The priority assigned to the role.'),
      'type' => 'float',
      'not null' => TRUE,
      'default' => 0.5,
    ));
    db_change_field($ret, 'xmlsitemap_user_role', 'priority', 'priority', array(
      'description' => t('The priority assigned to the role.'),
      'type' => 'float',
      'not null' => TRUE,
      'default' => 0.5,
    ));
  }
  else {
    db_create_table($ret, 'xmlsitemap_user_role', array(
      'description' => 'The base table for xmlsitemap.',
      'fields' => array(
        'rid' => array(
          'description' => 'The role ID.',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0,
        ),
        'priority' => array(
          'description' => t('The priority assigned to the role.'),
          'type' => 'float',
          'not null' => TRUE,
          'default' => 0.5,
        ),
      ),
      'primary key' => array(
        'rid',
      ),
    ));
  }
  return $ret;
}