@@ -87,57 +87,57 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | class EE_DMS_4_1_0_prices extends EE_Data_Migration_Script_Stage_Table |
| 89 | 89 | { |
| 90 | - private $_new_price_table; |
|
| 91 | - private $_new_ticket_table; |
|
| 92 | - private $_new_ticket_price_table; |
|
| 93 | - private $_new_datetime_ticket_table; |
|
| 94 | - /** |
|
| 95 | - * A count of all the different tickets created, used for setting the new ones' TKT_Order |
|
| 96 | - * @var int |
|
| 97 | - */ |
|
| 98 | - private $_ticket_count = 0; |
|
| 99 | - const price_type_base = 1; |
|
| 100 | - const price_type_member_discount = 3; |
|
| 101 | - const price_type_percent_surcharge = 4; |
|
| 102 | - const price_type_flat_surcharge = 5; |
|
| 90 | + private $_new_price_table; |
|
| 91 | + private $_new_ticket_table; |
|
| 92 | + private $_new_ticket_price_table; |
|
| 93 | + private $_new_datetime_ticket_table; |
|
| 94 | + /** |
|
| 95 | + * A count of all the different tickets created, used for setting the new ones' TKT_Order |
|
| 96 | + * @var int |
|
| 97 | + */ |
|
| 98 | + private $_ticket_count = 0; |
|
| 99 | + const price_type_base = 1; |
|
| 100 | + const price_type_member_discount = 3; |
|
| 101 | + const price_type_percent_surcharge = 4; |
|
| 102 | + const price_type_flat_surcharge = 5; |
|
| 103 | 103 | |
| 104 | - public function __construct() |
|
| 105 | - { |
|
| 106 | - global $wpdb; |
|
| 107 | - $this->_pretty_name = __("Prices", "event_espresso"); |
|
| 108 | - $this->_old_table = $wpdb->prefix."events_prices"; |
|
| 109 | - $this->select_expression = 'p.*, e.event_status'; |
|
| 110 | - $this->_extra_where_sql = ' AS p |
|
| 104 | + public function __construct() |
|
| 105 | + { |
|
| 106 | + global $wpdb; |
|
| 107 | + $this->_pretty_name = __("Prices", "event_espresso"); |
|
| 108 | + $this->_old_table = $wpdb->prefix."events_prices"; |
|
| 109 | + $this->select_expression = 'p.*, e.event_status'; |
|
| 110 | + $this->_extra_where_sql = ' AS p |
|
| 111 | 111 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON p.event_id=e.id |
| 112 | 112 | WHERE e.event_status!="D"'; |
| 113 | - $this->_new_price_table = $wpdb->prefix."esp_price"; |
|
| 114 | - $this->_new_ticket_table = $wpdb->prefix."esp_ticket"; |
|
| 115 | - $this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price"; |
|
| 116 | - $this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket"; |
|
| 117 | - parent::__construct(); |
|
| 118 | - } |
|
| 119 | - protected function _migrate_old_row($old_row) |
|
| 120 | - { |
|
| 121 | - // create the base price |
|
| 122 | - $new_price_id = $this->_insert_new_price($old_row); |
|
| 123 | - // create the member discount if there is any |
|
| 124 | - // commented-out because we may actually NOT be supporting this in 4.1 |
|
| 113 | + $this->_new_price_table = $wpdb->prefix."esp_price"; |
|
| 114 | + $this->_new_ticket_table = $wpdb->prefix."esp_ticket"; |
|
| 115 | + $this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price"; |
|
| 116 | + $this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket"; |
|
| 117 | + parent::__construct(); |
|
| 118 | + } |
|
| 119 | + protected function _migrate_old_row($old_row) |
|
| 120 | + { |
|
| 121 | + // create the base price |
|
| 122 | + $new_price_id = $this->_insert_new_price($old_row); |
|
| 123 | + // create the member discount if there is any |
|
| 124 | + // commented-out because we may actually NOT be supporting this in 4.1 |
|
| 125 | 125 | // if($old_row['event_cost'] != $old_row['member_price']){ |
| 126 | 126 | // $member_price_discount_id = $this->_insert_new_member_price($old_row); |
| 127 | 127 | // }else{ |
| 128 | 128 | // $member_price_discount_id = 0; |
| 129 | 129 | // } |
| 130 | - // create the surcharge if there is any |
|
| 131 | - if (floatval($old_row['surcharge']) >= 0.01) { |
|
| 132 | - $surcharge_price_id = $this->_insert_new_surcharge_price($old_row); |
|
| 133 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id,$surcharge_price_id)); |
|
| 134 | - } else { |
|
| 135 | - $surcharge_price_id = 0; |
|
| 136 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id)); |
|
| 137 | - } |
|
| 138 | - // associate the ticket to all datetimes for event (ie, this ONE ticket grants access to ALL datetimes, not just one of the attendee's choice. |
|
| 139 | - // if the latter were the case, then we'd create a separate ticket for each datetime and ahve their association be one-to-one) |
|
| 140 | - // create ticket |
|
| 130 | + // create the surcharge if there is any |
|
| 131 | + if (floatval($old_row['surcharge']) >= 0.01) { |
|
| 132 | + $surcharge_price_id = $this->_insert_new_surcharge_price($old_row); |
|
| 133 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id,$surcharge_price_id)); |
|
| 134 | + } else { |
|
| 135 | + $surcharge_price_id = 0; |
|
| 136 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id)); |
|
| 137 | + } |
|
| 138 | + // associate the ticket to all datetimes for event (ie, this ONE ticket grants access to ALL datetimes, not just one of the attendee's choice. |
|
| 139 | + // if the latter were the case, then we'd create a separate ticket for each datetime and ahve their association be one-to-one) |
|
| 140 | + // create ticket |
|
| 141 | 141 | // $ticket_id = $this->_insert_new_ticket($old_row); |
| 142 | 142 | // if($ticket_id){ |
| 143 | 143 | // $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_ticket_table, $ticket_id); |
@@ -149,62 +149,62 @@ discard block |
||
| 149 | 149 | // $this->_insert_datetime_ticket_relation($new_datetime_id, $ticket_id); |
| 150 | 150 | // } |
| 151 | 151 | // } |
| 152 | - // create a ticket for each old price -old datetime combo |
|
| 153 | - $tickets_for_old_price = array(); |
|
| 154 | - foreach ($this->_get_datetime_ids_for_old_event_id($old_row['event_id']) as $new_datetime_id) { |
|
| 155 | - $ticket_id = $this->_insert_new_ticket($old_row); |
|
| 156 | - $tickets_for_old_price[] = $ticket_id; |
|
| 157 | - // associate to old prices |
|
| 158 | - $this->_insert_ticket_price_relation($ticket_id, $new_price_id); |
|
| 159 | - $this->_insert_ticket_price_relation($ticket_id, $surcharge_price_id); |
|
| 160 | - $this->_insert_datetime_ticket_relation($new_datetime_id, $ticket_id); |
|
| 161 | - } |
|
| 162 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_ticket_table, $tickets_for_old_price); |
|
| 163 | - } |
|
| 164 | - /** |
|
| 165 | - * Creates a 4.1 price base type |
|
| 166 | - * @global type $wpdb |
|
| 167 | - * @param type $old_price |
|
| 168 | - * @return int |
|
| 169 | - */ |
|
| 170 | - private function _insert_new_price($old_price) |
|
| 171 | - { |
|
| 172 | - global $wpdb; |
|
| 173 | - $cols_n_values = array( |
|
| 174 | - 'PRT_ID'=>self::price_type_base, |
|
| 175 | - 'PRC_amount'=>floatval($old_price['event_cost']), |
|
| 176 | - 'PRC_name'=>$old_price['price_type'], |
|
| 177 | - 'PRC_is_default'=>false, |
|
| 178 | - 'PRC_overrides'=>false, |
|
| 179 | - 'PRC_order'=>0, |
|
| 180 | - 'PRC_deleted'=>false, |
|
| 181 | - 'PRC_parent'=>null |
|
| 152 | + // create a ticket for each old price -old datetime combo |
|
| 153 | + $tickets_for_old_price = array(); |
|
| 154 | + foreach ($this->_get_datetime_ids_for_old_event_id($old_row['event_id']) as $new_datetime_id) { |
|
| 155 | + $ticket_id = $this->_insert_new_ticket($old_row); |
|
| 156 | + $tickets_for_old_price[] = $ticket_id; |
|
| 157 | + // associate to old prices |
|
| 158 | + $this->_insert_ticket_price_relation($ticket_id, $new_price_id); |
|
| 159 | + $this->_insert_ticket_price_relation($ticket_id, $surcharge_price_id); |
|
| 160 | + $this->_insert_datetime_ticket_relation($new_datetime_id, $ticket_id); |
|
| 161 | + } |
|
| 162 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_ticket_table, $tickets_for_old_price); |
|
| 163 | + } |
|
| 164 | + /** |
|
| 165 | + * Creates a 4.1 price base type |
|
| 166 | + * @global type $wpdb |
|
| 167 | + * @param type $old_price |
|
| 168 | + * @return int |
|
| 169 | + */ |
|
| 170 | + private function _insert_new_price($old_price) |
|
| 171 | + { |
|
| 172 | + global $wpdb; |
|
| 173 | + $cols_n_values = array( |
|
| 174 | + 'PRT_ID'=>self::price_type_base, |
|
| 175 | + 'PRC_amount'=>floatval($old_price['event_cost']), |
|
| 176 | + 'PRC_name'=>$old_price['price_type'], |
|
| 177 | + 'PRC_is_default'=>false, |
|
| 178 | + 'PRC_overrides'=>false, |
|
| 179 | + 'PRC_order'=>0, |
|
| 180 | + 'PRC_deleted'=>false, |
|
| 181 | + 'PRC_parent'=>null |
|
| 182 | 182 | |
| 183 | - ); |
|
| 184 | - $datatypes = array( |
|
| 185 | - '%d',// PRT_ID |
|
| 186 | - '%f',// PRT_amount |
|
| 187 | - '%s',// PRC_name |
|
| 188 | - '%d',// PRC_is_default |
|
| 189 | - '%d',// PRC_overrides |
|
| 190 | - '%d',// PRC_order |
|
| 191 | - '%d',// PRC_deleted |
|
| 192 | - '%d',// PRC_parent |
|
| 193 | - ); |
|
| 194 | - $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes); |
|
| 195 | - if (! $success) { |
|
| 196 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes)); |
|
| 197 | - return 0; |
|
| 198 | - } |
|
| 199 | - $new_id = $wpdb->insert_id; |
|
| 200 | - return $new_id; |
|
| 201 | - } |
|
| 202 | - /** |
|
| 203 | - * Creates a 4.1 member price discount |
|
| 204 | - * @global type $wpdb |
|
| 205 | - * @param type $old_price |
|
| 206 | - * @return int |
|
| 207 | - */ |
|
| 183 | + ); |
|
| 184 | + $datatypes = array( |
|
| 185 | + '%d',// PRT_ID |
|
| 186 | + '%f',// PRT_amount |
|
| 187 | + '%s',// PRC_name |
|
| 188 | + '%d',// PRC_is_default |
|
| 189 | + '%d',// PRC_overrides |
|
| 190 | + '%d',// PRC_order |
|
| 191 | + '%d',// PRC_deleted |
|
| 192 | + '%d',// PRC_parent |
|
| 193 | + ); |
|
| 194 | + $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes); |
|
| 195 | + if (! $success) { |
|
| 196 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes)); |
|
| 197 | + return 0; |
|
| 198 | + } |
|
| 199 | + $new_id = $wpdb->insert_id; |
|
| 200 | + return $new_id; |
|
| 201 | + } |
|
| 202 | + /** |
|
| 203 | + * Creates a 4.1 member price discount |
|
| 204 | + * @global type $wpdb |
|
| 205 | + * @param type $old_price |
|
| 206 | + * @return int |
|
| 207 | + */ |
|
| 208 | 208 | // private function _insert_new_member_price($old_price){ |
| 209 | 209 | // $discount_amount = floatval($old_price['event_cost']) - floatval($old_price['member_price']); |
| 210 | 210 | // global $wpdb; |
@@ -237,207 +237,207 @@ discard block |
||
| 237 | 237 | // $new_id = $wpdb->insert_id; |
| 238 | 238 | // return $new_id; |
| 239 | 239 | // } |
| 240 | - /** |
|
| 241 | - * Creates a 4.1 member price discount |
|
| 242 | - * @global type $wpdb |
|
| 243 | - * @param type $old_price |
|
| 244 | - * @return int |
|
| 245 | - */ |
|
| 246 | - private function _insert_new_surcharge_price($old_price) |
|
| 247 | - { |
|
| 240 | + /** |
|
| 241 | + * Creates a 4.1 member price discount |
|
| 242 | + * @global type $wpdb |
|
| 243 | + * @param type $old_price |
|
| 244 | + * @return int |
|
| 245 | + */ |
|
| 246 | + private function _insert_new_surcharge_price($old_price) |
|
| 247 | + { |
|
| 248 | 248 | |
| 249 | - if ($old_price['surcharge_type'] == 'flat_rate') { |
|
| 250 | - $price_type = self::price_type_flat_surcharge; |
|
| 251 | - } else { |
|
| 252 | - $price_type = self::price_type_percent_surcharge; |
|
| 253 | - } |
|
| 254 | - global $wpdb; |
|
| 255 | - $cols_n_values = array( |
|
| 256 | - 'PRT_ID'=>$price_type, |
|
| 257 | - 'PRC_amount'=>floatval($old_price['surcharge']), |
|
| 258 | - 'PRC_name'=> __("Surcharge", "event_espresso"), |
|
| 259 | - 'PRC_is_default'=>false, |
|
| 260 | - 'PRC_overrides'=>false, |
|
| 261 | - 'PRC_order'=>20, |
|
| 262 | - 'PRC_deleted'=>false, |
|
| 263 | - 'PRC_parent'=>null |
|
| 249 | + if ($old_price['surcharge_type'] == 'flat_rate') { |
|
| 250 | + $price_type = self::price_type_flat_surcharge; |
|
| 251 | + } else { |
|
| 252 | + $price_type = self::price_type_percent_surcharge; |
|
| 253 | + } |
|
| 254 | + global $wpdb; |
|
| 255 | + $cols_n_values = array( |
|
| 256 | + 'PRT_ID'=>$price_type, |
|
| 257 | + 'PRC_amount'=>floatval($old_price['surcharge']), |
|
| 258 | + 'PRC_name'=> __("Surcharge", "event_espresso"), |
|
| 259 | + 'PRC_is_default'=>false, |
|
| 260 | + 'PRC_overrides'=>false, |
|
| 261 | + 'PRC_order'=>20, |
|
| 262 | + 'PRC_deleted'=>false, |
|
| 263 | + 'PRC_parent'=>null |
|
| 264 | 264 | |
| 265 | - ); |
|
| 266 | - $datatypes = array( |
|
| 267 | - '%d',// PRT_ID |
|
| 268 | - '%f',// PRT_amount |
|
| 269 | - '%s',// PRC_name |
|
| 270 | - '%d',// PRC_is_default |
|
| 271 | - '%d',// PRC_overrides |
|
| 272 | - '%d',// PRC_order |
|
| 273 | - '%d',// PRC_deleted |
|
| 274 | - '%d',// PRC_parent |
|
| 275 | - ); |
|
| 276 | - $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes); |
|
| 277 | - if (! $success) { |
|
| 278 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes)); |
|
| 279 | - return 0; |
|
| 280 | - } |
|
| 281 | - $new_id = $wpdb->insert_id; |
|
| 282 | - return $new_id; |
|
| 283 | - } |
|
| 284 | - /** |
|
| 285 | - * Inserts a 4.1 ticket based off the 3.1 price, and the price IDs we've already made from the 3.1 price |
|
| 286 | - * @param $old_price_row array where keys are columns |
|
| 287 | - * @param $new_base_price_id int |
|
| 288 | - * @param $new_member_discount_id int |
|
| 289 | - * @param $new_surcharge_id int |
|
| 290 | - * @return int new ticket id |
|
| 291 | - */ |
|
| 292 | - private function _insert_new_ticket($old_price_row) |
|
| 293 | - { |
|
| 294 | - global $wpdb; |
|
| 295 | - $event_row = $this->_get_event_row($old_price_row['event_id']); |
|
| 296 | - if ($old_price_row['surcharge_type'] == 'flat_rate') { |
|
| 297 | - $final_ticket_price = floatval($old_price_row['event_cost']) + floatval($old_price_row['surcharge']); |
|
| 298 | - } else {// percent surcharge |
|
| 299 | - $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge'])/100); |
|
| 300 | - } |
|
| 301 | - $start_date = $event_row['registration_start']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_startT']); |
|
| 302 | - $start_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $start_date, $event_row['timezone_string']); |
|
| 303 | - $end_date = $event_row['registration_end']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_endT']); |
|
| 304 | - $end_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $end_date, $event_row['timezone_string']); |
|
| 305 | - $cols_n_values = array( |
|
| 306 | - 'TTM_ID'=>0, |
|
| 307 | - 'TKT_name'=>$old_price_row['price_type'], |
|
| 308 | - 'TKT_description'=>'', |
|
| 309 | - 'TKT_start_date'=>$start_date_utc, |
|
| 310 | - 'TKT_end_date'=>$end_date_utc, |
|
| 311 | - 'TKT_min'=>0, |
|
| 312 | - 'TKT_max'=>-1, |
|
| 313 | - 'TKT_price'=>$final_ticket_price, |
|
| 314 | - 'TKT_sold'=> 0,// note: this will get calculated as we actually add registrations during the migration |
|
| 315 | - 'TKT_qty'=> -1, |
|
| 316 | - 'TKT_uses'=> 1, |
|
| 317 | - 'TKT_taxable'=>false,// so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices |
|
| 318 | - 'TKT_is_default'=>false, |
|
| 319 | - 'TKT_order'=>$this->_get_ticket_count(), |
|
| 320 | - 'TKT_row'=>0,// doesn't matter because UI reset this on first save anyways |
|
| 321 | - 'TKT_deleted'=>false, |
|
| 322 | - 'TKT_parent'=>0 |
|
| 265 | + ); |
|
| 266 | + $datatypes = array( |
|
| 267 | + '%d',// PRT_ID |
|
| 268 | + '%f',// PRT_amount |
|
| 269 | + '%s',// PRC_name |
|
| 270 | + '%d',// PRC_is_default |
|
| 271 | + '%d',// PRC_overrides |
|
| 272 | + '%d',// PRC_order |
|
| 273 | + '%d',// PRC_deleted |
|
| 274 | + '%d',// PRC_parent |
|
| 275 | + ); |
|
| 276 | + $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes); |
|
| 277 | + if (! $success) { |
|
| 278 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes)); |
|
| 279 | + return 0; |
|
| 280 | + } |
|
| 281 | + $new_id = $wpdb->insert_id; |
|
| 282 | + return $new_id; |
|
| 283 | + } |
|
| 284 | + /** |
|
| 285 | + * Inserts a 4.1 ticket based off the 3.1 price, and the price IDs we've already made from the 3.1 price |
|
| 286 | + * @param $old_price_row array where keys are columns |
|
| 287 | + * @param $new_base_price_id int |
|
| 288 | + * @param $new_member_discount_id int |
|
| 289 | + * @param $new_surcharge_id int |
|
| 290 | + * @return int new ticket id |
|
| 291 | + */ |
|
| 292 | + private function _insert_new_ticket($old_price_row) |
|
| 293 | + { |
|
| 294 | + global $wpdb; |
|
| 295 | + $event_row = $this->_get_event_row($old_price_row['event_id']); |
|
| 296 | + if ($old_price_row['surcharge_type'] == 'flat_rate') { |
|
| 297 | + $final_ticket_price = floatval($old_price_row['event_cost']) + floatval($old_price_row['surcharge']); |
|
| 298 | + } else {// percent surcharge |
|
| 299 | + $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge'])/100); |
|
| 300 | + } |
|
| 301 | + $start_date = $event_row['registration_start']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_startT']); |
|
| 302 | + $start_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $start_date, $event_row['timezone_string']); |
|
| 303 | + $end_date = $event_row['registration_end']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_endT']); |
|
| 304 | + $end_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $end_date, $event_row['timezone_string']); |
|
| 305 | + $cols_n_values = array( |
|
| 306 | + 'TTM_ID'=>0, |
|
| 307 | + 'TKT_name'=>$old_price_row['price_type'], |
|
| 308 | + 'TKT_description'=>'', |
|
| 309 | + 'TKT_start_date'=>$start_date_utc, |
|
| 310 | + 'TKT_end_date'=>$end_date_utc, |
|
| 311 | + 'TKT_min'=>0, |
|
| 312 | + 'TKT_max'=>-1, |
|
| 313 | + 'TKT_price'=>$final_ticket_price, |
|
| 314 | + 'TKT_sold'=> 0,// note: this will get calculated as we actually add registrations during the migration |
|
| 315 | + 'TKT_qty'=> -1, |
|
| 316 | + 'TKT_uses'=> 1, |
|
| 317 | + 'TKT_taxable'=>false,// so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices |
|
| 318 | + 'TKT_is_default'=>false, |
|
| 319 | + 'TKT_order'=>$this->_get_ticket_count(), |
|
| 320 | + 'TKT_row'=>0,// doesn't matter because UI reset this on first save anyways |
|
| 321 | + 'TKT_deleted'=>false, |
|
| 322 | + 'TKT_parent'=>0 |
|
| 323 | 323 | |
| 324 | - ); |
|
| 325 | - $datatypes = array( |
|
| 326 | - '%d',// TTM_ID |
|
| 327 | - '%s',// TKT_name |
|
| 328 | - '%s',// TKT_description |
|
| 329 | - '%s',// TKT_start_date |
|
| 330 | - '%s',// TKT_end_date |
|
| 331 | - '%d',// TKT_min |
|
| 332 | - '%d',// TKT_max |
|
| 333 | - '%f',// TKT_price |
|
| 334 | - '%d',// TKT_sold |
|
| 335 | - '%d',// TKT_qty |
|
| 336 | - '%d',// TKT_uses |
|
| 337 | - '%d',// TKT_taxable |
|
| 338 | - '%d',// TKT_is_default |
|
| 339 | - '%d',// TKT_order |
|
| 340 | - '%d',// TKT_row |
|
| 341 | - '%d',// TKT_deleted |
|
| 342 | - '%d',// TKT_parent |
|
| 343 | - ); |
|
| 344 | - $success = $wpdb->insert($this->_new_ticket_table, $cols_n_values, $datatypes); |
|
| 345 | - if (! $success) { |
|
| 346 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price_row, $this->_new_ticket_table, $cols_n_values, $datatypes)); |
|
| 347 | - return 0; |
|
| 348 | - } |
|
| 349 | - $new_id = $wpdb->insert_id; |
|
| 350 | - return $new_id; |
|
| 351 | - } |
|
| 324 | + ); |
|
| 325 | + $datatypes = array( |
|
| 326 | + '%d',// TTM_ID |
|
| 327 | + '%s',// TKT_name |
|
| 328 | + '%s',// TKT_description |
|
| 329 | + '%s',// TKT_start_date |
|
| 330 | + '%s',// TKT_end_date |
|
| 331 | + '%d',// TKT_min |
|
| 332 | + '%d',// TKT_max |
|
| 333 | + '%f',// TKT_price |
|
| 334 | + '%d',// TKT_sold |
|
| 335 | + '%d',// TKT_qty |
|
| 336 | + '%d',// TKT_uses |
|
| 337 | + '%d',// TKT_taxable |
|
| 338 | + '%d',// TKT_is_default |
|
| 339 | + '%d',// TKT_order |
|
| 340 | + '%d',// TKT_row |
|
| 341 | + '%d',// TKT_deleted |
|
| 342 | + '%d',// TKT_parent |
|
| 343 | + ); |
|
| 344 | + $success = $wpdb->insert($this->_new_ticket_table, $cols_n_values, $datatypes); |
|
| 345 | + if (! $success) { |
|
| 346 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price_row, $this->_new_ticket_table, $cols_n_values, $datatypes)); |
|
| 347 | + return 0; |
|
| 348 | + } |
|
| 349 | + $new_id = $wpdb->insert_id; |
|
| 350 | + return $new_id; |
|
| 351 | + } |
|
| 352 | 352 | |
| 353 | - /** |
|
| 354 | - * Adds a join between a ticket and a price |
|
| 355 | - * @global type $wpdb |
|
| 356 | - * @param type $new_ticket_id |
|
| 357 | - * @param type $new_price_id |
|
| 358 | - * @return int |
|
| 359 | - */ |
|
| 360 | - private function _insert_ticket_price_relation($new_ticket_id, $new_price_id) |
|
| 361 | - { |
|
| 362 | - global $wpdb; |
|
| 363 | - $cols_n_values = array( |
|
| 364 | - 'TKT_ID'=>$new_ticket_id, |
|
| 365 | - 'PRC_ID'=>$new_price_id, |
|
| 366 | - ); |
|
| 367 | - $datatypes = array( |
|
| 368 | - '%d',// TKT_ID |
|
| 369 | - '%d',// PRC_ID |
|
| 370 | - ); |
|
| 371 | - $success = $wpdb->insert($this->_new_ticket_price_table, $cols_n_values, $datatypes); |
|
| 372 | - if (! $success) { |
|
| 373 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'price id'=>$new_price_id), $this->_new_ticket_price_table, $cols_n_values, $datatypes)); |
|
| 374 | - return 0; |
|
| 375 | - } |
|
| 376 | - $new_id = $wpdb->insert_id; |
|
| 377 | - return $new_id; |
|
| 378 | - } |
|
| 353 | + /** |
|
| 354 | + * Adds a join between a ticket and a price |
|
| 355 | + * @global type $wpdb |
|
| 356 | + * @param type $new_ticket_id |
|
| 357 | + * @param type $new_price_id |
|
| 358 | + * @return int |
|
| 359 | + */ |
|
| 360 | + private function _insert_ticket_price_relation($new_ticket_id, $new_price_id) |
|
| 361 | + { |
|
| 362 | + global $wpdb; |
|
| 363 | + $cols_n_values = array( |
|
| 364 | + 'TKT_ID'=>$new_ticket_id, |
|
| 365 | + 'PRC_ID'=>$new_price_id, |
|
| 366 | + ); |
|
| 367 | + $datatypes = array( |
|
| 368 | + '%d',// TKT_ID |
|
| 369 | + '%d',// PRC_ID |
|
| 370 | + ); |
|
| 371 | + $success = $wpdb->insert($this->_new_ticket_price_table, $cols_n_values, $datatypes); |
|
| 372 | + if (! $success) { |
|
| 373 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'price id'=>$new_price_id), $this->_new_ticket_price_table, $cols_n_values, $datatypes)); |
|
| 374 | + return 0; |
|
| 375 | + } |
|
| 376 | + $new_id = $wpdb->insert_id; |
|
| 377 | + return $new_id; |
|
| 378 | + } |
|
| 379 | 379 | |
| 380 | - /** |
|
| 381 | - * Adds a join between a ticket and a datetime |
|
| 382 | - * @global type $wpdb |
|
| 383 | - * @param type $new_ticket_id |
|
| 384 | - * @param type $new_price_id |
|
| 385 | - * @return int |
|
| 386 | - */ |
|
| 387 | - private function _insert_datetime_ticket_relation($new_datetime_id, $new_ticket_id) |
|
| 388 | - { |
|
| 389 | - global $wpdb; |
|
| 390 | - $cols_n_values = array( |
|
| 391 | - 'TKT_ID'=>$new_ticket_id, |
|
| 392 | - 'DTT_ID'=>$new_datetime_id, |
|
| 393 | - ); |
|
| 394 | - $datatypes = array( |
|
| 395 | - '%d',// TKT_ID |
|
| 396 | - '%d',// DTT_ID |
|
| 397 | - ); |
|
| 398 | - $success = $wpdb->insert($this->_new_datetime_ticket_table, $cols_n_values, $datatypes); |
|
| 399 | - if (! $success) { |
|
| 400 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'datetime id'=>$new_datetime_id), $this->_new_datetime_ticket_table, $cols_n_values, $datatypes)); |
|
| 401 | - return 0; |
|
| 402 | - } |
|
| 403 | - $new_id = $wpdb->insert_id; |
|
| 404 | - return $new_id; |
|
| 405 | - } |
|
| 380 | + /** |
|
| 381 | + * Adds a join between a ticket and a datetime |
|
| 382 | + * @global type $wpdb |
|
| 383 | + * @param type $new_ticket_id |
|
| 384 | + * @param type $new_price_id |
|
| 385 | + * @return int |
|
| 386 | + */ |
|
| 387 | + private function _insert_datetime_ticket_relation($new_datetime_id, $new_ticket_id) |
|
| 388 | + { |
|
| 389 | + global $wpdb; |
|
| 390 | + $cols_n_values = array( |
|
| 391 | + 'TKT_ID'=>$new_ticket_id, |
|
| 392 | + 'DTT_ID'=>$new_datetime_id, |
|
| 393 | + ); |
|
| 394 | + $datatypes = array( |
|
| 395 | + '%d',// TKT_ID |
|
| 396 | + '%d',// DTT_ID |
|
| 397 | + ); |
|
| 398 | + $success = $wpdb->insert($this->_new_datetime_ticket_table, $cols_n_values, $datatypes); |
|
| 399 | + if (! $success) { |
|
| 400 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'datetime id'=>$new_datetime_id), $this->_new_datetime_ticket_table, $cols_n_values, $datatypes)); |
|
| 401 | + return 0; |
|
| 402 | + } |
|
| 403 | + $new_id = $wpdb->insert_id; |
|
| 404 | + return $new_id; |
|
| 405 | + } |
|
| 406 | 406 | |
| 407 | - /** |
|
| 408 | - * Simply gets the 3.1 event row data |
|
| 409 | - * @global type $wpdb |
|
| 410 | - * @param type $event_id |
|
| 411 | - * @return array |
|
| 412 | - */ |
|
| 413 | - private function _get_event_row($event_id) |
|
| 414 | - { |
|
| 415 | - global $wpdb; |
|
| 416 | - $old_event_table = $wpdb->prefix."events_detail"; |
|
| 417 | - return $wpdb->get_row($wpdb->prepare("SELECT * FROM $old_event_table WHERE id=%d", $event_id), ARRAY_A); |
|
| 418 | - } |
|
| 419 | - /** |
|
| 420 | - * Gets a higher ticket count than last time it was called (and is persisted between HTTP requests). |
|
| 421 | - * Yes we COULD run a query joining events->datetimes->ticket_datetimes->tickets, but this should work fine too |
|
| 422 | - * @return int |
|
| 423 | - */ |
|
| 424 | - private function _get_ticket_count() |
|
| 425 | - { |
|
| 426 | - return $this->_ticket_count++; |
|
| 427 | - } |
|
| 407 | + /** |
|
| 408 | + * Simply gets the 3.1 event row data |
|
| 409 | + * @global type $wpdb |
|
| 410 | + * @param type $event_id |
|
| 411 | + * @return array |
|
| 412 | + */ |
|
| 413 | + private function _get_event_row($event_id) |
|
| 414 | + { |
|
| 415 | + global $wpdb; |
|
| 416 | + $old_event_table = $wpdb->prefix."events_detail"; |
|
| 417 | + return $wpdb->get_row($wpdb->prepare("SELECT * FROM $old_event_table WHERE id=%d", $event_id), ARRAY_A); |
|
| 418 | + } |
|
| 419 | + /** |
|
| 420 | + * Gets a higher ticket count than last time it was called (and is persisted between HTTP requests). |
|
| 421 | + * Yes we COULD run a query joining events->datetimes->ticket_datetimes->tickets, but this should work fine too |
|
| 422 | + * @return int |
|
| 423 | + */ |
|
| 424 | + private function _get_ticket_count() |
|
| 425 | + { |
|
| 426 | + return $this->_ticket_count++; |
|
| 427 | + } |
|
| 428 | 428 | |
| 429 | - /** |
|
| 430 | - * Using the 3.1 event id, gets the 4.1 datetimes for it |
|
| 431 | - * @param int $old_event_id |
|
| 432 | - * @return array where values are datetime ids |
|
| 433 | - */ |
|
| 434 | - private function _get_datetime_ids_for_old_event_id($old_event_id) |
|
| 435 | - { |
|
| 436 | - global $wpdb; |
|
| 437 | - $new_cpt_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_event_id, $wpdb->posts); |
|
| 438 | - $datetime_ids = $wpdb->get_col($wpdb->prepare("SELECT DTT_ID FROM {$wpdb->prefix}esp_datetime WHERE EVT_ID=%d", $new_cpt_id)); |
|
| 439 | - return $datetime_ids; |
|
| 440 | - } |
|
| 429 | + /** |
|
| 430 | + * Using the 3.1 event id, gets the 4.1 datetimes for it |
|
| 431 | + * @param int $old_event_id |
|
| 432 | + * @return array where values are datetime ids |
|
| 433 | + */ |
|
| 434 | + private function _get_datetime_ids_for_old_event_id($old_event_id) |
|
| 435 | + { |
|
| 436 | + global $wpdb; |
|
| 437 | + $new_cpt_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_event_id, $wpdb->posts); |
|
| 438 | + $datetime_ids = $wpdb->get_col($wpdb->prepare("SELECT DTT_ID FROM {$wpdb->prefix}esp_datetime WHERE EVT_ID=%d", $new_cpt_id)); |
|
| 439 | + return $datetime_ids; |
|
| 440 | + } |
|
| 441 | 441 | } |
| 442 | 442 | // @todo: tell users that in 3.1 the limit was on registration PER event,in 4.1 it's limit PER TICKET... SO, if they sell 2 different types of tickets |
| 443 | 443 | // |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | $this->_old_table = $wpdb->prefix."events_prices"; |
| 109 | 109 | $this->select_expression = 'p.*, e.event_status'; |
| 110 | 110 | $this->_extra_where_sql = ' AS p |
| 111 | - INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON p.event_id=e.id |
|
| 111 | + INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON p.event_id=e.id |
|
| 112 | 112 | WHERE e.event_status!="D"'; |
| 113 | 113 | $this->_new_price_table = $wpdb->prefix."esp_price"; |
| 114 | 114 | $this->_new_ticket_table = $wpdb->prefix."esp_ticket"; |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | // create the surcharge if there is any |
| 131 | 131 | if (floatval($old_row['surcharge']) >= 0.01) { |
| 132 | 132 | $surcharge_price_id = $this->_insert_new_surcharge_price($old_row); |
| 133 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id,$surcharge_price_id)); |
|
| 133 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id, $surcharge_price_id)); |
|
| 134 | 134 | } else { |
| 135 | 135 | $surcharge_price_id = 0; |
| 136 | 136 | $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id)); |
@@ -182,17 +182,17 @@ discard block |
||
| 182 | 182 | |
| 183 | 183 | ); |
| 184 | 184 | $datatypes = array( |
| 185 | - '%d',// PRT_ID |
|
| 186 | - '%f',// PRT_amount |
|
| 187 | - '%s',// PRC_name |
|
| 188 | - '%d',// PRC_is_default |
|
| 189 | - '%d',// PRC_overrides |
|
| 190 | - '%d',// PRC_order |
|
| 191 | - '%d',// PRC_deleted |
|
| 192 | - '%d',// PRC_parent |
|
| 185 | + '%d', // PRT_ID |
|
| 186 | + '%f', // PRT_amount |
|
| 187 | + '%s', // PRC_name |
|
| 188 | + '%d', // PRC_is_default |
|
| 189 | + '%d', // PRC_overrides |
|
| 190 | + '%d', // PRC_order |
|
| 191 | + '%d', // PRC_deleted |
|
| 192 | + '%d', // PRC_parent |
|
| 193 | 193 | ); |
| 194 | 194 | $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes); |
| 195 | - if (! $success) { |
|
| 195 | + if ( ! $success) { |
|
| 196 | 196 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes)); |
| 197 | 197 | return 0; |
| 198 | 198 | } |
@@ -264,17 +264,17 @@ discard block |
||
| 264 | 264 | |
| 265 | 265 | ); |
| 266 | 266 | $datatypes = array( |
| 267 | - '%d',// PRT_ID |
|
| 268 | - '%f',// PRT_amount |
|
| 269 | - '%s',// PRC_name |
|
| 270 | - '%d',// PRC_is_default |
|
| 271 | - '%d',// PRC_overrides |
|
| 272 | - '%d',// PRC_order |
|
| 273 | - '%d',// PRC_deleted |
|
| 274 | - '%d',// PRC_parent |
|
| 267 | + '%d', // PRT_ID |
|
| 268 | + '%f', // PRT_amount |
|
| 269 | + '%s', // PRC_name |
|
| 270 | + '%d', // PRC_is_default |
|
| 271 | + '%d', // PRC_overrides |
|
| 272 | + '%d', // PRC_order |
|
| 273 | + '%d', // PRC_deleted |
|
| 274 | + '%d', // PRC_parent |
|
| 275 | 275 | ); |
| 276 | 276 | $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes); |
| 277 | - if (! $success) { |
|
| 277 | + if ( ! $success) { |
|
| 278 | 278 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes)); |
| 279 | 279 | return 0; |
| 280 | 280 | } |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | if ($old_price_row['surcharge_type'] == 'flat_rate') { |
| 297 | 297 | $final_ticket_price = floatval($old_price_row['event_cost']) + floatval($old_price_row['surcharge']); |
| 298 | 298 | } else {// percent surcharge |
| 299 | - $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge'])/100); |
|
| 299 | + $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge']) / 100); |
|
| 300 | 300 | } |
| 301 | 301 | $start_date = $event_row['registration_start']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_startT']); |
| 302 | 302 | $start_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $start_date, $event_row['timezone_string']); |
@@ -311,38 +311,38 @@ discard block |
||
| 311 | 311 | 'TKT_min'=>0, |
| 312 | 312 | 'TKT_max'=>-1, |
| 313 | 313 | 'TKT_price'=>$final_ticket_price, |
| 314 | - 'TKT_sold'=> 0,// note: this will get calculated as we actually add registrations during the migration |
|
| 314 | + 'TKT_sold'=> 0, // note: this will get calculated as we actually add registrations during the migration |
|
| 315 | 315 | 'TKT_qty'=> -1, |
| 316 | 316 | 'TKT_uses'=> 1, |
| 317 | - 'TKT_taxable'=>false,// so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices |
|
| 317 | + 'TKT_taxable'=>false, // so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices |
|
| 318 | 318 | 'TKT_is_default'=>false, |
| 319 | 319 | 'TKT_order'=>$this->_get_ticket_count(), |
| 320 | - 'TKT_row'=>0,// doesn't matter because UI reset this on first save anyways |
|
| 320 | + 'TKT_row'=>0, // doesn't matter because UI reset this on first save anyways |
|
| 321 | 321 | 'TKT_deleted'=>false, |
| 322 | 322 | 'TKT_parent'=>0 |
| 323 | 323 | |
| 324 | 324 | ); |
| 325 | 325 | $datatypes = array( |
| 326 | - '%d',// TTM_ID |
|
| 327 | - '%s',// TKT_name |
|
| 328 | - '%s',// TKT_description |
|
| 329 | - '%s',// TKT_start_date |
|
| 330 | - '%s',// TKT_end_date |
|
| 331 | - '%d',// TKT_min |
|
| 332 | - '%d',// TKT_max |
|
| 333 | - '%f',// TKT_price |
|
| 334 | - '%d',// TKT_sold |
|
| 335 | - '%d',// TKT_qty |
|
| 336 | - '%d',// TKT_uses |
|
| 337 | - '%d',// TKT_taxable |
|
| 338 | - '%d',// TKT_is_default |
|
| 339 | - '%d',// TKT_order |
|
| 340 | - '%d',// TKT_row |
|
| 341 | - '%d',// TKT_deleted |
|
| 342 | - '%d',// TKT_parent |
|
| 326 | + '%d', // TTM_ID |
|
| 327 | + '%s', // TKT_name |
|
| 328 | + '%s', // TKT_description |
|
| 329 | + '%s', // TKT_start_date |
|
| 330 | + '%s', // TKT_end_date |
|
| 331 | + '%d', // TKT_min |
|
| 332 | + '%d', // TKT_max |
|
| 333 | + '%f', // TKT_price |
|
| 334 | + '%d', // TKT_sold |
|
| 335 | + '%d', // TKT_qty |
|
| 336 | + '%d', // TKT_uses |
|
| 337 | + '%d', // TKT_taxable |
|
| 338 | + '%d', // TKT_is_default |
|
| 339 | + '%d', // TKT_order |
|
| 340 | + '%d', // TKT_row |
|
| 341 | + '%d', // TKT_deleted |
|
| 342 | + '%d', // TKT_parent |
|
| 343 | 343 | ); |
| 344 | 344 | $success = $wpdb->insert($this->_new_ticket_table, $cols_n_values, $datatypes); |
| 345 | - if (! $success) { |
|
| 345 | + if ( ! $success) { |
|
| 346 | 346 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price_row, $this->_new_ticket_table, $cols_n_values, $datatypes)); |
| 347 | 347 | return 0; |
| 348 | 348 | } |
@@ -365,12 +365,12 @@ discard block |
||
| 365 | 365 | 'PRC_ID'=>$new_price_id, |
| 366 | 366 | ); |
| 367 | 367 | $datatypes = array( |
| 368 | - '%d',// TKT_ID |
|
| 369 | - '%d',// PRC_ID |
|
| 368 | + '%d', // TKT_ID |
|
| 369 | + '%d', // PRC_ID |
|
| 370 | 370 | ); |
| 371 | 371 | $success = $wpdb->insert($this->_new_ticket_price_table, $cols_n_values, $datatypes); |
| 372 | - if (! $success) { |
|
| 373 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'price id'=>$new_price_id), $this->_new_ticket_price_table, $cols_n_values, $datatypes)); |
|
| 372 | + if ( ! $success) { |
|
| 373 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id, 'price id'=>$new_price_id), $this->_new_ticket_price_table, $cols_n_values, $datatypes)); |
|
| 374 | 374 | return 0; |
| 375 | 375 | } |
| 376 | 376 | $new_id = $wpdb->insert_id; |
@@ -392,12 +392,12 @@ discard block |
||
| 392 | 392 | 'DTT_ID'=>$new_datetime_id, |
| 393 | 393 | ); |
| 394 | 394 | $datatypes = array( |
| 395 | - '%d',// TKT_ID |
|
| 396 | - '%d',// DTT_ID |
|
| 395 | + '%d', // TKT_ID |
|
| 396 | + '%d', // DTT_ID |
|
| 397 | 397 | ); |
| 398 | 398 | $success = $wpdb->insert($this->_new_datetime_ticket_table, $cols_n_values, $datatypes); |
| 399 | - if (! $success) { |
|
| 400 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'datetime id'=>$new_datetime_id), $this->_new_datetime_ticket_table, $cols_n_values, $datatypes)); |
|
| 399 | + if ( ! $success) { |
|
| 400 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id, 'datetime id'=>$new_datetime_id), $this->_new_datetime_ticket_table, $cols_n_values, $datatypes)); |
|
| 401 | 401 | return 0; |
| 402 | 402 | } |
| 403 | 403 | $new_id = $wpdb->insert_id; |
@@ -32,87 +32,87 @@ |
||
| 32 | 32 | |
| 33 | 33 | class EE_DMS_4_1_0_answers extends EE_Data_Migration_Script_Stage_Table |
| 34 | 34 | { |
| 35 | - private $_new_answer_table; |
|
| 36 | - private $_new_question_table; |
|
| 37 | - public function __construct() |
|
| 38 | - { |
|
| 39 | - global $wpdb; |
|
| 40 | - $this->_pretty_name = __("Answers", "event_espresso"); |
|
| 41 | - $this->_old_table = $wpdb->prefix."events_answer"; |
|
| 42 | - // join to attendee and then join to events table |
|
| 43 | - $this->select_expression = 'ans.*, e.event_status'; |
|
| 44 | - $this->_extra_where_sql = ' AS ans |
|
| 35 | + private $_new_answer_table; |
|
| 36 | + private $_new_question_table; |
|
| 37 | + public function __construct() |
|
| 38 | + { |
|
| 39 | + global $wpdb; |
|
| 40 | + $this->_pretty_name = __("Answers", "event_espresso"); |
|
| 41 | + $this->_old_table = $wpdb->prefix."events_answer"; |
|
| 42 | + // join to attendee and then join to events table |
|
| 43 | + $this->select_expression = 'ans.*, e.event_status'; |
|
| 44 | + $this->_extra_where_sql = ' AS ans |
|
| 45 | 45 | INNER JOIN ' . $wpdb->prefix . 'events_attendee AS att ON ans.attendee_id = att.id |
| 46 | 46 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id = e.id |
| 47 | 47 | WHERE e.event_status !="D"'; |
| 48 | - $this->_new_answer_table = $wpdb->prefix."esp_answer"; |
|
| 49 | - $this->_new_question_table = $wpdb->prefix."esp_question"; |
|
| 50 | - parent::__construct(); |
|
| 51 | - } |
|
| 52 | - protected function _migrate_old_row($old_row) |
|
| 53 | - { |
|
| 54 | - // get the new REGs for the old answer |
|
| 55 | - global $wpdb; |
|
| 56 | - $old_attendee_table = $wpdb->prefix."events_attendee"; |
|
| 57 | - $new_reg_table = $wpdb->prefix."esp_registration"; |
|
| 58 | - $regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table); |
|
| 59 | - if (! $regs) { |
|
| 60 | - $this->add_error(sprintf(__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row))); |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - // as inefficient as this sounds, we create an answer per REGISTRATION, (even if the registrations use the same attendee) |
|
| 64 | - foreach ($regs as $new_reg_id) { |
|
| 65 | - $new_answer_id = $this->_insert_new_answer($old_row, $new_reg_id); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - /** |
|
| 69 | - * Creates a 4.1 price base type |
|
| 70 | - * @global type $wpdb |
|
| 71 | - * @param array $old_price |
|
| 72 | - * @param int $new_reg_id |
|
| 73 | - * @return int |
|
| 74 | - */ |
|
| 75 | - private function _insert_new_answer($old_answer, $new_reg_id) |
|
| 76 | - { |
|
| 77 | - global $wpdb; |
|
| 78 | - $old_question_table = $wpdb->prefix."events_question"; |
|
| 79 | - $new_question_id = $this->get_migration_script()->get_mapping_new_pk($old_question_table, $old_answer['question_id'], $this->_new_question_table); |
|
| 48 | + $this->_new_answer_table = $wpdb->prefix."esp_answer"; |
|
| 49 | + $this->_new_question_table = $wpdb->prefix."esp_question"; |
|
| 50 | + parent::__construct(); |
|
| 51 | + } |
|
| 52 | + protected function _migrate_old_row($old_row) |
|
| 53 | + { |
|
| 54 | + // get the new REGs for the old answer |
|
| 55 | + global $wpdb; |
|
| 56 | + $old_attendee_table = $wpdb->prefix."events_attendee"; |
|
| 57 | + $new_reg_table = $wpdb->prefix."esp_registration"; |
|
| 58 | + $regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table); |
|
| 59 | + if (! $regs) { |
|
| 60 | + $this->add_error(sprintf(__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row))); |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + // as inefficient as this sounds, we create an answer per REGISTRATION, (even if the registrations use the same attendee) |
|
| 64 | + foreach ($regs as $new_reg_id) { |
|
| 65 | + $new_answer_id = $this->_insert_new_answer($old_row, $new_reg_id); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + /** |
|
| 69 | + * Creates a 4.1 price base type |
|
| 70 | + * @global type $wpdb |
|
| 71 | + * @param array $old_price |
|
| 72 | + * @param int $new_reg_id |
|
| 73 | + * @return int |
|
| 74 | + */ |
|
| 75 | + private function _insert_new_answer($old_answer, $new_reg_id) |
|
| 76 | + { |
|
| 77 | + global $wpdb; |
|
| 78 | + $old_question_table = $wpdb->prefix."events_question"; |
|
| 79 | + $new_question_id = $this->get_migration_script()->get_mapping_new_pk($old_question_table, $old_answer['question_id'], $this->_new_question_table); |
|
| 80 | 80 | |
| 81 | - $question_type = $this->_get_question_type($new_question_id); |
|
| 82 | - if (in_array($question_type, array('MULTIPLE'))) { |
|
| 83 | - $ans_value = serialize(explode(",", stripslashes($old_answer['answer']))); |
|
| 84 | - } else { |
|
| 85 | - $ans_value = stripslashes($old_answer['answer']); |
|
| 86 | - } |
|
| 87 | - $cols_n_values = array( |
|
| 88 | - 'REG_ID'=>$new_reg_id, |
|
| 89 | - 'QST_ID'=>$new_question_id, |
|
| 90 | - 'ANS_value'=>$ans_value |
|
| 91 | - ); |
|
| 92 | - $datatypes = array( |
|
| 93 | - '%d',// REG_ID |
|
| 94 | - '%d',// QST_ID |
|
| 95 | - '%s',// ANS_value |
|
| 96 | - ); |
|
| 97 | - $success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes); |
|
| 98 | - if (! $success) { |
|
| 99 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes)); |
|
| 100 | - return 0; |
|
| 101 | - } |
|
| 102 | - $new_id = $wpdb->insert_id; |
|
| 103 | - return $new_id; |
|
| 104 | - } |
|
| 81 | + $question_type = $this->_get_question_type($new_question_id); |
|
| 82 | + if (in_array($question_type, array('MULTIPLE'))) { |
|
| 83 | + $ans_value = serialize(explode(",", stripslashes($old_answer['answer']))); |
|
| 84 | + } else { |
|
| 85 | + $ans_value = stripslashes($old_answer['answer']); |
|
| 86 | + } |
|
| 87 | + $cols_n_values = array( |
|
| 88 | + 'REG_ID'=>$new_reg_id, |
|
| 89 | + 'QST_ID'=>$new_question_id, |
|
| 90 | + 'ANS_value'=>$ans_value |
|
| 91 | + ); |
|
| 92 | + $datatypes = array( |
|
| 93 | + '%d',// REG_ID |
|
| 94 | + '%d',// QST_ID |
|
| 95 | + '%s',// ANS_value |
|
| 96 | + ); |
|
| 97 | + $success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes); |
|
| 98 | + if (! $success) { |
|
| 99 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes)); |
|
| 100 | + return 0; |
|
| 101 | + } |
|
| 102 | + $new_id = $wpdb->insert_id; |
|
| 103 | + return $new_id; |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Gets the question's type |
|
| 108 | - * @global type $wpdb |
|
| 109 | - * @param type $question_id |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - private function _get_question_type($question_id) |
|
| 113 | - { |
|
| 114 | - global $wpdb; |
|
| 115 | - $type = $wpdb->get_var($wpdb->prepare("SELECT QST_type FROM ".$this->_new_question_table." WHERE QST_ID=%d LIMIT 1", $question_id)); |
|
| 116 | - return $type; |
|
| 117 | - } |
|
| 106 | + /** |
|
| 107 | + * Gets the question's type |
|
| 108 | + * @global type $wpdb |
|
| 109 | + * @param type $question_id |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + private function _get_question_type($question_id) |
|
| 113 | + { |
|
| 114 | + global $wpdb; |
|
| 115 | + $type = $wpdb->get_var($wpdb->prepare("SELECT QST_type FROM ".$this->_new_question_table." WHERE QST_ID=%d LIMIT 1", $question_id)); |
|
| 116 | + return $type; |
|
| 117 | + } |
|
| 118 | 118 | } |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | // join to attendee and then join to events table |
| 43 | 43 | $this->select_expression = 'ans.*, e.event_status'; |
| 44 | 44 | $this->_extra_where_sql = ' AS ans |
| 45 | - INNER JOIN ' . $wpdb->prefix . 'events_attendee AS att ON ans.attendee_id = att.id |
|
| 46 | - INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id = e.id |
|
| 45 | + INNER JOIN ' . $wpdb->prefix.'events_attendee AS att ON ans.attendee_id = att.id |
|
| 46 | + INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id = e.id |
|
| 47 | 47 | WHERE e.event_status !="D"'; |
| 48 | 48 | $this->_new_answer_table = $wpdb->prefix."esp_answer"; |
| 49 | 49 | $this->_new_question_table = $wpdb->prefix."esp_question"; |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | $old_attendee_table = $wpdb->prefix."events_attendee"; |
| 57 | 57 | $new_reg_table = $wpdb->prefix."esp_registration"; |
| 58 | 58 | $regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table); |
| 59 | - if (! $regs) { |
|
| 59 | + if ( ! $regs) { |
|
| 60 | 60 | $this->add_error(sprintf(__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row))); |
| 61 | 61 | return false; |
| 62 | 62 | } |
@@ -90,12 +90,12 @@ discard block |
||
| 90 | 90 | 'ANS_value'=>$ans_value |
| 91 | 91 | ); |
| 92 | 92 | $datatypes = array( |
| 93 | - '%d',// REG_ID |
|
| 94 | - '%d',// QST_ID |
|
| 95 | - '%s',// ANS_value |
|
| 93 | + '%d', // REG_ID |
|
| 94 | + '%d', // QST_ID |
|
| 95 | + '%s', // ANS_value |
|
| 96 | 96 | ); |
| 97 | 97 | $success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes); |
| 98 | - if (! $success) { |
|
| 98 | + if ( ! $success) { |
|
| 99 | 99 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes)); |
| 100 | 100 | return 0; |
| 101 | 101 | } |
@@ -26,160 +26,160 @@ |
||
| 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->select_expression = 'att.*, e.event_status'; |
|
| 36 | - $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->select_expression = 'att.*, e.event_status'; |
|
| 36 | + $this->_extra_where_sql = 'AS att |
|
| 37 | 37 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
| 38 | 38 | WHERE e.event_status!="D"'; |
| 39 | - $this->_new_table = $wpdb->prefix."esp_checkin"; |
|
| 40 | - parent::__construct(); |
|
| 41 | - } |
|
| 42 | - protected function _migrate_old_row($old_row) |
|
| 43 | - { |
|
| 44 | - global $wpdb; |
|
| 45 | - $new_reg_table = $wpdb->prefix."esp_registration"; |
|
| 39 | + $this->_new_table = $wpdb->prefix."esp_checkin"; |
|
| 40 | + parent::__construct(); |
|
| 41 | + } |
|
| 42 | + protected function _migrate_old_row($old_row) |
|
| 43 | + { |
|
| 44 | + global $wpdb; |
|
| 45 | + $new_reg_table = $wpdb->prefix."esp_registration"; |
|
| 46 | 46 | |
| 47 | - $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ; |
|
| 47 | + $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ; |
|
| 48 | 48 | |
| 49 | - $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
|
| 50 | - if (! $new_registrations_for_attendee) { |
|
| 51 | - $new_registrations_for_attendee = array(); |
|
| 52 | - } |
|
| 53 | - $new_datetime = $this->_try_to_find_datetime($old_row); |
|
| 49 | + $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
|
| 50 | + if (! $new_registrations_for_attendee) { |
|
| 51 | + $new_registrations_for_attendee = array(); |
|
| 52 | + } |
|
| 53 | + $new_datetime = $this->_try_to_find_datetime($old_row); |
|
| 54 | 54 | |
| 55 | - // make sure registrations array is numerically indexed starting at 0 (it probably already is) |
|
| 56 | - $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
|
| 57 | - $new_checkin_ids = array(); |
|
| 58 | - for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) { |
|
| 59 | - $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
| 60 | - if (! $new_reg_id) { |
|
| 61 | - $this->add_error(sprintf( |
|
| 62 | - esc_html__( |
|
| 63 | - /* translators: %1$s database row represented in JSON, %2$s number of registrations to check-in |
|
| 55 | + // make sure registrations array is numerically indexed starting at 0 (it probably already is) |
|
| 56 | + $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
|
| 57 | + $new_checkin_ids = array(); |
|
| 58 | + for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) { |
|
| 59 | + $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
| 60 | + if (! $new_reg_id) { |
|
| 61 | + $this->add_error(sprintf( |
|
| 62 | + esc_html__( |
|
| 63 | + /* translators: %1$s database row represented in JSON, %2$s number of registrations to check-in |
|
| 64 | 64 | * %3$s number of registrations for the attendee, %4$s new registration rows represented in JSON |
| 65 | 65 | */ |
| 66 | - // @codingStandardsIgnoreStart |
|
| 67 | - '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)', |
|
| 68 | - // @codingStandardsIgnoreEnd |
|
| 69 | - 'event_espresso' |
|
| 70 | - ), |
|
| 71 | - $this->_json_encode($old_row), |
|
| 72 | - abs($num_to_checkin_at_this_time), |
|
| 73 | - count($new_registrations_for_attendee), |
|
| 74 | - $this->_json_encode($new_registrations_for_attendee) |
|
| 75 | - )); |
|
| 76 | - break; |
|
| 77 | - } |
|
| 78 | - $existing_checkin_record = $wpdb->get_var( |
|
| 79 | - $wpdb->prepare( |
|
| 80 | - "SELECT CHK_ID FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", |
|
| 81 | - $new_reg_id |
|
| 82 | - ) |
|
| 83 | - ); |
|
| 84 | - if (! $existing_checkin_record) { |
|
| 85 | - $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
|
| 86 | - if ($new_id) { |
|
| 87 | - $new_checkin_ids[]= $new_id; |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - if ($new_checkin_ids) { |
|
| 92 | - $this->get_migration_script()->set_mapping( |
|
| 93 | - $this->_old_table, |
|
| 94 | - $old_row['id'], |
|
| 95 | - $this->_new_table, |
|
| 96 | - $new_checkin_ids |
|
| 97 | - ); |
|
| 98 | - } |
|
| 99 | - } |
|
| 66 | + // @codingStandardsIgnoreStart |
|
| 67 | + '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)', |
|
| 68 | + // @codingStandardsIgnoreEnd |
|
| 69 | + 'event_espresso' |
|
| 70 | + ), |
|
| 71 | + $this->_json_encode($old_row), |
|
| 72 | + abs($num_to_checkin_at_this_time), |
|
| 73 | + count($new_registrations_for_attendee), |
|
| 74 | + $this->_json_encode($new_registrations_for_attendee) |
|
| 75 | + )); |
|
| 76 | + break; |
|
| 77 | + } |
|
| 78 | + $existing_checkin_record = $wpdb->get_var( |
|
| 79 | + $wpdb->prepare( |
|
| 80 | + "SELECT CHK_ID FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", |
|
| 81 | + $new_reg_id |
|
| 82 | + ) |
|
| 83 | + ); |
|
| 84 | + if (! $existing_checkin_record) { |
|
| 85 | + $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
|
| 86 | + if ($new_id) { |
|
| 87 | + $new_checkin_ids[]= $new_id; |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + if ($new_checkin_ids) { |
|
| 92 | + $this->get_migration_script()->set_mapping( |
|
| 93 | + $this->_old_table, |
|
| 94 | + $old_row['id'], |
|
| 95 | + $this->_new_table, |
|
| 96 | + $new_checkin_ids |
|
| 97 | + ); |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * Tries to find the new datetime the Check-in was for, based on the attendee row |
|
| 104 | - * (because we know the attendee was for an event as a specific time, and we know |
|
| 105 | - * the event's OLD ID...) |
|
| 106 | - * @global type $wpdb |
|
| 107 | - * @param array $old_attendee_row |
|
| 108 | - * @return array row of datetime from DB |
|
| 109 | - */ |
|
| 110 | - private function _try_to_find_datetime($old_attendee) |
|
| 111 | - { |
|
| 112 | - global $wpdb; |
|
| 102 | + /** |
|
| 103 | + * Tries to find the new datetime the Check-in was for, based on the attendee row |
|
| 104 | + * (because we know the attendee was for an event as a specific time, and we know |
|
| 105 | + * the event's OLD ID...) |
|
| 106 | + * @global type $wpdb |
|
| 107 | + * @param array $old_attendee_row |
|
| 108 | + * @return array row of datetime from DB |
|
| 109 | + */ |
|
| 110 | + private function _try_to_find_datetime($old_attendee) |
|
| 111 | + { |
|
| 112 | + global $wpdb; |
|
| 113 | 113 | |
| 114 | - $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts); |
|
| 115 | - if (! $new_event_id) { |
|
| 116 | - $this->add_error( |
|
| 117 | - sprintf( |
|
| 118 | - esc_html__( |
|
| 119 | - /* translators: 1: original event ID, 2: original attendee database row */ |
|
| 120 | - // @codingStandardsIgnoreStart |
|
| 121 | - 'Could not find new event ID with old event ID %1$d, on attendee row %2$s; and because of that couldn\'t find the correct datetime for Check-in', |
|
| 122 | - // @codingStandardsIgnoreEnd |
|
| 123 | - 'event_espresso' |
|
| 124 | - ), |
|
| 125 | - $old_attendee['event_id'], |
|
| 126 | - $this->_json_encode($old_attendee) |
|
| 127 | - ) |
|
| 128 | - ); |
|
| 129 | - return 0; |
|
| 130 | - } |
|
| 131 | - $old_att_start_date = $old_attendee['start_date']; |
|
| 132 | - $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
| 133 | - $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
| 114 | + $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts); |
|
| 115 | + if (! $new_event_id) { |
|
| 116 | + $this->add_error( |
|
| 117 | + sprintf( |
|
| 118 | + esc_html__( |
|
| 119 | + /* translators: 1: original event ID, 2: original attendee database row */ |
|
| 120 | + // @codingStandardsIgnoreStart |
|
| 121 | + 'Could not find new event ID with old event ID %1$d, on attendee row %2$s; and because of that couldn\'t find the correct datetime for Check-in', |
|
| 122 | + // @codingStandardsIgnoreEnd |
|
| 123 | + 'event_espresso' |
|
| 124 | + ), |
|
| 125 | + $old_attendee['event_id'], |
|
| 126 | + $this->_json_encode($old_attendee) |
|
| 127 | + ) |
|
| 128 | + ); |
|
| 129 | + return 0; |
|
| 130 | + } |
|
| 131 | + $old_att_start_date = $old_attendee['start_date']; |
|
| 132 | + $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
| 133 | + $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
| 134 | 134 | |
| 135 | - $datetime_table = $wpdb->prefix."esp_datetime"; |
|
| 136 | - // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
| 137 | - // the most important condition should be last, as it will be array_shift'ed off last |
|
| 138 | - $conditions = array( |
|
| 139 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
| 140 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
| 141 | - ); |
|
| 142 | - // start running queries, widening search each time by removing a condition |
|
| 143 | - $datetime_found = null; |
|
| 144 | - do { |
|
| 145 | - $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
|
| 146 | - $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
|
| 147 | - array_shift($conditions); |
|
| 148 | - } while (! $datetime_found && $conditions); |
|
| 149 | - return $datetime_found; |
|
| 150 | - } |
|
| 135 | + $datetime_table = $wpdb->prefix."esp_datetime"; |
|
| 136 | + // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
| 137 | + // the most important condition should be last, as it will be array_shift'ed off last |
|
| 138 | + $conditions = array( |
|
| 139 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
| 140 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
| 141 | + ); |
|
| 142 | + // start running queries, widening search each time by removing a condition |
|
| 143 | + $datetime_found = null; |
|
| 144 | + do { |
|
| 145 | + $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
|
| 146 | + $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
|
| 147 | + array_shift($conditions); |
|
| 148 | + } while (! $datetime_found && $conditions); |
|
| 149 | + return $datetime_found; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap |
|
| 154 | - * @param int $new_reg_id |
|
| 155 | - * @param int $new_datetime_id |
|
| 156 | - * @param string $timestamp mysql datetime |
|
| 157 | - * @return int new Check-in id |
|
| 158 | - */ |
|
| 159 | - private function _insert_checkin_record($new_reg_id, $new_datetime) |
|
| 160 | - { |
|
| 161 | - global $wpdb; |
|
| 152 | + /** |
|
| 153 | + * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap |
|
| 154 | + * @param int $new_reg_id |
|
| 155 | + * @param int $new_datetime_id |
|
| 156 | + * @param string $timestamp mysql datetime |
|
| 157 | + * @return int new Check-in id |
|
| 158 | + */ |
|
| 159 | + private function _insert_checkin_record($new_reg_id, $new_datetime) |
|
| 160 | + { |
|
| 161 | + global $wpdb; |
|
| 162 | 162 | |
| 163 | 163 | |
| 164 | - // ok we can actually do what we set out to do: add a checkin/checkout record |
|
| 165 | - $cols_n_values = array( |
|
| 166 | - 'REG_ID'=>$new_reg_id, |
|
| 167 | - 'DTT_ID'=>$new_datetime['DTT_ID'], |
|
| 168 | - 'CHK_in'=>true, |
|
| 169 | - 'CHK_timestamp'=>$new_datetime['DTT_EVT_start'] |
|
| 170 | - ); |
|
| 171 | - $datatypes = array( |
|
| 172 | - '%d',// REG_ID |
|
| 173 | - '%d',// DTT_ID |
|
| 174 | - '%d',// CHK_in |
|
| 175 | - '%s',// CHK_timestamp |
|
| 176 | - ); |
|
| 177 | - $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
| 178 | - if (! $success) { |
|
| 179 | - $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)); |
|
| 180 | - return 0; |
|
| 181 | - } |
|
| 182 | - $new_id = $wpdb->insert_id; |
|
| 183 | - return $new_id; |
|
| 184 | - } |
|
| 164 | + // ok we can actually do what we set out to do: add a checkin/checkout record |
|
| 165 | + $cols_n_values = array( |
|
| 166 | + 'REG_ID'=>$new_reg_id, |
|
| 167 | + 'DTT_ID'=>$new_datetime['DTT_ID'], |
|
| 168 | + 'CHK_in'=>true, |
|
| 169 | + 'CHK_timestamp'=>$new_datetime['DTT_EVT_start'] |
|
| 170 | + ); |
|
| 171 | + $datatypes = array( |
|
| 172 | + '%d',// REG_ID |
|
| 173 | + '%d',// DTT_ID |
|
| 174 | + '%d',// CHK_in |
|
| 175 | + '%s',// CHK_timestamp |
|
| 176 | + ); |
|
| 177 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
| 178 | + if (! $success) { |
|
| 179 | + $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)); |
|
| 180 | + return 0; |
|
| 181 | + } |
|
| 182 | + $new_id = $wpdb->insert_id; |
|
| 183 | + return $new_id; |
|
| 184 | + } |
|
| 185 | 185 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | $this->_old_table = $wpdb->prefix."events_attendee"; |
| 35 | 35 | $this->select_expression = 'att.*, e.event_status'; |
| 36 | 36 | $this->_extra_where_sql = 'AS att |
| 37 | - INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
|
| 37 | + INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id=e.id |
|
| 38 | 38 | WHERE e.event_status!="D"'; |
| 39 | 39 | $this->_new_table = $wpdb->prefix."esp_checkin"; |
| 40 | 40 | parent::__construct(); |
@@ -44,10 +44,10 @@ discard block |
||
| 44 | 44 | global $wpdb; |
| 45 | 45 | $new_reg_table = $wpdb->prefix."esp_registration"; |
| 46 | 46 | |
| 47 | - $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ; |
|
| 47 | + $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']), intval($old_row['checked_in']))); |
|
| 48 | 48 | |
| 49 | 49 | $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
| 50 | - if (! $new_registrations_for_attendee) { |
|
| 50 | + if ( ! $new_registrations_for_attendee) { |
|
| 51 | 51 | $new_registrations_for_attendee = array(); |
| 52 | 52 | } |
| 53 | 53 | $new_datetime = $this->_try_to_find_datetime($old_row); |
@@ -55,9 +55,9 @@ discard block |
||
| 55 | 55 | // make sure registrations array is numerically indexed starting at 0 (it probably already is) |
| 56 | 56 | $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
| 57 | 57 | $new_checkin_ids = array(); |
| 58 | - for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) { |
|
| 59 | - $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
| 60 | - if (! $new_reg_id) { |
|
| 58 | + for ($i = 0; $i < abs($num_to_checkin_at_this_time); $i++) { |
|
| 59 | + $new_reg_id = $new_registrations_for_attendee[$i]; |
|
| 60 | + if ( ! $new_reg_id) { |
|
| 61 | 61 | $this->add_error(sprintf( |
| 62 | 62 | esc_html__( |
| 63 | 63 | /* translators: %1$s database row represented in JSON, %2$s number of registrations to check-in |
@@ -81,10 +81,10 @@ discard block |
||
| 81 | 81 | $new_reg_id |
| 82 | 82 | ) |
| 83 | 83 | ); |
| 84 | - if (! $existing_checkin_record) { |
|
| 84 | + if ( ! $existing_checkin_record) { |
|
| 85 | 85 | $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
| 86 | 86 | if ($new_id) { |
| 87 | - $new_checkin_ids[]= $new_id; |
|
| 87 | + $new_checkin_ids[] = $new_id; |
|
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | } |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | global $wpdb; |
| 113 | 113 | |
| 114 | 114 | $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts); |
| 115 | - if (! $new_event_id) { |
|
| 115 | + if ( ! $new_event_id) { |
|
| 116 | 116 | $this->add_error( |
| 117 | 117 | sprintf( |
| 118 | 118 | esc_html__( |
@@ -136,8 +136,8 @@ discard block |
||
| 136 | 136 | // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
| 137 | 137 | // the most important condition should be last, as it will be array_shift'ed off last |
| 138 | 138 | $conditions = array( |
| 139 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
| 140 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
| 139 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime), // times match? |
|
| 140 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id), // events match? |
|
| 141 | 141 | ); |
| 142 | 142 | // start running queries, widening search each time by removing a condition |
| 143 | 143 | $datetime_found = null; |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
| 146 | 146 | $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
| 147 | 147 | array_shift($conditions); |
| 148 | - } while (! $datetime_found && $conditions); |
|
| 148 | + }while ( ! $datetime_found && $conditions); |
|
| 149 | 149 | return $datetime_found; |
| 150 | 150 | } |
| 151 | 151 | |
@@ -169,13 +169,13 @@ discard block |
||
| 169 | 169 | 'CHK_timestamp'=>$new_datetime['DTT_EVT_start'] |
| 170 | 170 | ); |
| 171 | 171 | $datatypes = array( |
| 172 | - '%d',// REG_ID |
|
| 173 | - '%d',// DTT_ID |
|
| 174 | - '%d',// CHK_in |
|
| 175 | - '%s',// CHK_timestamp |
|
| 172 | + '%d', // REG_ID |
|
| 173 | + '%d', // DTT_ID |
|
| 174 | + '%d', // CHK_in |
|
| 175 | + '%s', // CHK_timestamp |
|
| 176 | 176 | ); |
| 177 | 177 | $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
| 178 | - if (! $success) { |
|
| 178 | + if ( ! $success) { |
|
| 179 | 179 | $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)); |
| 180 | 180 | return 0; |
| 181 | 181 | } |
@@ -183,647 +183,647 @@ |
||
| 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. Important note: partial payments were marked as "Pending". |
|
| 764 | - // Also, an offline payment had blank status (ie, ""). |
|
| 765 | - $old_pay_stati_indicating_no_payment = array('', 'Incomplete', 'Not Completed'); |
|
| 766 | - // if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment... |
|
| 767 | - if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && !in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) { |
|
| 768 | - $pay_status_mapping = array( |
|
| 769 | - 'Completed' => 'PAP', |
|
| 770 | - 'Payment Declined' => 'PDC', |
|
| 771 | - 'Cancelled' => 'PCN', |
|
| 772 | - 'Declined' => 'PDC' |
|
| 773 | - ); |
|
| 774 | - $by_admin = $old_attendee['payment'] == 'Admin'; |
|
| 775 | - $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 |
|
| 776 | - $cols_n_values = array( |
|
| 777 | - 'TXN_ID' => $new_txn_id, |
|
| 778 | - 'STS_ID' => $STS_ID, |
|
| 779 | - 'PAY_timestamp' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
| 780 | - 'PAY_method' => 'CART', |
|
| 781 | - 'PAY_amount' => $old_attendee['amount_pd'], |
|
| 782 | - // 'txn_type' was used both for the gateway's name, and for other payment notes. |
|
| 783 | - 'PAY_gateway' => $old_attendee['txn_type'], |
|
| 784 | - 'PAY_extra_accntng' => $old_attendee['txn_type'], |
|
| 785 | - 'PAY_gateway_response' => '', |
|
| 786 | - 'PAY_txn_id_chq_nmbr' => substr($old_attendee['txn_id'], 0, 32), |
|
| 787 | - 'PAY_via_admin' => $by_admin, |
|
| 788 | - 'PAY_details' => $old_attendee['transaction_details'] |
|
| 789 | - ); |
|
| 790 | - $datatypes = array( |
|
| 791 | - '%d',// TXN_Id |
|
| 792 | - '%s',// STS_ID |
|
| 793 | - '%s',// PAY_timestamp |
|
| 794 | - '%s',// PAY_method |
|
| 795 | - '%f',// PAY_amount |
|
| 796 | - '%s',// PAY_gateway |
|
| 797 | - '%s',// PAY_gateway_response |
|
| 798 | - '%s',// PAY_txn_id_chq_nmbr |
|
| 799 | - '%d',// PAY_via_admin |
|
| 800 | - '%s',// PAY_details |
|
| 801 | - ); |
|
| 802 | - $success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes); |
|
| 803 | - if (!$success) { |
|
| 804 | - $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)); |
|
| 805 | - return 0; |
|
| 806 | - } |
|
| 807 | - $new_id = $wpdb->insert_id; |
|
| 808 | - return $new_id; |
|
| 809 | - } else { |
|
| 810 | - return 0; |
|
| 811 | - } |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - /** |
|
| 815 | - * If MER is active, if you want ot fin dthe other registrations on that attendee row |
|
| 816 | - * @global type $wpdb |
|
| 817 | - * @param type $old_registration_id |
|
| 818 | - * @return array |
|
| 819 | - */ |
|
| 820 | - private function _find_mer_primary_attendee_using_mer_tables($old_registration_id) |
|
| 821 | - { |
|
| 822 | - if (!$this->_mer_tables_exist()) { |
|
| 823 | - return false; |
|
| 824 | - } |
|
| 825 | - global $wpdb; |
|
| 826 | - $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); |
|
| 827 | - return $old_att_for_primary_reg; |
|
| 828 | - } |
|
| 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. Important note: partial payments were marked as "Pending". |
|
| 764 | + // Also, an offline payment had blank status (ie, ""). |
|
| 765 | + $old_pay_stati_indicating_no_payment = array('', 'Incomplete', 'Not Completed'); |
|
| 766 | + // if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment... |
|
| 767 | + if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && !in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) { |
|
| 768 | + $pay_status_mapping = array( |
|
| 769 | + 'Completed' => 'PAP', |
|
| 770 | + 'Payment Declined' => 'PDC', |
|
| 771 | + 'Cancelled' => 'PCN', |
|
| 772 | + 'Declined' => 'PDC' |
|
| 773 | + ); |
|
| 774 | + $by_admin = $old_attendee['payment'] == 'Admin'; |
|
| 775 | + $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 |
|
| 776 | + $cols_n_values = array( |
|
| 777 | + 'TXN_ID' => $new_txn_id, |
|
| 778 | + 'STS_ID' => $STS_ID, |
|
| 779 | + 'PAY_timestamp' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
| 780 | + 'PAY_method' => 'CART', |
|
| 781 | + 'PAY_amount' => $old_attendee['amount_pd'], |
|
| 782 | + // 'txn_type' was used both for the gateway's name, and for other payment notes. |
|
| 783 | + 'PAY_gateway' => $old_attendee['txn_type'], |
|
| 784 | + 'PAY_extra_accntng' => $old_attendee['txn_type'], |
|
| 785 | + 'PAY_gateway_response' => '', |
|
| 786 | + 'PAY_txn_id_chq_nmbr' => substr($old_attendee['txn_id'], 0, 32), |
|
| 787 | + 'PAY_via_admin' => $by_admin, |
|
| 788 | + 'PAY_details' => $old_attendee['transaction_details'] |
|
| 789 | + ); |
|
| 790 | + $datatypes = array( |
|
| 791 | + '%d',// TXN_Id |
|
| 792 | + '%s',// STS_ID |
|
| 793 | + '%s',// PAY_timestamp |
|
| 794 | + '%s',// PAY_method |
|
| 795 | + '%f',// PAY_amount |
|
| 796 | + '%s',// PAY_gateway |
|
| 797 | + '%s',// PAY_gateway_response |
|
| 798 | + '%s',// PAY_txn_id_chq_nmbr |
|
| 799 | + '%d',// PAY_via_admin |
|
| 800 | + '%s',// PAY_details |
|
| 801 | + ); |
|
| 802 | + $success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes); |
|
| 803 | + if (!$success) { |
|
| 804 | + $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)); |
|
| 805 | + return 0; |
|
| 806 | + } |
|
| 807 | + $new_id = $wpdb->insert_id; |
|
| 808 | + return $new_id; |
|
| 809 | + } else { |
|
| 810 | + return 0; |
|
| 811 | + } |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + /** |
|
| 815 | + * If MER is active, if you want ot fin dthe other registrations on that attendee row |
|
| 816 | + * @global type $wpdb |
|
| 817 | + * @param type $old_registration_id |
|
| 818 | + * @return array |
|
| 819 | + */ |
|
| 820 | + private function _find_mer_primary_attendee_using_mer_tables($old_registration_id) |
|
| 821 | + { |
|
| 822 | + if (!$this->_mer_tables_exist()) { |
|
| 823 | + return false; |
|
| 824 | + } |
|
| 825 | + global $wpdb; |
|
| 826 | + $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); |
|
| 827 | + return $old_att_for_primary_reg; |
|
| 828 | + } |
|
| 829 | 829 | } |
@@ -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. |
@@ -764,7 +764,7 @@ discard block |
||
| 764 | 764 | // Also, an offline payment had blank status (ie, ""). |
| 765 | 765 | $old_pay_stati_indicating_no_payment = array('', 'Incomplete', 'Not Completed'); |
| 766 | 766 | // if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment... |
| 767 | - if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && !in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) { |
|
| 767 | + if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && ! in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) { |
|
| 768 | 768 | $pay_status_mapping = array( |
| 769 | 769 | 'Completed' => 'PAP', |
| 770 | 770 | 'Payment Declined' => 'PDC', |
@@ -772,7 +772,7 @@ discard block |
||
| 772 | 772 | 'Declined' => 'PDC' |
| 773 | 773 | ); |
| 774 | 774 | $by_admin = $old_attendee['payment'] == 'Admin'; |
| 775 | - $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 | + $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 |
|
| 776 | 776 | $cols_n_values = array( |
| 777 | 777 | 'TXN_ID' => $new_txn_id, |
| 778 | 778 | 'STS_ID' => $STS_ID, |
@@ -788,19 +788,19 @@ discard block |
||
| 788 | 788 | 'PAY_details' => $old_attendee['transaction_details'] |
| 789 | 789 | ); |
| 790 | 790 | $datatypes = array( |
| 791 | - '%d',// TXN_Id |
|
| 792 | - '%s',// STS_ID |
|
| 793 | - '%s',// PAY_timestamp |
|
| 794 | - '%s',// PAY_method |
|
| 795 | - '%f',// PAY_amount |
|
| 796 | - '%s',// PAY_gateway |
|
| 797 | - '%s',// PAY_gateway_response |
|
| 798 | - '%s',// PAY_txn_id_chq_nmbr |
|
| 799 | - '%d',// PAY_via_admin |
|
| 800 | - '%s',// PAY_details |
|
| 791 | + '%d', // TXN_Id |
|
| 792 | + '%s', // STS_ID |
|
| 793 | + '%s', // PAY_timestamp |
|
| 794 | + '%s', // PAY_method |
|
| 795 | + '%f', // PAY_amount |
|
| 796 | + '%s', // PAY_gateway |
|
| 797 | + '%s', // PAY_gateway_response |
|
| 798 | + '%s', // PAY_txn_id_chq_nmbr |
|
| 799 | + '%d', // PAY_via_admin |
|
| 800 | + '%s', // PAY_details |
|
| 801 | 801 | ); |
| 802 | 802 | $success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes); |
| 803 | - if (!$success) { |
|
| 803 | + if ( ! $success) { |
|
| 804 | 804 | $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)); |
| 805 | 805 | return 0; |
| 806 | 806 | } |
@@ -819,7 +819,7 @@ discard block |
||
| 819 | 819 | */ |
| 820 | 820 | private function _find_mer_primary_attendee_using_mer_tables($old_registration_id) |
| 821 | 821 | { |
| 822 | - if (!$this->_mer_tables_exist()) { |
|
| 822 | + if ( ! $this->_mer_tables_exist()) { |
|
| 823 | 823 | return false; |
| 824 | 824 | } |
| 825 | 825 | global $wpdb; |
@@ -38,172 +38,172 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | class EE_DMS_4_1_0_line_items extends EE_Data_Migration_Script_Stage_Table |
| 40 | 40 | { |
| 41 | - private $_new_line_table; |
|
| 42 | - private $_new_transaction_table; |
|
| 43 | - private $_new_reg_table; |
|
| 44 | - public function __construct() |
|
| 45 | - { |
|
| 46 | - global $wpdb; |
|
| 47 | - $this->_pretty_name = __("Line Items", "event_espresso"); |
|
| 48 | - $this->_old_table = $wpdb->prefix."events_attendee"; |
|
| 49 | - $this->select_expression = 'att.*, e.event_status'; |
|
| 50 | - $this->_extra_where_sql = ' AS att |
|
| 41 | + private $_new_line_table; |
|
| 42 | + private $_new_transaction_table; |
|
| 43 | + private $_new_reg_table; |
|
| 44 | + public function __construct() |
|
| 45 | + { |
|
| 46 | + global $wpdb; |
|
| 47 | + $this->_pretty_name = __("Line Items", "event_espresso"); |
|
| 48 | + $this->_old_table = $wpdb->prefix."events_attendee"; |
|
| 49 | + $this->select_expression = 'att.*, e.event_status'; |
|
| 50 | + $this->_extra_where_sql = ' AS att |
|
| 51 | 51 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
| 52 | 52 | WHERE e.event_status!="D"'; |
| 53 | - $this->_new_transaction_table = $wpdb->prefix."esp_transaction"; |
|
| 54 | - $this->_new_line_table = $wpdb->prefix."esp_line_item"; |
|
| 55 | - $this->_new_reg_table = $wpdb->prefix."esp_registration"; |
|
| 56 | - parent::__construct(); |
|
| 57 | - } |
|
| 53 | + $this->_new_transaction_table = $wpdb->prefix."esp_transaction"; |
|
| 54 | + $this->_new_line_table = $wpdb->prefix."esp_line_item"; |
|
| 55 | + $this->_new_reg_table = $wpdb->prefix."esp_registration"; |
|
| 56 | + parent::__construct(); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - protected function _migrate_old_row($old_row) |
|
| 60 | - { |
|
| 61 | - // insert line items if its a primary id |
|
| 62 | - if (intval($old_row['is_primary'])) { |
|
| 63 | - $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $this->_new_transaction_table); |
|
| 64 | - if (! $txn_id) { |
|
| 65 | - $this->add_error(sprintf(__("Could not find the transaction for the 3.1 attendee %d from row %s", "event_espresso"), $old_row['id'], $this->_json_encode($old_row))); |
|
| 66 | - return; |
|
| 67 | - } |
|
| 68 | - $txn = $this->_get_txn($txn_id); |
|
| 69 | - $new_line_items = $this->_insert_new_line_items($txn, $old_row); |
|
| 70 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_line_table, $new_line_items); |
|
| 71 | - } |
|
| 72 | - } |
|
| 59 | + protected function _migrate_old_row($old_row) |
|
| 60 | + { |
|
| 61 | + // insert line items if its a primary id |
|
| 62 | + if (intval($old_row['is_primary'])) { |
|
| 63 | + $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $this->_new_transaction_table); |
|
| 64 | + if (! $txn_id) { |
|
| 65 | + $this->add_error(sprintf(__("Could not find the transaction for the 3.1 attendee %d from row %s", "event_espresso"), $old_row['id'], $this->_json_encode($old_row))); |
|
| 66 | + return; |
|
| 67 | + } |
|
| 68 | + $txn = $this->_get_txn($txn_id); |
|
| 69 | + $new_line_items = $this->_insert_new_line_items($txn, $old_row); |
|
| 70 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_line_table, $new_line_items); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - private function _get_txn($txn_id) |
|
| 75 | - { |
|
| 76 | - global $wpdb; |
|
| 77 | - $txn = $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->_new_transaction_table WHERE TXN_ID=%d", $txn_id), ARRAY_A); |
|
| 78 | - return $txn; |
|
| 79 | - } |
|
| 74 | + private function _get_txn($txn_id) |
|
| 75 | + { |
|
| 76 | + global $wpdb; |
|
| 77 | + $txn = $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->_new_transaction_table WHERE TXN_ID=%d", $txn_id), ARRAY_A); |
|
| 78 | + return $txn; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * In 4.1, we'd normally need more info than just the registrations to make the line items. Ie, we'd need |
|
| 83 | - * the transaction, and tax prices at the time of registration. (And probably promotions and other price factors). |
|
| 84 | - * But seeing how these are REGs created from 3.1 attendee data, which have |
|
| 85 | - * @param array $transaction |
|
| 86 | - * @return array new line item ids |
|
| 87 | - */ |
|
| 88 | - private function _insert_new_line_items($transaction, $old_attendee) |
|
| 89 | - { |
|
| 90 | - global $wpdb; |
|
| 91 | - $regs_on_this_transaction = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".$this->_new_reg_table." WHERE TXN_ID=%d", $transaction['TXN_ID']), ARRAY_A); |
|
| 92 | - $new_line_item_ids = array(); |
|
| 93 | - // create a totla line item |
|
| 94 | - $total_line_item_id = $this->_insert_new_line_item(array( |
|
| 95 | - 'LIN_code'=>'total', |
|
| 96 | - 'TXN_ID'=>$transaction['TXN_ID'], |
|
| 97 | - 'LIN_name'=> __("Total", "event_espresso"), |
|
| 98 | - 'LIN_total'=>$transaction['TXN_total'], |
|
| 99 | - 'LIN_type'=>'total', |
|
| 100 | - 'OBJ_ID'=>$transaction['TXN_ID'], |
|
| 101 | - 'OBJ_type'=>'Transaction' |
|
| 102 | - ), $old_attendee); |
|
| 103 | - $new_line_item_ids[] = $total_line_item_id; |
|
| 104 | - // create a subtotal line item |
|
| 105 | - $reg_total = 0; |
|
| 106 | - foreach ($regs_on_this_transaction as $new_reg) { |
|
| 107 | - $reg_total += floatval($new_reg['REG_final_price']); |
|
| 108 | - } |
|
| 109 | - $subtotal_line_item_id = $this->_insert_new_line_item(array( |
|
| 110 | - 'LIN_code'=>'sub-total', |
|
| 111 | - 'TXN_ID'=>$transaction['TXN_ID'], |
|
| 112 | - 'LIN_name'=> __("Subtotal", "event_espresso"), |
|
| 113 | - 'LIN_total'=>$reg_total, |
|
| 114 | - 'LIN_parent'=>$total_line_item_id, |
|
| 115 | - 'LIN_type'=>'sub-total', |
|
| 116 | - ), $old_attendee); |
|
| 117 | - $new_line_item_ids[] = $subtotal_line_item_id; |
|
| 118 | - // group REGs by TKT_ID |
|
| 119 | - $regs_by_tkt = array(); |
|
| 120 | - foreach ($regs_on_this_transaction as $new_reg) { |
|
| 121 | - $regs_by_tkt[ $new_reg['TKT_ID'] ][] = $new_reg; |
|
| 122 | - } |
|
| 81 | + /** |
|
| 82 | + * In 4.1, we'd normally need more info than just the registrations to make the line items. Ie, we'd need |
|
| 83 | + * the transaction, and tax prices at the time of registration. (And probably promotions and other price factors). |
|
| 84 | + * But seeing how these are REGs created from 3.1 attendee data, which have |
|
| 85 | + * @param array $transaction |
|
| 86 | + * @return array new line item ids |
|
| 87 | + */ |
|
| 88 | + private function _insert_new_line_items($transaction, $old_attendee) |
|
| 89 | + { |
|
| 90 | + global $wpdb; |
|
| 91 | + $regs_on_this_transaction = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".$this->_new_reg_table." WHERE TXN_ID=%d", $transaction['TXN_ID']), ARRAY_A); |
|
| 92 | + $new_line_item_ids = array(); |
|
| 93 | + // create a totla line item |
|
| 94 | + $total_line_item_id = $this->_insert_new_line_item(array( |
|
| 95 | + 'LIN_code'=>'total', |
|
| 96 | + 'TXN_ID'=>$transaction['TXN_ID'], |
|
| 97 | + 'LIN_name'=> __("Total", "event_espresso"), |
|
| 98 | + 'LIN_total'=>$transaction['TXN_total'], |
|
| 99 | + 'LIN_type'=>'total', |
|
| 100 | + 'OBJ_ID'=>$transaction['TXN_ID'], |
|
| 101 | + 'OBJ_type'=>'Transaction' |
|
| 102 | + ), $old_attendee); |
|
| 103 | + $new_line_item_ids[] = $total_line_item_id; |
|
| 104 | + // create a subtotal line item |
|
| 105 | + $reg_total = 0; |
|
| 106 | + foreach ($regs_on_this_transaction as $new_reg) { |
|
| 107 | + $reg_total += floatval($new_reg['REG_final_price']); |
|
| 108 | + } |
|
| 109 | + $subtotal_line_item_id = $this->_insert_new_line_item(array( |
|
| 110 | + 'LIN_code'=>'sub-total', |
|
| 111 | + 'TXN_ID'=>$transaction['TXN_ID'], |
|
| 112 | + 'LIN_name'=> __("Subtotal", "event_espresso"), |
|
| 113 | + 'LIN_total'=>$reg_total, |
|
| 114 | + 'LIN_parent'=>$total_line_item_id, |
|
| 115 | + 'LIN_type'=>'sub-total', |
|
| 116 | + ), $old_attendee); |
|
| 117 | + $new_line_item_ids[] = $subtotal_line_item_id; |
|
| 118 | + // group REGs by TKT_ID |
|
| 119 | + $regs_by_tkt = array(); |
|
| 120 | + foreach ($regs_on_this_transaction as $new_reg) { |
|
| 121 | + $regs_by_tkt[ $new_reg['TKT_ID'] ][] = $new_reg; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - // create individual line items |
|
| 124 | + // create individual line items |
|
| 125 | 125 | |
| 126 | - foreach ($regs_by_tkt as $ticket_id => $regs) { |
|
| 127 | - $count = count($regs); |
|
| 128 | - $line_total = 0; |
|
| 129 | - foreach ($regs as $new_reg) { |
|
| 130 | - $line_total += $new_reg['REG_final_price']; |
|
| 131 | - } |
|
| 132 | - $a_reg = reset($regs); |
|
| 133 | - $new_ticket = $this->_get_new_ticket_row($a_reg['TKT_ID']); |
|
| 134 | - $reg_line_item_id = $this->_insert_new_line_item(array( |
|
| 135 | - 'LIN_code'=> md5('Ticket' . $ticket_id . time()), |
|
| 136 | - 'TXN_ID'=>$transaction['TXN_ID'], |
|
| 137 | - 'LIN_name'=>$new_ticket['TKT_name'], |
|
| 138 | - 'LIN_unit_price'=>$a_reg['REG_final_price'], |
|
| 139 | - 'LIN_is_taxable'=>false, |
|
| 140 | - 'LIN_total'=>$line_total, |
|
| 141 | - 'LIN_quantity'=>$count, |
|
| 142 | - 'LIN_parent'=>$subtotal_line_item_id, |
|
| 143 | - 'OBJ_ID'=>$ticket_id, |
|
| 144 | - 'OBJ_type'=>'Ticket' |
|
| 145 | - ), $old_attendee); |
|
| 146 | - $new_line_item_ids[] = $reg_line_item_id; |
|
| 147 | - } |
|
| 126 | + foreach ($regs_by_tkt as $ticket_id => $regs) { |
|
| 127 | + $count = count($regs); |
|
| 128 | + $line_total = 0; |
|
| 129 | + foreach ($regs as $new_reg) { |
|
| 130 | + $line_total += $new_reg['REG_final_price']; |
|
| 131 | + } |
|
| 132 | + $a_reg = reset($regs); |
|
| 133 | + $new_ticket = $this->_get_new_ticket_row($a_reg['TKT_ID']); |
|
| 134 | + $reg_line_item_id = $this->_insert_new_line_item(array( |
|
| 135 | + 'LIN_code'=> md5('Ticket' . $ticket_id . time()), |
|
| 136 | + 'TXN_ID'=>$transaction['TXN_ID'], |
|
| 137 | + 'LIN_name'=>$new_ticket['TKT_name'], |
|
| 138 | + 'LIN_unit_price'=>$a_reg['REG_final_price'], |
|
| 139 | + 'LIN_is_taxable'=>false, |
|
| 140 | + 'LIN_total'=>$line_total, |
|
| 141 | + 'LIN_quantity'=>$count, |
|
| 142 | + 'LIN_parent'=>$subtotal_line_item_id, |
|
| 143 | + 'OBJ_ID'=>$ticket_id, |
|
| 144 | + 'OBJ_type'=>'Ticket' |
|
| 145 | + ), $old_attendee); |
|
| 146 | + $new_line_item_ids[] = $reg_line_item_id; |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | 149 | |
| 150 | 150 | |
| 151 | - return $new_line_item_ids; |
|
| 152 | - } |
|
| 153 | - /** |
|
| 154 | - * Gets the full ticket by ID |
|
| 155 | - * @global type $wpdb |
|
| 156 | - * @param type $new_ticket_id |
|
| 157 | - * @return array |
|
| 158 | - */ |
|
| 159 | - private function _get_new_ticket_row($new_ticket_id) |
|
| 160 | - { |
|
| 161 | - global $wpdb; |
|
| 162 | - $ticket_row = $wpdb->get_row($wpdb->prepare("SELECT * FROM ".$wpdb->prefix."esp_ticket WHERE TKT_ID=%d", $new_ticket_id), ARRAY_A); |
|
| 163 | - return $ticket_row; |
|
| 164 | - } |
|
| 151 | + return $new_line_item_ids; |
|
| 152 | + } |
|
| 153 | + /** |
|
| 154 | + * Gets the full ticket by ID |
|
| 155 | + * @global type $wpdb |
|
| 156 | + * @param type $new_ticket_id |
|
| 157 | + * @return array |
|
| 158 | + */ |
|
| 159 | + private function _get_new_ticket_row($new_ticket_id) |
|
| 160 | + { |
|
| 161 | + global $wpdb; |
|
| 162 | + $ticket_row = $wpdb->get_row($wpdb->prepare("SELECT * FROM ".$wpdb->prefix."esp_ticket WHERE TKT_ID=%d", $new_ticket_id), ARRAY_A); |
|
| 163 | + return $ticket_row; |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - private function _insert_new_line_item($cols_n_values, $old_attendee) |
|
| 167 | - { |
|
| 168 | - global $wpdb; |
|
| 169 | - $default_cols_n_values = array( |
|
| 170 | - 'LIN_code'=>'', |
|
| 171 | - 'TXN_ID'=>0, |
|
| 172 | - 'LIN_name'=>'', |
|
| 173 | - 'LIN_desc'=>'', |
|
| 174 | - 'LIN_unit_price'=>0, |
|
| 175 | - 'LIN_percent'=>0, |
|
| 176 | - 'LIN_is_taxable'=>false, |
|
| 177 | - 'LIN_order'=>0, |
|
| 178 | - 'LIN_total'=>0, |
|
| 179 | - 'LIN_quantity'=>null, |
|
| 180 | - 'LIN_parent'=>0, |
|
| 181 | - 'LIN_type'=>'line-item', |
|
| 182 | - 'OBJ_ID'=>null, |
|
| 183 | - 'OBJ_type'=>null |
|
| 184 | - ); |
|
| 185 | - $cols_n_values = array_merge($default_cols_n_values, $cols_n_values); |
|
| 186 | - $datatypes = array( |
|
| 187 | - '%s',// LIN_code |
|
| 188 | - '%d',// TXN_ID |
|
| 189 | - '%s',// LIN_name |
|
| 190 | - '%s',// LIN_desc |
|
| 191 | - '%f',// LIN_unit_price |
|
| 192 | - '%f',// LIN_percent |
|
| 193 | - '%d',// LIN_is_taxable |
|
| 194 | - '%d',// LIN_order |
|
| 195 | - '%f',// LIN_total |
|
| 196 | - '%d',// LIN_quantity |
|
| 197 | - '%d',// LIN_parent |
|
| 198 | - '%s',// LIN_type |
|
| 199 | - '%d',// OBJ_ID |
|
| 200 | - '%s',// OBJ_type |
|
| 201 | - ); |
|
| 202 | - $success = $wpdb->insert($this->_new_line_table, $cols_n_values, $datatypes); |
|
| 203 | - if (! $success) { |
|
| 204 | - $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)); |
|
| 205 | - return 0; |
|
| 206 | - } |
|
| 207 | - return $wpdb->insert_id; |
|
| 208 | - } |
|
| 166 | + private function _insert_new_line_item($cols_n_values, $old_attendee) |
|
| 167 | + { |
|
| 168 | + global $wpdb; |
|
| 169 | + $default_cols_n_values = array( |
|
| 170 | + 'LIN_code'=>'', |
|
| 171 | + 'TXN_ID'=>0, |
|
| 172 | + 'LIN_name'=>'', |
|
| 173 | + 'LIN_desc'=>'', |
|
| 174 | + 'LIN_unit_price'=>0, |
|
| 175 | + 'LIN_percent'=>0, |
|
| 176 | + 'LIN_is_taxable'=>false, |
|
| 177 | + 'LIN_order'=>0, |
|
| 178 | + 'LIN_total'=>0, |
|
| 179 | + 'LIN_quantity'=>null, |
|
| 180 | + 'LIN_parent'=>0, |
|
| 181 | + 'LIN_type'=>'line-item', |
|
| 182 | + 'OBJ_ID'=>null, |
|
| 183 | + 'OBJ_type'=>null |
|
| 184 | + ); |
|
| 185 | + $cols_n_values = array_merge($default_cols_n_values, $cols_n_values); |
|
| 186 | + $datatypes = array( |
|
| 187 | + '%s',// LIN_code |
|
| 188 | + '%d',// TXN_ID |
|
| 189 | + '%s',// LIN_name |
|
| 190 | + '%s',// LIN_desc |
|
| 191 | + '%f',// LIN_unit_price |
|
| 192 | + '%f',// LIN_percent |
|
| 193 | + '%d',// LIN_is_taxable |
|
| 194 | + '%d',// LIN_order |
|
| 195 | + '%f',// LIN_total |
|
| 196 | + '%d',// LIN_quantity |
|
| 197 | + '%d',// LIN_parent |
|
| 198 | + '%s',// LIN_type |
|
| 199 | + '%d',// OBJ_ID |
|
| 200 | + '%s',// OBJ_type |
|
| 201 | + ); |
|
| 202 | + $success = $wpdb->insert($this->_new_line_table, $cols_n_values, $datatypes); |
|
| 203 | + if (! $success) { |
|
| 204 | + $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)); |
|
| 205 | + return 0; |
|
| 206 | + } |
|
| 207 | + return $wpdb->insert_id; |
|
| 208 | + } |
|
| 209 | 209 | } |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | $this->_old_table = $wpdb->prefix."events_attendee"; |
| 49 | 49 | $this->select_expression = 'att.*, e.event_status'; |
| 50 | 50 | $this->_extra_where_sql = ' AS att |
| 51 | - INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
|
| 51 | + INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id=e.id |
|
| 52 | 52 | WHERE e.event_status!="D"'; |
| 53 | 53 | $this->_new_transaction_table = $wpdb->prefix."esp_transaction"; |
| 54 | 54 | $this->_new_line_table = $wpdb->prefix."esp_line_item"; |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | // insert line items if its a primary id |
| 62 | 62 | if (intval($old_row['is_primary'])) { |
| 63 | 63 | $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $this->_new_transaction_table); |
| 64 | - if (! $txn_id) { |
|
| 64 | + if ( ! $txn_id) { |
|
| 65 | 65 | $this->add_error(sprintf(__("Could not find the transaction for the 3.1 attendee %d from row %s", "event_espresso"), $old_row['id'], $this->_json_encode($old_row))); |
| 66 | 66 | return; |
| 67 | 67 | } |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | // group REGs by TKT_ID |
| 119 | 119 | $regs_by_tkt = array(); |
| 120 | 120 | foreach ($regs_on_this_transaction as $new_reg) { |
| 121 | - $regs_by_tkt[ $new_reg['TKT_ID'] ][] = $new_reg; |
|
| 121 | + $regs_by_tkt[$new_reg['TKT_ID']][] = $new_reg; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | // create individual line items |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | $a_reg = reset($regs); |
| 133 | 133 | $new_ticket = $this->_get_new_ticket_row($a_reg['TKT_ID']); |
| 134 | 134 | $reg_line_item_id = $this->_insert_new_line_item(array( |
| 135 | - 'LIN_code'=> md5('Ticket' . $ticket_id . time()), |
|
| 135 | + 'LIN_code'=> md5('Ticket'.$ticket_id.time()), |
|
| 136 | 136 | 'TXN_ID'=>$transaction['TXN_ID'], |
| 137 | 137 | 'LIN_name'=>$new_ticket['TKT_name'], |
| 138 | 138 | 'LIN_unit_price'=>$a_reg['REG_final_price'], |
@@ -184,23 +184,23 @@ discard block |
||
| 184 | 184 | ); |
| 185 | 185 | $cols_n_values = array_merge($default_cols_n_values, $cols_n_values); |
| 186 | 186 | $datatypes = array( |
| 187 | - '%s',// LIN_code |
|
| 188 | - '%d',// TXN_ID |
|
| 189 | - '%s',// LIN_name |
|
| 190 | - '%s',// LIN_desc |
|
| 191 | - '%f',// LIN_unit_price |
|
| 192 | - '%f',// LIN_percent |
|
| 193 | - '%d',// LIN_is_taxable |
|
| 194 | - '%d',// LIN_order |
|
| 195 | - '%f',// LIN_total |
|
| 196 | - '%d',// LIN_quantity |
|
| 197 | - '%d',// LIN_parent |
|
| 198 | - '%s',// LIN_type |
|
| 199 | - '%d',// OBJ_ID |
|
| 200 | - '%s',// OBJ_type |
|
| 187 | + '%s', // LIN_code |
|
| 188 | + '%d', // TXN_ID |
|
| 189 | + '%s', // LIN_name |
|
| 190 | + '%s', // LIN_desc |
|
| 191 | + '%f', // LIN_unit_price |
|
| 192 | + '%f', // LIN_percent |
|
| 193 | + '%d', // LIN_is_taxable |
|
| 194 | + '%d', // LIN_order |
|
| 195 | + '%f', // LIN_total |
|
| 196 | + '%d', // LIN_quantity |
|
| 197 | + '%d', // LIN_parent |
|
| 198 | + '%s', // LIN_type |
|
| 199 | + '%d', // OBJ_ID |
|
| 200 | + '%s', // OBJ_type |
|
| 201 | 201 | ); |
| 202 | 202 | $success = $wpdb->insert($this->_new_line_table, $cols_n_values, $datatypes); |
| 203 | - if (! $success) { |
|
| 203 | + if ( ! $success) { |
|
| 204 | 204 | $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)); |
| 205 | 205 | return 0; |
| 206 | 206 | } |
@@ -38,103 +38,103 @@ |
||
| 38 | 38 | * @since 4.0 |
| 39 | 39 | */ |
| 40 | 40 | if (function_exists('espresso_version')) { |
| 41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | - /** |
|
| 43 | - * espresso_duplicate_plugin_error |
|
| 44 | - * displays if more than one version of EE is activated at the same time |
|
| 45 | - */ |
|
| 46 | - function espresso_duplicate_plugin_error() |
|
| 47 | - { |
|
| 48 | - ?> |
|
| 41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | + /** |
|
| 43 | + * espresso_duplicate_plugin_error |
|
| 44 | + * displays if more than one version of EE is activated at the same time |
|
| 45 | + */ |
|
| 46 | + function espresso_duplicate_plugin_error() |
|
| 47 | + { |
|
| 48 | + ?> |
|
| 49 | 49 | <div class="error"> |
| 50 | 50 | <p> |
| 51 | 51 | <?php |
| 52 | - echo esc_html__( |
|
| 53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ); ?> |
|
| 52 | + echo esc_html__( |
|
| 53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 63 | 63 | } else { |
| 64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
| 65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | - /** |
|
| 67 | - * espresso_minimum_php_version_error |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - function espresso_minimum_php_version_error() |
|
| 72 | - { |
|
| 73 | - ?> |
|
| 64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
| 65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | + /** |
|
| 67 | + * espresso_minimum_php_version_error |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + function espresso_minimum_php_version_error() |
|
| 72 | + { |
|
| 73 | + ?> |
|
| 74 | 74 | <div class="error"> |
| 75 | 75 | <p> |
| 76 | 76 | <?php |
| 77 | - printf( |
|
| 78 | - esc_html__( |
|
| 79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | - 'event_espresso' |
|
| 81 | - ), |
|
| 82 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | - PHP_VERSION, |
|
| 84 | - '<br/>', |
|
| 85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | - ); |
|
| 87 | - ?> |
|
| 77 | + printf( |
|
| 78 | + esc_html__( |
|
| 79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | + 'event_espresso' |
|
| 81 | + ), |
|
| 82 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | + PHP_VERSION, |
|
| 84 | + '<br/>', |
|
| 85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | + ); |
|
| 87 | + ?> |
|
| 88 | 88 | </p> |
| 89 | 89 | </div> |
| 90 | 90 | <?php |
| 91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | - } |
|
| 91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | - } else { |
|
| 96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | - /** |
|
| 98 | - * espresso_version |
|
| 99 | - * Returns the plugin version |
|
| 100 | - * |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - function espresso_version() |
|
| 104 | - { |
|
| 105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.80.rc.103'); |
|
| 106 | - } |
|
| 94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | + } else { |
|
| 96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | + /** |
|
| 98 | + * espresso_version |
|
| 99 | + * Returns the plugin version |
|
| 100 | + * |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + function espresso_version() |
|
| 104 | + { |
|
| 105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.80.rc.103'); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * espresso_plugin_activation |
|
| 110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | - */ |
|
| 112 | - function espresso_plugin_activation() |
|
| 113 | - { |
|
| 114 | - update_option('ee_espresso_activation', true); |
|
| 115 | - } |
|
| 108 | + /** |
|
| 109 | + * espresso_plugin_activation |
|
| 110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | + */ |
|
| 112 | + function espresso_plugin_activation() |
|
| 113 | + { |
|
| 114 | + update_option('ee_espresso_activation', true); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 118 | 118 | |
| 119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | - bootstrap_espresso(); |
|
| 121 | - } |
|
| 119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | + bootstrap_espresso(); |
|
| 121 | + } |
|
| 122 | 122 | } |
| 123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
| 124 | - /** |
|
| 125 | - * deactivate_plugin |
|
| 126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | - * |
|
| 128 | - * @access public |
|
| 129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | - * @return void |
|
| 131 | - */ |
|
| 132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | - { |
|
| 134 | - if (! function_exists('deactivate_plugins')) { |
|
| 135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | - } |
|
| 137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | - deactivate_plugins($plugin_basename); |
|
| 139 | - } |
|
| 124 | + /** |
|
| 125 | + * deactivate_plugin |
|
| 126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | + * |
|
| 128 | + * @access public |
|
| 129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | + * @return void |
|
| 131 | + */ |
|
| 132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | + { |
|
| 134 | + if (! function_exists('deactivate_plugins')) { |
|
| 135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | + } |
|
| 137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | + deactivate_plugins($plugin_basename); |
|
| 139 | + } |
|
| 140 | 140 | } |