You are here

function invite_update_8 in Invite 5

Same name and namespace in other branches
  1. 5.2 invite.install \invite_update_8()
  2. 6.2 invite.install \invite_update_8()
  3. 7.2 invite.install \invite_update_8()

Change message to a generic data column and convert existing messages.

File

./invite.install, line 228

Code

function invite_update_8() {
  $ret = array();

  // Add column data first
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {invite} ADD COLUMN data TEXT NOT NULL");
      break;
    case 'pgsql':
      db_add_column($ret, 'invite', 'data', 'TEXT', array(
        'not null' => TRUE,
        'default' => "''",
      ));
      break;
  }

  // Convert existing messages
  $result = db_query("SELECT reg_code, message FROM {invite} WHERE message != ''");
  while ($row = db_fetch_object($result)) {
    if (substr($row->message, 0, 2) == 'a:') {

      // Already serialized
      continue;
    }
    $data = array(
      'subject' => NULL,
      'message' => $row->message,
    );
    db_query("UPDATE {invite} SET data = '%s' WHERE reg_code = '%s'", serialize($data), $row->reg_code);
  }

  // Finally drop column message
  $ret[] = update_sql("ALTER TABLE {invite} DROP message");
  return $ret;
}