You are here

sms_user.install in SMS Framework 5

File

modules/sms_user/sms_user.install
View source
<?php

function sms_user_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {sms_user} (\n        uid int(10) NOT NULL,\n        delta varchar(32),\n        number varchar(32) NOT NULL,\n        status tinyint(4) NOT NULL,\n        code varchar(4) NOT NULL,\n        gateway longtext,\n        PRIMARY KEY (uid, delta),\n        UNIQUE KEY number (number)\n      ) /*!40100 DEFAULT CHARACTER SET utf8 */ ");
      break;
  }
}

/**
 * Implementation of hook_uninstall().
 */
function sms_user_uninstall() {
  if (db_table_exists('sms_user')) {
    db_query('DROP TABLE {sms_user}');
  }
  drupal_set_message(t('SMS User uninstalled successfully.'));
}

/**
 * Update: Storing user numbers in separate table
 */
function sms_user_update_1() {
  $ret = array();

  // Add table
  $ret[] = update_sql("CREATE TABLE {sms_user} (\n    uid int(10) NOT NULL,\n    delta varchar(32),\n    number varchar(32) NOT NULL,\n    status tinyint(4) NOT NULL,\n    code varchar(4) NOT NULL,\n    gateway longtext,\n    PRIMARY KEY (uid, delta),\n    UNIQUE KEY number (number)\n  ) /*!40100 DEFAULT CHARACTER SET utf8 */ ");
  $result = db_query("SELECT uid, data FROM {users} WHERE uid <> 0");
  while ($user = db_fetch_array($result)) {
    $data = unserialize($user['data']);
    if ($data['sms_user']) {
      $sms_data = $data['sms_user'];
      db_query("INSERT INTO {sms_user} (number, status, code, gateway, uid, delta) VALUES ('%s', %d, '%s', '%s', %d, %d)", array(
        $sms_data['number'],
        $sms_data['status'],
        $sms_data['code'],
        serialize($sms_data['gateway']),
        $user['uid'],
        0,
      ));
      unset($data['sms_user']);
      $ret[] = update_sql("UPDATE {users} SET data = '" . serialize($data) . "' WHERE uid = " . $user['uid']);
    }
  }
  return $ret;
}

Functions

Namesort descending Description
sms_user_install
sms_user_uninstall Implementation of hook_uninstall().
sms_user_update_1 Update: Storing user numbers in separate table