<?php
// $Id$

/**
 * @file
 * Install file for Stalker module
 */

/**
 * Implementation of hook_schema().
 *
 * Describe the module's data model as an associative array. This removes
 * the requirement to write database-specific SQL to create tables.
 *
 * For full details: http://drupal.org/node/146843
 */
function stalker_schema() {
  $schema = array();

  $schema['stalker'] = array(
    'description' => t('Contain counter information for profile views.'),
    'fields' => array(
      'stalker_uid' => array(
        'description' => t('The {users}.uid of the user viewing a profile.'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'profile_uid' => array(
        'description' => t('The {users}.uid of the profile being viewed.'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'view_count' => array(
        'description' => t('Simple counter per user.'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'last_stalked' => array(
        'description' => t('The last time this user stalked.'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array('stalker_uid', 'profile_uid'),
  );


  return $schema;
}

/**
 * Implementation of hook_install().
 *
 * Perform initial setup tasks.
 */
function stalker_install() {
  drupal_install_schema('stalker');
}


/**
 * Implementation of hook_uninstall().
 *
 * Perform final clean-up tasks.
 */
function stalker_uninstall() {
  drupal_uninstall_schema('stalker');
}
 
 
 
/**
 * Implementation of an update hook.
 */
function stalker_update_6001() {
  $ret = array();

  $spec = array(
    'description' => t('The last time this user stalked.'),
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  );

  db_add_field($ret, 'stalker', 'last_stalked', $spec);

  $ret[] = update_sql("DELETE FROM {stalker} WHERE view_count < 0");

  return $ret;
}
 
 
 













