@@ -579,8 +579,8 @@ discard block |
||
| 579 | 579 | * that they WILL be added (because the attendees stage runs nearly last during |
| 580 | 580 | * the migration script) |
| 581 | 581 | * @param type $new_ticket_id |
| 582 | - * @param type $sold |
|
| 583 | - * @param type $STS_ID |
|
| 582 | + * @param string $STS_ID |
|
| 583 | + * @param integer $quantity_sold |
|
| 584 | 584 | * @return boolean whether they were successfully updated or not |
| 585 | 585 | */ |
| 586 | 586 | protected function _add_regs_to_ticket_and_datetimes($new_ticket_id, $quantity_sold, $STS_ID) |
@@ -777,6 +777,10 @@ discard block |
||
| 777 | 777 | } |
| 778 | 778 | return $count; |
| 779 | 779 | } |
| 780 | + |
|
| 781 | + /** |
|
| 782 | + * @param integer $new_txn_id |
|
| 783 | + */ |
|
| 780 | 784 | private function _insert_new_payment($old_attendee, $new_txn_id) |
| 781 | 785 | { |
| 782 | 786 | global $wpdb; |
@@ -53,10 +53,6 @@ discard block |
||
| 53 | 53 | ENGINE=InnoDB |
| 54 | 54 | AUTO_INCREMENT=3 |
| 55 | 55 | ; |
| 56 | - |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - |
|
| 60 | 56 | * 4.1 Attendee tables and fields: |
| 61 | 57 | * $this->_tables = array( |
| 62 | 58 | 'Attendee_CPT'=> new EE_Primary_Table('posts', 'ID'), |
@@ -186,634 +182,634 @@ discard block |
||
| 186 | 182 | */ |
| 187 | 183 | class EE_DMS_4_1_0_attendees extends EE_Data_Migration_Script_Stage_Table |
| 188 | 184 | { |
| 189 | - private $_new_attendee_cpt_table; |
|
| 190 | - private $_new_attendee_meta_table; |
|
| 191 | - private $_new_reg_table; |
|
| 192 | - private $_new_transaction_table; |
|
| 193 | - private $_new_payment_table; |
|
| 194 | - private $_new_line_table; |
|
| 195 | - private $_old_mer_table; |
|
| 196 | - private $_new_ticket_table; |
|
| 197 | - private $_new_ticket_datetime_table; |
|
| 198 | - private $_new_datetime_table; |
|
| 199 | - private $_new_datetime_ticket_table; |
|
| 200 | - private $_new_price_table; |
|
| 201 | - private $_new_ticket_price_table; |
|
| 202 | - /** |
|
| 203 | - * Rememebrs whether or not the mer table exists |
|
| 204 | - * @var boolean |
|
| 205 | - */ |
|
| 206 | - private $_mer_tables_exist = null; |
|
| 207 | - public function __construct() |
|
| 208 | - { |
|
| 209 | - global $wpdb; |
|
| 210 | - $this->_pretty_name = __("Attendees", "event_espresso"); |
|
| 211 | - $this->_old_table = $wpdb->prefix."events_attendee"; |
|
| 212 | - $this->_extra_where_sql = 'AS att |
|
| 185 | + private $_new_attendee_cpt_table; |
|
| 186 | + private $_new_attendee_meta_table; |
|
| 187 | + private $_new_reg_table; |
|
| 188 | + private $_new_transaction_table; |
|
| 189 | + private $_new_payment_table; |
|
| 190 | + private $_new_line_table; |
|
| 191 | + private $_old_mer_table; |
|
| 192 | + private $_new_ticket_table; |
|
| 193 | + private $_new_ticket_datetime_table; |
|
| 194 | + private $_new_datetime_table; |
|
| 195 | + private $_new_datetime_ticket_table; |
|
| 196 | + private $_new_price_table; |
|
| 197 | + private $_new_ticket_price_table; |
|
| 198 | + /** |
|
| 199 | + * Rememebrs whether or not the mer table exists |
|
| 200 | + * @var boolean |
|
| 201 | + */ |
|
| 202 | + private $_mer_tables_exist = null; |
|
| 203 | + public function __construct() |
|
| 204 | + { |
|
| 205 | + global $wpdb; |
|
| 206 | + $this->_pretty_name = __("Attendees", "event_espresso"); |
|
| 207 | + $this->_old_table = $wpdb->prefix."events_attendee"; |
|
| 208 | + $this->_extra_where_sql = 'AS att |
|
| 213 | 209 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
| 214 | 210 | WHERE e.event_status!="D"'; |
| 215 | - $this->_old_mer_table = $wpdb->prefix."events_multi_event_registration_id_group"; |
|
| 216 | - $this->_new_attendee_cpt_table = $wpdb->posts; |
|
| 217 | - $this->_new_attendee_meta_table = $wpdb->prefix."esp_attendee_meta"; |
|
| 218 | - $this->_new_reg_table = $wpdb->prefix."esp_registration"; |
|
| 219 | - $this->_new_transaction_table = $wpdb->prefix."esp_transaction"; |
|
| 220 | - $this->_new_payment_table = $wpdb->prefix."esp_payment"; |
|
| 221 | - $this->_new_line_table = $wpdb->prefix."esp_line_item"; |
|
| 222 | - $this->_new_ticket_table = $wpdb->prefix."esp_ticket"; |
|
| 223 | - $this->_new_ticket_datetime_table = $wpdb->prefix."esp_datetime_ticket"; |
|
| 224 | - $this->_new_datetime_table = $wpdb->prefix."esp_datetime"; |
|
| 225 | - $this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket"; |
|
| 226 | - $this->_new_price_table = $wpdb->prefix."esp_price"; |
|
| 227 | - $this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price"; |
|
| 228 | - parent::__construct(); |
|
| 229 | - } |
|
| 211 | + $this->_old_mer_table = $wpdb->prefix."events_multi_event_registration_id_group"; |
|
| 212 | + $this->_new_attendee_cpt_table = $wpdb->posts; |
|
| 213 | + $this->_new_attendee_meta_table = $wpdb->prefix."esp_attendee_meta"; |
|
| 214 | + $this->_new_reg_table = $wpdb->prefix."esp_registration"; |
|
| 215 | + $this->_new_transaction_table = $wpdb->prefix."esp_transaction"; |
|
| 216 | + $this->_new_payment_table = $wpdb->prefix."esp_payment"; |
|
| 217 | + $this->_new_line_table = $wpdb->prefix."esp_line_item"; |
|
| 218 | + $this->_new_ticket_table = $wpdb->prefix."esp_ticket"; |
|
| 219 | + $this->_new_ticket_datetime_table = $wpdb->prefix."esp_datetime_ticket"; |
|
| 220 | + $this->_new_datetime_table = $wpdb->prefix."esp_datetime"; |
|
| 221 | + $this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket"; |
|
| 222 | + $this->_new_price_table = $wpdb->prefix."esp_price"; |
|
| 223 | + $this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price"; |
|
| 224 | + parent::__construct(); |
|
| 225 | + } |
|
| 230 | 226 | |
| 231 | - protected function _migrate_old_row($old_row) |
|
| 232 | - { |
|
| 233 | - // first check if there's already a new attendee with similar characteristics |
|
| 234 | - $new_att_id = $this->_find_attendee_cpt_matching($old_row); |
|
| 235 | - if (! $new_att_id) { |
|
| 236 | - $new_att_id = $this->_insert_new_attendee_cpt($old_row); |
|
| 237 | - if (! $new_att_id) { |
|
| 238 | - // if we couldnt even make an attendee, abandon all hope |
|
| 239 | - return false; |
|
| 240 | - } |
|
| 241 | - $new_att_meta_id = $this->_insert_attendee_meta_row($old_row, $new_att_id); |
|
| 242 | - if ($new_att_meta_id) { |
|
| 243 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_meta_table, $new_att_meta_id); |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_cpt_table, $new_att_id); |
|
| 227 | + protected function _migrate_old_row($old_row) |
|
| 228 | + { |
|
| 229 | + // first check if there's already a new attendee with similar characteristics |
|
| 230 | + $new_att_id = $this->_find_attendee_cpt_matching($old_row); |
|
| 231 | + if (! $new_att_id) { |
|
| 232 | + $new_att_id = $this->_insert_new_attendee_cpt($old_row); |
|
| 233 | + if (! $new_att_id) { |
|
| 234 | + // if we couldnt even make an attendee, abandon all hope |
|
| 235 | + return false; |
|
| 236 | + } |
|
| 237 | + $new_att_meta_id = $this->_insert_attendee_meta_row($old_row, $new_att_id); |
|
| 238 | + if ($new_att_meta_id) { |
|
| 239 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_meta_table, $new_att_meta_id); |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_cpt_table, $new_att_id); |
|
| 247 | 243 | |
| 248 | - $txn_id = $this->_insert_new_transaction($old_row); |
|
| 249 | - if (! $txn_id) { |
|
| 250 | - // if we couldnt make the transaction, also abandon all hope |
|
| 251 | - return false; |
|
| 252 | - } |
|
| 253 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_transaction_table, $txn_id); |
|
| 254 | - $pay_id = $this->_insert_new_payment($old_row, $txn_id); |
|
| 255 | - if ($pay_id) { |
|
| 256 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_payment_table, $pay_id); |
|
| 257 | - } |
|
| 244 | + $txn_id = $this->_insert_new_transaction($old_row); |
|
| 245 | + if (! $txn_id) { |
|
| 246 | + // if we couldnt make the transaction, also abandon all hope |
|
| 247 | + return false; |
|
| 248 | + } |
|
| 249 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_transaction_table, $txn_id); |
|
| 250 | + $pay_id = $this->_insert_new_payment($old_row, $txn_id); |
|
| 251 | + if ($pay_id) { |
|
| 252 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_payment_table, $pay_id); |
|
| 253 | + } |
|
| 258 | 254 | |
| 259 | 255 | |
| 260 | - // even if there was no payment, we can go ahead with adding the reg |
|
| 261 | - $new_regs = $this->_insert_new_registrations($old_row, $new_att_id, $txn_id); |
|
| 262 | - if ($new_regs) { |
|
| 263 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_reg_table, $new_regs); |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - /** |
|
| 267 | - * Checks if there's already an attendee CPT in the db that has the same |
|
| 268 | - * first and last name, and email. If so, returns its ID as an int. |
|
| 269 | - * @global type $wpdb |
|
| 270 | - * @param array $old_attendee |
|
| 271 | - * @return int |
|
| 272 | - */ |
|
| 273 | - private function _find_attendee_cpt_matching($old_attendee) |
|
| 274 | - { |
|
| 275 | - global $wpdb; |
|
| 276 | - $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'])); |
|
| 277 | - return intval($existing_attendee_id); |
|
| 278 | - } |
|
| 279 | - private function _insert_new_attendee_cpt($old_attendee) |
|
| 280 | - { |
|
| 281 | - global $wpdb; |
|
| 282 | - $cols_n_values = array( |
|
| 283 | - 'post_title'=>stripslashes($old_attendee['fname']." ".$old_attendee['lname']),// ATT_full_name |
|
| 284 | - 'post_content'=>'',// ATT_bio |
|
| 285 | - 'post_name'=>sanitize_title($old_attendee['fname']."-".$old_attendee['lname']),// ATT_slug |
|
| 286 | - 'post_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_created |
|
| 287 | - 'post_excerpt'=>'',// ATT_short_bio |
|
| 288 | - 'post_modified'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_modified |
|
| 289 | - 'post_author'=>0,// ATT_author |
|
| 290 | - 'post_parent'=>0,// ATT_parent |
|
| 291 | - 'post_type'=>'espresso_attendees',// post_type |
|
| 292 | - 'post_status'=>'publish'// status |
|
| 293 | - ); |
|
| 294 | - $datatypes = array( |
|
| 295 | - '%s',// ATT_full_name |
|
| 296 | - '%s',// ATT_bio |
|
| 297 | - '%s',// ATT_slug |
|
| 298 | - '%s',// ATT_created |
|
| 299 | - '%s',// ATT_short_bio |
|
| 300 | - '%s',// ATT_modified |
|
| 301 | - '%d',// ATT_author |
|
| 302 | - '%d',// ATT_parent |
|
| 303 | - '%s',// post_type |
|
| 304 | - '%s',// status |
|
| 305 | - ); |
|
| 306 | - $success = $wpdb->insert($this->_new_attendee_cpt_table, $cols_n_values, $datatypes); |
|
| 307 | - if (! $success) { |
|
| 308 | - $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)); |
|
| 309 | - return 0; |
|
| 310 | - } |
|
| 311 | - $new_id = $wpdb->insert_id; |
|
| 312 | - return $new_id; |
|
| 313 | - } |
|
| 256 | + // even if there was no payment, we can go ahead with adding the reg |
|
| 257 | + $new_regs = $this->_insert_new_registrations($old_row, $new_att_id, $txn_id); |
|
| 258 | + if ($new_regs) { |
|
| 259 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_reg_table, $new_regs); |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + /** |
|
| 263 | + * Checks if there's already an attendee CPT in the db that has the same |
|
| 264 | + * first and last name, and email. If so, returns its ID as an int. |
|
| 265 | + * @global type $wpdb |
|
| 266 | + * @param array $old_attendee |
|
| 267 | + * @return int |
|
| 268 | + */ |
|
| 269 | + private function _find_attendee_cpt_matching($old_attendee) |
|
| 270 | + { |
|
| 271 | + global $wpdb; |
|
| 272 | + $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'])); |
|
| 273 | + return intval($existing_attendee_id); |
|
| 274 | + } |
|
| 275 | + private function _insert_new_attendee_cpt($old_attendee) |
|
| 276 | + { |
|
| 277 | + global $wpdb; |
|
| 278 | + $cols_n_values = array( |
|
| 279 | + 'post_title'=>stripslashes($old_attendee['fname']." ".$old_attendee['lname']),// ATT_full_name |
|
| 280 | + 'post_content'=>'',// ATT_bio |
|
| 281 | + 'post_name'=>sanitize_title($old_attendee['fname']."-".$old_attendee['lname']),// ATT_slug |
|
| 282 | + 'post_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_created |
|
| 283 | + 'post_excerpt'=>'',// ATT_short_bio |
|
| 284 | + 'post_modified'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_modified |
|
| 285 | + 'post_author'=>0,// ATT_author |
|
| 286 | + 'post_parent'=>0,// ATT_parent |
|
| 287 | + 'post_type'=>'espresso_attendees',// post_type |
|
| 288 | + 'post_status'=>'publish'// status |
|
| 289 | + ); |
|
| 290 | + $datatypes = array( |
|
| 291 | + '%s',// ATT_full_name |
|
| 292 | + '%s',// ATT_bio |
|
| 293 | + '%s',// ATT_slug |
|
| 294 | + '%s',// ATT_created |
|
| 295 | + '%s',// ATT_short_bio |
|
| 296 | + '%s',// ATT_modified |
|
| 297 | + '%d',// ATT_author |
|
| 298 | + '%d',// ATT_parent |
|
| 299 | + '%s',// post_type |
|
| 300 | + '%s',// status |
|
| 301 | + ); |
|
| 302 | + $success = $wpdb->insert($this->_new_attendee_cpt_table, $cols_n_values, $datatypes); |
|
| 303 | + if (! $success) { |
|
| 304 | + $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)); |
|
| 305 | + return 0; |
|
| 306 | + } |
|
| 307 | + $new_id = $wpdb->insert_id; |
|
| 308 | + return $new_id; |
|
| 309 | + } |
|
| 314 | 310 | |
| 315 | - private function _insert_attendee_meta_row($old_attendee, $new_attendee_cpt_id) |
|
| 316 | - { |
|
| 317 | - global $wpdb; |
|
| 318 | - // get the state and country ids from the old row |
|
| 319 | - try { |
|
| 320 | - $new_country = $this->get_migration_script()->get_or_create_country(stripslashes($old_attendee['country_id'])); |
|
| 321 | - $new_country_iso = $new_country['CNT_ISO']; |
|
| 322 | - } catch (EE_Error $exception) { |
|
| 323 | - $new_country_iso = $this->get_migration_script()->get_default_country_iso(); |
|
| 324 | - } |
|
| 325 | - try { |
|
| 326 | - $new_state = $this->get_migration_script()->get_or_create_state(stripslashes($old_attendee['state']), $new_country_iso); |
|
| 327 | - $new_state_id = $new_state['STA_ID']; |
|
| 328 | - } catch (EE_Error $exception) { |
|
| 329 | - $new_state_id = 0; |
|
| 330 | - } |
|
| 331 | - $cols_n_values = array( |
|
| 332 | - 'ATT_ID'=>$new_attendee_cpt_id, |
|
| 333 | - 'ATT_fname'=>stripslashes($old_attendee['fname']), |
|
| 334 | - 'ATT_lname'=>stripslashes($old_attendee['lname']), |
|
| 335 | - 'ATT_address'=>stripslashes($old_attendee['address']), |
|
| 336 | - 'ATT_address2'=>stripslashes($old_attendee['address2']), |
|
| 337 | - 'ATT_city'=>stripslashes($old_attendee['city']), |
|
| 338 | - 'STA_ID'=>$new_state_id, |
|
| 339 | - 'CNT_ISO'=>$new_country_iso, |
|
| 340 | - 'ATT_zip'=>stripslashes($old_attendee['zip']), |
|
| 341 | - 'ATT_email'=>stripslashes($old_attendee['email']), |
|
| 342 | - 'ATT_phone'=>stripslashes($old_attendee['phone']), |
|
| 343 | - ); |
|
| 344 | - $datatypes = array( |
|
| 345 | - '%d',// ATT_ID |
|
| 346 | - '%s',// ATT_fname |
|
| 347 | - '%s',// ATT_lname |
|
| 348 | - '%s',// ATT_address |
|
| 349 | - '%s',// ATT_address2 |
|
| 350 | - '%s',// ATT_city |
|
| 351 | - '%d',// STA_ID |
|
| 352 | - '%s',// CNT_ISO |
|
| 353 | - '%s',// ATT_zip |
|
| 354 | - '%s',// ATT_email |
|
| 355 | - '%s',// ATT_phone |
|
| 356 | - ); |
|
| 357 | - $success = $wpdb->insert($this->_new_attendee_meta_table, $cols_n_values, $datatypes); |
|
| 358 | - if (! $success) { |
|
| 359 | - $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)); |
|
| 360 | - return 0; |
|
| 361 | - } |
|
| 362 | - $new_id = $wpdb->insert_id; |
|
| 363 | - return $new_id; |
|
| 364 | - } |
|
| 311 | + private function _insert_attendee_meta_row($old_attendee, $new_attendee_cpt_id) |
|
| 312 | + { |
|
| 313 | + global $wpdb; |
|
| 314 | + // get the state and country ids from the old row |
|
| 315 | + try { |
|
| 316 | + $new_country = $this->get_migration_script()->get_or_create_country(stripslashes($old_attendee['country_id'])); |
|
| 317 | + $new_country_iso = $new_country['CNT_ISO']; |
|
| 318 | + } catch (EE_Error $exception) { |
|
| 319 | + $new_country_iso = $this->get_migration_script()->get_default_country_iso(); |
|
| 320 | + } |
|
| 321 | + try { |
|
| 322 | + $new_state = $this->get_migration_script()->get_or_create_state(stripslashes($old_attendee['state']), $new_country_iso); |
|
| 323 | + $new_state_id = $new_state['STA_ID']; |
|
| 324 | + } catch (EE_Error $exception) { |
|
| 325 | + $new_state_id = 0; |
|
| 326 | + } |
|
| 327 | + $cols_n_values = array( |
|
| 328 | + 'ATT_ID'=>$new_attendee_cpt_id, |
|
| 329 | + 'ATT_fname'=>stripslashes($old_attendee['fname']), |
|
| 330 | + 'ATT_lname'=>stripslashes($old_attendee['lname']), |
|
| 331 | + 'ATT_address'=>stripslashes($old_attendee['address']), |
|
| 332 | + 'ATT_address2'=>stripslashes($old_attendee['address2']), |
|
| 333 | + 'ATT_city'=>stripslashes($old_attendee['city']), |
|
| 334 | + 'STA_ID'=>$new_state_id, |
|
| 335 | + 'CNT_ISO'=>$new_country_iso, |
|
| 336 | + 'ATT_zip'=>stripslashes($old_attendee['zip']), |
|
| 337 | + 'ATT_email'=>stripslashes($old_attendee['email']), |
|
| 338 | + 'ATT_phone'=>stripslashes($old_attendee['phone']), |
|
| 339 | + ); |
|
| 340 | + $datatypes = array( |
|
| 341 | + '%d',// ATT_ID |
|
| 342 | + '%s',// ATT_fname |
|
| 343 | + '%s',// ATT_lname |
|
| 344 | + '%s',// ATT_address |
|
| 345 | + '%s',// ATT_address2 |
|
| 346 | + '%s',// ATT_city |
|
| 347 | + '%d',// STA_ID |
|
| 348 | + '%s',// CNT_ISO |
|
| 349 | + '%s',// ATT_zip |
|
| 350 | + '%s',// ATT_email |
|
| 351 | + '%s',// ATT_phone |
|
| 352 | + ); |
|
| 353 | + $success = $wpdb->insert($this->_new_attendee_meta_table, $cols_n_values, $datatypes); |
|
| 354 | + if (! $success) { |
|
| 355 | + $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)); |
|
| 356 | + return 0; |
|
| 357 | + } |
|
| 358 | + $new_id = $wpdb->insert_id; |
|
| 359 | + return $new_id; |
|
| 360 | + } |
|
| 365 | 361 | |
| 366 | - /** |
|
| 367 | - * Note: we don't necessarily create a new transaction for each attendee row. |
|
| 368 | - * Only if the old attendee 'is_primary' is true; otherwise we find the old attendee row that |
|
| 369 | - * 'is_primary' and has the same 'txn_id', then we return ITS new transaction id |
|
| 370 | - * @global type $wpdb |
|
| 371 | - * @param type $old_attendee |
|
| 372 | - * @return int new transaction id |
|
| 373 | - */ |
|
| 374 | - private function _insert_new_transaction($old_attendee) |
|
| 375 | - { |
|
| 376 | - global $wpdb; |
|
| 362 | + /** |
|
| 363 | + * Note: we don't necessarily create a new transaction for each attendee row. |
|
| 364 | + * Only if the old attendee 'is_primary' is true; otherwise we find the old attendee row that |
|
| 365 | + * 'is_primary' and has the same 'txn_id', then we return ITS new transaction id |
|
| 366 | + * @global type $wpdb |
|
| 367 | + * @param type $old_attendee |
|
| 368 | + * @return int new transaction id |
|
| 369 | + */ |
|
| 370 | + private function _insert_new_transaction($old_attendee) |
|
| 371 | + { |
|
| 372 | + global $wpdb; |
|
| 377 | 373 | |
| 378 | - // first: let's check for an existing transaction for this old attendee |
|
| 379 | - if (intval($old_attendee['is_primary'])) {// primary attendee, so create txn |
|
| 380 | - $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($old_attendee['id']), $this->_new_transaction_table); |
|
| 381 | - } else { // non-primary attendee, so find its primary attendee's transaction |
|
| 382 | - $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'])); |
|
| 383 | - if (! $primary_attendee_old_id) { |
|
| 384 | - $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee['registration_id']); |
|
| 385 | - $primary_attendee_old_id = is_array($primary_attendee) ? $primary_attendee['id'] : null; |
|
| 386 | - } |
|
| 387 | - $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($primary_attendee_old_id), $this->_new_transaction_table); |
|
| 388 | - if (! $txn_id) { |
|
| 389 | - $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)); |
|
| 390 | - $txn_id = 0; |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - // if there isn't yet a transaction row for this, create one |
|
| 394 | - // (so even if it was a non-primary attendee with no EE3 primary attendee, |
|
| 395 | - // it ought to have SOME transaction, so we'll make one) |
|
| 396 | - if (! $txn_id) { |
|
| 397 | - // maps 3.1 payment stati onto 4.1 transaction stati |
|
| 398 | - $txn_status_mapping = array( |
|
| 399 | - 'Completed'=>'TCM', |
|
| 400 | - 'Pending'=>'TIN', |
|
| 401 | - 'Payment Declined'=>'TIN', |
|
| 402 | - 'Incomplete'=>'TIN', |
|
| 403 | - 'Not Completed'=>'TIN', |
|
| 404 | - 'Cancelled'=>'TIN', |
|
| 405 | - 'Declined'=>'TIN' |
|
| 406 | - ); |
|
| 407 | - $STS_ID = isset($txn_status_mapping[ $old_attendee['payment_status'] ]) ? $txn_status_mapping[ $old_attendee['payment_status'] ] : 'TIN'; |
|
| 408 | - $cols_n_values = array( |
|
| 409 | - 'TXN_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
| 410 | - 'TXN_total'=>floatval($old_attendee['total_cost']), |
|
| 411 | - 'TXN_paid'=>floatval($old_attendee['amount_pd']), |
|
| 412 | - 'STS_ID'=>$STS_ID, |
|
| 413 | - 'TXN_hash_salt'=>$old_attendee['hashSalt'] |
|
| 414 | - ); |
|
| 415 | - $datatypes = array( |
|
| 416 | - '%s',// TXN_timestamp |
|
| 417 | - '%f',// TXN_total |
|
| 418 | - '%f',// TXN_paid |
|
| 419 | - '%s',// STS_ID |
|
| 420 | - '%s',// TXN_hash_salt |
|
| 421 | - ); |
|
| 422 | - $success = $wpdb->insert($this->_new_transaction_table, $cols_n_values, $datatypes); |
|
| 423 | - if (! $success) { |
|
| 424 | - $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)); |
|
| 425 | - return 0; |
|
| 426 | - } |
|
| 427 | - $txn_id = $wpdb->insert_id; |
|
| 428 | - } |
|
| 374 | + // first: let's check for an existing transaction for this old attendee |
|
| 375 | + if (intval($old_attendee['is_primary'])) {// primary attendee, so create txn |
|
| 376 | + $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($old_attendee['id']), $this->_new_transaction_table); |
|
| 377 | + } else { // non-primary attendee, so find its primary attendee's transaction |
|
| 378 | + $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'])); |
|
| 379 | + if (! $primary_attendee_old_id) { |
|
| 380 | + $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee['registration_id']); |
|
| 381 | + $primary_attendee_old_id = is_array($primary_attendee) ? $primary_attendee['id'] : null; |
|
| 382 | + } |
|
| 383 | + $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($primary_attendee_old_id), $this->_new_transaction_table); |
|
| 384 | + if (! $txn_id) { |
|
| 385 | + $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)); |
|
| 386 | + $txn_id = 0; |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | + // if there isn't yet a transaction row for this, create one |
|
| 390 | + // (so even if it was a non-primary attendee with no EE3 primary attendee, |
|
| 391 | + // it ought to have SOME transaction, so we'll make one) |
|
| 392 | + if (! $txn_id) { |
|
| 393 | + // maps 3.1 payment stati onto 4.1 transaction stati |
|
| 394 | + $txn_status_mapping = array( |
|
| 395 | + 'Completed'=>'TCM', |
|
| 396 | + 'Pending'=>'TIN', |
|
| 397 | + 'Payment Declined'=>'TIN', |
|
| 398 | + 'Incomplete'=>'TIN', |
|
| 399 | + 'Not Completed'=>'TIN', |
|
| 400 | + 'Cancelled'=>'TIN', |
|
| 401 | + 'Declined'=>'TIN' |
|
| 402 | + ); |
|
| 403 | + $STS_ID = isset($txn_status_mapping[ $old_attendee['payment_status'] ]) ? $txn_status_mapping[ $old_attendee['payment_status'] ] : 'TIN'; |
|
| 404 | + $cols_n_values = array( |
|
| 405 | + 'TXN_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
| 406 | + 'TXN_total'=>floatval($old_attendee['total_cost']), |
|
| 407 | + 'TXN_paid'=>floatval($old_attendee['amount_pd']), |
|
| 408 | + 'STS_ID'=>$STS_ID, |
|
| 409 | + 'TXN_hash_salt'=>$old_attendee['hashSalt'] |
|
| 410 | + ); |
|
| 411 | + $datatypes = array( |
|
| 412 | + '%s',// TXN_timestamp |
|
| 413 | + '%f',// TXN_total |
|
| 414 | + '%f',// TXN_paid |
|
| 415 | + '%s',// STS_ID |
|
| 416 | + '%s',// TXN_hash_salt |
|
| 417 | + ); |
|
| 418 | + $success = $wpdb->insert($this->_new_transaction_table, $cols_n_values, $datatypes); |
|
| 419 | + if (! $success) { |
|
| 420 | + $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)); |
|
| 421 | + return 0; |
|
| 422 | + } |
|
| 423 | + $txn_id = $wpdb->insert_id; |
|
| 424 | + } |
|
| 429 | 425 | |
| 430 | - return $txn_id; |
|
| 431 | - } |
|
| 432 | - /** |
|
| 433 | - * Detects if the MER tables exist |
|
| 434 | - * @global type $wpdb |
|
| 435 | - * @return boolean |
|
| 436 | - */ |
|
| 437 | - private function _mer_tables_exist() |
|
| 438 | - { |
|
| 439 | - if ($this->_mer_tables_exist === null) { |
|
| 440 | - global $wpdb; |
|
| 426 | + return $txn_id; |
|
| 427 | + } |
|
| 428 | + /** |
|
| 429 | + * Detects if the MER tables exist |
|
| 430 | + * @global type $wpdb |
|
| 431 | + * @return boolean |
|
| 432 | + */ |
|
| 433 | + private function _mer_tables_exist() |
|
| 434 | + { |
|
| 435 | + if ($this->_mer_tables_exist === null) { |
|
| 436 | + global $wpdb; |
|
| 441 | 437 | |
| 442 | - if ($wpdb->get_var("SHOW TABLES LIKE '{$this->_old_mer_table}'") != $this->_old_mer_table) { |
|
| 443 | - $this->_mer_tables_exist = false; |
|
| 444 | - } else { |
|
| 445 | - $this->_mer_tables_exist = true; |
|
| 446 | - } |
|
| 447 | - } |
|
| 448 | - return $this->_mer_tables_exist; |
|
| 449 | - } |
|
| 438 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$this->_old_mer_table}'") != $this->_old_mer_table) { |
|
| 439 | + $this->_mer_tables_exist = false; |
|
| 440 | + } else { |
|
| 441 | + $this->_mer_tables_exist = true; |
|
| 442 | + } |
|
| 443 | + } |
|
| 444 | + return $this->_mer_tables_exist; |
|
| 445 | + } |
|
| 450 | 446 | |
| 451 | - /** |
|
| 452 | - * Gets the 4.1 registration's status given the 3.1 attendee row. We consider |
|
| 453 | - * whether the event required pre-approval or not,a dn the 4.1 payment status. |
|
| 454 | - * @global type $wpdb |
|
| 455 | - * @param type $old_attendee_row |
|
| 456 | - * @return string |
|
| 457 | - */ |
|
| 458 | - private function _get_reg_status_for_old_payment_status($old_attendee_row) |
|
| 459 | - { |
|
| 460 | - // need event default reg status and if pre_approval was required |
|
| 461 | - global $wpdb; |
|
| 462 | - $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'])); |
|
| 463 | - return $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID( |
|
| 464 | - $old_attendee_row['payment_status'], |
|
| 465 | - intval($event_required_pre_approval) && intval($old_attendee_row['pre_approve']) |
|
| 466 | - ); |
|
| 467 | - } |
|
| 468 | - /** |
|
| 469 | - * Adds however many rgistrations are indicated by the old attendee's QUANTITY field, |
|
| 470 | - * and returns an array of their IDs |
|
| 471 | - * @global type $wpdb |
|
| 472 | - * @param array $old_attendee |
|
| 473 | - * @param int $new_attendee_id |
|
| 474 | - * @param int $new_txn_id |
|
| 475 | - * @return array of new registratio ids |
|
| 476 | - */ |
|
| 477 | - private function _insert_new_registrations($old_attendee, $new_attendee_id, $new_txn_id) |
|
| 478 | - { |
|
| 479 | - global $wpdb; |
|
| 447 | + /** |
|
| 448 | + * Gets the 4.1 registration's status given the 3.1 attendee row. We consider |
|
| 449 | + * whether the event required pre-approval or not,a dn the 4.1 payment status. |
|
| 450 | + * @global type $wpdb |
|
| 451 | + * @param type $old_attendee_row |
|
| 452 | + * @return string |
|
| 453 | + */ |
|
| 454 | + private function _get_reg_status_for_old_payment_status($old_attendee_row) |
|
| 455 | + { |
|
| 456 | + // need event default reg status and if pre_approval was required |
|
| 457 | + global $wpdb; |
|
| 458 | + $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'])); |
|
| 459 | + return $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID( |
|
| 460 | + $old_attendee_row['payment_status'], |
|
| 461 | + intval($event_required_pre_approval) && intval($old_attendee_row['pre_approve']) |
|
| 462 | + ); |
|
| 463 | + } |
|
| 464 | + /** |
|
| 465 | + * Adds however many rgistrations are indicated by the old attendee's QUANTITY field, |
|
| 466 | + * and returns an array of their IDs |
|
| 467 | + * @global type $wpdb |
|
| 468 | + * @param array $old_attendee |
|
| 469 | + * @param int $new_attendee_id |
|
| 470 | + * @param int $new_txn_id |
|
| 471 | + * @return array of new registratio ids |
|
| 472 | + */ |
|
| 473 | + private function _insert_new_registrations($old_attendee, $new_attendee_id, $new_txn_id) |
|
| 474 | + { |
|
| 475 | + global $wpdb; |
|
| 480 | 476 | |
| 481 | - $STS_ID = $this->_get_reg_status_for_old_payment_status($old_attendee); |
|
| 482 | - $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix.'events_detail', $old_attendee['event_id'], $wpdb->posts); |
|
| 483 | - if (! $new_event_id) { |
|
| 484 | - $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))); |
|
| 485 | - } |
|
| 477 | + $STS_ID = $this->_get_reg_status_for_old_payment_status($old_attendee); |
|
| 478 | + $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix.'events_detail', $old_attendee['event_id'], $wpdb->posts); |
|
| 479 | + if (! $new_event_id) { |
|
| 480 | + $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))); |
|
| 481 | + } |
|
| 486 | 482 | |
| 487 | - $ticket_id = $this->_try_to_find_new_ticket_id($old_attendee, $new_event_id); |
|
| 488 | - if (! $ticket_id) { |
|
| 489 | - $ticket_id = $this->_insert_new_ticket_because_none_found($old_attendee, $new_event_id); |
|
| 490 | - $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)); |
|
| 491 | - } |
|
| 492 | - $regs_on_this_row = intval($old_attendee['quantity']); |
|
| 493 | - $new_regs = array(); |
|
| 494 | - // 4 cases we need to account for: |
|
| 495 | - // 1 old attendee_details row with a quantity of X (no mer) |
|
| 496 | - // Y old attendee_details rows with a quantity of 1 (no mer) joined by their common registration_id |
|
| 497 | - // Y old attendee_details rows with a quantity of x (because of mer) |
|
| 498 | - // Y old attendee_details rows with a quantity of 1 (because of mer) joined by wp_events_multi_event_registration_id_group |
|
| 499 | - for ($count = 1; $count <= $regs_on_this_row; $count++) { |
|
| 500 | - // sum regs on older rows |
|
| 501 | - $regs_on_this_event_and_txn = $this->_sum_old_attendees_on_old_txn($old_attendee, true); |
|
| 502 | - $cols_n_values = array( |
|
| 503 | - 'EVT_ID'=>$new_event_id, |
|
| 504 | - 'ATT_ID'=>$new_attendee_id, |
|
| 505 | - 'TXN_ID'=>$new_txn_id, |
|
| 506 | - 'TKT_ID'=>$ticket_id, |
|
| 507 | - 'STS_ID'=>$STS_ID, |
|
| 508 | - 'REG_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
| 509 | - 'REG_final_price'=>$old_attendee['final_price'], |
|
| 510 | - 'REG_session'=> substr($old_attendee['attendee_session'], 0, 44), |
|
| 511 | - 'REG_code'=>sanitize_key($old_attendee['registration_id']), |
|
| 512 | - 'REG_url_link'=> sanitize_key($old_attendee['registration_id'].'-'.$count), |
|
| 513 | - 'REG_count'=>$regs_on_this_event_and_txn + $count, |
|
| 514 | - 'REG_group_size'=>$this->_sum_old_attendees_on_old_txn($old_attendee, false), |
|
| 515 | - 'REG_att_is_going'=>true, |
|
| 516 | - 'REG_deleted'=>false |
|
| 517 | - ); |
|
| 518 | - $datatypes = array( |
|
| 519 | - '%d',// EVT_ID |
|
| 520 | - '%d',// ATT_ID |
|
| 521 | - '%d',// TXN_ID |
|
| 522 | - '%d',// TKT_ID |
|
| 523 | - '%s',// STS_ID |
|
| 524 | - '%s',// REG_date |
|
| 525 | - '%f',// REG_final_price |
|
| 526 | - '%s',// REG_session |
|
| 527 | - '%s',// REG_code |
|
| 528 | - '%s',// REG_url_link |
|
| 529 | - '%d',// REG_count |
|
| 530 | - '%d',// REG_group_size |
|
| 531 | - '%d',// REG_att_is_going |
|
| 532 | - '%d',// REG_deleted |
|
| 533 | - ); |
|
| 534 | - $success = $wpdb->insert($this->_new_reg_table, $cols_n_values, $datatypes); |
|
| 535 | - if (! $success) { |
|
| 536 | - $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)); |
|
| 537 | - return 0; |
|
| 538 | - } |
|
| 539 | - $cols_n_values['REG_ID'] = $wpdb->insert_id; |
|
| 540 | - $new_regs[] = $wpdb->insert_id; |
|
| 541 | - } |
|
| 542 | - $this->_add_regs_to_ticket_and_datetimes($ticket_id, count($new_regs), $STS_ID); |
|
| 543 | - return $new_regs; |
|
| 544 | - } |
|
| 483 | + $ticket_id = $this->_try_to_find_new_ticket_id($old_attendee, $new_event_id); |
|
| 484 | + if (! $ticket_id) { |
|
| 485 | + $ticket_id = $this->_insert_new_ticket_because_none_found($old_attendee, $new_event_id); |
|
| 486 | + $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)); |
|
| 487 | + } |
|
| 488 | + $regs_on_this_row = intval($old_attendee['quantity']); |
|
| 489 | + $new_regs = array(); |
|
| 490 | + // 4 cases we need to account for: |
|
| 491 | + // 1 old attendee_details row with a quantity of X (no mer) |
|
| 492 | + // Y old attendee_details rows with a quantity of 1 (no mer) joined by their common registration_id |
|
| 493 | + // Y old attendee_details rows with a quantity of x (because of mer) |
|
| 494 | + // Y old attendee_details rows with a quantity of 1 (because of mer) joined by wp_events_multi_event_registration_id_group |
|
| 495 | + for ($count = 1; $count <= $regs_on_this_row; $count++) { |
|
| 496 | + // sum regs on older rows |
|
| 497 | + $regs_on_this_event_and_txn = $this->_sum_old_attendees_on_old_txn($old_attendee, true); |
|
| 498 | + $cols_n_values = array( |
|
| 499 | + 'EVT_ID'=>$new_event_id, |
|
| 500 | + 'ATT_ID'=>$new_attendee_id, |
|
| 501 | + 'TXN_ID'=>$new_txn_id, |
|
| 502 | + 'TKT_ID'=>$ticket_id, |
|
| 503 | + 'STS_ID'=>$STS_ID, |
|
| 504 | + 'REG_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
| 505 | + 'REG_final_price'=>$old_attendee['final_price'], |
|
| 506 | + 'REG_session'=> substr($old_attendee['attendee_session'], 0, 44), |
|
| 507 | + 'REG_code'=>sanitize_key($old_attendee['registration_id']), |
|
| 508 | + 'REG_url_link'=> sanitize_key($old_attendee['registration_id'].'-'.$count), |
|
| 509 | + 'REG_count'=>$regs_on_this_event_and_txn + $count, |
|
| 510 | + 'REG_group_size'=>$this->_sum_old_attendees_on_old_txn($old_attendee, false), |
|
| 511 | + 'REG_att_is_going'=>true, |
|
| 512 | + 'REG_deleted'=>false |
|
| 513 | + ); |
|
| 514 | + $datatypes = array( |
|
| 515 | + '%d',// EVT_ID |
|
| 516 | + '%d',// ATT_ID |
|
| 517 | + '%d',// TXN_ID |
|
| 518 | + '%d',// TKT_ID |
|
| 519 | + '%s',// STS_ID |
|
| 520 | + '%s',// REG_date |
|
| 521 | + '%f',// REG_final_price |
|
| 522 | + '%s',// REG_session |
|
| 523 | + '%s',// REG_code |
|
| 524 | + '%s',// REG_url_link |
|
| 525 | + '%d',// REG_count |
|
| 526 | + '%d',// REG_group_size |
|
| 527 | + '%d',// REG_att_is_going |
|
| 528 | + '%d',// REG_deleted |
|
| 529 | + ); |
|
| 530 | + $success = $wpdb->insert($this->_new_reg_table, $cols_n_values, $datatypes); |
|
| 531 | + if (! $success) { |
|
| 532 | + $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)); |
|
| 533 | + return 0; |
|
| 534 | + } |
|
| 535 | + $cols_n_values['REG_ID'] = $wpdb->insert_id; |
|
| 536 | + $new_regs[] = $wpdb->insert_id; |
|
| 537 | + } |
|
| 538 | + $this->_add_regs_to_ticket_and_datetimes($ticket_id, count($new_regs), $STS_ID); |
|
| 539 | + return $new_regs; |
|
| 540 | + } |
|
| 545 | 541 | |
| 546 | - /** |
|
| 547 | - * Increments the sold values on the ticket and its related datetimes by the amount sold, |
|
| 548 | - * which should be done directly after adding the rows. Yes this means we're constantly incrementing |
|
| 549 | - * the sold amounts as we go, and is less efficient than a single big query, |
|
| 550 | - * but its safer because we KNOW these regs have been added, rather than inferring |
|
| 551 | - * that they WILL be added (because the attendees stage runs nearly last during |
|
| 552 | - * the migration script) |
|
| 553 | - * @param type $new_ticket_id |
|
| 554 | - * @param type $sold |
|
| 555 | - * @param type $STS_ID |
|
| 556 | - * @return boolean whether they were successfully updated or not |
|
| 557 | - */ |
|
| 558 | - protected function _add_regs_to_ticket_and_datetimes($new_ticket_id, $quantity_sold, $STS_ID) |
|
| 559 | - { |
|
| 560 | - if ($STS_ID != 'RAP') { |
|
| 561 | - return true; |
|
| 562 | - } |
|
| 563 | - global $wpdb; |
|
| 564 | - $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)); |
|
| 565 | - if ($success) { |
|
| 566 | - // get the ticket's datetimes, and increment them too |
|
| 567 | - $success_update_dateimtes = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT |
|
| 542 | + /** |
|
| 543 | + * Increments the sold values on the ticket and its related datetimes by the amount sold, |
|
| 544 | + * which should be done directly after adding the rows. Yes this means we're constantly incrementing |
|
| 545 | + * the sold amounts as we go, and is less efficient than a single big query, |
|
| 546 | + * but its safer because we KNOW these regs have been added, rather than inferring |
|
| 547 | + * that they WILL be added (because the attendees stage runs nearly last during |
|
| 548 | + * the migration script) |
|
| 549 | + * @param type $new_ticket_id |
|
| 550 | + * @param type $sold |
|
| 551 | + * @param type $STS_ID |
|
| 552 | + * @return boolean whether they were successfully updated or not |
|
| 553 | + */ |
|
| 554 | + protected function _add_regs_to_ticket_and_datetimes($new_ticket_id, $quantity_sold, $STS_ID) |
|
| 555 | + { |
|
| 556 | + if ($STS_ID != 'RAP') { |
|
| 557 | + return true; |
|
| 558 | + } |
|
| 559 | + global $wpdb; |
|
| 560 | + $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)); |
|
| 561 | + if ($success) { |
|
| 562 | + // get the ticket's datetimes, and increment them too |
|
| 563 | + $success_update_dateimtes = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT |
|
| 568 | 564 | INNER JOIN {$this->_new_ticket_datetime_table} as DTK ON TKT.TKT_ID = DTK.TKT_ID |
| 569 | 565 | INNER JOIN {$this->_new_datetime_table} as DTT ON DTK.DTT_ID = DTT.DTT_ID |
| 570 | 566 | SET DTT.DTT_sold = DTT.DTT_sold + %d WHERE TKT.TKT_ID = %d", $quantity_sold, $new_ticket_id)); |
| 571 | - if (! $success_update_dateimtes) { |
|
| 572 | - $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)); |
|
| 573 | - } |
|
| 574 | - } else { |
|
| 575 | - $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)); |
|
| 576 | - } |
|
| 577 | - return true; |
|
| 578 | - } |
|
| 579 | - /** |
|
| 580 | - * Makes a best guess at which ticket is the one the attendee purchased. |
|
| 581 | - * Obviously, the old attendee's event_id narrows it down quite a bit; |
|
| 582 | - * then the old attendee's orig_price and event_time, and price_option can uniquely identify the ticket |
|
| 583 | - * however, if we don't find an exact match, see if any of those conditions match; |
|
| 584 | - * and lastly if none of that works, just use the first ticket for the event we find |
|
| 585 | - * @param array $old_attendee |
|
| 586 | - */ |
|
| 587 | - private function _try_to_find_new_ticket_id($old_attendee, $new_event_id) |
|
| 588 | - { |
|
| 589 | - global $wpdb; |
|
| 590 | - $tickets_table = $this->_new_ticket_table; |
|
| 591 | - $datetime_tickets_table = $this->_new_ticket_datetime_table; |
|
| 592 | - $datetime_table = $this->_new_datetime_table; |
|
| 567 | + if (! $success_update_dateimtes) { |
|
| 568 | + $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)); |
|
| 569 | + } |
|
| 570 | + } else { |
|
| 571 | + $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)); |
|
| 572 | + } |
|
| 573 | + return true; |
|
| 574 | + } |
|
| 575 | + /** |
|
| 576 | + * Makes a best guess at which ticket is the one the attendee purchased. |
|
| 577 | + * Obviously, the old attendee's event_id narrows it down quite a bit; |
|
| 578 | + * then the old attendee's orig_price and event_time, and price_option can uniquely identify the ticket |
|
| 579 | + * however, if we don't find an exact match, see if any of those conditions match; |
|
| 580 | + * and lastly if none of that works, just use the first ticket for the event we find |
|
| 581 | + * @param array $old_attendee |
|
| 582 | + */ |
|
| 583 | + private function _try_to_find_new_ticket_id($old_attendee, $new_event_id) |
|
| 584 | + { |
|
| 585 | + global $wpdb; |
|
| 586 | + $tickets_table = $this->_new_ticket_table; |
|
| 587 | + $datetime_tickets_table = $this->_new_ticket_datetime_table; |
|
| 588 | + $datetime_table = $this->_new_datetime_table; |
|
| 593 | 589 | |
| 594 | - $old_att_price_option = $old_attendee['price_option']; |
|
| 595 | - $old_att_price = floatval($old_attendee['orig_price']); |
|
| 590 | + $old_att_price_option = $old_attendee['price_option']; |
|
| 591 | + $old_att_price = floatval($old_attendee['orig_price']); |
|
| 596 | 592 | |
| 597 | - $old_att_start_date = $old_attendee['start_date']; |
|
| 598 | - $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
| 599 | - $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
| 600 | - // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
| 601 | - // the most important condition should be last, as it will be array_shift'ed off last |
|
| 602 | - $conditions = array( |
|
| 603 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
| 604 | - $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price),// prices match? |
|
| 605 | - $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option),// names match? |
|
| 606 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
| 607 | - ); |
|
| 608 | - $select_and_join_part = "SELECT $tickets_table.TKT_ID FROM $tickets_table INNER JOIN |
|
| 593 | + $old_att_start_date = $old_attendee['start_date']; |
|
| 594 | + $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
| 595 | + $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
| 596 | + // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
| 597 | + // the most important condition should be last, as it will be array_shift'ed off last |
|
| 598 | + $conditions = array( |
|
| 599 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
| 600 | + $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price),// prices match? |
|
| 601 | + $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option),// names match? |
|
| 602 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
| 603 | + ); |
|
| 604 | + $select_and_join_part = "SELECT $tickets_table.TKT_ID FROM $tickets_table INNER JOIN |
|
| 609 | 605 | $datetime_tickets_table ON $tickets_table.TKT_ID = $datetime_tickets_table.TKT_ID INNER JOIN |
| 610 | 606 | $datetime_table ON $datetime_tickets_table.DTT_ID = $datetime_table.DTT_ID"; |
| 611 | - // start running queries, widening search each time by removing a condition |
|
| 612 | - do { |
|
| 613 | - $full_query = $select_and_join_part." WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
|
| 614 | - $ticket_id_found = $wpdb->get_var($full_query); |
|
| 615 | - array_shift($conditions); |
|
| 616 | - } while (! $ticket_id_found && $conditions); |
|
| 617 | - return $ticket_id_found; |
|
| 618 | - } |
|
| 607 | + // start running queries, widening search each time by removing a condition |
|
| 608 | + do { |
|
| 609 | + $full_query = $select_and_join_part." WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
|
| 610 | + $ticket_id_found = $wpdb->get_var($full_query); |
|
| 611 | + array_shift($conditions); |
|
| 612 | + } while (! $ticket_id_found && $conditions); |
|
| 613 | + return $ticket_id_found; |
|
| 614 | + } |
|
| 619 | 615 | |
| 620 | - /** |
|
| 621 | - * If we couldn't find a 4.1 ticket for a 3.1 attendee row, this function creates one; |
|
| 622 | - * and it also tries to find a datetime that works, and a inserts a price, and associates |
|
| 623 | - * the new ticket to that datetime and price. |
|
| 624 | - * @return int ticket id |
|
| 625 | - */ |
|
| 626 | - private function _insert_new_ticket_because_none_found($old_attendee, $new_event_id) |
|
| 627 | - { |
|
| 628 | - global $wpdb; |
|
| 629 | - $old_att_price_option = $old_attendee['price_option']; |
|
| 630 | - $old_att_price = floatval($old_attendee['orig_price']); |
|
| 616 | + /** |
|
| 617 | + * If we couldn't find a 4.1 ticket for a 3.1 attendee row, this function creates one; |
|
| 618 | + * and it also tries to find a datetime that works, and a inserts a price, and associates |
|
| 619 | + * the new ticket to that datetime and price. |
|
| 620 | + * @return int ticket id |
|
| 621 | + */ |
|
| 622 | + private function _insert_new_ticket_because_none_found($old_attendee, $new_event_id) |
|
| 623 | + { |
|
| 624 | + global $wpdb; |
|
| 625 | + $old_att_price_option = $old_attendee['price_option']; |
|
| 626 | + $old_att_price = floatval($old_attendee['orig_price']); |
|
| 631 | 627 | |
| 632 | - $old_att_start_date = $old_attendee['start_date']; |
|
| 633 | - $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
| 634 | - $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"); |
|
| 628 | + $old_att_start_date = $old_attendee['start_date']; |
|
| 629 | + $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
| 630 | + $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"); |
|
| 635 | 631 | |
| 636 | 632 | |
| 637 | - // insert new datetime unless we find one |
|
| 638 | - $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); |
|
| 639 | - if (! $datetime_id) { |
|
| 640 | - $old_att_end_date = $old_attendee['start_date']; |
|
| 641 | - $old_att_end_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
| 642 | - $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"); |
|
| 643 | - $wpdb->insert( |
|
| 644 | - $this->_new_datetime_table, |
|
| 645 | - array( |
|
| 646 | - 'EVT_ID' => $new_event_id, |
|
| 647 | - 'DTT_EVT_start' => $old_att_start_datetime, |
|
| 648 | - 'DTT_EVT_end' => $old_att_end_datetime, |
|
| 649 | - 'DTT_deleted' => true |
|
| 650 | - ), |
|
| 651 | - array( |
|
| 652 | - '%d',// EVT_ID |
|
| 653 | - '%s',// DTT_EVT_start |
|
| 654 | - '%s',// DTT_EVT_end |
|
| 655 | - '%d',// DTT_deleted |
|
| 656 | - ) |
|
| 657 | - ); |
|
| 658 | - $datetime_id = $wpdb->insert_id; |
|
| 659 | - } |
|
| 633 | + // insert new datetime unless we find one |
|
| 634 | + $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); |
|
| 635 | + if (! $datetime_id) { |
|
| 636 | + $old_att_end_date = $old_attendee['start_date']; |
|
| 637 | + $old_att_end_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
| 638 | + $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"); |
|
| 639 | + $wpdb->insert( |
|
| 640 | + $this->_new_datetime_table, |
|
| 641 | + array( |
|
| 642 | + 'EVT_ID' => $new_event_id, |
|
| 643 | + 'DTT_EVT_start' => $old_att_start_datetime, |
|
| 644 | + 'DTT_EVT_end' => $old_att_end_datetime, |
|
| 645 | + 'DTT_deleted' => true |
|
| 646 | + ), |
|
| 647 | + array( |
|
| 648 | + '%d',// EVT_ID |
|
| 649 | + '%s',// DTT_EVT_start |
|
| 650 | + '%s',// DTT_EVT_end |
|
| 651 | + '%d',// DTT_deleted |
|
| 652 | + ) |
|
| 653 | + ); |
|
| 654 | + $datetime_id = $wpdb->insert_id; |
|
| 655 | + } |
|
| 660 | 656 | |
| 661 | - // insert new ticket |
|
| 662 | - $success = $wpdb->insert( |
|
| 663 | - $wpdb->prefix . 'esp_ticket', |
|
| 664 | - array( |
|
| 665 | - 'TKT_name' => $old_att_price_option, |
|
| 666 | - 'TKT_qty' => -1, |
|
| 667 | - 'TKT_price' => $old_att_price, |
|
| 668 | - '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 |
|
| 669 | - 'TKT_end_date' => $old_att_end_datetime, |
|
| 657 | + // insert new ticket |
|
| 658 | + $success = $wpdb->insert( |
|
| 659 | + $wpdb->prefix . 'esp_ticket', |
|
| 660 | + array( |
|
| 661 | + 'TKT_name' => $old_att_price_option, |
|
| 662 | + 'TKT_qty' => -1, |
|
| 663 | + 'TKT_price' => $old_att_price, |
|
| 664 | + '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 |
|
| 665 | + 'TKT_end_date' => $old_att_end_datetime, |
|
| 670 | 666 | |
| 671 | - ), |
|
| 672 | - array( |
|
| 673 | - '%s',// name |
|
| 674 | - '%d',// qty |
|
| 675 | - '%d',// price |
|
| 676 | - '%s',// start_date |
|
| 677 | - '%s',// end_date |
|
| 678 | - ) |
|
| 679 | - ); |
|
| 680 | - $ticket_id = $wpdb->insert_id; |
|
| 681 | - // associate the ticket with the datetime we found earlier |
|
| 682 | - $wpdb->insert( |
|
| 683 | - $this->_new_datetime_ticket_table, |
|
| 684 | - array( |
|
| 685 | - 'DTT_ID' => $datetime_id, |
|
| 686 | - 'TKT_ID' => $ticket_id |
|
| 687 | - ), |
|
| 688 | - array( |
|
| 689 | - '%d',// DTT_ID |
|
| 690 | - '%d',// TKT_ID |
|
| 691 | - ) |
|
| 692 | - ); |
|
| 693 | - // insert new price |
|
| 694 | - $wpdb->insert( |
|
| 695 | - $this->_new_price_table, |
|
| 696 | - array( |
|
| 697 | - 'PRC_amount' => $old_att_price, |
|
| 698 | - 'PRT_ID' => EE_DMS_4_1_0_prices::price_type_base, |
|
| 699 | - 'PRC_name' => $old_att_price_option, |
|
| 700 | - 'PRC_deleted' => true |
|
| 701 | - ), |
|
| 702 | - array( |
|
| 703 | - '%d',// PRC_amount |
|
| 704 | - '%d',// PRT_ID |
|
| 705 | - '%s',// PRC_name |
|
| 706 | - '%d',// PRC_deleted |
|
| 707 | - ) |
|
| 708 | - ); |
|
| 709 | - $price_id = $wpdb->insert_id; |
|
| 710 | - // associate the price to the ticket |
|
| 711 | - $wpdb->insert( |
|
| 712 | - $this->_new_ticket_price_table, |
|
| 713 | - array( |
|
| 714 | - 'TKT_ID' => $ticket_id, |
|
| 715 | - 'PRC_ID' => $price_id |
|
| 716 | - ), |
|
| 717 | - array( |
|
| 718 | - '%d',// TKT_ID |
|
| 719 | - '%d',// PRC_ID |
|
| 720 | - ) |
|
| 721 | - ); |
|
| 722 | - return $ticket_id; |
|
| 723 | - } |
|
| 724 | - /** |
|
| 725 | - * Counts all the registrations on this transaction. If $count_only_older is TRUE then returns the number added SO FAR (ie, |
|
| 726 | - * only considers attendee rows with an ID less than this one's), but if $count_only_older is FALSe returns ALL |
|
| 727 | - * @global type $wpdb |
|
| 728 | - * @param array $old_attendee_row |
|
| 729 | - * @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 |
|
| 730 | - * @return int |
|
| 731 | - */ |
|
| 732 | - private function _sum_old_attendees_on_old_txn($old_attendee_row, $count_only_older = false) |
|
| 733 | - { |
|
| 734 | - global $wpdb; |
|
| 735 | - $count_only_older_sql = $count_only_older ? $wpdb->prepare(" AND id<%d", $old_attendee_row['id']) : ''; |
|
| 736 | - $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']))); |
|
| 667 | + ), |
|
| 668 | + array( |
|
| 669 | + '%s',// name |
|
| 670 | + '%d',// qty |
|
| 671 | + '%d',// price |
|
| 672 | + '%s',// start_date |
|
| 673 | + '%s',// end_date |
|
| 674 | + ) |
|
| 675 | + ); |
|
| 676 | + $ticket_id = $wpdb->insert_id; |
|
| 677 | + // associate the ticket with the datetime we found earlier |
|
| 678 | + $wpdb->insert( |
|
| 679 | + $this->_new_datetime_ticket_table, |
|
| 680 | + array( |
|
| 681 | + 'DTT_ID' => $datetime_id, |
|
| 682 | + 'TKT_ID' => $ticket_id |
|
| 683 | + ), |
|
| 684 | + array( |
|
| 685 | + '%d',// DTT_ID |
|
| 686 | + '%d',// TKT_ID |
|
| 687 | + ) |
|
| 688 | + ); |
|
| 689 | + // insert new price |
|
| 690 | + $wpdb->insert( |
|
| 691 | + $this->_new_price_table, |
|
| 692 | + array( |
|
| 693 | + 'PRC_amount' => $old_att_price, |
|
| 694 | + 'PRT_ID' => EE_DMS_4_1_0_prices::price_type_base, |
|
| 695 | + 'PRC_name' => $old_att_price_option, |
|
| 696 | + 'PRC_deleted' => true |
|
| 697 | + ), |
|
| 698 | + array( |
|
| 699 | + '%d',// PRC_amount |
|
| 700 | + '%d',// PRT_ID |
|
| 701 | + '%s',// PRC_name |
|
| 702 | + '%d',// PRC_deleted |
|
| 703 | + ) |
|
| 704 | + ); |
|
| 705 | + $price_id = $wpdb->insert_id; |
|
| 706 | + // associate the price to the ticket |
|
| 707 | + $wpdb->insert( |
|
| 708 | + $this->_new_ticket_price_table, |
|
| 709 | + array( |
|
| 710 | + 'TKT_ID' => $ticket_id, |
|
| 711 | + 'PRC_ID' => $price_id |
|
| 712 | + ), |
|
| 713 | + array( |
|
| 714 | + '%d',// TKT_ID |
|
| 715 | + '%d',// PRC_ID |
|
| 716 | + ) |
|
| 717 | + ); |
|
| 718 | + return $ticket_id; |
|
| 719 | + } |
|
| 720 | + /** |
|
| 721 | + * Counts all the registrations on this transaction. If $count_only_older is TRUE then returns the number added SO FAR (ie, |
|
| 722 | + * only considers attendee rows with an ID less than this one's), but if $count_only_older is FALSe returns ALL |
|
| 723 | + * @global type $wpdb |
|
| 724 | + * @param array $old_attendee_row |
|
| 725 | + * @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 |
|
| 726 | + * @return int |
|
| 727 | + */ |
|
| 728 | + private function _sum_old_attendees_on_old_txn($old_attendee_row, $count_only_older = false) |
|
| 729 | + { |
|
| 730 | + global $wpdb; |
|
| 731 | + $count_only_older_sql = $count_only_older ? $wpdb->prepare(" AND id<%d", $old_attendee_row['id']) : ''; |
|
| 732 | + $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']))); |
|
| 737 | 733 | |
| 738 | - if ($this->_mer_tables_exist()) { |
|
| 739 | - // if MER exists, then its a little tricky. |
|
| 740 | - // when users registered by adding items to the cart, and it was a |
|
| 741 | - // group registration requiring additional attendee INFO, then the attendee rows |
|
| 742 | - // DO NOT have the same registration_id (although they probably should have) |
|
| 743 | - // they are related just like MER attendee rows are related, through the MER group table |
|
| 744 | - // BUT we want to count all the MER attendee rows for the same registration |
|
| 745 | - $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee_row['registration_id']); |
|
| 734 | + if ($this->_mer_tables_exist()) { |
|
| 735 | + // if MER exists, then its a little tricky. |
|
| 736 | + // when users registered by adding items to the cart, and it was a |
|
| 737 | + // group registration requiring additional attendee INFO, then the attendee rows |
|
| 738 | + // DO NOT have the same registration_id (although they probably should have) |
|
| 739 | + // they are related just like MER attendee rows are related, through the MER group table |
|
| 740 | + // BUT we want to count all the MER attendee rows for the same registration |
|
| 741 | + $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee_row['registration_id']); |
|
| 746 | 742 | |
| 747 | - $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'])); |
|
| 748 | - $count = max($count_using_mer_table, $count); |
|
| 749 | - } |
|
| 750 | - return $count; |
|
| 751 | - } |
|
| 752 | - private function _insert_new_payment($old_attendee, $new_txn_id) |
|
| 753 | - { |
|
| 754 | - global $wpdb; |
|
| 755 | - // only add a payment for primary attendees |
|
| 756 | - $old_pay_stati_indicating_no_payment = array('Pending','Incomplete','Not Completed'); |
|
| 757 | - // if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment... |
|
| 758 | - if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && ! in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) { |
|
| 759 | - $pay_status_mapping = array( |
|
| 760 | - 'Completed'=>'PAP', |
|
| 761 | - 'Payment Declined'=>'PDC', |
|
| 762 | - 'Cancelled'=>'PCN', |
|
| 763 | - 'Declined'=>'PDC' |
|
| 764 | - ); |
|
| 765 | - $by_admin = $old_attendee['payment'] == 'Admin'; |
|
| 766 | - $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 |
|
| 767 | - $cols_n_values = array( |
|
| 768 | - 'TXN_ID'=>$new_txn_id, |
|
| 769 | - 'STS_ID'=>$STS_ID, |
|
| 770 | - 'PAY_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
| 771 | - 'PAY_method'=>'CART', |
|
| 772 | - 'PAY_amount'=>$old_attendee['amount_pd'], |
|
| 773 | - 'PAY_gateway'=>$old_attendee['txn_type'], |
|
| 774 | - 'PAY_gateway_response'=>'', |
|
| 775 | - 'PAY_txn_id_chq_nmbr'=>substr($old_attendee['txn_id'], 0, 32), |
|
| 776 | - 'PAY_via_admin'=>$by_admin, |
|
| 777 | - 'PAY_details'=>$old_attendee['transaction_details'] |
|
| 743 | + $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'])); |
|
| 744 | + $count = max($count_using_mer_table, $count); |
|
| 745 | + } |
|
| 746 | + return $count; |
|
| 747 | + } |
|
| 748 | + private function _insert_new_payment($old_attendee, $new_txn_id) |
|
| 749 | + { |
|
| 750 | + global $wpdb; |
|
| 751 | + // only add a payment for primary attendees |
|
| 752 | + $old_pay_stati_indicating_no_payment = array('Pending','Incomplete','Not Completed'); |
|
| 753 | + // if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment... |
|
| 754 | + if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && ! in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) { |
|
| 755 | + $pay_status_mapping = array( |
|
| 756 | + 'Completed'=>'PAP', |
|
| 757 | + 'Payment Declined'=>'PDC', |
|
| 758 | + 'Cancelled'=>'PCN', |
|
| 759 | + 'Declined'=>'PDC' |
|
| 760 | + ); |
|
| 761 | + $by_admin = $old_attendee['payment'] == 'Admin'; |
|
| 762 | + $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 |
|
| 763 | + $cols_n_values = array( |
|
| 764 | + 'TXN_ID'=>$new_txn_id, |
|
| 765 | + 'STS_ID'=>$STS_ID, |
|
| 766 | + 'PAY_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
| 767 | + 'PAY_method'=>'CART', |
|
| 768 | + 'PAY_amount'=>$old_attendee['amount_pd'], |
|
| 769 | + 'PAY_gateway'=>$old_attendee['txn_type'], |
|
| 770 | + 'PAY_gateway_response'=>'', |
|
| 771 | + 'PAY_txn_id_chq_nmbr'=>substr($old_attendee['txn_id'], 0, 32), |
|
| 772 | + 'PAY_via_admin'=>$by_admin, |
|
| 773 | + 'PAY_details'=>$old_attendee['transaction_details'] |
|
| 778 | 774 | |
| 779 | - ); |
|
| 780 | - $datatypes = array( |
|
| 781 | - '%d',// TXN_Id |
|
| 782 | - '%s',// STS_ID |
|
| 783 | - '%s',// PAY_timestamp |
|
| 784 | - '%s',// PAY_method |
|
| 785 | - '%f',// PAY_amount |
|
| 786 | - '%s',// PAY_gateway |
|
| 787 | - '%s',// PAY_gateway_response |
|
| 788 | - '%s',// PAY_txn_id_chq_nmbr |
|
| 789 | - '%d',// PAY_via_admin |
|
| 790 | - '%s',// PAY_details |
|
| 791 | - ); |
|
| 792 | - $success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes); |
|
| 793 | - if (! $success) { |
|
| 794 | - $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)); |
|
| 795 | - return 0; |
|
| 796 | - } |
|
| 797 | - $new_id = $wpdb->insert_id; |
|
| 798 | - return $new_id; |
|
| 799 | - } else { |
|
| 800 | - return 0; |
|
| 801 | - } |
|
| 802 | - } |
|
| 775 | + ); |
|
| 776 | + $datatypes = array( |
|
| 777 | + '%d',// TXN_Id |
|
| 778 | + '%s',// STS_ID |
|
| 779 | + '%s',// PAY_timestamp |
|
| 780 | + '%s',// PAY_method |
|
| 781 | + '%f',// PAY_amount |
|
| 782 | + '%s',// PAY_gateway |
|
| 783 | + '%s',// PAY_gateway_response |
|
| 784 | + '%s',// PAY_txn_id_chq_nmbr |
|
| 785 | + '%d',// PAY_via_admin |
|
| 786 | + '%s',// PAY_details |
|
| 787 | + ); |
|
| 788 | + $success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes); |
|
| 789 | + if (! $success) { |
|
| 790 | + $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)); |
|
| 791 | + return 0; |
|
| 792 | + } |
|
| 793 | + $new_id = $wpdb->insert_id; |
|
| 794 | + return $new_id; |
|
| 795 | + } else { |
|
| 796 | + return 0; |
|
| 797 | + } |
|
| 798 | + } |
|
| 803 | 799 | |
| 804 | - /** |
|
| 805 | - * If MER is active, if you want ot fin dthe other registrations on that attendee row |
|
| 806 | - * @global type $wpdb |
|
| 807 | - * @param type $old_registration_id |
|
| 808 | - * @return array |
|
| 809 | - */ |
|
| 810 | - private function _find_mer_primary_attendee_using_mer_tables($old_registration_id) |
|
| 811 | - { |
|
| 812 | - if (! $this->_mer_tables_exist()) { |
|
| 813 | - return false; |
|
| 814 | - } |
|
| 815 | - global $wpdb; |
|
| 816 | - $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); |
|
| 817 | - return $old_att_for_primary_reg; |
|
| 818 | - } |
|
| 800 | + /** |
|
| 801 | + * If MER is active, if you want ot fin dthe other registrations on that attendee row |
|
| 802 | + * @global type $wpdb |
|
| 803 | + * @param type $old_registration_id |
|
| 804 | + * @return array |
|
| 805 | + */ |
|
| 806 | + private function _find_mer_primary_attendee_using_mer_tables($old_registration_id) |
|
| 807 | + { |
|
| 808 | + if (! $this->_mer_tables_exist()) { |
|
| 809 | + return false; |
|
| 810 | + } |
|
| 811 | + global $wpdb; |
|
| 812 | + $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); |
|
| 813 | + return $old_att_for_primary_reg; |
|
| 814 | + } |
|
| 819 | 815 | } |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | $this->_pretty_name = __("Attendees", "event_espresso"); |
| 211 | 211 | $this->_old_table = $wpdb->prefix."events_attendee"; |
| 212 | 212 | $this->_extra_where_sql = 'AS att |
| 213 | - INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
|
| 213 | + INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id=e.id |
|
| 214 | 214 | WHERE e.event_status!="D"'; |
| 215 | 215 | $this->_old_mer_table = $wpdb->prefix."events_multi_event_registration_id_group"; |
| 216 | 216 | $this->_new_attendee_cpt_table = $wpdb->posts; |
@@ -232,9 +232,9 @@ discard block |
||
| 232 | 232 | { |
| 233 | 233 | // first check if there's already a new attendee with similar characteristics |
| 234 | 234 | $new_att_id = $this->_find_attendee_cpt_matching($old_row); |
| 235 | - if (! $new_att_id) { |
|
| 235 | + if ( ! $new_att_id) { |
|
| 236 | 236 | $new_att_id = $this->_insert_new_attendee_cpt($old_row); |
| 237 | - if (! $new_att_id) { |
|
| 237 | + if ( ! $new_att_id) { |
|
| 238 | 238 | // if we couldnt even make an attendee, abandon all hope |
| 239 | 239 | return false; |
| 240 | 240 | } |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_cpt_table, $new_att_id); |
| 247 | 247 | |
| 248 | 248 | $txn_id = $this->_insert_new_transaction($old_row); |
| 249 | - if (! $txn_id) { |
|
| 249 | + if ( ! $txn_id) { |
|
| 250 | 250 | // if we couldnt make the transaction, also abandon all hope |
| 251 | 251 | return false; |
| 252 | 252 | } |
@@ -280,31 +280,31 @@ discard block |
||
| 280 | 280 | { |
| 281 | 281 | global $wpdb; |
| 282 | 282 | $cols_n_values = array( |
| 283 | - 'post_title'=>stripslashes($old_attendee['fname']." ".$old_attendee['lname']),// ATT_full_name |
|
| 284 | - 'post_content'=>'',// ATT_bio |
|
| 285 | - 'post_name'=>sanitize_title($old_attendee['fname']."-".$old_attendee['lname']),// ATT_slug |
|
| 286 | - 'post_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_created |
|
| 287 | - 'post_excerpt'=>'',// ATT_short_bio |
|
| 288 | - 'post_modified'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_modified |
|
| 289 | - 'post_author'=>0,// ATT_author |
|
| 290 | - 'post_parent'=>0,// ATT_parent |
|
| 291 | - 'post_type'=>'espresso_attendees',// post_type |
|
| 283 | + 'post_title'=>stripslashes($old_attendee['fname']." ".$old_attendee['lname']), // ATT_full_name |
|
| 284 | + 'post_content'=>'', // ATT_bio |
|
| 285 | + 'post_name'=>sanitize_title($old_attendee['fname']."-".$old_attendee['lname']), // ATT_slug |
|
| 286 | + 'post_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), // ATT_created |
|
| 287 | + 'post_excerpt'=>'', // ATT_short_bio |
|
| 288 | + 'post_modified'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), // ATT_modified |
|
| 289 | + 'post_author'=>0, // ATT_author |
|
| 290 | + 'post_parent'=>0, // ATT_parent |
|
| 291 | + 'post_type'=>'espresso_attendees', // post_type |
|
| 292 | 292 | 'post_status'=>'publish'// status |
| 293 | 293 | ); |
| 294 | 294 | $datatypes = array( |
| 295 | - '%s',// ATT_full_name |
|
| 296 | - '%s',// ATT_bio |
|
| 297 | - '%s',// ATT_slug |
|
| 298 | - '%s',// ATT_created |
|
| 299 | - '%s',// ATT_short_bio |
|
| 300 | - '%s',// ATT_modified |
|
| 301 | - '%d',// ATT_author |
|
| 302 | - '%d',// ATT_parent |
|
| 303 | - '%s',// post_type |
|
| 304 | - '%s',// status |
|
| 295 | + '%s', // ATT_full_name |
|
| 296 | + '%s', // ATT_bio |
|
| 297 | + '%s', // ATT_slug |
|
| 298 | + '%s', // ATT_created |
|
| 299 | + '%s', // ATT_short_bio |
|
| 300 | + '%s', // ATT_modified |
|
| 301 | + '%d', // ATT_author |
|
| 302 | + '%d', // ATT_parent |
|
| 303 | + '%s', // post_type |
|
| 304 | + '%s', // status |
|
| 305 | 305 | ); |
| 306 | 306 | $success = $wpdb->insert($this->_new_attendee_cpt_table, $cols_n_values, $datatypes); |
| 307 | - if (! $success) { |
|
| 307 | + if ( ! $success) { |
|
| 308 | 308 | $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)); |
| 309 | 309 | return 0; |
| 310 | 310 | } |
@@ -342,20 +342,20 @@ discard block |
||
| 342 | 342 | 'ATT_phone'=>stripslashes($old_attendee['phone']), |
| 343 | 343 | ); |
| 344 | 344 | $datatypes = array( |
| 345 | - '%d',// ATT_ID |
|
| 346 | - '%s',// ATT_fname |
|
| 347 | - '%s',// ATT_lname |
|
| 348 | - '%s',// ATT_address |
|
| 349 | - '%s',// ATT_address2 |
|
| 350 | - '%s',// ATT_city |
|
| 351 | - '%d',// STA_ID |
|
| 352 | - '%s',// CNT_ISO |
|
| 353 | - '%s',// ATT_zip |
|
| 354 | - '%s',// ATT_email |
|
| 355 | - '%s',// ATT_phone |
|
| 345 | + '%d', // ATT_ID |
|
| 346 | + '%s', // ATT_fname |
|
| 347 | + '%s', // ATT_lname |
|
| 348 | + '%s', // ATT_address |
|
| 349 | + '%s', // ATT_address2 |
|
| 350 | + '%s', // ATT_city |
|
| 351 | + '%d', // STA_ID |
|
| 352 | + '%s', // CNT_ISO |
|
| 353 | + '%s', // ATT_zip |
|
| 354 | + '%s', // ATT_email |
|
| 355 | + '%s', // ATT_phone |
|
| 356 | 356 | ); |
| 357 | 357 | $success = $wpdb->insert($this->_new_attendee_meta_table, $cols_n_values, $datatypes); |
| 358 | - if (! $success) { |
|
| 358 | + if ( ! $success) { |
|
| 359 | 359 | $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)); |
| 360 | 360 | return 0; |
| 361 | 361 | } |
@@ -380,12 +380,12 @@ discard block |
||
| 380 | 380 | $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($old_attendee['id']), $this->_new_transaction_table); |
| 381 | 381 | } else { // non-primary attendee, so find its primary attendee's transaction |
| 382 | 382 | $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'])); |
| 383 | - if (! $primary_attendee_old_id) { |
|
| 383 | + if ( ! $primary_attendee_old_id) { |
|
| 384 | 384 | $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee['registration_id']); |
| 385 | 385 | $primary_attendee_old_id = is_array($primary_attendee) ? $primary_attendee['id'] : null; |
| 386 | 386 | } |
| 387 | 387 | $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($primary_attendee_old_id), $this->_new_transaction_table); |
| 388 | - if (! $txn_id) { |
|
| 388 | + if ( ! $txn_id) { |
|
| 389 | 389 | $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)); |
| 390 | 390 | $txn_id = 0; |
| 391 | 391 | } |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | // if there isn't yet a transaction row for this, create one |
| 394 | 394 | // (so even if it was a non-primary attendee with no EE3 primary attendee, |
| 395 | 395 | // it ought to have SOME transaction, so we'll make one) |
| 396 | - if (! $txn_id) { |
|
| 396 | + if ( ! $txn_id) { |
|
| 397 | 397 | // maps 3.1 payment stati onto 4.1 transaction stati |
| 398 | 398 | $txn_status_mapping = array( |
| 399 | 399 | 'Completed'=>'TCM', |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | 'Cancelled'=>'TIN', |
| 405 | 405 | 'Declined'=>'TIN' |
| 406 | 406 | ); |
| 407 | - $STS_ID = isset($txn_status_mapping[ $old_attendee['payment_status'] ]) ? $txn_status_mapping[ $old_attendee['payment_status'] ] : 'TIN'; |
|
| 407 | + $STS_ID = isset($txn_status_mapping[$old_attendee['payment_status']]) ? $txn_status_mapping[$old_attendee['payment_status']] : 'TIN'; |
|
| 408 | 408 | $cols_n_values = array( |
| 409 | 409 | 'TXN_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
| 410 | 410 | 'TXN_total'=>floatval($old_attendee['total_cost']), |
@@ -413,14 +413,14 @@ discard block |
||
| 413 | 413 | 'TXN_hash_salt'=>$old_attendee['hashSalt'] |
| 414 | 414 | ); |
| 415 | 415 | $datatypes = array( |
| 416 | - '%s',// TXN_timestamp |
|
| 417 | - '%f',// TXN_total |
|
| 418 | - '%f',// TXN_paid |
|
| 419 | - '%s',// STS_ID |
|
| 420 | - '%s',// TXN_hash_salt |
|
| 416 | + '%s', // TXN_timestamp |
|
| 417 | + '%f', // TXN_total |
|
| 418 | + '%f', // TXN_paid |
|
| 419 | + '%s', // STS_ID |
|
| 420 | + '%s', // TXN_hash_salt |
|
| 421 | 421 | ); |
| 422 | 422 | $success = $wpdb->insert($this->_new_transaction_table, $cols_n_values, $datatypes); |
| 423 | - if (! $success) { |
|
| 423 | + if ( ! $success) { |
|
| 424 | 424 | $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)); |
| 425 | 425 | return 0; |
| 426 | 426 | } |
@@ -480,12 +480,12 @@ discard block |
||
| 480 | 480 | |
| 481 | 481 | $STS_ID = $this->_get_reg_status_for_old_payment_status($old_attendee); |
| 482 | 482 | $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix.'events_detail', $old_attendee['event_id'], $wpdb->posts); |
| 483 | - if (! $new_event_id) { |
|
| 483 | + if ( ! $new_event_id) { |
|
| 484 | 484 | $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))); |
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | $ticket_id = $this->_try_to_find_new_ticket_id($old_attendee, $new_event_id); |
| 488 | - if (! $ticket_id) { |
|
| 488 | + if ( ! $ticket_id) { |
|
| 489 | 489 | $ticket_id = $this->_insert_new_ticket_because_none_found($old_attendee, $new_event_id); |
| 490 | 490 | $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)); |
| 491 | 491 | } |
@@ -516,23 +516,23 @@ discard block |
||
| 516 | 516 | 'REG_deleted'=>false |
| 517 | 517 | ); |
| 518 | 518 | $datatypes = array( |
| 519 | - '%d',// EVT_ID |
|
| 520 | - '%d',// ATT_ID |
|
| 521 | - '%d',// TXN_ID |
|
| 522 | - '%d',// TKT_ID |
|
| 523 | - '%s',// STS_ID |
|
| 524 | - '%s',// REG_date |
|
| 525 | - '%f',// REG_final_price |
|
| 526 | - '%s',// REG_session |
|
| 527 | - '%s',// REG_code |
|
| 528 | - '%s',// REG_url_link |
|
| 529 | - '%d',// REG_count |
|
| 530 | - '%d',// REG_group_size |
|
| 531 | - '%d',// REG_att_is_going |
|
| 532 | - '%d',// REG_deleted |
|
| 519 | + '%d', // EVT_ID |
|
| 520 | + '%d', // ATT_ID |
|
| 521 | + '%d', // TXN_ID |
|
| 522 | + '%d', // TKT_ID |
|
| 523 | + '%s', // STS_ID |
|
| 524 | + '%s', // REG_date |
|
| 525 | + '%f', // REG_final_price |
|
| 526 | + '%s', // REG_session |
|
| 527 | + '%s', // REG_code |
|
| 528 | + '%s', // REG_url_link |
|
| 529 | + '%d', // REG_count |
|
| 530 | + '%d', // REG_group_size |
|
| 531 | + '%d', // REG_att_is_going |
|
| 532 | + '%d', // REG_deleted |
|
| 533 | 533 | ); |
| 534 | 534 | $success = $wpdb->insert($this->_new_reg_table, $cols_n_values, $datatypes); |
| 535 | - if (! $success) { |
|
| 535 | + if ( ! $success) { |
|
| 536 | 536 | $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)); |
| 537 | 537 | return 0; |
| 538 | 538 | } |
@@ -564,11 +564,11 @@ discard block |
||
| 564 | 564 | $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)); |
| 565 | 565 | if ($success) { |
| 566 | 566 | // get the ticket's datetimes, and increment them too |
| 567 | - $success_update_dateimtes = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT |
|
| 567 | + $success_update_dateimtes = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT |
|
| 568 | 568 | INNER JOIN {$this->_new_ticket_datetime_table} as DTK ON TKT.TKT_ID = DTK.TKT_ID |
| 569 | 569 | INNER JOIN {$this->_new_datetime_table} as DTT ON DTK.DTT_ID = DTT.DTT_ID |
| 570 | 570 | SET DTT.DTT_sold = DTT.DTT_sold + %d WHERE TKT.TKT_ID = %d", $quantity_sold, $new_ticket_id)); |
| 571 | - if (! $success_update_dateimtes) { |
|
| 571 | + if ( ! $success_update_dateimtes) { |
|
| 572 | 572 | $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)); |
| 573 | 573 | } |
| 574 | 574 | } else { |
@@ -600,10 +600,10 @@ discard block |
||
| 600 | 600 | // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
| 601 | 601 | // the most important condition should be last, as it will be array_shift'ed off last |
| 602 | 602 | $conditions = array( |
| 603 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
| 604 | - $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price),// prices match? |
|
| 605 | - $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option),// names match? |
|
| 606 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
| 603 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime), // times match? |
|
| 604 | + $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price), // prices match? |
|
| 605 | + $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option), // names match? |
|
| 606 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id), // events match? |
|
| 607 | 607 | ); |
| 608 | 608 | $select_and_join_part = "SELECT $tickets_table.TKT_ID FROM $tickets_table INNER JOIN |
| 609 | 609 | $datetime_tickets_table ON $tickets_table.TKT_ID = $datetime_tickets_table.TKT_ID INNER JOIN |
@@ -613,7 +613,7 @@ discard block |
||
| 613 | 613 | $full_query = $select_and_join_part." WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
| 614 | 614 | $ticket_id_found = $wpdb->get_var($full_query); |
| 615 | 615 | array_shift($conditions); |
| 616 | - } while (! $ticket_id_found && $conditions); |
|
| 616 | + }while ( ! $ticket_id_found && $conditions); |
|
| 617 | 617 | return $ticket_id_found; |
| 618 | 618 | } |
| 619 | 619 | |
@@ -635,8 +635,8 @@ discard block |
||
| 635 | 635 | |
| 636 | 636 | |
| 637 | 637 | // insert new datetime unless we find one |
| 638 | - $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); |
|
| 639 | - if (! $datetime_id) { |
|
| 638 | + $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); |
|
| 639 | + if ( ! $datetime_id) { |
|
| 640 | 640 | $old_att_end_date = $old_attendee['start_date']; |
| 641 | 641 | $old_att_end_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
| 642 | 642 | $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,10 +649,10 @@ discard block |
||
| 649 | 649 | 'DTT_deleted' => true |
| 650 | 650 | ), |
| 651 | 651 | array( |
| 652 | - '%d',// EVT_ID |
|
| 653 | - '%s',// DTT_EVT_start |
|
| 654 | - '%s',// DTT_EVT_end |
|
| 655 | - '%d',// DTT_deleted |
|
| 652 | + '%d', // EVT_ID |
|
| 653 | + '%s', // DTT_EVT_start |
|
| 654 | + '%s', // DTT_EVT_end |
|
| 655 | + '%d', // DTT_deleted |
|
| 656 | 656 | ) |
| 657 | 657 | ); |
| 658 | 658 | $datetime_id = $wpdb->insert_id; |
@@ -660,21 +660,21 @@ discard block |
||
| 660 | 660 | |
| 661 | 661 | // insert new ticket |
| 662 | 662 | $success = $wpdb->insert( |
| 663 | - $wpdb->prefix . 'esp_ticket', |
|
| 663 | + $wpdb->prefix.'esp_ticket', |
|
| 664 | 664 | array( |
| 665 | 665 | 'TKT_name' => $old_att_price_option, |
| 666 | 666 | 'TKT_qty' => -1, |
| 667 | 667 | 'TKT_price' => $old_att_price, |
| 668 | - '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 |
|
| 668 | + '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 |
|
| 669 | 669 | 'TKT_end_date' => $old_att_end_datetime, |
| 670 | 670 | |
| 671 | 671 | ), |
| 672 | 672 | array( |
| 673 | - '%s',// name |
|
| 674 | - '%d',// qty |
|
| 675 | - '%d',// price |
|
| 676 | - '%s',// start_date |
|
| 677 | - '%s',// end_date |
|
| 673 | + '%s', // name |
|
| 674 | + '%d', // qty |
|
| 675 | + '%d', // price |
|
| 676 | + '%s', // start_date |
|
| 677 | + '%s', // end_date |
|
| 678 | 678 | ) |
| 679 | 679 | ); |
| 680 | 680 | $ticket_id = $wpdb->insert_id; |
@@ -686,8 +686,8 @@ discard block |
||
| 686 | 686 | 'TKT_ID' => $ticket_id |
| 687 | 687 | ), |
| 688 | 688 | array( |
| 689 | - '%d',// DTT_ID |
|
| 690 | - '%d',// TKT_ID |
|
| 689 | + '%d', // DTT_ID |
|
| 690 | + '%d', // TKT_ID |
|
| 691 | 691 | ) |
| 692 | 692 | ); |
| 693 | 693 | // insert new price |
@@ -700,10 +700,10 @@ discard block |
||
| 700 | 700 | 'PRC_deleted' => true |
| 701 | 701 | ), |
| 702 | 702 | array( |
| 703 | - '%d',// PRC_amount |
|
| 704 | - '%d',// PRT_ID |
|
| 705 | - '%s',// PRC_name |
|
| 706 | - '%d',// PRC_deleted |
|
| 703 | + '%d', // PRC_amount |
|
| 704 | + '%d', // PRT_ID |
|
| 705 | + '%s', // PRC_name |
|
| 706 | + '%d', // PRC_deleted |
|
| 707 | 707 | ) |
| 708 | 708 | ); |
| 709 | 709 | $price_id = $wpdb->insert_id; |
@@ -715,8 +715,8 @@ discard block |
||
| 715 | 715 | 'PRC_ID' => $price_id |
| 716 | 716 | ), |
| 717 | 717 | array( |
| 718 | - '%d',// TKT_ID |
|
| 719 | - '%d',// PRC_ID |
|
| 718 | + '%d', // TKT_ID |
|
| 719 | + '%d', // PRC_ID |
|
| 720 | 720 | ) |
| 721 | 721 | ); |
| 722 | 722 | return $ticket_id; |
@@ -753,7 +753,7 @@ discard block |
||
| 753 | 753 | { |
| 754 | 754 | global $wpdb; |
| 755 | 755 | // only add a payment for primary attendees |
| 756 | - $old_pay_stati_indicating_no_payment = array('Pending','Incomplete','Not Completed'); |
|
| 756 | + $old_pay_stati_indicating_no_payment = array('Pending', 'Incomplete', 'Not Completed'); |
|
| 757 | 757 | // if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment... |
| 758 | 758 | if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && ! in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) { |
| 759 | 759 | $pay_status_mapping = array( |
@@ -763,7 +763,7 @@ discard block |
||
| 763 | 763 | 'Declined'=>'PDC' |
| 764 | 764 | ); |
| 765 | 765 | $by_admin = $old_attendee['payment'] == 'Admin'; |
| 766 | - $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 |
|
| 766 | + $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 |
|
| 767 | 767 | $cols_n_values = array( |
| 768 | 768 | 'TXN_ID'=>$new_txn_id, |
| 769 | 769 | 'STS_ID'=>$STS_ID, |
@@ -778,19 +778,19 @@ discard block |
||
| 778 | 778 | |
| 779 | 779 | ); |
| 780 | 780 | $datatypes = array( |
| 781 | - '%d',// TXN_Id |
|
| 782 | - '%s',// STS_ID |
|
| 783 | - '%s',// PAY_timestamp |
|
| 784 | - '%s',// PAY_method |
|
| 785 | - '%f',// PAY_amount |
|
| 786 | - '%s',// PAY_gateway |
|
| 787 | - '%s',// PAY_gateway_response |
|
| 788 | - '%s',// PAY_txn_id_chq_nmbr |
|
| 789 | - '%d',// PAY_via_admin |
|
| 790 | - '%s',// PAY_details |
|
| 781 | + '%d', // TXN_Id |
|
| 782 | + '%s', // STS_ID |
|
| 783 | + '%s', // PAY_timestamp |
|
| 784 | + '%s', // PAY_method |
|
| 785 | + '%f', // PAY_amount |
|
| 786 | + '%s', // PAY_gateway |
|
| 787 | + '%s', // PAY_gateway_response |
|
| 788 | + '%s', // PAY_txn_id_chq_nmbr |
|
| 789 | + '%d', // PAY_via_admin |
|
| 790 | + '%s', // PAY_details |
|
| 791 | 791 | ); |
| 792 | 792 | $success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes); |
| 793 | - if (! $success) { |
|
| 793 | + if ( ! $success) { |
|
| 794 | 794 | $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)); |
| 795 | 795 | return 0; |
| 796 | 796 | } |
@@ -809,7 +809,7 @@ discard block |
||
| 809 | 809 | */ |
| 810 | 810 | private function _find_mer_primary_attendee_using_mer_tables($old_registration_id) |
| 811 | 811 | { |
| 812 | - if (! $this->_mer_tables_exist()) { |
|
| 812 | + if ( ! $this->_mer_tables_exist()) { |
|
| 813 | 813 | return false; |
| 814 | 814 | } |
| 815 | 815 | global $wpdb; |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * (because we know the attendee was for an event as a specific time, and we know |
| 86 | 86 | * the event's OLD ID...) |
| 87 | 87 | * @global type $wpdb |
| 88 | - * @param array $old_attendee_row |
|
| 88 | + * @param array $old_attendee |
|
| 89 | 89 | * @return array row of datetime from DB |
| 90 | 90 | */ |
| 91 | 91 | private function _try_to_find_datetime($old_attendee) |
@@ -121,8 +121,7 @@ discard block |
||
| 121 | 121 | /** |
| 122 | 122 | * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap |
| 123 | 123 | * @param int $new_reg_id |
| 124 | - * @param int $new_datetime_id |
|
| 125 | - * @param string $timestamp mysql datetime |
|
| 124 | + * @param int $new_datetime |
|
| 126 | 125 | * @return int new Check-in id |
| 127 | 126 | */ |
| 128 | 127 | private function _insert_checkin_record($new_reg_id, $new_datetime) |
@@ -26,159 +26,159 @@ |
||
| 26 | 26 | |
| 27 | 27 | class EE_DMS_4_1_0_checkins extends EE_Data_Migration_Script_Stage_Table |
| 28 | 28 | { |
| 29 | - private $_new_table; |
|
| 30 | - public function __construct() |
|
| 31 | - { |
|
| 32 | - global $wpdb; |
|
| 33 | - $this->_pretty_name = esc_html__('Checkins', 'event_espresso'); |
|
| 34 | - $this->_old_table = $wpdb->prefix."events_attendee"; |
|
| 35 | - $this->_extra_where_sql = 'AS att |
|
| 29 | + private $_new_table; |
|
| 30 | + public function __construct() |
|
| 31 | + { |
|
| 32 | + global $wpdb; |
|
| 33 | + $this->_pretty_name = esc_html__('Checkins', 'event_espresso'); |
|
| 34 | + $this->_old_table = $wpdb->prefix."events_attendee"; |
|
| 35 | + $this->_extra_where_sql = 'AS att |
|
| 36 | 36 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
| 37 | 37 | WHERE e.event_status!="D"'; |
| 38 | - $this->_new_table = $wpdb->prefix."esp_checkin"; |
|
| 39 | - parent::__construct(); |
|
| 40 | - } |
|
| 41 | - protected function _migrate_old_row($old_row) |
|
| 42 | - { |
|
| 43 | - global $wpdb; |
|
| 44 | - $new_reg_table = $wpdb->prefix."esp_registration"; |
|
| 38 | + $this->_new_table = $wpdb->prefix."esp_checkin"; |
|
| 39 | + parent::__construct(); |
|
| 40 | + } |
|
| 41 | + protected function _migrate_old_row($old_row) |
|
| 42 | + { |
|
| 43 | + global $wpdb; |
|
| 44 | + $new_reg_table = $wpdb->prefix."esp_registration"; |
|
| 45 | 45 | |
| 46 | - $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ; |
|
| 46 | + $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ; |
|
| 47 | 47 | |
| 48 | - $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
|
| 49 | - if (! $new_registrations_for_attendee) { |
|
| 50 | - $new_registrations_for_attendee = array(); |
|
| 51 | - } |
|
| 52 | - $new_datetime = $this->_try_to_find_datetime($old_row); |
|
| 48 | + $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
|
| 49 | + if (! $new_registrations_for_attendee) { |
|
| 50 | + $new_registrations_for_attendee = array(); |
|
| 51 | + } |
|
| 52 | + $new_datetime = $this->_try_to_find_datetime($old_row); |
|
| 53 | 53 | |
| 54 | - // make sure registrations array is numerically indexed starting at 0 (it probably already is) |
|
| 55 | - $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
|
| 56 | - $new_checkin_ids = array(); |
|
| 57 | - for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) { |
|
| 58 | - $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
| 59 | - if (! $new_reg_id) { |
|
| 60 | - $this->add_error(sprintf( |
|
| 61 | - esc_html__( |
|
| 62 | - /* translators: %1$s database row represented in JSON, %2$s number of registrations to check-in |
|
| 54 | + // make sure registrations array is numerically indexed starting at 0 (it probably already is) |
|
| 55 | + $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
|
| 56 | + $new_checkin_ids = array(); |
|
| 57 | + for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) { |
|
| 58 | + $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
| 59 | + if (! $new_reg_id) { |
|
| 60 | + $this->add_error(sprintf( |
|
| 61 | + esc_html__( |
|
| 62 | + /* translators: %1$s database row represented in JSON, %2$s number of registrations to check-in |
|
| 63 | 63 | * %3$s number of registrations for the attendee, %4$s new registration rows represented in JSON |
| 64 | 64 | */ |
| 65 | - // @codingStandardsIgnoreStart |
|
| 66 | - 'It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)', |
|
| 67 | - // @codingStandardsIgnoreEnd |
|
| 68 | - 'event_espresso' |
|
| 69 | - ), |
|
| 70 | - $this->_json_encode($old_row), |
|
| 71 | - abs($num_to_checkin_at_this_time), |
|
| 72 | - count($new_registrations_for_attendee), |
|
| 73 | - $this->_json_encode($new_registrations_for_attendee) |
|
| 74 | - )); |
|
| 75 | - break; |
|
| 76 | - } |
|
| 77 | - $existing_checkin_record = $wpdb->get_var( |
|
| 78 | - $wpdb->prepare( |
|
| 79 | - "SELECT CHK_ID FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", |
|
| 80 | - $new_reg_id |
|
| 81 | - ) |
|
| 82 | - ); |
|
| 83 | - if (! $existing_checkin_record) { |
|
| 84 | - $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
|
| 85 | - if ($new_id) { |
|
| 86 | - $new_checkin_ids[]= $new_id; |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - if ($new_checkin_ids) { |
|
| 91 | - $this->get_migration_script()->set_mapping( |
|
| 92 | - $this->_old_table, |
|
| 93 | - $old_row['id'], |
|
| 94 | - $this->_new_table, |
|
| 95 | - $new_checkin_ids |
|
| 96 | - ); |
|
| 97 | - } |
|
| 98 | - } |
|
| 65 | + // @codingStandardsIgnoreStart |
|
| 66 | + 'It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)', |
|
| 67 | + // @codingStandardsIgnoreEnd |
|
| 68 | + 'event_espresso' |
|
| 69 | + ), |
|
| 70 | + $this->_json_encode($old_row), |
|
| 71 | + abs($num_to_checkin_at_this_time), |
|
| 72 | + count($new_registrations_for_attendee), |
|
| 73 | + $this->_json_encode($new_registrations_for_attendee) |
|
| 74 | + )); |
|
| 75 | + break; |
|
| 76 | + } |
|
| 77 | + $existing_checkin_record = $wpdb->get_var( |
|
| 78 | + $wpdb->prepare( |
|
| 79 | + "SELECT CHK_ID FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", |
|
| 80 | + $new_reg_id |
|
| 81 | + ) |
|
| 82 | + ); |
|
| 83 | + if (! $existing_checkin_record) { |
|
| 84 | + $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
|
| 85 | + if ($new_id) { |
|
| 86 | + $new_checkin_ids[]= $new_id; |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + if ($new_checkin_ids) { |
|
| 91 | + $this->get_migration_script()->set_mapping( |
|
| 92 | + $this->_old_table, |
|
| 93 | + $old_row['id'], |
|
| 94 | + $this->_new_table, |
|
| 95 | + $new_checkin_ids |
|
| 96 | + ); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Tries to find the new datetime the Check-in was for, based on the attendee row |
|
| 103 | - * (because we know the attendee was for an event as a specific time, and we know |
|
| 104 | - * the event's OLD ID...) |
|
| 105 | - * @global type $wpdb |
|
| 106 | - * @param array $old_attendee_row |
|
| 107 | - * @return array row of datetime from DB |
|
| 108 | - */ |
|
| 109 | - private function _try_to_find_datetime($old_attendee) |
|
| 110 | - { |
|
| 111 | - global $wpdb; |
|
| 101 | + /** |
|
| 102 | + * Tries to find the new datetime the Check-in was for, based on the attendee row |
|
| 103 | + * (because we know the attendee was for an event as a specific time, and we know |
|
| 104 | + * the event's OLD ID...) |
|
| 105 | + * @global type $wpdb |
|
| 106 | + * @param array $old_attendee_row |
|
| 107 | + * @return array row of datetime from DB |
|
| 108 | + */ |
|
| 109 | + private function _try_to_find_datetime($old_attendee) |
|
| 110 | + { |
|
| 111 | + global $wpdb; |
|
| 112 | 112 | |
| 113 | - $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts); |
|
| 114 | - if (! $new_event_id) { |
|
| 115 | - $this->add_error( |
|
| 116 | - sprintf( |
|
| 117 | - esc_html__( |
|
| 118 | - /* translators: 1: original event ID, 2: original attendee database row */ |
|
| 119 | - // @codingStandardsIgnoreStart |
|
| 120 | - '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', |
|
| 121 | - // @codingStandardsIgnoreEnd |
|
| 122 | - 'event_espresso' |
|
| 123 | - ), |
|
| 124 | - $old_attendee['event_id'], |
|
| 125 | - $this->_json_encode($old_attendee) |
|
| 126 | - ) |
|
| 127 | - ); |
|
| 128 | - return 0; |
|
| 129 | - } |
|
| 130 | - $old_att_start_date = $old_attendee['start_date']; |
|
| 131 | - $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
| 132 | - $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
| 113 | + $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts); |
|
| 114 | + if (! $new_event_id) { |
|
| 115 | + $this->add_error( |
|
| 116 | + sprintf( |
|
| 117 | + esc_html__( |
|
| 118 | + /* translators: 1: original event ID, 2: original attendee database row */ |
|
| 119 | + // @codingStandardsIgnoreStart |
|
| 120 | + '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', |
|
| 121 | + // @codingStandardsIgnoreEnd |
|
| 122 | + 'event_espresso' |
|
| 123 | + ), |
|
| 124 | + $old_attendee['event_id'], |
|
| 125 | + $this->_json_encode($old_attendee) |
|
| 126 | + ) |
|
| 127 | + ); |
|
| 128 | + return 0; |
|
| 129 | + } |
|
| 130 | + $old_att_start_date = $old_attendee['start_date']; |
|
| 131 | + $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
| 132 | + $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
| 133 | 133 | |
| 134 | - $datetime_table = $wpdb->prefix."esp_datetime"; |
|
| 135 | - // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
| 136 | - // the most important condition should be last, as it will be array_shift'ed off last |
|
| 137 | - $conditions = array( |
|
| 138 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
| 139 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
| 140 | - ); |
|
| 141 | - // start running queries, widening search each time by removing a condition |
|
| 142 | - $datetime_found = null; |
|
| 143 | - do { |
|
| 144 | - $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
|
| 145 | - $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
|
| 146 | - array_shift($conditions); |
|
| 147 | - } while (! $datetime_found && $conditions); |
|
| 148 | - return $datetime_found; |
|
| 149 | - } |
|
| 134 | + $datetime_table = $wpdb->prefix."esp_datetime"; |
|
| 135 | + // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
| 136 | + // the most important condition should be last, as it will be array_shift'ed off last |
|
| 137 | + $conditions = array( |
|
| 138 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
| 139 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
| 140 | + ); |
|
| 141 | + // start running queries, widening search each time by removing a condition |
|
| 142 | + $datetime_found = null; |
|
| 143 | + do { |
|
| 144 | + $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
|
| 145 | + $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
|
| 146 | + array_shift($conditions); |
|
| 147 | + } while (! $datetime_found && $conditions); |
|
| 148 | + return $datetime_found; |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap |
|
| 153 | - * @param int $new_reg_id |
|
| 154 | - * @param int $new_datetime_id |
|
| 155 | - * @param string $timestamp mysql datetime |
|
| 156 | - * @return int new Check-in id |
|
| 157 | - */ |
|
| 158 | - private function _insert_checkin_record($new_reg_id, $new_datetime) |
|
| 159 | - { |
|
| 160 | - global $wpdb; |
|
| 151 | + /** |
|
| 152 | + * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap |
|
| 153 | + * @param int $new_reg_id |
|
| 154 | + * @param int $new_datetime_id |
|
| 155 | + * @param string $timestamp mysql datetime |
|
| 156 | + * @return int new Check-in id |
|
| 157 | + */ |
|
| 158 | + private function _insert_checkin_record($new_reg_id, $new_datetime) |
|
| 159 | + { |
|
| 160 | + global $wpdb; |
|
| 161 | 161 | |
| 162 | 162 | |
| 163 | - // ok we can actually do what we set out to do: add a checkin/checkout record |
|
| 164 | - $cols_n_values = array( |
|
| 165 | - 'REG_ID'=>$new_reg_id, |
|
| 166 | - 'DTT_ID'=>$new_datetime['DTT_ID'], |
|
| 167 | - 'CHK_in'=>true, |
|
| 168 | - 'CHK_timestamp'=>$new_datetime['DTT_EVT_start'] |
|
| 169 | - ); |
|
| 170 | - $datatypes = array( |
|
| 171 | - '%d',// REG_ID |
|
| 172 | - '%d',// DTT_ID |
|
| 173 | - '%d',// CHK_in |
|
| 174 | - '%s',// CHK_timestamp |
|
| 175 | - ); |
|
| 176 | - $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
| 177 | - if (! $success) { |
|
| 178 | - $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)); |
|
| 179 | - return 0; |
|
| 180 | - } |
|
| 181 | - $new_id = $wpdb->insert_id; |
|
| 182 | - return $new_id; |
|
| 183 | - } |
|
| 163 | + // ok we can actually do what we set out to do: add a checkin/checkout record |
|
| 164 | + $cols_n_values = array( |
|
| 165 | + 'REG_ID'=>$new_reg_id, |
|
| 166 | + 'DTT_ID'=>$new_datetime['DTT_ID'], |
|
| 167 | + 'CHK_in'=>true, |
|
| 168 | + 'CHK_timestamp'=>$new_datetime['DTT_EVT_start'] |
|
| 169 | + ); |
|
| 170 | + $datatypes = array( |
|
| 171 | + '%d',// REG_ID |
|
| 172 | + '%d',// DTT_ID |
|
| 173 | + '%d',// CHK_in |
|
| 174 | + '%s',// CHK_timestamp |
|
| 175 | + ); |
|
| 176 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
| 177 | + if (! $success) { |
|
| 178 | + $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)); |
|
| 179 | + return 0; |
|
| 180 | + } |
|
| 181 | + $new_id = $wpdb->insert_id; |
|
| 182 | + return $new_id; |
|
| 183 | + } |
|
| 184 | 184 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | $this->_pretty_name = esc_html__('Checkins', 'event_espresso'); |
| 34 | 34 | $this->_old_table = $wpdb->prefix."events_attendee"; |
| 35 | 35 | $this->_extra_where_sql = 'AS att |
| 36 | - INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
|
| 36 | + INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id=e.id |
|
| 37 | 37 | WHERE e.event_status!="D"'; |
| 38 | 38 | $this->_new_table = $wpdb->prefix."esp_checkin"; |
| 39 | 39 | parent::__construct(); |
@@ -43,10 +43,10 @@ discard block |
||
| 43 | 43 | global $wpdb; |
| 44 | 44 | $new_reg_table = $wpdb->prefix."esp_registration"; |
| 45 | 45 | |
| 46 | - $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ; |
|
| 46 | + $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']), intval($old_row['checked_in']))); |
|
| 47 | 47 | |
| 48 | 48 | $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
| 49 | - if (! $new_registrations_for_attendee) { |
|
| 49 | + if ( ! $new_registrations_for_attendee) { |
|
| 50 | 50 | $new_registrations_for_attendee = array(); |
| 51 | 51 | } |
| 52 | 52 | $new_datetime = $this->_try_to_find_datetime($old_row); |
@@ -54,9 +54,9 @@ discard block |
||
| 54 | 54 | // make sure registrations array is numerically indexed starting at 0 (it probably already is) |
| 55 | 55 | $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
| 56 | 56 | $new_checkin_ids = array(); |
| 57 | - for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) { |
|
| 58 | - $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
| 59 | - if (! $new_reg_id) { |
|
| 57 | + for ($i = 0; $i < abs($num_to_checkin_at_this_time); $i++) { |
|
| 58 | + $new_reg_id = $new_registrations_for_attendee[$i]; |
|
| 59 | + if ( ! $new_reg_id) { |
|
| 60 | 60 | $this->add_error(sprintf( |
| 61 | 61 | esc_html__( |
| 62 | 62 | /* translators: %1$s database row represented in JSON, %2$s number of registrations to check-in |
@@ -80,10 +80,10 @@ discard block |
||
| 80 | 80 | $new_reg_id |
| 81 | 81 | ) |
| 82 | 82 | ); |
| 83 | - if (! $existing_checkin_record) { |
|
| 83 | + if ( ! $existing_checkin_record) { |
|
| 84 | 84 | $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
| 85 | 85 | if ($new_id) { |
| 86 | - $new_checkin_ids[]= $new_id; |
|
| 86 | + $new_checkin_ids[] = $new_id; |
|
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | } |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | global $wpdb; |
| 112 | 112 | |
| 113 | 113 | $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts); |
| 114 | - if (! $new_event_id) { |
|
| 114 | + if ( ! $new_event_id) { |
|
| 115 | 115 | $this->add_error( |
| 116 | 116 | sprintf( |
| 117 | 117 | esc_html__( |
@@ -135,8 +135,8 @@ discard block |
||
| 135 | 135 | // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
| 136 | 136 | // the most important condition should be last, as it will be array_shift'ed off last |
| 137 | 137 | $conditions = array( |
| 138 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
| 139 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
| 138 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime), // times match? |
|
| 139 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id), // events match? |
|
| 140 | 140 | ); |
| 141 | 141 | // start running queries, widening search each time by removing a condition |
| 142 | 142 | $datetime_found = null; |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
| 145 | 145 | $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
| 146 | 146 | array_shift($conditions); |
| 147 | - } while (! $datetime_found && $conditions); |
|
| 147 | + }while ( ! $datetime_found && $conditions); |
|
| 148 | 148 | return $datetime_found; |
| 149 | 149 | } |
| 150 | 150 | |
@@ -168,13 +168,13 @@ discard block |
||
| 168 | 168 | 'CHK_timestamp'=>$new_datetime['DTT_EVT_start'] |
| 169 | 169 | ); |
| 170 | 170 | $datatypes = array( |
| 171 | - '%d',// REG_ID |
|
| 172 | - '%d',// DTT_ID |
|
| 173 | - '%d',// CHK_in |
|
| 174 | - '%s',// CHK_timestamp |
|
| 171 | + '%d', // REG_ID |
|
| 172 | + '%d', // DTT_ID |
|
| 173 | + '%d', // CHK_in |
|
| 174 | + '%s', // CHK_timestamp |
|
| 175 | 175 | ); |
| 176 | 176 | $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
| 177 | - if (! $success) { |
|
| 177 | + if ( ! $success) { |
|
| 178 | 178 | $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)); |
| 179 | 179 | return 0; |
| 180 | 180 | } |
@@ -98,6 +98,9 @@ |
||
| 98 | 98 | $this->get_migration_script()->set_mapping($this->_old_table, $old_event['id'], $this->_new_table, $new_event_question_group_ids); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | + /** |
|
| 102 | + * @param boolean $primary |
|
| 103 | + */ |
|
| 101 | 104 | private function _insert_event_question_group($old_event, $old_question_group_id, $primary) |
| 102 | 105 | { |
| 103 | 106 | global $wpdb; |
@@ -101,14 +101,14 @@ discard block |
||
| 101 | 101 | private function _insert_event_question_group($old_event, $old_question_group_id, $primary) |
| 102 | 102 | { |
| 103 | 103 | global $wpdb; |
| 104 | - $new_question_group_id =$this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_qst_group", intval($old_question_group_id), $wpdb->prefix."esp_question_group"); |
|
| 104 | + $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_qst_group", intval($old_question_group_id), $wpdb->prefix."esp_question_group"); |
|
| 105 | 105 | |
| 106 | - if (! $new_question_group_id) { |
|
| 106 | + if ( ! $new_question_group_id) { |
|
| 107 | 107 | $this->add_error(sprintf(__("Could not find 4.1 question ID for 3.1 question id #%s on event $%s", "event_espresso"), $old_question_group_id, $old_event['id'])); |
| 108 | 108 | return 0; |
| 109 | 109 | } |
| 110 | 110 | $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", intval($old_event['id']), $wpdb->posts); |
| 111 | - if (! $new_question_group_id) { |
|
| 111 | + if ( ! $new_question_group_id) { |
|
| 112 | 112 | $this->add_error(sprintf(__("Could not find 4.1 event 3.1 event id #%s", "event_espresso"), $old_event['id'])); |
| 113 | 113 | return 0; |
| 114 | 114 | } |
@@ -118,12 +118,12 @@ discard block |
||
| 118 | 118 | 'EQG_primary'=>$primary |
| 119 | 119 | ); |
| 120 | 120 | $datatypes = array( |
| 121 | - '%d',// EVT_ID |
|
| 122 | - '%d',// QSG_ID |
|
| 123 | - '%d',// EQG_primary |
|
| 121 | + '%d', // EVT_ID |
|
| 122 | + '%d', // QSG_ID |
|
| 123 | + '%d', // EQG_primary |
|
| 124 | 124 | ); |
| 125 | 125 | $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
| 126 | - if (! $success) { |
|
| 126 | + if ( ! $success) { |
|
| 127 | 127 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_table, $cols_n_values, $datatypes)); |
| 128 | 128 | return 0; |
| 129 | 129 | } |
@@ -16,15 +16,13 @@ discard block |
||
| 16 | 16 | 'EQG_primary'=>new EE_Boolean_Field('EQG_primary', __('Flag indicating question is only for primary attendees','event_espresso'), false, false) |
| 17 | 17 | ) |
| 18 | 18 | ); |
| 19 | - |
|
| 20 | - |
|
| 21 | 19 | * |
| 22 | 20 | */ |
| 23 | 21 | class EE_DMS_4_1_0_event_question_group extends EE_Data_Migration_Script_Stage_Table |
| 24 | 22 | { |
| 25 | - private $_new_table; |
|
| 26 | - public function _migrate_old_row($old_row) |
|
| 27 | - { |
|
| 23 | + private $_new_table; |
|
| 24 | + public function _migrate_old_row($old_row) |
|
| 25 | + { |
|
| 28 | 26 | // $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $this->_new_transaction_table); |
| 29 | 27 | // if ( ! $txn_id ){ |
| 30 | 28 | // $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))); |
@@ -34,8 +32,8 @@ discard block |
||
| 34 | 32 | // $new_line_items = $this->_insert_new_line_items($txn,$old_row); |
| 35 | 33 | // $this->get_migration_script()->set_mapping($this->_old_table,$old_row['id'],$this->_new_line_table,$new_line_items); |
| 36 | 34 | |
| 37 | - $this->_insert_new_event_question_groups($old_row); |
|
| 38 | - } |
|
| 35 | + $this->_insert_new_event_question_groups($old_row); |
|
| 36 | + } |
|
| 39 | 37 | // function _migration_step($num_items=50){ |
| 40 | 38 | // global $wpdb; |
| 41 | 39 | // $start_at_record = $this->count_records_migrated(); |
@@ -55,79 +53,79 @@ discard block |
||
| 55 | 53 | // $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table); |
| 56 | 54 | // return $count; |
| 57 | 55 | // } |
| 58 | - public function __construct() |
|
| 59 | - { |
|
| 60 | - global $wpdb; |
|
| 61 | - $this->_old_table = $wpdb->prefix."events_detail"; |
|
| 62 | - $this->_extra_where_sql = 'WHERE event_status!="D"'; |
|
| 63 | - $this->_new_table = $wpdb->prefix."esp_event_question_group"; |
|
| 64 | - $this->_pretty_name = __("Question Groups in each Event", "event_espresso"); |
|
| 65 | - parent::__construct(); |
|
| 66 | - } |
|
| 56 | + public function __construct() |
|
| 57 | + { |
|
| 58 | + global $wpdb; |
|
| 59 | + $this->_old_table = $wpdb->prefix."events_detail"; |
|
| 60 | + $this->_extra_where_sql = 'WHERE event_status!="D"'; |
|
| 61 | + $this->_new_table = $wpdb->prefix."esp_event_question_group"; |
|
| 62 | + $this->_pretty_name = __("Question Groups in each Event", "event_espresso"); |
|
| 63 | + parent::__construct(); |
|
| 64 | + } |
|
| 67 | 65 | |
| 68 | - /** |
|
| 69 | - * Attempts to insert a new question group inthe new format given an old one |
|
| 70 | - * @global type $wpdb |
|
| 71 | - * @param array $old_event |
|
| 72 | - * @return void |
|
| 73 | - */ |
|
| 74 | - private function _insert_new_event_question_groups($old_event) |
|
| 75 | - { |
|
| 76 | - $new_event_question_group_ids = array(); |
|
| 77 | - $question_groups_for_primary = maybe_unserialize($old_event['question_groups']); |
|
| 78 | - if (is_array($question_groups_for_primary)) { |
|
| 79 | - foreach ($question_groups_for_primary as $old_question_group_id) { |
|
| 80 | - $new_id = $this->_insert_event_question_group($old_event, $old_question_group_id, true); |
|
| 81 | - if ($new_id) { |
|
| 82 | - $new_event_question_group_ids[] = $new_id; |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - $event_meta = maybe_unserialize($old_event['event_meta']); |
|
| 87 | - if (isset($event_meta['add_attendee_question_groups'])) { |
|
| 88 | - if (is_array($event_meta['add_attendee_question_groups'])) { |
|
| 89 | - foreach ($event_meta['add_attendee_question_groups'] as $old_question_group_id) { |
|
| 90 | - $new_id = $this->_insert_event_question_group($old_event, $old_question_group_id, false); |
|
| 91 | - if ($new_id) { |
|
| 92 | - $new_event_question_group_ids[] = $new_id; |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - } |
|
| 66 | + /** |
|
| 67 | + * Attempts to insert a new question group inthe new format given an old one |
|
| 68 | + * @global type $wpdb |
|
| 69 | + * @param array $old_event |
|
| 70 | + * @return void |
|
| 71 | + */ |
|
| 72 | + private function _insert_new_event_question_groups($old_event) |
|
| 73 | + { |
|
| 74 | + $new_event_question_group_ids = array(); |
|
| 75 | + $question_groups_for_primary = maybe_unserialize($old_event['question_groups']); |
|
| 76 | + if (is_array($question_groups_for_primary)) { |
|
| 77 | + foreach ($question_groups_for_primary as $old_question_group_id) { |
|
| 78 | + $new_id = $this->_insert_event_question_group($old_event, $old_question_group_id, true); |
|
| 79 | + if ($new_id) { |
|
| 80 | + $new_event_question_group_ids[] = $new_id; |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + $event_meta = maybe_unserialize($old_event['event_meta']); |
|
| 85 | + if (isset($event_meta['add_attendee_question_groups'])) { |
|
| 86 | + if (is_array($event_meta['add_attendee_question_groups'])) { |
|
| 87 | + foreach ($event_meta['add_attendee_question_groups'] as $old_question_group_id) { |
|
| 88 | + $new_id = $this->_insert_event_question_group($old_event, $old_question_group_id, false); |
|
| 89 | + if ($new_id) { |
|
| 90 | + $new_event_question_group_ids[] = $new_id; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + } |
|
| 97 | 95 | |
| 98 | 96 | |
| 99 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_event['id'], $this->_new_table, $new_event_question_group_ids); |
|
| 100 | - } |
|
| 97 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_event['id'], $this->_new_table, $new_event_question_group_ids); |
|
| 98 | + } |
|
| 101 | 99 | |
| 102 | - private function _insert_event_question_group($old_event, $old_question_group_id, $primary) |
|
| 103 | - { |
|
| 104 | - global $wpdb; |
|
| 105 | - $new_question_group_id =$this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_qst_group", intval($old_question_group_id), $wpdb->prefix."esp_question_group"); |
|
| 100 | + private function _insert_event_question_group($old_event, $old_question_group_id, $primary) |
|
| 101 | + { |
|
| 102 | + global $wpdb; |
|
| 103 | + $new_question_group_id =$this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_qst_group", intval($old_question_group_id), $wpdb->prefix."esp_question_group"); |
|
| 106 | 104 | |
| 107 | - if (! $new_question_group_id) { |
|
| 108 | - $this->add_error(sprintf(__("Could not find 4.1 question ID for 3.1 question id #%s on event $%s", "event_espresso"), $old_question_group_id, $old_event['id'])); |
|
| 109 | - return 0; |
|
| 110 | - } |
|
| 111 | - $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", intval($old_event['id']), $wpdb->posts); |
|
| 112 | - if (! $new_question_group_id) { |
|
| 113 | - $this->add_error(sprintf(__("Could not find 4.1 event 3.1 event id #%s", "event_espresso"), $old_event['id'])); |
|
| 114 | - return 0; |
|
| 115 | - } |
|
| 116 | - $cols_n_values = array( |
|
| 117 | - 'EVT_ID'=>$new_event_id, |
|
| 118 | - 'QSG_ID'=>$new_question_group_id, |
|
| 119 | - 'EQG_primary'=>$primary |
|
| 120 | - ); |
|
| 121 | - $datatypes = array( |
|
| 122 | - '%d',// EVT_ID |
|
| 123 | - '%d',// QSG_ID |
|
| 124 | - '%d',// EQG_primary |
|
| 125 | - ); |
|
| 126 | - $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
| 127 | - if (! $success) { |
|
| 128 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_table, $cols_n_values, $datatypes)); |
|
| 129 | - return 0; |
|
| 130 | - } |
|
| 131 | - return $wpdb->insert_id; |
|
| 132 | - } |
|
| 105 | + if (! $new_question_group_id) { |
|
| 106 | + $this->add_error(sprintf(__("Could not find 4.1 question ID for 3.1 question id #%s on event $%s", "event_espresso"), $old_question_group_id, $old_event['id'])); |
|
| 107 | + return 0; |
|
| 108 | + } |
|
| 109 | + $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", intval($old_event['id']), $wpdb->posts); |
|
| 110 | + if (! $new_question_group_id) { |
|
| 111 | + $this->add_error(sprintf(__("Could not find 4.1 event 3.1 event id #%s", "event_espresso"), $old_event['id'])); |
|
| 112 | + return 0; |
|
| 113 | + } |
|
| 114 | + $cols_n_values = array( |
|
| 115 | + 'EVT_ID'=>$new_event_id, |
|
| 116 | + 'QSG_ID'=>$new_question_group_id, |
|
| 117 | + 'EQG_primary'=>$primary |
|
| 118 | + ); |
|
| 119 | + $datatypes = array( |
|
| 120 | + '%d',// EVT_ID |
|
| 121 | + '%d',// QSG_ID |
|
| 122 | + '%d',// EQG_primary |
|
| 123 | + ); |
|
| 124 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
| 125 | + if (! $success) { |
|
| 126 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_table, $cols_n_values, $datatypes)); |
|
| 127 | + return 0; |
|
| 128 | + } |
|
| 129 | + return $wpdb->insert_id; |
|
| 130 | + } |
|
| 133 | 131 | } |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | |
| 427 | 427 | /** |
| 428 | 428 | * @param $old_event |
| 429 | - * @param $new_cpt_id |
|
| 429 | + * @param integer $new_cpt_id |
|
| 430 | 430 | * @return int |
| 431 | 431 | */ |
| 432 | 432 | private function _insert_event_meta($old_event, $new_cpt_id) |
@@ -693,8 +693,8 @@ discard block |
||
| 693 | 693 | |
| 694 | 694 | |
| 695 | 695 | /** |
| 696 | - * @param $new_event_id |
|
| 697 | - * @param $new_venue_id |
|
| 696 | + * @param integer $new_event_id |
|
| 697 | + * @param integer $new_venue_id |
|
| 698 | 698 | * @return int |
| 699 | 699 | */ |
| 700 | 700 | private function _insert_new_venue_to_event($new_event_id, $new_venue_id) |
@@ -84,8 +84,6 @@ discard block |
||
| 84 | 84 | KEY `submitted` (`submitted`), |
| 85 | 85 | KEY `likes` (`likes`) |
| 86 | 86 | ) ENGINE=InnoDB AUTO_INCREMENT=63 DEFAULT CHARSET=utf8$$ |
| 87 | - |
|
| 88 | - |
|
| 89 | 87 | * |
| 90 | 88 | * 4.1 Event model: |
| 91 | 89 | * $this->_tables = array( |
@@ -124,7 +122,6 @@ discard block |
||
| 124 | 122 | 'EVT_donations'=>new EE_Boolean_Field('EVT_donations', __("Accept Donations?", "event_espresso"), false, false) |
| 125 | 123 | |
| 126 | 124 | )); |
| 127 | - |
|
| 128 | 125 | * |
| 129 | 126 | * 3.1's start end table |
| 130 | 127 | * |
@@ -137,8 +134,6 @@ discard block |
||
| 137 | 134 | PRIMARY KEY (`id`), |
| 138 | 135 | KEY `event_id` (`event_id`) |
| 139 | 136 | ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8$$ |
| 140 | - |
|
| 141 | - |
|
| 142 | 137 | * |
| 143 | 138 | * and 4.1 Datetime model's tables and fields: |
| 144 | 139 | * $this->_tables = array( |
@@ -160,172 +155,172 @@ discard block |
||
| 160 | 155 | */ |
| 161 | 156 | class EE_DMS_4_1_0_events extends EE_Data_Migration_Script_Stage |
| 162 | 157 | { |
| 163 | - private $_old_table; |
|
| 164 | - private $_old_start_end_table; |
|
| 165 | - private $_new_table; |
|
| 166 | - private $_new_meta_table; |
|
| 167 | - private $_new_datetime_table; |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Just initializes the status of the migration |
|
| 173 | - * @throws EE_Error |
|
| 174 | - */ |
|
| 175 | - public function __construct() |
|
| 176 | - { |
|
| 177 | - global $wpdb; |
|
| 178 | - $this->_old_table = $wpdb->prefix."events_detail"; |
|
| 179 | - $this->_old_start_end_table = $wpdb->prefix."events_start_end"; |
|
| 180 | - $this->_new_table = $wpdb->prefix."posts"; |
|
| 181 | - $this->_new_meta_table = $wpdb->prefix."esp_event_meta"; |
|
| 182 | - $this->_new_datetime_table = $wpdb->prefix."esp_datetime"; |
|
| 183 | - $this->_pretty_name = __("Events", "event_espresso"); |
|
| 184 | - parent::__construct(); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Counts the records to migrate; the public version may cache it |
|
| 191 | - * @return int |
|
| 192 | - */ |
|
| 193 | - public function _count_records_to_migrate() |
|
| 194 | - { |
|
| 195 | - global $wpdb; |
|
| 196 | - $count = $wpdb->get_var("SELECT COUNT(*) FROM ".$this->_old_table . ' WHERE event_status !="D"'); |
|
| 197 | - return intval($count); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property accordingly. |
|
| 204 | - * Note: it should not alter the count of items migrated. That is done in the public function that calls this. |
|
| 205 | - * IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the last migration step, otherwise it |
|
| 206 | - * should always return $num_items_to_migrate. (Eg, if we're migrating attendees rows from the database, and $num_items_to_migrate is set to 50, |
|
| 207 | - * then we SHOULD actually migrate 50 rows,but at very least we MUST report/return 50 items migrated) |
|
| 208 | - * @param int $num_items_to_migrate |
|
| 209 | - * @return int number of items ACTUALLY migrated |
|
| 210 | - */ |
|
| 211 | - protected function _migration_step($num_items_to_migrate = 50) |
|
| 212 | - { |
|
| 213 | - global $wpdb; |
|
| 214 | - // because the migration of each event can be a LOT more work, make each step smaller |
|
| 215 | - $num_items_to_migrate = max(1, $num_items_to_migrate/5); |
|
| 216 | - $events = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table WHERE event_status!='D' LIMIT %d,%d", $this->count_records_migrated(), $num_items_to_migrate), ARRAY_A); |
|
| 217 | - $items_migrated_this_step = 0; |
|
| 218 | - |
|
| 219 | - foreach ($events as $event_row) { |
|
| 220 | - $guid = null; |
|
| 221 | - // insert new 4.1 Attendee object using $wpdb |
|
| 222 | - $post_id = $this->_insert_cpt($event_row); |
|
| 223 | - if ($post_id) { |
|
| 224 | - $this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_table, $post_id); |
|
| 225 | - $meta_id = $this->_insert_event_meta($event_row, $post_id); |
|
| 226 | - if ($meta_id) { |
|
| 227 | - $this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_meta_table, $meta_id); |
|
| 228 | - } |
|
| 229 | - $this->_convert_start_end_times($event_row, $post_id); |
|
| 230 | - $event_meta = maybe_unserialize($event_row['event_meta']); |
|
| 231 | - $guid = isset($event_meta['event_thumbnail_url']) ? $event_meta['event_thumbnail_url'] : null; |
|
| 232 | - $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $post_id, $this); |
|
| 233 | - |
|
| 234 | - // maybe create a venue from info on the event? |
|
| 235 | - $new_venue_id = $this->_maybe_create_venue($event_row); |
|
| 236 | - if ($new_venue_id) { |
|
| 237 | - $this->_insert_new_venue_to_event($post_id, $new_venue_id); |
|
| 238 | - } |
|
| 239 | - $this->_add_post_metas($event_row, $post_id); |
|
| 240 | - } |
|
| 241 | - $items_migrated_this_step++; |
|
| 242 | - if ($guid) { |
|
| 243 | - // if we had to check for an image attachment |
|
| 244 | - // then let's call it a day (avoid timing out, because this took a long time) |
|
| 245 | - break; |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - if ($this->count_records_migrated() + $items_migrated_this_step >= $this->count_records_to_migrate()) { |
|
| 249 | - $this->set_status(EE_Data_Migration_Manager::status_completed); |
|
| 250 | - } |
|
| 251 | - return $items_migrated_this_step; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Stores any extra 3.1 "event_meta" column things as post meta |
|
| 256 | - * @param array $old_event |
|
| 257 | - * @param int $post_id |
|
| 258 | - * @return void |
|
| 259 | - */ |
|
| 260 | - private function _add_post_metas($old_event, $post_id) |
|
| 261 | - { |
|
| 262 | - $event_meta = maybe_unserialize($old_event['event_meta']); |
|
| 263 | - if (! $event_meta || ! is_array($event_meta)) { |
|
| 264 | - return; |
|
| 265 | - } |
|
| 266 | - unset($event_meta['date_submitted']);// factored into CPT |
|
| 267 | - unset($event_meta['additional_attendee_reg_info']);// factored into event meta table |
|
| 268 | - unset($event_meta['default_payment_status']);// dido |
|
| 269 | - unset($event_meta['event_thumbnail_url']);// used to find post featured image |
|
| 270 | - foreach ($event_meta as $meta_key => $meta_value) { |
|
| 271 | - if ($meta_key) {// if the meta key is just an empty string, ignore it |
|
| 272 | - $success = add_post_meta($post_id, $meta_key, $meta_value, true); |
|
| 273 | - if (! $success) { |
|
| 274 | - $this->add_error(sprintf(__("Could not add post meta for CPT with ID #%d. Meta key: '%s',meta value:'%d' for 3.1 event: %s", "event_espresso"), $post_id, $meta_key, $meta_value, implode(",", $old_event))); |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - if ($old_event['alt_email']) { |
|
| 279 | - add_post_meta($post_id, 'alt_email', $old_event['alt_email']); |
|
| 280 | - } |
|
| 281 | - if ($old_event['recurrence_id']) { |
|
| 282 | - add_post_meta($post_id, 'recurrence_id', $old_event['recurrence_id']); |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * Finds a unique slug for this event, given its name (we could have simply used |
|
| 290 | - * the old unique_identifier column, but it added a long string of seemingly random characters onto the end |
|
| 291 | - * and really wasn't that pretty for a slug, so we decided we'd make our own slug again) |
|
| 292 | - * @param string $event_name (the name of the event for reading by humans) |
|
| 293 | - * @param string $old_identifier the old EE3 identifier (a long unique string) |
|
| 294 | - * @param string $new_post_status a post status |
|
| 295 | - * @return string |
|
| 296 | - */ |
|
| 297 | - private function _find_unique_slug($event_name, $old_identifier = '', $new_post_status = 'publish') |
|
| 298 | - { |
|
| 299 | - $count = 0; |
|
| 300 | - $original_name = $event_name ? sanitize_title($event_name) : $old_identifier; |
|
| 301 | - return wp_unique_post_slug($original_name, 0, $new_post_status, 'espresso_events', 0); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * returns whether or not there is a post that has this same slug (post_title) |
|
| 306 | - * @global wpdb $wpdb |
|
| 307 | - * @param string $slug |
|
| 308 | - * @return boolean |
|
| 309 | - */ |
|
| 310 | - private function _other_post_exists_with_that_slug($slug) |
|
| 311 | - { |
|
| 312 | - global $wpdb; |
|
| 313 | - $query = $wpdb->prepare("SELECT COUNT(ID) FROM {$this->_new_table} WHERE event_status != 'D' AND post_name = %s", $slug); |
|
| 314 | - $count = $wpdb->get_var($query); |
|
| 315 | - return (boolean) intval($count); |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * @param $old_event |
|
| 322 | - * @return int |
|
| 323 | - */ |
|
| 324 | - private function _insert_cpt($old_event) |
|
| 325 | - { |
|
| 326 | - global $wpdb; |
|
| 327 | - // convert 3.1 event status to 4.1 CPT status |
|
| 328 | - // for reference, 3.1 event stati available for setting are: |
|
| 158 | + private $_old_table; |
|
| 159 | + private $_old_start_end_table; |
|
| 160 | + private $_new_table; |
|
| 161 | + private $_new_meta_table; |
|
| 162 | + private $_new_datetime_table; |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Just initializes the status of the migration |
|
| 168 | + * @throws EE_Error |
|
| 169 | + */ |
|
| 170 | + public function __construct() |
|
| 171 | + { |
|
| 172 | + global $wpdb; |
|
| 173 | + $this->_old_table = $wpdb->prefix."events_detail"; |
|
| 174 | + $this->_old_start_end_table = $wpdb->prefix."events_start_end"; |
|
| 175 | + $this->_new_table = $wpdb->prefix."posts"; |
|
| 176 | + $this->_new_meta_table = $wpdb->prefix."esp_event_meta"; |
|
| 177 | + $this->_new_datetime_table = $wpdb->prefix."esp_datetime"; |
|
| 178 | + $this->_pretty_name = __("Events", "event_espresso"); |
|
| 179 | + parent::__construct(); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * Counts the records to migrate; the public version may cache it |
|
| 186 | + * @return int |
|
| 187 | + */ |
|
| 188 | + public function _count_records_to_migrate() |
|
| 189 | + { |
|
| 190 | + global $wpdb; |
|
| 191 | + $count = $wpdb->get_var("SELECT COUNT(*) FROM ".$this->_old_table . ' WHERE event_status !="D"'); |
|
| 192 | + return intval($count); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property accordingly. |
|
| 199 | + * Note: it should not alter the count of items migrated. That is done in the public function that calls this. |
|
| 200 | + * IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the last migration step, otherwise it |
|
| 201 | + * should always return $num_items_to_migrate. (Eg, if we're migrating attendees rows from the database, and $num_items_to_migrate is set to 50, |
|
| 202 | + * then we SHOULD actually migrate 50 rows,but at very least we MUST report/return 50 items migrated) |
|
| 203 | + * @param int $num_items_to_migrate |
|
| 204 | + * @return int number of items ACTUALLY migrated |
|
| 205 | + */ |
|
| 206 | + protected function _migration_step($num_items_to_migrate = 50) |
|
| 207 | + { |
|
| 208 | + global $wpdb; |
|
| 209 | + // because the migration of each event can be a LOT more work, make each step smaller |
|
| 210 | + $num_items_to_migrate = max(1, $num_items_to_migrate/5); |
|
| 211 | + $events = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table WHERE event_status!='D' LIMIT %d,%d", $this->count_records_migrated(), $num_items_to_migrate), ARRAY_A); |
|
| 212 | + $items_migrated_this_step = 0; |
|
| 213 | + |
|
| 214 | + foreach ($events as $event_row) { |
|
| 215 | + $guid = null; |
|
| 216 | + // insert new 4.1 Attendee object using $wpdb |
|
| 217 | + $post_id = $this->_insert_cpt($event_row); |
|
| 218 | + if ($post_id) { |
|
| 219 | + $this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_table, $post_id); |
|
| 220 | + $meta_id = $this->_insert_event_meta($event_row, $post_id); |
|
| 221 | + if ($meta_id) { |
|
| 222 | + $this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_meta_table, $meta_id); |
|
| 223 | + } |
|
| 224 | + $this->_convert_start_end_times($event_row, $post_id); |
|
| 225 | + $event_meta = maybe_unserialize($event_row['event_meta']); |
|
| 226 | + $guid = isset($event_meta['event_thumbnail_url']) ? $event_meta['event_thumbnail_url'] : null; |
|
| 227 | + $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $post_id, $this); |
|
| 228 | + |
|
| 229 | + // maybe create a venue from info on the event? |
|
| 230 | + $new_venue_id = $this->_maybe_create_venue($event_row); |
|
| 231 | + if ($new_venue_id) { |
|
| 232 | + $this->_insert_new_venue_to_event($post_id, $new_venue_id); |
|
| 233 | + } |
|
| 234 | + $this->_add_post_metas($event_row, $post_id); |
|
| 235 | + } |
|
| 236 | + $items_migrated_this_step++; |
|
| 237 | + if ($guid) { |
|
| 238 | + // if we had to check for an image attachment |
|
| 239 | + // then let's call it a day (avoid timing out, because this took a long time) |
|
| 240 | + break; |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + if ($this->count_records_migrated() + $items_migrated_this_step >= $this->count_records_to_migrate()) { |
|
| 244 | + $this->set_status(EE_Data_Migration_Manager::status_completed); |
|
| 245 | + } |
|
| 246 | + return $items_migrated_this_step; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Stores any extra 3.1 "event_meta" column things as post meta |
|
| 251 | + * @param array $old_event |
|
| 252 | + * @param int $post_id |
|
| 253 | + * @return void |
|
| 254 | + */ |
|
| 255 | + private function _add_post_metas($old_event, $post_id) |
|
| 256 | + { |
|
| 257 | + $event_meta = maybe_unserialize($old_event['event_meta']); |
|
| 258 | + if (! $event_meta || ! is_array($event_meta)) { |
|
| 259 | + return; |
|
| 260 | + } |
|
| 261 | + unset($event_meta['date_submitted']);// factored into CPT |
|
| 262 | + unset($event_meta['additional_attendee_reg_info']);// factored into event meta table |
|
| 263 | + unset($event_meta['default_payment_status']);// dido |
|
| 264 | + unset($event_meta['event_thumbnail_url']);// used to find post featured image |
|
| 265 | + foreach ($event_meta as $meta_key => $meta_value) { |
|
| 266 | + if ($meta_key) {// if the meta key is just an empty string, ignore it |
|
| 267 | + $success = add_post_meta($post_id, $meta_key, $meta_value, true); |
|
| 268 | + if (! $success) { |
|
| 269 | + $this->add_error(sprintf(__("Could not add post meta for CPT with ID #%d. Meta key: '%s',meta value:'%d' for 3.1 event: %s", "event_espresso"), $post_id, $meta_key, $meta_value, implode(",", $old_event))); |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + if ($old_event['alt_email']) { |
|
| 274 | + add_post_meta($post_id, 'alt_email', $old_event['alt_email']); |
|
| 275 | + } |
|
| 276 | + if ($old_event['recurrence_id']) { |
|
| 277 | + add_post_meta($post_id, 'recurrence_id', $old_event['recurrence_id']); |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * Finds a unique slug for this event, given its name (we could have simply used |
|
| 285 | + * the old unique_identifier column, but it added a long string of seemingly random characters onto the end |
|
| 286 | + * and really wasn't that pretty for a slug, so we decided we'd make our own slug again) |
|
| 287 | + * @param string $event_name (the name of the event for reading by humans) |
|
| 288 | + * @param string $old_identifier the old EE3 identifier (a long unique string) |
|
| 289 | + * @param string $new_post_status a post status |
|
| 290 | + * @return string |
|
| 291 | + */ |
|
| 292 | + private function _find_unique_slug($event_name, $old_identifier = '', $new_post_status = 'publish') |
|
| 293 | + { |
|
| 294 | + $count = 0; |
|
| 295 | + $original_name = $event_name ? sanitize_title($event_name) : $old_identifier; |
|
| 296 | + return wp_unique_post_slug($original_name, 0, $new_post_status, 'espresso_events', 0); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * returns whether or not there is a post that has this same slug (post_title) |
|
| 301 | + * @global wpdb $wpdb |
|
| 302 | + * @param string $slug |
|
| 303 | + * @return boolean |
|
| 304 | + */ |
|
| 305 | + private function _other_post_exists_with_that_slug($slug) |
|
| 306 | + { |
|
| 307 | + global $wpdb; |
|
| 308 | + $query = $wpdb->prepare("SELECT COUNT(ID) FROM {$this->_new_table} WHERE event_status != 'D' AND post_name = %s", $slug); |
|
| 309 | + $count = $wpdb->get_var($query); |
|
| 310 | + return (boolean) intval($count); |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * @param $old_event |
|
| 317 | + * @return int |
|
| 318 | + */ |
|
| 319 | + private function _insert_cpt($old_event) |
|
| 320 | + { |
|
| 321 | + global $wpdb; |
|
| 322 | + // convert 3.1 event status to 4.1 CPT status |
|
| 323 | + // for reference, 3.1 event stati available for setting are: |
|
| 329 | 324 | // $status = array(array('id' => 'A', 'text' => __('Public', 'event_espresso')), array('id' => 'S', 'text' => __('Waitlist', 'event_espresso')), array('id' => 'O', 'text' => __('Ongoing', 'event_espresso')), array('id' => 'R', 'text' => __('Draft', 'event_espresso')), array('id' => 'D', 'text' => __('Deleted', 'event_espresso'))); |
| 330 | 325 | // and the json api uses the following to convert from 3.1 to 4.0 |
| 331 | 326 | // 'S'=>'secondary/waitlist', |
@@ -339,486 +334,486 @@ discard block |
||
| 339 | 334 | // 4.1 Event Post stati are the normal post statis |
| 340 | 335 | // (publish,future,draft,pending,private,trash,auto-draft,inherit) |
| 341 | 336 | // and 3 custom ones: cancelled,postponed,sold_out |
| 342 | - $status_conversions = array( |
|
| 343 | - 'R'=>'draft', |
|
| 344 | - 'X'=>'draft',// 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved |
|
| 345 | - 'P'=>'pending', |
|
| 346 | - 'IA'=>'draft',// draft and in the past |
|
| 337 | + $status_conversions = array( |
|
| 338 | + 'R'=>'draft', |
|
| 339 | + 'X'=>'draft',// 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved |
|
| 340 | + 'P'=>'pending', |
|
| 341 | + 'IA'=>'draft',// draft and in the past |
|
| 347 | 342 | // IA=inactive in 3.1: events were switched to this when they expired. in 4.1 that's just calculated |
| 348 | - 'O'=>'publish',// @todo: will be an event type later; if this is the status, set the end date WAAAY later; and add term for 'ongoing' |
|
| 349 | - 'A'=>'publish', |
|
| 350 | - 'S'=>'draft',// @todo: is it ok to just mark secondary/waitlist events as DRAFTS? |
|
| 351 | - 'D'=>'trash', |
|
| 352 | - ); |
|
| 353 | - $post_status = $status_conversions[ $old_event['event_status'] ]; |
|
| 354 | - // check if we've sold out |
|
| 355 | - if (intval($old_event['reg_limit']) <= self::count_registrations($old_event['id'])) { |
|
| 356 | - $post_status = 'sold_out'; |
|
| 357 | - } |
|
| 343 | + 'O'=>'publish',// @todo: will be an event type later; if this is the status, set the end date WAAAY later; and add term for 'ongoing' |
|
| 344 | + 'A'=>'publish', |
|
| 345 | + 'S'=>'draft',// @todo: is it ok to just mark secondary/waitlist events as DRAFTS? |
|
| 346 | + 'D'=>'trash', |
|
| 347 | + ); |
|
| 348 | + $post_status = $status_conversions[ $old_event['event_status'] ]; |
|
| 349 | + // check if we've sold out |
|
| 350 | + if (intval($old_event['reg_limit']) <= self::count_registrations($old_event['id'])) { |
|
| 351 | + $post_status = 'sold_out'; |
|
| 352 | + } |
|
| 358 | 353 | // FYI postponed and cancelled don't exist in 3.1 |
| 359 | - $cols_n_values = array( |
|
| 360 | - 'post_title'=>stripslashes($old_event['event_name']),// EVT_name |
|
| 361 | - 'post_content'=>stripslashes($old_event['event_desc']),// EVT_desc |
|
| 362 | - 'post_name'=>$this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status),// EVT_slug |
|
| 363 | - 'post_date'=>$old_event['submitted'],// EVT_created NOT |
|
| 364 | - 'post_date_gmt'=>get_gmt_from_date($old_event['submitted']), |
|
| 365 | - 'post_excerpt'=>'',// EVT_short_desc |
|
| 366 | - 'post_modified'=>$old_event['submitted'],// EVT_modified |
|
| 367 | - 'post_modified_gmt'=>get_gmt_from_date($old_event['submitted']), |
|
| 368 | - 'post_author'=>$old_event['wp_user'],// EVT_wp_user |
|
| 369 | - 'post_parent'=>0,// parent maybe get this from some REM field? |
|
| 370 | - 'menu_order'=>0,// EVT_order |
|
| 371 | - 'post_type'=>'espresso_events',// post_type |
|
| 372 | - 'post_status'=>$post_status,// status |
|
| 373 | - ); |
|
| 374 | - $cols_n_values_with_no_invalid_text = array(); |
|
| 375 | - foreach ($cols_n_values as $col => $value) { |
|
| 376 | - $value_sans_invalid_chars = $wpdb->strip_invalid_text_for_column($this->_new_table, $col, $value); |
|
| 377 | - if (! is_wp_error($value_sans_invalid_chars)) { |
|
| 378 | - $cols_n_values_with_no_invalid_text[ $col ] = $value_sans_invalid_chars; |
|
| 379 | - } else { |
|
| 380 | - // otherwise leave it as-is. It will blow everything up and stop the migration |
|
| 381 | - $cols_n_values_with_no_invalid_text[ $col ] = $value; |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - $cols_n_values = $cols_n_values_with_no_invalid_text; |
|
| 385 | - $datatypes = array( |
|
| 386 | - '%s',// EVT_name |
|
| 387 | - '%s',// EVT_desc |
|
| 388 | - '%s',// EVT_slug |
|
| 389 | - '%s',// EVT_created |
|
| 390 | - '%s', |
|
| 391 | - '%s',// EVT_short_desc |
|
| 392 | - '%s',// EVT_modified |
|
| 393 | - '%s', |
|
| 394 | - '%s',// EVT_wp_user |
|
| 395 | - '%d',// post_parent |
|
| 396 | - '%d',// EVT_order |
|
| 397 | - '%s',// post_type |
|
| 398 | - '%s',// status |
|
| 399 | - ); |
|
| 400 | - $success = $wpdb->insert( |
|
| 401 | - $this->_new_table, |
|
| 402 | - $cols_n_values, |
|
| 403 | - $datatypes |
|
| 404 | - ); |
|
| 405 | - if (! $success) { |
|
| 406 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_table, $cols_n_values, $datatypes)); |
|
| 407 | - return 0; |
|
| 408 | - } |
|
| 409 | - return $wpdb->insert_id; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * Counts all the registrations for the event in the 3.1 DB. (takes into account attendee rows which represent various registrations) |
|
| 414 | - * @global wpdb $wpdb |
|
| 415 | - * @param int $event_id |
|
| 416 | - * @return int |
|
| 417 | - */ |
|
| 418 | - public static function count_registrations($event_id) |
|
| 419 | - { |
|
| 420 | - global $wpdb; |
|
| 421 | - $count = $wpdb->get_var($wpdb->prepare("SELECT sum(quantity) FROM {$wpdb->prefix}events_attendee WHERE event_id=%d", $event_id)); |
|
| 422 | - return intval($count); |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - |
|
| 426 | - |
|
| 427 | - /** |
|
| 428 | - * @param $old_event |
|
| 429 | - * @param $new_cpt_id |
|
| 430 | - * @return int |
|
| 431 | - */ |
|
| 432 | - private function _insert_event_meta($old_event, $new_cpt_id) |
|
| 433 | - { |
|
| 434 | - global $wpdb; |
|
| 435 | - $event_meta = maybe_unserialize($old_event['event_meta']); |
|
| 354 | + $cols_n_values = array( |
|
| 355 | + 'post_title'=>stripslashes($old_event['event_name']),// EVT_name |
|
| 356 | + 'post_content'=>stripslashes($old_event['event_desc']),// EVT_desc |
|
| 357 | + 'post_name'=>$this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status),// EVT_slug |
|
| 358 | + 'post_date'=>$old_event['submitted'],// EVT_created NOT |
|
| 359 | + 'post_date_gmt'=>get_gmt_from_date($old_event['submitted']), |
|
| 360 | + 'post_excerpt'=>'',// EVT_short_desc |
|
| 361 | + 'post_modified'=>$old_event['submitted'],// EVT_modified |
|
| 362 | + 'post_modified_gmt'=>get_gmt_from_date($old_event['submitted']), |
|
| 363 | + 'post_author'=>$old_event['wp_user'],// EVT_wp_user |
|
| 364 | + 'post_parent'=>0,// parent maybe get this from some REM field? |
|
| 365 | + 'menu_order'=>0,// EVT_order |
|
| 366 | + 'post_type'=>'espresso_events',// post_type |
|
| 367 | + 'post_status'=>$post_status,// status |
|
| 368 | + ); |
|
| 369 | + $cols_n_values_with_no_invalid_text = array(); |
|
| 370 | + foreach ($cols_n_values as $col => $value) { |
|
| 371 | + $value_sans_invalid_chars = $wpdb->strip_invalid_text_for_column($this->_new_table, $col, $value); |
|
| 372 | + if (! is_wp_error($value_sans_invalid_chars)) { |
|
| 373 | + $cols_n_values_with_no_invalid_text[ $col ] = $value_sans_invalid_chars; |
|
| 374 | + } else { |
|
| 375 | + // otherwise leave it as-is. It will blow everything up and stop the migration |
|
| 376 | + $cols_n_values_with_no_invalid_text[ $col ] = $value; |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + $cols_n_values = $cols_n_values_with_no_invalid_text; |
|
| 380 | + $datatypes = array( |
|
| 381 | + '%s',// EVT_name |
|
| 382 | + '%s',// EVT_desc |
|
| 383 | + '%s',// EVT_slug |
|
| 384 | + '%s',// EVT_created |
|
| 385 | + '%s', |
|
| 386 | + '%s',// EVT_short_desc |
|
| 387 | + '%s',// EVT_modified |
|
| 388 | + '%s', |
|
| 389 | + '%s',// EVT_wp_user |
|
| 390 | + '%d',// post_parent |
|
| 391 | + '%d',// EVT_order |
|
| 392 | + '%s',// post_type |
|
| 393 | + '%s',// status |
|
| 394 | + ); |
|
| 395 | + $success = $wpdb->insert( |
|
| 396 | + $this->_new_table, |
|
| 397 | + $cols_n_values, |
|
| 398 | + $datatypes |
|
| 399 | + ); |
|
| 400 | + if (! $success) { |
|
| 401 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_table, $cols_n_values, $datatypes)); |
|
| 402 | + return 0; |
|
| 403 | + } |
|
| 404 | + return $wpdb->insert_id; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * Counts all the registrations for the event in the 3.1 DB. (takes into account attendee rows which represent various registrations) |
|
| 409 | + * @global wpdb $wpdb |
|
| 410 | + * @param int $event_id |
|
| 411 | + * @return int |
|
| 412 | + */ |
|
| 413 | + public static function count_registrations($event_id) |
|
| 414 | + { |
|
| 415 | + global $wpdb; |
|
| 416 | + $count = $wpdb->get_var($wpdb->prepare("SELECT sum(quantity) FROM {$wpdb->prefix}events_attendee WHERE event_id=%d", $event_id)); |
|
| 417 | + return intval($count); |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * @param $old_event |
|
| 424 | + * @param $new_cpt_id |
|
| 425 | + * @return int |
|
| 426 | + */ |
|
| 427 | + private function _insert_event_meta($old_event, $new_cpt_id) |
|
| 428 | + { |
|
| 429 | + global $wpdb; |
|
| 430 | + $event_meta = maybe_unserialize($old_event['event_meta']); |
|
| 436 | 431 | // for reference, 3.1 'default_payment_status' are: $default_payment_status = array( |
| 437 | 432 | // array('id' => "", 'text' => 'No Change'), |
| 438 | 433 | // array('id' => 'Incomplete', 'text' => 'Incomplete'), |
| 439 | 434 | // array('id' => 'Pending', 'text' => 'Pending'), |
| 440 | 435 | // //array('id' => 'Completed', 'text' => 'Completed') |
| 441 | 436 | // ); |
| 442 | - $default_reg_status = $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(isset($event_meta['default_payment_status']) ? $event_meta['default_payment_status'] : '', intval($old_event['require_pre_approval'])); |
|
| 443 | - $cols_n_values = array( |
|
| 444 | - 'EVT_ID'=>$new_cpt_id,// EVT_ID_fk |
|
| 445 | - 'EVT_display_desc'=> 'Y' == $old_event['display_desc'], |
|
| 446 | - 'EVT_display_ticket_selector'=> 'Y'== $old_event['display_reg_form'], |
|
| 447 | - 'EVT_visible_on'=> $this->get_migration_script()->convert_date_string_to_utc($this, $old_event, current_time('mysql'), $old_event['timezone_string']),// don't use the old 'visible_on', as it wasn't ever used |
|
| 448 | - 'EVT_additional_limit'=> $old_event['allow_multiple'] == 'N' ? 1 : $old_event['additional_limit'], |
|
| 449 | - 'EVT_default_registration_status' => $default_reg_status, |
|
| 450 | - 'EVT_member_only'=>$old_event['member_only'], |
|
| 451 | - 'EVT_phone'=> $old_event['phone'], |
|
| 452 | - 'EVT_allow_overflow' => 'Y' == $old_event['allow_overflow'], |
|
| 453 | - 'EVT_timezone_string'=> $old_event['timezone_string'], |
|
| 454 | - 'EVT_external_URL'=>$old_event['externalURL'], |
|
| 455 | - 'EVT_donations'=>false// doesnt exist in 3.1 |
|
| 456 | - |
|
| 457 | - ); |
|
| 458 | - $datatypes = array( |
|
| 459 | - '%s',// EVT_ID |
|
| 460 | - '%d',// EVT_display_desc |
|
| 461 | - '%d',// EVT_display_ticket_selector |
|
| 462 | - '%s',// EVT_visible_on |
|
| 463 | - '%d',// EVT_additional_limit |
|
| 464 | - '%s',// EVT_default_registration_status |
|
| 465 | - '%d',// EVT_member_only |
|
| 466 | - '%s',// EVT_phone |
|
| 467 | - '%d',// EVT_allow_overflow |
|
| 468 | - '%s',// EVT_timezone_string |
|
| 469 | - '%s',// EVT_external_URL |
|
| 470 | - '%d',// EVT_donations |
|
| 471 | - ); |
|
| 472 | - $success = $wpdb->insert( |
|
| 473 | - $this->_new_meta_table, |
|
| 474 | - $cols_n_values, |
|
| 475 | - $datatypes |
|
| 476 | - ); |
|
| 477 | - if (! $success) { |
|
| 478 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $cols_n_values, $datatypes)); |
|
| 479 | - return 0; |
|
| 480 | - } |
|
| 481 | - return $wpdb->insert_id; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * @param $old_event |
|
| 488 | - * @return int |
|
| 489 | - */ |
|
| 490 | - private function _maybe_create_venue($old_event) |
|
| 491 | - { |
|
| 492 | - if ($old_event['address'] || |
|
| 493 | - $old_event['address2'] || |
|
| 494 | - $old_event['city'] || |
|
| 495 | - $old_event['state'] || |
|
| 496 | - $old_event['zip'] || |
|
| 497 | - $old_event['venue_title'] || |
|
| 498 | - $old_event['venue_url'] || |
|
| 499 | - $old_event['venue_image'] || |
|
| 500 | - $old_event['venue_phone'] || |
|
| 501 | - $old_event['virtual_url'] || |
|
| 502 | - $old_event['virtual_phone'] |
|
| 503 | - ) { |
|
| 504 | - $old_id = $this->_duplicate_venue_exists($old_event); |
|
| 505 | - if ($old_id) { |
|
| 506 | - return $old_id; |
|
| 507 | - } |
|
| 508 | - $new_id = $this->_insert_venue_into_posts($old_event); |
|
| 509 | - if ($new_id) { |
|
| 510 | - $this->_insert_venue_into_meta_table($new_id, $old_event); |
|
| 511 | - $guid = isset($old_event['venue_image']) ? $old_event['venue_image'] : null; |
|
| 512 | - $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this); |
|
| 513 | - } |
|
| 514 | - // we don't bother recording the conversion from old events to venues as that |
|
| 515 | - // will complicate finding the conversion from old venues to new events |
|
| 516 | - return $new_id; |
|
| 517 | - } else { |
|
| 518 | - return 0; |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * Assuming there is venue data on this event, check if there is a duplicate venue already in the system for it. |
|
| 524 | - * If so, return it. Otherwise return NULL. |
|
| 525 | - * @param array $old_event |
|
| 526 | - * @return int duplicate venue id |
|
| 527 | - */ |
|
| 528 | - private function _duplicate_venue_exists($old_event) |
|
| 529 | - { |
|
| 530 | - global $wpdb; |
|
| 531 | - $conditions = array( |
|
| 532 | - 'VNU_address' => $old_event ['address'], |
|
| 533 | - 'VNU_address2' => $old_event['address2'], |
|
| 534 | - 'VNU_city' => $old_event['city'], |
|
| 535 | - 'VNU_zip' => $old_event['zip'], |
|
| 536 | - 'post_title'=> $this->_get_venue_title_for_event($old_event), |
|
| 537 | - 'VNU_phone'=>$old_event['venue_phone'],// VNU_phone |
|
| 538 | - 'VNU_url'=>$old_event['venue_url'],// VNU_url |
|
| 539 | - 'VNU_virtual_phone'=>$old_event['virtual_phone'],// VNU_virtual_phone |
|
| 540 | - 'VNU_virtual_url'=>$old_event['virtual_url'],// VNU_virtual_url |
|
| 541 | - ); |
|
| 542 | - $sql_conditions = array(); |
|
| 543 | - foreach ($conditions as $column => $value) { |
|
| 544 | - $sql_conditions [] = $wpdb->prepare("$column = %s", $value); |
|
| 545 | - } |
|
| 546 | - $query = "SELECT VNU_ID |
|
| 437 | + $default_reg_status = $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(isset($event_meta['default_payment_status']) ? $event_meta['default_payment_status'] : '', intval($old_event['require_pre_approval'])); |
|
| 438 | + $cols_n_values = array( |
|
| 439 | + 'EVT_ID'=>$new_cpt_id,// EVT_ID_fk |
|
| 440 | + 'EVT_display_desc'=> 'Y' == $old_event['display_desc'], |
|
| 441 | + 'EVT_display_ticket_selector'=> 'Y'== $old_event['display_reg_form'], |
|
| 442 | + 'EVT_visible_on'=> $this->get_migration_script()->convert_date_string_to_utc($this, $old_event, current_time('mysql'), $old_event['timezone_string']),// don't use the old 'visible_on', as it wasn't ever used |
|
| 443 | + 'EVT_additional_limit'=> $old_event['allow_multiple'] == 'N' ? 1 : $old_event['additional_limit'], |
|
| 444 | + 'EVT_default_registration_status' => $default_reg_status, |
|
| 445 | + 'EVT_member_only'=>$old_event['member_only'], |
|
| 446 | + 'EVT_phone'=> $old_event['phone'], |
|
| 447 | + 'EVT_allow_overflow' => 'Y' == $old_event['allow_overflow'], |
|
| 448 | + 'EVT_timezone_string'=> $old_event['timezone_string'], |
|
| 449 | + 'EVT_external_URL'=>$old_event['externalURL'], |
|
| 450 | + 'EVT_donations'=>false// doesnt exist in 3.1 |
|
| 451 | + |
|
| 452 | + ); |
|
| 453 | + $datatypes = array( |
|
| 454 | + '%s',// EVT_ID |
|
| 455 | + '%d',// EVT_display_desc |
|
| 456 | + '%d',// EVT_display_ticket_selector |
|
| 457 | + '%s',// EVT_visible_on |
|
| 458 | + '%d',// EVT_additional_limit |
|
| 459 | + '%s',// EVT_default_registration_status |
|
| 460 | + '%d',// EVT_member_only |
|
| 461 | + '%s',// EVT_phone |
|
| 462 | + '%d',// EVT_allow_overflow |
|
| 463 | + '%s',// EVT_timezone_string |
|
| 464 | + '%s',// EVT_external_URL |
|
| 465 | + '%d',// EVT_donations |
|
| 466 | + ); |
|
| 467 | + $success = $wpdb->insert( |
|
| 468 | + $this->_new_meta_table, |
|
| 469 | + $cols_n_values, |
|
| 470 | + $datatypes |
|
| 471 | + ); |
|
| 472 | + if (! $success) { |
|
| 473 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $cols_n_values, $datatypes)); |
|
| 474 | + return 0; |
|
| 475 | + } |
|
| 476 | + return $wpdb->insert_id; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * @param $old_event |
|
| 483 | + * @return int |
|
| 484 | + */ |
|
| 485 | + private function _maybe_create_venue($old_event) |
|
| 486 | + { |
|
| 487 | + if ($old_event['address'] || |
|
| 488 | + $old_event['address2'] || |
|
| 489 | + $old_event['city'] || |
|
| 490 | + $old_event['state'] || |
|
| 491 | + $old_event['zip'] || |
|
| 492 | + $old_event['venue_title'] || |
|
| 493 | + $old_event['venue_url'] || |
|
| 494 | + $old_event['venue_image'] || |
|
| 495 | + $old_event['venue_phone'] || |
|
| 496 | + $old_event['virtual_url'] || |
|
| 497 | + $old_event['virtual_phone'] |
|
| 498 | + ) { |
|
| 499 | + $old_id = $this->_duplicate_venue_exists($old_event); |
|
| 500 | + if ($old_id) { |
|
| 501 | + return $old_id; |
|
| 502 | + } |
|
| 503 | + $new_id = $this->_insert_venue_into_posts($old_event); |
|
| 504 | + if ($new_id) { |
|
| 505 | + $this->_insert_venue_into_meta_table($new_id, $old_event); |
|
| 506 | + $guid = isset($old_event['venue_image']) ? $old_event['venue_image'] : null; |
|
| 507 | + $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this); |
|
| 508 | + } |
|
| 509 | + // we don't bother recording the conversion from old events to venues as that |
|
| 510 | + // will complicate finding the conversion from old venues to new events |
|
| 511 | + return $new_id; |
|
| 512 | + } else { |
|
| 513 | + return 0; |
|
| 514 | + } |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * Assuming there is venue data on this event, check if there is a duplicate venue already in the system for it. |
|
| 519 | + * If so, return it. Otherwise return NULL. |
|
| 520 | + * @param array $old_event |
|
| 521 | + * @return int duplicate venue id |
|
| 522 | + */ |
|
| 523 | + private function _duplicate_venue_exists($old_event) |
|
| 524 | + { |
|
| 525 | + global $wpdb; |
|
| 526 | + $conditions = array( |
|
| 527 | + 'VNU_address' => $old_event ['address'], |
|
| 528 | + 'VNU_address2' => $old_event['address2'], |
|
| 529 | + 'VNU_city' => $old_event['city'], |
|
| 530 | + 'VNU_zip' => $old_event['zip'], |
|
| 531 | + 'post_title'=> $this->_get_venue_title_for_event($old_event), |
|
| 532 | + 'VNU_phone'=>$old_event['venue_phone'],// VNU_phone |
|
| 533 | + 'VNU_url'=>$old_event['venue_url'],// VNU_url |
|
| 534 | + 'VNU_virtual_phone'=>$old_event['virtual_phone'],// VNU_virtual_phone |
|
| 535 | + 'VNU_virtual_url'=>$old_event['virtual_url'],// VNU_virtual_url |
|
| 536 | + ); |
|
| 537 | + $sql_conditions = array(); |
|
| 538 | + foreach ($conditions as $column => $value) { |
|
| 539 | + $sql_conditions [] = $wpdb->prepare("$column = %s", $value); |
|
| 540 | + } |
|
| 541 | + $query = "SELECT VNU_ID |
|
| 547 | 542 | FROM |
| 548 | 543 | {$wpdb->posts} as p INNER JOIN |
| 549 | 544 | {$wpdb->prefix}esp_venue_meta as v ON p.ID = v.VNU_ID |
| 550 | 545 | WHERE " . implode(" AND ", $sql_conditions) . " LIMIT 1"; |
| 551 | - $id = $wpdb->get_var($query); |
|
| 552 | - return $id; |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - /** |
|
| 556 | - * Gets teh venue's title or makes one up if there is none |
|
| 557 | - * @param array $event_data_array keys are events_details columns and values are their values |
|
| 558 | - * @return string |
|
| 559 | - */ |
|
| 560 | - protected function _get_venue_title_for_event($event_data_array) |
|
| 561 | - { |
|
| 562 | - return $event_data_array['venue_title'] ? stripslashes($event_data_array['venue_title']) : stripslashes(sprintf(__('Venue of %s', 'event_espresso'), $event_data_array['event_name'])); |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * Inserts the CPT |
|
| 567 | - * |
|
| 568 | - * @param array $old_event keys are cols, values are col values |
|
| 569 | - * @return int |
|
| 570 | - */ |
|
| 571 | - private function _insert_venue_into_posts($old_event) |
|
| 572 | - { |
|
| 573 | - global $wpdb; |
|
| 574 | - $insertion_array = array( |
|
| 575 | - 'post_title'=> $this->_get_venue_title_for_event($old_event),// VNU_name |
|
| 576 | - 'post_content'=>'',// VNU_desc |
|
| 577 | - 'post_name'=> $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-' . $old_event['event_name'])),// VNU_identifier |
|
| 578 | - 'post_date'=>current_time('mysql'),// VNU_created |
|
| 579 | - 'post_date_gmt'=>get_gmt_from_date(current_time('mysql')), |
|
| 580 | - 'post_excerpt'=>'',// VNU_short_desc arbitrary only 50 characters |
|
| 581 | - 'post_modified'=>current_time('mysql'),// VNU_modified |
|
| 582 | - 'post_modified_gmt'=>get_gmt_from_date(current_time('mysql')), |
|
| 583 | - 'post_author'=>$old_event['wp_user'],// VNU_wp_user |
|
| 584 | - 'post_parent'=>0,// parent |
|
| 585 | - 'menu_order'=>0,// VNU_order |
|
| 586 | - 'post_type'=>'espresso_venues'// post_type |
|
| 587 | - ); |
|
| 588 | - $datatypes_array = array( |
|
| 589 | - '%s',// VNU_name |
|
| 590 | - '%s',// VNU_desc |
|
| 591 | - '%s',// VNU_identifier |
|
| 592 | - '%s',// VNU_created |
|
| 593 | - '%s', |
|
| 594 | - '%s',// VNU_short_desc |
|
| 595 | - '%s',// VNU_modified |
|
| 596 | - '%s', |
|
| 597 | - '%d',// VNU_wp_user |
|
| 598 | - '%d',// parent |
|
| 599 | - '%d',// VNU_order |
|
| 600 | - '%s',// post_type |
|
| 601 | - ); |
|
| 602 | - $success = $wpdb->insert( |
|
| 603 | - $wpdb->posts, |
|
| 604 | - $insertion_array, |
|
| 605 | - $datatypes_array |
|
| 606 | - ); |
|
| 607 | - if (! $success) { |
|
| 608 | - $this->add_error( |
|
| 609 | - $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
| 610 | - $this->_old_table, |
|
| 611 | - $old_event, |
|
| 612 | - $this->_new_table, |
|
| 613 | - $insertion_array, |
|
| 614 | - $datatypes_array |
|
| 615 | - ) |
|
| 616 | - ); |
|
| 617 | - return 0; |
|
| 618 | - } |
|
| 619 | - return $wpdb->insert_id; |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - /** |
|
| 623 | - * Inserts into the venue_meta table |
|
| 624 | - * @param int $cpt_id |
|
| 625 | - * @param array $old_event |
|
| 626 | - * @return int |
|
| 627 | - */ |
|
| 628 | - private function _insert_venue_into_meta_table($cpt_id, $old_event) |
|
| 629 | - { |
|
| 630 | - global $wpdb; |
|
| 631 | - |
|
| 632 | - // assume the country is the same as the organization's old settings |
|
| 633 | - $country_iso = $this->get_migration_script()->get_default_country_iso(); |
|
| 634 | - // find the state from the venue, or the organization, or just guess california |
|
| 635 | - if (! $old_event['state']) { |
|
| 636 | - $old_org_options = get_option('events_organization_settings'); |
|
| 637 | - $state_name = stripslashes($old_org_options['organization_state']); |
|
| 638 | - } else { |
|
| 639 | - $state_name = $old_event['state']; |
|
| 640 | - } |
|
| 641 | - if (! $state_name) { |
|
| 642 | - $state_name = 'CA'; |
|
| 643 | - } |
|
| 644 | - // get a state ID with the same name, if possible |
|
| 645 | - try { |
|
| 646 | - $state = $this->get_migration_script()->get_or_create_state($state_name, $country_iso); |
|
| 647 | - $state_id = $state['STA_ID']; |
|
| 648 | - } catch (EE_Error $e) { |
|
| 649 | - $this->add_error($e->getMessage()); |
|
| 650 | - $state_id = 0; |
|
| 651 | - } |
|
| 652 | - // now insert into meta table |
|
| 653 | - $insertion_array = array( |
|
| 654 | - 'VNU_ID'=>$cpt_id,// VNU_ID_fk |
|
| 655 | - 'VNU_address'=>stripslashes($old_event['address']),// VNU_address |
|
| 656 | - 'VNU_address2'=>stripslashes($old_event['address2']),// VNU_address2 |
|
| 657 | - 'VNU_city'=>stripslashes($old_event['city']),// VNU_city |
|
| 658 | - 'STA_ID'=>$state_id,// STA_ID |
|
| 659 | - 'CNT_ISO'=>$country_iso,// CNT_ISO |
|
| 660 | - 'VNU_zip'=>$old_event['zip'],// VNU_zip |
|
| 661 | - 'VNU_phone'=>$old_event['venue_phone'],// VNU_phone |
|
| 662 | - 'VNU_capacity'=>-1,// VNU_capacity |
|
| 663 | - 'VNU_url'=>$old_event['venue_url'],// VNU_url |
|
| 664 | - 'VNU_virtual_phone'=>$old_event['virtual_phone'],// VNU_virtual_phone |
|
| 665 | - 'VNU_virtual_url'=>$old_event['virtual_url'],// VNU_virtual_url |
|
| 666 | - 'VNU_google_map_link'=>'',// VNU_google_map_link |
|
| 667 | - 'VNU_enable_for_gmap'=>true // VNU_enable_for_gmap |
|
| 668 | - ); |
|
| 669 | - $datatypes = array( |
|
| 670 | - '%d',// VNU_ID_fk |
|
| 671 | - '%s',// VNU_address |
|
| 672 | - '%s',// VNU_address2 |
|
| 673 | - '%s',// VNU_city |
|
| 674 | - '%d',// STA_ID |
|
| 675 | - '%s',// CNT_ISO |
|
| 676 | - '%s',// VNU_zip |
|
| 677 | - '%s',// VNU_phone |
|
| 678 | - '%d',// VNU_capacity |
|
| 679 | - '%s',// VNU_url |
|
| 680 | - '%s',// VNU_virtual_phone |
|
| 681 | - '%s',// VNU_virtual_url |
|
| 682 | - '%s',// VNU_google_map_link |
|
| 683 | - '%d',// VNU_enable_for_gmap |
|
| 684 | - ); |
|
| 685 | - $success = $wpdb->insert($wpdb->prefix."esp_venue_meta", $insertion_array, $datatypes); |
|
| 686 | - if (! $success) { |
|
| 687 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $insertion_array, $datatypes)); |
|
| 688 | - return 0; |
|
| 689 | - } |
|
| 690 | - return $wpdb->insert_id; |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * @param $new_event_id |
|
| 697 | - * @param $new_venue_id |
|
| 698 | - * @return int |
|
| 699 | - */ |
|
| 700 | - private function _insert_new_venue_to_event($new_event_id, $new_venue_id) |
|
| 701 | - { |
|
| 702 | - global $wpdb; |
|
| 703 | - if (! $new_event_id) { |
|
| 704 | - $this->add_error(sprintf(__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $new_event_id)); |
|
| 705 | - return 0; |
|
| 706 | - } |
|
| 707 | - if (! $new_venue_id) { |
|
| 708 | - $this->add_error(sprintf(__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $new_venue_id)); |
|
| 709 | - return 0; |
|
| 710 | - } |
|
| 711 | - $cols_n_values = array( |
|
| 712 | - 'EVT_ID'=>$new_event_id, |
|
| 713 | - 'VNU_ID'=>$new_venue_id, |
|
| 714 | - 'EVV_primary'=>true |
|
| 715 | - ); |
|
| 716 | - $datatypes = array( |
|
| 717 | - '%d',// EVT_ID |
|
| 718 | - '%d',// VNU_ID |
|
| 719 | - '%d',// EVT_primary |
|
| 720 | - ); |
|
| 721 | - $success = $wpdb->insert($wpdb->prefix."esp_event_venue", $cols_n_values, $datatypes); |
|
| 722 | - if (! $success) { |
|
| 723 | - $this->add_error( |
|
| 724 | - $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
| 725 | - $this->_old_table, |
|
| 726 | - array(), |
|
| 727 | - $this->_new_table, |
|
| 728 | - $cols_n_values, |
|
| 729 | - $datatypes |
|
| 730 | - ) |
|
| 731 | - ); |
|
| 732 | - return 0; |
|
| 733 | - } |
|
| 734 | - return $wpdb->insert_id; |
|
| 735 | - } |
|
| 736 | - /** |
|
| 737 | - * Converts all the 3.1 start-end times for the event to 4.1 datetimes |
|
| 738 | - * @global wpdb $wpdb |
|
| 739 | - * @param array $old_event results of get_results(...,ARRAY_A) |
|
| 740 | - * @param int $new_cpt_id new post ID |
|
| 741 | - * @return void (if there are errors though, adds them to the stage's error list |
|
| 742 | - */ |
|
| 743 | - private function _convert_start_end_times($old_event, $new_cpt_id) |
|
| 744 | - { |
|
| 745 | - $start_end_times = $this->_get_old_start_end_times($old_event['id']); |
|
| 746 | - foreach ($start_end_times as $start_end_time) { |
|
| 747 | - $datetime_id = $this->_insert_new_datetime($start_end_time, $old_event, $new_cpt_id); |
|
| 748 | - if ($datetime_id) { |
|
| 749 | - $this->get_migration_script()->set_mapping($this->_old_start_end_table, $start_end_time['id'], $this->_new_datetime_table, $datetime_id); |
|
| 750 | - } |
|
| 751 | - } |
|
| 752 | - } |
|
| 753 | - /** |
|
| 754 | - * Queries the 3.1 wp_events_start_end table to get all the start and end times for the event |
|
| 755 | - * @global wpdb $wpdb |
|
| 756 | - * @param int $old_event_id |
|
| 757 | - * @return array |
|
| 758 | - */ |
|
| 759 | - private function _get_old_start_end_times($old_event_id) |
|
| 760 | - { |
|
| 761 | - global $wpdb; |
|
| 762 | - return $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_start_end_table WHERE event_id=%d", $old_event_id), ARRAY_A); |
|
| 763 | - } |
|
| 764 | - /** |
|
| 765 | - * Inserts a 4.1 datetime given the 3.1 start_end db row and event_details row |
|
| 766 | - * @param array $start_end_time_row |
|
| 767 | - * @param array $old_event_row |
|
| 768 | - * @param int $new_cpt_id |
|
| 769 | - * @return int ID of new datetime |
|
| 770 | - */ |
|
| 771 | - private function _insert_new_datetime($start_end_time_row, $old_event_row, $new_cpt_id) |
|
| 772 | - { |
|
| 773 | - global $wpdb; |
|
| 774 | - $start_date = $old_event_row['start_date']; |
|
| 775 | - $start_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['start_time']); |
|
| 776 | - $end_date = $old_event_row['end_date']; |
|
| 777 | - $end_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['end_time']); |
|
| 778 | - $existing_datetimes = $this->_count_other_datetimes_exist_for_new_event($new_cpt_id); |
|
| 779 | - $start_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$start_date $start_time:00", $old_event_row['timezone_string']); |
|
| 780 | - $end_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$end_date $end_time:00", $old_event_row['timezone_string']); |
|
| 781 | - $cols_n_values = array( |
|
| 782 | - 'EVT_ID'=>$new_cpt_id,// EVT_ID |
|
| 783 | - 'DTT_EVT_start'=>$start_datetime_utc,// DTT_EVT_start |
|
| 784 | - 'DTT_EVT_end'=> $end_datetime_utc,// DTT_EVT_end |
|
| 785 | - 'DTT_reg_limit'=>intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'],// DTT_reg_limit |
|
| 786 | - 'DTT_sold'=>0,// note: we will increment this as registrations are added during the migration |
|
| 546 | + $id = $wpdb->get_var($query); |
|
| 547 | + return $id; |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + /** |
|
| 551 | + * Gets teh venue's title or makes one up if there is none |
|
| 552 | + * @param array $event_data_array keys are events_details columns and values are their values |
|
| 553 | + * @return string |
|
| 554 | + */ |
|
| 555 | + protected function _get_venue_title_for_event($event_data_array) |
|
| 556 | + { |
|
| 557 | + return $event_data_array['venue_title'] ? stripslashes($event_data_array['venue_title']) : stripslashes(sprintf(__('Venue of %s', 'event_espresso'), $event_data_array['event_name'])); |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * Inserts the CPT |
|
| 562 | + * |
|
| 563 | + * @param array $old_event keys are cols, values are col values |
|
| 564 | + * @return int |
|
| 565 | + */ |
|
| 566 | + private function _insert_venue_into_posts($old_event) |
|
| 567 | + { |
|
| 568 | + global $wpdb; |
|
| 569 | + $insertion_array = array( |
|
| 570 | + 'post_title'=> $this->_get_venue_title_for_event($old_event),// VNU_name |
|
| 571 | + 'post_content'=>'',// VNU_desc |
|
| 572 | + 'post_name'=> $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-' . $old_event['event_name'])),// VNU_identifier |
|
| 573 | + 'post_date'=>current_time('mysql'),// VNU_created |
|
| 574 | + 'post_date_gmt'=>get_gmt_from_date(current_time('mysql')), |
|
| 575 | + 'post_excerpt'=>'',// VNU_short_desc arbitrary only 50 characters |
|
| 576 | + 'post_modified'=>current_time('mysql'),// VNU_modified |
|
| 577 | + 'post_modified_gmt'=>get_gmt_from_date(current_time('mysql')), |
|
| 578 | + 'post_author'=>$old_event['wp_user'],// VNU_wp_user |
|
| 579 | + 'post_parent'=>0,// parent |
|
| 580 | + 'menu_order'=>0,// VNU_order |
|
| 581 | + 'post_type'=>'espresso_venues'// post_type |
|
| 582 | + ); |
|
| 583 | + $datatypes_array = array( |
|
| 584 | + '%s',// VNU_name |
|
| 585 | + '%s',// VNU_desc |
|
| 586 | + '%s',// VNU_identifier |
|
| 587 | + '%s',// VNU_created |
|
| 588 | + '%s', |
|
| 589 | + '%s',// VNU_short_desc |
|
| 590 | + '%s',// VNU_modified |
|
| 591 | + '%s', |
|
| 592 | + '%d',// VNU_wp_user |
|
| 593 | + '%d',// parent |
|
| 594 | + '%d',// VNU_order |
|
| 595 | + '%s',// post_type |
|
| 596 | + ); |
|
| 597 | + $success = $wpdb->insert( |
|
| 598 | + $wpdb->posts, |
|
| 599 | + $insertion_array, |
|
| 600 | + $datatypes_array |
|
| 601 | + ); |
|
| 602 | + if (! $success) { |
|
| 603 | + $this->add_error( |
|
| 604 | + $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
| 605 | + $this->_old_table, |
|
| 606 | + $old_event, |
|
| 607 | + $this->_new_table, |
|
| 608 | + $insertion_array, |
|
| 609 | + $datatypes_array |
|
| 610 | + ) |
|
| 611 | + ); |
|
| 612 | + return 0; |
|
| 613 | + } |
|
| 614 | + return $wpdb->insert_id; |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + /** |
|
| 618 | + * Inserts into the venue_meta table |
|
| 619 | + * @param int $cpt_id |
|
| 620 | + * @param array $old_event |
|
| 621 | + * @return int |
|
| 622 | + */ |
|
| 623 | + private function _insert_venue_into_meta_table($cpt_id, $old_event) |
|
| 624 | + { |
|
| 625 | + global $wpdb; |
|
| 626 | + |
|
| 627 | + // assume the country is the same as the organization's old settings |
|
| 628 | + $country_iso = $this->get_migration_script()->get_default_country_iso(); |
|
| 629 | + // find the state from the venue, or the organization, or just guess california |
|
| 630 | + if (! $old_event['state']) { |
|
| 631 | + $old_org_options = get_option('events_organization_settings'); |
|
| 632 | + $state_name = stripslashes($old_org_options['organization_state']); |
|
| 633 | + } else { |
|
| 634 | + $state_name = $old_event['state']; |
|
| 635 | + } |
|
| 636 | + if (! $state_name) { |
|
| 637 | + $state_name = 'CA'; |
|
| 638 | + } |
|
| 639 | + // get a state ID with the same name, if possible |
|
| 640 | + try { |
|
| 641 | + $state = $this->get_migration_script()->get_or_create_state($state_name, $country_iso); |
|
| 642 | + $state_id = $state['STA_ID']; |
|
| 643 | + } catch (EE_Error $e) { |
|
| 644 | + $this->add_error($e->getMessage()); |
|
| 645 | + $state_id = 0; |
|
| 646 | + } |
|
| 647 | + // now insert into meta table |
|
| 648 | + $insertion_array = array( |
|
| 649 | + 'VNU_ID'=>$cpt_id,// VNU_ID_fk |
|
| 650 | + 'VNU_address'=>stripslashes($old_event['address']),// VNU_address |
|
| 651 | + 'VNU_address2'=>stripslashes($old_event['address2']),// VNU_address2 |
|
| 652 | + 'VNU_city'=>stripslashes($old_event['city']),// VNU_city |
|
| 653 | + 'STA_ID'=>$state_id,// STA_ID |
|
| 654 | + 'CNT_ISO'=>$country_iso,// CNT_ISO |
|
| 655 | + 'VNU_zip'=>$old_event['zip'],// VNU_zip |
|
| 656 | + 'VNU_phone'=>$old_event['venue_phone'],// VNU_phone |
|
| 657 | + 'VNU_capacity'=>-1,// VNU_capacity |
|
| 658 | + 'VNU_url'=>$old_event['venue_url'],// VNU_url |
|
| 659 | + 'VNU_virtual_phone'=>$old_event['virtual_phone'],// VNU_virtual_phone |
|
| 660 | + 'VNU_virtual_url'=>$old_event['virtual_url'],// VNU_virtual_url |
|
| 661 | + 'VNU_google_map_link'=>'',// VNU_google_map_link |
|
| 662 | + 'VNU_enable_for_gmap'=>true // VNU_enable_for_gmap |
|
| 663 | + ); |
|
| 664 | + $datatypes = array( |
|
| 665 | + '%d',// VNU_ID_fk |
|
| 666 | + '%s',// VNU_address |
|
| 667 | + '%s',// VNU_address2 |
|
| 668 | + '%s',// VNU_city |
|
| 669 | + '%d',// STA_ID |
|
| 670 | + '%s',// CNT_ISO |
|
| 671 | + '%s',// VNU_zip |
|
| 672 | + '%s',// VNU_phone |
|
| 673 | + '%d',// VNU_capacity |
|
| 674 | + '%s',// VNU_url |
|
| 675 | + '%s',// VNU_virtual_phone |
|
| 676 | + '%s',// VNU_virtual_url |
|
| 677 | + '%s',// VNU_google_map_link |
|
| 678 | + '%d',// VNU_enable_for_gmap |
|
| 679 | + ); |
|
| 680 | + $success = $wpdb->insert($wpdb->prefix."esp_venue_meta", $insertion_array, $datatypes); |
|
| 681 | + if (! $success) { |
|
| 682 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $insertion_array, $datatypes)); |
|
| 683 | + return 0; |
|
| 684 | + } |
|
| 685 | + return $wpdb->insert_id; |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + |
|
| 689 | + |
|
| 690 | + /** |
|
| 691 | + * @param $new_event_id |
|
| 692 | + * @param $new_venue_id |
|
| 693 | + * @return int |
|
| 694 | + */ |
|
| 695 | + private function _insert_new_venue_to_event($new_event_id, $new_venue_id) |
|
| 696 | + { |
|
| 697 | + global $wpdb; |
|
| 698 | + if (! $new_event_id) { |
|
| 699 | + $this->add_error(sprintf(__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $new_event_id)); |
|
| 700 | + return 0; |
|
| 701 | + } |
|
| 702 | + if (! $new_venue_id) { |
|
| 703 | + $this->add_error(sprintf(__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $new_venue_id)); |
|
| 704 | + return 0; |
|
| 705 | + } |
|
| 706 | + $cols_n_values = array( |
|
| 707 | + 'EVT_ID'=>$new_event_id, |
|
| 708 | + 'VNU_ID'=>$new_venue_id, |
|
| 709 | + 'EVV_primary'=>true |
|
| 710 | + ); |
|
| 711 | + $datatypes = array( |
|
| 712 | + '%d',// EVT_ID |
|
| 713 | + '%d',// VNU_ID |
|
| 714 | + '%d',// EVT_primary |
|
| 715 | + ); |
|
| 716 | + $success = $wpdb->insert($wpdb->prefix."esp_event_venue", $cols_n_values, $datatypes); |
|
| 717 | + if (! $success) { |
|
| 718 | + $this->add_error( |
|
| 719 | + $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
| 720 | + $this->_old_table, |
|
| 721 | + array(), |
|
| 722 | + $this->_new_table, |
|
| 723 | + $cols_n_values, |
|
| 724 | + $datatypes |
|
| 725 | + ) |
|
| 726 | + ); |
|
| 727 | + return 0; |
|
| 728 | + } |
|
| 729 | + return $wpdb->insert_id; |
|
| 730 | + } |
|
| 731 | + /** |
|
| 732 | + * Converts all the 3.1 start-end times for the event to 4.1 datetimes |
|
| 733 | + * @global wpdb $wpdb |
|
| 734 | + * @param array $old_event results of get_results(...,ARRAY_A) |
|
| 735 | + * @param int $new_cpt_id new post ID |
|
| 736 | + * @return void (if there are errors though, adds them to the stage's error list |
|
| 737 | + */ |
|
| 738 | + private function _convert_start_end_times($old_event, $new_cpt_id) |
|
| 739 | + { |
|
| 740 | + $start_end_times = $this->_get_old_start_end_times($old_event['id']); |
|
| 741 | + foreach ($start_end_times as $start_end_time) { |
|
| 742 | + $datetime_id = $this->_insert_new_datetime($start_end_time, $old_event, $new_cpt_id); |
|
| 743 | + if ($datetime_id) { |
|
| 744 | + $this->get_migration_script()->set_mapping($this->_old_start_end_table, $start_end_time['id'], $this->_new_datetime_table, $datetime_id); |
|
| 745 | + } |
|
| 746 | + } |
|
| 747 | + } |
|
| 748 | + /** |
|
| 749 | + * Queries the 3.1 wp_events_start_end table to get all the start and end times for the event |
|
| 750 | + * @global wpdb $wpdb |
|
| 751 | + * @param int $old_event_id |
|
| 752 | + * @return array |
|
| 753 | + */ |
|
| 754 | + private function _get_old_start_end_times($old_event_id) |
|
| 755 | + { |
|
| 756 | + global $wpdb; |
|
| 757 | + return $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_start_end_table WHERE event_id=%d", $old_event_id), ARRAY_A); |
|
| 758 | + } |
|
| 759 | + /** |
|
| 760 | + * Inserts a 4.1 datetime given the 3.1 start_end db row and event_details row |
|
| 761 | + * @param array $start_end_time_row |
|
| 762 | + * @param array $old_event_row |
|
| 763 | + * @param int $new_cpt_id |
|
| 764 | + * @return int ID of new datetime |
|
| 765 | + */ |
|
| 766 | + private function _insert_new_datetime($start_end_time_row, $old_event_row, $new_cpt_id) |
|
| 767 | + { |
|
| 768 | + global $wpdb; |
|
| 769 | + $start_date = $old_event_row['start_date']; |
|
| 770 | + $start_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['start_time']); |
|
| 771 | + $end_date = $old_event_row['end_date']; |
|
| 772 | + $end_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['end_time']); |
|
| 773 | + $existing_datetimes = $this->_count_other_datetimes_exist_for_new_event($new_cpt_id); |
|
| 774 | + $start_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$start_date $start_time:00", $old_event_row['timezone_string']); |
|
| 775 | + $end_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$end_date $end_time:00", $old_event_row['timezone_string']); |
|
| 776 | + $cols_n_values = array( |
|
| 777 | + 'EVT_ID'=>$new_cpt_id,// EVT_ID |
|
| 778 | + 'DTT_EVT_start'=>$start_datetime_utc,// DTT_EVT_start |
|
| 779 | + 'DTT_EVT_end'=> $end_datetime_utc,// DTT_EVT_end |
|
| 780 | + 'DTT_reg_limit'=>intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'],// DTT_reg_limit |
|
| 781 | + 'DTT_sold'=>0,// note: we will increment this as registrations are added during the migration |
|
| 787 | 782 | // 'DTT_is_primary'=> 0 == $existing_datetimes ,//DTT_is_primary... if count==0, then we'll call it the 'primary' |
| 788 | - 'DTT_order'=> $existing_datetimes,// DTT_order, just give it the same order as the count of how many datetimes already exist |
|
| 789 | - 'DTT_parent'=>0, |
|
| 790 | - 'DTT_deleted'=>false |
|
| 791 | - ); |
|
| 792 | - $datatypes = array( |
|
| 793 | - '%d',// EVT_Id |
|
| 794 | - '%s',// DTT_EVT_start |
|
| 795 | - '%s',// DTT_EVT_end |
|
| 796 | - '%d',// DTT_reg_limit |
|
| 797 | - '%d',// DTT_sold |
|
| 783 | + 'DTT_order'=> $existing_datetimes,// DTT_order, just give it the same order as the count of how many datetimes already exist |
|
| 784 | + 'DTT_parent'=>0, |
|
| 785 | + 'DTT_deleted'=>false |
|
| 786 | + ); |
|
| 787 | + $datatypes = array( |
|
| 788 | + '%d',// EVT_Id |
|
| 789 | + '%s',// DTT_EVT_start |
|
| 790 | + '%s',// DTT_EVT_end |
|
| 791 | + '%d',// DTT_reg_limit |
|
| 792 | + '%d',// DTT_sold |
|
| 798 | 793 | // '%d',//DTT_is_primary |
| 799 | - '%d',// DTT_order |
|
| 800 | - '%d',// DTT_parent |
|
| 801 | - '%d',// DTT_deleted |
|
| 802 | - ); |
|
| 803 | - $success = $wpdb->insert($this->_new_datetime_table, $cols_n_values, $datatypes); |
|
| 804 | - if (! $success) { |
|
| 805 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_start_end_table, array_merge($old_event_row, $start_end_time_row), $this->_new_datetime_table, $cols_n_values, $datatypes)); |
|
| 806 | - return 0; |
|
| 807 | - } |
|
| 808 | - return $wpdb->insert_id; |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - /** |
|
| 812 | - * Checks if there's a 4.1 datetime for this event already. This is mostly only handy |
|
| 813 | - * when deciding whether a datetime we're about ot insert should be the 'primary' or not |
|
| 814 | - * @global wpdb $wpdb |
|
| 815 | - * @param int $cpt_event_id |
|
| 816 | - * @return int |
|
| 817 | - */ |
|
| 818 | - private function _count_other_datetimes_exist_for_new_event($cpt_event_id) |
|
| 819 | - { |
|
| 820 | - global $wpdb; |
|
| 821 | - $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $this->_new_datetime_table WHERE EVT_ID=%d", $cpt_event_id)); |
|
| 822 | - return intval($count); |
|
| 823 | - } |
|
| 794 | + '%d',// DTT_order |
|
| 795 | + '%d',// DTT_parent |
|
| 796 | + '%d',// DTT_deleted |
|
| 797 | + ); |
|
| 798 | + $success = $wpdb->insert($this->_new_datetime_table, $cols_n_values, $datatypes); |
|
| 799 | + if (! $success) { |
|
| 800 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_start_end_table, array_merge($old_event_row, $start_end_time_row), $this->_new_datetime_table, $cols_n_values, $datatypes)); |
|
| 801 | + return 0; |
|
| 802 | + } |
|
| 803 | + return $wpdb->insert_id; |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + /** |
|
| 807 | + * Checks if there's a 4.1 datetime for this event already. This is mostly only handy |
|
| 808 | + * when deciding whether a datetime we're about ot insert should be the 'primary' or not |
|
| 809 | + * @global wpdb $wpdb |
|
| 810 | + * @param int $cpt_event_id |
|
| 811 | + * @return int |
|
| 812 | + */ |
|
| 813 | + private function _count_other_datetimes_exist_for_new_event($cpt_event_id) |
|
| 814 | + { |
|
| 815 | + global $wpdb; |
|
| 816 | + $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $this->_new_datetime_table WHERE EVT_ID=%d", $cpt_event_id)); |
|
| 817 | + return intval($count); |
|
| 818 | + } |
|
| 824 | 819 | } |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | public function _count_records_to_migrate() |
| 194 | 194 | { |
| 195 | 195 | global $wpdb; |
| 196 | - $count = $wpdb->get_var("SELECT COUNT(*) FROM ".$this->_old_table . ' WHERE event_status !="D"'); |
|
| 196 | + $count = $wpdb->get_var("SELECT COUNT(*) FROM ".$this->_old_table.' WHERE event_status !="D"'); |
|
| 197 | 197 | return intval($count); |
| 198 | 198 | } |
| 199 | 199 | |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | { |
| 213 | 213 | global $wpdb; |
| 214 | 214 | // because the migration of each event can be a LOT more work, make each step smaller |
| 215 | - $num_items_to_migrate = max(1, $num_items_to_migrate/5); |
|
| 215 | + $num_items_to_migrate = max(1, $num_items_to_migrate / 5); |
|
| 216 | 216 | $events = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table WHERE event_status!='D' LIMIT %d,%d", $this->count_records_migrated(), $num_items_to_migrate), ARRAY_A); |
| 217 | 217 | $items_migrated_this_step = 0; |
| 218 | 218 | |
@@ -260,17 +260,17 @@ discard block |
||
| 260 | 260 | private function _add_post_metas($old_event, $post_id) |
| 261 | 261 | { |
| 262 | 262 | $event_meta = maybe_unserialize($old_event['event_meta']); |
| 263 | - if (! $event_meta || ! is_array($event_meta)) { |
|
| 263 | + if ( ! $event_meta || ! is_array($event_meta)) { |
|
| 264 | 264 | return; |
| 265 | 265 | } |
| 266 | - unset($event_meta['date_submitted']);// factored into CPT |
|
| 267 | - unset($event_meta['additional_attendee_reg_info']);// factored into event meta table |
|
| 268 | - unset($event_meta['default_payment_status']);// dido |
|
| 269 | - unset($event_meta['event_thumbnail_url']);// used to find post featured image |
|
| 266 | + unset($event_meta['date_submitted']); // factored into CPT |
|
| 267 | + unset($event_meta['additional_attendee_reg_info']); // factored into event meta table |
|
| 268 | + unset($event_meta['default_payment_status']); // dido |
|
| 269 | + unset($event_meta['event_thumbnail_url']); // used to find post featured image |
|
| 270 | 270 | foreach ($event_meta as $meta_key => $meta_value) { |
| 271 | 271 | if ($meta_key) {// if the meta key is just an empty string, ignore it |
| 272 | 272 | $success = add_post_meta($post_id, $meta_key, $meta_value, true); |
| 273 | - if (! $success) { |
|
| 273 | + if ( ! $success) { |
|
| 274 | 274 | $this->add_error(sprintf(__("Could not add post meta for CPT with ID #%d. Meta key: '%s',meta value:'%d' for 3.1 event: %s", "event_espresso"), $post_id, $meta_key, $meta_value, implode(",", $old_event))); |
| 275 | 275 | } |
| 276 | 276 | } |
@@ -341,68 +341,68 @@ discard block |
||
| 341 | 341 | // and 3 custom ones: cancelled,postponed,sold_out |
| 342 | 342 | $status_conversions = array( |
| 343 | 343 | 'R'=>'draft', |
| 344 | - 'X'=>'draft',// 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved |
|
| 344 | + 'X'=>'draft', // 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved |
|
| 345 | 345 | 'P'=>'pending', |
| 346 | - 'IA'=>'draft',// draft and in the past |
|
| 346 | + 'IA'=>'draft', // draft and in the past |
|
| 347 | 347 | // IA=inactive in 3.1: events were switched to this when they expired. in 4.1 that's just calculated |
| 348 | - 'O'=>'publish',// @todo: will be an event type later; if this is the status, set the end date WAAAY later; and add term for 'ongoing' |
|
| 348 | + 'O'=>'publish', // @todo: will be an event type later; if this is the status, set the end date WAAAY later; and add term for 'ongoing' |
|
| 349 | 349 | 'A'=>'publish', |
| 350 | - 'S'=>'draft',// @todo: is it ok to just mark secondary/waitlist events as DRAFTS? |
|
| 350 | + 'S'=>'draft', // @todo: is it ok to just mark secondary/waitlist events as DRAFTS? |
|
| 351 | 351 | 'D'=>'trash', |
| 352 | 352 | ); |
| 353 | - $post_status = $status_conversions[ $old_event['event_status'] ]; |
|
| 353 | + $post_status = $status_conversions[$old_event['event_status']]; |
|
| 354 | 354 | // check if we've sold out |
| 355 | 355 | if (intval($old_event['reg_limit']) <= self::count_registrations($old_event['id'])) { |
| 356 | 356 | $post_status = 'sold_out'; |
| 357 | 357 | } |
| 358 | 358 | // FYI postponed and cancelled don't exist in 3.1 |
| 359 | 359 | $cols_n_values = array( |
| 360 | - 'post_title'=>stripslashes($old_event['event_name']),// EVT_name |
|
| 361 | - 'post_content'=>stripslashes($old_event['event_desc']),// EVT_desc |
|
| 362 | - 'post_name'=>$this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status),// EVT_slug |
|
| 363 | - 'post_date'=>$old_event['submitted'],// EVT_created NOT |
|
| 360 | + 'post_title'=>stripslashes($old_event['event_name']), // EVT_name |
|
| 361 | + 'post_content'=>stripslashes($old_event['event_desc']), // EVT_desc |
|
| 362 | + 'post_name'=>$this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status), // EVT_slug |
|
| 363 | + 'post_date'=>$old_event['submitted'], // EVT_created NOT |
|
| 364 | 364 | 'post_date_gmt'=>get_gmt_from_date($old_event['submitted']), |
| 365 | - 'post_excerpt'=>'',// EVT_short_desc |
|
| 366 | - 'post_modified'=>$old_event['submitted'],// EVT_modified |
|
| 365 | + 'post_excerpt'=>'', // EVT_short_desc |
|
| 366 | + 'post_modified'=>$old_event['submitted'], // EVT_modified |
|
| 367 | 367 | 'post_modified_gmt'=>get_gmt_from_date($old_event['submitted']), |
| 368 | - 'post_author'=>$old_event['wp_user'],// EVT_wp_user |
|
| 369 | - 'post_parent'=>0,// parent maybe get this from some REM field? |
|
| 370 | - 'menu_order'=>0,// EVT_order |
|
| 371 | - 'post_type'=>'espresso_events',// post_type |
|
| 372 | - 'post_status'=>$post_status,// status |
|
| 368 | + 'post_author'=>$old_event['wp_user'], // EVT_wp_user |
|
| 369 | + 'post_parent'=>0, // parent maybe get this from some REM field? |
|
| 370 | + 'menu_order'=>0, // EVT_order |
|
| 371 | + 'post_type'=>'espresso_events', // post_type |
|
| 372 | + 'post_status'=>$post_status, // status |
|
| 373 | 373 | ); |
| 374 | 374 | $cols_n_values_with_no_invalid_text = array(); |
| 375 | 375 | foreach ($cols_n_values as $col => $value) { |
| 376 | 376 | $value_sans_invalid_chars = $wpdb->strip_invalid_text_for_column($this->_new_table, $col, $value); |
| 377 | - if (! is_wp_error($value_sans_invalid_chars)) { |
|
| 378 | - $cols_n_values_with_no_invalid_text[ $col ] = $value_sans_invalid_chars; |
|
| 377 | + if ( ! is_wp_error($value_sans_invalid_chars)) { |
|
| 378 | + $cols_n_values_with_no_invalid_text[$col] = $value_sans_invalid_chars; |
|
| 379 | 379 | } else { |
| 380 | 380 | // otherwise leave it as-is. It will blow everything up and stop the migration |
| 381 | - $cols_n_values_with_no_invalid_text[ $col ] = $value; |
|
| 381 | + $cols_n_values_with_no_invalid_text[$col] = $value; |
|
| 382 | 382 | } |
| 383 | 383 | } |
| 384 | 384 | $cols_n_values = $cols_n_values_with_no_invalid_text; |
| 385 | 385 | $datatypes = array( |
| 386 | - '%s',// EVT_name |
|
| 387 | - '%s',// EVT_desc |
|
| 388 | - '%s',// EVT_slug |
|
| 389 | - '%s',// EVT_created |
|
| 386 | + '%s', // EVT_name |
|
| 387 | + '%s', // EVT_desc |
|
| 388 | + '%s', // EVT_slug |
|
| 389 | + '%s', // EVT_created |
|
| 390 | 390 | '%s', |
| 391 | - '%s',// EVT_short_desc |
|
| 392 | - '%s',// EVT_modified |
|
| 391 | + '%s', // EVT_short_desc |
|
| 392 | + '%s', // EVT_modified |
|
| 393 | 393 | '%s', |
| 394 | - '%s',// EVT_wp_user |
|
| 395 | - '%d',// post_parent |
|
| 396 | - '%d',// EVT_order |
|
| 397 | - '%s',// post_type |
|
| 398 | - '%s',// status |
|
| 394 | + '%s', // EVT_wp_user |
|
| 395 | + '%d', // post_parent |
|
| 396 | + '%d', // EVT_order |
|
| 397 | + '%s', // post_type |
|
| 398 | + '%s', // status |
|
| 399 | 399 | ); |
| 400 | 400 | $success = $wpdb->insert( |
| 401 | 401 | $this->_new_table, |
| 402 | 402 | $cols_n_values, |
| 403 | 403 | $datatypes |
| 404 | 404 | ); |
| 405 | - if (! $success) { |
|
| 405 | + if ( ! $success) { |
|
| 406 | 406 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_table, $cols_n_values, $datatypes)); |
| 407 | 407 | return 0; |
| 408 | 408 | } |
@@ -441,10 +441,10 @@ discard block |
||
| 441 | 441 | // ); |
| 442 | 442 | $default_reg_status = $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(isset($event_meta['default_payment_status']) ? $event_meta['default_payment_status'] : '', intval($old_event['require_pre_approval'])); |
| 443 | 443 | $cols_n_values = array( |
| 444 | - 'EVT_ID'=>$new_cpt_id,// EVT_ID_fk |
|
| 444 | + 'EVT_ID'=>$new_cpt_id, // EVT_ID_fk |
|
| 445 | 445 | 'EVT_display_desc'=> 'Y' == $old_event['display_desc'], |
| 446 | - 'EVT_display_ticket_selector'=> 'Y'== $old_event['display_reg_form'], |
|
| 447 | - 'EVT_visible_on'=> $this->get_migration_script()->convert_date_string_to_utc($this, $old_event, current_time('mysql'), $old_event['timezone_string']),// don't use the old 'visible_on', as it wasn't ever used |
|
| 446 | + 'EVT_display_ticket_selector'=> 'Y' == $old_event['display_reg_form'], |
|
| 447 | + 'EVT_visible_on'=> $this->get_migration_script()->convert_date_string_to_utc($this, $old_event, current_time('mysql'), $old_event['timezone_string']), // don't use the old 'visible_on', as it wasn't ever used |
|
| 448 | 448 | 'EVT_additional_limit'=> $old_event['allow_multiple'] == 'N' ? 1 : $old_event['additional_limit'], |
| 449 | 449 | 'EVT_default_registration_status' => $default_reg_status, |
| 450 | 450 | 'EVT_member_only'=>$old_event['member_only'], |
@@ -456,25 +456,25 @@ discard block |
||
| 456 | 456 | |
| 457 | 457 | ); |
| 458 | 458 | $datatypes = array( |
| 459 | - '%s',// EVT_ID |
|
| 460 | - '%d',// EVT_display_desc |
|
| 461 | - '%d',// EVT_display_ticket_selector |
|
| 462 | - '%s',// EVT_visible_on |
|
| 463 | - '%d',// EVT_additional_limit |
|
| 464 | - '%s',// EVT_default_registration_status |
|
| 465 | - '%d',// EVT_member_only |
|
| 466 | - '%s',// EVT_phone |
|
| 467 | - '%d',// EVT_allow_overflow |
|
| 468 | - '%s',// EVT_timezone_string |
|
| 469 | - '%s',// EVT_external_URL |
|
| 470 | - '%d',// EVT_donations |
|
| 459 | + '%s', // EVT_ID |
|
| 460 | + '%d', // EVT_display_desc |
|
| 461 | + '%d', // EVT_display_ticket_selector |
|
| 462 | + '%s', // EVT_visible_on |
|
| 463 | + '%d', // EVT_additional_limit |
|
| 464 | + '%s', // EVT_default_registration_status |
|
| 465 | + '%d', // EVT_member_only |
|
| 466 | + '%s', // EVT_phone |
|
| 467 | + '%d', // EVT_allow_overflow |
|
| 468 | + '%s', // EVT_timezone_string |
|
| 469 | + '%s', // EVT_external_URL |
|
| 470 | + '%d', // EVT_donations |
|
| 471 | 471 | ); |
| 472 | 472 | $success = $wpdb->insert( |
| 473 | 473 | $this->_new_meta_table, |
| 474 | 474 | $cols_n_values, |
| 475 | 475 | $datatypes |
| 476 | 476 | ); |
| 477 | - if (! $success) { |
|
| 477 | + if ( ! $success) { |
|
| 478 | 478 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $cols_n_values, $datatypes)); |
| 479 | 479 | return 0; |
| 480 | 480 | } |
@@ -508,7 +508,7 @@ discard block |
||
| 508 | 508 | $new_id = $this->_insert_venue_into_posts($old_event); |
| 509 | 509 | if ($new_id) { |
| 510 | 510 | $this->_insert_venue_into_meta_table($new_id, $old_event); |
| 511 | - $guid = isset($old_event['venue_image']) ? $old_event['venue_image'] : null; |
|
| 511 | + $guid = isset($old_event['venue_image']) ? $old_event['venue_image'] : null; |
|
| 512 | 512 | $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this); |
| 513 | 513 | } |
| 514 | 514 | // we don't bother recording the conversion from old events to venues as that |
@@ -534,10 +534,10 @@ discard block |
||
| 534 | 534 | 'VNU_city' => $old_event['city'], |
| 535 | 535 | 'VNU_zip' => $old_event['zip'], |
| 536 | 536 | 'post_title'=> $this->_get_venue_title_for_event($old_event), |
| 537 | - 'VNU_phone'=>$old_event['venue_phone'],// VNU_phone |
|
| 538 | - 'VNU_url'=>$old_event['venue_url'],// VNU_url |
|
| 539 | - 'VNU_virtual_phone'=>$old_event['virtual_phone'],// VNU_virtual_phone |
|
| 540 | - 'VNU_virtual_url'=>$old_event['virtual_url'],// VNU_virtual_url |
|
| 537 | + 'VNU_phone'=>$old_event['venue_phone'], // VNU_phone |
|
| 538 | + 'VNU_url'=>$old_event['venue_url'], // VNU_url |
|
| 539 | + 'VNU_virtual_phone'=>$old_event['virtual_phone'], // VNU_virtual_phone |
|
| 540 | + 'VNU_virtual_url'=>$old_event['virtual_url'], // VNU_virtual_url |
|
| 541 | 541 | ); |
| 542 | 542 | $sql_conditions = array(); |
| 543 | 543 | foreach ($conditions as $column => $value) { |
@@ -547,7 +547,7 @@ discard block |
||
| 547 | 547 | FROM |
| 548 | 548 | {$wpdb->posts} as p INNER JOIN |
| 549 | 549 | {$wpdb->prefix}esp_venue_meta as v ON p.ID = v.VNU_ID |
| 550 | - WHERE " . implode(" AND ", $sql_conditions) . " LIMIT 1"; |
|
| 550 | + WHERE ".implode(" AND ", $sql_conditions)." LIMIT 1"; |
|
| 551 | 551 | $id = $wpdb->get_var($query); |
| 552 | 552 | return $id; |
| 553 | 553 | } |
@@ -572,39 +572,39 @@ discard block |
||
| 572 | 572 | { |
| 573 | 573 | global $wpdb; |
| 574 | 574 | $insertion_array = array( |
| 575 | - 'post_title'=> $this->_get_venue_title_for_event($old_event),// VNU_name |
|
| 576 | - 'post_content'=>'',// VNU_desc |
|
| 577 | - 'post_name'=> $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-' . $old_event['event_name'])),// VNU_identifier |
|
| 578 | - 'post_date'=>current_time('mysql'),// VNU_created |
|
| 575 | + 'post_title'=> $this->_get_venue_title_for_event($old_event), // VNU_name |
|
| 576 | + 'post_content'=>'', // VNU_desc |
|
| 577 | + 'post_name'=> $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-'.$old_event['event_name'])), // VNU_identifier |
|
| 578 | + 'post_date'=>current_time('mysql'), // VNU_created |
|
| 579 | 579 | 'post_date_gmt'=>get_gmt_from_date(current_time('mysql')), |
| 580 | - 'post_excerpt'=>'',// VNU_short_desc arbitrary only 50 characters |
|
| 581 | - 'post_modified'=>current_time('mysql'),// VNU_modified |
|
| 580 | + 'post_excerpt'=>'', // VNU_short_desc arbitrary only 50 characters |
|
| 581 | + 'post_modified'=>current_time('mysql'), // VNU_modified |
|
| 582 | 582 | 'post_modified_gmt'=>get_gmt_from_date(current_time('mysql')), |
| 583 | - 'post_author'=>$old_event['wp_user'],// VNU_wp_user |
|
| 584 | - 'post_parent'=>0,// parent |
|
| 585 | - 'menu_order'=>0,// VNU_order |
|
| 583 | + 'post_author'=>$old_event['wp_user'], // VNU_wp_user |
|
| 584 | + 'post_parent'=>0, // parent |
|
| 585 | + 'menu_order'=>0, // VNU_order |
|
| 586 | 586 | 'post_type'=>'espresso_venues'// post_type |
| 587 | 587 | ); |
| 588 | 588 | $datatypes_array = array( |
| 589 | - '%s',// VNU_name |
|
| 590 | - '%s',// VNU_desc |
|
| 591 | - '%s',// VNU_identifier |
|
| 592 | - '%s',// VNU_created |
|
| 589 | + '%s', // VNU_name |
|
| 590 | + '%s', // VNU_desc |
|
| 591 | + '%s', // VNU_identifier |
|
| 592 | + '%s', // VNU_created |
|
| 593 | 593 | '%s', |
| 594 | - '%s',// VNU_short_desc |
|
| 595 | - '%s',// VNU_modified |
|
| 594 | + '%s', // VNU_short_desc |
|
| 595 | + '%s', // VNU_modified |
|
| 596 | 596 | '%s', |
| 597 | - '%d',// VNU_wp_user |
|
| 598 | - '%d',// parent |
|
| 599 | - '%d',// VNU_order |
|
| 600 | - '%s',// post_type |
|
| 597 | + '%d', // VNU_wp_user |
|
| 598 | + '%d', // parent |
|
| 599 | + '%d', // VNU_order |
|
| 600 | + '%s', // post_type |
|
| 601 | 601 | ); |
| 602 | 602 | $success = $wpdb->insert( |
| 603 | 603 | $wpdb->posts, |
| 604 | 604 | $insertion_array, |
| 605 | 605 | $datatypes_array |
| 606 | 606 | ); |
| 607 | - if (! $success) { |
|
| 607 | + if ( ! $success) { |
|
| 608 | 608 | $this->add_error( |
| 609 | 609 | $this->get_migration_script()->_create_error_message_for_db_insertion( |
| 610 | 610 | $this->_old_table, |
@@ -632,13 +632,13 @@ discard block |
||
| 632 | 632 | // assume the country is the same as the organization's old settings |
| 633 | 633 | $country_iso = $this->get_migration_script()->get_default_country_iso(); |
| 634 | 634 | // find the state from the venue, or the organization, or just guess california |
| 635 | - if (! $old_event['state']) { |
|
| 635 | + if ( ! $old_event['state']) { |
|
| 636 | 636 | $old_org_options = get_option('events_organization_settings'); |
| 637 | 637 | $state_name = stripslashes($old_org_options['organization_state']); |
| 638 | 638 | } else { |
| 639 | 639 | $state_name = $old_event['state']; |
| 640 | 640 | } |
| 641 | - if (! $state_name) { |
|
| 641 | + if ( ! $state_name) { |
|
| 642 | 642 | $state_name = 'CA'; |
| 643 | 643 | } |
| 644 | 644 | // get a state ID with the same name, if possible |
@@ -651,39 +651,39 @@ discard block |
||
| 651 | 651 | } |
| 652 | 652 | // now insert into meta table |
| 653 | 653 | $insertion_array = array( |
| 654 | - 'VNU_ID'=>$cpt_id,// VNU_ID_fk |
|
| 655 | - 'VNU_address'=>stripslashes($old_event['address']),// VNU_address |
|
| 656 | - 'VNU_address2'=>stripslashes($old_event['address2']),// VNU_address2 |
|
| 657 | - 'VNU_city'=>stripslashes($old_event['city']),// VNU_city |
|
| 658 | - 'STA_ID'=>$state_id,// STA_ID |
|
| 659 | - 'CNT_ISO'=>$country_iso,// CNT_ISO |
|
| 660 | - 'VNU_zip'=>$old_event['zip'],// VNU_zip |
|
| 661 | - 'VNU_phone'=>$old_event['venue_phone'],// VNU_phone |
|
| 662 | - 'VNU_capacity'=>-1,// VNU_capacity |
|
| 663 | - 'VNU_url'=>$old_event['venue_url'],// VNU_url |
|
| 664 | - 'VNU_virtual_phone'=>$old_event['virtual_phone'],// VNU_virtual_phone |
|
| 665 | - 'VNU_virtual_url'=>$old_event['virtual_url'],// VNU_virtual_url |
|
| 666 | - 'VNU_google_map_link'=>'',// VNU_google_map_link |
|
| 654 | + 'VNU_ID'=>$cpt_id, // VNU_ID_fk |
|
| 655 | + 'VNU_address'=>stripslashes($old_event['address']), // VNU_address |
|
| 656 | + 'VNU_address2'=>stripslashes($old_event['address2']), // VNU_address2 |
|
| 657 | + 'VNU_city'=>stripslashes($old_event['city']), // VNU_city |
|
| 658 | + 'STA_ID'=>$state_id, // STA_ID |
|
| 659 | + 'CNT_ISO'=>$country_iso, // CNT_ISO |
|
| 660 | + 'VNU_zip'=>$old_event['zip'], // VNU_zip |
|
| 661 | + 'VNU_phone'=>$old_event['venue_phone'], // VNU_phone |
|
| 662 | + 'VNU_capacity'=>-1, // VNU_capacity |
|
| 663 | + 'VNU_url'=>$old_event['venue_url'], // VNU_url |
|
| 664 | + 'VNU_virtual_phone'=>$old_event['virtual_phone'], // VNU_virtual_phone |
|
| 665 | + 'VNU_virtual_url'=>$old_event['virtual_url'], // VNU_virtual_url |
|
| 666 | + 'VNU_google_map_link'=>'', // VNU_google_map_link |
|
| 667 | 667 | 'VNU_enable_for_gmap'=>true // VNU_enable_for_gmap |
| 668 | 668 | ); |
| 669 | 669 | $datatypes = array( |
| 670 | - '%d',// VNU_ID_fk |
|
| 671 | - '%s',// VNU_address |
|
| 672 | - '%s',// VNU_address2 |
|
| 673 | - '%s',// VNU_city |
|
| 674 | - '%d',// STA_ID |
|
| 675 | - '%s',// CNT_ISO |
|
| 676 | - '%s',// VNU_zip |
|
| 677 | - '%s',// VNU_phone |
|
| 678 | - '%d',// VNU_capacity |
|
| 679 | - '%s',// VNU_url |
|
| 680 | - '%s',// VNU_virtual_phone |
|
| 681 | - '%s',// VNU_virtual_url |
|
| 682 | - '%s',// VNU_google_map_link |
|
| 683 | - '%d',// VNU_enable_for_gmap |
|
| 670 | + '%d', // VNU_ID_fk |
|
| 671 | + '%s', // VNU_address |
|
| 672 | + '%s', // VNU_address2 |
|
| 673 | + '%s', // VNU_city |
|
| 674 | + '%d', // STA_ID |
|
| 675 | + '%s', // CNT_ISO |
|
| 676 | + '%s', // VNU_zip |
|
| 677 | + '%s', // VNU_phone |
|
| 678 | + '%d', // VNU_capacity |
|
| 679 | + '%s', // VNU_url |
|
| 680 | + '%s', // VNU_virtual_phone |
|
| 681 | + '%s', // VNU_virtual_url |
|
| 682 | + '%s', // VNU_google_map_link |
|
| 683 | + '%d', // VNU_enable_for_gmap |
|
| 684 | 684 | ); |
| 685 | 685 | $success = $wpdb->insert($wpdb->prefix."esp_venue_meta", $insertion_array, $datatypes); |
| 686 | - if (! $success) { |
|
| 686 | + if ( ! $success) { |
|
| 687 | 687 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $insertion_array, $datatypes)); |
| 688 | 688 | return 0; |
| 689 | 689 | } |
@@ -700,11 +700,11 @@ discard block |
||
| 700 | 700 | private function _insert_new_venue_to_event($new_event_id, $new_venue_id) |
| 701 | 701 | { |
| 702 | 702 | global $wpdb; |
| 703 | - if (! $new_event_id) { |
|
| 703 | + if ( ! $new_event_id) { |
|
| 704 | 704 | $this->add_error(sprintf(__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $new_event_id)); |
| 705 | 705 | return 0; |
| 706 | 706 | } |
| 707 | - if (! $new_venue_id) { |
|
| 707 | + if ( ! $new_venue_id) { |
|
| 708 | 708 | $this->add_error(sprintf(__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $new_venue_id)); |
| 709 | 709 | return 0; |
| 710 | 710 | } |
@@ -714,12 +714,12 @@ discard block |
||
| 714 | 714 | 'EVV_primary'=>true |
| 715 | 715 | ); |
| 716 | 716 | $datatypes = array( |
| 717 | - '%d',// EVT_ID |
|
| 718 | - '%d',// VNU_ID |
|
| 719 | - '%d',// EVT_primary |
|
| 717 | + '%d', // EVT_ID |
|
| 718 | + '%d', // VNU_ID |
|
| 719 | + '%d', // EVT_primary |
|
| 720 | 720 | ); |
| 721 | 721 | $success = $wpdb->insert($wpdb->prefix."esp_event_venue", $cols_n_values, $datatypes); |
| 722 | - if (! $success) { |
|
| 722 | + if ( ! $success) { |
|
| 723 | 723 | $this->add_error( |
| 724 | 724 | $this->get_migration_script()->_create_error_message_for_db_insertion( |
| 725 | 725 | $this->_old_table, |
@@ -779,29 +779,29 @@ discard block |
||
| 779 | 779 | $start_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$start_date $start_time:00", $old_event_row['timezone_string']); |
| 780 | 780 | $end_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$end_date $end_time:00", $old_event_row['timezone_string']); |
| 781 | 781 | $cols_n_values = array( |
| 782 | - 'EVT_ID'=>$new_cpt_id,// EVT_ID |
|
| 783 | - 'DTT_EVT_start'=>$start_datetime_utc,// DTT_EVT_start |
|
| 784 | - 'DTT_EVT_end'=> $end_datetime_utc,// DTT_EVT_end |
|
| 785 | - 'DTT_reg_limit'=>intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'],// DTT_reg_limit |
|
| 786 | - 'DTT_sold'=>0,// note: we will increment this as registrations are added during the migration |
|
| 782 | + 'EVT_ID'=>$new_cpt_id, // EVT_ID |
|
| 783 | + 'DTT_EVT_start'=>$start_datetime_utc, // DTT_EVT_start |
|
| 784 | + 'DTT_EVT_end'=> $end_datetime_utc, // DTT_EVT_end |
|
| 785 | + 'DTT_reg_limit'=>intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'], // DTT_reg_limit |
|
| 786 | + 'DTT_sold'=>0, // note: we will increment this as registrations are added during the migration |
|
| 787 | 787 | // 'DTT_is_primary'=> 0 == $existing_datetimes ,//DTT_is_primary... if count==0, then we'll call it the 'primary' |
| 788 | - 'DTT_order'=> $existing_datetimes,// DTT_order, just give it the same order as the count of how many datetimes already exist |
|
| 788 | + 'DTT_order'=> $existing_datetimes, // DTT_order, just give it the same order as the count of how many datetimes already exist |
|
| 789 | 789 | 'DTT_parent'=>0, |
| 790 | 790 | 'DTT_deleted'=>false |
| 791 | 791 | ); |
| 792 | 792 | $datatypes = array( |
| 793 | - '%d',// EVT_Id |
|
| 794 | - '%s',// DTT_EVT_start |
|
| 795 | - '%s',// DTT_EVT_end |
|
| 796 | - '%d',// DTT_reg_limit |
|
| 797 | - '%d',// DTT_sold |
|
| 793 | + '%d', // EVT_Id |
|
| 794 | + '%s', // DTT_EVT_start |
|
| 795 | + '%s', // DTT_EVT_end |
|
| 796 | + '%d', // DTT_reg_limit |
|
| 797 | + '%d', // DTT_sold |
|
| 798 | 798 | // '%d',//DTT_is_primary |
| 799 | - '%d',// DTT_order |
|
| 800 | - '%d',// DTT_parent |
|
| 801 | - '%d',// DTT_deleted |
|
| 799 | + '%d', // DTT_order |
|
| 800 | + '%d', // DTT_parent |
|
| 801 | + '%d', // DTT_deleted |
|
| 802 | 802 | ); |
| 803 | 803 | $success = $wpdb->insert($this->_new_datetime_table, $cols_n_values, $datatypes); |
| 804 | - if (! $success) { |
|
| 804 | + if ( ! $success) { |
|
| 805 | 805 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_start_end_table, array_merge($old_event_row, $start_end_time_row), $this->_new_datetime_table, $cols_n_values, $datatypes)); |
| 806 | 806 | return 0; |
| 807 | 807 | } |
@@ -273,7 +273,6 @@ |
||
| 273 | 273 | /** |
| 274 | 274 | * Creates a 4.1 member price discount |
| 275 | 275 | * @global type $wpdb |
| 276 | - * @param type $old_price |
|
| 277 | 276 | * @return int |
| 278 | 277 | */ |
| 279 | 278 | private function _insert_new_global_surcharge_price($org_options) |
@@ -103,289 +103,289 @@ |
||
| 103 | 103 | class EE_DMS_4_1_0_org_options extends EE_Data_Migration_Script_Stage |
| 104 | 104 | { |
| 105 | 105 | |
| 106 | - public function _migration_step($num_items = 50) |
|
| 107 | - { |
|
| 106 | + public function _migration_step($num_items = 50) |
|
| 107 | + { |
|
| 108 | 108 | |
| 109 | - $items_actually_migrated = 0; |
|
| 110 | - $old_org_options = get_option('events_organization_settings'); |
|
| 111 | - foreach ($this->_org_options_we_know_how_to_migrate as $option_name) { |
|
| 112 | - // only bother migrating if there's a setting to migrate. Otherwise we'll just use the default |
|
| 113 | - if (isset($old_org_options[ $option_name ])) { |
|
| 114 | - $this->_handle_org_option($option_name, $old_org_options[ $option_name ]); |
|
| 115 | - } |
|
| 116 | - if ($option_name=='surcharge') { |
|
| 117 | - $this->_insert_new_global_surcharge_price($old_org_options); |
|
| 118 | - } |
|
| 119 | - $items_actually_migrated++; |
|
| 120 | - } |
|
| 109 | + $items_actually_migrated = 0; |
|
| 110 | + $old_org_options = get_option('events_organization_settings'); |
|
| 111 | + foreach ($this->_org_options_we_know_how_to_migrate as $option_name) { |
|
| 112 | + // only bother migrating if there's a setting to migrate. Otherwise we'll just use the default |
|
| 113 | + if (isset($old_org_options[ $option_name ])) { |
|
| 114 | + $this->_handle_org_option($option_name, $old_org_options[ $option_name ]); |
|
| 115 | + } |
|
| 116 | + if ($option_name=='surcharge') { |
|
| 117 | + $this->_insert_new_global_surcharge_price($old_org_options); |
|
| 118 | + } |
|
| 119 | + $items_actually_migrated++; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - $success = EE_Config::instance()->update_espresso_config(false, true); |
|
| 123 | - if (! $success) { |
|
| 124 | - $this->add_error(sprintf(__('Could not save EE Config during org options stage. Reason: %s', 'event_espresso'), EE_Error::get_notices(false))); |
|
| 125 | - EE_Error::overwrite_errors(); |
|
| 126 | - } |
|
| 127 | - EE_Network_Config::instance()->update_config(false, false); |
|
| 128 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
| 129 | - // we may have added new pages and this might be necessary |
|
| 130 | - flush_rewrite_rules(); |
|
| 131 | - $this->set_completed(); |
|
| 132 | - } |
|
| 133 | - return $items_actually_migrated; |
|
| 134 | - } |
|
| 135 | - public function _count_records_to_migrate() |
|
| 136 | - { |
|
| 137 | - $count_of_options_to_migrate = count($this->_org_options_we_know_how_to_migrate); |
|
| 138 | - return $count_of_options_to_migrate; |
|
| 139 | - } |
|
| 140 | - public function __construct() |
|
| 141 | - { |
|
| 142 | - $this->_pretty_name = __("Organization Options/Config", "event_espresso"); |
|
| 143 | - $this->_org_options_we_know_how_to_migrate = apply_filters('FHEE__EE_DMS_4_1_0_org_options__org_options_we_know_how_to_migrate', $this->_org_options_we_know_how_to_migrate); |
|
| 144 | - parent::__construct(); |
|
| 145 | - } |
|
| 122 | + $success = EE_Config::instance()->update_espresso_config(false, true); |
|
| 123 | + if (! $success) { |
|
| 124 | + $this->add_error(sprintf(__('Could not save EE Config during org options stage. Reason: %s', 'event_espresso'), EE_Error::get_notices(false))); |
|
| 125 | + EE_Error::overwrite_errors(); |
|
| 126 | + } |
|
| 127 | + EE_Network_Config::instance()->update_config(false, false); |
|
| 128 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
| 129 | + // we may have added new pages and this might be necessary |
|
| 130 | + flush_rewrite_rules(); |
|
| 131 | + $this->set_completed(); |
|
| 132 | + } |
|
| 133 | + return $items_actually_migrated; |
|
| 134 | + } |
|
| 135 | + public function _count_records_to_migrate() |
|
| 136 | + { |
|
| 137 | + $count_of_options_to_migrate = count($this->_org_options_we_know_how_to_migrate); |
|
| 138 | + return $count_of_options_to_migrate; |
|
| 139 | + } |
|
| 140 | + public function __construct() |
|
| 141 | + { |
|
| 142 | + $this->_pretty_name = __("Organization Options/Config", "event_espresso"); |
|
| 143 | + $this->_org_options_we_know_how_to_migrate = apply_filters('FHEE__EE_DMS_4_1_0_org_options__org_options_we_know_how_to_migrate', $this->_org_options_we_know_how_to_migrate); |
|
| 144 | + parent::__construct(); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - private function _handle_org_option($option_name, $value) |
|
| 148 | - { |
|
| 149 | - $c = EE_Config::instance(); |
|
| 150 | - $cn = EE_Network_Config::instance(); |
|
| 151 | - switch ($option_name) { |
|
| 152 | - case 'organization': |
|
| 153 | - $c->organization->name = $value; |
|
| 154 | - break; |
|
| 155 | - case 'organization_street1': |
|
| 156 | - $c->organization->address_1 = $value; |
|
| 157 | - break; |
|
| 158 | - case 'organization_street2': |
|
| 159 | - $c->organization->address_2 = $value; |
|
| 160 | - break; |
|
| 161 | - case 'organization_city': |
|
| 162 | - $c->organization->city = $value; |
|
| 163 | - break; |
|
| 164 | - case 'organization_state': |
|
| 165 | - try { |
|
| 166 | - $state = $this->get_migration_script()->get_or_create_state($value); |
|
| 167 | - $state_id = $state['STA_ID']; |
|
| 168 | - $c->organization->STA_ID = $state_id; |
|
| 169 | - } catch (EE_Error $e) { |
|
| 170 | - } |
|
| 171 | - break; |
|
| 172 | - case 'organization_zip': |
|
| 173 | - $c->organization->zip = $value; |
|
| 174 | - break; |
|
| 175 | - case 'contact_email': |
|
| 176 | - $c->organization->email = $value; |
|
| 177 | - break; |
|
| 178 | - case 'default_payment_status': |
|
| 179 | - $c->registration->default_STS_ID = $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID($value); |
|
| 180 | - break; |
|
| 181 | - case 'organization_country': |
|
| 182 | - $iso =$this->get_migration_script()->get_iso_from_3_1_country_id($value); |
|
| 183 | - $c->organization->CNT_ISO = $iso; |
|
| 184 | - $country_row = $this->get_migration_script()->get_or_create_country($iso); |
|
| 185 | - if (! $country_row) { |
|
| 186 | - $this->add_error(sprintf(__("Could not set country's currency config because no country exists for ISO %s", "event_espresso"), $iso)); |
|
| 187 | - } |
|
| 188 | - // can't use EE_Currency_Config's handy constructor because the models are off-limits right now (and it uses them) |
|
| 189 | - $c->currency->code = $country_row['CNT_cur_code']; // currency code: USD, CAD, EUR |
|
| 190 | - $c->currency->name = $country_row['CNT_cur_single']; // Dollar |
|
| 191 | - $c->currency->plural = $country_row['CNT_cur_plural']; // Dollars |
|
| 192 | - $c->currency->sign = $country_row['CNT_cur_sign']; // currency sign: $ |
|
| 193 | - $c->currency->sign_b4 = intval($country_row['CNT_cur_sign_b4']); // currency sign before or after: $TRUE or FALSE$ |
|
| 194 | - $c->currency->dec_plc = intval($country_row['CNT_cur_dec_plc']); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 195 | - $c->currency->dec_mrk = $country_row['CNT_cur_dec_mrk']; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 196 | - $c->currency->thsnds = $country_row['CNT_cur_thsnds']; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 147 | + private function _handle_org_option($option_name, $value) |
|
| 148 | + { |
|
| 149 | + $c = EE_Config::instance(); |
|
| 150 | + $cn = EE_Network_Config::instance(); |
|
| 151 | + switch ($option_name) { |
|
| 152 | + case 'organization': |
|
| 153 | + $c->organization->name = $value; |
|
| 154 | + break; |
|
| 155 | + case 'organization_street1': |
|
| 156 | + $c->organization->address_1 = $value; |
|
| 157 | + break; |
|
| 158 | + case 'organization_street2': |
|
| 159 | + $c->organization->address_2 = $value; |
|
| 160 | + break; |
|
| 161 | + case 'organization_city': |
|
| 162 | + $c->organization->city = $value; |
|
| 163 | + break; |
|
| 164 | + case 'organization_state': |
|
| 165 | + try { |
|
| 166 | + $state = $this->get_migration_script()->get_or_create_state($value); |
|
| 167 | + $state_id = $state['STA_ID']; |
|
| 168 | + $c->organization->STA_ID = $state_id; |
|
| 169 | + } catch (EE_Error $e) { |
|
| 170 | + } |
|
| 171 | + break; |
|
| 172 | + case 'organization_zip': |
|
| 173 | + $c->organization->zip = $value; |
|
| 174 | + break; |
|
| 175 | + case 'contact_email': |
|
| 176 | + $c->organization->email = $value; |
|
| 177 | + break; |
|
| 178 | + case 'default_payment_status': |
|
| 179 | + $c->registration->default_STS_ID = $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID($value); |
|
| 180 | + break; |
|
| 181 | + case 'organization_country': |
|
| 182 | + $iso =$this->get_migration_script()->get_iso_from_3_1_country_id($value); |
|
| 183 | + $c->organization->CNT_ISO = $iso; |
|
| 184 | + $country_row = $this->get_migration_script()->get_or_create_country($iso); |
|
| 185 | + if (! $country_row) { |
|
| 186 | + $this->add_error(sprintf(__("Could not set country's currency config because no country exists for ISO %s", "event_espresso"), $iso)); |
|
| 187 | + } |
|
| 188 | + // can't use EE_Currency_Config's handy constructor because the models are off-limits right now (and it uses them) |
|
| 189 | + $c->currency->code = $country_row['CNT_cur_code']; // currency code: USD, CAD, EUR |
|
| 190 | + $c->currency->name = $country_row['CNT_cur_single']; // Dollar |
|
| 191 | + $c->currency->plural = $country_row['CNT_cur_plural']; // Dollars |
|
| 192 | + $c->currency->sign = $country_row['CNT_cur_sign']; // currency sign: $ |
|
| 193 | + $c->currency->sign_b4 = intval($country_row['CNT_cur_sign_b4']); // currency sign before or after: $TRUE or FALSE$ |
|
| 194 | + $c->currency->dec_plc = intval($country_row['CNT_cur_dec_plc']); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 195 | + $c->currency->dec_mrk = $country_row['CNT_cur_dec_mrk']; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 196 | + $c->currency->thsnds = $country_row['CNT_cur_thsnds']; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 197 | 197 | // $c->currency = new EE_Currency_Config($c->organization->CNT_ISO);break; |
| 198 | 198 | // case 'currency_symbol': ignore the currency symbol. we'll just go by their country. |
| 199 | 199 | // $c->currency->sign = $value;break; |
| 200 | - case 'show_pending_payment_options': |
|
| 201 | - $c->registration->show_pending_payment_options = ($value == 'Y'); |
|
| 202 | - break; |
|
| 203 | - case 'display_address_in_regform': |
|
| 204 | - $c->template_settings->display_address_in_regform = ($value == 'Y'); |
|
| 205 | - break; |
|
| 206 | - case 'default_logo_url': |
|
| 207 | - $c->organization->logo_url = $value; |
|
| 208 | - break; |
|
| 209 | - case 'event_page_id': |
|
| 210 | - // also, find that post, and changes the shortcode in it from ESPRESSO_PAYMENTS |
|
| 211 | - // to ESPRESSO_THANK_YOU |
|
| 212 | - $reg_page_post = get_post($value); |
|
| 213 | - $reg_page_post->post_content = str_replace("[ESPRESSO_EVENTS]", "[ESPRESSO_CHECKOUT]", $reg_page_post->post_content); |
|
| 214 | - wp_update_post($reg_page_post); |
|
| 215 | - $c->core->reg_page_id = $value; |
|
| 216 | - break; |
|
| 217 | - case 'return_url': |
|
| 218 | - // also, find that post, and changes the shortcode in it from ESPRESSO_PAYMENTS |
|
| 219 | - // to ESPRESSO_THANK_YOU |
|
| 220 | - $thank_you_page_post = get_post($value); |
|
| 221 | - $thank_you_page_post->post_content = str_replace("[ESPRESSO_PAYMENTS]", "[ESPRESSO_THANK_YOU]", $thank_you_page_post->post_content); |
|
| 222 | - wp_update_post($thank_you_page_post); |
|
| 223 | - $c->core->thank_you_page_id = $value; |
|
| 224 | - break; |
|
| 225 | - case 'cancel_return': |
|
| 226 | - $c->core->cancel_page_id = $value; |
|
| 200 | + case 'show_pending_payment_options': |
|
| 201 | + $c->registration->show_pending_payment_options = ($value == 'Y'); |
|
| 202 | + break; |
|
| 203 | + case 'display_address_in_regform': |
|
| 204 | + $c->template_settings->display_address_in_regform = ($value == 'Y'); |
|
| 205 | + break; |
|
| 206 | + case 'default_logo_url': |
|
| 207 | + $c->organization->logo_url = $value; |
|
| 208 | + break; |
|
| 209 | + case 'event_page_id': |
|
| 210 | + // also, find that post, and changes the shortcode in it from ESPRESSO_PAYMENTS |
|
| 211 | + // to ESPRESSO_THANK_YOU |
|
| 212 | + $reg_page_post = get_post($value); |
|
| 213 | + $reg_page_post->post_content = str_replace("[ESPRESSO_EVENTS]", "[ESPRESSO_CHECKOUT]", $reg_page_post->post_content); |
|
| 214 | + wp_update_post($reg_page_post); |
|
| 215 | + $c->core->reg_page_id = $value; |
|
| 216 | + break; |
|
| 217 | + case 'return_url': |
|
| 218 | + // also, find that post, and changes the shortcode in it from ESPRESSO_PAYMENTS |
|
| 219 | + // to ESPRESSO_THANK_YOU |
|
| 220 | + $thank_you_page_post = get_post($value); |
|
| 221 | + $thank_you_page_post->post_content = str_replace("[ESPRESSO_PAYMENTS]", "[ESPRESSO_THANK_YOU]", $thank_you_page_post->post_content); |
|
| 222 | + wp_update_post($thank_you_page_post); |
|
| 223 | + $c->core->thank_you_page_id = $value; |
|
| 224 | + break; |
|
| 225 | + case 'cancel_return': |
|
| 226 | + $c->core->cancel_page_id = $value; |
|
| 227 | 227 | |
| 228 | - break; |
|
| 229 | - case 'notify_url': |
|
| 230 | - $c->core->txn_page_id = $value; |
|
| 231 | - break; |
|
| 232 | - case 'use_captcha': |
|
| 233 | - $c->registration->use_captcha = ($value == 'Y'); |
|
| 234 | - break; |
|
| 235 | - case 'recaptcha_publickey': |
|
| 236 | - $c->registration->recaptcha_publickey = $value; |
|
| 237 | - break; |
|
| 238 | - case 'recaptcha_privatekey': |
|
| 239 | - $c->registration->recaptcha_privatekey = $value; |
|
| 240 | - break; |
|
| 241 | - case 'recaptcha_theme': |
|
| 242 | - $c->registration->recaptcha_theme = $value; |
|
| 243 | - break; |
|
| 244 | - case 'recaptcha_width': |
|
| 245 | - $c->registration->recaptcha_width = $value; |
|
| 246 | - break; |
|
| 247 | - case 'recaptcha_language': |
|
| 248 | - $c->registration->recaptcha_language = $value; |
|
| 249 | - break; |
|
| 250 | - case 'espresso_dashboard_widget': |
|
| 251 | - $c->admin->use_dashboard_widget = ($value == 'Y'); |
|
| 252 | - break; |
|
| 253 | - case 'use_personnel_manager': |
|
| 254 | - $c->admin->use_personnel_manager = ($value == 'Y'); |
|
| 255 | - break; |
|
| 256 | - case 'use_event_timezones': |
|
| 257 | - $c->admin->use_event_timezones = ($value == 'Y'); |
|
| 258 | - break; |
|
| 259 | - case 'full_logging': |
|
| 260 | - $c->admin->use_full_logging = ($value == 'Y'); |
|
| 261 | - break; |
|
| 262 | - case 'affiliate_id': |
|
| 263 | - $c->admin->affiliate_id = $value; |
|
| 264 | - break; |
|
| 265 | - case 'site_license_key': |
|
| 266 | - $cn->core->site_license_key = $value; |
|
| 267 | - break; |
|
| 268 | - default: |
|
| 269 | - do_action('AHEE__EE_DMS_4_1_0__handle_org_option', $option_name, $value); |
|
| 270 | - } |
|
| 271 | - } |
|
| 228 | + break; |
|
| 229 | + case 'notify_url': |
|
| 230 | + $c->core->txn_page_id = $value; |
|
| 231 | + break; |
|
| 232 | + case 'use_captcha': |
|
| 233 | + $c->registration->use_captcha = ($value == 'Y'); |
|
| 234 | + break; |
|
| 235 | + case 'recaptcha_publickey': |
|
| 236 | + $c->registration->recaptcha_publickey = $value; |
|
| 237 | + break; |
|
| 238 | + case 'recaptcha_privatekey': |
|
| 239 | + $c->registration->recaptcha_privatekey = $value; |
|
| 240 | + break; |
|
| 241 | + case 'recaptcha_theme': |
|
| 242 | + $c->registration->recaptcha_theme = $value; |
|
| 243 | + break; |
|
| 244 | + case 'recaptcha_width': |
|
| 245 | + $c->registration->recaptcha_width = $value; |
|
| 246 | + break; |
|
| 247 | + case 'recaptcha_language': |
|
| 248 | + $c->registration->recaptcha_language = $value; |
|
| 249 | + break; |
|
| 250 | + case 'espresso_dashboard_widget': |
|
| 251 | + $c->admin->use_dashboard_widget = ($value == 'Y'); |
|
| 252 | + break; |
|
| 253 | + case 'use_personnel_manager': |
|
| 254 | + $c->admin->use_personnel_manager = ($value == 'Y'); |
|
| 255 | + break; |
|
| 256 | + case 'use_event_timezones': |
|
| 257 | + $c->admin->use_event_timezones = ($value == 'Y'); |
|
| 258 | + break; |
|
| 259 | + case 'full_logging': |
|
| 260 | + $c->admin->use_full_logging = ($value == 'Y'); |
|
| 261 | + break; |
|
| 262 | + case 'affiliate_id': |
|
| 263 | + $c->admin->affiliate_id = $value; |
|
| 264 | + break; |
|
| 265 | + case 'site_license_key': |
|
| 266 | + $cn->core->site_license_key = $value; |
|
| 267 | + break; |
|
| 268 | + default: |
|
| 269 | + do_action('AHEE__EE_DMS_4_1_0__handle_org_option', $option_name, $value); |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | 272 | |
| 273 | - /** |
|
| 274 | - * Creates a 4.1 member price discount |
|
| 275 | - * @global type $wpdb |
|
| 276 | - * @param type $old_price |
|
| 277 | - * @return int |
|
| 278 | - */ |
|
| 279 | - private function _insert_new_global_surcharge_price($org_options) |
|
| 280 | - { |
|
| 281 | - $amount = floatval($org_options['surcharge']); |
|
| 282 | - // dont createa a price if the surcharge is 0 |
|
| 283 | - if ($amount <=.01) { |
|
| 284 | - return 0; |
|
| 285 | - } |
|
| 286 | - if ($org_options['surcharge_type'] == 'flat_rate') { |
|
| 287 | - $price_type = EE_DMS_4_1_0_prices::price_type_flat_surcharge; |
|
| 288 | - } else { |
|
| 289 | - $price_type = EE_DMS_4_1_0_prices::price_type_percent_surcharge; |
|
| 290 | - } |
|
| 291 | - global $wpdb; |
|
| 292 | - $cols_n_values = array( |
|
| 293 | - 'PRT_ID'=>$price_type, |
|
| 294 | - 'PRC_amount'=>$amount, |
|
| 295 | - 'PRC_name'=> $org_options['surcharge_text'], |
|
| 296 | - 'PRC_is_default'=>true, |
|
| 297 | - 'PRC_overrides'=>false, |
|
| 298 | - 'PRC_order'=>100, |
|
| 299 | - 'PRC_deleted'=>false, |
|
| 300 | - 'PRC_parent'=>null |
|
| 273 | + /** |
|
| 274 | + * Creates a 4.1 member price discount |
|
| 275 | + * @global type $wpdb |
|
| 276 | + * @param type $old_price |
|
| 277 | + * @return int |
|
| 278 | + */ |
|
| 279 | + private function _insert_new_global_surcharge_price($org_options) |
|
| 280 | + { |
|
| 281 | + $amount = floatval($org_options['surcharge']); |
|
| 282 | + // dont createa a price if the surcharge is 0 |
|
| 283 | + if ($amount <=.01) { |
|
| 284 | + return 0; |
|
| 285 | + } |
|
| 286 | + if ($org_options['surcharge_type'] == 'flat_rate') { |
|
| 287 | + $price_type = EE_DMS_4_1_0_prices::price_type_flat_surcharge; |
|
| 288 | + } else { |
|
| 289 | + $price_type = EE_DMS_4_1_0_prices::price_type_percent_surcharge; |
|
| 290 | + } |
|
| 291 | + global $wpdb; |
|
| 292 | + $cols_n_values = array( |
|
| 293 | + 'PRT_ID'=>$price_type, |
|
| 294 | + 'PRC_amount'=>$amount, |
|
| 295 | + 'PRC_name'=> $org_options['surcharge_text'], |
|
| 296 | + 'PRC_is_default'=>true, |
|
| 297 | + 'PRC_overrides'=>false, |
|
| 298 | + 'PRC_order'=>100, |
|
| 299 | + 'PRC_deleted'=>false, |
|
| 300 | + 'PRC_parent'=>null |
|
| 301 | 301 | |
| 302 | - ); |
|
| 303 | - $datatypes = array( |
|
| 304 | - '%d',// PRT_ID |
|
| 305 | - '%f',// PRT_amount |
|
| 306 | - '%s',// PRC_name |
|
| 307 | - '%d',// PRC_is_default |
|
| 308 | - '%d',// PRC_overrides |
|
| 309 | - '%d',// PRC_order |
|
| 310 | - '%d',// PRC_deleted |
|
| 311 | - '%d',// PRC_parent |
|
| 312 | - ); |
|
| 313 | - $price_table = $wpdb->prefix."esp_price"; |
|
| 314 | - $success = $wpdb->insert($price_table, $cols_n_values, $datatypes); |
|
| 315 | - if (! $success) { |
|
| 316 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion( |
|
| 317 | - 'org_options', |
|
| 318 | - array( |
|
| 319 | - 'surcharge'=>$org_options['surcharge'], |
|
| 320 | - 'surcharge_type'=>$org_options['surcharge_type'], |
|
| 321 | - 'surcharge_text'=>$org_options['surcharge_text']), |
|
| 322 | - $price_table, |
|
| 323 | - $cols_n_values, |
|
| 324 | - $datatypes |
|
| 325 | - )); |
|
| 326 | - return 0; |
|
| 327 | - } |
|
| 328 | - $new_id = $wpdb->insert_id; |
|
| 329 | - return $new_id; |
|
| 330 | - } |
|
| 302 | + ); |
|
| 303 | + $datatypes = array( |
|
| 304 | + '%d',// PRT_ID |
|
| 305 | + '%f',// PRT_amount |
|
| 306 | + '%s',// PRC_name |
|
| 307 | + '%d',// PRC_is_default |
|
| 308 | + '%d',// PRC_overrides |
|
| 309 | + '%d',// PRC_order |
|
| 310 | + '%d',// PRC_deleted |
|
| 311 | + '%d',// PRC_parent |
|
| 312 | + ); |
|
| 313 | + $price_table = $wpdb->prefix."esp_price"; |
|
| 314 | + $success = $wpdb->insert($price_table, $cols_n_values, $datatypes); |
|
| 315 | + if (! $success) { |
|
| 316 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion( |
|
| 317 | + 'org_options', |
|
| 318 | + array( |
|
| 319 | + 'surcharge'=>$org_options['surcharge'], |
|
| 320 | + 'surcharge_type'=>$org_options['surcharge_type'], |
|
| 321 | + 'surcharge_text'=>$org_options['surcharge_text']), |
|
| 322 | + $price_table, |
|
| 323 | + $cols_n_values, |
|
| 324 | + $datatypes |
|
| 325 | + )); |
|
| 326 | + return 0; |
|
| 327 | + } |
|
| 328 | + $new_id = $wpdb->insert_id; |
|
| 329 | + return $new_id; |
|
| 330 | + } |
|
| 331 | 331 | |
| 332 | - protected $_org_options_we_know_how_to_migrate = array( |
|
| 333 | - 'organization', |
|
| 334 | - 'organization_street1', |
|
| 335 | - 'organization_street2', |
|
| 336 | - 'organization_city', |
|
| 337 | - 'organization_state', |
|
| 338 | - 'organization_zip', |
|
| 339 | - 'contact_email', |
|
| 340 | - 'default_mail', |
|
| 341 | - 'payment_subject', |
|
| 342 | - 'payment_message', |
|
| 343 | - 'message', |
|
| 344 | - 'default_payment_status', |
|
| 345 | - 'surcharge',// unused? |
|
| 346 | - 'country_id',// unused? |
|
| 347 | - 'organization_country', |
|
| 332 | + protected $_org_options_we_know_how_to_migrate = array( |
|
| 333 | + 'organization', |
|
| 334 | + 'organization_street1', |
|
| 335 | + 'organization_street2', |
|
| 336 | + 'organization_city', |
|
| 337 | + 'organization_state', |
|
| 338 | + 'organization_zip', |
|
| 339 | + 'contact_email', |
|
| 340 | + 'default_mail', |
|
| 341 | + 'payment_subject', |
|
| 342 | + 'payment_message', |
|
| 343 | + 'message', |
|
| 344 | + 'default_payment_status', |
|
| 345 | + 'surcharge',// unused? |
|
| 346 | + 'country_id',// unused? |
|
| 347 | + 'organization_country', |
|
| 348 | 348 | // 'currency_symbol', |
| 349 | - 'expire_on_registration_end', |
|
| 350 | - 'email_before_payment', |
|
| 351 | - 'email_fancy_headers', |
|
| 352 | - 'enable_default_style', |
|
| 353 | - 'event_ssl_active', |
|
| 354 | - 'selected_style', |
|
| 355 | - 'show_pending_payment_options', |
|
| 356 | - 'show_reg_footer', |
|
| 357 | - 'skip_confirmation_page', |
|
| 358 | - 'allow_mer_discounts',// no equiv |
|
| 359 | - 'allow_mer_vouchers',// no equiv |
|
| 360 | - 'display_short_description_in_event_list', |
|
| 361 | - 'display_description_on_multi_reg_page', |
|
| 362 | - 'display_address_in_event_list', |
|
| 363 | - 'display_address_in_regform', |
|
| 364 | - 'use_custom_post_types',// no equiv |
|
| 365 | - 'display_ical_download', |
|
| 366 | - 'display_featured_image', |
|
| 367 | - 'themeroller', |
|
| 368 | - 'default_logo_url', |
|
| 369 | - 'event_page_id', |
|
| 370 | - 'return_url', |
|
| 371 | - 'cancel_return', |
|
| 372 | - 'notify_url', |
|
| 373 | - 'events_in_dashboard', |
|
| 374 | - 'use_captcha', |
|
| 375 | - 'recaptcha_publickey', |
|
| 376 | - 'recaptcha_privatekey', |
|
| 377 | - 'recaptcha_theme', |
|
| 378 | - 'recaptcha_width', |
|
| 379 | - 'recaptcha_language', |
|
| 380 | - 'espresso_dashboard_widget', |
|
| 381 | - 'time_reg_limit', |
|
| 349 | + 'expire_on_registration_end', |
|
| 350 | + 'email_before_payment', |
|
| 351 | + 'email_fancy_headers', |
|
| 352 | + 'enable_default_style', |
|
| 353 | + 'event_ssl_active', |
|
| 354 | + 'selected_style', |
|
| 355 | + 'show_pending_payment_options', |
|
| 356 | + 'show_reg_footer', |
|
| 357 | + 'skip_confirmation_page', |
|
| 358 | + 'allow_mer_discounts',// no equiv |
|
| 359 | + 'allow_mer_vouchers',// no equiv |
|
| 360 | + 'display_short_description_in_event_list', |
|
| 361 | + 'display_description_on_multi_reg_page', |
|
| 362 | + 'display_address_in_event_list', |
|
| 363 | + 'display_address_in_regform', |
|
| 364 | + 'use_custom_post_types',// no equiv |
|
| 365 | + 'display_ical_download', |
|
| 366 | + 'display_featured_image', |
|
| 367 | + 'themeroller', |
|
| 368 | + 'default_logo_url', |
|
| 369 | + 'event_page_id', |
|
| 370 | + 'return_url', |
|
| 371 | + 'cancel_return', |
|
| 372 | + 'notify_url', |
|
| 373 | + 'events_in_dashboard', |
|
| 374 | + 'use_captcha', |
|
| 375 | + 'recaptcha_publickey', |
|
| 376 | + 'recaptcha_privatekey', |
|
| 377 | + 'recaptcha_theme', |
|
| 378 | + 'recaptcha_width', |
|
| 379 | + 'recaptcha_language', |
|
| 380 | + 'espresso_dashboard_widget', |
|
| 381 | + 'time_reg_limit', |
|
| 382 | 382 | // 'use_attendee_pre_approval', removed in 4.1- instead this is factored into the default reg status |
| 383 | - 'use_personnel_manager',// no equiv |
|
| 384 | - 'use_event_timezones', |
|
| 385 | - 'full_logging', |
|
| 386 | - 'surcharge_type',// unused |
|
| 387 | - 'surcharge_text',// unused |
|
| 388 | - 'affiliate_id', |
|
| 389 | - 'site_license_key', |
|
| 390 | - ); |
|
| 383 | + 'use_personnel_manager',// no equiv |
|
| 384 | + 'use_event_timezones', |
|
| 385 | + 'full_logging', |
|
| 386 | + 'surcharge_type',// unused |
|
| 387 | + 'surcharge_text',// unused |
|
| 388 | + 'affiliate_id', |
|
| 389 | + 'site_license_key', |
|
| 390 | + ); |
|
| 391 | 391 | } |
@@ -110,17 +110,17 @@ discard block |
||
| 110 | 110 | $old_org_options = get_option('events_organization_settings'); |
| 111 | 111 | foreach ($this->_org_options_we_know_how_to_migrate as $option_name) { |
| 112 | 112 | // only bother migrating if there's a setting to migrate. Otherwise we'll just use the default |
| 113 | - if (isset($old_org_options[ $option_name ])) { |
|
| 114 | - $this->_handle_org_option($option_name, $old_org_options[ $option_name ]); |
|
| 113 | + if (isset($old_org_options[$option_name])) { |
|
| 114 | + $this->_handle_org_option($option_name, $old_org_options[$option_name]); |
|
| 115 | 115 | } |
| 116 | - if ($option_name=='surcharge') { |
|
| 116 | + if ($option_name == 'surcharge') { |
|
| 117 | 117 | $this->_insert_new_global_surcharge_price($old_org_options); |
| 118 | 118 | } |
| 119 | 119 | $items_actually_migrated++; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | $success = EE_Config::instance()->update_espresso_config(false, true); |
| 123 | - if (! $success) { |
|
| 123 | + if ( ! $success) { |
|
| 124 | 124 | $this->add_error(sprintf(__('Could not save EE Config during org options stage. Reason: %s', 'event_espresso'), EE_Error::get_notices(false))); |
| 125 | 125 | EE_Error::overwrite_errors(); |
| 126 | 126 | } |
@@ -176,24 +176,24 @@ discard block |
||
| 176 | 176 | $c->organization->email = $value; |
| 177 | 177 | break; |
| 178 | 178 | case 'default_payment_status': |
| 179 | - $c->registration->default_STS_ID = $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID($value); |
|
| 179 | + $c->registration->default_STS_ID = $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID($value); |
|
| 180 | 180 | break; |
| 181 | 181 | case 'organization_country': |
| 182 | - $iso =$this->get_migration_script()->get_iso_from_3_1_country_id($value); |
|
| 182 | + $iso = $this->get_migration_script()->get_iso_from_3_1_country_id($value); |
|
| 183 | 183 | $c->organization->CNT_ISO = $iso; |
| 184 | 184 | $country_row = $this->get_migration_script()->get_or_create_country($iso); |
| 185 | - if (! $country_row) { |
|
| 185 | + if ( ! $country_row) { |
|
| 186 | 186 | $this->add_error(sprintf(__("Could not set country's currency config because no country exists for ISO %s", "event_espresso"), $iso)); |
| 187 | 187 | } |
| 188 | 188 | // can't use EE_Currency_Config's handy constructor because the models are off-limits right now (and it uses them) |
| 189 | - $c->currency->code = $country_row['CNT_cur_code']; // currency code: USD, CAD, EUR |
|
| 190 | - $c->currency->name = $country_row['CNT_cur_single']; // Dollar |
|
| 191 | - $c->currency->plural = $country_row['CNT_cur_plural']; // Dollars |
|
| 192 | - $c->currency->sign = $country_row['CNT_cur_sign']; // currency sign: $ |
|
| 193 | - $c->currency->sign_b4 = intval($country_row['CNT_cur_sign_b4']); // currency sign before or after: $TRUE or FALSE$ |
|
| 194 | - $c->currency->dec_plc = intval($country_row['CNT_cur_dec_plc']); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 195 | - $c->currency->dec_mrk = $country_row['CNT_cur_dec_mrk']; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 196 | - $c->currency->thsnds = $country_row['CNT_cur_thsnds']; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 189 | + $c->currency->code = $country_row['CNT_cur_code']; // currency code: USD, CAD, EUR |
|
| 190 | + $c->currency->name = $country_row['CNT_cur_single']; // Dollar |
|
| 191 | + $c->currency->plural = $country_row['CNT_cur_plural']; // Dollars |
|
| 192 | + $c->currency->sign = $country_row['CNT_cur_sign']; // currency sign: $ |
|
| 193 | + $c->currency->sign_b4 = intval($country_row['CNT_cur_sign_b4']); // currency sign before or after: $TRUE or FALSE$ |
|
| 194 | + $c->currency->dec_plc = intval($country_row['CNT_cur_dec_plc']); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 195 | + $c->currency->dec_mrk = $country_row['CNT_cur_dec_mrk']; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 196 | + $c->currency->thsnds = $country_row['CNT_cur_thsnds']; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 197 | 197 | // $c->currency = new EE_Currency_Config($c->organization->CNT_ISO);break; |
| 198 | 198 | // case 'currency_symbol': ignore the currency symbol. we'll just go by their country. |
| 199 | 199 | // $c->currency->sign = $value;break; |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | { |
| 281 | 281 | $amount = floatval($org_options['surcharge']); |
| 282 | 282 | // dont createa a price if the surcharge is 0 |
| 283 | - if ($amount <=.01) { |
|
| 283 | + if ($amount <= .01) { |
|
| 284 | 284 | return 0; |
| 285 | 285 | } |
| 286 | 286 | if ($org_options['surcharge_type'] == 'flat_rate') { |
@@ -301,18 +301,18 @@ discard block |
||
| 301 | 301 | |
| 302 | 302 | ); |
| 303 | 303 | $datatypes = array( |
| 304 | - '%d',// PRT_ID |
|
| 305 | - '%f',// PRT_amount |
|
| 306 | - '%s',// PRC_name |
|
| 307 | - '%d',// PRC_is_default |
|
| 308 | - '%d',// PRC_overrides |
|
| 309 | - '%d',// PRC_order |
|
| 310 | - '%d',// PRC_deleted |
|
| 311 | - '%d',// PRC_parent |
|
| 304 | + '%d', // PRT_ID |
|
| 305 | + '%f', // PRT_amount |
|
| 306 | + '%s', // PRC_name |
|
| 307 | + '%d', // PRC_is_default |
|
| 308 | + '%d', // PRC_overrides |
|
| 309 | + '%d', // PRC_order |
|
| 310 | + '%d', // PRC_deleted |
|
| 311 | + '%d', // PRC_parent |
|
| 312 | 312 | ); |
| 313 | 313 | $price_table = $wpdb->prefix."esp_price"; |
| 314 | 314 | $success = $wpdb->insert($price_table, $cols_n_values, $datatypes); |
| 315 | - if (! $success) { |
|
| 315 | + if ( ! $success) { |
|
| 316 | 316 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion( |
| 317 | 317 | 'org_options', |
| 318 | 318 | array( |
@@ -342,8 +342,8 @@ discard block |
||
| 342 | 342 | 'payment_message', |
| 343 | 343 | 'message', |
| 344 | 344 | 'default_payment_status', |
| 345 | - 'surcharge',// unused? |
|
| 346 | - 'country_id',// unused? |
|
| 345 | + 'surcharge', // unused? |
|
| 346 | + 'country_id', // unused? |
|
| 347 | 347 | 'organization_country', |
| 348 | 348 | // 'currency_symbol', |
| 349 | 349 | 'expire_on_registration_end', |
@@ -355,13 +355,13 @@ discard block |
||
| 355 | 355 | 'show_pending_payment_options', |
| 356 | 356 | 'show_reg_footer', |
| 357 | 357 | 'skip_confirmation_page', |
| 358 | - 'allow_mer_discounts',// no equiv |
|
| 359 | - 'allow_mer_vouchers',// no equiv |
|
| 358 | + 'allow_mer_discounts', // no equiv |
|
| 359 | + 'allow_mer_vouchers', // no equiv |
|
| 360 | 360 | 'display_short_description_in_event_list', |
| 361 | 361 | 'display_description_on_multi_reg_page', |
| 362 | 362 | 'display_address_in_event_list', |
| 363 | 363 | 'display_address_in_regform', |
| 364 | - 'use_custom_post_types',// no equiv |
|
| 364 | + 'use_custom_post_types', // no equiv |
|
| 365 | 365 | 'display_ical_download', |
| 366 | 366 | 'display_featured_image', |
| 367 | 367 | 'themeroller', |
@@ -380,11 +380,11 @@ discard block |
||
| 380 | 380 | 'espresso_dashboard_widget', |
| 381 | 381 | 'time_reg_limit', |
| 382 | 382 | // 'use_attendee_pre_approval', removed in 4.1- instead this is factored into the default reg status |
| 383 | - 'use_personnel_manager',// no equiv |
|
| 383 | + 'use_personnel_manager', // no equiv |
|
| 384 | 384 | 'use_event_timezones', |
| 385 | 385 | 'full_logging', |
| 386 | - 'surcharge_type',// unused |
|
| 387 | - 'surcharge_text',// unused |
|
| 386 | + 'surcharge_type', // unused |
|
| 387 | + 'surcharge_text', // unused |
|
| 388 | 388 | 'affiliate_id', |
| 389 | 389 | 'site_license_key', |
| 390 | 390 | ); |
@@ -349,8 +349,8 @@ discard block |
||
| 349 | 349 | /** |
| 350 | 350 | * Adds a join between a ticket and a price |
| 351 | 351 | * @global type $wpdb |
| 352 | - * @param type $new_ticket_id |
|
| 353 | - * @param type $new_price_id |
|
| 352 | + * @param integer $new_ticket_id |
|
| 353 | + * @param integer $new_price_id |
|
| 354 | 354 | * @return int |
| 355 | 355 | */ |
| 356 | 356 | private function _insert_ticket_price_relation($new_ticket_id, $new_price_id) |
@@ -376,8 +376,7 @@ discard block |
||
| 376 | 376 | /** |
| 377 | 377 | * Adds a join between a ticket and a datetime |
| 378 | 378 | * @global type $wpdb |
| 379 | - * @param type $new_ticket_id |
|
| 380 | - * @param type $new_price_id |
|
| 379 | + * @param integer $new_ticket_id |
|
| 381 | 380 | * @return int |
| 382 | 381 | */ |
| 383 | 382 | private function _insert_datetime_ticket_relation($new_datetime_id, $new_ticket_id) |
@@ -87,56 +87,56 @@ 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->_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->_extra_where_sql = ' AS p |
|
| 110 | 110 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON p.event_id=e.id |
| 111 | 111 | WHERE e.event_status!="D"'; |
| 112 | - $this->_new_price_table = $wpdb->prefix."esp_price"; |
|
| 113 | - $this->_new_ticket_table = $wpdb->prefix."esp_ticket"; |
|
| 114 | - $this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price"; |
|
| 115 | - $this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket"; |
|
| 116 | - parent::__construct(); |
|
| 117 | - } |
|
| 118 | - protected function _migrate_old_row($old_row) |
|
| 119 | - { |
|
| 120 | - // create the base price |
|
| 121 | - $new_price_id = $this->_insert_new_price($old_row); |
|
| 122 | - // create the member discount if there is any |
|
| 123 | - // commented-out because we may actually NOT be supporting this in 4.1 |
|
| 112 | + $this->_new_price_table = $wpdb->prefix."esp_price"; |
|
| 113 | + $this->_new_ticket_table = $wpdb->prefix."esp_ticket"; |
|
| 114 | + $this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price"; |
|
| 115 | + $this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket"; |
|
| 116 | + parent::__construct(); |
|
| 117 | + } |
|
| 118 | + protected function _migrate_old_row($old_row) |
|
| 119 | + { |
|
| 120 | + // create the base price |
|
| 121 | + $new_price_id = $this->_insert_new_price($old_row); |
|
| 122 | + // create the member discount if there is any |
|
| 123 | + // commented-out because we may actually NOT be supporting this in 4.1 |
|
| 124 | 124 | // if($old_row['event_cost'] != $old_row['member_price']){ |
| 125 | 125 | // $member_price_discount_id = $this->_insert_new_member_price($old_row); |
| 126 | 126 | // }else{ |
| 127 | 127 | // $member_price_discount_id = 0; |
| 128 | 128 | // } |
| 129 | - // create the surcharge if there is any |
|
| 130 | - if (floatval($old_row['surcharge']) >= 0.01) { |
|
| 131 | - $surcharge_price_id = $this->_insert_new_surcharge_price($old_row); |
|
| 132 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id,$surcharge_price_id)); |
|
| 133 | - } else { |
|
| 134 | - $surcharge_price_id = 0; |
|
| 135 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id)); |
|
| 136 | - } |
|
| 137 | - // 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. |
|
| 138 | - // if the latter were the case, then we'd create a separate ticket for each datetime and ahve their association be one-to-one) |
|
| 139 | - // create ticket |
|
| 129 | + // create the surcharge if there is any |
|
| 130 | + if (floatval($old_row['surcharge']) >= 0.01) { |
|
| 131 | + $surcharge_price_id = $this->_insert_new_surcharge_price($old_row); |
|
| 132 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id,$surcharge_price_id)); |
|
| 133 | + } else { |
|
| 134 | + $surcharge_price_id = 0; |
|
| 135 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id)); |
|
| 136 | + } |
|
| 137 | + // 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. |
|
| 138 | + // if the latter were the case, then we'd create a separate ticket for each datetime and ahve their association be one-to-one) |
|
| 139 | + // create ticket |
|
| 140 | 140 | // $ticket_id = $this->_insert_new_ticket($old_row); |
| 141 | 141 | // if($ticket_id){ |
| 142 | 142 | // $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_ticket_table, $ticket_id); |
@@ -148,62 +148,62 @@ discard block |
||
| 148 | 148 | // $this->_insert_datetime_ticket_relation($new_datetime_id, $ticket_id); |
| 149 | 149 | // } |
| 150 | 150 | // } |
| 151 | - // create a ticket for each old price -old datetime combo |
|
| 152 | - $tickets_for_old_price = array(); |
|
| 153 | - foreach ($this->_get_datetime_ids_for_old_event_id($old_row['event_id']) as $new_datetime_id) { |
|
| 154 | - $ticket_id = $this->_insert_new_ticket($old_row); |
|
| 155 | - $tickets_for_old_price[] = $ticket_id; |
|
| 156 | - // associate to old prices |
|
| 157 | - $this->_insert_ticket_price_relation($ticket_id, $new_price_id); |
|
| 158 | - $this->_insert_ticket_price_relation($ticket_id, $surcharge_price_id); |
|
| 159 | - $this->_insert_datetime_ticket_relation($new_datetime_id, $ticket_id); |
|
| 160 | - } |
|
| 161 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_ticket_table, $tickets_for_old_price); |
|
| 162 | - } |
|
| 163 | - /** |
|
| 164 | - * Creates a 4.1 price base type |
|
| 165 | - * @global type $wpdb |
|
| 166 | - * @param type $old_price |
|
| 167 | - * @return int |
|
| 168 | - */ |
|
| 169 | - private function _insert_new_price($old_price) |
|
| 170 | - { |
|
| 171 | - global $wpdb; |
|
| 172 | - $cols_n_values = array( |
|
| 173 | - 'PRT_ID'=>self::price_type_base, |
|
| 174 | - 'PRC_amount'=>floatval($old_price['event_cost']), |
|
| 175 | - 'PRC_name'=>$old_price['price_type'], |
|
| 176 | - 'PRC_is_default'=>false, |
|
| 177 | - 'PRC_overrides'=>false, |
|
| 178 | - 'PRC_order'=>0, |
|
| 179 | - 'PRC_deleted'=>false, |
|
| 180 | - 'PRC_parent'=>null |
|
| 151 | + // create a ticket for each old price -old datetime combo |
|
| 152 | + $tickets_for_old_price = array(); |
|
| 153 | + foreach ($this->_get_datetime_ids_for_old_event_id($old_row['event_id']) as $new_datetime_id) { |
|
| 154 | + $ticket_id = $this->_insert_new_ticket($old_row); |
|
| 155 | + $tickets_for_old_price[] = $ticket_id; |
|
| 156 | + // associate to old prices |
|
| 157 | + $this->_insert_ticket_price_relation($ticket_id, $new_price_id); |
|
| 158 | + $this->_insert_ticket_price_relation($ticket_id, $surcharge_price_id); |
|
| 159 | + $this->_insert_datetime_ticket_relation($new_datetime_id, $ticket_id); |
|
| 160 | + } |
|
| 161 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_ticket_table, $tickets_for_old_price); |
|
| 162 | + } |
|
| 163 | + /** |
|
| 164 | + * Creates a 4.1 price base type |
|
| 165 | + * @global type $wpdb |
|
| 166 | + * @param type $old_price |
|
| 167 | + * @return int |
|
| 168 | + */ |
|
| 169 | + private function _insert_new_price($old_price) |
|
| 170 | + { |
|
| 171 | + global $wpdb; |
|
| 172 | + $cols_n_values = array( |
|
| 173 | + 'PRT_ID'=>self::price_type_base, |
|
| 174 | + 'PRC_amount'=>floatval($old_price['event_cost']), |
|
| 175 | + 'PRC_name'=>$old_price['price_type'], |
|
| 176 | + 'PRC_is_default'=>false, |
|
| 177 | + 'PRC_overrides'=>false, |
|
| 178 | + 'PRC_order'=>0, |
|
| 179 | + 'PRC_deleted'=>false, |
|
| 180 | + 'PRC_parent'=>null |
|
| 181 | 181 | |
| 182 | - ); |
|
| 183 | - $datatypes = array( |
|
| 184 | - '%d',// PRT_ID |
|
| 185 | - '%f',// PRT_amount |
|
| 186 | - '%s',// PRC_name |
|
| 187 | - '%d',// PRC_is_default |
|
| 188 | - '%d',// PRC_overrides |
|
| 189 | - '%d',// PRC_order |
|
| 190 | - '%d',// PRC_deleted |
|
| 191 | - '%d',// PRC_parent |
|
| 192 | - ); |
|
| 193 | - $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes); |
|
| 194 | - if (! $success) { |
|
| 195 | - $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)); |
|
| 196 | - return 0; |
|
| 197 | - } |
|
| 198 | - $new_id = $wpdb->insert_id; |
|
| 199 | - return $new_id; |
|
| 200 | - } |
|
| 201 | - /** |
|
| 202 | - * Creates a 4.1 member price discount |
|
| 203 | - * @global type $wpdb |
|
| 204 | - * @param type $old_price |
|
| 205 | - * @return int |
|
| 206 | - */ |
|
| 182 | + ); |
|
| 183 | + $datatypes = array( |
|
| 184 | + '%d',// PRT_ID |
|
| 185 | + '%f',// PRT_amount |
|
| 186 | + '%s',// PRC_name |
|
| 187 | + '%d',// PRC_is_default |
|
| 188 | + '%d',// PRC_overrides |
|
| 189 | + '%d',// PRC_order |
|
| 190 | + '%d',// PRC_deleted |
|
| 191 | + '%d',// PRC_parent |
|
| 192 | + ); |
|
| 193 | + $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes); |
|
| 194 | + if (! $success) { |
|
| 195 | + $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)); |
|
| 196 | + return 0; |
|
| 197 | + } |
|
| 198 | + $new_id = $wpdb->insert_id; |
|
| 199 | + return $new_id; |
|
| 200 | + } |
|
| 201 | + /** |
|
| 202 | + * Creates a 4.1 member price discount |
|
| 203 | + * @global type $wpdb |
|
| 204 | + * @param type $old_price |
|
| 205 | + * @return int |
|
| 206 | + */ |
|
| 207 | 207 | // private function _insert_new_member_price($old_price){ |
| 208 | 208 | // $discount_amount = floatval($old_price['event_cost']) - floatval($old_price['member_price']); |
| 209 | 209 | // global $wpdb; |
@@ -236,207 +236,207 @@ discard block |
||
| 236 | 236 | // $new_id = $wpdb->insert_id; |
| 237 | 237 | // return $new_id; |
| 238 | 238 | // } |
| 239 | - /** |
|
| 240 | - * Creates a 4.1 member price discount |
|
| 241 | - * @global type $wpdb |
|
| 242 | - * @param type $old_price |
|
| 243 | - * @return int |
|
| 244 | - */ |
|
| 245 | - private function _insert_new_surcharge_price($old_price) |
|
| 246 | - { |
|
| 239 | + /** |
|
| 240 | + * Creates a 4.1 member price discount |
|
| 241 | + * @global type $wpdb |
|
| 242 | + * @param type $old_price |
|
| 243 | + * @return int |
|
| 244 | + */ |
|
| 245 | + private function _insert_new_surcharge_price($old_price) |
|
| 246 | + { |
|
| 247 | 247 | |
| 248 | - if ($old_price['surcharge_type'] == 'flat_rate') { |
|
| 249 | - $price_type = self::price_type_flat_surcharge; |
|
| 250 | - } else { |
|
| 251 | - $price_type = self::price_type_percent_surcharge; |
|
| 252 | - } |
|
| 253 | - global $wpdb; |
|
| 254 | - $cols_n_values = array( |
|
| 255 | - 'PRT_ID'=>$price_type, |
|
| 256 | - 'PRC_amount'=>floatval($old_price['surcharge']), |
|
| 257 | - 'PRC_name'=> __("Surcharge", "event_espresso"), |
|
| 258 | - 'PRC_is_default'=>false, |
|
| 259 | - 'PRC_overrides'=>false, |
|
| 260 | - 'PRC_order'=>20, |
|
| 261 | - 'PRC_deleted'=>false, |
|
| 262 | - 'PRC_parent'=>null |
|
| 248 | + if ($old_price['surcharge_type'] == 'flat_rate') { |
|
| 249 | + $price_type = self::price_type_flat_surcharge; |
|
| 250 | + } else { |
|
| 251 | + $price_type = self::price_type_percent_surcharge; |
|
| 252 | + } |
|
| 253 | + global $wpdb; |
|
| 254 | + $cols_n_values = array( |
|
| 255 | + 'PRT_ID'=>$price_type, |
|
| 256 | + 'PRC_amount'=>floatval($old_price['surcharge']), |
|
| 257 | + 'PRC_name'=> __("Surcharge", "event_espresso"), |
|
| 258 | + 'PRC_is_default'=>false, |
|
| 259 | + 'PRC_overrides'=>false, |
|
| 260 | + 'PRC_order'=>20, |
|
| 261 | + 'PRC_deleted'=>false, |
|
| 262 | + 'PRC_parent'=>null |
|
| 263 | 263 | |
| 264 | - ); |
|
| 265 | - $datatypes = array( |
|
| 266 | - '%d',// PRT_ID |
|
| 267 | - '%f',// PRT_amount |
|
| 268 | - '%s',// PRC_name |
|
| 269 | - '%d',// PRC_is_default |
|
| 270 | - '%d',// PRC_overrides |
|
| 271 | - '%d',// PRC_order |
|
| 272 | - '%d',// PRC_deleted |
|
| 273 | - '%d',// PRC_parent |
|
| 274 | - ); |
|
| 275 | - $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes); |
|
| 276 | - if (! $success) { |
|
| 277 | - $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)); |
|
| 278 | - return 0; |
|
| 279 | - } |
|
| 280 | - $new_id = $wpdb->insert_id; |
|
| 281 | - return $new_id; |
|
| 282 | - } |
|
| 283 | - /** |
|
| 284 | - * Inserts a 4.1 ticket based off the 3.1 price, and the price IDs we've already made from the 3.1 price |
|
| 285 | - * @param $old_price_row array where keys are columns |
|
| 286 | - * @param $new_base_price_id int |
|
| 287 | - * @param $new_member_discount_id int |
|
| 288 | - * @param $new_surcharge_id int |
|
| 289 | - * @return int new ticket id |
|
| 290 | - */ |
|
| 291 | - private function _insert_new_ticket($old_price_row) |
|
| 292 | - { |
|
| 293 | - global $wpdb; |
|
| 294 | - $event_row = $this->_get_event_row($old_price_row['event_id']); |
|
| 295 | - if ($old_price_row['surcharge_type'] == 'flat_rate') { |
|
| 296 | - $final_ticket_price = floatval($old_price_row['event_cost']) + floatval($old_price_row['surcharge']); |
|
| 297 | - } else {// percent surcharge |
|
| 298 | - $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge'])/100); |
|
| 299 | - } |
|
| 300 | - $start_date = $event_row['registration_start']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_startT']); |
|
| 301 | - $start_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $start_date, $event_row['timezone_string']); |
|
| 302 | - $end_date = $event_row['registration_end']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_endT']); |
|
| 303 | - $end_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $end_date, $event_row['timezone_string']); |
|
| 304 | - $cols_n_values = array( |
|
| 305 | - 'TTM_ID'=>0, |
|
| 306 | - 'TKT_name'=>$old_price_row['price_type'], |
|
| 307 | - 'TKT_description'=>'', |
|
| 308 | - 'TKT_start_date'=>$start_date_utc, |
|
| 309 | - 'TKT_end_date'=>$end_date_utc, |
|
| 310 | - 'TKT_min'=>0, |
|
| 311 | - 'TKT_max'=>-1, |
|
| 312 | - 'TKT_price'=>$final_ticket_price, |
|
| 313 | - 'TKT_sold'=> 0,// note: this will get calculated as we actually add registrations during the migration |
|
| 314 | - 'TKT_qty'=> -1, |
|
| 315 | - 'TKT_uses'=> 1, |
|
| 316 | - '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_is_default'=>false, |
|
| 318 | - 'TKT_order'=>$this->_get_ticket_count(), |
|
| 319 | - 'TKT_row'=>0,// doesn't matter because UI reset this on first save anyways |
|
| 320 | - 'TKT_deleted'=>false, |
|
| 321 | - 'TKT_parent'=>0 |
|
| 264 | + ); |
|
| 265 | + $datatypes = array( |
|
| 266 | + '%d',// PRT_ID |
|
| 267 | + '%f',// PRT_amount |
|
| 268 | + '%s',// PRC_name |
|
| 269 | + '%d',// PRC_is_default |
|
| 270 | + '%d',// PRC_overrides |
|
| 271 | + '%d',// PRC_order |
|
| 272 | + '%d',// PRC_deleted |
|
| 273 | + '%d',// PRC_parent |
|
| 274 | + ); |
|
| 275 | + $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes); |
|
| 276 | + if (! $success) { |
|
| 277 | + $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)); |
|
| 278 | + return 0; |
|
| 279 | + } |
|
| 280 | + $new_id = $wpdb->insert_id; |
|
| 281 | + return $new_id; |
|
| 282 | + } |
|
| 283 | + /** |
|
| 284 | + * Inserts a 4.1 ticket based off the 3.1 price, and the price IDs we've already made from the 3.1 price |
|
| 285 | + * @param $old_price_row array where keys are columns |
|
| 286 | + * @param $new_base_price_id int |
|
| 287 | + * @param $new_member_discount_id int |
|
| 288 | + * @param $new_surcharge_id int |
|
| 289 | + * @return int new ticket id |
|
| 290 | + */ |
|
| 291 | + private function _insert_new_ticket($old_price_row) |
|
| 292 | + { |
|
| 293 | + global $wpdb; |
|
| 294 | + $event_row = $this->_get_event_row($old_price_row['event_id']); |
|
| 295 | + if ($old_price_row['surcharge_type'] == 'flat_rate') { |
|
| 296 | + $final_ticket_price = floatval($old_price_row['event_cost']) + floatval($old_price_row['surcharge']); |
|
| 297 | + } else {// percent surcharge |
|
| 298 | + $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge'])/100); |
|
| 299 | + } |
|
| 300 | + $start_date = $event_row['registration_start']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_startT']); |
|
| 301 | + $start_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $start_date, $event_row['timezone_string']); |
|
| 302 | + $end_date = $event_row['registration_end']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_endT']); |
|
| 303 | + $end_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $end_date, $event_row['timezone_string']); |
|
| 304 | + $cols_n_values = array( |
|
| 305 | + 'TTM_ID'=>0, |
|
| 306 | + 'TKT_name'=>$old_price_row['price_type'], |
|
| 307 | + 'TKT_description'=>'', |
|
| 308 | + 'TKT_start_date'=>$start_date_utc, |
|
| 309 | + 'TKT_end_date'=>$end_date_utc, |
|
| 310 | + 'TKT_min'=>0, |
|
| 311 | + 'TKT_max'=>-1, |
|
| 312 | + 'TKT_price'=>$final_ticket_price, |
|
| 313 | + 'TKT_sold'=> 0,// note: this will get calculated as we actually add registrations during the migration |
|
| 314 | + 'TKT_qty'=> -1, |
|
| 315 | + 'TKT_uses'=> 1, |
|
| 316 | + '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_is_default'=>false, |
|
| 318 | + 'TKT_order'=>$this->_get_ticket_count(), |
|
| 319 | + 'TKT_row'=>0,// doesn't matter because UI reset this on first save anyways |
|
| 320 | + 'TKT_deleted'=>false, |
|
| 321 | + 'TKT_parent'=>0 |
|
| 322 | 322 | |
| 323 | - ); |
|
| 324 | - $datatypes = array( |
|
| 325 | - '%d',// TTM_ID |
|
| 326 | - '%s',// TKT_name |
|
| 327 | - '%s',// TKT_description |
|
| 328 | - '%s',// TKT_start_date |
|
| 329 | - '%s',// TKT_end_date |
|
| 330 | - '%d',// TKT_min |
|
| 331 | - '%d',// TKT_max |
|
| 332 | - '%f',// TKT_price |
|
| 333 | - '%d',// TKT_sold |
|
| 334 | - '%d',// TKT_qty |
|
| 335 | - '%d',// TKT_uses |
|
| 336 | - '%d',// TKT_taxable |
|
| 337 | - '%d',// TKT_is_default |
|
| 338 | - '%d',// TKT_order |
|
| 339 | - '%d',// TKT_row |
|
| 340 | - '%d',// TKT_deleted |
|
| 341 | - '%d',// TKT_parent |
|
| 342 | - ); |
|
| 343 | - $success = $wpdb->insert($this->_new_ticket_table, $cols_n_values, $datatypes); |
|
| 344 | - if (! $success) { |
|
| 345 | - $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)); |
|
| 346 | - return 0; |
|
| 347 | - } |
|
| 348 | - $new_id = $wpdb->insert_id; |
|
| 349 | - return $new_id; |
|
| 350 | - } |
|
| 323 | + ); |
|
| 324 | + $datatypes = array( |
|
| 325 | + '%d',// TTM_ID |
|
| 326 | + '%s',// TKT_name |
|
| 327 | + '%s',// TKT_description |
|
| 328 | + '%s',// TKT_start_date |
|
| 329 | + '%s',// TKT_end_date |
|
| 330 | + '%d',// TKT_min |
|
| 331 | + '%d',// TKT_max |
|
| 332 | + '%f',// TKT_price |
|
| 333 | + '%d',// TKT_sold |
|
| 334 | + '%d',// TKT_qty |
|
| 335 | + '%d',// TKT_uses |
|
| 336 | + '%d',// TKT_taxable |
|
| 337 | + '%d',// TKT_is_default |
|
| 338 | + '%d',// TKT_order |
|
| 339 | + '%d',// TKT_row |
|
| 340 | + '%d',// TKT_deleted |
|
| 341 | + '%d',// TKT_parent |
|
| 342 | + ); |
|
| 343 | + $success = $wpdb->insert($this->_new_ticket_table, $cols_n_values, $datatypes); |
|
| 344 | + if (! $success) { |
|
| 345 | + $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)); |
|
| 346 | + return 0; |
|
| 347 | + } |
|
| 348 | + $new_id = $wpdb->insert_id; |
|
| 349 | + return $new_id; |
|
| 350 | + } |
|
| 351 | 351 | |
| 352 | - /** |
|
| 353 | - * Adds a join between a ticket and a price |
|
| 354 | - * @global type $wpdb |
|
| 355 | - * @param type $new_ticket_id |
|
| 356 | - * @param type $new_price_id |
|
| 357 | - * @return int |
|
| 358 | - */ |
|
| 359 | - private function _insert_ticket_price_relation($new_ticket_id, $new_price_id) |
|
| 360 | - { |
|
| 361 | - global $wpdb; |
|
| 362 | - $cols_n_values = array( |
|
| 363 | - 'TKT_ID'=>$new_ticket_id, |
|
| 364 | - 'PRC_ID'=>$new_price_id, |
|
| 365 | - ); |
|
| 366 | - $datatypes = array( |
|
| 367 | - '%d',// TKT_ID |
|
| 368 | - '%d',// PRC_ID |
|
| 369 | - ); |
|
| 370 | - $success = $wpdb->insert($this->_new_ticket_price_table, $cols_n_values, $datatypes); |
|
| 371 | - if (! $success) { |
|
| 372 | - $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)); |
|
| 373 | - return 0; |
|
| 374 | - } |
|
| 375 | - $new_id = $wpdb->insert_id; |
|
| 376 | - return $new_id; |
|
| 377 | - } |
|
| 352 | + /** |
|
| 353 | + * Adds a join between a ticket and a price |
|
| 354 | + * @global type $wpdb |
|
| 355 | + * @param type $new_ticket_id |
|
| 356 | + * @param type $new_price_id |
|
| 357 | + * @return int |
|
| 358 | + */ |
|
| 359 | + private function _insert_ticket_price_relation($new_ticket_id, $new_price_id) |
|
| 360 | + { |
|
| 361 | + global $wpdb; |
|
| 362 | + $cols_n_values = array( |
|
| 363 | + 'TKT_ID'=>$new_ticket_id, |
|
| 364 | + 'PRC_ID'=>$new_price_id, |
|
| 365 | + ); |
|
| 366 | + $datatypes = array( |
|
| 367 | + '%d',// TKT_ID |
|
| 368 | + '%d',// PRC_ID |
|
| 369 | + ); |
|
| 370 | + $success = $wpdb->insert($this->_new_ticket_price_table, $cols_n_values, $datatypes); |
|
| 371 | + if (! $success) { |
|
| 372 | + $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)); |
|
| 373 | + return 0; |
|
| 374 | + } |
|
| 375 | + $new_id = $wpdb->insert_id; |
|
| 376 | + return $new_id; |
|
| 377 | + } |
|
| 378 | 378 | |
| 379 | - /** |
|
| 380 | - * Adds a join between a ticket and a datetime |
|
| 381 | - * @global type $wpdb |
|
| 382 | - * @param type $new_ticket_id |
|
| 383 | - * @param type $new_price_id |
|
| 384 | - * @return int |
|
| 385 | - */ |
|
| 386 | - private function _insert_datetime_ticket_relation($new_datetime_id, $new_ticket_id) |
|
| 387 | - { |
|
| 388 | - global $wpdb; |
|
| 389 | - $cols_n_values = array( |
|
| 390 | - 'TKT_ID'=>$new_ticket_id, |
|
| 391 | - 'DTT_ID'=>$new_datetime_id, |
|
| 392 | - ); |
|
| 393 | - $datatypes = array( |
|
| 394 | - '%d',// TKT_ID |
|
| 395 | - '%d',// DTT_ID |
|
| 396 | - ); |
|
| 397 | - $success = $wpdb->insert($this->_new_datetime_ticket_table, $cols_n_values, $datatypes); |
|
| 398 | - if (! $success) { |
|
| 399 | - $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)); |
|
| 400 | - return 0; |
|
| 401 | - } |
|
| 402 | - $new_id = $wpdb->insert_id; |
|
| 403 | - return $new_id; |
|
| 404 | - } |
|
| 379 | + /** |
|
| 380 | + * Adds a join between a ticket and a datetime |
|
| 381 | + * @global type $wpdb |
|
| 382 | + * @param type $new_ticket_id |
|
| 383 | + * @param type $new_price_id |
|
| 384 | + * @return int |
|
| 385 | + */ |
|
| 386 | + private function _insert_datetime_ticket_relation($new_datetime_id, $new_ticket_id) |
|
| 387 | + { |
|
| 388 | + global $wpdb; |
|
| 389 | + $cols_n_values = array( |
|
| 390 | + 'TKT_ID'=>$new_ticket_id, |
|
| 391 | + 'DTT_ID'=>$new_datetime_id, |
|
| 392 | + ); |
|
| 393 | + $datatypes = array( |
|
| 394 | + '%d',// TKT_ID |
|
| 395 | + '%d',// DTT_ID |
|
| 396 | + ); |
|
| 397 | + $success = $wpdb->insert($this->_new_datetime_ticket_table, $cols_n_values, $datatypes); |
|
| 398 | + if (! $success) { |
|
| 399 | + $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)); |
|
| 400 | + return 0; |
|
| 401 | + } |
|
| 402 | + $new_id = $wpdb->insert_id; |
|
| 403 | + return $new_id; |
|
| 404 | + } |
|
| 405 | 405 | |
| 406 | - /** |
|
| 407 | - * Simply gets the 3.1 event row data |
|
| 408 | - * @global type $wpdb |
|
| 409 | - * @param type $event_id |
|
| 410 | - * @return array |
|
| 411 | - */ |
|
| 412 | - private function _get_event_row($event_id) |
|
| 413 | - { |
|
| 414 | - global $wpdb; |
|
| 415 | - $old_event_table = $wpdb->prefix."events_detail"; |
|
| 416 | - return $wpdb->get_row($wpdb->prepare("SELECT * FROM $old_event_table WHERE id=%d", $event_id), ARRAY_A); |
|
| 417 | - } |
|
| 418 | - /** |
|
| 419 | - * Gets a higher ticket count than last time it was called (and is persisted between HTTP requests). |
|
| 420 | - * Yes we COULD run a query joining events->datetimes->ticket_datetimes->tickets, but this should work fine too |
|
| 421 | - * @return int |
|
| 422 | - */ |
|
| 423 | - private function _get_ticket_count() |
|
| 424 | - { |
|
| 425 | - return $this->_ticket_count++; |
|
| 426 | - } |
|
| 406 | + /** |
|
| 407 | + * Simply gets the 3.1 event row data |
|
| 408 | + * @global type $wpdb |
|
| 409 | + * @param type $event_id |
|
| 410 | + * @return array |
|
| 411 | + */ |
|
| 412 | + private function _get_event_row($event_id) |
|
| 413 | + { |
|
| 414 | + global $wpdb; |
|
| 415 | + $old_event_table = $wpdb->prefix."events_detail"; |
|
| 416 | + return $wpdb->get_row($wpdb->prepare("SELECT * FROM $old_event_table WHERE id=%d", $event_id), ARRAY_A); |
|
| 417 | + } |
|
| 418 | + /** |
|
| 419 | + * Gets a higher ticket count than last time it was called (and is persisted between HTTP requests). |
|
| 420 | + * Yes we COULD run a query joining events->datetimes->ticket_datetimes->tickets, but this should work fine too |
|
| 421 | + * @return int |
|
| 422 | + */ |
|
| 423 | + private function _get_ticket_count() |
|
| 424 | + { |
|
| 425 | + return $this->_ticket_count++; |
|
| 426 | + } |
|
| 427 | 427 | |
| 428 | - /** |
|
| 429 | - * Using the 3.1 event id, gets the 4.1 datetimes for it |
|
| 430 | - * @param int $old_event_id |
|
| 431 | - * @return array where values are datetime ids |
|
| 432 | - */ |
|
| 433 | - private function _get_datetime_ids_for_old_event_id($old_event_id) |
|
| 434 | - { |
|
| 435 | - global $wpdb; |
|
| 436 | - $new_cpt_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_event_id, $wpdb->posts); |
|
| 437 | - $datetime_ids = $wpdb->get_col($wpdb->prepare("SELECT DTT_ID FROM {$wpdb->prefix}esp_datetime WHERE EVT_ID=%d", $new_cpt_id)); |
|
| 438 | - return $datetime_ids; |
|
| 439 | - } |
|
| 428 | + /** |
|
| 429 | + * Using the 3.1 event id, gets the 4.1 datetimes for it |
|
| 430 | + * @param int $old_event_id |
|
| 431 | + * @return array where values are datetime ids |
|
| 432 | + */ |
|
| 433 | + private function _get_datetime_ids_for_old_event_id($old_event_id) |
|
| 434 | + { |
|
| 435 | + global $wpdb; |
|
| 436 | + $new_cpt_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_event_id, $wpdb->posts); |
|
| 437 | + $datetime_ids = $wpdb->get_col($wpdb->prepare("SELECT DTT_ID FROM {$wpdb->prefix}esp_datetime WHERE EVT_ID=%d", $new_cpt_id)); |
|
| 438 | + return $datetime_ids; |
|
| 439 | + } |
|
| 440 | 440 | } |
| 441 | 441 | // @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 |
| 442 | 442 | // |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | $this->_pretty_name = __("Prices", "event_espresso"); |
| 108 | 108 | $this->_old_table = $wpdb->prefix."events_prices"; |
| 109 | 109 | $this->_extra_where_sql = ' AS p |
| 110 | - INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON p.event_id=e.id |
|
| 110 | + INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON p.event_id=e.id |
|
| 111 | 111 | WHERE e.event_status!="D"'; |
| 112 | 112 | $this->_new_price_table = $wpdb->prefix."esp_price"; |
| 113 | 113 | $this->_new_ticket_table = $wpdb->prefix."esp_ticket"; |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | // create the surcharge if there is any |
| 130 | 130 | if (floatval($old_row['surcharge']) >= 0.01) { |
| 131 | 131 | $surcharge_price_id = $this->_insert_new_surcharge_price($old_row); |
| 132 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id,$surcharge_price_id)); |
|
| 132 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id, $surcharge_price_id)); |
|
| 133 | 133 | } else { |
| 134 | 134 | $surcharge_price_id = 0; |
| 135 | 135 | $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id)); |
@@ -181,17 +181,17 @@ discard block |
||
| 181 | 181 | |
| 182 | 182 | ); |
| 183 | 183 | $datatypes = array( |
| 184 | - '%d',// PRT_ID |
|
| 185 | - '%f',// PRT_amount |
|
| 186 | - '%s',// PRC_name |
|
| 187 | - '%d',// PRC_is_default |
|
| 188 | - '%d',// PRC_overrides |
|
| 189 | - '%d',// PRC_order |
|
| 190 | - '%d',// PRC_deleted |
|
| 191 | - '%d',// PRC_parent |
|
| 184 | + '%d', // PRT_ID |
|
| 185 | + '%f', // PRT_amount |
|
| 186 | + '%s', // PRC_name |
|
| 187 | + '%d', // PRC_is_default |
|
| 188 | + '%d', // PRC_overrides |
|
| 189 | + '%d', // PRC_order |
|
| 190 | + '%d', // PRC_deleted |
|
| 191 | + '%d', // PRC_parent |
|
| 192 | 192 | ); |
| 193 | 193 | $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes); |
| 194 | - if (! $success) { |
|
| 194 | + if ( ! $success) { |
|
| 195 | 195 | $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)); |
| 196 | 196 | return 0; |
| 197 | 197 | } |
@@ -263,17 +263,17 @@ discard block |
||
| 263 | 263 | |
| 264 | 264 | ); |
| 265 | 265 | $datatypes = array( |
| 266 | - '%d',// PRT_ID |
|
| 267 | - '%f',// PRT_amount |
|
| 268 | - '%s',// PRC_name |
|
| 269 | - '%d',// PRC_is_default |
|
| 270 | - '%d',// PRC_overrides |
|
| 271 | - '%d',// PRC_order |
|
| 272 | - '%d',// PRC_deleted |
|
| 273 | - '%d',// PRC_parent |
|
| 266 | + '%d', // PRT_ID |
|
| 267 | + '%f', // PRT_amount |
|
| 268 | + '%s', // PRC_name |
|
| 269 | + '%d', // PRC_is_default |
|
| 270 | + '%d', // PRC_overrides |
|
| 271 | + '%d', // PRC_order |
|
| 272 | + '%d', // PRC_deleted |
|
| 273 | + '%d', // PRC_parent |
|
| 274 | 274 | ); |
| 275 | 275 | $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes); |
| 276 | - if (! $success) { |
|
| 276 | + if ( ! $success) { |
|
| 277 | 277 | $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)); |
| 278 | 278 | return 0; |
| 279 | 279 | } |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | if ($old_price_row['surcharge_type'] == 'flat_rate') { |
| 296 | 296 | $final_ticket_price = floatval($old_price_row['event_cost']) + floatval($old_price_row['surcharge']); |
| 297 | 297 | } else {// percent surcharge |
| 298 | - $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge'])/100); |
|
| 298 | + $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge']) / 100); |
|
| 299 | 299 | } |
| 300 | 300 | $start_date = $event_row['registration_start']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_startT']); |
| 301 | 301 | $start_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $start_date, $event_row['timezone_string']); |
@@ -310,38 +310,38 @@ discard block |
||
| 310 | 310 | 'TKT_min'=>0, |
| 311 | 311 | 'TKT_max'=>-1, |
| 312 | 312 | 'TKT_price'=>$final_ticket_price, |
| 313 | - 'TKT_sold'=> 0,// note: this will get calculated as we actually add registrations during the migration |
|
| 313 | + 'TKT_sold'=> 0, // note: this will get calculated as we actually add registrations during the migration |
|
| 314 | 314 | 'TKT_qty'=> -1, |
| 315 | 315 | 'TKT_uses'=> 1, |
| 316 | - 'TKT_taxable'=>false,// so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices |
|
| 316 | + 'TKT_taxable'=>false, // so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices |
|
| 317 | 317 | 'TKT_is_default'=>false, |
| 318 | 318 | 'TKT_order'=>$this->_get_ticket_count(), |
| 319 | - 'TKT_row'=>0,// doesn't matter because UI reset this on first save anyways |
|
| 319 | + 'TKT_row'=>0, // doesn't matter because UI reset this on first save anyways |
|
| 320 | 320 | 'TKT_deleted'=>false, |
| 321 | 321 | 'TKT_parent'=>0 |
| 322 | 322 | |
| 323 | 323 | ); |
| 324 | 324 | $datatypes = array( |
| 325 | - '%d',// TTM_ID |
|
| 326 | - '%s',// TKT_name |
|
| 327 | - '%s',// TKT_description |
|
| 328 | - '%s',// TKT_start_date |
|
| 329 | - '%s',// TKT_end_date |
|
| 330 | - '%d',// TKT_min |
|
| 331 | - '%d',// TKT_max |
|
| 332 | - '%f',// TKT_price |
|
| 333 | - '%d',// TKT_sold |
|
| 334 | - '%d',// TKT_qty |
|
| 335 | - '%d',// TKT_uses |
|
| 336 | - '%d',// TKT_taxable |
|
| 337 | - '%d',// TKT_is_default |
|
| 338 | - '%d',// TKT_order |
|
| 339 | - '%d',// TKT_row |
|
| 340 | - '%d',// TKT_deleted |
|
| 341 | - '%d',// TKT_parent |
|
| 325 | + '%d', // TTM_ID |
|
| 326 | + '%s', // TKT_name |
|
| 327 | + '%s', // TKT_description |
|
| 328 | + '%s', // TKT_start_date |
|
| 329 | + '%s', // TKT_end_date |
|
| 330 | + '%d', // TKT_min |
|
| 331 | + '%d', // TKT_max |
|
| 332 | + '%f', // TKT_price |
|
| 333 | + '%d', // TKT_sold |
|
| 334 | + '%d', // TKT_qty |
|
| 335 | + '%d', // TKT_uses |
|
| 336 | + '%d', // TKT_taxable |
|
| 337 | + '%d', // TKT_is_default |
|
| 338 | + '%d', // TKT_order |
|
| 339 | + '%d', // TKT_row |
|
| 340 | + '%d', // TKT_deleted |
|
| 341 | + '%d', // TKT_parent |
|
| 342 | 342 | ); |
| 343 | 343 | $success = $wpdb->insert($this->_new_ticket_table, $cols_n_values, $datatypes); |
| 344 | - if (! $success) { |
|
| 344 | + if ( ! $success) { |
|
| 345 | 345 | $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)); |
| 346 | 346 | return 0; |
| 347 | 347 | } |
@@ -364,12 +364,12 @@ discard block |
||
| 364 | 364 | 'PRC_ID'=>$new_price_id, |
| 365 | 365 | ); |
| 366 | 366 | $datatypes = array( |
| 367 | - '%d',// TKT_ID |
|
| 368 | - '%d',// PRC_ID |
|
| 367 | + '%d', // TKT_ID |
|
| 368 | + '%d', // PRC_ID |
|
| 369 | 369 | ); |
| 370 | 370 | $success = $wpdb->insert($this->_new_ticket_price_table, $cols_n_values, $datatypes); |
| 371 | - if (! $success) { |
|
| 372 | - $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)); |
|
| 371 | + if ( ! $success) { |
|
| 372 | + $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)); |
|
| 373 | 373 | return 0; |
| 374 | 374 | } |
| 375 | 375 | $new_id = $wpdb->insert_id; |
@@ -391,12 +391,12 @@ discard block |
||
| 391 | 391 | 'DTT_ID'=>$new_datetime_id, |
| 392 | 392 | ); |
| 393 | 393 | $datatypes = array( |
| 394 | - '%d',// TKT_ID |
|
| 395 | - '%d',// DTT_ID |
|
| 394 | + '%d', // TKT_ID |
|
| 395 | + '%d', // DTT_ID |
|
| 396 | 396 | ); |
| 397 | 397 | $success = $wpdb->insert($this->_new_datetime_ticket_table, $cols_n_values, $datatypes); |
| 398 | - if (! $success) { |
|
| 399 | - $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)); |
|
| 398 | + if ( ! $success) { |
|
| 399 | + $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)); |
|
| 400 | 400 | return 0; |
| 401 | 401 | } |
| 402 | 402 | $new_id = $wpdb->insert_id; |
@@ -130,7 +130,7 @@ |
||
| 130 | 130 | * being address info, and 0 being neither) |
| 131 | 131 | * @global type $wpdb |
| 132 | 132 | * @param type $new_question_group_id |
| 133 | - * @return boolean |
|
| 133 | + * @return integer |
|
| 134 | 134 | */ |
| 135 | 135 | private function _is_system_question_group($new_question_group_id) |
| 136 | 136 | { |
@@ -12,8 +12,6 @@ discard block |
||
| 12 | 12 | KEY `group_id` (`group_id`), |
| 13 | 13 | KEY `question_id` (`question_id`) |
| 14 | 14 | ) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8$$ |
| 15 | - |
|
| 16 | - |
|
| 17 | 15 | * 4.1 question group question model's tables and fields: |
| 18 | 16 | $this->_tables = array( |
| 19 | 17 | 'Question_Group_Question'=>new EE_Primary_Table('esp_question_group_question','QGQ_ID') |
@@ -29,113 +27,113 @@ discard block |
||
| 29 | 27 | */ |
| 30 | 28 | class EE_DMS_4_1_0_question_group_question extends EE_Data_Migration_Script_Stage |
| 31 | 29 | { |
| 32 | - private $_old_table; |
|
| 33 | - private $_new_table; |
|
| 34 | - public function _migration_step($num_items = 50) |
|
| 35 | - { |
|
| 30 | + private $_old_table; |
|
| 31 | + private $_new_table; |
|
| 32 | + public function _migration_step($num_items = 50) |
|
| 33 | + { |
|
| 36 | 34 | |
| 37 | - global $wpdb; |
|
| 38 | - $start_at_record = $this->count_records_migrated(); |
|
| 39 | - $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A); |
|
| 40 | - $items_actually_migrated = 0; |
|
| 41 | - foreach ($rows as $question_group_question) { |
|
| 42 | - $this->_insert_new_question_group_question($question_group_question); |
|
| 43 | - $items_actually_migrated++; |
|
| 44 | - } |
|
| 45 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
| 46 | - $this->set_completed(); |
|
| 47 | - } |
|
| 48 | - return $items_actually_migrated; |
|
| 49 | - } |
|
| 50 | - public function _count_records_to_migrate() |
|
| 51 | - { |
|
| 52 | - global $wpdb; |
|
| 53 | - $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table); |
|
| 54 | - return $count; |
|
| 55 | - } |
|
| 56 | - public function __construct() |
|
| 57 | - { |
|
| 58 | - global $wpdb; |
|
| 59 | - $this->_old_table = $wpdb->prefix."events_qst_group_rel"; |
|
| 60 | - $this->_new_table = $wpdb->prefix."esp_question_group_question"; |
|
| 61 | - $this->_pretty_name = __("Question Group to Question Relations", "event_espresso"); |
|
| 62 | - parent::__construct(); |
|
| 63 | - } |
|
| 35 | + global $wpdb; |
|
| 36 | + $start_at_record = $this->count_records_migrated(); |
|
| 37 | + $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A); |
|
| 38 | + $items_actually_migrated = 0; |
|
| 39 | + foreach ($rows as $question_group_question) { |
|
| 40 | + $this->_insert_new_question_group_question($question_group_question); |
|
| 41 | + $items_actually_migrated++; |
|
| 42 | + } |
|
| 43 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
| 44 | + $this->set_completed(); |
|
| 45 | + } |
|
| 46 | + return $items_actually_migrated; |
|
| 47 | + } |
|
| 48 | + public function _count_records_to_migrate() |
|
| 49 | + { |
|
| 50 | + global $wpdb; |
|
| 51 | + $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table); |
|
| 52 | + return $count; |
|
| 53 | + } |
|
| 54 | + public function __construct() |
|
| 55 | + { |
|
| 56 | + global $wpdb; |
|
| 57 | + $this->_old_table = $wpdb->prefix."events_qst_group_rel"; |
|
| 58 | + $this->_new_table = $wpdb->prefix."esp_question_group_question"; |
|
| 59 | + $this->_pretty_name = __("Question Group to Question Relations", "event_espresso"); |
|
| 60 | + parent::__construct(); |
|
| 61 | + } |
|
| 64 | 62 | |
| 65 | - /** |
|
| 66 | - * Attempts to insert a new question group inthe new format given an old one |
|
| 67 | - * @global type $wpdb |
|
| 68 | - * @param array $old_question_group_question |
|
| 69 | - * @return int |
|
| 70 | - */ |
|
| 71 | - private function _insert_new_question_group_question($old_question_group_question) |
|
| 72 | - { |
|
| 73 | - global $wpdb; |
|
| 74 | - $new_question_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_question", $old_question_group_question['question_id'], $wpdb->prefix."esp_question"); |
|
| 75 | - $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_qst_group", $old_question_group_question['group_id'], $wpdb->prefix."esp_question_group"); |
|
| 76 | - if (! $new_question_id) { |
|
| 77 | - $this->add_error(sprintf(__("Could not find 4.1 question id for 3.1 question #%d.", "event_espresso"), $old_question_group_question['question_id'])); |
|
| 78 | - return 0; |
|
| 79 | - } |
|
| 80 | - if (! $new_question_group_id) { |
|
| 81 | - $this->add_error(sprintf(__("Could not find 4.1 question group id for 3.1 question group #%d.", "event_espresso"), $old_question_group_question['group_id'])); |
|
| 82 | - return 0; |
|
| 83 | - } |
|
| 84 | - // if it's a system question, it needs to be in the right system group. otherwise no dice! |
|
| 85 | - if (($this->_is_system_question_group($new_question_group_id) == $this->_is_system_question_for_question_group($new_question_id) ) |
|
| 86 | - || |
|
| 87 | - ! $this->_is_system_question_for_question_group($new_question_id) |
|
| 88 | - ) { |
|
| 89 | - $cols_n_values = array( |
|
| 90 | - 'QSG_ID'=>$new_question_group_id, |
|
| 91 | - 'QST_ID'=>$new_question_id |
|
| 92 | - ); |
|
| 93 | - $datatypes = array( |
|
| 94 | - '%d',// QSG_ID |
|
| 95 | - '%d',// QST_ID |
|
| 96 | - ); |
|
| 97 | - $success = $wpdb->insert($this->_new_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_question_group_question, $this->_new_table, $cols_n_values, $datatypes)); |
|
| 100 | - return 0; |
|
| 101 | - } |
|
| 102 | - return $wpdb->insert_id; |
|
| 103 | - } else { |
|
| 104 | - return false; |
|
| 105 | - } |
|
| 106 | - } |
|
| 63 | + /** |
|
| 64 | + * Attempts to insert a new question group inthe new format given an old one |
|
| 65 | + * @global type $wpdb |
|
| 66 | + * @param array $old_question_group_question |
|
| 67 | + * @return int |
|
| 68 | + */ |
|
| 69 | + private function _insert_new_question_group_question($old_question_group_question) |
|
| 70 | + { |
|
| 71 | + global $wpdb; |
|
| 72 | + $new_question_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_question", $old_question_group_question['question_id'], $wpdb->prefix."esp_question"); |
|
| 73 | + $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_qst_group", $old_question_group_question['group_id'], $wpdb->prefix."esp_question_group"); |
|
| 74 | + if (! $new_question_id) { |
|
| 75 | + $this->add_error(sprintf(__("Could not find 4.1 question id for 3.1 question #%d.", "event_espresso"), $old_question_group_question['question_id'])); |
|
| 76 | + return 0; |
|
| 77 | + } |
|
| 78 | + if (! $new_question_group_id) { |
|
| 79 | + $this->add_error(sprintf(__("Could not find 4.1 question group id for 3.1 question group #%d.", "event_espresso"), $old_question_group_question['group_id'])); |
|
| 80 | + return 0; |
|
| 81 | + } |
|
| 82 | + // if it's a system question, it needs to be in the right system group. otherwise no dice! |
|
| 83 | + if (($this->_is_system_question_group($new_question_group_id) == $this->_is_system_question_for_question_group($new_question_id) ) |
|
| 84 | + || |
|
| 85 | + ! $this->_is_system_question_for_question_group($new_question_id) |
|
| 86 | + ) { |
|
| 87 | + $cols_n_values = array( |
|
| 88 | + 'QSG_ID'=>$new_question_group_id, |
|
| 89 | + 'QST_ID'=>$new_question_id |
|
| 90 | + ); |
|
| 91 | + $datatypes = array( |
|
| 92 | + '%d',// QSG_ID |
|
| 93 | + '%d',// QST_ID |
|
| 94 | + ); |
|
| 95 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
| 96 | + if (! $success) { |
|
| 97 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question_group_question, $this->_new_table, $cols_n_values, $datatypes)); |
|
| 98 | + return 0; |
|
| 99 | + } |
|
| 100 | + return $wpdb->insert_id; |
|
| 101 | + } else { |
|
| 102 | + return false; |
|
| 103 | + } |
|
| 104 | + } |
|
| 107 | 105 | |
| 108 | - /** |
|
| 109 | - * If this question is a system question, returns the QSG_system number that |
|
| 110 | - * indicates the question group its permitted in. |
|
| 111 | - * @global type $wpdb |
|
| 112 | - * @param type $new_question_id |
|
| 113 | - * @return int |
|
| 114 | - */ |
|
| 115 | - private function _is_system_question_for_question_group($new_question_id) |
|
| 116 | - { |
|
| 117 | - global $wpdb; |
|
| 118 | - $system_id = $wpdb->get_var($wpdb->prepare("SELECT QST_system FROM ".$wpdb->prefix."esp_question WHERE QST_ID=%d", $new_question_id)); |
|
| 119 | - if (in_array($system_id, array('fname','lname','email'))) { |
|
| 120 | - return 1; |
|
| 121 | - } elseif ($system_id!='' && $system_id) { |
|
| 122 | - return 2; |
|
| 123 | - } else { |
|
| 124 | - return 0; |
|
| 125 | - } |
|
| 126 | - } |
|
| 106 | + /** |
|
| 107 | + * If this question is a system question, returns the QSG_system number that |
|
| 108 | + * indicates the question group its permitted in. |
|
| 109 | + * @global type $wpdb |
|
| 110 | + * @param type $new_question_id |
|
| 111 | + * @return int |
|
| 112 | + */ |
|
| 113 | + private function _is_system_question_for_question_group($new_question_id) |
|
| 114 | + { |
|
| 115 | + global $wpdb; |
|
| 116 | + $system_id = $wpdb->get_var($wpdb->prepare("SELECT QST_system FROM ".$wpdb->prefix."esp_question WHERE QST_ID=%d", $new_question_id)); |
|
| 117 | + if (in_array($system_id, array('fname','lname','email'))) { |
|
| 118 | + return 1; |
|
| 119 | + } elseif ($system_id!='' && $system_id) { |
|
| 120 | + return 2; |
|
| 121 | + } else { |
|
| 122 | + return 0; |
|
| 123 | + } |
|
| 124 | + } |
|
| 127 | 125 | |
| 128 | - /** |
|
| 129 | - * Returns the questino group's QSG_system value (1 meaning personal info, 2 |
|
| 130 | - * being address info, and 0 being neither) |
|
| 131 | - * @global type $wpdb |
|
| 132 | - * @param type $new_question_group_id |
|
| 133 | - * @return boolean |
|
| 134 | - */ |
|
| 135 | - private function _is_system_question_group($new_question_group_id) |
|
| 136 | - { |
|
| 137 | - global $wpdb; |
|
| 138 | - $system_id = $wpdb->get_var($wpdb->prepare("SELECT QSG_system FROM ".$wpdb->prefix."esp_question_group WHERE QSG_ID=%d", $new_question_group_id)); |
|
| 139 | - return intval($system_id); |
|
| 140 | - } |
|
| 126 | + /** |
|
| 127 | + * Returns the questino group's QSG_system value (1 meaning personal info, 2 |
|
| 128 | + * being address info, and 0 being neither) |
|
| 129 | + * @global type $wpdb |
|
| 130 | + * @param type $new_question_group_id |
|
| 131 | + * @return boolean |
|
| 132 | + */ |
|
| 133 | + private function _is_system_question_group($new_question_group_id) |
|
| 134 | + { |
|
| 135 | + global $wpdb; |
|
| 136 | + $system_id = $wpdb->get_var($wpdb->prepare("SELECT QSG_system FROM ".$wpdb->prefix."esp_question_group WHERE QSG_ID=%d", $new_question_group_id)); |
|
| 137 | + return intval($system_id); |
|
| 138 | + } |
|
| 141 | 139 | } |
@@ -73,16 +73,16 @@ discard block |
||
| 73 | 73 | global $wpdb; |
| 74 | 74 | $new_question_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_question", $old_question_group_question['question_id'], $wpdb->prefix."esp_question"); |
| 75 | 75 | $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_qst_group", $old_question_group_question['group_id'], $wpdb->prefix."esp_question_group"); |
| 76 | - if (! $new_question_id) { |
|
| 76 | + if ( ! $new_question_id) { |
|
| 77 | 77 | $this->add_error(sprintf(__("Could not find 4.1 question id for 3.1 question #%d.", "event_espresso"), $old_question_group_question['question_id'])); |
| 78 | 78 | return 0; |
| 79 | 79 | } |
| 80 | - if (! $new_question_group_id) { |
|
| 80 | + if ( ! $new_question_group_id) { |
|
| 81 | 81 | $this->add_error(sprintf(__("Could not find 4.1 question group id for 3.1 question group #%d.", "event_espresso"), $old_question_group_question['group_id'])); |
| 82 | 82 | return 0; |
| 83 | 83 | } |
| 84 | 84 | // if it's a system question, it needs to be in the right system group. otherwise no dice! |
| 85 | - if (($this->_is_system_question_group($new_question_group_id) == $this->_is_system_question_for_question_group($new_question_id) ) |
|
| 85 | + if (($this->_is_system_question_group($new_question_group_id) == $this->_is_system_question_for_question_group($new_question_id)) |
|
| 86 | 86 | || |
| 87 | 87 | ! $this->_is_system_question_for_question_group($new_question_id) |
| 88 | 88 | ) { |
@@ -91,11 +91,11 @@ discard block |
||
| 91 | 91 | 'QST_ID'=>$new_question_id |
| 92 | 92 | ); |
| 93 | 93 | $datatypes = array( |
| 94 | - '%d',// QSG_ID |
|
| 95 | - '%d',// QST_ID |
|
| 94 | + '%d', // QSG_ID |
|
| 95 | + '%d', // QST_ID |
|
| 96 | 96 | ); |
| 97 | 97 | $success = $wpdb->insert($this->_new_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_question_group_question, $this->_new_table, $cols_n_values, $datatypes)); |
| 100 | 100 | return 0; |
| 101 | 101 | } |
@@ -116,9 +116,9 @@ discard block |
||
| 116 | 116 | { |
| 117 | 117 | global $wpdb; |
| 118 | 118 | $system_id = $wpdb->get_var($wpdb->prepare("SELECT QST_system FROM ".$wpdb->prefix."esp_question WHERE QST_ID=%d", $new_question_id)); |
| 119 | - if (in_array($system_id, array('fname','lname','email'))) { |
|
| 119 | + if (in_array($system_id, array('fname', 'lname', 'email'))) { |
|
| 120 | 120 | return 1; |
| 121 | - } elseif ($system_id!='' && $system_id) { |
|
| 121 | + } elseif ($system_id != '' && $system_id) { |
|
| 122 | 122 | return 2; |
| 123 | 123 | } else { |
| 124 | 124 | return 0; |
@@ -205,7 +205,7 @@ |
||
| 205 | 205 | |
| 206 | 206 | /** |
| 207 | 207 | * Inserts into the venue_meta table |
| 208 | - * @param type $cpt_id |
|
| 208 | + * @param integer $cpt_id |
|
| 209 | 209 | * @param type $old_venue |
| 210 | 210 | * @return int |
| 211 | 211 | */ |
@@ -63,210 +63,210 @@ |
||
| 63 | 63 | */ |
| 64 | 64 | class EE_DMS_4_1_0_venues extends EE_Data_Migration_Script_Stage |
| 65 | 65 | { |
| 66 | - private $_old_table; |
|
| 67 | - private $_new_table; |
|
| 68 | - private $_new_meta_table; |
|
| 69 | - public function _migration_step($num_items = 50) |
|
| 70 | - { |
|
| 71 | - global $wpdb; |
|
| 72 | - $start_at_record = $this->count_records_migrated(); |
|
| 73 | - $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".$this->_old_table." LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A); |
|
| 74 | - $items_actually_migrated = 0; |
|
| 75 | - foreach ($rows as $old_venue) { |
|
| 76 | - if (! $new_id = $this->_insert_into_posts($old_venue)) { |
|
| 77 | - $items_actually_migrated++; |
|
| 78 | - continue; |
|
| 79 | - } |
|
| 80 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_venue['id'], $this->_new_table, $new_id); |
|
| 81 | - if (! $new_meta_id = $this->_insert_into_meta_table($new_id, $old_venue)) { |
|
| 82 | - $items_actually_migrated++; |
|
| 83 | - continue; |
|
| 84 | - } |
|
| 85 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_venue['id'], $this->_new_meta_table, $new_meta_id); |
|
| 86 | - // lastly, save the 'contact' as post meta, because it doesn't exist anywhere else but someone may still want it |
|
| 87 | - $venue_meta = maybe_unserialize($old_venue['meta']); |
|
| 88 | - if (isset($venue_meta['contact']) && $venue_meta['contact']) { |
|
| 89 | - add_post_meta($new_id, 'contact', $venue_meta['contact']); |
|
| 90 | - } |
|
| 91 | - // is there an image on this venue? |
|
| 92 | - $guid = isset($venue_meta['image']) && $venue_meta['image'] ? $venue_meta['image'] : null; |
|
| 93 | - if ($guid) { |
|
| 94 | - $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this); |
|
| 95 | - } |
|
| 96 | - $items_actually_migrated++; |
|
| 97 | - if ($guid) { |
|
| 98 | - // if there was an image, we may have had to download it etc and it may have taken |
|
| 99 | - // longer, then let's not bother migrating anymore on this step |
|
| 100 | - break; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
| 104 | - $this->set_completed(); |
|
| 105 | - } |
|
| 106 | - return $items_actually_migrated; |
|
| 107 | - } |
|
| 108 | - public function _count_records_to_migrate() |
|
| 109 | - { |
|
| 110 | - global $wpdb; |
|
| 111 | - $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table); |
|
| 112 | - return $count; |
|
| 113 | - } |
|
| 114 | - public function __construct() |
|
| 115 | - { |
|
| 116 | - $this->_pretty_name = __("Venues", "event_espresso"); |
|
| 117 | - global $wpdb; |
|
| 118 | - $this->_old_table = $wpdb->prefix."events_venue"; |
|
| 119 | - $this->_new_table = $wpdb->posts; |
|
| 120 | - $this->_new_meta_table = $wpdb->prefix."esp_venue_meta"; |
|
| 121 | - parent::__construct(); |
|
| 122 | - } |
|
| 66 | + private $_old_table; |
|
| 67 | + private $_new_table; |
|
| 68 | + private $_new_meta_table; |
|
| 69 | + public function _migration_step($num_items = 50) |
|
| 70 | + { |
|
| 71 | + global $wpdb; |
|
| 72 | + $start_at_record = $this->count_records_migrated(); |
|
| 73 | + $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".$this->_old_table." LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A); |
|
| 74 | + $items_actually_migrated = 0; |
|
| 75 | + foreach ($rows as $old_venue) { |
|
| 76 | + if (! $new_id = $this->_insert_into_posts($old_venue)) { |
|
| 77 | + $items_actually_migrated++; |
|
| 78 | + continue; |
|
| 79 | + } |
|
| 80 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_venue['id'], $this->_new_table, $new_id); |
|
| 81 | + if (! $new_meta_id = $this->_insert_into_meta_table($new_id, $old_venue)) { |
|
| 82 | + $items_actually_migrated++; |
|
| 83 | + continue; |
|
| 84 | + } |
|
| 85 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_venue['id'], $this->_new_meta_table, $new_meta_id); |
|
| 86 | + // lastly, save the 'contact' as post meta, because it doesn't exist anywhere else but someone may still want it |
|
| 87 | + $venue_meta = maybe_unserialize($old_venue['meta']); |
|
| 88 | + if (isset($venue_meta['contact']) && $venue_meta['contact']) { |
|
| 89 | + add_post_meta($new_id, 'contact', $venue_meta['contact']); |
|
| 90 | + } |
|
| 91 | + // is there an image on this venue? |
|
| 92 | + $guid = isset($venue_meta['image']) && $venue_meta['image'] ? $venue_meta['image'] : null; |
|
| 93 | + if ($guid) { |
|
| 94 | + $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this); |
|
| 95 | + } |
|
| 96 | + $items_actually_migrated++; |
|
| 97 | + if ($guid) { |
|
| 98 | + // if there was an image, we may have had to download it etc and it may have taken |
|
| 99 | + // longer, then let's not bother migrating anymore on this step |
|
| 100 | + break; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
| 104 | + $this->set_completed(); |
|
| 105 | + } |
|
| 106 | + return $items_actually_migrated; |
|
| 107 | + } |
|
| 108 | + public function _count_records_to_migrate() |
|
| 109 | + { |
|
| 110 | + global $wpdb; |
|
| 111 | + $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table); |
|
| 112 | + return $count; |
|
| 113 | + } |
|
| 114 | + public function __construct() |
|
| 115 | + { |
|
| 116 | + $this->_pretty_name = __("Venues", "event_espresso"); |
|
| 117 | + global $wpdb; |
|
| 118 | + $this->_old_table = $wpdb->prefix."events_venue"; |
|
| 119 | + $this->_new_table = $wpdb->posts; |
|
| 120 | + $this->_new_meta_table = $wpdb->prefix."esp_venue_meta"; |
|
| 121 | + parent::__construct(); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * Inserts the CPT |
|
| 126 | - * @param array $old_venue keys are cols, values are col values |
|
| 127 | - * @return int |
|
| 128 | - */ |
|
| 129 | - private function _insert_into_posts($old_venue) |
|
| 130 | - { |
|
| 131 | - global $wpdb; |
|
| 132 | - $meta = maybe_unserialize($old_venue['meta']); |
|
| 133 | - $slug = $this->_find_unique_slug($old_venue['name'], $old_venue['identifier']); |
|
| 134 | - $insertion_array = array( |
|
| 135 | - 'post_title'=>stripslashes($old_venue['name']),// VNU_name |
|
| 136 | - 'post_content'=>isset($meta['description']) ? stripslashes(strip_tags($meta['description'])) : '',// VNU_desc |
|
| 137 | - 'post_name'=> $slug,// VNU_identifier |
|
| 138 | - 'post_date'=>current_time('mysql'),// VNU_created |
|
| 139 | - 'post_date_gmt'=> current_time('mysql', true), |
|
| 140 | - 'post_excerpt'=>'',// wp_trim_words($meta['description'] ? $meta['description'] : '',50),//VNU_short_desc arbitraty only 50 characters |
|
| 141 | - 'post_modified'=>current_time('mysql'),// VNU_modified |
|
| 142 | - 'post_modified_gmt'=>current_time('mysql', true), |
|
| 143 | - 'post_author'=>$old_venue['wp_user'],// VNU_wp_user |
|
| 144 | - 'post_parent'=>0,// parent |
|
| 145 | - 'menu_order'=>0,// VNU_order |
|
| 146 | - 'post_type'=>'espresso_venues'// post_type |
|
| 147 | - ); |
|
| 148 | - $datatypes_array = array( |
|
| 149 | - '%s',// VNU_name |
|
| 150 | - '%s',// VNU_desc |
|
| 151 | - '%s',// VNU_identifier |
|
| 152 | - '%s',// VNU_created |
|
| 153 | - '%s', |
|
| 154 | - '%s',// VNU_short_desc |
|
| 155 | - '%s',// VNU_modified |
|
| 156 | - '%s', |
|
| 157 | - '%d',// VNU_wp_user |
|
| 158 | - '%d',// parent |
|
| 159 | - '%d',// VNU_order |
|
| 160 | - '%s',// post_type |
|
| 161 | - ); |
|
| 162 | - $success = $wpdb->insert( |
|
| 163 | - $this->_new_table, |
|
| 164 | - $insertion_array, |
|
| 165 | - $datatypes_array |
|
| 166 | - ); |
|
| 167 | - if (! $success) { |
|
| 168 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_venue, $this->_new_table, $insertion_array, $datatypes_array)); |
|
| 169 | - return 0; |
|
| 170 | - } |
|
| 171 | - return $wpdb->insert_id; |
|
| 172 | - } |
|
| 124 | + /** |
|
| 125 | + * Inserts the CPT |
|
| 126 | + * @param array $old_venue keys are cols, values are col values |
|
| 127 | + * @return int |
|
| 128 | + */ |
|
| 129 | + private function _insert_into_posts($old_venue) |
|
| 130 | + { |
|
| 131 | + global $wpdb; |
|
| 132 | + $meta = maybe_unserialize($old_venue['meta']); |
|
| 133 | + $slug = $this->_find_unique_slug($old_venue['name'], $old_venue['identifier']); |
|
| 134 | + $insertion_array = array( |
|
| 135 | + 'post_title'=>stripslashes($old_venue['name']),// VNU_name |
|
| 136 | + 'post_content'=>isset($meta['description']) ? stripslashes(strip_tags($meta['description'])) : '',// VNU_desc |
|
| 137 | + 'post_name'=> $slug,// VNU_identifier |
|
| 138 | + 'post_date'=>current_time('mysql'),// VNU_created |
|
| 139 | + 'post_date_gmt'=> current_time('mysql', true), |
|
| 140 | + 'post_excerpt'=>'',// wp_trim_words($meta['description'] ? $meta['description'] : '',50),//VNU_short_desc arbitraty only 50 characters |
|
| 141 | + 'post_modified'=>current_time('mysql'),// VNU_modified |
|
| 142 | + 'post_modified_gmt'=>current_time('mysql', true), |
|
| 143 | + 'post_author'=>$old_venue['wp_user'],// VNU_wp_user |
|
| 144 | + 'post_parent'=>0,// parent |
|
| 145 | + 'menu_order'=>0,// VNU_order |
|
| 146 | + 'post_type'=>'espresso_venues'// post_type |
|
| 147 | + ); |
|
| 148 | + $datatypes_array = array( |
|
| 149 | + '%s',// VNU_name |
|
| 150 | + '%s',// VNU_desc |
|
| 151 | + '%s',// VNU_identifier |
|
| 152 | + '%s',// VNU_created |
|
| 153 | + '%s', |
|
| 154 | + '%s',// VNU_short_desc |
|
| 155 | + '%s',// VNU_modified |
|
| 156 | + '%s', |
|
| 157 | + '%d',// VNU_wp_user |
|
| 158 | + '%d',// parent |
|
| 159 | + '%d',// VNU_order |
|
| 160 | + '%s',// post_type |
|
| 161 | + ); |
|
| 162 | + $success = $wpdb->insert( |
|
| 163 | + $this->_new_table, |
|
| 164 | + $insertion_array, |
|
| 165 | + $datatypes_array |
|
| 166 | + ); |
|
| 167 | + if (! $success) { |
|
| 168 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_venue, $this->_new_table, $insertion_array, $datatypes_array)); |
|
| 169 | + return 0; |
|
| 170 | + } |
|
| 171 | + return $wpdb->insert_id; |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | - /** |
|
| 175 | - * Finds a unique slug for this venue, given its name (we could have simply used |
|
| 176 | - * the old unique_identifier column, but it added a long string of seemingly random characters onto the end |
|
| 177 | - * and really wasn't that pretty for a slug, so we decided we'd make our own slug again) |
|
| 178 | - * @param string $post_name |
|
| 179 | - * @return string |
|
| 180 | - */ |
|
| 181 | - private function _find_unique_slug($post_name, $old_identifier = '') |
|
| 182 | - { |
|
| 183 | - $count = 0; |
|
| 184 | - $original_name = $post_name ? sanitize_title($post_name) : $old_identifier; |
|
| 185 | - $event_slug = $original_name; |
|
| 186 | - while ($this->_other_post_exists_with_that_slug($event_slug) && $count<50) { |
|
| 187 | - $event_slug = sanitize_title($original_name."-".++$count); |
|
| 188 | - } |
|
| 189 | - return $event_slug; |
|
| 190 | - } |
|
| 174 | + /** |
|
| 175 | + * Finds a unique slug for this venue, given its name (we could have simply used |
|
| 176 | + * the old unique_identifier column, but it added a long string of seemingly random characters onto the end |
|
| 177 | + * and really wasn't that pretty for a slug, so we decided we'd make our own slug again) |
|
| 178 | + * @param string $post_name |
|
| 179 | + * @return string |
|
| 180 | + */ |
|
| 181 | + private function _find_unique_slug($post_name, $old_identifier = '') |
|
| 182 | + { |
|
| 183 | + $count = 0; |
|
| 184 | + $original_name = $post_name ? sanitize_title($post_name) : $old_identifier; |
|
| 185 | + $event_slug = $original_name; |
|
| 186 | + while ($this->_other_post_exists_with_that_slug($event_slug) && $count<50) { |
|
| 187 | + $event_slug = sanitize_title($original_name."-".++$count); |
|
| 188 | + } |
|
| 189 | + return $event_slug; |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | - /** |
|
| 193 | - * returns whether or not there is a post that has this same slug (post_title) |
|
| 194 | - * @global type $wpdb |
|
| 195 | - * @param type $slug |
|
| 196 | - * @return boolean |
|
| 197 | - */ |
|
| 198 | - private function _other_post_exists_with_that_slug($slug) |
|
| 199 | - { |
|
| 200 | - global $wpdb; |
|
| 201 | - $query = $wpdb->prepare("SELECT COUNT(ID) FROM ".$this->_new_table." WHERE post_name = %s", $slug); |
|
| 202 | - $count = $wpdb->get_var($query); |
|
| 203 | - return (boolean) intval($count); |
|
| 204 | - } |
|
| 192 | + /** |
|
| 193 | + * returns whether or not there is a post that has this same slug (post_title) |
|
| 194 | + * @global type $wpdb |
|
| 195 | + * @param type $slug |
|
| 196 | + * @return boolean |
|
| 197 | + */ |
|
| 198 | + private function _other_post_exists_with_that_slug($slug) |
|
| 199 | + { |
|
| 200 | + global $wpdb; |
|
| 201 | + $query = $wpdb->prepare("SELECT COUNT(ID) FROM ".$this->_new_table." WHERE post_name = %s", $slug); |
|
| 202 | + $count = $wpdb->get_var($query); |
|
| 203 | + return (boolean) intval($count); |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - /** |
|
| 207 | - * Inserts into the venue_meta table |
|
| 208 | - * @param type $cpt_id |
|
| 209 | - * @param type $old_venue |
|
| 210 | - * @return int |
|
| 211 | - */ |
|
| 212 | - private function _insert_into_meta_table($cpt_id, $old_venue) |
|
| 213 | - { |
|
| 214 | - global $wpdb; |
|
| 215 | - // get a country with the same name, or insert one |
|
| 216 | - try { |
|
| 217 | - $country = $this->get_migration_script()->get_or_create_country(stripslashes($old_venue['country'])); |
|
| 218 | - $country_iso = $country['CNT_ISO']; |
|
| 219 | - } catch (EE_Error $e) { |
|
| 220 | - $this->add_error(sprintf(__("%s for venue %s", "event_espresso"), $e->getMessage(), $this->_json_encode($old_venue))); |
|
| 221 | - $country_iso = null; |
|
| 222 | - } |
|
| 223 | - // get a state with the same name, if possible |
|
| 224 | - try { |
|
| 225 | - $state = $this->get_migration_script()->get_or_create_state(stripslashes($old_venue['state']), isset($country['CNT_name']) ? $country['CNT_name'] : strip_tags($old_venue['country'])); |
|
| 226 | - $state_id = $state['STA_ID']; |
|
| 227 | - } catch (EE_Error $e) { |
|
| 228 | - $this->add_error(sprintf(__("%s for venue %s", "event_espresso"), $e->getMessage(), $this->_json_encode($old_venue))); |
|
| 229 | - $state_id = 0; |
|
| 230 | - } |
|
| 231 | - $meta = maybe_unserialize($old_venue['meta']); |
|
| 232 | - // now insert into meta table |
|
| 233 | - $insertion_array = array( |
|
| 234 | - 'VNU_ID'=>$cpt_id,// VNU_ID_fk |
|
| 235 | - 'VNU_address'=>stripslashes($old_venue['address']),// VNU_address |
|
| 236 | - 'VNU_address2'=>stripslashes($old_venue['address2']),// VNU_address2 |
|
| 237 | - 'VNU_city'=>stripslashes($old_venue['city']),// VNU_city |
|
| 238 | - 'STA_ID'=>$state_id,// STA_ID |
|
| 239 | - 'CNT_ISO'=>$country_iso,// CNT_ISO |
|
| 240 | - 'VNU_zip'=>stripslashes($old_venue['zip']),// VNU_zip |
|
| 241 | - 'VNU_phone'=>isset($meta['phone']) ? stripslashes($meta['phone']) : '',// VNU_phone |
|
| 242 | - 'VNU_capacity'=>-1,// VNU_capacity |
|
| 243 | - 'VNU_url'=>isset($meta['website']) ? stripslashes($meta['website']) : '',// VNU_url |
|
| 244 | - 'VNU_virtual_phone'=>'',// VNU_virtual_phone |
|
| 245 | - 'VNU_virtual_url'=>'',// VNU_virtual_url |
|
| 246 | - 'VNU_google_map_link'=>'',// VNU_google_map_link |
|
| 247 | - 'VNU_enable_for_gmap'=>true // VNU_enable_for_gmap |
|
| 248 | - ); |
|
| 249 | - $datatypes = array( |
|
| 250 | - '%d',// VNU_ID_fk |
|
| 251 | - '%s',// VNU_address |
|
| 252 | - '%s',// VNU_address2 |
|
| 253 | - '%s',// VNU_city |
|
| 254 | - '%d',// STA_ID |
|
| 255 | - '%s',// CNT_ISO |
|
| 256 | - '%s',// VNU_zip |
|
| 257 | - '%s',// VNU_phone |
|
| 258 | - '%d',// VNU_capacity |
|
| 259 | - '%s',// VNU_url |
|
| 260 | - '%s',// VNU_virtual_phone |
|
| 261 | - '%s',// VNU_virtual_url |
|
| 262 | - '%s',// VNU_google_map_link |
|
| 263 | - '%d',// VNU_enable_for_gmap |
|
| 264 | - ); |
|
| 265 | - $success = $wpdb->insert($this->_new_meta_table, $insertion_array, $datatypes); |
|
| 266 | - if (! $success) { |
|
| 267 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_venue, $this->_new_meta_table, $insertion_array, $datatypes)); |
|
| 268 | - return 0; |
|
| 269 | - } |
|
| 270 | - return $wpdb->insert_id; |
|
| 271 | - } |
|
| 206 | + /** |
|
| 207 | + * Inserts into the venue_meta table |
|
| 208 | + * @param type $cpt_id |
|
| 209 | + * @param type $old_venue |
|
| 210 | + * @return int |
|
| 211 | + */ |
|
| 212 | + private function _insert_into_meta_table($cpt_id, $old_venue) |
|
| 213 | + { |
|
| 214 | + global $wpdb; |
|
| 215 | + // get a country with the same name, or insert one |
|
| 216 | + try { |
|
| 217 | + $country = $this->get_migration_script()->get_or_create_country(stripslashes($old_venue['country'])); |
|
| 218 | + $country_iso = $country['CNT_ISO']; |
|
| 219 | + } catch (EE_Error $e) { |
|
| 220 | + $this->add_error(sprintf(__("%s for venue %s", "event_espresso"), $e->getMessage(), $this->_json_encode($old_venue))); |
|
| 221 | + $country_iso = null; |
|
| 222 | + } |
|
| 223 | + // get a state with the same name, if possible |
|
| 224 | + try { |
|
| 225 | + $state = $this->get_migration_script()->get_or_create_state(stripslashes($old_venue['state']), isset($country['CNT_name']) ? $country['CNT_name'] : strip_tags($old_venue['country'])); |
|
| 226 | + $state_id = $state['STA_ID']; |
|
| 227 | + } catch (EE_Error $e) { |
|
| 228 | + $this->add_error(sprintf(__("%s for venue %s", "event_espresso"), $e->getMessage(), $this->_json_encode($old_venue))); |
|
| 229 | + $state_id = 0; |
|
| 230 | + } |
|
| 231 | + $meta = maybe_unserialize($old_venue['meta']); |
|
| 232 | + // now insert into meta table |
|
| 233 | + $insertion_array = array( |
|
| 234 | + 'VNU_ID'=>$cpt_id,// VNU_ID_fk |
|
| 235 | + 'VNU_address'=>stripslashes($old_venue['address']),// VNU_address |
|
| 236 | + 'VNU_address2'=>stripslashes($old_venue['address2']),// VNU_address2 |
|
| 237 | + 'VNU_city'=>stripslashes($old_venue['city']),// VNU_city |
|
| 238 | + 'STA_ID'=>$state_id,// STA_ID |
|
| 239 | + 'CNT_ISO'=>$country_iso,// CNT_ISO |
|
| 240 | + 'VNU_zip'=>stripslashes($old_venue['zip']),// VNU_zip |
|
| 241 | + 'VNU_phone'=>isset($meta['phone']) ? stripslashes($meta['phone']) : '',// VNU_phone |
|
| 242 | + 'VNU_capacity'=>-1,// VNU_capacity |
|
| 243 | + 'VNU_url'=>isset($meta['website']) ? stripslashes($meta['website']) : '',// VNU_url |
|
| 244 | + 'VNU_virtual_phone'=>'',// VNU_virtual_phone |
|
| 245 | + 'VNU_virtual_url'=>'',// VNU_virtual_url |
|
| 246 | + 'VNU_google_map_link'=>'',// VNU_google_map_link |
|
| 247 | + 'VNU_enable_for_gmap'=>true // VNU_enable_for_gmap |
|
| 248 | + ); |
|
| 249 | + $datatypes = array( |
|
| 250 | + '%d',// VNU_ID_fk |
|
| 251 | + '%s',// VNU_address |
|
| 252 | + '%s',// VNU_address2 |
|
| 253 | + '%s',// VNU_city |
|
| 254 | + '%d',// STA_ID |
|
| 255 | + '%s',// CNT_ISO |
|
| 256 | + '%s',// VNU_zip |
|
| 257 | + '%s',// VNU_phone |
|
| 258 | + '%d',// VNU_capacity |
|
| 259 | + '%s',// VNU_url |
|
| 260 | + '%s',// VNU_virtual_phone |
|
| 261 | + '%s',// VNU_virtual_url |
|
| 262 | + '%s',// VNU_google_map_link |
|
| 263 | + '%d',// VNU_enable_for_gmap |
|
| 264 | + ); |
|
| 265 | + $success = $wpdb->insert($this->_new_meta_table, $insertion_array, $datatypes); |
|
| 266 | + if (! $success) { |
|
| 267 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_venue, $this->_new_meta_table, $insertion_array, $datatypes)); |
|
| 268 | + return 0; |
|
| 269 | + } |
|
| 270 | + return $wpdb->insert_id; |
|
| 271 | + } |
|
| 272 | 272 | } |
@@ -73,12 +73,12 @@ discard block |
||
| 73 | 73 | $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".$this->_old_table." LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A); |
| 74 | 74 | $items_actually_migrated = 0; |
| 75 | 75 | foreach ($rows as $old_venue) { |
| 76 | - if (! $new_id = $this->_insert_into_posts($old_venue)) { |
|
| 76 | + if ( ! $new_id = $this->_insert_into_posts($old_venue)) { |
|
| 77 | 77 | $items_actually_migrated++; |
| 78 | 78 | continue; |
| 79 | 79 | } |
| 80 | 80 | $this->get_migration_script()->set_mapping($this->_old_table, $old_venue['id'], $this->_new_table, $new_id); |
| 81 | - if (! $new_meta_id = $this->_insert_into_meta_table($new_id, $old_venue)) { |
|
| 81 | + if ( ! $new_meta_id = $this->_insert_into_meta_table($new_id, $old_venue)) { |
|
| 82 | 82 | $items_actually_migrated++; |
| 83 | 83 | continue; |
| 84 | 84 | } |
@@ -132,39 +132,39 @@ discard block |
||
| 132 | 132 | $meta = maybe_unserialize($old_venue['meta']); |
| 133 | 133 | $slug = $this->_find_unique_slug($old_venue['name'], $old_venue['identifier']); |
| 134 | 134 | $insertion_array = array( |
| 135 | - 'post_title'=>stripslashes($old_venue['name']),// VNU_name |
|
| 136 | - 'post_content'=>isset($meta['description']) ? stripslashes(strip_tags($meta['description'])) : '',// VNU_desc |
|
| 137 | - 'post_name'=> $slug,// VNU_identifier |
|
| 138 | - 'post_date'=>current_time('mysql'),// VNU_created |
|
| 135 | + 'post_title'=>stripslashes($old_venue['name']), // VNU_name |
|
| 136 | + 'post_content'=>isset($meta['description']) ? stripslashes(strip_tags($meta['description'])) : '', // VNU_desc |
|
| 137 | + 'post_name'=> $slug, // VNU_identifier |
|
| 138 | + 'post_date'=>current_time('mysql'), // VNU_created |
|
| 139 | 139 | 'post_date_gmt'=> current_time('mysql', true), |
| 140 | - 'post_excerpt'=>'',// wp_trim_words($meta['description'] ? $meta['description'] : '',50),//VNU_short_desc arbitraty only 50 characters |
|
| 141 | - 'post_modified'=>current_time('mysql'),// VNU_modified |
|
| 140 | + 'post_excerpt'=>'', // wp_trim_words($meta['description'] ? $meta['description'] : '',50),//VNU_short_desc arbitraty only 50 characters |
|
| 141 | + 'post_modified'=>current_time('mysql'), // VNU_modified |
|
| 142 | 142 | 'post_modified_gmt'=>current_time('mysql', true), |
| 143 | - 'post_author'=>$old_venue['wp_user'],// VNU_wp_user |
|
| 144 | - 'post_parent'=>0,// parent |
|
| 145 | - 'menu_order'=>0,// VNU_order |
|
| 143 | + 'post_author'=>$old_venue['wp_user'], // VNU_wp_user |
|
| 144 | + 'post_parent'=>0, // parent |
|
| 145 | + 'menu_order'=>0, // VNU_order |
|
| 146 | 146 | 'post_type'=>'espresso_venues'// post_type |
| 147 | 147 | ); |
| 148 | 148 | $datatypes_array = array( |
| 149 | - '%s',// VNU_name |
|
| 150 | - '%s',// VNU_desc |
|
| 151 | - '%s',// VNU_identifier |
|
| 152 | - '%s',// VNU_created |
|
| 149 | + '%s', // VNU_name |
|
| 150 | + '%s', // VNU_desc |
|
| 151 | + '%s', // VNU_identifier |
|
| 152 | + '%s', // VNU_created |
|
| 153 | 153 | '%s', |
| 154 | - '%s',// VNU_short_desc |
|
| 155 | - '%s',// VNU_modified |
|
| 154 | + '%s', // VNU_short_desc |
|
| 155 | + '%s', // VNU_modified |
|
| 156 | 156 | '%s', |
| 157 | - '%d',// VNU_wp_user |
|
| 158 | - '%d',// parent |
|
| 159 | - '%d',// VNU_order |
|
| 160 | - '%s',// post_type |
|
| 157 | + '%d', // VNU_wp_user |
|
| 158 | + '%d', // parent |
|
| 159 | + '%d', // VNU_order |
|
| 160 | + '%s', // post_type |
|
| 161 | 161 | ); |
| 162 | 162 | $success = $wpdb->insert( |
| 163 | 163 | $this->_new_table, |
| 164 | 164 | $insertion_array, |
| 165 | 165 | $datatypes_array |
| 166 | 166 | ); |
| 167 | - if (! $success) { |
|
| 167 | + if ( ! $success) { |
|
| 168 | 168 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_venue, $this->_new_table, $insertion_array, $datatypes_array)); |
| 169 | 169 | return 0; |
| 170 | 170 | } |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | $count = 0; |
| 184 | 184 | $original_name = $post_name ? sanitize_title($post_name) : $old_identifier; |
| 185 | 185 | $event_slug = $original_name; |
| 186 | - while ($this->_other_post_exists_with_that_slug($event_slug) && $count<50) { |
|
| 186 | + while ($this->_other_post_exists_with_that_slug($event_slug) && $count < 50) { |
|
| 187 | 187 | $event_slug = sanitize_title($original_name."-".++$count); |
| 188 | 188 | } |
| 189 | 189 | return $event_slug; |
@@ -231,39 +231,39 @@ discard block |
||
| 231 | 231 | $meta = maybe_unserialize($old_venue['meta']); |
| 232 | 232 | // now insert into meta table |
| 233 | 233 | $insertion_array = array( |
| 234 | - 'VNU_ID'=>$cpt_id,// VNU_ID_fk |
|
| 235 | - 'VNU_address'=>stripslashes($old_venue['address']),// VNU_address |
|
| 236 | - 'VNU_address2'=>stripslashes($old_venue['address2']),// VNU_address2 |
|
| 237 | - 'VNU_city'=>stripslashes($old_venue['city']),// VNU_city |
|
| 238 | - 'STA_ID'=>$state_id,// STA_ID |
|
| 239 | - 'CNT_ISO'=>$country_iso,// CNT_ISO |
|
| 240 | - 'VNU_zip'=>stripslashes($old_venue['zip']),// VNU_zip |
|
| 241 | - 'VNU_phone'=>isset($meta['phone']) ? stripslashes($meta['phone']) : '',// VNU_phone |
|
| 242 | - 'VNU_capacity'=>-1,// VNU_capacity |
|
| 243 | - 'VNU_url'=>isset($meta['website']) ? stripslashes($meta['website']) : '',// VNU_url |
|
| 244 | - 'VNU_virtual_phone'=>'',// VNU_virtual_phone |
|
| 245 | - 'VNU_virtual_url'=>'',// VNU_virtual_url |
|
| 246 | - 'VNU_google_map_link'=>'',// VNU_google_map_link |
|
| 234 | + 'VNU_ID'=>$cpt_id, // VNU_ID_fk |
|
| 235 | + 'VNU_address'=>stripslashes($old_venue['address']), // VNU_address |
|
| 236 | + 'VNU_address2'=>stripslashes($old_venue['address2']), // VNU_address2 |
|
| 237 | + 'VNU_city'=>stripslashes($old_venue['city']), // VNU_city |
|
| 238 | + 'STA_ID'=>$state_id, // STA_ID |
|
| 239 | + 'CNT_ISO'=>$country_iso, // CNT_ISO |
|
| 240 | + 'VNU_zip'=>stripslashes($old_venue['zip']), // VNU_zip |
|
| 241 | + 'VNU_phone'=>isset($meta['phone']) ? stripslashes($meta['phone']) : '', // VNU_phone |
|
| 242 | + 'VNU_capacity'=>-1, // VNU_capacity |
|
| 243 | + 'VNU_url'=>isset($meta['website']) ? stripslashes($meta['website']) : '', // VNU_url |
|
| 244 | + 'VNU_virtual_phone'=>'', // VNU_virtual_phone |
|
| 245 | + 'VNU_virtual_url'=>'', // VNU_virtual_url |
|
| 246 | + 'VNU_google_map_link'=>'', // VNU_google_map_link |
|
| 247 | 247 | 'VNU_enable_for_gmap'=>true // VNU_enable_for_gmap |
| 248 | 248 | ); |
| 249 | 249 | $datatypes = array( |
| 250 | - '%d',// VNU_ID_fk |
|
| 251 | - '%s',// VNU_address |
|
| 252 | - '%s',// VNU_address2 |
|
| 253 | - '%s',// VNU_city |
|
| 254 | - '%d',// STA_ID |
|
| 255 | - '%s',// CNT_ISO |
|
| 256 | - '%s',// VNU_zip |
|
| 257 | - '%s',// VNU_phone |
|
| 258 | - '%d',// VNU_capacity |
|
| 259 | - '%s',// VNU_url |
|
| 260 | - '%s',// VNU_virtual_phone |
|
| 261 | - '%s',// VNU_virtual_url |
|
| 262 | - '%s',// VNU_google_map_link |
|
| 263 | - '%d',// VNU_enable_for_gmap |
|
| 250 | + '%d', // VNU_ID_fk |
|
| 251 | + '%s', // VNU_address |
|
| 252 | + '%s', // VNU_address2 |
|
| 253 | + '%s', // VNU_city |
|
| 254 | + '%d', // STA_ID |
|
| 255 | + '%s', // CNT_ISO |
|
| 256 | + '%s', // VNU_zip |
|
| 257 | + '%s', // VNU_phone |
|
| 258 | + '%d', // VNU_capacity |
|
| 259 | + '%s', // VNU_url |
|
| 260 | + '%s', // VNU_virtual_phone |
|
| 261 | + '%s', // VNU_virtual_url |
|
| 262 | + '%s', // VNU_google_map_link |
|
| 263 | + '%d', // VNU_enable_for_gmap |
|
| 264 | 264 | ); |
| 265 | 265 | $success = $wpdb->insert($this->_new_meta_table, $insertion_array, $datatypes); |
| 266 | - if (! $success) { |
|
| 266 | + if ( ! $success) { |
|
| 267 | 267 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_venue, $this->_new_meta_table, $insertion_array, $datatypes)); |
| 268 | 268 | return 0; |
| 269 | 269 | } |
@@ -128,6 +128,9 @@ discard block |
||
| 128 | 128 | return $items_actually_migrated; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | + /** |
|
| 132 | + * @param integer $num_items_to_migrate |
|
| 133 | + */ |
|
| 131 | 134 | private function _gather_relations_to_add($num_items_to_migrate) |
| 132 | 135 | { |
| 133 | 136 | $relations_to_add_this_step = array(); |
@@ -160,8 +163,6 @@ discard block |
||
| 160 | 163 | |
| 161 | 164 | /** |
| 162 | 165 | * Adds teh relation between the payment method and the currencies it can be used for |
| 163 | - * @param int $id |
|
| 164 | - * @param string $gateway_slug |
|
| 165 | 166 | */ |
| 166 | 167 | private function _add_currency_relations($pm_id, $currency_code) |
| 167 | 168 | { |
@@ -12,174 +12,174 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class EE_DMS_4_6_0_payment_method_currencies extends EE_Data_Migration_Script_Stage |
| 14 | 14 | { |
| 15 | - protected $_currency_table_name; |
|
| 16 | - protected $_currency_payment_method_table_name; |
|
| 17 | - protected $_payment_method_table_name; |
|
| 18 | - /** |
|
| 19 | - * each key is the name of a 4.1-style gateway we know how to migrate to 4.6 |
|
| 20 | - * @var array |
|
| 21 | - */ |
|
| 22 | - protected $_gateway_currencies = array( |
|
| 23 | - 'Aim' => array( |
|
| 24 | - 'AUD', |
|
| 25 | - 'USD', |
|
| 26 | - 'CAD', |
|
| 27 | - 'EUR', |
|
| 28 | - 'GBP', |
|
| 29 | - 'NZD', |
|
| 30 | - ), |
|
| 31 | - 'Bank' => 'all', |
|
| 32 | - 'Check' => 'all', |
|
| 33 | - 'Invoice' => 'all', |
|
| 34 | - 'Mijireh' => 'all', |
|
| 35 | - 'Paypal_Pro' => array( |
|
| 36 | - 'USD', |
|
| 37 | - 'GBP', |
|
| 38 | - 'CAD', |
|
| 39 | - 'AUD', |
|
| 40 | - 'BRL', |
|
| 41 | - 'CHF', |
|
| 42 | - 'CZK', |
|
| 43 | - 'DKK', |
|
| 44 | - 'EUR', |
|
| 45 | - 'HKD', |
|
| 46 | - 'HUF', |
|
| 47 | - 'ILS', |
|
| 48 | - 'JPY', |
|
| 49 | - 'MXN', |
|
| 50 | - 'MYR', |
|
| 51 | - 'NOK', |
|
| 52 | - 'NZD', |
|
| 53 | - 'PHP', |
|
| 54 | - 'PLN', |
|
| 55 | - 'SEK', |
|
| 56 | - 'SGD', |
|
| 57 | - 'THB', |
|
| 58 | - 'TRY', |
|
| 59 | - 'TWD', |
|
| 60 | - ), |
|
| 61 | - 'Paypal_Standard' => array( |
|
| 62 | - 'USD', |
|
| 63 | - 'GBP', |
|
| 64 | - 'CAD', |
|
| 65 | - 'AUD', |
|
| 66 | - 'BRL', |
|
| 67 | - 'CHF', |
|
| 68 | - 'CZK', |
|
| 69 | - 'DKK', |
|
| 70 | - 'EUR', |
|
| 71 | - 'HKD', |
|
| 72 | - 'HUF', |
|
| 73 | - 'ILS', |
|
| 74 | - 'JPY', |
|
| 75 | - 'MXN', |
|
| 76 | - 'MYR', |
|
| 77 | - 'NOK', |
|
| 78 | - 'NZD', |
|
| 79 | - 'PHP', |
|
| 80 | - 'PLN', |
|
| 81 | - 'SEK', |
|
| 82 | - 'SGD', |
|
| 83 | - 'THB', |
|
| 84 | - 'TRY', |
|
| 85 | - 'TWD' |
|
| 86 | - ) |
|
| 87 | - ); |
|
| 88 | - public function __construct() |
|
| 89 | - { |
|
| 90 | - global $wpdb; |
|
| 91 | - $this->_pretty_name = __('Payment Method Currencies', 'event_espresso'); |
|
| 92 | - $this->_payment_method_table_name = $wpdb->prefix.'esp_payment_method'; |
|
| 93 | - $this->_currency_payment_method_table_name = $wpdb->prefix.'esp_currency_payment_method'; |
|
| 94 | - $this->_currency_table_name = $wpdb->prefix.'esp_currency'; |
|
| 95 | - parent::__construct(); |
|
| 96 | - } |
|
| 15 | + protected $_currency_table_name; |
|
| 16 | + protected $_currency_payment_method_table_name; |
|
| 17 | + protected $_payment_method_table_name; |
|
| 18 | + /** |
|
| 19 | + * each key is the name of a 4.1-style gateway we know how to migrate to 4.6 |
|
| 20 | + * @var array |
|
| 21 | + */ |
|
| 22 | + protected $_gateway_currencies = array( |
|
| 23 | + 'Aim' => array( |
|
| 24 | + 'AUD', |
|
| 25 | + 'USD', |
|
| 26 | + 'CAD', |
|
| 27 | + 'EUR', |
|
| 28 | + 'GBP', |
|
| 29 | + 'NZD', |
|
| 30 | + ), |
|
| 31 | + 'Bank' => 'all', |
|
| 32 | + 'Check' => 'all', |
|
| 33 | + 'Invoice' => 'all', |
|
| 34 | + 'Mijireh' => 'all', |
|
| 35 | + 'Paypal_Pro' => array( |
|
| 36 | + 'USD', |
|
| 37 | + 'GBP', |
|
| 38 | + 'CAD', |
|
| 39 | + 'AUD', |
|
| 40 | + 'BRL', |
|
| 41 | + 'CHF', |
|
| 42 | + 'CZK', |
|
| 43 | + 'DKK', |
|
| 44 | + 'EUR', |
|
| 45 | + 'HKD', |
|
| 46 | + 'HUF', |
|
| 47 | + 'ILS', |
|
| 48 | + 'JPY', |
|
| 49 | + 'MXN', |
|
| 50 | + 'MYR', |
|
| 51 | + 'NOK', |
|
| 52 | + 'NZD', |
|
| 53 | + 'PHP', |
|
| 54 | + 'PLN', |
|
| 55 | + 'SEK', |
|
| 56 | + 'SGD', |
|
| 57 | + 'THB', |
|
| 58 | + 'TRY', |
|
| 59 | + 'TWD', |
|
| 60 | + ), |
|
| 61 | + 'Paypal_Standard' => array( |
|
| 62 | + 'USD', |
|
| 63 | + 'GBP', |
|
| 64 | + 'CAD', |
|
| 65 | + 'AUD', |
|
| 66 | + 'BRL', |
|
| 67 | + 'CHF', |
|
| 68 | + 'CZK', |
|
| 69 | + 'DKK', |
|
| 70 | + 'EUR', |
|
| 71 | + 'HKD', |
|
| 72 | + 'HUF', |
|
| 73 | + 'ILS', |
|
| 74 | + 'JPY', |
|
| 75 | + 'MXN', |
|
| 76 | + 'MYR', |
|
| 77 | + 'NOK', |
|
| 78 | + 'NZD', |
|
| 79 | + 'PHP', |
|
| 80 | + 'PLN', |
|
| 81 | + 'SEK', |
|
| 82 | + 'SGD', |
|
| 83 | + 'THB', |
|
| 84 | + 'TRY', |
|
| 85 | + 'TWD' |
|
| 86 | + ) |
|
| 87 | + ); |
|
| 88 | + public function __construct() |
|
| 89 | + { |
|
| 90 | + global $wpdb; |
|
| 91 | + $this->_pretty_name = __('Payment Method Currencies', 'event_espresso'); |
|
| 92 | + $this->_payment_method_table_name = $wpdb->prefix.'esp_payment_method'; |
|
| 93 | + $this->_currency_payment_method_table_name = $wpdb->prefix.'esp_currency_payment_method'; |
|
| 94 | + $this->_currency_table_name = $wpdb->prefix.'esp_currency'; |
|
| 95 | + parent::__construct(); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - protected function _count_records_to_migrate() |
|
| 99 | - { |
|
| 100 | - $count = 0; |
|
| 101 | - foreach ($this->_gateway_currencies as $currencies) { |
|
| 102 | - if ($currencies == 'all') { |
|
| 103 | - $currencies = $this->_get_all_currencies(); |
|
| 104 | - } |
|
| 105 | - $count += count($currencies); |
|
| 106 | - } |
|
| 107 | - return $count; |
|
| 108 | - } |
|
| 98 | + protected function _count_records_to_migrate() |
|
| 99 | + { |
|
| 100 | + $count = 0; |
|
| 101 | + foreach ($this->_gateway_currencies as $currencies) { |
|
| 102 | + if ($currencies == 'all') { |
|
| 103 | + $currencies = $this->_get_all_currencies(); |
|
| 104 | + } |
|
| 105 | + $count += count($currencies); |
|
| 106 | + } |
|
| 107 | + return $count; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | 110 | |
| 111 | 111 | |
| 112 | - protected function _migration_step($num_items_to_migrate = 50) |
|
| 113 | - { |
|
| 114 | - $items_actually_migrated = 0; |
|
| 115 | - $relations_to_add_this_step = $this->_gather_relations_to_add($num_items_to_migrate); |
|
| 116 | - foreach ($relations_to_add_this_step as $pm_slug => $currencies) { |
|
| 117 | - $id = $this->get_migration_script()->get_mapping_new_pk('EE_Gateway_Config', $pm_slug, $this->_payment_method_table_name); |
|
| 118 | - foreach ($currencies as $currency) { |
|
| 119 | - if ($id) { |
|
| 120 | - $this->_add_currency_relations($id, $currency); |
|
| 121 | - } |
|
| 122 | - $items_actually_migrated++; |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
| 126 | - $this->set_completed(); |
|
| 127 | - } |
|
| 128 | - return $items_actually_migrated; |
|
| 129 | - } |
|
| 112 | + protected function _migration_step($num_items_to_migrate = 50) |
|
| 113 | + { |
|
| 114 | + $items_actually_migrated = 0; |
|
| 115 | + $relations_to_add_this_step = $this->_gather_relations_to_add($num_items_to_migrate); |
|
| 116 | + foreach ($relations_to_add_this_step as $pm_slug => $currencies) { |
|
| 117 | + $id = $this->get_migration_script()->get_mapping_new_pk('EE_Gateway_Config', $pm_slug, $this->_payment_method_table_name); |
|
| 118 | + foreach ($currencies as $currency) { |
|
| 119 | + if ($id) { |
|
| 120 | + $this->_add_currency_relations($id, $currency); |
|
| 121 | + } |
|
| 122 | + $items_actually_migrated++; |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
| 126 | + $this->set_completed(); |
|
| 127 | + } |
|
| 128 | + return $items_actually_migrated; |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - private function _gather_relations_to_add($num_items_to_migrate) |
|
| 132 | - { |
|
| 133 | - $relations_to_add_this_step = array(); |
|
| 134 | - $migrate_up_to_count = $this->count_records_migrated() + $num_items_to_migrate; |
|
| 135 | - $iterator = 0; |
|
| 136 | - foreach ($this->_gateway_currencies as $pm_slug => $currencies) { |
|
| 137 | - if ($currencies == 'all') { |
|
| 138 | - $currencies = $this->_get_all_currencies(); |
|
| 139 | - } |
|
| 140 | - foreach ($currencies as $currency_code) { |
|
| 141 | - if ($this->count_records_migrated() <= $iterator && |
|
| 142 | - $iterator < $migrate_up_to_count ) { |
|
| 143 | - $relations_to_add_this_step[ $pm_slug ] [] = $currency_code; |
|
| 144 | - } |
|
| 145 | - $iterator++; |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - return $relations_to_add_this_step; |
|
| 149 | - } |
|
| 150 | - /** |
|
| 151 | - * Gets all the currency codes in the database |
|
| 152 | - * @return array |
|
| 153 | - */ |
|
| 154 | - private function _get_all_currencies() |
|
| 155 | - { |
|
| 156 | - global $wpdb; |
|
| 157 | - $currencies = $wpdb->get_col("SELECT CUR_code FROM {$this->_currency_table_name}"); |
|
| 158 | - return $currencies; |
|
| 159 | - } |
|
| 131 | + private function _gather_relations_to_add($num_items_to_migrate) |
|
| 132 | + { |
|
| 133 | + $relations_to_add_this_step = array(); |
|
| 134 | + $migrate_up_to_count = $this->count_records_migrated() + $num_items_to_migrate; |
|
| 135 | + $iterator = 0; |
|
| 136 | + foreach ($this->_gateway_currencies as $pm_slug => $currencies) { |
|
| 137 | + if ($currencies == 'all') { |
|
| 138 | + $currencies = $this->_get_all_currencies(); |
|
| 139 | + } |
|
| 140 | + foreach ($currencies as $currency_code) { |
|
| 141 | + if ($this->count_records_migrated() <= $iterator && |
|
| 142 | + $iterator < $migrate_up_to_count ) { |
|
| 143 | + $relations_to_add_this_step[ $pm_slug ] [] = $currency_code; |
|
| 144 | + } |
|
| 145 | + $iterator++; |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + return $relations_to_add_this_step; |
|
| 149 | + } |
|
| 150 | + /** |
|
| 151 | + * Gets all the currency codes in the database |
|
| 152 | + * @return array |
|
| 153 | + */ |
|
| 154 | + private function _get_all_currencies() |
|
| 155 | + { |
|
| 156 | + global $wpdb; |
|
| 157 | + $currencies = $wpdb->get_col("SELECT CUR_code FROM {$this->_currency_table_name}"); |
|
| 158 | + return $currencies; |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - /** |
|
| 162 | - * Adds teh relation between the payment method and the currencies it can be used for |
|
| 163 | - * @param int $id |
|
| 164 | - * @param string $gateway_slug |
|
| 165 | - */ |
|
| 166 | - private function _add_currency_relations($pm_id, $currency_code) |
|
| 167 | - { |
|
| 168 | - global $wpdb; |
|
| 169 | - $cur_pm_relation = array( |
|
| 170 | - 'CUR_code'=>$currency_code, |
|
| 171 | - 'PMD_ID'=>$pm_id, |
|
| 172 | - ); |
|
| 173 | - $success = $wpdb->insert( |
|
| 174 | - $this->_currency_payment_method_table_name, |
|
| 175 | - $cur_pm_relation, |
|
| 176 | - array( |
|
| 177 | - '%s',// CUR_code |
|
| 178 | - '%d',// PMD_ID |
|
| 179 | - ) |
|
| 180 | - ); |
|
| 181 | - if (! $success) { |
|
| 182 | - $this->add_error(sprintf(__('Could not add currency relation %s because %s', "event_espresso"), wp_json_encode($cur_pm_relation), $wpdb->last_error)); |
|
| 183 | - } |
|
| 184 | - } |
|
| 161 | + /** |
|
| 162 | + * Adds teh relation between the payment method and the currencies it can be used for |
|
| 163 | + * @param int $id |
|
| 164 | + * @param string $gateway_slug |
|
| 165 | + */ |
|
| 166 | + private function _add_currency_relations($pm_id, $currency_code) |
|
| 167 | + { |
|
| 168 | + global $wpdb; |
|
| 169 | + $cur_pm_relation = array( |
|
| 170 | + 'CUR_code'=>$currency_code, |
|
| 171 | + 'PMD_ID'=>$pm_id, |
|
| 172 | + ); |
|
| 173 | + $success = $wpdb->insert( |
|
| 174 | + $this->_currency_payment_method_table_name, |
|
| 175 | + $cur_pm_relation, |
|
| 176 | + array( |
|
| 177 | + '%s',// CUR_code |
|
| 178 | + '%d',// PMD_ID |
|
| 179 | + ) |
|
| 180 | + ); |
|
| 181 | + if (! $success) { |
|
| 182 | + $this->add_error(sprintf(__('Could not add currency relation %s because %s', "event_espresso"), wp_json_encode($cur_pm_relation), $wpdb->last_error)); |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | 185 | } |
@@ -139,8 +139,8 @@ discard block |
||
| 139 | 139 | } |
| 140 | 140 | foreach ($currencies as $currency_code) { |
| 141 | 141 | if ($this->count_records_migrated() <= $iterator && |
| 142 | - $iterator < $migrate_up_to_count ) { |
|
| 143 | - $relations_to_add_this_step[ $pm_slug ] [] = $currency_code; |
|
| 142 | + $iterator < $migrate_up_to_count) { |
|
| 143 | + $relations_to_add_this_step[$pm_slug] [] = $currency_code; |
|
| 144 | 144 | } |
| 145 | 145 | $iterator++; |
| 146 | 146 | } |
@@ -174,11 +174,11 @@ discard block |
||
| 174 | 174 | $this->_currency_payment_method_table_name, |
| 175 | 175 | $cur_pm_relation, |
| 176 | 176 | array( |
| 177 | - '%s',// CUR_code |
|
| 178 | - '%d',// PMD_ID |
|
| 177 | + '%s', // CUR_code |
|
| 178 | + '%d', // PMD_ID |
|
| 179 | 179 | ) |
| 180 | 180 | ); |
| 181 | - if (! $success) { |
|
| 181 | + if ( ! $success) { |
|
| 182 | 182 | $this->add_error(sprintf(__('Could not add currency relation %s because %s', "event_espresso"), wp_json_encode($cur_pm_relation), $wpdb->last_error)); |
| 183 | 183 | } |
| 184 | 184 | } |