View source
<?php
function webform_invitation_schema() {
$schema['webform_invitation_codes'] = array(
'description' => 'Table for storing generated form tokens.',
'fields' => array(
'cid' => array(
'description' => 'The primary identifier for a code.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'nid' => array(
'description' => 'The primary identifier for a node.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'code' => array(
'description' => 'A code for the webform.',
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
'time_generated' => array(
'description' => 'The Unix timestamp when the code was generated.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'used' => array(
'description' => 'The Unix timestamp when the code was used.',
'type' => 'int',
'not null' => FALSE,
'default' => NULL,
),
'sid' => array(
'description' => 'The submission ID using this code.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'nid' => array(
'nid',
),
'used' => array(
'used',
),
),
'unique keys' => array(
'nid_code' => array(
'nid',
'code',
),
),
'primary key' => array(
'cid',
),
);
$schema['webform_invitation'] = array(
'description' => 'Table for storing invitation settings.',
'fields' => array(
'nid' => array(
'description' => 'The primary identifier for a node.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'invitation' => array(
'description' => 'Use invitation codes?',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'cid' => array(
'description' => 'Component ID of Webform Invitation textfield.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'nid',
),
);
return $schema;
}
function webform_invitation_disable() {
$db_settings = db_select('webform_invitation', 'i')
->fields('i')
->condition('invitation', 1, '=')
->execute();
while ($result = $db_settings
->fetchAssoc()) {
$node = node_load($result['nid']);
foreach ($node->webform['components'] as $id => $com) {
if ($com['form_key'] == 'webform_invitation_code') {
unset($node->webform['components'][$id]);
node_save($node);
break;
}
}
}
}
function webform_invitation_update_7200() {
db_add_field('webform_invitation', 'cid', array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Component ID of Webform Invitation textfield.',
));
db_add_field('webform_invitation_codes', 'sid', array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'The submission ID using this code.',
));
}
function webform_invitation_update_7201() {
$db_settings = db_select('webform_invitation', 'i')
->fields('i')
->condition('invitation', 1, '=')
->execute();
while ($result = $db_settings
->fetchAssoc()) {
$node = node_load($result['nid']);
foreach ($node->webform['components'] as $id => $com) {
if ($com['form_key'] == 'webform_invitation_code') {
db_merge('webform_invitation')
->key(array(
'nid' => $result['nid'],
))
->fields(array(
'cid' => $id,
))
->execute();
break;
}
}
}
}
function webform_invitation_update_7202() {
$schema = webform_invitation_schema();
$field = $schema['webform_invitation_codes']['fields']['time_generated'];
db_change_field('webform_invitation_codes', 'generated', 'time_generated', $field);
}