| webmaster@1 | 1 <?php | 
| webmaster@1 | 2 // $Id: statistics.install,v 1.13 2007/12/18 12:59:22 dries Exp $ | 
| webmaster@1 | 3 | 
| webmaster@1 | 4 /** | 
| webmaster@1 | 5  * Implementation of hook_install(). | 
| webmaster@1 | 6  */ | 
| webmaster@1 | 7 function statistics_install() { | 
| webmaster@1 | 8   // Create tables. | 
| webmaster@1 | 9   drupal_install_schema('statistics'); | 
| webmaster@1 | 10 } | 
| webmaster@1 | 11 | 
| webmaster@1 | 12 /** | 
| webmaster@1 | 13  * Changes session ID  field to VARCHAR(64) to add support for SHA-1 hashes. | 
| webmaster@1 | 14  */ | 
| webmaster@1 | 15 function statistics_update_1000() { | 
| webmaster@1 | 16   $ret = array(); | 
| webmaster@1 | 17 | 
| webmaster@1 | 18   switch ($GLOBALS['db_type']) { | 
| webmaster@1 | 19     case 'mysql': | 
| webmaster@1 | 20     case 'mysqli': | 
| webmaster@1 | 21       $ret[] = update_sql("ALTER TABLE {accesslog} CHANGE COLUMN sid sid varchar(64) NOT NULL default ''"); | 
| webmaster@1 | 22       break; | 
| webmaster@1 | 23     case 'pgsql': | 
| webmaster@1 | 24       db_change_column($ret, 'accesslog', 'sid', 'sid', 'varchar(64)', array('not null' => TRUE, 'default' => "''")); | 
| webmaster@1 | 25       break; | 
| webmaster@1 | 26   } | 
| webmaster@1 | 27 | 
| webmaster@1 | 28   return $ret; | 
| webmaster@1 | 29 } | 
| webmaster@1 | 30 | 
| webmaster@1 | 31 /** | 
| webmaster@1 | 32  * Implementation of hook_uninstall(). | 
| webmaster@1 | 33  */ | 
| webmaster@1 | 34 function statistics_uninstall() { | 
| webmaster@1 | 35   // Remove tables. | 
| webmaster@1 | 36   drupal_uninstall_schema('statistics'); | 
| webmaster@1 | 37 | 
| webmaster@1 | 38   variable_del('statistics_count_content_views'); | 
| webmaster@1 | 39   variable_del('statistics_enable_access_log'); | 
| webmaster@1 | 40   variable_del('statistics_flush_accesslog_timer'); | 
| webmaster@1 | 41   variable_del('statistics_day_timestamp'); | 
| webmaster@1 | 42   variable_del('statistics_block_top_day_num'); | 
| webmaster@1 | 43   variable_del('statistics_block_top_all_num'); | 
| webmaster@1 | 44   variable_del('statistics_block_top_last_num'); | 
| webmaster@1 | 45 } | 
| webmaster@1 | 46 | 
| webmaster@1 | 47 /** | 
| webmaster@1 | 48  * Implementation of hook_schema(). | 
| webmaster@1 | 49  */ | 
| webmaster@1 | 50 function statistics_schema() { | 
| webmaster@1 | 51   $schema['accesslog'] = array( | 
| webmaster@1 | 52     'description' => t('Stores site access information for statistics.'), | 
| webmaster@1 | 53     'fields' => array( | 
| webmaster@1 | 54       'aid' => array( | 
| webmaster@1 | 55         'type' => 'serial', | 
| webmaster@1 | 56         'not null' => TRUE, | 
| webmaster@1 | 57         'description' => t('Primary Key: Unique accesslog ID.'), | 
| webmaster@1 | 58       ), | 
| webmaster@1 | 59       'sid' => array( | 
| webmaster@1 | 60         'type' => 'varchar', | 
| webmaster@1 | 61         'length' => 64, | 
| webmaster@1 | 62         'not null' => TRUE, | 
| webmaster@1 | 63         'default' => '', | 
| webmaster@1 | 64         'description' => t('Browser session ID of user that visited page.'), | 
| webmaster@1 | 65       ), | 
| webmaster@1 | 66       'title' => array( | 
| webmaster@1 | 67         'type' => 'varchar', | 
| webmaster@1 | 68         'length' => 255, | 
| webmaster@1 | 69         'not null' => FALSE, | 
| webmaster@1 | 70         'description' => t('Title of page visited.'), | 
| webmaster@1 | 71       ), | 
| webmaster@1 | 72       'path' => array( | 
| webmaster@1 | 73         'type' => 'varchar', | 
| webmaster@1 | 74         'length' => 255, | 
| webmaster@1 | 75         'not null' => FALSE, | 
| webmaster@1 | 76         'description' => t('Internal path to page visited (relative to Drupal root.)'), | 
| webmaster@1 | 77       ), | 
| webmaster@1 | 78       'url' => array( | 
| webmaster@1 | 79         'type' => 'varchar', | 
| webmaster@1 | 80         'length' => 255, | 
| webmaster@1 | 81         'not null' => FALSE, | 
| webmaster@1 | 82         'description' => t('Referrer URI.'), | 
| webmaster@1 | 83       ), | 
| webmaster@1 | 84       'hostname' => array( | 
| webmaster@1 | 85         'type' => 'varchar', | 
| webmaster@1 | 86         'length' => 128, | 
| webmaster@1 | 87         'not null' => FALSE, | 
| webmaster@1 | 88         'description' => t('Hostname of user that visited the page.'), | 
| webmaster@1 | 89       ), | 
| webmaster@1 | 90       'uid' => array( | 
| webmaster@1 | 91         'type' => 'int', | 
| webmaster@1 | 92         'unsigned' => TRUE, | 
| webmaster@1 | 93         'not null' => FALSE, | 
| webmaster@1 | 94         'default' => 0, | 
| webmaster@1 | 95         'description' => t('User {users}.uid that visited the page.'), | 
| webmaster@1 | 96       ), | 
| webmaster@1 | 97       'timer' => array( | 
| webmaster@1 | 98         'type' => 'int', | 
| webmaster@1 | 99         'unsigned' => TRUE, | 
| webmaster@1 | 100         'not null' => TRUE, | 
| webmaster@1 | 101         'default' => 0, | 
| webmaster@1 | 102         'description' => t('Time in milliseconds that the page took to load.'), | 
| webmaster@1 | 103       ), | 
| webmaster@1 | 104       'timestamp' => array( | 
| webmaster@1 | 105         'type' => 'int', | 
| webmaster@1 | 106         'unsigned' => TRUE, | 
| webmaster@1 | 107         'not null' => TRUE, | 
| webmaster@1 | 108         'default' => 0, | 
| webmaster@1 | 109         'description' => t('Timestamp of when the page was visited.'), | 
| webmaster@1 | 110       ), | 
| webmaster@1 | 111     ), | 
| webmaster@1 | 112     'indexes' => array( | 
| webmaster@1 | 113       'accesslog_timestamp' => array('timestamp'), | 
| webmaster@1 | 114       'uid' => array('uid'), | 
| webmaster@1 | 115     ), | 
| webmaster@1 | 116     'primary key' => array('aid'), | 
| webmaster@1 | 117   ); | 
| webmaster@1 | 118 | 
| webmaster@1 | 119   return $schema; | 
| webmaster@1 | 120 } | 
| webmaster@1 | 121 |