<?php
// $Id: false_account.install,v 1.3.4.2 2009/01/07 14:52:33 nunoveloso18 Exp $

/**
 * @file
 * Schema installation for false account module
 */

/**
 * Implementation of hook_install()
 */
function false_account_install() {
  $created = drupal_install_schema('false_account');

  if ($created[0]['success']) {
    drupal_set_message(t('False Account module installed successfully.'));
  }
  else {
    drupal_set_message(t('Table installation for the False Accounts module was unsuccessful.'), 'error');
  }
}


/**
 * Implementation of hook_uninstall().
 */
function false_account_uninstall() {
  drupal_uninstall_schema('false_account');
}


/**
 * Implementation of hook_update_N()
 * new DB structure
 */
function false_account_update_1() {

  $return = array();
  $done = array();
  
  $result = db_query('
    SELECT cid, created
    FROM {false_accounts}
    GROUP BY cid 
    ORDER BY created DESC'
  );
  
  while ($cookie = db_fetch_object($result)) {
    $done[] = db_query('
      UPDATE {false_accounts} 
      SET created = %d
      WHERE cid = "%s"',
      $cookie->created, $cookie->cid
    );
  }

  if (! in_array(false, $done)) {
    drupal_set_message(t('False Account module upgraded successfully.'));
  }
  else {
    drupal_set_message(t('Table upgrade for the False Accounts module was unsuccessful.'), 
      'error');
  }
  return $return;
}


/**
 * Implementation of hook_schema()
 */
function false_account_schema() {
  $schema['false_accounts'] = array(
    'fields' => array(
      'cid' => array('type' => 'varchar', 'length' => '64', 'not null' => TRUE),
      'uid' => array('type' => 'int', 'not null' => TRUE, 'disp-width' => '10'),
      'created' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 
        'disp-width' => '11'),
      'status' => array('type' => 'int', 'unsigned' => TRUE, 'size' => 'tiny', 'not null' => TRUE, 
        'default' => 0, 'disp-width' => '3')
    ),
    'primary key' => array('cid', 'uid'),
  );
  
  return $schema;
}


