advpoll.install in Advanced Poll 6.3
Same filename and directory in other branches
Manage database installation and upgrading for advpoll.
File
advpoll.installView source
<?php
/**
* @file
* Manage database installation and upgrading for advpoll.
*/
/**
* Implementation of hook_install().
*/
function advpoll_install() {
// Create database tables.
drupal_install_schema('advpoll');
}
/**
* Implementation of hook_schema().
*/
function advpoll_schema() {
$schema = array();
$schema['advpoll'] = array(
'description' => t('Stores the main settings for an advanced poll node.'),
'fields' => array(
'nid' => array(
'description' => t("The advpoll's {node}.nid"),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'quorum' => array(
'description' => t('Quorum for the poll, currently unimplemented.'),
'type' => 'int',
'unsigned' => TRUE,
'default' => 0,
),
'mode' => array(
'description' => t('The type of poll, either ranking of binary.'),
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
),
'use_list' => array(
'description' => t('Whether or not an electoral list is being used.'),
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'active' => array(
'description' => t('Whether or not the poll is still open for voting.'),
'type' => 'int',
'not null' => TRUE,
'default' => 1,
),
'max_choices' => array(
'description' => t('An upper limit on how many choices can be selected.'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'algorithm' => array(
'description' => t('Within a given voting mode, the formula used to calculate the poll winner.'),
'type' => 'varchar',
'length' => 100,
),
'show_votes' => array(
'description' => t('Whether or not to display votes that have been cast.'),
'type' => 'int',
'not null' => TRUE,
'default' => 1,
),
'create_view_block' => array(
'description' => t('Whether or not to generate a block for this poll.'),
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'start_date' => array(
'description' => t('The date at which voting begins for the poll.'),
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'end_date' => array(
'description' => t('The date at which voting ends for the poll.'),
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'writeins' => array(
'description' => t('Whether or not to allow write-in votes.'),
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'show_writeins' => array(
'description' => t('Whether or not to list write-in votes as possible choices.'),
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'question' => array(
'description' => t('Optional text to display as the subject of the poll.'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'footer_message' => array(
'description' => t('Optional text to display in the footer of the poll.'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array(
'nid',
),
);
$schema['advpoll_electoral_list'] = array(
'description' => t('Stores the list of eligible votes for polls that use an electoral list.'),
'fields' => array(
'nid' => array(
'description' => t('Node id for the relevant advpoll.'),
'type' => 'int',
'not null' => TRUE,
),
'uid' => array(
'description' => t('User id who will be given access to vote in an advpoll.'),
'type' => 'int',
'not null' => TRUE,
),
),
'primary key' => array(
'nid',
'uid',
),
);
$schema['advpoll_choices'] = array(
'description' => t('Stores the settings for an individual choice in a poll.'),
'fields' => array(
'cid' => array(
'description' => t('The unique id of the choice.'),
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'nid' => array(
'description' => t('The choice is assigned to this advpoll node.'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'label' => array(
'description' => t('A string description of what this choice represents.'),
'type' => 'text',
'not null' => TRUE,
),
'weight' => array(
'description' => t('An integer value used to order the display of choices from lowest to highest.'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'writein' => array(
'description' => t('Whether or not this choice was a write-in vote by a user.'),
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'nid' => array(
'nid',
'weight',
),
),
'primary key' => array(
'cid',
),
);
return $schema;
}
/**
* Implementation of hook_uninstall().
*/
function advpoll_uninstall() {
// Needs to be included due to _advpoll_list_modes().
include_once './' . drupal_get_path('module', 'advpoll') . '/advpoll.module';
// Remove all advpoll content types and their variables.
$variables = array(
'choices',
'max_choices',
'algorithm',
'runtime',
'writeins',
'show_writeins',
'electoral_list',
'show_votes',
'view_results',
'use_question',
'advpoll_settings',
);
foreach (_advpoll_list_modes() as $mode) {
node_type_delete('advpoll_' . $mode['name']);
}
// consolidated all variables into one object for efficiency - other variables were
// never actually being set.
variable_del('advpoll_settings');
// Remove all votes.
db_query("DELETE FROM {votingapi_vote} WHERE content_type = 'advpoll'");
// Remove all cache data.
db_query("DELETE FROM {votingapi_cache} WHERE content_type = 'advpoll'");
// Remove all advpoll nodes.
$result = db_query('SELECT nid FROM {advpoll}');
while ($obj = db_fetch_object($result)) {
node_delete($obj->nid);
}
// Remove all database tables.
drupal_uninstall_schema('advpoll');
}
/**
* No-op update to clear Voting API cache after fixing http://drupal.org/node/361593
*/
function advpoll_update_6000() {
return array();
}
function advpoll_update_6100() {
$ret = array();
$attributes = array(
'description' => t('Whether or not to generate a view block for this poll.'),
'type' => 'int',
'not null' => TRUE,
'default' => 0,
);
db_add_field($ret, 'advpoll', 'create_view_block', $attributes);
return $ret;
}
function advpoll_update_6200() {
$ret = array();
$attributes = array(
'description' => t('Optional text to display in the footer of the poll.'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
);
db_add_field($ret, 'advpoll', 'footer_message', $attributes);
return $ret;
}
Functions
Name | Description |
---|---|
advpoll_install | Implementation of hook_install(). |
advpoll_schema | Implementation of hook_schema(). |
advpoll_uninstall | Implementation of hook_uninstall(). |
advpoll_update_6000 | No-op update to clear Voting API cache after fixing http://drupal.org/node/361593 |
advpoll_update_6100 | |
advpoll_update_6200 |