summaryrefslogtreecommitdiff
path: root/modules/statistics/statistics.install
blob: 93cfc8c5f18390648f09396d24fcc43dca136909 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
// $Id$

/**
 * Implementation of hook_install().
 */
function statistics_install() {
  // Create tables.
  drupal_install_schema('statistics');
}

/**
 * Changes session ID  field to VARCHAR(64) to add support for SHA-1 hashes.
 */
function statistics_update_1000() {
  $ret = array();

  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {accesslog} CHANGE COLUMN sid sid varchar(64) NOT NULL default ''");
      break;
    case 'pgsql':
      db_change_column($ret, 'accesslog', 'sid', 'sid', 'varchar(64)', array('not null' => TRUE, 'default' => "''"));
      break;
  }

  return $ret;
}

/**
 * Implementation of hook_uninstall().
 */
function statistics_uninstall() {
  // Remove tables.
  drupal_uninstall_schema('statistics');

  variable_del('statistics_count_content_views');
  variable_del('statistics_enable_access_log');
  variable_del('statistics_flush_accesslog_timer');
  variable_del('statistics_day_timestamp');
  variable_del('statistics_block_top_day_num');
  variable_del('statistics_block_top_all_num');
  variable_del('statistics_block_top_last_num');
}

/**
 * Implementation of hook_schema().
 */
function statistics_schema() {
  $schema['accesslog'] = array(
    'fields' => array(
      'aid'       => array('type' => 'serial', 'not null' => TRUE),
      'sid'       => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => ''),
      'title'     => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE),
      'path'      => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE),
      'url'       => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE),
      'hostname'  => array('type' => 'varchar', 'length' => 128, 'not null' => FALSE),
      'uid'       => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0),
      'timer'     => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
      'timestamp' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)
    ),
    'indexes' => array('accesslog_timestamp' => array('timestamp')),
    'primary key' => array('aid'),
  );

  return $schema;
}