@@ -206,26 +206,26 @@ discard block |
||
206 | 206 | { |
207 | 207 | global $wpdb; |
208 | 208 | $this->_pretty_name = __("Attendees", "event_espresso"); |
209 | - $this->_old_table = $wpdb->prefix . "events_attendee"; |
|
209 | + $this->_old_table = $wpdb->prefix."events_attendee"; |
|
210 | 210 | // Only select the event status column from the event table. |
211 | 211 | $this->select_expression = 'att.*, e.event_status'; |
212 | 212 | // Only select attendees for events that aren't deleted. |
213 | 213 | $this->_extra_where_sql = 'AS att |
214 | - INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
|
214 | + INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id=e.id |
|
215 | 215 | WHERE e.event_status!="D"'; |
216 | - $this->_old_mer_table = $wpdb->prefix . "events_multi_event_registration_id_group"; |
|
216 | + $this->_old_mer_table = $wpdb->prefix."events_multi_event_registration_id_group"; |
|
217 | 217 | $this->_new_attendee_cpt_table = $wpdb->posts; |
218 | - $this->_new_attendee_meta_table = $wpdb->prefix . "esp_attendee_meta"; |
|
219 | - $this->_new_reg_table = $wpdb->prefix . "esp_registration"; |
|
220 | - $this->_new_transaction_table = $wpdb->prefix . "esp_transaction"; |
|
221 | - $this->_new_payment_table = $wpdb->prefix . "esp_payment"; |
|
222 | - $this->_new_line_table = $wpdb->prefix . "esp_line_item"; |
|
223 | - $this->_new_ticket_table = $wpdb->prefix . "esp_ticket"; |
|
224 | - $this->_new_ticket_datetime_table = $wpdb->prefix . "esp_datetime_ticket"; |
|
225 | - $this->_new_datetime_table = $wpdb->prefix . "esp_datetime"; |
|
226 | - $this->_new_datetime_ticket_table = $wpdb->prefix . "esp_datetime_ticket"; |
|
227 | - $this->_new_price_table = $wpdb->prefix . "esp_price"; |
|
228 | - $this->_new_ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
218 | + $this->_new_attendee_meta_table = $wpdb->prefix."esp_attendee_meta"; |
|
219 | + $this->_new_reg_table = $wpdb->prefix."esp_registration"; |
|
220 | + $this->_new_transaction_table = $wpdb->prefix."esp_transaction"; |
|
221 | + $this->_new_payment_table = $wpdb->prefix."esp_payment"; |
|
222 | + $this->_new_line_table = $wpdb->prefix."esp_line_item"; |
|
223 | + $this->_new_ticket_table = $wpdb->prefix."esp_ticket"; |
|
224 | + $this->_new_ticket_datetime_table = $wpdb->prefix."esp_datetime_ticket"; |
|
225 | + $this->_new_datetime_table = $wpdb->prefix."esp_datetime"; |
|
226 | + $this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket"; |
|
227 | + $this->_new_price_table = $wpdb->prefix."esp_price"; |
|
228 | + $this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price"; |
|
229 | 229 | parent::__construct(); |
230 | 230 | } |
231 | 231 | |
@@ -233,9 +233,9 @@ discard block |
||
233 | 233 | { |
234 | 234 | // first check if there's already a new attendee with similar characteristics |
235 | 235 | $new_att_id = $this->_find_attendee_cpt_matching($old_row); |
236 | - if (!$new_att_id) { |
|
236 | + if ( ! $new_att_id) { |
|
237 | 237 | $new_att_id = $this->_insert_new_attendee_cpt($old_row); |
238 | - if (!$new_att_id) { |
|
238 | + if ( ! $new_att_id) { |
|
239 | 239 | // if we couldnt even make an attendee, abandon all hope |
240 | 240 | return false; |
241 | 241 | } |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_cpt_table, $new_att_id); |
248 | 248 | |
249 | 249 | $txn_id = $this->_insert_new_transaction($old_row); |
250 | - if (!$txn_id) { |
|
250 | + if ( ! $txn_id) { |
|
251 | 251 | // if we couldnt make the transaction, also abandon all hope |
252 | 252 | return false; |
253 | 253 | } |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | private function _find_attendee_cpt_matching($old_attendee) |
276 | 276 | { |
277 | 277 | global $wpdb; |
278 | - $existing_attendee_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . $this->_new_attendee_cpt_table . " AS cpt INNER JOIN " . $this->_new_attendee_meta_table . " AS meta ON cpt.ID = meta.ATT_ID WHERE meta.ATT_fname = %s AND meta.ATT_lname = %s AND meta.ATT_email = %s LIMIT 1", $old_attendee['fname'], $old_attendee['lname'], $old_attendee['email'])); |
|
278 | + $existing_attendee_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM ".$this->_new_attendee_cpt_table." AS cpt INNER JOIN ".$this->_new_attendee_meta_table." AS meta ON cpt.ID = meta.ATT_ID WHERE meta.ATT_fname = %s AND meta.ATT_lname = %s AND meta.ATT_email = %s LIMIT 1", $old_attendee['fname'], $old_attendee['lname'], $old_attendee['email'])); |
|
279 | 279 | return intval($existing_attendee_id); |
280 | 280 | } |
281 | 281 | |
@@ -283,31 +283,31 @@ discard block |
||
283 | 283 | { |
284 | 284 | global $wpdb; |
285 | 285 | $cols_n_values = array( |
286 | - 'post_title' => stripslashes($old_attendee['fname'] . " " . $old_attendee['lname']),// ATT_full_name |
|
287 | - 'post_content' => '',// ATT_bio |
|
288 | - 'post_name' => sanitize_title($old_attendee['fname'] . "-" . $old_attendee['lname']),// ATT_slug |
|
289 | - 'post_date' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_created |
|
290 | - 'post_excerpt' => '',// ATT_short_bio |
|
291 | - 'post_modified' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_modified |
|
292 | - 'post_author' => 0,// ATT_author |
|
293 | - 'post_parent' => 0,// ATT_parent |
|
294 | - 'post_type' => 'espresso_attendees',// post_type |
|
286 | + 'post_title' => stripslashes($old_attendee['fname']." ".$old_attendee['lname']), // ATT_full_name |
|
287 | + 'post_content' => '', // ATT_bio |
|
288 | + 'post_name' => sanitize_title($old_attendee['fname']."-".$old_attendee['lname']), // ATT_slug |
|
289 | + 'post_date' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), // ATT_created |
|
290 | + 'post_excerpt' => '', // ATT_short_bio |
|
291 | + 'post_modified' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), // ATT_modified |
|
292 | + 'post_author' => 0, // ATT_author |
|
293 | + 'post_parent' => 0, // ATT_parent |
|
294 | + 'post_type' => 'espresso_attendees', // post_type |
|
295 | 295 | 'post_status' => 'publish'// status |
296 | 296 | ); |
297 | 297 | $datatypes = array( |
298 | - '%s',// ATT_full_name |
|
299 | - '%s',// ATT_bio |
|
300 | - '%s',// ATT_slug |
|
301 | - '%s',// ATT_created |
|
302 | - '%s',// ATT_short_bio |
|
303 | - '%s',// ATT_modified |
|
304 | - '%d',// ATT_author |
|
305 | - '%d',// ATT_parent |
|
306 | - '%s',// post_type |
|
307 | - '%s',// status |
|
298 | + '%s', // ATT_full_name |
|
299 | + '%s', // ATT_bio |
|
300 | + '%s', // ATT_slug |
|
301 | + '%s', // ATT_created |
|
302 | + '%s', // ATT_short_bio |
|
303 | + '%s', // ATT_modified |
|
304 | + '%d', // ATT_author |
|
305 | + '%d', // ATT_parent |
|
306 | + '%s', // post_type |
|
307 | + '%s', // status |
|
308 | 308 | ); |
309 | 309 | $success = $wpdb->insert($this->_new_attendee_cpt_table, $cols_n_values, $datatypes); |
310 | - if (!$success) { |
|
310 | + if ( ! $success) { |
|
311 | 311 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes)); |
312 | 312 | return 0; |
313 | 313 | } |
@@ -345,20 +345,20 @@ discard block |
||
345 | 345 | 'ATT_phone' => stripslashes($old_attendee['phone']), |
346 | 346 | ); |
347 | 347 | $datatypes = array( |
348 | - '%d',// ATT_ID |
|
349 | - '%s',// ATT_fname |
|
350 | - '%s',// ATT_lname |
|
351 | - '%s',// ATT_address |
|
352 | - '%s',// ATT_address2 |
|
353 | - '%s',// ATT_city |
|
354 | - '%d',// STA_ID |
|
355 | - '%s',// CNT_ISO |
|
356 | - '%s',// ATT_zip |
|
357 | - '%s',// ATT_email |
|
358 | - '%s',// ATT_phone |
|
348 | + '%d', // ATT_ID |
|
349 | + '%s', // ATT_fname |
|
350 | + '%s', // ATT_lname |
|
351 | + '%s', // ATT_address |
|
352 | + '%s', // ATT_address2 |
|
353 | + '%s', // ATT_city |
|
354 | + '%d', // STA_ID |
|
355 | + '%s', // CNT_ISO |
|
356 | + '%s', // ATT_zip |
|
357 | + '%s', // ATT_email |
|
358 | + '%s', // ATT_phone |
|
359 | 359 | ); |
360 | 360 | $success = $wpdb->insert($this->_new_attendee_meta_table, $cols_n_values, $datatypes); |
361 | - if (!$success) { |
|
361 | + if ( ! $success) { |
|
362 | 362 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_meta_table, $cols_n_values, $datatypes)); |
363 | 363 | return 0; |
364 | 364 | } |
@@ -382,13 +382,13 @@ discard block |
||
382 | 382 | if (intval($old_attendee['is_primary'])) {// primary attendee, so create txn |
383 | 383 | $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($old_attendee['id']), $this->_new_transaction_table); |
384 | 384 | } else { // non-primary attendee, so find its primary attendee's transaction |
385 | - $primary_attendee_old_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . $this->_old_table . " WHERE is_primary=1 and registration_id=%s", $old_attendee['registration_id'])); |
|
386 | - if (!$primary_attendee_old_id) { |
|
385 | + $primary_attendee_old_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM ".$this->_old_table." WHERE is_primary=1 and registration_id=%s", $old_attendee['registration_id'])); |
|
386 | + if ( ! $primary_attendee_old_id) { |
|
387 | 387 | $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee['registration_id']); |
388 | 388 | $primary_attendee_old_id = is_array($primary_attendee) ? $primary_attendee['id'] : null; |
389 | 389 | } |
390 | 390 | $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($primary_attendee_old_id), $this->_new_transaction_table); |
391 | - if (!$txn_id) { |
|
391 | + if ( ! $txn_id) { |
|
392 | 392 | $this->add_error(sprintf(__("Could not find primary attendee's new transaction. Current attendee is: %s, we think the 3.1 primary attendee for it has id %d, but there's no 4.1 transaction for that primary attendee id.", "event_espresso"), $this->_json_encode($old_attendee), $primary_attendee_old_id)); |
393 | 393 | $txn_id = 0; |
394 | 394 | } |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | // if there isn't yet a transaction row for this, create one |
397 | 397 | // (so even if it was a non-primary attendee with no EE3 primary attendee, |
398 | 398 | // it ought to have SOME transaction, so we'll make one) |
399 | - if (!$txn_id) { |
|
399 | + if ( ! $txn_id) { |
|
400 | 400 | // maps 3.1 payment stati onto 4.1 transaction stati |
401 | 401 | $txn_status_mapping = array( |
402 | 402 | 'Completed' => 'TCM', |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | 'Cancelled' => 'TIN', |
408 | 408 | 'Declined' => 'TIN' |
409 | 409 | ); |
410 | - $STS_ID = isset($txn_status_mapping[ $old_attendee['payment_status'] ]) ? $txn_status_mapping[ $old_attendee['payment_status'] ] : 'TIN'; |
|
410 | + $STS_ID = isset($txn_status_mapping[$old_attendee['payment_status']]) ? $txn_status_mapping[$old_attendee['payment_status']] : 'TIN'; |
|
411 | 411 | $cols_n_values = array( |
412 | 412 | 'TXN_timestamp' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
413 | 413 | 'TXN_total' => floatval($old_attendee['total_cost']), |
@@ -416,14 +416,14 @@ discard block |
||
416 | 416 | 'TXN_hash_salt' => $old_attendee['hashSalt'] |
417 | 417 | ); |
418 | 418 | $datatypes = array( |
419 | - '%s',// TXN_timestamp |
|
420 | - '%f',// TXN_total |
|
421 | - '%f',// TXN_paid |
|
422 | - '%s',// STS_ID |
|
423 | - '%s',// TXN_hash_salt |
|
419 | + '%s', // TXN_timestamp |
|
420 | + '%f', // TXN_total |
|
421 | + '%f', // TXN_paid |
|
422 | + '%s', // STS_ID |
|
423 | + '%s', // TXN_hash_salt |
|
424 | 424 | ); |
425 | 425 | $success = $wpdb->insert($this->_new_transaction_table, $cols_n_values, $datatypes); |
426 | - if (!$success) { |
|
426 | + if ( ! $success) { |
|
427 | 427 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_transaction_table, $cols_n_values, $datatypes)); |
428 | 428 | return 0; |
429 | 429 | } |
@@ -463,7 +463,7 @@ discard block |
||
463 | 463 | { |
464 | 464 | // need event default reg status and if pre_approval was required |
465 | 465 | global $wpdb; |
466 | - $event_required_pre_approval = $wpdb->get_var($wpdb->prepare("SELECT require_pre_approval FROM " . $wpdb->prefix . "events_detail WHERE id = %d", $old_attendee_row['event_id'])); |
|
466 | + $event_required_pre_approval = $wpdb->get_var($wpdb->prepare("SELECT require_pre_approval FROM ".$wpdb->prefix."events_detail WHERE id = %d", $old_attendee_row['event_id'])); |
|
467 | 467 | return $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID( |
468 | 468 | $old_attendee_row['payment_status'], |
469 | 469 | intval($event_required_pre_approval) && intval($old_attendee_row['pre_approve']) |
@@ -484,13 +484,13 @@ discard block |
||
484 | 484 | global $wpdb; |
485 | 485 | |
486 | 486 | $STS_ID = $this->_get_reg_status_for_old_payment_status($old_attendee); |
487 | - $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . 'events_detail', $old_attendee['event_id'], $wpdb->posts); |
|
488 | - if (!$new_event_id) { |
|
487 | + $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix.'events_detail', $old_attendee['event_id'], $wpdb->posts); |
|
488 | + if ( ! $new_event_id) { |
|
489 | 489 | $this->add_error(sprintf(__("Could not find NEW event CPT ID for old event '%d' on old attendee %s", "event_espresso"), $old_attendee['event_id'], $this->_json_encode($old_attendee))); |
490 | 490 | } |
491 | 491 | |
492 | 492 | $ticket_id = $this->_try_to_find_new_ticket_id($old_attendee, $new_event_id); |
493 | - if (!$ticket_id) { |
|
493 | + if ( ! $ticket_id) { |
|
494 | 494 | $ticket_id = $this->_insert_new_ticket_because_none_found($old_attendee, $new_event_id); |
495 | 495 | $this->add_error(sprintf(__('Could not find a ticket for old attendee with id %d for new event %d, so created a new ticket with id %d', 'event_espresso'), $old_attendee['id'], $new_event_id, $ticket_id)); |
496 | 496 | } |
@@ -514,30 +514,30 @@ discard block |
||
514 | 514 | 'REG_final_price' => $old_attendee['final_price'], |
515 | 515 | 'REG_session' => substr($old_attendee['attendee_session'], 0, 44), |
516 | 516 | 'REG_code' => sanitize_key($old_attendee['registration_id']), |
517 | - 'REG_url_link' => sanitize_key($old_attendee['registration_id'] . '-' . $count), |
|
517 | + 'REG_url_link' => sanitize_key($old_attendee['registration_id'].'-'.$count), |
|
518 | 518 | 'REG_count' => $regs_on_this_event_and_txn + $count, |
519 | 519 | 'REG_group_size' => $this->_sum_old_attendees_on_old_txn($old_attendee, false), |
520 | 520 | 'REG_att_is_going' => true, |
521 | 521 | 'REG_deleted' => false |
522 | 522 | ); |
523 | 523 | $datatypes = array( |
524 | - '%d',// EVT_ID |
|
525 | - '%d',// ATT_ID |
|
526 | - '%d',// TXN_ID |
|
527 | - '%d',// TKT_ID |
|
528 | - '%s',// STS_ID |
|
529 | - '%s',// REG_date |
|
530 | - '%f',// REG_final_price |
|
531 | - '%s',// REG_session |
|
532 | - '%s',// REG_code |
|
533 | - '%s',// REG_url_link |
|
534 | - '%d',// REG_count |
|
535 | - '%d',// REG_group_size |
|
536 | - '%d',// REG_att_is_going |
|
537 | - '%d',// REG_deleted |
|
524 | + '%d', // EVT_ID |
|
525 | + '%d', // ATT_ID |
|
526 | + '%d', // TXN_ID |
|
527 | + '%d', // TKT_ID |
|
528 | + '%s', // STS_ID |
|
529 | + '%s', // REG_date |
|
530 | + '%f', // REG_final_price |
|
531 | + '%s', // REG_session |
|
532 | + '%s', // REG_code |
|
533 | + '%s', // REG_url_link |
|
534 | + '%d', // REG_count |
|
535 | + '%d', // REG_group_size |
|
536 | + '%d', // REG_att_is_going |
|
537 | + '%d', // REG_deleted |
|
538 | 538 | ); |
539 | 539 | $success = $wpdb->insert($this->_new_reg_table, $cols_n_values, $datatypes); |
540 | - if (!$success) { |
|
540 | + if ( ! $success) { |
|
541 | 541 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_reg_table, $cols_n_values, $datatypes)); |
542 | 542 | return 0; |
543 | 543 | } |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | INNER JOIN {$this->_new_ticket_datetime_table} as DTK ON TKT.TKT_ID = DTK.TKT_ID |
574 | 574 | INNER JOIN {$this->_new_datetime_table} as DTT ON DTK.DTT_ID = DTT.DTT_ID |
575 | 575 | SET DTT.DTT_sold = DTT.DTT_sold + %d WHERE TKT.TKT_ID = %d", $quantity_sold, $new_ticket_id)); |
576 | - if (!$success_update_dateimtes) { |
|
576 | + if ( ! $success_update_dateimtes) { |
|
577 | 577 | $this->add_error(sprintf(__("Could not update datetimes related to ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error)); |
578 | 578 | } |
579 | 579 | } else { |
@@ -606,20 +606,20 @@ discard block |
||
606 | 606 | // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
607 | 607 | // the most important condition should be last, as it will be array_shift'ed off last |
608 | 608 | $conditions = array( |
609 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
610 | - $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price),// prices match? |
|
611 | - $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option),// names match? |
|
612 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
609 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime), // times match? |
|
610 | + $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price), // prices match? |
|
611 | + $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option), // names match? |
|
612 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id), // events match? |
|
613 | 613 | ); |
614 | 614 | $select_and_join_part = "SELECT $tickets_table.TKT_ID FROM $tickets_table INNER JOIN |
615 | 615 | $datetime_tickets_table ON $tickets_table.TKT_ID = $datetime_tickets_table.TKT_ID INNER JOIN |
616 | 616 | $datetime_table ON $datetime_tickets_table.DTT_ID = $datetime_table.DTT_ID"; |
617 | 617 | // start running queries, widening search each time by removing a condition |
618 | 618 | do { |
619 | - $full_query = $select_and_join_part . " WHERE " . implode(" AND ", $conditions) . " LIMIT 1"; |
|
619 | + $full_query = $select_and_join_part." WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
|
620 | 620 | $ticket_id_found = $wpdb->get_var($full_query); |
621 | 621 | array_shift($conditions); |
622 | - } while (!$ticket_id_found && $conditions); |
|
622 | + }while ( ! $ticket_id_found && $conditions); |
|
623 | 623 | return $ticket_id_found; |
624 | 624 | } |
625 | 625 | |
@@ -641,8 +641,8 @@ discard block |
||
641 | 641 | |
642 | 642 | |
643 | 643 | // insert new datetime unless we find one |
644 | - $datetime_id = $wpdb->get_var($wpdb->prepare("SELECT DTT_ID FROM " . $this->_new_datetime_table . " WHERE DTT_EVT_start=%s AND EVT_ID=%d LIMIT 1", $old_att_start_datetime, $new_event_id), ARRAY_A); |
|
645 | - if (!$datetime_id) { |
|
644 | + $datetime_id = $wpdb->get_var($wpdb->prepare("SELECT DTT_ID FROM ".$this->_new_datetime_table." WHERE DTT_EVT_start=%s AND EVT_ID=%d LIMIT 1", $old_att_start_datetime, $new_event_id), ARRAY_A); |
|
645 | + if ( ! $datetime_id) { |
|
646 | 646 | $old_att_end_date = $old_attendee['start_date']; |
647 | 647 | $old_att_end_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
648 | 648 | $old_att_end_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_end_date $old_att_end_time:00"); |
@@ -655,10 +655,10 @@ discard block |
||
655 | 655 | 'DTT_deleted' => true |
656 | 656 | ), |
657 | 657 | array( |
658 | - '%d',// EVT_ID |
|
659 | - '%s',// DTT_EVT_start |
|
660 | - '%s',// DTT_EVT_end |
|
661 | - '%d',// DTT_deleted |
|
658 | + '%d', // EVT_ID |
|
659 | + '%s', // DTT_EVT_start |
|
660 | + '%s', // DTT_EVT_end |
|
661 | + '%d', // DTT_deleted |
|
662 | 662 | ) |
663 | 663 | ); |
664 | 664 | $datetime_id = $wpdb->insert_id; |
@@ -666,21 +666,21 @@ discard block |
||
666 | 666 | |
667 | 667 | // insert new ticket |
668 | 668 | $success = $wpdb->insert( |
669 | - $wpdb->prefix . 'esp_ticket', |
|
669 | + $wpdb->prefix.'esp_ticket', |
|
670 | 670 | array( |
671 | 671 | 'TKT_name' => $old_att_price_option, |
672 | 672 | 'TKT_qty' => -1, |
673 | 673 | 'TKT_price' => $old_att_price, |
674 | - 'TKT_start_date' => $old_att_start_datetime,// we really have no clue what the time should be, but at least it was available when they attended |
|
674 | + 'TKT_start_date' => $old_att_start_datetime, // we really have no clue what the time should be, but at least it was available when they attended |
|
675 | 675 | 'TKT_end_date' => $old_att_end_datetime, |
676 | 676 | |
677 | 677 | ), |
678 | 678 | array( |
679 | - '%s',// name |
|
680 | - '%d',// qty |
|
681 | - '%d',// price |
|
682 | - '%s',// start_date |
|
683 | - '%s',// end_date |
|
679 | + '%s', // name |
|
680 | + '%d', // qty |
|
681 | + '%d', // price |
|
682 | + '%s', // start_date |
|
683 | + '%s', // end_date |
|
684 | 684 | ) |
685 | 685 | ); |
686 | 686 | $ticket_id = $wpdb->insert_id; |
@@ -692,8 +692,8 @@ discard block |
||
692 | 692 | 'TKT_ID' => $ticket_id |
693 | 693 | ), |
694 | 694 | array( |
695 | - '%d',// DTT_ID |
|
696 | - '%d',// TKT_ID |
|
695 | + '%d', // DTT_ID |
|
696 | + '%d', // TKT_ID |
|
697 | 697 | ) |
698 | 698 | ); |
699 | 699 | // insert new price |
@@ -706,10 +706,10 @@ discard block |
||
706 | 706 | 'PRC_deleted' => true |
707 | 707 | ), |
708 | 708 | array( |
709 | - '%d',// PRC_amount |
|
710 | - '%d',// PRT_ID |
|
711 | - '%s',// PRC_name |
|
712 | - '%d',// PRC_deleted |
|
709 | + '%d', // PRC_amount |
|
710 | + '%d', // PRT_ID |
|
711 | + '%s', // PRC_name |
|
712 | + '%d', // PRC_deleted |
|
713 | 713 | ) |
714 | 714 | ); |
715 | 715 | $price_id = $wpdb->insert_id; |
@@ -721,8 +721,8 @@ discard block |
||
721 | 721 | 'PRC_ID' => $price_id |
722 | 722 | ), |
723 | 723 | array( |
724 | - '%d',// TKT_ID |
|
725 | - '%d',// PRC_ID |
|
724 | + '%d', // TKT_ID |
|
725 | + '%d', // PRC_ID |
|
726 | 726 | ) |
727 | 727 | ); |
728 | 728 | return $ticket_id; |
@@ -740,7 +740,7 @@ discard block |
||
740 | 740 | { |
741 | 741 | global $wpdb; |
742 | 742 | $count_only_older_sql = $count_only_older ? $wpdb->prepare(" AND id<%d", $old_attendee_row['id']) : ''; |
743 | - $count = intval($wpdb->get_var($wpdb->prepare("SELECT SUM(quantity) FROM " . $this->_old_table . " WHERE registration_id=%s $count_only_older_sql", $old_attendee_row['registration_id']))); |
|
743 | + $count = intval($wpdb->get_var($wpdb->prepare("SELECT SUM(quantity) FROM ".$this->_old_table." WHERE registration_id=%s $count_only_older_sql", $old_attendee_row['registration_id']))); |
|
744 | 744 | |
745 | 745 | if ($this->_mer_tables_exist()) { |
746 | 746 | // if MER exists, then its a little tricky. |
@@ -763,7 +763,7 @@ discard block |
||
763 | 763 | // only add a payment for primary attendees |
764 | 764 | $old_pay_stati_indicating_no_payment = array('Pending', 'Incomplete', 'Not Completed'); |
765 | 765 | // if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment... |
766 | - if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && !in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) { |
|
766 | + if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && ! in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) { |
|
767 | 767 | $pay_status_mapping = array( |
768 | 768 | 'Completed' => 'PAP', |
769 | 769 | 'Payment Declined' => 'PDC', |
@@ -771,7 +771,7 @@ discard block |
||
771 | 771 | 'Declined' => 'PDC' |
772 | 772 | ); |
773 | 773 | $by_admin = $old_attendee['payment'] == 'Admin'; |
774 | - $STS_ID = isset($pay_status_mapping[ $old_attendee['payment_status'] ]) ? $pay_status_mapping[ $old_attendee['payment_status'] ] : 'PFL';// IE, if we don't recognize the status, assume payment failed |
|
774 | + $STS_ID = isset($pay_status_mapping[$old_attendee['payment_status']]) ? $pay_status_mapping[$old_attendee['payment_status']] : 'PFL'; // IE, if we don't recognize the status, assume payment failed |
|
775 | 775 | $cols_n_values = array( |
776 | 776 | 'TXN_ID' => $new_txn_id, |
777 | 777 | 'STS_ID' => $STS_ID, |
@@ -786,19 +786,19 @@ discard block |
||
786 | 786 | 'PAY_details' => $old_attendee['transaction_details'] |
787 | 787 | ); |
788 | 788 | $datatypes = array( |
789 | - '%d',// TXN_Id |
|
790 | - '%s',// STS_ID |
|
791 | - '%s',// PAY_timestamp |
|
792 | - '%s',// PAY_method |
|
793 | - '%f',// PAY_amount |
|
794 | - '%s',// PAY_gateway |
|
795 | - '%s',// PAY_gateway_response |
|
796 | - '%s',// PAY_txn_id_chq_nmbr |
|
797 | - '%d',// PAY_via_admin |
|
798 | - '%s',// PAY_details |
|
789 | + '%d', // TXN_Id |
|
790 | + '%s', // STS_ID |
|
791 | + '%s', // PAY_timestamp |
|
792 | + '%s', // PAY_method |
|
793 | + '%f', // PAY_amount |
|
794 | + '%s', // PAY_gateway |
|
795 | + '%s', // PAY_gateway_response |
|
796 | + '%s', // PAY_txn_id_chq_nmbr |
|
797 | + '%d', // PAY_via_admin |
|
798 | + '%s', // PAY_details |
|
799 | 799 | ); |
800 | 800 | $success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes); |
801 | - if (!$success) { |
|
801 | + if ( ! $success) { |
|
802 | 802 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes)); |
803 | 803 | return 0; |
804 | 804 | } |
@@ -817,7 +817,7 @@ discard block |
||
817 | 817 | */ |
818 | 818 | private function _find_mer_primary_attendee_using_mer_tables($old_registration_id) |
819 | 819 | { |
820 | - if (!$this->_mer_tables_exist()) { |
|
820 | + if ( ! $this->_mer_tables_exist()) { |
|
821 | 821 | return false; |
822 | 822 | } |
823 | 823 | global $wpdb; |
@@ -183,646 +183,646 @@ |
||
183 | 183 | */ |
184 | 184 | class EE_DMS_4_1_0_attendees extends EE_Data_Migration_Script_Stage_Table |
185 | 185 | { |
186 | - private $_new_attendee_cpt_table; |
|
187 | - private $_new_attendee_meta_table; |
|
188 | - private $_new_reg_table; |
|
189 | - private $_new_transaction_table; |
|
190 | - private $_new_payment_table; |
|
191 | - private $_new_line_table; |
|
192 | - private $_old_mer_table; |
|
193 | - private $_new_ticket_table; |
|
194 | - private $_new_ticket_datetime_table; |
|
195 | - private $_new_datetime_table; |
|
196 | - private $_new_datetime_ticket_table; |
|
197 | - private $_new_price_table; |
|
198 | - private $_new_ticket_price_table; |
|
199 | - /** |
|
200 | - * Rememebrs whether or not the mer table exists |
|
201 | - * @var boolean |
|
202 | - */ |
|
203 | - private $_mer_tables_exist = null; |
|
204 | - |
|
205 | - public function __construct() |
|
206 | - { |
|
207 | - global $wpdb; |
|
208 | - $this->_pretty_name = __("Attendees", "event_espresso"); |
|
209 | - $this->_old_table = $wpdb->prefix . "events_attendee"; |
|
210 | - // Only select the event status column from the event table. |
|
211 | - $this->select_expression = 'att.*, e.event_status'; |
|
212 | - // Only select attendees for events that aren't deleted. |
|
213 | - $this->_extra_where_sql = 'AS att |
|
186 | + private $_new_attendee_cpt_table; |
|
187 | + private $_new_attendee_meta_table; |
|
188 | + private $_new_reg_table; |
|
189 | + private $_new_transaction_table; |
|
190 | + private $_new_payment_table; |
|
191 | + private $_new_line_table; |
|
192 | + private $_old_mer_table; |
|
193 | + private $_new_ticket_table; |
|
194 | + private $_new_ticket_datetime_table; |
|
195 | + private $_new_datetime_table; |
|
196 | + private $_new_datetime_ticket_table; |
|
197 | + private $_new_price_table; |
|
198 | + private $_new_ticket_price_table; |
|
199 | + /** |
|
200 | + * Rememebrs whether or not the mer table exists |
|
201 | + * @var boolean |
|
202 | + */ |
|
203 | + private $_mer_tables_exist = null; |
|
204 | + |
|
205 | + public function __construct() |
|
206 | + { |
|
207 | + global $wpdb; |
|
208 | + $this->_pretty_name = __("Attendees", "event_espresso"); |
|
209 | + $this->_old_table = $wpdb->prefix . "events_attendee"; |
|
210 | + // Only select the event status column from the event table. |
|
211 | + $this->select_expression = 'att.*, e.event_status'; |
|
212 | + // Only select attendees for events that aren't deleted. |
|
213 | + $this->_extra_where_sql = 'AS att |
|
214 | 214 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
215 | 215 | WHERE e.event_status!="D"'; |
216 | - $this->_old_mer_table = $wpdb->prefix . "events_multi_event_registration_id_group"; |
|
217 | - $this->_new_attendee_cpt_table = $wpdb->posts; |
|
218 | - $this->_new_attendee_meta_table = $wpdb->prefix . "esp_attendee_meta"; |
|
219 | - $this->_new_reg_table = $wpdb->prefix . "esp_registration"; |
|
220 | - $this->_new_transaction_table = $wpdb->prefix . "esp_transaction"; |
|
221 | - $this->_new_payment_table = $wpdb->prefix . "esp_payment"; |
|
222 | - $this->_new_line_table = $wpdb->prefix . "esp_line_item"; |
|
223 | - $this->_new_ticket_table = $wpdb->prefix . "esp_ticket"; |
|
224 | - $this->_new_ticket_datetime_table = $wpdb->prefix . "esp_datetime_ticket"; |
|
225 | - $this->_new_datetime_table = $wpdb->prefix . "esp_datetime"; |
|
226 | - $this->_new_datetime_ticket_table = $wpdb->prefix . "esp_datetime_ticket"; |
|
227 | - $this->_new_price_table = $wpdb->prefix . "esp_price"; |
|
228 | - $this->_new_ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
229 | - parent::__construct(); |
|
230 | - } |
|
231 | - |
|
232 | - protected function _migrate_old_row($old_row) |
|
233 | - { |
|
234 | - // first check if there's already a new attendee with similar characteristics |
|
235 | - $new_att_id = $this->_find_attendee_cpt_matching($old_row); |
|
236 | - if (!$new_att_id) { |
|
237 | - $new_att_id = $this->_insert_new_attendee_cpt($old_row); |
|
238 | - if (!$new_att_id) { |
|
239 | - // if we couldnt even make an attendee, abandon all hope |
|
240 | - return false; |
|
241 | - } |
|
242 | - $new_att_meta_id = $this->_insert_attendee_meta_row($old_row, $new_att_id); |
|
243 | - if ($new_att_meta_id) { |
|
244 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_meta_table, $new_att_meta_id); |
|
245 | - } |
|
246 | - } |
|
247 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_cpt_table, $new_att_id); |
|
248 | - |
|
249 | - $txn_id = $this->_insert_new_transaction($old_row); |
|
250 | - if (!$txn_id) { |
|
251 | - // if we couldnt make the transaction, also abandon all hope |
|
252 | - return false; |
|
253 | - } |
|
254 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_transaction_table, $txn_id); |
|
255 | - $pay_id = $this->_insert_new_payment($old_row, $txn_id); |
|
256 | - if ($pay_id) { |
|
257 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_payment_table, $pay_id); |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - // even if there was no payment, we can go ahead with adding the reg |
|
262 | - $new_regs = $this->_insert_new_registrations($old_row, $new_att_id, $txn_id); |
|
263 | - if ($new_regs) { |
|
264 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_reg_table, $new_regs); |
|
265 | - } |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * Checks if there's already an attendee CPT in the db that has the same |
|
270 | - * first and last name, and email. If so, returns its ID as an int. |
|
271 | - * @global type $wpdb |
|
272 | - * @param array $old_attendee |
|
273 | - * @return int |
|
274 | - */ |
|
275 | - private function _find_attendee_cpt_matching($old_attendee) |
|
276 | - { |
|
277 | - global $wpdb; |
|
278 | - $existing_attendee_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . $this->_new_attendee_cpt_table . " AS cpt INNER JOIN " . $this->_new_attendee_meta_table . " AS meta ON cpt.ID = meta.ATT_ID WHERE meta.ATT_fname = %s AND meta.ATT_lname = %s AND meta.ATT_email = %s LIMIT 1", $old_attendee['fname'], $old_attendee['lname'], $old_attendee['email'])); |
|
279 | - return intval($existing_attendee_id); |
|
280 | - } |
|
281 | - |
|
282 | - private function _insert_new_attendee_cpt($old_attendee) |
|
283 | - { |
|
284 | - global $wpdb; |
|
285 | - $cols_n_values = array( |
|
286 | - 'post_title' => stripslashes($old_attendee['fname'] . " " . $old_attendee['lname']),// ATT_full_name |
|
287 | - 'post_content' => '',// ATT_bio |
|
288 | - 'post_name' => sanitize_title($old_attendee['fname'] . "-" . $old_attendee['lname']),// ATT_slug |
|
289 | - 'post_date' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_created |
|
290 | - 'post_excerpt' => '',// ATT_short_bio |
|
291 | - 'post_modified' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_modified |
|
292 | - 'post_author' => 0,// ATT_author |
|
293 | - 'post_parent' => 0,// ATT_parent |
|
294 | - 'post_type' => 'espresso_attendees',// post_type |
|
295 | - 'post_status' => 'publish'// status |
|
296 | - ); |
|
297 | - $datatypes = array( |
|
298 | - '%s',// ATT_full_name |
|
299 | - '%s',// ATT_bio |
|
300 | - '%s',// ATT_slug |
|
301 | - '%s',// ATT_created |
|
302 | - '%s',// ATT_short_bio |
|
303 | - '%s',// ATT_modified |
|
304 | - '%d',// ATT_author |
|
305 | - '%d',// ATT_parent |
|
306 | - '%s',// post_type |
|
307 | - '%s',// status |
|
308 | - ); |
|
309 | - $success = $wpdb->insert($this->_new_attendee_cpt_table, $cols_n_values, $datatypes); |
|
310 | - if (!$success) { |
|
311 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes)); |
|
312 | - return 0; |
|
313 | - } |
|
314 | - $new_id = $wpdb->insert_id; |
|
315 | - return $new_id; |
|
316 | - } |
|
317 | - |
|
318 | - private function _insert_attendee_meta_row($old_attendee, $new_attendee_cpt_id) |
|
319 | - { |
|
320 | - global $wpdb; |
|
321 | - // get the state and country ids from the old row |
|
322 | - try { |
|
323 | - $new_country = $this->get_migration_script()->get_or_create_country(stripslashes($old_attendee['country_id'])); |
|
324 | - $new_country_iso = $new_country['CNT_ISO']; |
|
325 | - } catch (EE_Error $exception) { |
|
326 | - $new_country_iso = $this->get_migration_script()->get_default_country_iso(); |
|
327 | - } |
|
328 | - try { |
|
329 | - $new_state = $this->get_migration_script()->get_or_create_state(stripslashes($old_attendee['state']), $new_country_iso); |
|
330 | - $new_state_id = $new_state['STA_ID']; |
|
331 | - } catch (EE_Error $exception) { |
|
332 | - $new_state_id = 0; |
|
333 | - } |
|
334 | - $cols_n_values = array( |
|
335 | - 'ATT_ID' => $new_attendee_cpt_id, |
|
336 | - 'ATT_fname' => stripslashes($old_attendee['fname']), |
|
337 | - 'ATT_lname' => stripslashes($old_attendee['lname']), |
|
338 | - 'ATT_address' => stripslashes($old_attendee['address']), |
|
339 | - 'ATT_address2' => stripslashes($old_attendee['address2']), |
|
340 | - 'ATT_city' => stripslashes($old_attendee['city']), |
|
341 | - 'STA_ID' => $new_state_id, |
|
342 | - 'CNT_ISO' => $new_country_iso, |
|
343 | - 'ATT_zip' => stripslashes($old_attendee['zip']), |
|
344 | - 'ATT_email' => stripslashes($old_attendee['email']), |
|
345 | - 'ATT_phone' => stripslashes($old_attendee['phone']), |
|
346 | - ); |
|
347 | - $datatypes = array( |
|
348 | - '%d',// ATT_ID |
|
349 | - '%s',// ATT_fname |
|
350 | - '%s',// ATT_lname |
|
351 | - '%s',// ATT_address |
|
352 | - '%s',// ATT_address2 |
|
353 | - '%s',// ATT_city |
|
354 | - '%d',// STA_ID |
|
355 | - '%s',// CNT_ISO |
|
356 | - '%s',// ATT_zip |
|
357 | - '%s',// ATT_email |
|
358 | - '%s',// ATT_phone |
|
359 | - ); |
|
360 | - $success = $wpdb->insert($this->_new_attendee_meta_table, $cols_n_values, $datatypes); |
|
361 | - if (!$success) { |
|
362 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_meta_table, $cols_n_values, $datatypes)); |
|
363 | - return 0; |
|
364 | - } |
|
365 | - $new_id = $wpdb->insert_id; |
|
366 | - return $new_id; |
|
367 | - } |
|
368 | - |
|
369 | - /** |
|
370 | - * Note: we don't necessarily create a new transaction for each attendee row. |
|
371 | - * Only if the old attendee 'is_primary' is true; otherwise we find the old attendee row that |
|
372 | - * 'is_primary' and has the same 'txn_id', then we return ITS new transaction id |
|
373 | - * @global type $wpdb |
|
374 | - * @param type $old_attendee |
|
375 | - * @return int new transaction id |
|
376 | - */ |
|
377 | - private function _insert_new_transaction($old_attendee) |
|
378 | - { |
|
379 | - global $wpdb; |
|
380 | - |
|
381 | - // first: let's check for an existing transaction for this old attendee |
|
382 | - if (intval($old_attendee['is_primary'])) {// primary attendee, so create txn |
|
383 | - $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($old_attendee['id']), $this->_new_transaction_table); |
|
384 | - } else { // non-primary attendee, so find its primary attendee's transaction |
|
385 | - $primary_attendee_old_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . $this->_old_table . " WHERE is_primary=1 and registration_id=%s", $old_attendee['registration_id'])); |
|
386 | - if (!$primary_attendee_old_id) { |
|
387 | - $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee['registration_id']); |
|
388 | - $primary_attendee_old_id = is_array($primary_attendee) ? $primary_attendee['id'] : null; |
|
389 | - } |
|
390 | - $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($primary_attendee_old_id), $this->_new_transaction_table); |
|
391 | - if (!$txn_id) { |
|
392 | - $this->add_error(sprintf(__("Could not find primary attendee's new transaction. Current attendee is: %s, we think the 3.1 primary attendee for it has id %d, but there's no 4.1 transaction for that primary attendee id.", "event_espresso"), $this->_json_encode($old_attendee), $primary_attendee_old_id)); |
|
393 | - $txn_id = 0; |
|
394 | - } |
|
395 | - } |
|
396 | - // if there isn't yet a transaction row for this, create one |
|
397 | - // (so even if it was a non-primary attendee with no EE3 primary attendee, |
|
398 | - // it ought to have SOME transaction, so we'll make one) |
|
399 | - if (!$txn_id) { |
|
400 | - // maps 3.1 payment stati onto 4.1 transaction stati |
|
401 | - $txn_status_mapping = array( |
|
402 | - 'Completed' => 'TCM', |
|
403 | - 'Pending' => 'TIN', |
|
404 | - 'Payment Declined' => 'TIN', |
|
405 | - 'Incomplete' => 'TIN', |
|
406 | - 'Not Completed' => 'TIN', |
|
407 | - 'Cancelled' => 'TIN', |
|
408 | - 'Declined' => 'TIN' |
|
409 | - ); |
|
410 | - $STS_ID = isset($txn_status_mapping[ $old_attendee['payment_status'] ]) ? $txn_status_mapping[ $old_attendee['payment_status'] ] : 'TIN'; |
|
411 | - $cols_n_values = array( |
|
412 | - 'TXN_timestamp' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
413 | - 'TXN_total' => floatval($old_attendee['total_cost']), |
|
414 | - 'TXN_paid' => floatval($old_attendee['amount_pd']), |
|
415 | - 'STS_ID' => $STS_ID, |
|
416 | - 'TXN_hash_salt' => $old_attendee['hashSalt'] |
|
417 | - ); |
|
418 | - $datatypes = array( |
|
419 | - '%s',// TXN_timestamp |
|
420 | - '%f',// TXN_total |
|
421 | - '%f',// TXN_paid |
|
422 | - '%s',// STS_ID |
|
423 | - '%s',// TXN_hash_salt |
|
424 | - ); |
|
425 | - $success = $wpdb->insert($this->_new_transaction_table, $cols_n_values, $datatypes); |
|
426 | - if (!$success) { |
|
427 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_transaction_table, $cols_n_values, $datatypes)); |
|
428 | - return 0; |
|
429 | - } |
|
430 | - $txn_id = $wpdb->insert_id; |
|
431 | - } |
|
432 | - |
|
433 | - return $txn_id; |
|
434 | - } |
|
435 | - |
|
436 | - /** |
|
437 | - * Detects if the MER tables exist |
|
438 | - * @global type $wpdb |
|
439 | - * @return boolean |
|
440 | - */ |
|
441 | - private function _mer_tables_exist() |
|
442 | - { |
|
443 | - if ($this->_mer_tables_exist === null) { |
|
444 | - global $wpdb; |
|
445 | - |
|
446 | - if ($wpdb->get_var("SHOW TABLES LIKE '{$this->_old_mer_table}'") != $this->_old_mer_table) { |
|
447 | - $this->_mer_tables_exist = false; |
|
448 | - } else { |
|
449 | - $this->_mer_tables_exist = true; |
|
450 | - } |
|
451 | - } |
|
452 | - return $this->_mer_tables_exist; |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * Gets the 4.1 registration's status given the 3.1 attendee row. We consider |
|
457 | - * whether the event required pre-approval or not,a dn the 4.1 payment status. |
|
458 | - * @global type $wpdb |
|
459 | - * @param type $old_attendee_row |
|
460 | - * @return string |
|
461 | - */ |
|
462 | - private function _get_reg_status_for_old_payment_status($old_attendee_row) |
|
463 | - { |
|
464 | - // need event default reg status and if pre_approval was required |
|
465 | - global $wpdb; |
|
466 | - $event_required_pre_approval = $wpdb->get_var($wpdb->prepare("SELECT require_pre_approval FROM " . $wpdb->prefix . "events_detail WHERE id = %d", $old_attendee_row['event_id'])); |
|
467 | - return $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID( |
|
468 | - $old_attendee_row['payment_status'], |
|
469 | - intval($event_required_pre_approval) && intval($old_attendee_row['pre_approve']) |
|
470 | - ); |
|
471 | - } |
|
472 | - |
|
473 | - /** |
|
474 | - * Adds however many rgistrations are indicated by the old attendee's QUANTITY field, |
|
475 | - * and returns an array of their IDs |
|
476 | - * @global type $wpdb |
|
477 | - * @param array $old_attendee |
|
478 | - * @param int $new_attendee_id |
|
479 | - * @param int $new_txn_id |
|
480 | - * @return array of new registratio ids |
|
481 | - */ |
|
482 | - private function _insert_new_registrations($old_attendee, $new_attendee_id, $new_txn_id) |
|
483 | - { |
|
484 | - global $wpdb; |
|
485 | - |
|
486 | - $STS_ID = $this->_get_reg_status_for_old_payment_status($old_attendee); |
|
487 | - $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . 'events_detail', $old_attendee['event_id'], $wpdb->posts); |
|
488 | - if (!$new_event_id) { |
|
489 | - $this->add_error(sprintf(__("Could not find NEW event CPT ID for old event '%d' on old attendee %s", "event_espresso"), $old_attendee['event_id'], $this->_json_encode($old_attendee))); |
|
490 | - } |
|
491 | - |
|
492 | - $ticket_id = $this->_try_to_find_new_ticket_id($old_attendee, $new_event_id); |
|
493 | - if (!$ticket_id) { |
|
494 | - $ticket_id = $this->_insert_new_ticket_because_none_found($old_attendee, $new_event_id); |
|
495 | - $this->add_error(sprintf(__('Could not find a ticket for old attendee with id %d for new event %d, so created a new ticket with id %d', 'event_espresso'), $old_attendee['id'], $new_event_id, $ticket_id)); |
|
496 | - } |
|
497 | - $regs_on_this_row = intval($old_attendee['quantity']); |
|
498 | - $new_regs = array(); |
|
499 | - // 4 cases we need to account for: |
|
500 | - // 1 old attendee_details row with a quantity of X (no mer) |
|
501 | - // Y old attendee_details rows with a quantity of 1 (no mer) joined by their common registration_id |
|
502 | - // Y old attendee_details rows with a quantity of x (because of mer) |
|
503 | - // Y old attendee_details rows with a quantity of 1 (because of mer) joined by wp_events_multi_event_registration_id_group |
|
504 | - for ($count = 1; $count <= $regs_on_this_row; $count++) { |
|
505 | - // sum regs on older rows |
|
506 | - $regs_on_this_event_and_txn = $this->_sum_old_attendees_on_old_txn($old_attendee, true); |
|
507 | - $cols_n_values = array( |
|
508 | - 'EVT_ID' => $new_event_id, |
|
509 | - 'ATT_ID' => $new_attendee_id, |
|
510 | - 'TXN_ID' => $new_txn_id, |
|
511 | - 'TKT_ID' => $ticket_id, |
|
512 | - 'STS_ID' => $STS_ID, |
|
513 | - 'REG_date' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
514 | - 'REG_final_price' => $old_attendee['final_price'], |
|
515 | - 'REG_session' => substr($old_attendee['attendee_session'], 0, 44), |
|
516 | - 'REG_code' => sanitize_key($old_attendee['registration_id']), |
|
517 | - 'REG_url_link' => sanitize_key($old_attendee['registration_id'] . '-' . $count), |
|
518 | - 'REG_count' => $regs_on_this_event_and_txn + $count, |
|
519 | - 'REG_group_size' => $this->_sum_old_attendees_on_old_txn($old_attendee, false), |
|
520 | - 'REG_att_is_going' => true, |
|
521 | - 'REG_deleted' => false |
|
522 | - ); |
|
523 | - $datatypes = array( |
|
524 | - '%d',// EVT_ID |
|
525 | - '%d',// ATT_ID |
|
526 | - '%d',// TXN_ID |
|
527 | - '%d',// TKT_ID |
|
528 | - '%s',// STS_ID |
|
529 | - '%s',// REG_date |
|
530 | - '%f',// REG_final_price |
|
531 | - '%s',// REG_session |
|
532 | - '%s',// REG_code |
|
533 | - '%s',// REG_url_link |
|
534 | - '%d',// REG_count |
|
535 | - '%d',// REG_group_size |
|
536 | - '%d',// REG_att_is_going |
|
537 | - '%d',// REG_deleted |
|
538 | - ); |
|
539 | - $success = $wpdb->insert($this->_new_reg_table, $cols_n_values, $datatypes); |
|
540 | - if (!$success) { |
|
541 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_reg_table, $cols_n_values, $datatypes)); |
|
542 | - return 0; |
|
543 | - } |
|
544 | - $cols_n_values['REG_ID'] = $wpdb->insert_id; |
|
545 | - $new_regs[] = $wpdb->insert_id; |
|
546 | - } |
|
547 | - $this->_add_regs_to_ticket_and_datetimes($ticket_id, count($new_regs), $STS_ID); |
|
548 | - return $new_regs; |
|
549 | - } |
|
550 | - |
|
551 | - /** |
|
552 | - * Increments the sold values on the ticket and its related datetimes by the amount sold, |
|
553 | - * which should be done directly after adding the rows. Yes this means we're constantly incrementing |
|
554 | - * the sold amounts as we go, and is less efficient than a single big query, |
|
555 | - * but its safer because we KNOW these regs have been added, rather than inferring |
|
556 | - * that they WILL be added (because the attendees stage runs nearly last during |
|
557 | - * the migration script) |
|
558 | - * @param type $new_ticket_id |
|
559 | - * @param type $sold |
|
560 | - * @param type $STS_ID |
|
561 | - * @return boolean whether they were successfully updated or not |
|
562 | - */ |
|
563 | - protected function _add_regs_to_ticket_and_datetimes($new_ticket_id, $quantity_sold, $STS_ID) |
|
564 | - { |
|
565 | - if ($STS_ID != 'RAP') { |
|
566 | - return true; |
|
567 | - } |
|
568 | - global $wpdb; |
|
569 | - $success = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} SET TKT_sold=TKT_sold+%d WHERE TKT_ID=%d", $quantity_sold, $new_ticket_id)); |
|
570 | - if ($success) { |
|
571 | - // get the ticket's datetimes, and increment them too |
|
572 | - $success_update_dateimtes = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT |
|
216 | + $this->_old_mer_table = $wpdb->prefix . "events_multi_event_registration_id_group"; |
|
217 | + $this->_new_attendee_cpt_table = $wpdb->posts; |
|
218 | + $this->_new_attendee_meta_table = $wpdb->prefix . "esp_attendee_meta"; |
|
219 | + $this->_new_reg_table = $wpdb->prefix . "esp_registration"; |
|
220 | + $this->_new_transaction_table = $wpdb->prefix . "esp_transaction"; |
|
221 | + $this->_new_payment_table = $wpdb->prefix . "esp_payment"; |
|
222 | + $this->_new_line_table = $wpdb->prefix . "esp_line_item"; |
|
223 | + $this->_new_ticket_table = $wpdb->prefix . "esp_ticket"; |
|
224 | + $this->_new_ticket_datetime_table = $wpdb->prefix . "esp_datetime_ticket"; |
|
225 | + $this->_new_datetime_table = $wpdb->prefix . "esp_datetime"; |
|
226 | + $this->_new_datetime_ticket_table = $wpdb->prefix . "esp_datetime_ticket"; |
|
227 | + $this->_new_price_table = $wpdb->prefix . "esp_price"; |
|
228 | + $this->_new_ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
229 | + parent::__construct(); |
|
230 | + } |
|
231 | + |
|
232 | + protected function _migrate_old_row($old_row) |
|
233 | + { |
|
234 | + // first check if there's already a new attendee with similar characteristics |
|
235 | + $new_att_id = $this->_find_attendee_cpt_matching($old_row); |
|
236 | + if (!$new_att_id) { |
|
237 | + $new_att_id = $this->_insert_new_attendee_cpt($old_row); |
|
238 | + if (!$new_att_id) { |
|
239 | + // if we couldnt even make an attendee, abandon all hope |
|
240 | + return false; |
|
241 | + } |
|
242 | + $new_att_meta_id = $this->_insert_attendee_meta_row($old_row, $new_att_id); |
|
243 | + if ($new_att_meta_id) { |
|
244 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_meta_table, $new_att_meta_id); |
|
245 | + } |
|
246 | + } |
|
247 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_cpt_table, $new_att_id); |
|
248 | + |
|
249 | + $txn_id = $this->_insert_new_transaction($old_row); |
|
250 | + if (!$txn_id) { |
|
251 | + // if we couldnt make the transaction, also abandon all hope |
|
252 | + return false; |
|
253 | + } |
|
254 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_transaction_table, $txn_id); |
|
255 | + $pay_id = $this->_insert_new_payment($old_row, $txn_id); |
|
256 | + if ($pay_id) { |
|
257 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_payment_table, $pay_id); |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + // even if there was no payment, we can go ahead with adding the reg |
|
262 | + $new_regs = $this->_insert_new_registrations($old_row, $new_att_id, $txn_id); |
|
263 | + if ($new_regs) { |
|
264 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_reg_table, $new_regs); |
|
265 | + } |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * Checks if there's already an attendee CPT in the db that has the same |
|
270 | + * first and last name, and email. If so, returns its ID as an int. |
|
271 | + * @global type $wpdb |
|
272 | + * @param array $old_attendee |
|
273 | + * @return int |
|
274 | + */ |
|
275 | + private function _find_attendee_cpt_matching($old_attendee) |
|
276 | + { |
|
277 | + global $wpdb; |
|
278 | + $existing_attendee_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . $this->_new_attendee_cpt_table . " AS cpt INNER JOIN " . $this->_new_attendee_meta_table . " AS meta ON cpt.ID = meta.ATT_ID WHERE meta.ATT_fname = %s AND meta.ATT_lname = %s AND meta.ATT_email = %s LIMIT 1", $old_attendee['fname'], $old_attendee['lname'], $old_attendee['email'])); |
|
279 | + return intval($existing_attendee_id); |
|
280 | + } |
|
281 | + |
|
282 | + private function _insert_new_attendee_cpt($old_attendee) |
|
283 | + { |
|
284 | + global $wpdb; |
|
285 | + $cols_n_values = array( |
|
286 | + 'post_title' => stripslashes($old_attendee['fname'] . " " . $old_attendee['lname']),// ATT_full_name |
|
287 | + 'post_content' => '',// ATT_bio |
|
288 | + 'post_name' => sanitize_title($old_attendee['fname'] . "-" . $old_attendee['lname']),// ATT_slug |
|
289 | + 'post_date' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_created |
|
290 | + 'post_excerpt' => '',// ATT_short_bio |
|
291 | + 'post_modified' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_modified |
|
292 | + 'post_author' => 0,// ATT_author |
|
293 | + 'post_parent' => 0,// ATT_parent |
|
294 | + 'post_type' => 'espresso_attendees',// post_type |
|
295 | + 'post_status' => 'publish'// status |
|
296 | + ); |
|
297 | + $datatypes = array( |
|
298 | + '%s',// ATT_full_name |
|
299 | + '%s',// ATT_bio |
|
300 | + '%s',// ATT_slug |
|
301 | + '%s',// ATT_created |
|
302 | + '%s',// ATT_short_bio |
|
303 | + '%s',// ATT_modified |
|
304 | + '%d',// ATT_author |
|
305 | + '%d',// ATT_parent |
|
306 | + '%s',// post_type |
|
307 | + '%s',// status |
|
308 | + ); |
|
309 | + $success = $wpdb->insert($this->_new_attendee_cpt_table, $cols_n_values, $datatypes); |
|
310 | + if (!$success) { |
|
311 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes)); |
|
312 | + return 0; |
|
313 | + } |
|
314 | + $new_id = $wpdb->insert_id; |
|
315 | + return $new_id; |
|
316 | + } |
|
317 | + |
|
318 | + private function _insert_attendee_meta_row($old_attendee, $new_attendee_cpt_id) |
|
319 | + { |
|
320 | + global $wpdb; |
|
321 | + // get the state and country ids from the old row |
|
322 | + try { |
|
323 | + $new_country = $this->get_migration_script()->get_or_create_country(stripslashes($old_attendee['country_id'])); |
|
324 | + $new_country_iso = $new_country['CNT_ISO']; |
|
325 | + } catch (EE_Error $exception) { |
|
326 | + $new_country_iso = $this->get_migration_script()->get_default_country_iso(); |
|
327 | + } |
|
328 | + try { |
|
329 | + $new_state = $this->get_migration_script()->get_or_create_state(stripslashes($old_attendee['state']), $new_country_iso); |
|
330 | + $new_state_id = $new_state['STA_ID']; |
|
331 | + } catch (EE_Error $exception) { |
|
332 | + $new_state_id = 0; |
|
333 | + } |
|
334 | + $cols_n_values = array( |
|
335 | + 'ATT_ID' => $new_attendee_cpt_id, |
|
336 | + 'ATT_fname' => stripslashes($old_attendee['fname']), |
|
337 | + 'ATT_lname' => stripslashes($old_attendee['lname']), |
|
338 | + 'ATT_address' => stripslashes($old_attendee['address']), |
|
339 | + 'ATT_address2' => stripslashes($old_attendee['address2']), |
|
340 | + 'ATT_city' => stripslashes($old_attendee['city']), |
|
341 | + 'STA_ID' => $new_state_id, |
|
342 | + 'CNT_ISO' => $new_country_iso, |
|
343 | + 'ATT_zip' => stripslashes($old_attendee['zip']), |
|
344 | + 'ATT_email' => stripslashes($old_attendee['email']), |
|
345 | + 'ATT_phone' => stripslashes($old_attendee['phone']), |
|
346 | + ); |
|
347 | + $datatypes = array( |
|
348 | + '%d',// ATT_ID |
|
349 | + '%s',// ATT_fname |
|
350 | + '%s',// ATT_lname |
|
351 | + '%s',// ATT_address |
|
352 | + '%s',// ATT_address2 |
|
353 | + '%s',// ATT_city |
|
354 | + '%d',// STA_ID |
|
355 | + '%s',// CNT_ISO |
|
356 | + '%s',// ATT_zip |
|
357 | + '%s',// ATT_email |
|
358 | + '%s',// ATT_phone |
|
359 | + ); |
|
360 | + $success = $wpdb->insert($this->_new_attendee_meta_table, $cols_n_values, $datatypes); |
|
361 | + if (!$success) { |
|
362 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_meta_table, $cols_n_values, $datatypes)); |
|
363 | + return 0; |
|
364 | + } |
|
365 | + $new_id = $wpdb->insert_id; |
|
366 | + return $new_id; |
|
367 | + } |
|
368 | + |
|
369 | + /** |
|
370 | + * Note: we don't necessarily create a new transaction for each attendee row. |
|
371 | + * Only if the old attendee 'is_primary' is true; otherwise we find the old attendee row that |
|
372 | + * 'is_primary' and has the same 'txn_id', then we return ITS new transaction id |
|
373 | + * @global type $wpdb |
|
374 | + * @param type $old_attendee |
|
375 | + * @return int new transaction id |
|
376 | + */ |
|
377 | + private function _insert_new_transaction($old_attendee) |
|
378 | + { |
|
379 | + global $wpdb; |
|
380 | + |
|
381 | + // first: let's check for an existing transaction for this old attendee |
|
382 | + if (intval($old_attendee['is_primary'])) {// primary attendee, so create txn |
|
383 | + $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($old_attendee['id']), $this->_new_transaction_table); |
|
384 | + } else { // non-primary attendee, so find its primary attendee's transaction |
|
385 | + $primary_attendee_old_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . $this->_old_table . " WHERE is_primary=1 and registration_id=%s", $old_attendee['registration_id'])); |
|
386 | + if (!$primary_attendee_old_id) { |
|
387 | + $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee['registration_id']); |
|
388 | + $primary_attendee_old_id = is_array($primary_attendee) ? $primary_attendee['id'] : null; |
|
389 | + } |
|
390 | + $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($primary_attendee_old_id), $this->_new_transaction_table); |
|
391 | + if (!$txn_id) { |
|
392 | + $this->add_error(sprintf(__("Could not find primary attendee's new transaction. Current attendee is: %s, we think the 3.1 primary attendee for it has id %d, but there's no 4.1 transaction for that primary attendee id.", "event_espresso"), $this->_json_encode($old_attendee), $primary_attendee_old_id)); |
|
393 | + $txn_id = 0; |
|
394 | + } |
|
395 | + } |
|
396 | + // if there isn't yet a transaction row for this, create one |
|
397 | + // (so even if it was a non-primary attendee with no EE3 primary attendee, |
|
398 | + // it ought to have SOME transaction, so we'll make one) |
|
399 | + if (!$txn_id) { |
|
400 | + // maps 3.1 payment stati onto 4.1 transaction stati |
|
401 | + $txn_status_mapping = array( |
|
402 | + 'Completed' => 'TCM', |
|
403 | + 'Pending' => 'TIN', |
|
404 | + 'Payment Declined' => 'TIN', |
|
405 | + 'Incomplete' => 'TIN', |
|
406 | + 'Not Completed' => 'TIN', |
|
407 | + 'Cancelled' => 'TIN', |
|
408 | + 'Declined' => 'TIN' |
|
409 | + ); |
|
410 | + $STS_ID = isset($txn_status_mapping[ $old_attendee['payment_status'] ]) ? $txn_status_mapping[ $old_attendee['payment_status'] ] : 'TIN'; |
|
411 | + $cols_n_values = array( |
|
412 | + 'TXN_timestamp' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
413 | + 'TXN_total' => floatval($old_attendee['total_cost']), |
|
414 | + 'TXN_paid' => floatval($old_attendee['amount_pd']), |
|
415 | + 'STS_ID' => $STS_ID, |
|
416 | + 'TXN_hash_salt' => $old_attendee['hashSalt'] |
|
417 | + ); |
|
418 | + $datatypes = array( |
|
419 | + '%s',// TXN_timestamp |
|
420 | + '%f',// TXN_total |
|
421 | + '%f',// TXN_paid |
|
422 | + '%s',// STS_ID |
|
423 | + '%s',// TXN_hash_salt |
|
424 | + ); |
|
425 | + $success = $wpdb->insert($this->_new_transaction_table, $cols_n_values, $datatypes); |
|
426 | + if (!$success) { |
|
427 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_transaction_table, $cols_n_values, $datatypes)); |
|
428 | + return 0; |
|
429 | + } |
|
430 | + $txn_id = $wpdb->insert_id; |
|
431 | + } |
|
432 | + |
|
433 | + return $txn_id; |
|
434 | + } |
|
435 | + |
|
436 | + /** |
|
437 | + * Detects if the MER tables exist |
|
438 | + * @global type $wpdb |
|
439 | + * @return boolean |
|
440 | + */ |
|
441 | + private function _mer_tables_exist() |
|
442 | + { |
|
443 | + if ($this->_mer_tables_exist === null) { |
|
444 | + global $wpdb; |
|
445 | + |
|
446 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$this->_old_mer_table}'") != $this->_old_mer_table) { |
|
447 | + $this->_mer_tables_exist = false; |
|
448 | + } else { |
|
449 | + $this->_mer_tables_exist = true; |
|
450 | + } |
|
451 | + } |
|
452 | + return $this->_mer_tables_exist; |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * Gets the 4.1 registration's status given the 3.1 attendee row. We consider |
|
457 | + * whether the event required pre-approval or not,a dn the 4.1 payment status. |
|
458 | + * @global type $wpdb |
|
459 | + * @param type $old_attendee_row |
|
460 | + * @return string |
|
461 | + */ |
|
462 | + private function _get_reg_status_for_old_payment_status($old_attendee_row) |
|
463 | + { |
|
464 | + // need event default reg status and if pre_approval was required |
|
465 | + global $wpdb; |
|
466 | + $event_required_pre_approval = $wpdb->get_var($wpdb->prepare("SELECT require_pre_approval FROM " . $wpdb->prefix . "events_detail WHERE id = %d", $old_attendee_row['event_id'])); |
|
467 | + return $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID( |
|
468 | + $old_attendee_row['payment_status'], |
|
469 | + intval($event_required_pre_approval) && intval($old_attendee_row['pre_approve']) |
|
470 | + ); |
|
471 | + } |
|
472 | + |
|
473 | + /** |
|
474 | + * Adds however many rgistrations are indicated by the old attendee's QUANTITY field, |
|
475 | + * and returns an array of their IDs |
|
476 | + * @global type $wpdb |
|
477 | + * @param array $old_attendee |
|
478 | + * @param int $new_attendee_id |
|
479 | + * @param int $new_txn_id |
|
480 | + * @return array of new registratio ids |
|
481 | + */ |
|
482 | + private function _insert_new_registrations($old_attendee, $new_attendee_id, $new_txn_id) |
|
483 | + { |
|
484 | + global $wpdb; |
|
485 | + |
|
486 | + $STS_ID = $this->_get_reg_status_for_old_payment_status($old_attendee); |
|
487 | + $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . 'events_detail', $old_attendee['event_id'], $wpdb->posts); |
|
488 | + if (!$new_event_id) { |
|
489 | + $this->add_error(sprintf(__("Could not find NEW event CPT ID for old event '%d' on old attendee %s", "event_espresso"), $old_attendee['event_id'], $this->_json_encode($old_attendee))); |
|
490 | + } |
|
491 | + |
|
492 | + $ticket_id = $this->_try_to_find_new_ticket_id($old_attendee, $new_event_id); |
|
493 | + if (!$ticket_id) { |
|
494 | + $ticket_id = $this->_insert_new_ticket_because_none_found($old_attendee, $new_event_id); |
|
495 | + $this->add_error(sprintf(__('Could not find a ticket for old attendee with id %d for new event %d, so created a new ticket with id %d', 'event_espresso'), $old_attendee['id'], $new_event_id, $ticket_id)); |
|
496 | + } |
|
497 | + $regs_on_this_row = intval($old_attendee['quantity']); |
|
498 | + $new_regs = array(); |
|
499 | + // 4 cases we need to account for: |
|
500 | + // 1 old attendee_details row with a quantity of X (no mer) |
|
501 | + // Y old attendee_details rows with a quantity of 1 (no mer) joined by their common registration_id |
|
502 | + // Y old attendee_details rows with a quantity of x (because of mer) |
|
503 | + // Y old attendee_details rows with a quantity of 1 (because of mer) joined by wp_events_multi_event_registration_id_group |
|
504 | + for ($count = 1; $count <= $regs_on_this_row; $count++) { |
|
505 | + // sum regs on older rows |
|
506 | + $regs_on_this_event_and_txn = $this->_sum_old_attendees_on_old_txn($old_attendee, true); |
|
507 | + $cols_n_values = array( |
|
508 | + 'EVT_ID' => $new_event_id, |
|
509 | + 'ATT_ID' => $new_attendee_id, |
|
510 | + 'TXN_ID' => $new_txn_id, |
|
511 | + 'TKT_ID' => $ticket_id, |
|
512 | + 'STS_ID' => $STS_ID, |
|
513 | + 'REG_date' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
514 | + 'REG_final_price' => $old_attendee['final_price'], |
|
515 | + 'REG_session' => substr($old_attendee['attendee_session'], 0, 44), |
|
516 | + 'REG_code' => sanitize_key($old_attendee['registration_id']), |
|
517 | + 'REG_url_link' => sanitize_key($old_attendee['registration_id'] . '-' . $count), |
|
518 | + 'REG_count' => $regs_on_this_event_and_txn + $count, |
|
519 | + 'REG_group_size' => $this->_sum_old_attendees_on_old_txn($old_attendee, false), |
|
520 | + 'REG_att_is_going' => true, |
|
521 | + 'REG_deleted' => false |
|
522 | + ); |
|
523 | + $datatypes = array( |
|
524 | + '%d',// EVT_ID |
|
525 | + '%d',// ATT_ID |
|
526 | + '%d',// TXN_ID |
|
527 | + '%d',// TKT_ID |
|
528 | + '%s',// STS_ID |
|
529 | + '%s',// REG_date |
|
530 | + '%f',// REG_final_price |
|
531 | + '%s',// REG_session |
|
532 | + '%s',// REG_code |
|
533 | + '%s',// REG_url_link |
|
534 | + '%d',// REG_count |
|
535 | + '%d',// REG_group_size |
|
536 | + '%d',// REG_att_is_going |
|
537 | + '%d',// REG_deleted |
|
538 | + ); |
|
539 | + $success = $wpdb->insert($this->_new_reg_table, $cols_n_values, $datatypes); |
|
540 | + if (!$success) { |
|
541 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_reg_table, $cols_n_values, $datatypes)); |
|
542 | + return 0; |
|
543 | + } |
|
544 | + $cols_n_values['REG_ID'] = $wpdb->insert_id; |
|
545 | + $new_regs[] = $wpdb->insert_id; |
|
546 | + } |
|
547 | + $this->_add_regs_to_ticket_and_datetimes($ticket_id, count($new_regs), $STS_ID); |
|
548 | + return $new_regs; |
|
549 | + } |
|
550 | + |
|
551 | + /** |
|
552 | + * Increments the sold values on the ticket and its related datetimes by the amount sold, |
|
553 | + * which should be done directly after adding the rows. Yes this means we're constantly incrementing |
|
554 | + * the sold amounts as we go, and is less efficient than a single big query, |
|
555 | + * but its safer because we KNOW these regs have been added, rather than inferring |
|
556 | + * that they WILL be added (because the attendees stage runs nearly last during |
|
557 | + * the migration script) |
|
558 | + * @param type $new_ticket_id |
|
559 | + * @param type $sold |
|
560 | + * @param type $STS_ID |
|
561 | + * @return boolean whether they were successfully updated or not |
|
562 | + */ |
|
563 | + protected function _add_regs_to_ticket_and_datetimes($new_ticket_id, $quantity_sold, $STS_ID) |
|
564 | + { |
|
565 | + if ($STS_ID != 'RAP') { |
|
566 | + return true; |
|
567 | + } |
|
568 | + global $wpdb; |
|
569 | + $success = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} SET TKT_sold=TKT_sold+%d WHERE TKT_ID=%d", $quantity_sold, $new_ticket_id)); |
|
570 | + if ($success) { |
|
571 | + // get the ticket's datetimes, and increment them too |
|
572 | + $success_update_dateimtes = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT |
|
573 | 573 | INNER JOIN {$this->_new_ticket_datetime_table} as DTK ON TKT.TKT_ID = DTK.TKT_ID |
574 | 574 | INNER JOIN {$this->_new_datetime_table} as DTT ON DTK.DTT_ID = DTT.DTT_ID |
575 | 575 | SET DTT.DTT_sold = DTT.DTT_sold + %d WHERE TKT.TKT_ID = %d", $quantity_sold, $new_ticket_id)); |
576 | - if (!$success_update_dateimtes) { |
|
577 | - $this->add_error(sprintf(__("Could not update datetimes related to ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error)); |
|
578 | - } |
|
579 | - } else { |
|
580 | - $this->add_error(sprintf(__("Could not update ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error)); |
|
581 | - } |
|
582 | - return true; |
|
583 | - } |
|
584 | - |
|
585 | - /** |
|
586 | - * Makes a best guess at which ticket is the one the attendee purchased. |
|
587 | - * Obviously, the old attendee's event_id narrows it down quite a bit; |
|
588 | - * then the old attendee's orig_price and event_time, and price_option can uniquely identify the ticket |
|
589 | - * however, if we don't find an exact match, see if any of those conditions match; |
|
590 | - * and lastly if none of that works, just use the first ticket for the event we find |
|
591 | - * @param array $old_attendee |
|
592 | - */ |
|
593 | - private function _try_to_find_new_ticket_id($old_attendee, $new_event_id) |
|
594 | - { |
|
595 | - global $wpdb; |
|
596 | - $tickets_table = $this->_new_ticket_table; |
|
597 | - $datetime_tickets_table = $this->_new_ticket_datetime_table; |
|
598 | - $datetime_table = $this->_new_datetime_table; |
|
599 | - |
|
600 | - $old_att_price_option = $old_attendee['price_option']; |
|
601 | - $old_att_price = floatval($old_attendee['orig_price']); |
|
602 | - |
|
603 | - $old_att_start_date = $old_attendee['start_date']; |
|
604 | - $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
605 | - $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
606 | - // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
607 | - // the most important condition should be last, as it will be array_shift'ed off last |
|
608 | - $conditions = array( |
|
609 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
610 | - $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price),// prices match? |
|
611 | - $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option),// names match? |
|
612 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
613 | - ); |
|
614 | - $select_and_join_part = "SELECT $tickets_table.TKT_ID FROM $tickets_table INNER JOIN |
|
576 | + if (!$success_update_dateimtes) { |
|
577 | + $this->add_error(sprintf(__("Could not update datetimes related to ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error)); |
|
578 | + } |
|
579 | + } else { |
|
580 | + $this->add_error(sprintf(__("Could not update ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error)); |
|
581 | + } |
|
582 | + return true; |
|
583 | + } |
|
584 | + |
|
585 | + /** |
|
586 | + * Makes a best guess at which ticket is the one the attendee purchased. |
|
587 | + * Obviously, the old attendee's event_id narrows it down quite a bit; |
|
588 | + * then the old attendee's orig_price and event_time, and price_option can uniquely identify the ticket |
|
589 | + * however, if we don't find an exact match, see if any of those conditions match; |
|
590 | + * and lastly if none of that works, just use the first ticket for the event we find |
|
591 | + * @param array $old_attendee |
|
592 | + */ |
|
593 | + private function _try_to_find_new_ticket_id($old_attendee, $new_event_id) |
|
594 | + { |
|
595 | + global $wpdb; |
|
596 | + $tickets_table = $this->_new_ticket_table; |
|
597 | + $datetime_tickets_table = $this->_new_ticket_datetime_table; |
|
598 | + $datetime_table = $this->_new_datetime_table; |
|
599 | + |
|
600 | + $old_att_price_option = $old_attendee['price_option']; |
|
601 | + $old_att_price = floatval($old_attendee['orig_price']); |
|
602 | + |
|
603 | + $old_att_start_date = $old_attendee['start_date']; |
|
604 | + $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
605 | + $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
606 | + // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
607 | + // the most important condition should be last, as it will be array_shift'ed off last |
|
608 | + $conditions = array( |
|
609 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
610 | + $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price),// prices match? |
|
611 | + $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option),// names match? |
|
612 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
613 | + ); |
|
614 | + $select_and_join_part = "SELECT $tickets_table.TKT_ID FROM $tickets_table INNER JOIN |
|
615 | 615 | $datetime_tickets_table ON $tickets_table.TKT_ID = $datetime_tickets_table.TKT_ID INNER JOIN |
616 | 616 | $datetime_table ON $datetime_tickets_table.DTT_ID = $datetime_table.DTT_ID"; |
617 | - // start running queries, widening search each time by removing a condition |
|
618 | - do { |
|
619 | - $full_query = $select_and_join_part . " WHERE " . implode(" AND ", $conditions) . " LIMIT 1"; |
|
620 | - $ticket_id_found = $wpdb->get_var($full_query); |
|
621 | - array_shift($conditions); |
|
622 | - } while (!$ticket_id_found && $conditions); |
|
623 | - return $ticket_id_found; |
|
624 | - } |
|
625 | - |
|
626 | - /** |
|
627 | - * If we couldn't find a 4.1 ticket for a 3.1 attendee row, this function creates one; |
|
628 | - * and it also tries to find a datetime that works, and a inserts a price, and associates |
|
629 | - * the new ticket to that datetime and price. |
|
630 | - * @return int ticket id |
|
631 | - */ |
|
632 | - private function _insert_new_ticket_because_none_found($old_attendee, $new_event_id) |
|
633 | - { |
|
634 | - global $wpdb; |
|
635 | - $old_att_price_option = $old_attendee['price_option']; |
|
636 | - $old_att_price = floatval($old_attendee['orig_price']); |
|
637 | - |
|
638 | - $old_att_start_date = $old_attendee['start_date']; |
|
639 | - $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
640 | - $old_att_start_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
641 | - |
|
642 | - |
|
643 | - // insert new datetime unless we find one |
|
644 | - $datetime_id = $wpdb->get_var($wpdb->prepare("SELECT DTT_ID FROM " . $this->_new_datetime_table . " WHERE DTT_EVT_start=%s AND EVT_ID=%d LIMIT 1", $old_att_start_datetime, $new_event_id), ARRAY_A); |
|
645 | - if (!$datetime_id) { |
|
646 | - $old_att_end_date = $old_attendee['start_date']; |
|
647 | - $old_att_end_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
648 | - $old_att_end_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_end_date $old_att_end_time:00"); |
|
649 | - $wpdb->insert( |
|
650 | - $this->_new_datetime_table, |
|
651 | - array( |
|
652 | - 'EVT_ID' => $new_event_id, |
|
653 | - 'DTT_EVT_start' => $old_att_start_datetime, |
|
654 | - 'DTT_EVT_end' => $old_att_end_datetime, |
|
655 | - 'DTT_deleted' => true |
|
656 | - ), |
|
657 | - array( |
|
658 | - '%d',// EVT_ID |
|
659 | - '%s',// DTT_EVT_start |
|
660 | - '%s',// DTT_EVT_end |
|
661 | - '%d',// DTT_deleted |
|
662 | - ) |
|
663 | - ); |
|
664 | - $datetime_id = $wpdb->insert_id; |
|
665 | - } |
|
666 | - |
|
667 | - // insert new ticket |
|
668 | - $success = $wpdb->insert( |
|
669 | - $wpdb->prefix . 'esp_ticket', |
|
670 | - array( |
|
671 | - 'TKT_name' => $old_att_price_option, |
|
672 | - 'TKT_qty' => -1, |
|
673 | - 'TKT_price' => $old_att_price, |
|
674 | - 'TKT_start_date' => $old_att_start_datetime,// we really have no clue what the time should be, but at least it was available when they attended |
|
675 | - 'TKT_end_date' => $old_att_end_datetime, |
|
676 | - |
|
677 | - ), |
|
678 | - array( |
|
679 | - '%s',// name |
|
680 | - '%d',// qty |
|
681 | - '%d',// price |
|
682 | - '%s',// start_date |
|
683 | - '%s',// end_date |
|
684 | - ) |
|
685 | - ); |
|
686 | - $ticket_id = $wpdb->insert_id; |
|
687 | - // associate the ticket with the datetime we found earlier |
|
688 | - $wpdb->insert( |
|
689 | - $this->_new_datetime_ticket_table, |
|
690 | - array( |
|
691 | - 'DTT_ID' => $datetime_id, |
|
692 | - 'TKT_ID' => $ticket_id |
|
693 | - ), |
|
694 | - array( |
|
695 | - '%d',// DTT_ID |
|
696 | - '%d',// TKT_ID |
|
697 | - ) |
|
698 | - ); |
|
699 | - // insert new price |
|
700 | - $wpdb->insert( |
|
701 | - $this->_new_price_table, |
|
702 | - array( |
|
703 | - 'PRC_amount' => $old_att_price, |
|
704 | - 'PRT_ID' => EE_DMS_4_1_0_prices::price_type_base, |
|
705 | - 'PRC_name' => $old_att_price_option, |
|
706 | - 'PRC_deleted' => true |
|
707 | - ), |
|
708 | - array( |
|
709 | - '%d',// PRC_amount |
|
710 | - '%d',// PRT_ID |
|
711 | - '%s',// PRC_name |
|
712 | - '%d',// PRC_deleted |
|
713 | - ) |
|
714 | - ); |
|
715 | - $price_id = $wpdb->insert_id; |
|
716 | - // associate the price to the ticket |
|
717 | - $wpdb->insert( |
|
718 | - $this->_new_ticket_price_table, |
|
719 | - array( |
|
720 | - 'TKT_ID' => $ticket_id, |
|
721 | - 'PRC_ID' => $price_id |
|
722 | - ), |
|
723 | - array( |
|
724 | - '%d',// TKT_ID |
|
725 | - '%d',// PRC_ID |
|
726 | - ) |
|
727 | - ); |
|
728 | - return $ticket_id; |
|
729 | - } |
|
730 | - |
|
731 | - /** |
|
732 | - * Counts all the registrations on this transaction. If $count_only_older is TRUE then returns the number added SO FAR (ie, |
|
733 | - * only considers attendee rows with an ID less than this one's), but if $count_only_older is FALSe returns ALL |
|
734 | - * @global type $wpdb |
|
735 | - * @param array $old_attendee_row |
|
736 | - * @param boolean $count_only_older true if you want the running count (ie, the total up to this row), and false if you want ALL |
|
737 | - * @return int |
|
738 | - */ |
|
739 | - private function _sum_old_attendees_on_old_txn($old_attendee_row, $count_only_older = false) |
|
740 | - { |
|
741 | - global $wpdb; |
|
742 | - $count_only_older_sql = $count_only_older ? $wpdb->prepare(" AND id<%d", $old_attendee_row['id']) : ''; |
|
743 | - $count = intval($wpdb->get_var($wpdb->prepare("SELECT SUM(quantity) FROM " . $this->_old_table . " WHERE registration_id=%s $count_only_older_sql", $old_attendee_row['registration_id']))); |
|
744 | - |
|
745 | - if ($this->_mer_tables_exist()) { |
|
746 | - // if MER exists, then its a little tricky. |
|
747 | - // when users registered by adding items to the cart, and it was a |
|
748 | - // group registration requiring additional attendee INFO, then the attendee rows |
|
749 | - // DO NOT have the same registration_id (although they probably should have) |
|
750 | - // they are related just like MER attendee rows are related, through the MER group table |
|
751 | - // BUT we want to count all the MER attendee rows for the same registration |
|
752 | - $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee_row['registration_id']); |
|
753 | - |
|
754 | - $count_using_mer_table = $wpdb->get_var($wpdb->prepare("SELECT SUM(quantity) FROM {$this->_old_table} att INNER JOIN {$this->_old_mer_table} mer ON att.registration_id = mer.registration_id WHERE att.event_id=%d AND mer.primary_registration_id = %s $count_only_older_sql", $old_attendee_row['event_id'], $primary_attendee['registration_id'])); |
|
755 | - $count = max($count_using_mer_table, $count); |
|
756 | - } |
|
757 | - return $count; |
|
758 | - } |
|
759 | - |
|
760 | - private function _insert_new_payment($old_attendee, $new_txn_id) |
|
761 | - { |
|
762 | - global $wpdb; |
|
763 | - // only add a payment for primary attendees |
|
764 | - $old_pay_stati_indicating_no_payment = array('Pending', 'Incomplete', 'Not Completed'); |
|
765 | - // if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment... |
|
766 | - if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && !in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) { |
|
767 | - $pay_status_mapping = array( |
|
768 | - 'Completed' => 'PAP', |
|
769 | - 'Payment Declined' => 'PDC', |
|
770 | - 'Cancelled' => 'PCN', |
|
771 | - 'Declined' => 'PDC' |
|
772 | - ); |
|
773 | - $by_admin = $old_attendee['payment'] == 'Admin'; |
|
774 | - $STS_ID = isset($pay_status_mapping[ $old_attendee['payment_status'] ]) ? $pay_status_mapping[ $old_attendee['payment_status'] ] : 'PFL';// IE, if we don't recognize the status, assume payment failed |
|
775 | - $cols_n_values = array( |
|
776 | - 'TXN_ID' => $new_txn_id, |
|
777 | - 'STS_ID' => $STS_ID, |
|
778 | - 'PAY_timestamp' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
779 | - 'PAY_method' => 'CART', |
|
780 | - 'PAY_amount' => $old_attendee['amount_pd'], |
|
781 | - // 'txn_type' was used both for the gateway's name, and for other payment notes. |
|
782 | - 'PAY_gateway' => $old_attendee['txn_type'], |
|
783 | - 'PAY_extra_accntng' => $old_attendee['txn_type'], |
|
784 | - 'PAY_gateway_response' => '', |
|
785 | - 'PAY_txn_id_chq_nmbr' => substr($old_attendee['txn_id'], 0, 32), |
|
786 | - 'PAY_via_admin' => $by_admin, |
|
787 | - 'PAY_details' => $old_attendee['transaction_details'] |
|
788 | - ); |
|
789 | - $datatypes = array( |
|
790 | - '%d',// TXN_Id |
|
791 | - '%s',// STS_ID |
|
792 | - '%s',// PAY_timestamp |
|
793 | - '%s',// PAY_method |
|
794 | - '%f',// PAY_amount |
|
795 | - '%s',// PAY_gateway |
|
796 | - '%s',// PAY_gateway_response |
|
797 | - '%s',// PAY_txn_id_chq_nmbr |
|
798 | - '%d',// PAY_via_admin |
|
799 | - '%s',// PAY_details |
|
800 | - ); |
|
801 | - $success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes); |
|
802 | - if (!$success) { |
|
803 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes)); |
|
804 | - return 0; |
|
805 | - } |
|
806 | - $new_id = $wpdb->insert_id; |
|
807 | - return $new_id; |
|
808 | - } else { |
|
809 | - return 0; |
|
810 | - } |
|
811 | - } |
|
812 | - |
|
813 | - /** |
|
814 | - * If MER is active, if you want ot fin dthe other registrations on that attendee row |
|
815 | - * @global type $wpdb |
|
816 | - * @param type $old_registration_id |
|
817 | - * @return array |
|
818 | - */ |
|
819 | - private function _find_mer_primary_attendee_using_mer_tables($old_registration_id) |
|
820 | - { |
|
821 | - if (!$this->_mer_tables_exist()) { |
|
822 | - return false; |
|
823 | - } |
|
824 | - global $wpdb; |
|
825 | - $old_att_for_primary_reg = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$this->_old_mer_table} AS mer INNER JOIN {$this->_old_table} AS att ON mer.primary_registration_id = att.registration_id WHERE mer.registration_id=%s LIMIT 1", $old_registration_id), ARRAY_A); |
|
826 | - return $old_att_for_primary_reg; |
|
827 | - } |
|
617 | + // start running queries, widening search each time by removing a condition |
|
618 | + do { |
|
619 | + $full_query = $select_and_join_part . " WHERE " . implode(" AND ", $conditions) . " LIMIT 1"; |
|
620 | + $ticket_id_found = $wpdb->get_var($full_query); |
|
621 | + array_shift($conditions); |
|
622 | + } while (!$ticket_id_found && $conditions); |
|
623 | + return $ticket_id_found; |
|
624 | + } |
|
625 | + |
|
626 | + /** |
|
627 | + * If we couldn't find a 4.1 ticket for a 3.1 attendee row, this function creates one; |
|
628 | + * and it also tries to find a datetime that works, and a inserts a price, and associates |
|
629 | + * the new ticket to that datetime and price. |
|
630 | + * @return int ticket id |
|
631 | + */ |
|
632 | + private function _insert_new_ticket_because_none_found($old_attendee, $new_event_id) |
|
633 | + { |
|
634 | + global $wpdb; |
|
635 | + $old_att_price_option = $old_attendee['price_option']; |
|
636 | + $old_att_price = floatval($old_attendee['orig_price']); |
|
637 | + |
|
638 | + $old_att_start_date = $old_attendee['start_date']; |
|
639 | + $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
640 | + $old_att_start_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
641 | + |
|
642 | + |
|
643 | + // insert new datetime unless we find one |
|
644 | + $datetime_id = $wpdb->get_var($wpdb->prepare("SELECT DTT_ID FROM " . $this->_new_datetime_table . " WHERE DTT_EVT_start=%s AND EVT_ID=%d LIMIT 1", $old_att_start_datetime, $new_event_id), ARRAY_A); |
|
645 | + if (!$datetime_id) { |
|
646 | + $old_att_end_date = $old_attendee['start_date']; |
|
647 | + $old_att_end_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
648 | + $old_att_end_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_end_date $old_att_end_time:00"); |
|
649 | + $wpdb->insert( |
|
650 | + $this->_new_datetime_table, |
|
651 | + array( |
|
652 | + 'EVT_ID' => $new_event_id, |
|
653 | + 'DTT_EVT_start' => $old_att_start_datetime, |
|
654 | + 'DTT_EVT_end' => $old_att_end_datetime, |
|
655 | + 'DTT_deleted' => true |
|
656 | + ), |
|
657 | + array( |
|
658 | + '%d',// EVT_ID |
|
659 | + '%s',// DTT_EVT_start |
|
660 | + '%s',// DTT_EVT_end |
|
661 | + '%d',// DTT_deleted |
|
662 | + ) |
|
663 | + ); |
|
664 | + $datetime_id = $wpdb->insert_id; |
|
665 | + } |
|
666 | + |
|
667 | + // insert new ticket |
|
668 | + $success = $wpdb->insert( |
|
669 | + $wpdb->prefix . 'esp_ticket', |
|
670 | + array( |
|
671 | + 'TKT_name' => $old_att_price_option, |
|
672 | + 'TKT_qty' => -1, |
|
673 | + 'TKT_price' => $old_att_price, |
|
674 | + 'TKT_start_date' => $old_att_start_datetime,// we really have no clue what the time should be, but at least it was available when they attended |
|
675 | + 'TKT_end_date' => $old_att_end_datetime, |
|
676 | + |
|
677 | + ), |
|
678 | + array( |
|
679 | + '%s',// name |
|
680 | + '%d',// qty |
|
681 | + '%d',// price |
|
682 | + '%s',// start_date |
|
683 | + '%s',// end_date |
|
684 | + ) |
|
685 | + ); |
|
686 | + $ticket_id = $wpdb->insert_id; |
|
687 | + // associate the ticket with the datetime we found earlier |
|
688 | + $wpdb->insert( |
|
689 | + $this->_new_datetime_ticket_table, |
|
690 | + array( |
|
691 | + 'DTT_ID' => $datetime_id, |
|
692 | + 'TKT_ID' => $ticket_id |
|
693 | + ), |
|
694 | + array( |
|
695 | + '%d',// DTT_ID |
|
696 | + '%d',// TKT_ID |
|
697 | + ) |
|
698 | + ); |
|
699 | + // insert new price |
|
700 | + $wpdb->insert( |
|
701 | + $this->_new_price_table, |
|
702 | + array( |
|
703 | + 'PRC_amount' => $old_att_price, |
|
704 | + 'PRT_ID' => EE_DMS_4_1_0_prices::price_type_base, |
|
705 | + 'PRC_name' => $old_att_price_option, |
|
706 | + 'PRC_deleted' => true |
|
707 | + ), |
|
708 | + array( |
|
709 | + '%d',// PRC_amount |
|
710 | + '%d',// PRT_ID |
|
711 | + '%s',// PRC_name |
|
712 | + '%d',// PRC_deleted |
|
713 | + ) |
|
714 | + ); |
|
715 | + $price_id = $wpdb->insert_id; |
|
716 | + // associate the price to the ticket |
|
717 | + $wpdb->insert( |
|
718 | + $this->_new_ticket_price_table, |
|
719 | + array( |
|
720 | + 'TKT_ID' => $ticket_id, |
|
721 | + 'PRC_ID' => $price_id |
|
722 | + ), |
|
723 | + array( |
|
724 | + '%d',// TKT_ID |
|
725 | + '%d',// PRC_ID |
|
726 | + ) |
|
727 | + ); |
|
728 | + return $ticket_id; |
|
729 | + } |
|
730 | + |
|
731 | + /** |
|
732 | + * Counts all the registrations on this transaction. If $count_only_older is TRUE then returns the number added SO FAR (ie, |
|
733 | + * only considers attendee rows with an ID less than this one's), but if $count_only_older is FALSe returns ALL |
|
734 | + * @global type $wpdb |
|
735 | + * @param array $old_attendee_row |
|
736 | + * @param boolean $count_only_older true if you want the running count (ie, the total up to this row), and false if you want ALL |
|
737 | + * @return int |
|
738 | + */ |
|
739 | + private function _sum_old_attendees_on_old_txn($old_attendee_row, $count_only_older = false) |
|
740 | + { |
|
741 | + global $wpdb; |
|
742 | + $count_only_older_sql = $count_only_older ? $wpdb->prepare(" AND id<%d", $old_attendee_row['id']) : ''; |
|
743 | + $count = intval($wpdb->get_var($wpdb->prepare("SELECT SUM(quantity) FROM " . $this->_old_table . " WHERE registration_id=%s $count_only_older_sql", $old_attendee_row['registration_id']))); |
|
744 | + |
|
745 | + if ($this->_mer_tables_exist()) { |
|
746 | + // if MER exists, then its a little tricky. |
|
747 | + // when users registered by adding items to the cart, and it was a |
|
748 | + // group registration requiring additional attendee INFO, then the attendee rows |
|
749 | + // DO NOT have the same registration_id (although they probably should have) |
|
750 | + // they are related just like MER attendee rows are related, through the MER group table |
|
751 | + // BUT we want to count all the MER attendee rows for the same registration |
|
752 | + $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee_row['registration_id']); |
|
753 | + |
|
754 | + $count_using_mer_table = $wpdb->get_var($wpdb->prepare("SELECT SUM(quantity) FROM {$this->_old_table} att INNER JOIN {$this->_old_mer_table} mer ON att.registration_id = mer.registration_id WHERE att.event_id=%d AND mer.primary_registration_id = %s $count_only_older_sql", $old_attendee_row['event_id'], $primary_attendee['registration_id'])); |
|
755 | + $count = max($count_using_mer_table, $count); |
|
756 | + } |
|
757 | + return $count; |
|
758 | + } |
|
759 | + |
|
760 | + private function _insert_new_payment($old_attendee, $new_txn_id) |
|
761 | + { |
|
762 | + global $wpdb; |
|
763 | + // only add a payment for primary attendees |
|
764 | + $old_pay_stati_indicating_no_payment = array('Pending', 'Incomplete', 'Not Completed'); |
|
765 | + // if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment... |
|
766 | + if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && !in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) { |
|
767 | + $pay_status_mapping = array( |
|
768 | + 'Completed' => 'PAP', |
|
769 | + 'Payment Declined' => 'PDC', |
|
770 | + 'Cancelled' => 'PCN', |
|
771 | + 'Declined' => 'PDC' |
|
772 | + ); |
|
773 | + $by_admin = $old_attendee['payment'] == 'Admin'; |
|
774 | + $STS_ID = isset($pay_status_mapping[ $old_attendee['payment_status'] ]) ? $pay_status_mapping[ $old_attendee['payment_status'] ] : 'PFL';// IE, if we don't recognize the status, assume payment failed |
|
775 | + $cols_n_values = array( |
|
776 | + 'TXN_ID' => $new_txn_id, |
|
777 | + 'STS_ID' => $STS_ID, |
|
778 | + 'PAY_timestamp' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
779 | + 'PAY_method' => 'CART', |
|
780 | + 'PAY_amount' => $old_attendee['amount_pd'], |
|
781 | + // 'txn_type' was used both for the gateway's name, and for other payment notes. |
|
782 | + 'PAY_gateway' => $old_attendee['txn_type'], |
|
783 | + 'PAY_extra_accntng' => $old_attendee['txn_type'], |
|
784 | + 'PAY_gateway_response' => '', |
|
785 | + 'PAY_txn_id_chq_nmbr' => substr($old_attendee['txn_id'], 0, 32), |
|
786 | + 'PAY_via_admin' => $by_admin, |
|
787 | + 'PAY_details' => $old_attendee['transaction_details'] |
|
788 | + ); |
|
789 | + $datatypes = array( |
|
790 | + '%d',// TXN_Id |
|
791 | + '%s',// STS_ID |
|
792 | + '%s',// PAY_timestamp |
|
793 | + '%s',// PAY_method |
|
794 | + '%f',// PAY_amount |
|
795 | + '%s',// PAY_gateway |
|
796 | + '%s',// PAY_gateway_response |
|
797 | + '%s',// PAY_txn_id_chq_nmbr |
|
798 | + '%d',// PAY_via_admin |
|
799 | + '%s',// PAY_details |
|
800 | + ); |
|
801 | + $success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes); |
|
802 | + if (!$success) { |
|
803 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes)); |
|
804 | + return 0; |
|
805 | + } |
|
806 | + $new_id = $wpdb->insert_id; |
|
807 | + return $new_id; |
|
808 | + } else { |
|
809 | + return 0; |
|
810 | + } |
|
811 | + } |
|
812 | + |
|
813 | + /** |
|
814 | + * If MER is active, if you want ot fin dthe other registrations on that attendee row |
|
815 | + * @global type $wpdb |
|
816 | + * @param type $old_registration_id |
|
817 | + * @return array |
|
818 | + */ |
|
819 | + private function _find_mer_primary_attendee_using_mer_tables($old_registration_id) |
|
820 | + { |
|
821 | + if (!$this->_mer_tables_exist()) { |
|
822 | + return false; |
|
823 | + } |
|
824 | + global $wpdb; |
|
825 | + $old_att_for_primary_reg = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$this->_old_mer_table} AS mer INNER JOIN {$this->_old_table} AS att ON mer.primary_registration_id = att.registration_id WHERE mer.registration_id=%s LIMIT 1", $old_registration_id), ARRAY_A); |
|
826 | + return $old_att_for_primary_reg; |
|
827 | + } |
|
828 | 828 | } |