support data import via booking_tempid as well as nid
This commit is contained in:
@@ -85,6 +85,11 @@ function booking_import_data_admin_submit($form, &$form_state)
|
||||
$datetime_fields = array('booking_outflight_origin_ts', 'booking_outflight_destination_ts', 'booking_rtrnflight_origin_ts',
|
||||
'booking_rtrnflight_destination_ts','booking_dob', 'booking_passport_expiry_date');
|
||||
$builtin_fields_to_import = array('nid');
|
||||
|
||||
// These are fields we can use to key the update
|
||||
$unique_fields = array('nid', 'booking_tempid');
|
||||
$update_key = "";
|
||||
|
||||
//$custom_fields_to_import = explode(";", variable_get('booking_import_include_fields', ''));
|
||||
$data = $form_state['input'];
|
||||
$import_fields = $data['booking_import_data_fields'];
|
||||
@@ -136,7 +141,20 @@ function booking_import_data_admin_submit($form, &$form_state)
|
||||
$studygroups_update_array = array();
|
||||
$studygroup_roles_update_array = array();
|
||||
|
||||
//do some error checking
|
||||
// Check that there is a key we can use to perform the update
|
||||
foreach ($unique_fields as $key) {
|
||||
if (array_key_exists($key, $record)) {
|
||||
$update_key = $key;
|
||||
}
|
||||
}
|
||||
|
||||
// Check that we found a key, otherwise the update can't be processed
|
||||
if ($key === "") {
|
||||
drupal_set_message("Error: Unable to locate any unique identifier in input file for record number $update_counter.", 'error', FALSE);
|
||||
break;
|
||||
}
|
||||
|
||||
// Pre-process some data
|
||||
foreach($fields_to_import as $field) {
|
||||
//make sure to skip the nid field since we can't update that
|
||||
if ($field == 'nid') {
|
||||
@@ -175,14 +193,15 @@ function booking_import_data_admin_submit($form, &$form_state)
|
||||
}
|
||||
}
|
||||
|
||||
// Perform the actual update
|
||||
if (count($update_array) > 0) {
|
||||
$query = db_update('booking_person')
|
||||
->fields($update_array)
|
||||
->condition('nid', $record['nid']);
|
||||
->condition($key, $record[$key]);
|
||||
|
||||
$rows = $query->execute();
|
||||
|
||||
$update_messages[] = t("Update Query:<br />@info<br />Condition: @nid<br />Rows affected: @rows<br />Values: <br /><pre>@values</pre>", array('@info' => (string) $query, '@nid' => $record['nid'], '@rows' => $rows, '@values' => print_r( $update_array, true) ));
|
||||
$update_messages[] = t("Update Query:<br />@info<br />Condition: @nid<br />Rows affected: @rows<br />Values: <br /><pre>@values</pre>",
|
||||
array('@info' => (string) $query, '@nid' => $record[$key], '@rows' => $rows, '@values' => print_r( $update_array, true) ));
|
||||
}
|
||||
|
||||
//handle study group processing
|
||||
|
Reference in New Issue
Block a user