user_stats.install 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * @file
  4. * Install and update hooks for the User Stats module.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function user_stats_schema() {
  10. $schema['user_stats_values'] = array(
  11. 'description' => 'User Stats data.',
  12. 'fields' => array(
  13. 'name' => array(
  14. 'type' => 'varchar',
  15. 'length' => 128,
  16. 'not null' => TRUE,
  17. 'default' => '',
  18. 'description' => 'The name of the statistic.',
  19. ),
  20. 'uid' => array(
  21. 'type' => 'int',
  22. 'unsigned' => TRUE,
  23. 'not null' => TRUE,
  24. 'default' => 0,
  25. 'description' => 'The {users}.uid of the statistic user.',
  26. ),
  27. 'value' => array(
  28. 'type' => 'int',
  29. 'not null' => TRUE,
  30. 'default' => 0,
  31. 'description' => 'The value of the statistic.',
  32. ),
  33. ),
  34. 'primary key' => array('name', 'uid'),
  35. );
  36. $schema['user_stats_ips'] = array(
  37. 'description' => 'IP address storage, links timestamps and uids to IP',
  38. 'fields' => array(
  39. 'iid' => array(
  40. 'type' => 'serial',
  41. 'not null' => TRUE,
  42. 'description' => 'Primary key: IP address unique ID.',
  43. ),
  44. 'uid' => array(
  45. 'type' => 'int',
  46. 'unsigned' => TRUE,
  47. 'not null' => TRUE,
  48. 'default' => 0,
  49. 'description' => 'The {users}.uid of the user.',
  50. ),
  51. 'ip_address' => array(
  52. 'type' => 'varchar',
  53. 'length' => 40,
  54. 'not null' => TRUE,
  55. 'default' => '',
  56. 'description' => "The user's IP address.",
  57. ),
  58. 'first_seen_timestamp' => array(
  59. 'description' => 'The Unix timestamp when the IP address was first used by this user.',
  60. 'type' => 'int',
  61. 'not null' => TRUE,
  62. 'default' => 0,
  63. ),
  64. ),
  65. 'primary key' => array('iid'),
  66. 'indexes' => array(
  67. 'uid' => array('uid'),
  68. 'first_seen_timestamp' => array('first_seen_timestamp'),
  69. ),
  70. );
  71. return $schema;
  72. }
  73. /**
  74. * Implements hook_uninstall().
  75. */
  76. function user_stats_uninstall() {
  77. variable_del('user_stats_rebuild_stats');
  78. variable_del('user_stats_last_cron_check');
  79. variable_del('user_stats_included_content_types');
  80. variable_del('user_stats_reset_login_count');
  81. variable_del('user_stats_reset_post_count');
  82. variable_del('user_stats_user_per_cron');
  83. variable_del('user_stats_count_posts');
  84. variable_del('user_stats_count_comments');
  85. variable_del('user_stats_count_logins');
  86. }
  87. /**
  88. * Expands the width of the field table to 40.
  89. */
  90. function user_stats_update_7102(&$sandbox) {
  91. $ip_address = array(
  92. 'type' => 'varchar',
  93. 'length' => 40,
  94. 'not null' => TRUE,
  95. 'default' => '',
  96. 'description' => "The user's IP address.",
  97. );
  98. db_change_field('user_stats_ips', 'ip_address', 'ip_address', $ip_address);
  99. }