add some field exclusions to update hook

This commit is contained in:
2017-09-08 23:37:00 +10:00
parent 5e616019dd
commit c27f2c1005

View File

@@ -384,14 +384,24 @@ function booking_update($node) {
global $event;
$data = array();
//these fields should be stored in the database as Y or N, but come back from the FAPI as 1 or 0
$boolean_keys = array('booking_baptised', 'booking_married', 'booking_help_praying', 'booking_help_meditations', 'booking_help_reading',
'booking_help_chairing', 'booking_help_readgroup_lead', 'booking_help_discussgroup_lead', 'booking_lifesaver',
'booking_firstaid', 'booking_nurse', 'booking_doctor', 'booking_has_mission_experience', 'booking_skills_builder',
'booking_skills_cooking', 'booking_skills_childminding', 'booking_skills_language', 'booking_skills_other',
'booking_welfare_required', 'booking_payment_complete', 'booking_refund_processed', 'booking_committee_member'
);
//these fields should be zero if not defined
$default_zero_keys = array('booking_luckynum', 'booking_bf_gf_nid', 'booking_keepseparate_id', 'booking_refund_due');
//some fields are present in $node from the SQL view we use that don't belong in booking_person so exclude them
$excluded_keys = array('booking_person_nid', 'booking_transport_type', 'booking_transport_from_morriset_reqd', 'booking_transport_to_morriset_reqd',
'booking_flightnum_inbound', 'booking_flight_datetime_inbound', 'booking_flightnum_outbound', 'booking_flight_datetime_outbound', 'booking_accom_before_reqd',
'booking_accom_before_staying_with', 'booking_accom_after_reqd', 'booking_accom_after_staying_with', 'booking_roomlocation_descrip',
'booking_roomlocation_active', 'booking_price', 'booking_price_descrip', 'booking_late_price', 'booking_earlyaccess_code',
'booking_room_bedtype', 'booking_room_location_id', 'booking_room_number', 'booking_agreement'
);
//before we update this user, check what their previous registration status was
$previous_status = db_query("SELECT booking_status, booking_payment_id, booking_total_pay_reqd, booking_amount_paid FROM {booking_person} where nid = :nid", array(
':nid' => $node->nid))
@@ -408,6 +418,9 @@ function booking_update($node) {
elseif (in_array($key, $default_zero_keys, FALSE)) {
$data[$key] = $value == '' ? 0 : $value;
}
elseif (in_array($key, $excluded_keys, FALSE)) {
//skip these fields from the update of booking_person
}
else {
$data[$key] = _booking_remove_emoji($value);
}
@@ -415,7 +428,7 @@ function booking_update($node) {
}
}
watchdog('booking', 'Updating node: @info', array('@info' => var_export($data, TRUE)));
//db_update('booking_person')->fields($data)->condition('nid', $node->nid)->execute();
db_update('booking_person')->fields($data)->condition('nid', $node->nid)->execute();
/*
//watchdog('booking', 'Updating node: @info', array('@info' => var_export($node, TRUE)));
db_update('booking_person')