@@ -26,147 +26,147 @@ |
||
| 26 | 26 | |
| 27 | 27 | class EE_DMS_4_1_0_checkins extends EE_Data_Migration_Script_Stage_Table |
| 28 | 28 | { |
| 29 | - private $_new_table; |
|
| 30 | - public function __construct() |
|
| 31 | - { |
|
| 32 | - global $wpdb; |
|
| 33 | - $this->_pretty_name = esc_html__('Checkins', 'event_espresso'); |
|
| 34 | - $this->_old_table = $wpdb->prefix."events_attendee"; |
|
| 35 | - $this->_extra_where_sql = 'AS att |
|
| 29 | + private $_new_table; |
|
| 30 | + public function __construct() |
|
| 31 | + { |
|
| 32 | + global $wpdb; |
|
| 33 | + $this->_pretty_name = esc_html__('Checkins', 'event_espresso'); |
|
| 34 | + $this->_old_table = $wpdb->prefix."events_attendee"; |
|
| 35 | + $this->_extra_where_sql = 'AS att |
|
| 36 | 36 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
| 37 | 37 | WHERE e.event_status!="D"'; |
| 38 | - $this->_new_table = $wpdb->prefix."esp_checkin"; |
|
| 39 | - parent::__construct(); |
|
| 40 | - } |
|
| 41 | - protected function _migrate_old_row($old_row) |
|
| 42 | - { |
|
| 43 | - global $wpdb; |
|
| 44 | - $new_reg_table = $wpdb->prefix."esp_registration"; |
|
| 38 | + $this->_new_table = $wpdb->prefix."esp_checkin"; |
|
| 39 | + parent::__construct(); |
|
| 40 | + } |
|
| 41 | + protected function _migrate_old_row($old_row) |
|
| 42 | + { |
|
| 43 | + global $wpdb; |
|
| 44 | + $new_reg_table = $wpdb->prefix."esp_registration"; |
|
| 45 | 45 | |
| 46 | - $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ; |
|
| 46 | + $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ; |
|
| 47 | 47 | |
| 48 | - $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
|
| 49 | - if (! $new_registrations_for_attendee) { |
|
| 50 | - $new_registrations_for_attendee = array(); |
|
| 51 | - } |
|
| 52 | - $new_datetime = $this->_try_to_find_datetime($old_row); |
|
| 48 | + $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
|
| 49 | + if (! $new_registrations_for_attendee) { |
|
| 50 | + $new_registrations_for_attendee = array(); |
|
| 51 | + } |
|
| 52 | + $new_datetime = $this->_try_to_find_datetime($old_row); |
|
| 53 | 53 | |
| 54 | - // make sure registrations array is numerically indexed starting at 0 (it probably already is) |
|
| 55 | - $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
|
| 56 | - $new_checkin_ids = array(); |
|
| 57 | - for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) { |
|
| 58 | - $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
| 59 | - if (! $new_reg_id) { |
|
| 60 | - $this->add_error(sprintf( |
|
| 61 | - esc_html__( |
|
| 62 | - /* translators: %1$s database row represented in JSON, %2$s number of registrations to check-in |
|
| 54 | + // make sure registrations array is numerically indexed starting at 0 (it probably already is) |
|
| 55 | + $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
|
| 56 | + $new_checkin_ids = array(); |
|
| 57 | + for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) { |
|
| 58 | + $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
| 59 | + if (! $new_reg_id) { |
|
| 60 | + $this->add_error(sprintf( |
|
| 61 | + esc_html__( |
|
| 62 | + /* translators: %1$s database row represented in JSON, %2$s number of registrations to check-in |
|
| 63 | 63 | * %3$s number of registrations for the attendee, %4$s new registration rows represented in JSON |
| 64 | 64 | */ |
| 65 | - // @codingStandardsIgnoreStart |
|
| 66 | - 'It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)', |
|
| 67 | - // @codingStandardsIgnoreEnd |
|
| 68 | - 'event_espresso' |
|
| 69 | - ), |
|
| 70 | - $this->_json_encode($old_row), |
|
| 71 | - abs($num_to_checkin_at_this_time), |
|
| 72 | - count($new_registrations_for_attendee), |
|
| 73 | - $this->_json_encode($new_registrations_for_attendee) |
|
| 74 | - )); |
|
| 75 | - break; |
|
| 76 | - } |
|
| 77 | - $existing_checkin_record = $wpdb->get_var( |
|
| 78 | - $wpdb->prepare( |
|
| 79 | - "SELECT CHK_ID FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", |
|
| 80 | - $new_reg_id |
|
| 81 | - ) |
|
| 82 | - ); |
|
| 83 | - if (! $existing_checkin_record) { |
|
| 84 | - $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
|
| 85 | - if ($new_id) { |
|
| 86 | - $new_checkin_ids[]= $new_id; |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - if ($new_checkin_ids) { |
|
| 91 | - $this->get_migration_script()->set_mapping( |
|
| 92 | - $this->_old_table, |
|
| 93 | - $old_row['id'], |
|
| 94 | - $this->_new_table, |
|
| 95 | - $new_checkin_ids |
|
| 96 | - ); |
|
| 97 | - } |
|
| 98 | - } |
|
| 65 | + // @codingStandardsIgnoreStart |
|
| 66 | + 'It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)', |
|
| 67 | + // @codingStandardsIgnoreEnd |
|
| 68 | + 'event_espresso' |
|
| 69 | + ), |
|
| 70 | + $this->_json_encode($old_row), |
|
| 71 | + abs($num_to_checkin_at_this_time), |
|
| 72 | + count($new_registrations_for_attendee), |
|
| 73 | + $this->_json_encode($new_registrations_for_attendee) |
|
| 74 | + )); |
|
| 75 | + break; |
|
| 76 | + } |
|
| 77 | + $existing_checkin_record = $wpdb->get_var( |
|
| 78 | + $wpdb->prepare( |
|
| 79 | + "SELECT CHK_ID FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", |
|
| 80 | + $new_reg_id |
|
| 81 | + ) |
|
| 82 | + ); |
|
| 83 | + if (! $existing_checkin_record) { |
|
| 84 | + $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
|
| 85 | + if ($new_id) { |
|
| 86 | + $new_checkin_ids[]= $new_id; |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + if ($new_checkin_ids) { |
|
| 91 | + $this->get_migration_script()->set_mapping( |
|
| 92 | + $this->_old_table, |
|
| 93 | + $old_row['id'], |
|
| 94 | + $this->_new_table, |
|
| 95 | + $new_checkin_ids |
|
| 96 | + ); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Tries to find the new datetime the Check-in was for, based on the attendee row |
|
| 103 | - * (because we know the attendee was for an event as a specific time, and we know |
|
| 104 | - * the event's OLD ID...) |
|
| 105 | - * @global type $wpdb |
|
| 106 | - * @param array $old_attendee_row |
|
| 107 | - * @return array row of datetime from DB |
|
| 108 | - */ |
|
| 109 | - private function _try_to_find_datetime($old_attendee) |
|
| 110 | - { |
|
| 111 | - global $wpdb; |
|
| 101 | + /** |
|
| 102 | + * Tries to find the new datetime the Check-in was for, based on the attendee row |
|
| 103 | + * (because we know the attendee was for an event as a specific time, and we know |
|
| 104 | + * the event's OLD ID...) |
|
| 105 | + * @global type $wpdb |
|
| 106 | + * @param array $old_attendee_row |
|
| 107 | + * @return array row of datetime from DB |
|
| 108 | + */ |
|
| 109 | + private function _try_to_find_datetime($old_attendee) |
|
| 110 | + { |
|
| 111 | + global $wpdb; |
|
| 112 | 112 | |
| 113 | - $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts); |
|
| 114 | - if (! $new_event_id) { |
|
| 115 | - $this->add_error(sprintf(esc_html__('Could not find new event ID with old event ID %d, on attendee row %s; and because of that couldn\'t find the correct datetime for Check-in', 'event_espresso'), $old_attendee['event_id'], $this->_json_encode($old_attendee))); |
|
| 116 | - return 0; |
|
| 117 | - } |
|
| 118 | - $old_att_start_date = $old_attendee['start_date']; |
|
| 119 | - $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
| 120 | - $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
| 113 | + $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts); |
|
| 114 | + if (! $new_event_id) { |
|
| 115 | + $this->add_error(sprintf(esc_html__('Could not find new event ID with old event ID %d, on attendee row %s; and because of that couldn\'t find the correct datetime for Check-in', 'event_espresso'), $old_attendee['event_id'], $this->_json_encode($old_attendee))); |
|
| 116 | + return 0; |
|
| 117 | + } |
|
| 118 | + $old_att_start_date = $old_attendee['start_date']; |
|
| 119 | + $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
| 120 | + $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
| 121 | 121 | |
| 122 | - $datetime_table = $wpdb->prefix."esp_datetime"; |
|
| 123 | - // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
| 124 | - // the most important condition should be last, as it will be array_shift'ed off last |
|
| 125 | - $conditions = array( |
|
| 126 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
| 127 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
| 128 | - ); |
|
| 129 | - // start running queries, widening search each time by removing a condition |
|
| 130 | - $datetime_found = null; |
|
| 131 | - do { |
|
| 132 | - $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
|
| 133 | - $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
|
| 134 | - array_shift($conditions); |
|
| 135 | - } while (! $datetime_found && $conditions); |
|
| 136 | - return $datetime_found; |
|
| 137 | - } |
|
| 122 | + $datetime_table = $wpdb->prefix."esp_datetime"; |
|
| 123 | + // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
| 124 | + // the most important condition should be last, as it will be array_shift'ed off last |
|
| 125 | + $conditions = array( |
|
| 126 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
| 127 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
| 128 | + ); |
|
| 129 | + // start running queries, widening search each time by removing a condition |
|
| 130 | + $datetime_found = null; |
|
| 131 | + do { |
|
| 132 | + $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
|
| 133 | + $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
|
| 134 | + array_shift($conditions); |
|
| 135 | + } while (! $datetime_found && $conditions); |
|
| 136 | + return $datetime_found; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap |
|
| 141 | - * @param int $new_reg_id |
|
| 142 | - * @param int $new_datetime_id |
|
| 143 | - * @param string $timestamp mysql datetime |
|
| 144 | - * @return int new Check-in id |
|
| 145 | - */ |
|
| 146 | - private function _insert_checkin_record($new_reg_id, $new_datetime) |
|
| 147 | - { |
|
| 148 | - global $wpdb; |
|
| 139 | + /** |
|
| 140 | + * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap |
|
| 141 | + * @param int $new_reg_id |
|
| 142 | + * @param int $new_datetime_id |
|
| 143 | + * @param string $timestamp mysql datetime |
|
| 144 | + * @return int new Check-in id |
|
| 145 | + */ |
|
| 146 | + private function _insert_checkin_record($new_reg_id, $new_datetime) |
|
| 147 | + { |
|
| 148 | + global $wpdb; |
|
| 149 | 149 | |
| 150 | 150 | |
| 151 | - // ok we can actually do what we set out to do: add a checkin/checkout record |
|
| 152 | - $cols_n_values = array( |
|
| 153 | - 'REG_ID'=>$new_reg_id, |
|
| 154 | - 'DTT_ID'=>$new_datetime['DTT_ID'], |
|
| 155 | - 'CHK_in'=>true, |
|
| 156 | - 'CHK_timestamp'=>$new_datetime['DTT_EVT_start'] |
|
| 157 | - ); |
|
| 158 | - $datatypes = array( |
|
| 159 | - '%d',// REG_ID |
|
| 160 | - '%d',// DTT_ID |
|
| 161 | - '%d',// CHK_in |
|
| 162 | - '%s',// CHK_timestamp |
|
| 163 | - ); |
|
| 164 | - $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
| 165 | - if (! $success) { |
|
| 166 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes)); |
|
| 167 | - return 0; |
|
| 168 | - } |
|
| 169 | - $new_id = $wpdb->insert_id; |
|
| 170 | - return $new_id; |
|
| 171 | - } |
|
| 151 | + // ok we can actually do what we set out to do: add a checkin/checkout record |
|
| 152 | + $cols_n_values = array( |
|
| 153 | + 'REG_ID'=>$new_reg_id, |
|
| 154 | + 'DTT_ID'=>$new_datetime['DTT_ID'], |
|
| 155 | + 'CHK_in'=>true, |
|
| 156 | + 'CHK_timestamp'=>$new_datetime['DTT_EVT_start'] |
|
| 157 | + ); |
|
| 158 | + $datatypes = array( |
|
| 159 | + '%d',// REG_ID |
|
| 160 | + '%d',// DTT_ID |
|
| 161 | + '%d',// CHK_in |
|
| 162 | + '%s',// CHK_timestamp |
|
| 163 | + ); |
|
| 164 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
| 165 | + if (! $success) { |
|
| 166 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes)); |
|
| 167 | + return 0; |
|
| 168 | + } |
|
| 169 | + $new_id = $wpdb->insert_id; |
|
| 170 | + return $new_id; |
|
| 171 | + } |
|
| 172 | 172 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | $this->_pretty_name = esc_html__('Checkins', 'event_espresso'); |
| 34 | 34 | $this->_old_table = $wpdb->prefix."events_attendee"; |
| 35 | 35 | $this->_extra_where_sql = 'AS att |
| 36 | - INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
|
| 36 | + INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id=e.id |
|
| 37 | 37 | WHERE e.event_status!="D"'; |
| 38 | 38 | $this->_new_table = $wpdb->prefix."esp_checkin"; |
| 39 | 39 | parent::__construct(); |
@@ -43,10 +43,10 @@ discard block |
||
| 43 | 43 | global $wpdb; |
| 44 | 44 | $new_reg_table = $wpdb->prefix."esp_registration"; |
| 45 | 45 | |
| 46 | - $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ; |
|
| 46 | + $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']), intval($old_row['checked_in']))); |
|
| 47 | 47 | |
| 48 | 48 | $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
| 49 | - if (! $new_registrations_for_attendee) { |
|
| 49 | + if ( ! $new_registrations_for_attendee) { |
|
| 50 | 50 | $new_registrations_for_attendee = array(); |
| 51 | 51 | } |
| 52 | 52 | $new_datetime = $this->_try_to_find_datetime($old_row); |
@@ -54,9 +54,9 @@ discard block |
||
| 54 | 54 | // make sure registrations array is numerically indexed starting at 0 (it probably already is) |
| 55 | 55 | $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
| 56 | 56 | $new_checkin_ids = array(); |
| 57 | - for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) { |
|
| 58 | - $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
| 59 | - if (! $new_reg_id) { |
|
| 57 | + for ($i = 0; $i < abs($num_to_checkin_at_this_time); $i++) { |
|
| 58 | + $new_reg_id = $new_registrations_for_attendee[$i]; |
|
| 59 | + if ( ! $new_reg_id) { |
|
| 60 | 60 | $this->add_error(sprintf( |
| 61 | 61 | esc_html__( |
| 62 | 62 | /* translators: %1$s database row represented in JSON, %2$s number of registrations to check-in |
@@ -80,10 +80,10 @@ discard block |
||
| 80 | 80 | $new_reg_id |
| 81 | 81 | ) |
| 82 | 82 | ); |
| 83 | - if (! $existing_checkin_record) { |
|
| 83 | + if ( ! $existing_checkin_record) { |
|
| 84 | 84 | $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
| 85 | 85 | if ($new_id) { |
| 86 | - $new_checkin_ids[]= $new_id; |
|
| 86 | + $new_checkin_ids[] = $new_id; |
|
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | } |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | global $wpdb; |
| 112 | 112 | |
| 113 | 113 | $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts); |
| 114 | - if (! $new_event_id) { |
|
| 114 | + if ( ! $new_event_id) { |
|
| 115 | 115 | $this->add_error(sprintf(esc_html__('Could not find new event ID with old event ID %d, on attendee row %s; and because of that couldn\'t find the correct datetime for Check-in', 'event_espresso'), $old_attendee['event_id'], $this->_json_encode($old_attendee))); |
| 116 | 116 | return 0; |
| 117 | 117 | } |
@@ -123,8 +123,8 @@ discard block |
||
| 123 | 123 | // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
| 124 | 124 | // the most important condition should be last, as it will be array_shift'ed off last |
| 125 | 125 | $conditions = array( |
| 126 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
| 127 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
| 126 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime), // times match? |
|
| 127 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id), // events match? |
|
| 128 | 128 | ); |
| 129 | 129 | // start running queries, widening search each time by removing a condition |
| 130 | 130 | $datetime_found = null; |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
| 133 | 133 | $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
| 134 | 134 | array_shift($conditions); |
| 135 | - } while (! $datetime_found && $conditions); |
|
| 135 | + }while ( ! $datetime_found && $conditions); |
|
| 136 | 136 | return $datetime_found; |
| 137 | 137 | } |
| 138 | 138 | |
@@ -156,13 +156,13 @@ discard block |
||
| 156 | 156 | 'CHK_timestamp'=>$new_datetime['DTT_EVT_start'] |
| 157 | 157 | ); |
| 158 | 158 | $datatypes = array( |
| 159 | - '%d',// REG_ID |
|
| 160 | - '%d',// DTT_ID |
|
| 161 | - '%d',// CHK_in |
|
| 162 | - '%s',// CHK_timestamp |
|
| 159 | + '%d', // REG_ID |
|
| 160 | + '%d', // DTT_ID |
|
| 161 | + '%d', // CHK_in |
|
| 162 | + '%s', // CHK_timestamp |
|
| 163 | 163 | ); |
| 164 | 164 | $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
| 165 | - if (! $success) { |
|
| 165 | + if ( ! $success) { |
|
| 166 | 166 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes)); |
| 167 | 167 | return 0; |
| 168 | 168 | } |