2006-07-13 13:14:25 +00:00
|
|
|
<?php
|
2006-07-14 01:05:10 +00:00
|
|
|
// $Id$
|
2006-07-13 13:14:25 +00:00
|
|
|
|
2009-04-26 16:31:23 +00:00
|
|
|
/**
|
|
|
|
* @file
|
2009-05-13 19:42:18 +00:00
|
|
|
* Install, update and uninstall functions for the poll module.
|
2009-04-26 16:31:23 +00:00
|
|
|
*/
|
|
|
|
|
2007-10-05 14:43:26 +00:00
|
|
|
/**
|
2009-12-04 16:49:48 +00:00
|
|
|
* Implements hook_schema().
|
2007-10-05 14:43:26 +00:00
|
|
|
*/
|
|
|
|
function poll_schema() {
|
|
|
|
$schema['poll'] = array(
|
2008-11-15 13:01:11 +00:00
|
|
|
'description' => 'Stores poll-specific information for poll nodes.',
|
2007-10-05 14:43:26 +00:00
|
|
|
'fields' => array(
|
2008-03-15 12:31:29 +00:00
|
|
|
'nid' => array(
|
2007-10-10 11:39:35 +00:00
|
|
|
'type' => 'int',
|
|
|
|
'unsigned' => TRUE,
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
2008-11-15 13:01:11 +00:00
|
|
|
'description' => "The poll's {node}.nid.",
|
2008-03-15 12:31:29 +00:00
|
|
|
),
|
2007-10-10 11:39:35 +00:00
|
|
|
'runtime' => array(
|
|
|
|
'type' => 'int',
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
2008-11-15 13:01:11 +00:00
|
|
|
'description' => 'The number of seconds past {node}.created during which the poll is open.',
|
2008-03-15 12:31:29 +00:00
|
|
|
),
|
|
|
|
'active' => array(
|
2007-10-10 11:39:35 +00:00
|
|
|
'type' => 'int',
|
|
|
|
'unsigned' => TRUE,
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
2008-11-15 13:01:11 +00:00
|
|
|
'description' => 'Boolean indicating whether or not the poll is open.',
|
2007-10-10 11:39:35 +00:00
|
|
|
),
|
2008-03-15 12:31:29 +00:00
|
|
|
),
|
2007-10-05 14:43:26 +00:00
|
|
|
'primary key' => array('nid'),
|
2009-06-01 22:07:10 +00:00
|
|
|
'foreign keys' => array(
|
|
|
|
'nid' => array('node' => 'nid'),
|
|
|
|
),
|
2008-03-15 12:31:29 +00:00
|
|
|
);
|
2007-10-05 14:43:26 +00:00
|
|
|
|
2008-12-05 12:50:28 +00:00
|
|
|
$schema['poll_choice'] = array(
|
2008-11-15 13:01:11 +00:00
|
|
|
'description' => 'Stores information about all choices for all {poll}s.',
|
2007-10-05 14:43:26 +00:00
|
|
|
'fields' => array(
|
2008-03-15 12:31:29 +00:00
|
|
|
'chid' => array(
|
2007-10-10 11:39:35 +00:00
|
|
|
'type' => 'serial',
|
|
|
|
'unsigned' => TRUE,
|
|
|
|
'not null' => TRUE,
|
2008-11-15 13:01:11 +00:00
|
|
|
'description' => 'Unique identifier for a poll choice.',
|
2008-03-15 12:31:29 +00:00
|
|
|
),
|
|
|
|
'nid' => array(
|
2007-10-10 11:39:35 +00:00
|
|
|
'type' => 'int',
|
|
|
|
'unsigned' => TRUE,
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
2008-11-15 13:01:11 +00:00
|
|
|
'description' => 'The {node}.nid this choice belongs to.',
|
2008-03-15 12:31:29 +00:00
|
|
|
),
|
|
|
|
'chtext' => array(
|
2007-10-10 11:39:35 +00:00
|
|
|
'type' => 'varchar',
|
|
|
|
'length' => 128,
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => '',
|
2008-11-15 13:01:11 +00:00
|
|
|
'description' => 'The text for this choice.',
|
2009-10-16 19:06:25 +00:00
|
|
|
'translatable' => TRUE,
|
2008-03-15 12:31:29 +00:00
|
|
|
),
|
2007-10-10 11:39:35 +00:00
|
|
|
'chvotes' => array(
|
|
|
|
'type' => 'int',
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
2008-11-15 13:01:11 +00:00
|
|
|
'description' => 'The total number of votes this choice has received by all users.',
|
2008-03-15 12:31:29 +00:00
|
|
|
),
|
2008-05-15 20:56:48 +00:00
|
|
|
'weight' => array(
|
2007-10-10 11:39:35 +00:00
|
|
|
'type' => 'int',
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
2008-11-15 13:01:11 +00:00
|
|
|
'description' => 'The sort order of this choice among all choices for the same node.',
|
2007-10-10 11:39:35 +00:00
|
|
|
),
|
2008-03-15 12:31:29 +00:00
|
|
|
),
|
2007-10-10 11:39:35 +00:00
|
|
|
'indexes' => array(
|
2008-03-15 12:31:29 +00:00
|
|
|
'nid' => array('nid'),
|
|
|
|
),
|
2007-10-05 14:43:26 +00:00
|
|
|
'primary key' => array('chid'),
|
2009-06-01 22:07:10 +00:00
|
|
|
'foreign keys' => array(
|
|
|
|
'nid' => array('node' => 'nid'),
|
|
|
|
),
|
2008-03-15 12:31:29 +00:00
|
|
|
);
|
2007-10-12 14:10:18 +00:00
|
|
|
|
2008-12-05 12:50:28 +00:00
|
|
|
$schema['poll_vote'] = array(
|
2009-02-26 07:30:29 +00:00
|
|
|
'description' => 'Stores per-{users} votes for each {poll}.',
|
2007-10-05 14:43:26 +00:00
|
|
|
'fields' => array(
|
2008-05-15 20:56:48 +00:00
|
|
|
'chid' => array(
|
|
|
|
'type' => 'int',
|
|
|
|
'unsigned' => TRUE,
|
|
|
|
'not null' => TRUE,
|
2009-02-26 07:30:29 +00:00
|
|
|
'description' => "The {users}'s vote for this poll.",
|
2008-05-15 20:56:48 +00:00
|
|
|
),
|
2008-03-15 12:31:29 +00:00
|
|
|
'nid' => array(
|
2007-10-10 11:39:35 +00:00
|
|
|
'type' => 'int',
|
|
|
|
'unsigned' => TRUE,
|
|
|
|
'not null' => TRUE,
|
2008-11-15 13:01:11 +00:00
|
|
|
'description' => 'The {poll} node this vote is for.',
|
2008-03-15 12:31:29 +00:00
|
|
|
),
|
|
|
|
'uid' => array(
|
2007-10-10 11:39:35 +00:00
|
|
|
'type' => 'int',
|
|
|
|
'unsigned' => TRUE,
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
2009-02-26 07:30:29 +00:00
|
|
|
'description' => 'The {users}.uid this vote is from unless the voter was anonymous.',
|
2008-03-15 12:31:29 +00:00
|
|
|
),
|
2007-10-10 11:39:35 +00:00
|
|
|
'hostname' => array(
|
|
|
|
'type' => 'varchar',
|
|
|
|
'length' => 128,
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => '',
|
2008-11-15 13:01:11 +00:00
|
|
|
'description' => 'The IP address this vote is from unless the voter was logged in.',
|
2007-10-10 11:39:35 +00:00
|
|
|
),
|
2009-01-21 14:42:16 +00:00
|
|
|
'timestamp' => array(
|
|
|
|
'type' => 'int',
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
|
|
|
'description' => 'The timestamp of the vote creation.',
|
|
|
|
),
|
2008-03-15 12:31:29 +00:00
|
|
|
),
|
2007-12-18 12:59:22 +00:00
|
|
|
'primary key' => array('nid', 'uid', 'hostname'),
|
2009-06-01 22:07:10 +00:00
|
|
|
'foreign keys' => array(
|
|
|
|
'nid' => array('node' => 'nid'),
|
|
|
|
'uid' => array('users' => 'uid'),
|
|
|
|
),
|
2007-10-05 14:43:26 +00:00
|
|
|
'indexes' => array(
|
2008-05-15 20:56:48 +00:00
|
|
|
'chid' => array('chid'),
|
2007-10-05 14:43:26 +00:00
|
|
|
'hostname' => array('hostname'),
|
2008-03-15 12:31:29 +00:00
|
|
|
'uid' => array('uid'),
|
|
|
|
),
|
|
|
|
);
|
2007-10-05 14:43:26 +00:00
|
|
|
|
|
|
|
return $schema;
|
|
|
|
}
|
2008-12-05 12:50:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Rename {poll_choices} table to {poll_choice} and {poll_votes} to {poll_vote}.
|
|
|
|
*/
|
|
|
|
function poll_update_7001() {
|
2009-09-29 15:13:57 +00:00
|
|
|
db_rename_table('poll_choices', 'poll_choice');
|
|
|
|
db_rename_table('poll_votes', 'poll_vote');
|
2008-12-05 12:50:28 +00:00
|
|
|
}
|
2009-01-21 14:42:16 +00:00
|
|
|
|
|
|
|
/**
|
2010-01-28 13:52:30 +00:00
|
|
|
* Add timestamp field to {poll_vote}.
|
2009-01-21 14:42:16 +00:00
|
|
|
*/
|
|
|
|
function poll_update_7002() {
|
|
|
|
$field = array(
|
|
|
|
'type' => 'int',
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
|
|
|
);
|
2010-01-28 13:52:30 +00:00
|
|
|
db_add_field('poll_vote', 'timestamp', $field);
|
2009-01-21 14:42:16 +00:00
|
|
|
}
|
2010-01-30 00:08:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the weight column to normal int.
|
|
|
|
*/
|
|
|
|
function poll_update_7003() {
|
|
|
|
db_change_field('poll_choice', 'weight', 'weight', array(
|
|
|
|
'type' => 'int',
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
|
|
|
'description' => 'The sort order of this choice among all choices for the same node.',
|
|
|
|
));
|
|
|
|
}
|