| 1 |
<?php
|
| 2 |
// $Id: poll.install,v 1.26 2009/09/29 15:13:56 dries Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Install, update and uninstall functions for the poll module.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implement hook_schema().
|
| 11 |
*/
|
| 12 |
function poll_schema() {
|
| 13 |
$schema['poll'] = array(
|
| 14 |
'description' => 'Stores poll-specific information for poll nodes.',
|
| 15 |
'fields' => array(
|
| 16 |
'nid' => array(
|
| 17 |
'type' => 'int',
|
| 18 |
'unsigned' => TRUE,
|
| 19 |
'not null' => TRUE,
|
| 20 |
'default' => 0,
|
| 21 |
'description' => "The poll's {node}.nid.",
|
| 22 |
),
|
| 23 |
'runtime' => array(
|
| 24 |
'type' => 'int',
|
| 25 |
'not null' => TRUE,
|
| 26 |
'default' => 0,
|
| 27 |
'description' => 'The number of seconds past {node}.created during which the poll is open.',
|
| 28 |
),
|
| 29 |
'active' => array(
|
| 30 |
'type' => 'int',
|
| 31 |
'unsigned' => TRUE,
|
| 32 |
'not null' => TRUE,
|
| 33 |
'default' => 0,
|
| 34 |
'description' => 'Boolean indicating whether or not the poll is open.',
|
| 35 |
),
|
| 36 |
),
|
| 37 |
'primary key' => array('nid'),
|
| 38 |
'foreign keys' => array(
|
| 39 |
'nid' => array('node' => 'nid'),
|
| 40 |
),
|
| 41 |
);
|
| 42 |
|
| 43 |
$schema['poll_choice'] = array(
|
| 44 |
'description' => 'Stores information about all choices for all {poll}s.',
|
| 45 |
'fields' => array(
|
| 46 |
'chid' => array(
|
| 47 |
'type' => 'serial',
|
| 48 |
'unsigned' => TRUE,
|
| 49 |
'not null' => TRUE,
|
| 50 |
'description' => 'Unique identifier for a poll choice.',
|
| 51 |
),
|
| 52 |
'nid' => array(
|
| 53 |
'type' => 'int',
|
| 54 |
'unsigned' => TRUE,
|
| 55 |
'not null' => TRUE,
|
| 56 |
'default' => 0,
|
| 57 |
'description' => 'The {node}.nid this choice belongs to.',
|
| 58 |
),
|
| 59 |
'chtext' => array(
|
| 60 |
'type' => 'varchar',
|
| 61 |
'length' => 128,
|
| 62 |
'not null' => TRUE,
|
| 63 |
'default' => '',
|
| 64 |
'description' => 'The text for this choice.',
|
| 65 |
'translatable' => TRUE,
|
| 66 |
),
|
| 67 |
'chvotes' => array(
|
| 68 |
'type' => 'int',
|
| 69 |
'not null' => TRUE,
|
| 70 |
'default' => 0,
|
| 71 |
'description' => 'The total number of votes this choice has received by all users.',
|
| 72 |
),
|
| 73 |
'weight' => array(
|
| 74 |
'type' => 'int',
|
| 75 |
'size' => 'tiny',
|
| 76 |
'not null' => TRUE,
|
| 77 |
'default' => 0,
|
| 78 |
'description' => 'The sort order of this choice among all choices for the same node.',
|
| 79 |
),
|
| 80 |
),
|
| 81 |
'indexes' => array(
|
| 82 |
'nid' => array('nid'),
|
| 83 |
),
|
| 84 |
'primary key' => array('chid'),
|
| 85 |
'foreign keys' => array(
|
| 86 |
'nid' => array('node' => 'nid'),
|
| 87 |
),
|
| 88 |
);
|
| 89 |
|
| 90 |
$schema['poll_vote'] = array(
|
| 91 |
'description' => 'Stores per-{users} votes for each {poll}.',
|
| 92 |
'fields' => array(
|
| 93 |
'chid' => array(
|
| 94 |
'type' => 'int',
|
| 95 |
'unsigned' => TRUE,
|
| 96 |
'not null' => TRUE,
|
| 97 |
'description' => "The {users}'s vote for this poll.",
|
| 98 |
),
|
| 99 |
'nid' => array(
|
| 100 |
'type' => 'int',
|
| 101 |
'unsigned' => TRUE,
|
| 102 |
'not null' => TRUE,
|
| 103 |
'description' => 'The {poll} node this vote is for.',
|
| 104 |
),
|
| 105 |
'uid' => array(
|
| 106 |
'type' => 'int',
|
| 107 |
'unsigned' => TRUE,
|
| 108 |
'not null' => TRUE,
|
| 109 |
'default' => 0,
|
| 110 |
'description' => 'The {users}.uid this vote is from unless the voter was anonymous.',
|
| 111 |
),
|
| 112 |
'hostname' => array(
|
| 113 |
'type' => 'varchar',
|
| 114 |
'length' => 128,
|
| 115 |
'not null' => TRUE,
|
| 116 |
'default' => '',
|
| 117 |
'description' => 'The IP address this vote is from unless the voter was logged in.',
|
| 118 |
),
|
| 119 |
'timestamp' => array(
|
| 120 |
'type' => 'int',
|
| 121 |
'not null' => TRUE,
|
| 122 |
'default' => 0,
|
| 123 |
'description' => 'The timestamp of the vote creation.',
|
| 124 |
),
|
| 125 |
),
|
| 126 |
'primary key' => array('nid', 'uid', 'hostname'),
|
| 127 |
'foreign keys' => array(
|
| 128 |
'nid' => array('node' => 'nid'),
|
| 129 |
'uid' => array('users' => 'uid'),
|
| 130 |
),
|
| 131 |
'indexes' => array(
|
| 132 |
'chid' => array('chid'),
|
| 133 |
'hostname' => array('hostname'),
|
| 134 |
'uid' => array('uid'),
|
| 135 |
),
|
| 136 |
);
|
| 137 |
|
| 138 |
return $schema;
|
| 139 |
}
|
| 140 |
|
| 141 |
/**
|
| 142 |
* Rename {poll_choices} table to {poll_choice} and {poll_votes} to {poll_vote}.
|
| 143 |
*/
|
| 144 |
function poll_update_7001() {
|
| 145 |
db_rename_table('poll_choices', 'poll_choice');
|
| 146 |
db_rename_table('poll_votes', 'poll_vote');
|
| 147 |
}
|
| 148 |
|
| 149 |
/**
|
| 150 |
* Add timestamp field to {poll_votes}.
|
| 151 |
*/
|
| 152 |
function poll_update_7002() {
|
| 153 |
$field = array(
|
| 154 |
'type' => 'int',
|
| 155 |
'not null' => TRUE,
|
| 156 |
'default' => 0,
|
| 157 |
);
|
| 158 |
db_add_field('poll_votes', 'timestamp', $field);
|
| 159 |
}
|