handle node updates more generically

This commit is contained in:
2017-09-08 23:24:51 +10:00
parent 0763037aec
commit 088648812e

View File

@@ -382,12 +382,40 @@ function booking_insert($node) {
*/
function booking_update($node) {
global $event;
$data = array();
$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'
);
$default_zero_keys = array('booking_luckynum', 'booking_bf_gf_nid', 'booking_keepseparate_id', 'booking_refund_due');
//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))
->fetchObject();
// process the input data before updating database
foreach ($node as $key => $value) {
//check if the key is a field that belongs in the database
if ((strpos($key, "booking_") === 0) || $key === "nid") {
//do we need to treat this field carefully?
if (in_array($key, $boolean_keys, FALSE)) {
$data[$key] = $value == 1 ? 'Y' : 'N';
}
elseif (in_array($key, $default_zero_keys, FALSE)) {
$data[$key] = $value == '' ? 0 : $value;
}
else {
$data[$key] = _booking_remove_emoji($value);
}
}
}
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')
->fields(array (
@@ -460,10 +488,11 @@ function booking_update($node) {
'booking_status' => $node->booking_status,
'booking_comment_field' => $node->booking_comment_field,
'booking_song_choice' => $node->booking_song_choice,
'booking_freestyle_text' => $node->booking_freestyle_text,
))
->condition('nid', $node->nid)
->execute();
*/
//***now process some post-update triggers***
//if booking_partner_id is set, make sure the nid it refers to has this node as its booking_partner_id