rename table and fields to remove _regn for earlyaccess codes

This commit is contained in:
2017-06-29 15:45:11 +10:00
parent acfbd806ef
commit ac8ed27d63
3 changed files with 56 additions and 19 deletions

View File

@@ -122,7 +122,6 @@ function booking_getToken($length) {
return $token;
}
/**
* Function to generate csv of early access codes for the current event
*/

View File

@@ -635,17 +635,17 @@ function booking_update_7242() {
db_add_field('booking_person', 'booking_earlyaccess_code_id', $spec);
//create new table to store the valid codes
$booking_regn_earlyaccess_codes = array(
$booking_earlyaccess_codes = array(
'fields' => array(
'cid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_eventid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_regn_earlyaccess_code' => array('type' => 'varchar', 'length' => '500', 'not null' => FALSE),
'booking_regn_earlyaccess_code_avail' => array('type' => 'varchar', 'length' => '1', 'not null' => FALSE),
'booking_earlyaccess_code' => array('type' => 'varchar', 'length' => '500', 'not null' => FALSE),
'booking_earlyaccess_code_avail' => array('type' => 'varchar', 'length' => '1', 'not null' => FALSE),
),
'primary key' => array('cid'),
);
db_create_table('booking_regn_earlyaccess_codes', $booking_regn_earlyaccess_codes);
db_create_table('booking_earlyaccess_codes', $booking_earlyaccess_codes);
//update the view to match the new table definition
_booking_node_create_mysqlview();
@@ -660,6 +660,32 @@ function booking_update_7243() {
variable_set('mail_system', array_merge($current, $addition));
}
/**
* Rename booking_earlyaccess_code_id in booking_person table to booking_earlyaccess_code
*/
function booking_update_7244() {
$spec = array('type' => 'int', 'length' => '11', 'default' => 0, 'not null' => FALSE);
db_change_field('booking_person', 'booking_earlyaccess_code_id', 'booking_earlyaccess_code', $spec);
db_drop_table('booking_regn_earlyaccess_codes');
//create new table to store the valid codes
$booking_earlyaccess_codes = array(
'fields' => array(
'cid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_eventid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_earlyaccess_code' => array('type' => 'varchar', 'length' => '500', 'not null' => FALSE),
'booking_earlyaccess_code_avail' => array('type' => 'varchar', 'length' => '1', 'not null' => FALSE),
),
'primary key' => array('cid'),
);
db_create_table('booking_earlyaccess_codes', $booking_earlyaccess_codes);
//update the view to match the new table definition
_booking_node_create_mysqlview();
}
/**
* Implementation of hook_install().
*/
@@ -730,7 +756,7 @@ function booking_schema() {
'nid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_eventid' => array('type' => 'int', 'length' => '11', 'default' => 0, 'not null' => FALSE),
'booking_tempid' => array('type' => 'varchar', 'length' => '40', 'not null' => FALSE),
'booking_earlyaccess_code_id' => array('type' => 'int', 'length' => '11', 'default' => 0, 'not null' => FALSE),
'booking_earlyaccess_code' => array('type' => 'int', 'length' => '11', 'default' => 0, 'not null' => FALSE),
'booking_timestamp' => array('type' => 'int', 'not null' => TRUE, 'disp-width' => '11'),
'booking_firstname' => array('type' => 'varchar', 'length' => '50', 'not null' => TRUE),
'booking_lastname' => array('type' => 'varchar', 'length' => '50', 'not null' => TRUE),
@@ -1045,12 +1071,12 @@ function booking_schema() {
);
//This lists all the early registration access codes
$schema['booking_regn_earlyaccess_codes'] = array(
$schema['booking_earlyaccess_codes'] = array(
'fields' => array(
'cid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_eventid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_regn_earlyaccess_code' => array('type' => 'varchar', 'length' => '500', 'not null' => FALSE),
'booking_regn_earlyaccess_code_avail' => array('type' => 'varchar', 'length' => '1', 'not null' => FALSE),
'booking_earlyaccess_code' => array('type' => 'varchar', 'length' => '500', 'not null' => FALSE),
'booking_earlyaccess_code_avail' => array('type' => 'varchar', 'length' => '1', 'not null' => FALSE),
),
'primary key' => array('cid'),
);

View File

@@ -117,12 +117,12 @@ function booking_form($node, &$form_state, $inserting = FALSE, $early_access_all
"Without this code, your registration will not be accepted.</p>" .
"<p><strong>NOTE: each early-access code can only be used once, so don't pass it along to your friends!</strong></p>"),
);
$form['early-access']['booking_regn_earlyaccess_code'] = array(
$form['early-access']['booking_earlyaccess_code'] = array(
'#type' => 'textfield',
'#title' => t('Unique Early-Access Code'),
'#maxlength' => 45,
'#required' => TRUE,
'#default_value' => !empty($data->booking_regn_earlyaccess_code) ? $data->booking_regn_earlyaccess_code : ''
'#default_value' => !empty($data->booking_earlyaccess_code) ? $data->booking_earlyaccess_code : ''
);
$form['booking_earlyaccess'] = array(
'#type' => 'hidden',
@@ -921,7 +921,7 @@ function booking_form($node, &$form_state, $inserting = FALSE, $early_access_all
return $form;
}
// @todo - validate the early access code here, booking_regn_earlyaccess_code
// @todo - validate the early access code here, booking_earlyaccess_code
function booking_form_validate($form, &$form_state) {
global $event;
@@ -931,23 +931,23 @@ function booking_form_validate($form, &$form_state) {
//if necessary, validate early access code
if (variable_get('booking_enable_earlyaccess_codes', 0) == 1 && (isset($data['booking_earlyaccess']) && $data['booking_earlyaccess'] == 1)) {
if (isset($data['booking_regn_earlyaccess_code']) && $data['booking_regn_earlyaccess_code'] != '') {
//perform a database lookup against the booking_regn_earlyaccess_codes table
if (isset($data['booking_earlyaccess_code']) && $data['booking_earlyaccess_code'] != '') {
//perform a database lookup against the booking_earlyaccess_codes table
$code_check = db_query("SELECT cid " .
"FROM {booking_regn_earlyaccess_codes} " .
"WHERE booking_regn_earlyaccess_code = :code AND booking_eventid = :eid AND booking_regn_earlyaccess_code_avail = 'Y'",
"FROM {booking_earlyaccess_codes} " .
"WHERE booking_earlyaccess_code = :code AND booking_eventid = :eid AND booking_earlyaccess_code_avail = 'Y'",
array(
':code' => $data['booking_regn_earlyaccess_code'],
':code' => $data['booking_earlyaccess_code'],
':eid' => $event->eid,
)
)->fetchObject();
//see if we got a result
if (! $code_check) {
form_set_error('booking_regn_earlyaccess_code', t('You have entered an invalid early registration code. If you do not have a code, please wait until normal registrations open.'));
form_set_error('booking_earlyaccess_code', t('You have entered an invalid early registration code. If you do not have a code, please wait until normal registrations open.'));
}
}
else {
form_set_error('booking_regn_earlyaccess_code', t('You must enter an early access code to register now. If you do not have a code, please wait until normal registrations open.'));
form_set_error('booking_earlyaccess_code', t('You must enter an early access code to register now. If you do not have a code, please wait until normal registrations open.'));
}
}
@@ -1248,6 +1248,7 @@ function booking_form_submit($form, &$form_state)
$node->booking_skills_language_details = empty($values['booking_skills_language_details']) ? 'N/A' : $values['booking_skills_language_details'];
$node->booking_skills_other = empty($values['booking_skills_other']) ? 'N' : ($values['booking_skills_other'] == 1 ? 'Y' : 'N');
$node->booking_skills_other_details = empty($values['booking_skills_other_details']) ? 'N/A' : $values['booking_skills_other_details'];
$node->booking_earlyaccess_code = empty($values['booking_earlyaccess_code']) ? '' : $values['booking_earlyaccess_code'];
//remove newlines from these fields so the CSV output doesn't get messed up
$medical = empty($values['booking_medical_conditions']) ? 'N/A' : $values['booking_medical_conditions'];
@@ -1294,6 +1295,17 @@ function _booking_form_submit_post_triggers($node)
{
global $event;
//mark early access code as being used
if (variable_get('booking_enable_earlyaccess_codes', 0) == 1 && $node->booking_earlyaccess_code != '') {
watchdog('booking_debug', "<pre>Early access code used, node info below\n@info</pre>", array('@info' => print_r($node, true)));
//update the database to mark the code as being unavailable
db_update('booking_earlyaccess_codes')->fields(array(
'booking_earlyaccess_code_avail' => 'N'
))->condition('booking_earlyaccess_code', $node->booking_earlyaccess_code)->execute();
}
//do these triggers really do anything? The partner id and bf/gf id won't be set in initial submit
//if booking_partner_id is set, make sure the nid it refers to has this node as its booking_partner_id