Completed
Branch BUG/many-migration-woes (79151c)
by
unknown
18:51 queued 09:48
created
data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_attendees.dmsstage.php 2 patches
Indentation   +601 added lines, -605 removed lines patch added patch discarded remove patch
@@ -53,10 +53,6 @@  discard block
 block discarded – undo
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,637 +182,637 @@  discard block
 block discarded – undo
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
-        // Only select the event status column from the event table.
213
-        $this->select_expression = 'att.*, e.event_status';
214
-        // Only select attendees for events that aren't deleted.
215
-        $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
+		// Only select the event status column from the event table.
209
+		$this->select_expression = 'att.*, e.event_status';
210
+		// Only select attendees for events that aren't deleted.
211
+		$this->_extra_where_sql = 'AS att
216 212
             INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id
217 213
             WHERE e.event_status!="D"';
218
-        $this->_old_mer_table = $wpdb->prefix."events_multi_event_registration_id_group";
219
-        $this->_new_attendee_cpt_table = $wpdb->posts;
220
-        $this->_new_attendee_meta_table = $wpdb->prefix."esp_attendee_meta";
221
-        $this->_new_reg_table = $wpdb->prefix."esp_registration";
222
-        $this->_new_transaction_table = $wpdb->prefix."esp_transaction";
223
-        $this->_new_payment_table = $wpdb->prefix."esp_payment";
224
-        $this->_new_line_table = $wpdb->prefix."esp_line_item";
225
-        $this->_new_ticket_table = $wpdb->prefix."esp_ticket";
226
-        $this->_new_ticket_datetime_table = $wpdb->prefix."esp_datetime_ticket";
227
-        $this->_new_datetime_table = $wpdb->prefix."esp_datetime";
228
-        $this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket";
229
-        $this->_new_price_table = $wpdb->prefix."esp_price";
230
-        $this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price";
231
-        parent::__construct();
232
-    }
214
+		$this->_old_mer_table = $wpdb->prefix."events_multi_event_registration_id_group";
215
+		$this->_new_attendee_cpt_table = $wpdb->posts;
216
+		$this->_new_attendee_meta_table = $wpdb->prefix."esp_attendee_meta";
217
+		$this->_new_reg_table = $wpdb->prefix."esp_registration";
218
+		$this->_new_transaction_table = $wpdb->prefix."esp_transaction";
219
+		$this->_new_payment_table = $wpdb->prefix."esp_payment";
220
+		$this->_new_line_table = $wpdb->prefix."esp_line_item";
221
+		$this->_new_ticket_table = $wpdb->prefix."esp_ticket";
222
+		$this->_new_ticket_datetime_table = $wpdb->prefix."esp_datetime_ticket";
223
+		$this->_new_datetime_table = $wpdb->prefix."esp_datetime";
224
+		$this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket";
225
+		$this->_new_price_table = $wpdb->prefix."esp_price";
226
+		$this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price";
227
+		parent::__construct();
228
+	}
233 229
 
234
-    protected function _migrate_old_row($old_row)
235
-    {
236
-        // first check if there's already a new attendee with similar characteristics
237
-        $new_att_id = $this->_find_attendee_cpt_matching($old_row);
238
-        if (! $new_att_id) {
239
-            $new_att_id = $this->_insert_new_attendee_cpt($old_row);
240
-            if (! $new_att_id) {
241
-                // if we couldnt even make an attendee, abandon all hope
242
-                return false;
243
-            }
244
-            $new_att_meta_id = $this->_insert_attendee_meta_row($old_row, $new_att_id);
245
-            if ($new_att_meta_id) {
246
-                $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_meta_table, $new_att_meta_id);
247
-            }
248
-        }
249
-        $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_cpt_table, $new_att_id);
230
+	protected function _migrate_old_row($old_row)
231
+	{
232
+		// first check if there's already a new attendee with similar characteristics
233
+		$new_att_id = $this->_find_attendee_cpt_matching($old_row);
234
+		if (! $new_att_id) {
235
+			$new_att_id = $this->_insert_new_attendee_cpt($old_row);
236
+			if (! $new_att_id) {
237
+				// if we couldnt even make an attendee, abandon all hope
238
+				return false;
239
+			}
240
+			$new_att_meta_id = $this->_insert_attendee_meta_row($old_row, $new_att_id);
241
+			if ($new_att_meta_id) {
242
+				$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_meta_table, $new_att_meta_id);
243
+			}
244
+		}
245
+		$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_cpt_table, $new_att_id);
250 246
 
251
-        $txn_id = $this->_insert_new_transaction($old_row);
252
-        if (! $txn_id) {
253
-            // if we couldnt make the transaction, also abandon all hope
254
-            return false;
255
-        }
256
-        $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_transaction_table, $txn_id);
257
-        $pay_id = $this->_insert_new_payment($old_row, $txn_id);
258
-        if ($pay_id) {
259
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_payment_table, $pay_id);
260
-        }
247
+		$txn_id = $this->_insert_new_transaction($old_row);
248
+		if (! $txn_id) {
249
+			// if we couldnt make the transaction, also abandon all hope
250
+			return false;
251
+		}
252
+		$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_transaction_table, $txn_id);
253
+		$pay_id = $this->_insert_new_payment($old_row, $txn_id);
254
+		if ($pay_id) {
255
+			$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_payment_table, $pay_id);
256
+		}
261 257
 
262 258
 
263
-        // even if there was no payment, we can go ahead with adding the reg
264
-        $new_regs = $this->_insert_new_registrations($old_row, $new_att_id, $txn_id);
265
-        if ($new_regs) {
266
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_reg_table, $new_regs);
267
-        }
268
-    }
269
-    /**
270
-     * Checks if there's already an attendee CPT in the db that has the same
271
-     * first and last name, and email. If so, returns its ID as an int.
272
-     * @global type $wpdb
273
-     * @param array $old_attendee
274
-     * @return int
275
-     */
276
-    private function _find_attendee_cpt_matching($old_attendee)
277
-    {
278
-        global $wpdb;
279
-        $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']));
280
-        return intval($existing_attendee_id);
281
-    }
282
-    private function _insert_new_attendee_cpt($old_attendee)
283
-    {
284
-        global $wpdb;
285
-        $cols_n_values = array(
286
-            'post_title'=>stripslashes($old_attendee['fname']." ".$old_attendee['lname']),// ATT_full_name
287
-            'post_content'=>'',// ATT_bio
288
-            'post_name'=>sanitize_title($old_attendee['fname']."-".$old_attendee['lname']),// ATT_slug
289
-            'post_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_created
290
-            'post_excerpt'=>'',// ATT_short_bio
291
-            'post_modified'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_modified
292
-            'post_author'=>0,// ATT_author
293
-            'post_parent'=>0,// ATT_parent
294
-            'post_type'=>'espresso_attendees',// post_type
295
-            'post_status'=>'publish'// status
296
-        );
297
-        $datatypes = array(
298
-            '%s',// ATT_full_name
299
-            '%s',// ATT_bio
300
-            '%s',// ATT_slug
301
-            '%s',// ATT_created
302
-            '%s',// ATT_short_bio
303
-            '%s',// ATT_modified
304
-            '%d',// ATT_author
305
-            '%d',// ATT_parent
306
-            '%s',// post_type
307
-            '%s',// status
308
-        );
309
-        $success = $wpdb->insert($this->_new_attendee_cpt_table, $cols_n_values, $datatypes);
310
-        if (! $success) {
311
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes));
312
-            return 0;
313
-        }
314
-        $new_id = $wpdb->insert_id;
315
-        return $new_id;
316
-    }
259
+		// even if there was no payment, we can go ahead with adding the reg
260
+		$new_regs = $this->_insert_new_registrations($old_row, $new_att_id, $txn_id);
261
+		if ($new_regs) {
262
+			$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_reg_table, $new_regs);
263
+		}
264
+	}
265
+	/**
266
+	 * Checks if there's already an attendee CPT in the db that has the same
267
+	 * first and last name, and email. If so, returns its ID as an int.
268
+	 * @global type $wpdb
269
+	 * @param array $old_attendee
270
+	 * @return int
271
+	 */
272
+	private function _find_attendee_cpt_matching($old_attendee)
273
+	{
274
+		global $wpdb;
275
+		$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']));
276
+		return intval($existing_attendee_id);
277
+	}
278
+	private function _insert_new_attendee_cpt($old_attendee)
279
+	{
280
+		global $wpdb;
281
+		$cols_n_values = array(
282
+			'post_title'=>stripslashes($old_attendee['fname']." ".$old_attendee['lname']),// ATT_full_name
283
+			'post_content'=>'',// ATT_bio
284
+			'post_name'=>sanitize_title($old_attendee['fname']."-".$old_attendee['lname']),// ATT_slug
285
+			'post_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_created
286
+			'post_excerpt'=>'',// ATT_short_bio
287
+			'post_modified'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_modified
288
+			'post_author'=>0,// ATT_author
289
+			'post_parent'=>0,// ATT_parent
290
+			'post_type'=>'espresso_attendees',// post_type
291
+			'post_status'=>'publish'// status
292
+		);
293
+		$datatypes = array(
294
+			'%s',// ATT_full_name
295
+			'%s',// ATT_bio
296
+			'%s',// ATT_slug
297
+			'%s',// ATT_created
298
+			'%s',// ATT_short_bio
299
+			'%s',// ATT_modified
300
+			'%d',// ATT_author
301
+			'%d',// ATT_parent
302
+			'%s',// post_type
303
+			'%s',// status
304
+		);
305
+		$success = $wpdb->insert($this->_new_attendee_cpt_table, $cols_n_values, $datatypes);
306
+		if (! $success) {
307
+			$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));
308
+			return 0;
309
+		}
310
+		$new_id = $wpdb->insert_id;
311
+		return $new_id;
312
+	}
317 313
 
318
-    private function _insert_attendee_meta_row($old_attendee, $new_attendee_cpt_id)
319
-    {
320
-        global $wpdb;
321
-        // get the state and country ids from the old row
322
-        try {
323
-            $new_country = $this->get_migration_script()->get_or_create_country(stripslashes($old_attendee['country_id']));
324
-            $new_country_iso = $new_country['CNT_ISO'];
325
-        } catch (EE_Error $exception) {
326
-            $new_country_iso = $this->get_migration_script()->get_default_country_iso();
327
-        }
328
-        try {
329
-            $new_state = $this->get_migration_script()->get_or_create_state(stripslashes($old_attendee['state']), $new_country_iso);
330
-            $new_state_id = $new_state['STA_ID'];
331
-        } catch (EE_Error $exception) {
332
-            $new_state_id = 0;
333
-        }
334
-        $cols_n_values = array(
335
-            'ATT_ID'=>$new_attendee_cpt_id,
336
-            'ATT_fname'=>stripslashes($old_attendee['fname']),
337
-            'ATT_lname'=>stripslashes($old_attendee['lname']),
338
-            'ATT_address'=>stripslashes($old_attendee['address']),
339
-            'ATT_address2'=>stripslashes($old_attendee['address2']),
340
-            'ATT_city'=>stripslashes($old_attendee['city']),
341
-            'STA_ID'=>$new_state_id,
342
-            'CNT_ISO'=>$new_country_iso,
343
-            'ATT_zip'=>stripslashes($old_attendee['zip']),
344
-            'ATT_email'=>stripslashes($old_attendee['email']),
345
-            'ATT_phone'=>stripslashes($old_attendee['phone']),
346
-        );
347
-        $datatypes = array(
348
-            '%d',// ATT_ID
349
-            '%s',// ATT_fname
350
-            '%s',// ATT_lname
351
-            '%s',// ATT_address
352
-            '%s',// ATT_address2
353
-            '%s',// ATT_city
354
-            '%d',// STA_ID
355
-            '%s',// CNT_ISO
356
-            '%s',// ATT_zip
357
-            '%s',// ATT_email
358
-            '%s',// ATT_phone
359
-        );
360
-        $success = $wpdb->insert($this->_new_attendee_meta_table, $cols_n_values, $datatypes);
361
-        if (! $success) {
362
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_meta_table, $cols_n_values, $datatypes));
363
-            return 0;
364
-        }
365
-        $new_id = $wpdb->insert_id;
366
-        return $new_id;
367
-    }
314
+	private function _insert_attendee_meta_row($old_attendee, $new_attendee_cpt_id)
315
+	{
316
+		global $wpdb;
317
+		// get the state and country ids from the old row
318
+		try {
319
+			$new_country = $this->get_migration_script()->get_or_create_country(stripslashes($old_attendee['country_id']));
320
+			$new_country_iso = $new_country['CNT_ISO'];
321
+		} catch (EE_Error $exception) {
322
+			$new_country_iso = $this->get_migration_script()->get_default_country_iso();
323
+		}
324
+		try {
325
+			$new_state = $this->get_migration_script()->get_or_create_state(stripslashes($old_attendee['state']), $new_country_iso);
326
+			$new_state_id = $new_state['STA_ID'];
327
+		} catch (EE_Error $exception) {
328
+			$new_state_id = 0;
329
+		}
330
+		$cols_n_values = array(
331
+			'ATT_ID'=>$new_attendee_cpt_id,
332
+			'ATT_fname'=>stripslashes($old_attendee['fname']),
333
+			'ATT_lname'=>stripslashes($old_attendee['lname']),
334
+			'ATT_address'=>stripslashes($old_attendee['address']),
335
+			'ATT_address2'=>stripslashes($old_attendee['address2']),
336
+			'ATT_city'=>stripslashes($old_attendee['city']),
337
+			'STA_ID'=>$new_state_id,
338
+			'CNT_ISO'=>$new_country_iso,
339
+			'ATT_zip'=>stripslashes($old_attendee['zip']),
340
+			'ATT_email'=>stripslashes($old_attendee['email']),
341
+			'ATT_phone'=>stripslashes($old_attendee['phone']),
342
+		);
343
+		$datatypes = array(
344
+			'%d',// ATT_ID
345
+			'%s',// ATT_fname
346
+			'%s',// ATT_lname
347
+			'%s',// ATT_address
348
+			'%s',// ATT_address2
349
+			'%s',// ATT_city
350
+			'%d',// STA_ID
351
+			'%s',// CNT_ISO
352
+			'%s',// ATT_zip
353
+			'%s',// ATT_email
354
+			'%s',// ATT_phone
355
+		);
356
+		$success = $wpdb->insert($this->_new_attendee_meta_table, $cols_n_values, $datatypes);
357
+		if (! $success) {
358
+			$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));
359
+			return 0;
360
+		}
361
+		$new_id = $wpdb->insert_id;
362
+		return $new_id;
363
+	}
368 364
 
369
-    /**
370
-     * Note: we don't necessarily create a new transaction for each attendee row.
371
-     * Only if the old attendee 'is_primary' is true; otherwise we find the old attendee row that
372
-     * 'is_primary' and has the same 'txn_id', then we return ITS new transaction id
373
-     * @global type $wpdb
374
-     * @param type $old_attendee
375
-     * @return int new transaction id
376
-     */
377
-    private function _insert_new_transaction($old_attendee)
378
-    {
379
-        global $wpdb;
365
+	/**
366
+	 * Note: we don't necessarily create a new transaction for each attendee row.
367
+	 * Only if the old attendee 'is_primary' is true; otherwise we find the old attendee row that
368
+	 * 'is_primary' and has the same 'txn_id', then we return ITS new transaction id
369
+	 * @global type $wpdb
370
+	 * @param type $old_attendee
371
+	 * @return int new transaction id
372
+	 */
373
+	private function _insert_new_transaction($old_attendee)
374
+	{
375
+		global $wpdb;
380 376
 
381
-        // first: let's check for an existing transaction for this old attendee
382
-        if (intval($old_attendee['is_primary'])) {// primary attendee, so create txn
383
-            $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($old_attendee['id']), $this->_new_transaction_table);
384
-        } else { // non-primary attendee, so find its primary attendee's transaction
385
-            $primary_attendee_old_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM ".$this->_old_table." WHERE is_primary=1 and registration_id=%s", $old_attendee['registration_id']));
386
-            if (! $primary_attendee_old_id) {
387
-                $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee['registration_id']);
388
-                $primary_attendee_old_id = is_array($primary_attendee) ? $primary_attendee['id'] : null;
389
-            }
390
-            $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($primary_attendee_old_id), $this->_new_transaction_table);
391
-            if (! $txn_id) {
392
-                $this->add_error(sprintf(__("Could not find primary attendee's new transaction. Current attendee is: %s, we think the 3.1 primary attendee for it has id %d, but there's no 4.1 transaction for that primary attendee id.", "event_espresso"), $this->_json_encode($old_attendee), $primary_attendee_old_id));
393
-                $txn_id = 0;
394
-            }
395
-        }
396
-        // if there isn't yet a transaction row for this, create one
397
-        // (so even if it was a non-primary attendee with no EE3 primary attendee,
398
-        // it ought to have SOME transaction, so we'll make one)
399
-        if (! $txn_id) {
400
-            // maps 3.1 payment stati onto 4.1 transaction stati
401
-            $txn_status_mapping = array(
402
-                'Completed'=>'TCM',
403
-                'Pending'=>'TIN',
404
-                'Payment Declined'=>'TIN',
405
-                'Incomplete'=>'TIN',
406
-                'Not Completed'=>'TIN',
407
-                'Cancelled'=>'TIN',
408
-                'Declined'=>'TIN'
409
-            );
410
-            $STS_ID = isset($txn_status_mapping[ $old_attendee['payment_status'] ]) ? $txn_status_mapping[ $old_attendee['payment_status'] ] : 'TIN';
411
-            $cols_n_values = array(
412
-                'TXN_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
413
-                'TXN_total'=>floatval($old_attendee['total_cost']),
414
-                'TXN_paid'=>floatval($old_attendee['amount_pd']),
415
-                'STS_ID'=>$STS_ID,
416
-                'TXN_hash_salt'=>$old_attendee['hashSalt']
417
-            );
418
-            $datatypes = array(
419
-                '%s',// TXN_timestamp
420
-                '%f',// TXN_total
421
-                '%f',// TXN_paid
422
-                '%s',// STS_ID
423
-                '%s',// TXN_hash_salt
424
-            );
425
-            $success = $wpdb->insert($this->_new_transaction_table, $cols_n_values, $datatypes);
426
-            if (! $success) {
427
-                $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_transaction_table, $cols_n_values, $datatypes));
428
-                return 0;
429
-            }
430
-            $txn_id = $wpdb->insert_id;
431
-        }
377
+		// first: let's check for an existing transaction for this old attendee
378
+		if (intval($old_attendee['is_primary'])) {// primary attendee, so create txn
379
+			$txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($old_attendee['id']), $this->_new_transaction_table);
380
+		} else { // non-primary attendee, so find its primary attendee's transaction
381
+			$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']));
382
+			if (! $primary_attendee_old_id) {
383
+				$primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee['registration_id']);
384
+				$primary_attendee_old_id = is_array($primary_attendee) ? $primary_attendee['id'] : null;
385
+			}
386
+			$txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($primary_attendee_old_id), $this->_new_transaction_table);
387
+			if (! $txn_id) {
388
+				$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));
389
+				$txn_id = 0;
390
+			}
391
+		}
392
+		// if there isn't yet a transaction row for this, create one
393
+		// (so even if it was a non-primary attendee with no EE3 primary attendee,
394
+		// it ought to have SOME transaction, so we'll make one)
395
+		if (! $txn_id) {
396
+			// maps 3.1 payment stati onto 4.1 transaction stati
397
+			$txn_status_mapping = array(
398
+				'Completed'=>'TCM',
399
+				'Pending'=>'TIN',
400
+				'Payment Declined'=>'TIN',
401
+				'Incomplete'=>'TIN',
402
+				'Not Completed'=>'TIN',
403
+				'Cancelled'=>'TIN',
404
+				'Declined'=>'TIN'
405
+			);
406
+			$STS_ID = isset($txn_status_mapping[ $old_attendee['payment_status'] ]) ? $txn_status_mapping[ $old_attendee['payment_status'] ] : 'TIN';
407
+			$cols_n_values = array(
408
+				'TXN_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
409
+				'TXN_total'=>floatval($old_attendee['total_cost']),
410
+				'TXN_paid'=>floatval($old_attendee['amount_pd']),
411
+				'STS_ID'=>$STS_ID,
412
+				'TXN_hash_salt'=>$old_attendee['hashSalt']
413
+			);
414
+			$datatypes = array(
415
+				'%s',// TXN_timestamp
416
+				'%f',// TXN_total
417
+				'%f',// TXN_paid
418
+				'%s',// STS_ID
419
+				'%s',// TXN_hash_salt
420
+			);
421
+			$success = $wpdb->insert($this->_new_transaction_table, $cols_n_values, $datatypes);
422
+			if (! $success) {
423
+				$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));
424
+				return 0;
425
+			}
426
+			$txn_id = $wpdb->insert_id;
427
+		}
432 428
 
433
-        return $txn_id;
434
-    }
435
-    /**
436
-     * Detects if the MER tables exist
437
-     * @global type $wpdb
438
-     * @return boolean
439
-     */
440
-    private function _mer_tables_exist()
441
-    {
442
-        if ($this->_mer_tables_exist === null) {
443
-            global $wpdb;
429
+		return $txn_id;
430
+	}
431
+	/**
432
+	 * Detects if the MER tables exist
433
+	 * @global type $wpdb
434
+	 * @return boolean
435
+	 */
436
+	private function _mer_tables_exist()
437
+	{
438
+		if ($this->_mer_tables_exist === null) {
439
+			global $wpdb;
444 440
 
445
-            if ($wpdb->get_var("SHOW TABLES LIKE '{$this->_old_mer_table}'") != $this->_old_mer_table) {
446
-                $this->_mer_tables_exist = false;
447
-            } else {
448
-                $this->_mer_tables_exist = true;
449
-            }
450
-        }
451
-        return $this->_mer_tables_exist;
452
-    }
441
+			if ($wpdb->get_var("SHOW TABLES LIKE '{$this->_old_mer_table}'") != $this->_old_mer_table) {
442
+				$this->_mer_tables_exist = false;
443
+			} else {
444
+				$this->_mer_tables_exist = true;
445
+			}
446
+		}
447
+		return $this->_mer_tables_exist;
448
+	}
453 449
 
454
-    /**
455
-     * Gets the 4.1 registration's status given the 3.1 attendee row. We consider
456
-     * whether the event required pre-approval or not,a dn the 4.1 payment status.
457
-     * @global type $wpdb
458
-     * @param type $old_attendee_row
459
-     * @return string
460
-     */
461
-    private function _get_reg_status_for_old_payment_status($old_attendee_row)
462
-    {
463
-        // need event default reg status and if pre_approval was required
464
-        global $wpdb;
465
-        $event_required_pre_approval = $wpdb->get_var($wpdb->prepare("SELECT require_pre_approval FROM ".$wpdb->prefix."events_detail WHERE id = %d", $old_attendee_row['event_id']));
466
-        return $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(
467
-            $old_attendee_row['payment_status'],
468
-            intval($event_required_pre_approval) && intval($old_attendee_row['pre_approve'])
469
-        );
470
-    }
471
-    /**
472
-     * Adds however many rgistrations are indicated by the old attendee's QUANTITY field,
473
-     * and returns an array of their IDs
474
-     * @global type $wpdb
475
-     * @param array $old_attendee
476
-     * @param int $new_attendee_id
477
-     * @param int $new_txn_id
478
-     * @return array of new registratio ids
479
-     */
480
-    private function _insert_new_registrations($old_attendee, $new_attendee_id, $new_txn_id)
481
-    {
482
-        global $wpdb;
450
+	/**
451
+	 * Gets the 4.1 registration's status given the 3.1 attendee row. We consider
452
+	 * whether the event required pre-approval or not,a dn the 4.1 payment status.
453
+	 * @global type $wpdb
454
+	 * @param type $old_attendee_row
455
+	 * @return string
456
+	 */
457
+	private function _get_reg_status_for_old_payment_status($old_attendee_row)
458
+	{
459
+		// need event default reg status and if pre_approval was required
460
+		global $wpdb;
461
+		$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']));
462
+		return $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(
463
+			$old_attendee_row['payment_status'],
464
+			intval($event_required_pre_approval) && intval($old_attendee_row['pre_approve'])
465
+		);
466
+	}
467
+	/**
468
+	 * Adds however many rgistrations are indicated by the old attendee's QUANTITY field,
469
+	 * and returns an array of their IDs
470
+	 * @global type $wpdb
471
+	 * @param array $old_attendee
472
+	 * @param int $new_attendee_id
473
+	 * @param int $new_txn_id
474
+	 * @return array of new registratio ids
475
+	 */
476
+	private function _insert_new_registrations($old_attendee, $new_attendee_id, $new_txn_id)
477
+	{
478
+		global $wpdb;
483 479
 
484
-        $STS_ID = $this->_get_reg_status_for_old_payment_status($old_attendee);
485
-        $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix.'events_detail', $old_attendee['event_id'], $wpdb->posts);
486
-        if (! $new_event_id) {
487
-            $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)));
488
-        }
480
+		$STS_ID = $this->_get_reg_status_for_old_payment_status($old_attendee);
481
+		$new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix.'events_detail', $old_attendee['event_id'], $wpdb->posts);
482
+		if (! $new_event_id) {
483
+			$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)));
484
+		}
489 485
 
490
-        $ticket_id = $this->_try_to_find_new_ticket_id($old_attendee, $new_event_id);
491
-        if (! $ticket_id) {
492
-            $ticket_id = $this->_insert_new_ticket_because_none_found($old_attendee, $new_event_id);
493
-            $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));
494
-        }
495
-        $regs_on_this_row = intval($old_attendee['quantity']);
496
-        $new_regs = array();
497
-        // 4 cases we need to account for:
498
-        // 1 old attendee_details row with a quantity of X (no mer)
499
-        // Y old attendee_details rows with a quantity of 1 (no mer) joined by their common registration_id
500
-        // Y old attendee_details rows with a quantity of x (because of mer)
501
-        // Y old attendee_details rows with a quantity of 1 (because of mer) joined by wp_events_multi_event_registration_id_group
502
-        for ($count = 1; $count <= $regs_on_this_row; $count++) {
503
-            // sum regs on older rows
504
-            $regs_on_this_event_and_txn = $this->_sum_old_attendees_on_old_txn($old_attendee, true);
505
-            $cols_n_values = array(
506
-                'EVT_ID'=>$new_event_id,
507
-                'ATT_ID'=>$new_attendee_id,
508
-                'TXN_ID'=>$new_txn_id,
509
-                'TKT_ID'=>$ticket_id,
510
-                'STS_ID'=>$STS_ID,
511
-                'REG_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
512
-                'REG_final_price'=>$old_attendee['final_price'],
513
-                'REG_session'=> substr($old_attendee['attendee_session'], 0, 44),
514
-                'REG_code'=>sanitize_key($old_attendee['registration_id']),
515
-                'REG_url_link'=>  sanitize_key($old_attendee['registration_id'].'-'.$count),
516
-                'REG_count'=>$regs_on_this_event_and_txn + $count,
517
-                'REG_group_size'=>$this->_sum_old_attendees_on_old_txn($old_attendee, false),
518
-                'REG_att_is_going'=>true,
519
-                'REG_deleted'=>false
520
-            );
521
-            $datatypes = array(
522
-                '%d',// EVT_ID
523
-                '%d',// ATT_ID
524
-                '%d',// TXN_ID
525
-                '%d',// TKT_ID
526
-                '%s',// STS_ID
527
-                '%s',// REG_date
528
-                '%f',// REG_final_price
529
-                '%s',// REG_session
530
-                '%s',// REG_code
531
-                '%s',// REG_url_link
532
-                '%d',// REG_count
533
-                '%d',// REG_group_size
534
-                '%d',// REG_att_is_going
535
-                '%d',// REG_deleted
536
-            );
537
-            $success = $wpdb->insert($this->_new_reg_table, $cols_n_values, $datatypes);
538
-            if (! $success) {
539
-                $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));
540
-                return 0;
541
-            }
542
-            $cols_n_values['REG_ID'] = $wpdb->insert_id;
543
-            $new_regs[] = $wpdb->insert_id;
544
-        }
545
-        $this->_add_regs_to_ticket_and_datetimes($ticket_id, count($new_regs), $STS_ID);
546
-        return $new_regs;
547
-    }
486
+		$ticket_id = $this->_try_to_find_new_ticket_id($old_attendee, $new_event_id);
487
+		if (! $ticket_id) {
488
+			$ticket_id = $this->_insert_new_ticket_because_none_found($old_attendee, $new_event_id);
489
+			$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));
490
+		}
491
+		$regs_on_this_row = intval($old_attendee['quantity']);
492
+		$new_regs = array();
493
+		// 4 cases we need to account for:
494
+		// 1 old attendee_details row with a quantity of X (no mer)
495
+		// Y old attendee_details rows with a quantity of 1 (no mer) joined by their common registration_id
496
+		// Y old attendee_details rows with a quantity of x (because of mer)
497
+		// Y old attendee_details rows with a quantity of 1 (because of mer) joined by wp_events_multi_event_registration_id_group
498
+		for ($count = 1; $count <= $regs_on_this_row; $count++) {
499
+			// sum regs on older rows
500
+			$regs_on_this_event_and_txn = $this->_sum_old_attendees_on_old_txn($old_attendee, true);
501
+			$cols_n_values = array(
502
+				'EVT_ID'=>$new_event_id,
503
+				'ATT_ID'=>$new_attendee_id,
504
+				'TXN_ID'=>$new_txn_id,
505
+				'TKT_ID'=>$ticket_id,
506
+				'STS_ID'=>$STS_ID,
507
+				'REG_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
508
+				'REG_final_price'=>$old_attendee['final_price'],
509
+				'REG_session'=> substr($old_attendee['attendee_session'], 0, 44),
510
+				'REG_code'=>sanitize_key($old_attendee['registration_id']),
511
+				'REG_url_link'=>  sanitize_key($old_attendee['registration_id'].'-'.$count),
512
+				'REG_count'=>$regs_on_this_event_and_txn + $count,
513
+				'REG_group_size'=>$this->_sum_old_attendees_on_old_txn($old_attendee, false),
514
+				'REG_att_is_going'=>true,
515
+				'REG_deleted'=>false
516
+			);
517
+			$datatypes = array(
518
+				'%d',// EVT_ID
519
+				'%d',// ATT_ID
520
+				'%d',// TXN_ID
521
+				'%d',// TKT_ID
522
+				'%s',// STS_ID
523
+				'%s',// REG_date
524
+				'%f',// REG_final_price
525
+				'%s',// REG_session
526
+				'%s',// REG_code
527
+				'%s',// REG_url_link
528
+				'%d',// REG_count
529
+				'%d',// REG_group_size
530
+				'%d',// REG_att_is_going
531
+				'%d',// REG_deleted
532
+			);
533
+			$success = $wpdb->insert($this->_new_reg_table, $cols_n_values, $datatypes);
534
+			if (! $success) {
535
+				$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));
536
+				return 0;
537
+			}
538
+			$cols_n_values['REG_ID'] = $wpdb->insert_id;
539
+			$new_regs[] = $wpdb->insert_id;
540
+		}
541
+		$this->_add_regs_to_ticket_and_datetimes($ticket_id, count($new_regs), $STS_ID);
542
+		return $new_regs;
543
+	}
548 544
 
549
-    /**
550
-     * Increments the sold values on the ticket and its related datetimes by the amount sold,
551
-     * which should be done directly after adding the rows. Yes this means we're constantly incrementing
552
-     * the sold amounts as we go, and is less efficient than a single big query,
553
-     * but its safer because we KNOW these regs have been added, rather than inferring
554
-     * that they WILL be added (because the attendees stage runs nearly last during
555
-     * the migration script)
556
-     * @param type $new_ticket_id
557
-     * @param type $sold
558
-     * @param type $STS_ID
559
-     * @return boolean whether they were successfully updated or not
560
-     */
561
-    protected function _add_regs_to_ticket_and_datetimes($new_ticket_id, $quantity_sold, $STS_ID)
562
-    {
563
-        if ($STS_ID != 'RAP') {
564
-            return true;
565
-        }
566
-        global $wpdb;
567
-        $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));
568
-        if ($success) {
569
-            // get the ticket's datetimes, and increment them too
570
-            $success_update_dateimtes =  $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT
545
+	/**
546
+	 * Increments the sold values on the ticket and its related datetimes by the amount sold,
547
+	 * which should be done directly after adding the rows. Yes this means we're constantly incrementing
548
+	 * the sold amounts as we go, and is less efficient than a single big query,
549
+	 * but its safer because we KNOW these regs have been added, rather than inferring
550
+	 * that they WILL be added (because the attendees stage runs nearly last during
551
+	 * the migration script)
552
+	 * @param type $new_ticket_id
553
+	 * @param type $sold
554
+	 * @param type $STS_ID
555
+	 * @return boolean whether they were successfully updated or not
556
+	 */
557
+	protected function _add_regs_to_ticket_and_datetimes($new_ticket_id, $quantity_sold, $STS_ID)
558
+	{
559
+		if ($STS_ID != 'RAP') {
560
+			return true;
561
+		}
562
+		global $wpdb;
563
+		$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));
564
+		if ($success) {
565
+			// get the ticket's datetimes, and increment them too
566
+			$success_update_dateimtes =  $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT
571 567
 				INNER JOIN {$this->_new_ticket_datetime_table} as DTK ON TKT.TKT_ID = DTK.TKT_ID
572 568
 				INNER JOIN {$this->_new_datetime_table} as DTT ON DTK.DTT_ID = DTT.DTT_ID
573 569
 				SET DTT.DTT_sold = DTT.DTT_sold + %d WHERE TKT.TKT_ID = %d", $quantity_sold, $new_ticket_id));
574
-            if (! $success_update_dateimtes) {
575
-                $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));
576
-            }
577
-        } else {
578
-            $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));
579
-        }
580
-        return true;
581
-    }
582
-    /**
583
-     * Makes a best guess at which ticket is the one the attendee purchased.
584
-     * Obviously, the old attendee's event_id narrows it down quite a bit;
585
-     * then the old attendee's orig_price and event_time, and price_option can uniquely identify the ticket
586
-     * however, if we don't find an exact match, see if any of those conditions match;
587
-     * and lastly if none of that works, just use the first ticket for the event we find
588
-     * @param array $old_attendee
589
-     */
590
-    private function _try_to_find_new_ticket_id($old_attendee, $new_event_id)
591
-    {
592
-        global $wpdb;
593
-        $tickets_table = $this->_new_ticket_table;
594
-        $datetime_tickets_table = $this->_new_ticket_datetime_table;
595
-        $datetime_table = $this->_new_datetime_table;
570
+			if (! $success_update_dateimtes) {
571
+				$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));
572
+			}
573
+		} else {
574
+			$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));
575
+		}
576
+		return true;
577
+	}
578
+	/**
579
+	 * Makes a best guess at which ticket is the one the attendee purchased.
580
+	 * Obviously, the old attendee's event_id narrows it down quite a bit;
581
+	 * then the old attendee's orig_price and event_time, and price_option can uniquely identify the ticket
582
+	 * however, if we don't find an exact match, see if any of those conditions match;
583
+	 * and lastly if none of that works, just use the first ticket for the event we find
584
+	 * @param array $old_attendee
585
+	 */
586
+	private function _try_to_find_new_ticket_id($old_attendee, $new_event_id)
587
+	{
588
+		global $wpdb;
589
+		$tickets_table = $this->_new_ticket_table;
590
+		$datetime_tickets_table = $this->_new_ticket_datetime_table;
591
+		$datetime_table = $this->_new_datetime_table;
596 592
 
597
-        $old_att_price_option = $old_attendee['price_option'];
598
-        $old_att_price = floatval($old_attendee['orig_price']);
593
+		$old_att_price_option = $old_attendee['price_option'];
594
+		$old_att_price = floatval($old_attendee['orig_price']);
599 595
 
600
-        $old_att_start_date = $old_attendee['start_date'];
601
-        $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
602
-        $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00");
603
-        // add all conditions to an array from which we can SHIFT conditions off in order to widen our search
604
-        // the most important condition should be last, as it will be array_shift'ed off last
605
-        $conditions = array(
606
-            $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match?
607
-            $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price),// prices match?
608
-            $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option),// names match?
609
-            $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match?
610
-        );
611
-        $select_and_join_part = "SELECT $tickets_table.TKT_ID FROM $tickets_table INNER JOIN
596
+		$old_att_start_date = $old_attendee['start_date'];
597
+		$old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
598
+		$old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00");
599
+		// add all conditions to an array from which we can SHIFT conditions off in order to widen our search
600
+		// the most important condition should be last, as it will be array_shift'ed off last
601
+		$conditions = array(
602
+			$wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match?
603
+			$wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price),// prices match?
604
+			$wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option),// names match?
605
+			$wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match?
606
+		);
607
+		$select_and_join_part = "SELECT $tickets_table.TKT_ID FROM $tickets_table INNER JOIN
612 608
 			$datetime_tickets_table ON $tickets_table.TKT_ID = $datetime_tickets_table.TKT_ID INNER JOIN
613 609
 			$datetime_table ON $datetime_tickets_table.DTT_ID = $datetime_table.DTT_ID";
614
-        // start running queries, widening search each time by removing a condition
615
-        do {
616
-            $full_query = $select_and_join_part." WHERE ".implode(" AND ", $conditions)." LIMIT 1";
617
-            $ticket_id_found = $wpdb->get_var($full_query);
618
-            array_shift($conditions);
619
-        } while (! $ticket_id_found && $conditions);
620
-        return $ticket_id_found;
621
-    }
610
+		// start running queries, widening search each time by removing a condition
611
+		do {
612
+			$full_query = $select_and_join_part." WHERE ".implode(" AND ", $conditions)." LIMIT 1";
613
+			$ticket_id_found = $wpdb->get_var($full_query);
614
+			array_shift($conditions);
615
+		} while (! $ticket_id_found && $conditions);
616
+		return $ticket_id_found;
617
+	}
622 618
 
623
-    /**
624
-     * If we couldn't find a 4.1 ticket for a 3.1 attendee row, this function creates one;
625
-     * and it also tries to find a datetime that works, and a inserts a price, and associates
626
-     * the new ticket to that datetime and price.
627
-     * @return int ticket id
628
-     */
629
-    private function _insert_new_ticket_because_none_found($old_attendee, $new_event_id)
630
-    {
631
-        global $wpdb;
632
-        $old_att_price_option = $old_attendee['price_option'];
633
-        $old_att_price = floatval($old_attendee['orig_price']);
619
+	/**
620
+	 * If we couldn't find a 4.1 ticket for a 3.1 attendee row, this function creates one;
621
+	 * and it also tries to find a datetime that works, and a inserts a price, and associates
622
+	 * the new ticket to that datetime and price.
623
+	 * @return int ticket id
624
+	 */
625
+	private function _insert_new_ticket_because_none_found($old_attendee, $new_event_id)
626
+	{
627
+		global $wpdb;
628
+		$old_att_price_option = $old_attendee['price_option'];
629
+		$old_att_price = floatval($old_attendee['orig_price']);
634 630
 
635
-        $old_att_start_date = $old_attendee['start_date'];
636
-        $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
637
-        $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");
631
+		$old_att_start_date = $old_attendee['start_date'];
632
+		$old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
633
+		$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");
638 634
 
639 635
 
640
-        // insert new datetime unless we find one
641
-        $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);
642
-        if (! $datetime_id) {
643
-            $old_att_end_date = $old_attendee['start_date'];
644
-            $old_att_end_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
645
-            $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");
646
-            $wpdb->insert(
647
-                $this->_new_datetime_table,
648
-                array(
649
-                        'EVT_ID' => $new_event_id,
650
-                        'DTT_EVT_start' => $old_att_start_datetime,
651
-                        'DTT_EVT_end' => $old_att_end_datetime,
652
-                        'DTT_deleted' => true
653
-                    ),
654
-                array(
655
-                        '%d',// EVT_ID
656
-                        '%s',// DTT_EVT_start
657
-                        '%s',// DTT_EVT_end
658
-                        '%d',// DTT_deleted
659
-                    )
660
-            );
661
-            $datetime_id = $wpdb->insert_id;
662
-        }
636
+		// insert new datetime unless we find one
637
+		$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);
638
+		if (! $datetime_id) {
639
+			$old_att_end_date = $old_attendee['start_date'];
640
+			$old_att_end_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
641
+			$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");
642
+			$wpdb->insert(
643
+				$this->_new_datetime_table,
644
+				array(
645
+						'EVT_ID' => $new_event_id,
646
+						'DTT_EVT_start' => $old_att_start_datetime,
647
+						'DTT_EVT_end' => $old_att_end_datetime,
648
+						'DTT_deleted' => true
649
+					),
650
+				array(
651
+						'%d',// EVT_ID
652
+						'%s',// DTT_EVT_start
653
+						'%s',// DTT_EVT_end
654
+						'%d',// DTT_deleted
655
+					)
656
+			);
657
+			$datetime_id = $wpdb->insert_id;
658
+		}
663 659
 
664
-        // insert new ticket
665
-        $success = $wpdb->insert(
666
-            $wpdb->prefix . 'esp_ticket',
667
-            array(
668
-                    'TKT_name' => $old_att_price_option,
669
-                    'TKT_qty' => -1,
670
-                    'TKT_price' => $old_att_price,
671
-                    '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
672
-                    'TKT_end_date' => $old_att_end_datetime,
660
+		// insert new ticket
661
+		$success = $wpdb->insert(
662
+			$wpdb->prefix . 'esp_ticket',
663
+			array(
664
+					'TKT_name' => $old_att_price_option,
665
+					'TKT_qty' => -1,
666
+					'TKT_price' => $old_att_price,
667
+					'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_end_date' => $old_att_end_datetime,
673 669
 
674
-                ),
675
-            array(
676
-                    '%s',// name
677
-                    '%d',// qty
678
-                    '%d',// price
679
-                    '%s',// start_date
680
-                    '%s',// end_date
681
-                )
682
-        );
683
-        $ticket_id = $wpdb->insert_id;
684
-        // associate the ticket with the datetime we found earlier
685
-        $wpdb->insert(
686
-            $this->_new_datetime_ticket_table,
687
-            array(
688
-                    'DTT_ID' => $datetime_id,
689
-                    'TKT_ID' => $ticket_id
690
-                ),
691
-            array(
692
-                    '%d',// DTT_ID
693
-                    '%d',// TKT_ID
694
-                )
695
-        );
696
-        // insert new price
697
-        $wpdb->insert(
698
-            $this->_new_price_table,
699
-            array(
700
-                    'PRC_amount' => $old_att_price,
701
-                    'PRT_ID' => EE_DMS_4_1_0_prices::price_type_base,
702
-                    'PRC_name' => $old_att_price_option,
703
-                    'PRC_deleted' => true
704
-                ),
705
-            array(
706
-                    '%d',// PRC_amount
707
-                    '%d',// PRT_ID
708
-                    '%s',// PRC_name
709
-                    '%d',// PRC_deleted
710
-                )
711
-        );
712
-        $price_id = $wpdb->insert_id;
713
-        // associate the price to the ticket
714
-        $wpdb->insert(
715
-            $this->_new_ticket_price_table,
716
-            array(
717
-                    'TKT_ID' => $ticket_id,
718
-                    'PRC_ID' => $price_id
719
-                ),
720
-            array(
721
-                    '%d',// TKT_ID
722
-                    '%d',// PRC_ID
723
-                )
724
-        );
725
-        return $ticket_id;
726
-    }
727
-    /**
728
-     * Counts all the registrations on this transaction. If $count_only_older is TRUE then returns the number added SO FAR (ie,
729
-     * only considers attendee rows with an ID less than this one's), but if $count_only_older is FALSe returns ALL
730
-     * @global type $wpdb
731
-     * @param array $old_attendee_row
732
-     * @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
733
-     * @return int
734
-     */
735
-    private function _sum_old_attendees_on_old_txn($old_attendee_row, $count_only_older = false)
736
-    {
737
-        global $wpdb;
738
-        $count_only_older_sql = $count_only_older ? $wpdb->prepare(" AND id<%d", $old_attendee_row['id']) : '';
739
-        $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'])));
670
+				),
671
+			array(
672
+					'%s',// name
673
+					'%d',// qty
674
+					'%d',// price
675
+					'%s',// start_date
676
+					'%s',// end_date
677
+				)
678
+		);
679
+		$ticket_id = $wpdb->insert_id;
680
+		// associate the ticket with the datetime we found earlier
681
+		$wpdb->insert(
682
+			$this->_new_datetime_ticket_table,
683
+			array(
684
+					'DTT_ID' => $datetime_id,
685
+					'TKT_ID' => $ticket_id
686
+				),
687
+			array(
688
+					'%d',// DTT_ID
689
+					'%d',// TKT_ID
690
+				)
691
+		);
692
+		// insert new price
693
+		$wpdb->insert(
694
+			$this->_new_price_table,
695
+			array(
696
+					'PRC_amount' => $old_att_price,
697
+					'PRT_ID' => EE_DMS_4_1_0_prices::price_type_base,
698
+					'PRC_name' => $old_att_price_option,
699
+					'PRC_deleted' => true
700
+				),
701
+			array(
702
+					'%d',// PRC_amount
703
+					'%d',// PRT_ID
704
+					'%s',// PRC_name
705
+					'%d',// PRC_deleted
706
+				)
707
+		);
708
+		$price_id = $wpdb->insert_id;
709
+		// associate the price to the ticket
710
+		$wpdb->insert(
711
+			$this->_new_ticket_price_table,
712
+			array(
713
+					'TKT_ID' => $ticket_id,
714
+					'PRC_ID' => $price_id
715
+				),
716
+			array(
717
+					'%d',// TKT_ID
718
+					'%d',// PRC_ID
719
+				)
720
+		);
721
+		return $ticket_id;
722
+	}
723
+	/**
724
+	 * Counts all the registrations on this transaction. If $count_only_older is TRUE then returns the number added SO FAR (ie,
725
+	 * only considers attendee rows with an ID less than this one's), but if $count_only_older is FALSe returns ALL
726
+	 * @global type $wpdb
727
+	 * @param array $old_attendee_row
728
+	 * @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
729
+	 * @return int
730
+	 */
731
+	private function _sum_old_attendees_on_old_txn($old_attendee_row, $count_only_older = false)
732
+	{
733
+		global $wpdb;
734
+		$count_only_older_sql = $count_only_older ? $wpdb->prepare(" AND id<%d", $old_attendee_row['id']) : '';
735
+		$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'])));
740 736
 
741
-        if ($this->_mer_tables_exist()) {
742
-            // if MER exists, then its a little tricky.
743
-            // when users registered by adding items to the cart, and it was a
744
-            // group registration requiring additional attendee INFO, then the attendee rows
745
-            // DO NOT have the same registration_id (although they probably should have)
746
-            // they are related just like MER attendee rows are related, through the MER group table
747
-            // BUT we want to count all the MER attendee rows for the same registration
748
-            $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee_row['registration_id']);
737
+		if ($this->_mer_tables_exist()) {
738
+			// if MER exists, then its a little tricky.
739
+			// when users registered by adding items to the cart, and it was a
740
+			// group registration requiring additional attendee INFO, then the attendee rows
741
+			// DO NOT have the same registration_id (although they probably should have)
742
+			// they are related just like MER attendee rows are related, through the MER group table
743
+			// BUT we want to count all the MER attendee rows for the same registration
744
+			$primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee_row['registration_id']);
749 745
 
750
-            $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']));
751
-            $count = max($count_using_mer_table, $count);
752
-        }
753
-        return $count;
754
-    }
755
-    private function _insert_new_payment($old_attendee, $new_txn_id)
756
-    {
757
-        global $wpdb;
758
-        // only add a payment for primary attendees
759
-        $old_pay_stati_indicating_no_payment = array('Pending','Incomplete','Not Completed');
760
-        // if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment...
761
-        if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && ! in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) {
762
-            $pay_status_mapping = array(
763
-                'Completed'=>'PAP',
764
-                'Payment Declined'=>'PDC',
765
-                'Cancelled'=>'PCN',
766
-                'Declined'=>'PDC'
767
-            );
768
-            $by_admin = $old_attendee['payment'] == 'Admin';
769
-            $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
770
-            $cols_n_values = array(
771
-                'TXN_ID'=>$new_txn_id,
772
-                'STS_ID'=>$STS_ID,
773
-                'PAY_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
774
-                'PAY_method'=>'CART',
775
-                'PAY_amount'=>$old_attendee['amount_pd'],
776
-                'PAY_gateway'=>$old_attendee['txn_type'],
777
-                'PAY_gateway_response'=>'',
778
-                'PAY_txn_id_chq_nmbr'=>substr($old_attendee['txn_id'], 0, 32),
779
-                'PAY_via_admin'=>$by_admin,
780
-                'PAY_details'=>$old_attendee['transaction_details']
746
+			$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']));
747
+			$count = max($count_using_mer_table, $count);
748
+		}
749
+		return $count;
750
+	}
751
+	private function _insert_new_payment($old_attendee, $new_txn_id)
752
+	{
753
+		global $wpdb;
754
+		// only add a payment for primary attendees
755
+		$old_pay_stati_indicating_no_payment = array('Pending','Incomplete','Not Completed');
756
+		// if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment...
757
+		if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && ! in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) {
758
+			$pay_status_mapping = array(
759
+				'Completed'=>'PAP',
760
+				'Payment Declined'=>'PDC',
761
+				'Cancelled'=>'PCN',
762
+				'Declined'=>'PDC'
763
+			);
764
+			$by_admin = $old_attendee['payment'] == 'Admin';
765
+			$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
+			$cols_n_values = array(
767
+				'TXN_ID'=>$new_txn_id,
768
+				'STS_ID'=>$STS_ID,
769
+				'PAY_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
770
+				'PAY_method'=>'CART',
771
+				'PAY_amount'=>$old_attendee['amount_pd'],
772
+				'PAY_gateway'=>$old_attendee['txn_type'],
773
+				'PAY_gateway_response'=>'',
774
+				'PAY_txn_id_chq_nmbr'=>substr($old_attendee['txn_id'], 0, 32),
775
+				'PAY_via_admin'=>$by_admin,
776
+				'PAY_details'=>$old_attendee['transaction_details']
781 777
 
782
-            );
783
-            $datatypes = array(
784
-                '%d',// TXN_Id
785
-                '%s',// STS_ID
786
-                '%s',// PAY_timestamp
787
-                '%s',// PAY_method
788
-                '%f',// PAY_amount
789
-                '%s',// PAY_gateway
790
-                '%s',// PAY_gateway_response
791
-                '%s',// PAY_txn_id_chq_nmbr
792
-                '%d',// PAY_via_admin
793
-                '%s',// PAY_details
794
-            );
795
-            $success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes);
796
-            if (! $success) {
797
-                $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));
798
-                return 0;
799
-            }
800
-            $new_id = $wpdb->insert_id;
801
-            return $new_id;
802
-        } else {
803
-            return 0;
804
-        }
805
-    }
778
+			);
779
+			$datatypes = array(
780
+				'%d',// TXN_Id
781
+				'%s',// STS_ID
782
+				'%s',// PAY_timestamp
783
+				'%s',// PAY_method
784
+				'%f',// PAY_amount
785
+				'%s',// PAY_gateway
786
+				'%s',// PAY_gateway_response
787
+				'%s',// PAY_txn_id_chq_nmbr
788
+				'%d',// PAY_via_admin
789
+				'%s',// PAY_details
790
+			);
791
+			$success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes);
792
+			if (! $success) {
793
+				$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));
794
+				return 0;
795
+			}
796
+			$new_id = $wpdb->insert_id;
797
+			return $new_id;
798
+		} else {
799
+			return 0;
800
+		}
801
+	}
806 802
 
807
-    /**
808
-     * If MER is active, if you want ot fin dthe other registrations on that attendee row
809
-     * @global type $wpdb
810
-     * @param type $old_registration_id
811
-     * @return array
812
-     */
813
-    private function _find_mer_primary_attendee_using_mer_tables($old_registration_id)
814
-    {
815
-        if (! $this->_mer_tables_exist()) {
816
-            return false;
817
-        }
818
-        global $wpdb;
819
-        $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);
820
-        return $old_att_for_primary_reg;
821
-    }
803
+	/**
804
+	 * If MER is active, if you want ot fin dthe other registrations on that attendee row
805
+	 * @global type $wpdb
806
+	 * @param type $old_registration_id
807
+	 * @return array
808
+	 */
809
+	private function _find_mer_primary_attendee_using_mer_tables($old_registration_id)
810
+	{
811
+		if (! $this->_mer_tables_exist()) {
812
+			return false;
813
+		}
814
+		global $wpdb;
815
+		$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);
816
+		return $old_att_for_primary_reg;
817
+	}
822 818
 }
Please login to merge, or discard this patch.
Spacing   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
         $this->select_expression = 'att.*, e.event_status';
214 214
         // Only select attendees for events that aren't deleted.
215 215
         $this->_extra_where_sql = 'AS att
216
-            INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id
216
+            INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id=e.id
217 217
             WHERE e.event_status!="D"';
218 218
         $this->_old_mer_table = $wpdb->prefix."events_multi_event_registration_id_group";
219 219
         $this->_new_attendee_cpt_table = $wpdb->posts;
@@ -235,9 +235,9 @@  discard block
 block discarded – undo
235 235
     {
236 236
         // first check if there's already a new attendee with similar characteristics
237 237
         $new_att_id = $this->_find_attendee_cpt_matching($old_row);
238
-        if (! $new_att_id) {
238
+        if ( ! $new_att_id) {
239 239
             $new_att_id = $this->_insert_new_attendee_cpt($old_row);
240
-            if (! $new_att_id) {
240
+            if ( ! $new_att_id) {
241 241
                 // if we couldnt even make an attendee, abandon all hope
242 242
                 return false;
243 243
             }
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
         $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_cpt_table, $new_att_id);
250 250
 
251 251
         $txn_id = $this->_insert_new_transaction($old_row);
252
-        if (! $txn_id) {
252
+        if ( ! $txn_id) {
253 253
             // if we couldnt make the transaction, also abandon all hope
254 254
             return false;
255 255
         }
@@ -283,31 +283,31 @@  discard block
 block discarded – undo
283 283
     {
284 284
         global $wpdb;
285 285
         $cols_n_values = array(
286
-            'post_title'=>stripslashes($old_attendee['fname']." ".$old_attendee['lname']),// ATT_full_name
287
-            'post_content'=>'',// ATT_bio
288
-            'post_name'=>sanitize_title($old_attendee['fname']."-".$old_attendee['lname']),// ATT_slug
289
-            'post_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_created
290
-            'post_excerpt'=>'',// ATT_short_bio
291
-            'post_modified'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_modified
292
-            'post_author'=>0,// ATT_author
293
-            'post_parent'=>0,// ATT_parent
294
-            'post_type'=>'espresso_attendees',// post_type
286
+            'post_title'=>stripslashes($old_attendee['fname']." ".$old_attendee['lname']), // ATT_full_name
287
+            'post_content'=>'', // ATT_bio
288
+            'post_name'=>sanitize_title($old_attendee['fname']."-".$old_attendee['lname']), // ATT_slug
289
+            'post_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), // ATT_created
290
+            'post_excerpt'=>'', // ATT_short_bio
291
+            'post_modified'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), // ATT_modified
292
+            'post_author'=>0, // ATT_author
293
+            'post_parent'=>0, // ATT_parent
294
+            'post_type'=>'espresso_attendees', // post_type
295 295
             'post_status'=>'publish'// status
296 296
         );
297 297
         $datatypes = array(
298
-            '%s',// ATT_full_name
299
-            '%s',// ATT_bio
300
-            '%s',// ATT_slug
301
-            '%s',// ATT_created
302
-            '%s',// ATT_short_bio
303
-            '%s',// ATT_modified
304
-            '%d',// ATT_author
305
-            '%d',// ATT_parent
306
-            '%s',// post_type
307
-            '%s',// status
298
+            '%s', // ATT_full_name
299
+            '%s', // ATT_bio
300
+            '%s', // ATT_slug
301
+            '%s', // ATT_created
302
+            '%s', // ATT_short_bio
303
+            '%s', // ATT_modified
304
+            '%d', // ATT_author
305
+            '%d', // ATT_parent
306
+            '%s', // post_type
307
+            '%s', // status
308 308
         );
309 309
         $success = $wpdb->insert($this->_new_attendee_cpt_table, $cols_n_values, $datatypes);
310
-        if (! $success) {
310
+        if ( ! $success) {
311 311
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes));
312 312
             return 0;
313 313
         }
@@ -345,20 +345,20 @@  discard block
 block discarded – undo
345 345
             'ATT_phone'=>stripslashes($old_attendee['phone']),
346 346
         );
347 347
         $datatypes = array(
348
-            '%d',// ATT_ID
349
-            '%s',// ATT_fname
350
-            '%s',// ATT_lname
351
-            '%s',// ATT_address
352
-            '%s',// ATT_address2
353
-            '%s',// ATT_city
354
-            '%d',// STA_ID
355
-            '%s',// CNT_ISO
356
-            '%s',// ATT_zip
357
-            '%s',// ATT_email
358
-            '%s',// ATT_phone
348
+            '%d', // ATT_ID
349
+            '%s', // ATT_fname
350
+            '%s', // ATT_lname
351
+            '%s', // ATT_address
352
+            '%s', // ATT_address2
353
+            '%s', // ATT_city
354
+            '%d', // STA_ID
355
+            '%s', // CNT_ISO
356
+            '%s', // ATT_zip
357
+            '%s', // ATT_email
358
+            '%s', // ATT_phone
359 359
         );
360 360
         $success = $wpdb->insert($this->_new_attendee_meta_table, $cols_n_values, $datatypes);
361
-        if (! $success) {
361
+        if ( ! $success) {
362 362
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_meta_table, $cols_n_values, $datatypes));
363 363
             return 0;
364 364
         }
@@ -383,12 +383,12 @@  discard block
 block discarded – undo
383 383
             $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($old_attendee['id']), $this->_new_transaction_table);
384 384
         } else { // non-primary attendee, so find its primary attendee's transaction
385 385
             $primary_attendee_old_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM ".$this->_old_table." WHERE is_primary=1 and registration_id=%s", $old_attendee['registration_id']));
386
-            if (! $primary_attendee_old_id) {
386
+            if ( ! $primary_attendee_old_id) {
387 387
                 $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee['registration_id']);
388 388
                 $primary_attendee_old_id = is_array($primary_attendee) ? $primary_attendee['id'] : null;
389 389
             }
390 390
             $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($primary_attendee_old_id), $this->_new_transaction_table);
391
-            if (! $txn_id) {
391
+            if ( ! $txn_id) {
392 392
                 $this->add_error(sprintf(__("Could not find primary attendee's new transaction. Current attendee is: %s, we think the 3.1 primary attendee for it has id %d, but there's no 4.1 transaction for that primary attendee id.", "event_espresso"), $this->_json_encode($old_attendee), $primary_attendee_old_id));
393 393
                 $txn_id = 0;
394 394
             }
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
         // if there isn't yet a transaction row for this, create one
397 397
         // (so even if it was a non-primary attendee with no EE3 primary attendee,
398 398
         // it ought to have SOME transaction, so we'll make one)
399
-        if (! $txn_id) {
399
+        if ( ! $txn_id) {
400 400
             // maps 3.1 payment stati onto 4.1 transaction stati
401 401
             $txn_status_mapping = array(
402 402
                 'Completed'=>'TCM',
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
                 'Cancelled'=>'TIN',
408 408
                 'Declined'=>'TIN'
409 409
             );
410
-            $STS_ID = isset($txn_status_mapping[ $old_attendee['payment_status'] ]) ? $txn_status_mapping[ $old_attendee['payment_status'] ] : 'TIN';
410
+            $STS_ID = isset($txn_status_mapping[$old_attendee['payment_status']]) ? $txn_status_mapping[$old_attendee['payment_status']] : 'TIN';
411 411
             $cols_n_values = array(
412 412
                 'TXN_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
413 413
                 'TXN_total'=>floatval($old_attendee['total_cost']),
@@ -416,14 +416,14 @@  discard block
 block discarded – undo
416 416
                 'TXN_hash_salt'=>$old_attendee['hashSalt']
417 417
             );
418 418
             $datatypes = array(
419
-                '%s',// TXN_timestamp
420
-                '%f',// TXN_total
421
-                '%f',// TXN_paid
422
-                '%s',// STS_ID
423
-                '%s',// TXN_hash_salt
419
+                '%s', // TXN_timestamp
420
+                '%f', // TXN_total
421
+                '%f', // TXN_paid
422
+                '%s', // STS_ID
423
+                '%s', // TXN_hash_salt
424 424
             );
425 425
             $success = $wpdb->insert($this->_new_transaction_table, $cols_n_values, $datatypes);
426
-            if (! $success) {
426
+            if ( ! $success) {
427 427
                 $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_transaction_table, $cols_n_values, $datatypes));
428 428
                 return 0;
429 429
             }
@@ -483,12 +483,12 @@  discard block
 block discarded – undo
483 483
 
484 484
         $STS_ID = $this->_get_reg_status_for_old_payment_status($old_attendee);
485 485
         $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix.'events_detail', $old_attendee['event_id'], $wpdb->posts);
486
-        if (! $new_event_id) {
486
+        if ( ! $new_event_id) {
487 487
             $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)));
488 488
         }
489 489
 
490 490
         $ticket_id = $this->_try_to_find_new_ticket_id($old_attendee, $new_event_id);
491
-        if (! $ticket_id) {
491
+        if ( ! $ticket_id) {
492 492
             $ticket_id = $this->_insert_new_ticket_because_none_found($old_attendee, $new_event_id);
493 493
             $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));
494 494
         }
@@ -519,23 +519,23 @@  discard block
 block discarded – undo
519 519
                 'REG_deleted'=>false
520 520
             );
521 521
             $datatypes = array(
522
-                '%d',// EVT_ID
523
-                '%d',// ATT_ID
524
-                '%d',// TXN_ID
525
-                '%d',// TKT_ID
526
-                '%s',// STS_ID
527
-                '%s',// REG_date
528
-                '%f',// REG_final_price
529
-                '%s',// REG_session
530
-                '%s',// REG_code
531
-                '%s',// REG_url_link
532
-                '%d',// REG_count
533
-                '%d',// REG_group_size
534
-                '%d',// REG_att_is_going
535
-                '%d',// REG_deleted
522
+                '%d', // EVT_ID
523
+                '%d', // ATT_ID
524
+                '%d', // TXN_ID
525
+                '%d', // TKT_ID
526
+                '%s', // STS_ID
527
+                '%s', // REG_date
528
+                '%f', // REG_final_price
529
+                '%s', // REG_session
530
+                '%s', // REG_code
531
+                '%s', // REG_url_link
532
+                '%d', // REG_count
533
+                '%d', // REG_group_size
534
+                '%d', // REG_att_is_going
535
+                '%d', // REG_deleted
536 536
             );
537 537
             $success = $wpdb->insert($this->_new_reg_table, $cols_n_values, $datatypes);
538
-            if (! $success) {
538
+            if ( ! $success) {
539 539
                 $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));
540 540
                 return 0;
541 541
             }
@@ -567,11 +567,11 @@  discard block
 block discarded – undo
567 567
         $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));
568 568
         if ($success) {
569 569
             // get the ticket's datetimes, and increment them too
570
-            $success_update_dateimtes =  $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT
570
+            $success_update_dateimtes = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT
571 571
 				INNER JOIN {$this->_new_ticket_datetime_table} as DTK ON TKT.TKT_ID = DTK.TKT_ID
572 572
 				INNER JOIN {$this->_new_datetime_table} as DTT ON DTK.DTT_ID = DTT.DTT_ID
573 573
 				SET DTT.DTT_sold = DTT.DTT_sold + %d WHERE TKT.TKT_ID = %d", $quantity_sold, $new_ticket_id));
574
-            if (! $success_update_dateimtes) {
574
+            if ( ! $success_update_dateimtes) {
575 575
                 $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));
576 576
             }
577 577
         } else {
@@ -603,10 +603,10 @@  discard block
 block discarded – undo
603 603
         // add all conditions to an array from which we can SHIFT conditions off in order to widen our search
604 604
         // the most important condition should be last, as it will be array_shift'ed off last
605 605
         $conditions = array(
606
-            $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match?
607
-            $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price),// prices match?
608
-            $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option),// names match?
609
-            $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match?
606
+            $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime), // times match?
607
+            $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price), // prices match?
608
+            $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option), // names match?
609
+            $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id), // events match?
610 610
         );
611 611
         $select_and_join_part = "SELECT $tickets_table.TKT_ID FROM $tickets_table INNER JOIN
612 612
 			$datetime_tickets_table ON $tickets_table.TKT_ID = $datetime_tickets_table.TKT_ID INNER JOIN
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
             $full_query = $select_and_join_part." WHERE ".implode(" AND ", $conditions)." LIMIT 1";
617 617
             $ticket_id_found = $wpdb->get_var($full_query);
618 618
             array_shift($conditions);
619
-        } while (! $ticket_id_found && $conditions);
619
+        }while ( ! $ticket_id_found && $conditions);
620 620
         return $ticket_id_found;
621 621
     }
622 622
 
@@ -638,8 +638,8 @@  discard block
 block discarded – undo
638 638
 
639 639
 
640 640
         // insert new datetime unless we find one
641
-        $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);
642
-        if (! $datetime_id) {
641
+        $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);
642
+        if ( ! $datetime_id) {
643 643
             $old_att_end_date = $old_attendee['start_date'];
644 644
             $old_att_end_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
645 645
             $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");
@@ -652,10 +652,10 @@  discard block
 block discarded – undo
652 652
                         'DTT_deleted' => true
653 653
                     ),
654 654
                 array(
655
-                        '%d',// EVT_ID
656
-                        '%s',// DTT_EVT_start
657
-                        '%s',// DTT_EVT_end
658
-                        '%d',// DTT_deleted
655
+                        '%d', // EVT_ID
656
+                        '%s', // DTT_EVT_start
657
+                        '%s', // DTT_EVT_end
658
+                        '%d', // DTT_deleted
659 659
                     )
660 660
             );
661 661
             $datetime_id = $wpdb->insert_id;
@@ -663,21 +663,21 @@  discard block
 block discarded – undo
663 663
 
664 664
         // insert new ticket
665 665
         $success = $wpdb->insert(
666
-            $wpdb->prefix . 'esp_ticket',
666
+            $wpdb->prefix.'esp_ticket',
667 667
             array(
668 668
                     'TKT_name' => $old_att_price_option,
669 669
                     'TKT_qty' => -1,
670 670
                     'TKT_price' => $old_att_price,
671
-                    '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
671
+                    '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
672 672
                     'TKT_end_date' => $old_att_end_datetime,
673 673
 
674 674
                 ),
675 675
             array(
676
-                    '%s',// name
677
-                    '%d',// qty
678
-                    '%d',// price
679
-                    '%s',// start_date
680
-                    '%s',// end_date
676
+                    '%s', // name
677
+                    '%d', // qty
678
+                    '%d', // price
679
+                    '%s', // start_date
680
+                    '%s', // end_date
681 681
                 )
682 682
         );
683 683
         $ticket_id = $wpdb->insert_id;
@@ -689,8 +689,8 @@  discard block
 block discarded – undo
689 689
                     'TKT_ID' => $ticket_id
690 690
                 ),
691 691
             array(
692
-                    '%d',// DTT_ID
693
-                    '%d',// TKT_ID
692
+                    '%d', // DTT_ID
693
+                    '%d', // TKT_ID
694 694
                 )
695 695
         );
696 696
         // insert new price
@@ -703,10 +703,10 @@  discard block
 block discarded – undo
703 703
                     'PRC_deleted' => true
704 704
                 ),
705 705
             array(
706
-                    '%d',// PRC_amount
707
-                    '%d',// PRT_ID
708
-                    '%s',// PRC_name
709
-                    '%d',// PRC_deleted
706
+                    '%d', // PRC_amount
707
+                    '%d', // PRT_ID
708
+                    '%s', // PRC_name
709
+                    '%d', // PRC_deleted
710 710
                 )
711 711
         );
712 712
         $price_id = $wpdb->insert_id;
@@ -718,8 +718,8 @@  discard block
 block discarded – undo
718 718
                     'PRC_ID' => $price_id
719 719
                 ),
720 720
             array(
721
-                    '%d',// TKT_ID
722
-                    '%d',// PRC_ID
721
+                    '%d', // TKT_ID
722
+                    '%d', // PRC_ID
723 723
                 )
724 724
         );
725 725
         return $ticket_id;
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
     {
757 757
         global $wpdb;
758 758
         // only add a payment for primary attendees
759
-        $old_pay_stati_indicating_no_payment = array('Pending','Incomplete','Not Completed');
759
+        $old_pay_stati_indicating_no_payment = array('Pending', 'Incomplete', 'Not Completed');
760 760
         // if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment...
761 761
         if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && ! in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) {
762 762
             $pay_status_mapping = array(
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
                 'Declined'=>'PDC'
767 767
             );
768 768
             $by_admin = $old_attendee['payment'] == 'Admin';
769
-            $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
769
+            $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
770 770
             $cols_n_values = array(
771 771
                 'TXN_ID'=>$new_txn_id,
772 772
                 'STS_ID'=>$STS_ID,
@@ -781,19 +781,19 @@  discard block
 block discarded – undo
781 781
 
782 782
             );
783 783
             $datatypes = array(
784
-                '%d',// TXN_Id
785
-                '%s',// STS_ID
786
-                '%s',// PAY_timestamp
787
-                '%s',// PAY_method
788
-                '%f',// PAY_amount
789
-                '%s',// PAY_gateway
790
-                '%s',// PAY_gateway_response
791
-                '%s',// PAY_txn_id_chq_nmbr
792
-                '%d',// PAY_via_admin
793
-                '%s',// PAY_details
784
+                '%d', // TXN_Id
785
+                '%s', // STS_ID
786
+                '%s', // PAY_timestamp
787
+                '%s', // PAY_method
788
+                '%f', // PAY_amount
789
+                '%s', // PAY_gateway
790
+                '%s', // PAY_gateway_response
791
+                '%s', // PAY_txn_id_chq_nmbr
792
+                '%d', // PAY_via_admin
793
+                '%s', // PAY_details
794 794
             );
795 795
             $success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes);
796
-            if (! $success) {
796
+            if ( ! $success) {
797 797
                 $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));
798 798
                 return 0;
799 799
             }
@@ -812,7 +812,7 @@  discard block
 block discarded – undo
812 812
      */
813 813
     private function _find_mer_primary_attendee_using_mer_tables($old_registration_id)
814 814
     {
815
-        if (! $this->_mer_tables_exist()) {
815
+        if ( ! $this->_mer_tables_exist()) {
816 816
             return false;
817 817
         }
818 818
         global $wpdb;
Please login to merge, or discard this patch.
core/data_migration_scripts/EE_Data_Migration_Script_Stage_Table.core.php 2 patches
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -16,89 +16,89 @@
 block discarded – undo
16 16
 abstract class EE_Data_Migration_Script_Stage_Table extends EE_Data_Migration_Script_Stage
17 17
 {
18 18
 
19
-    protected $_old_table;
19
+	protected $_old_table;
20 20
 
21
-    /**
22
-     * @var string The columns to select. May be overridden for children.
23
-     */
24
-    protected $select_expression = '*';
21
+	/**
22
+	 * @var string The columns to select. May be overridden for children.
23
+	 */
24
+	protected $select_expression = '*';
25 25
 
26
-    /**
27
-     * Set in the constructor to add this sql to both the counting query in
28
-     * EE_Data_Migration_Script_Stage_Table::_count_records_to_migrate() and
29
-     * EE_Data_Migration_Script_Stage_Table::_get_rows().
30
-     * Eg "where column_name like '%some_value%'"
31
-     *
32
-     * @var string
33
-     */
34
-    protected $_extra_where_sql;
26
+	/**
27
+	 * Set in the constructor to add this sql to both the counting query in
28
+	 * EE_Data_Migration_Script_Stage_Table::_count_records_to_migrate() and
29
+	 * EE_Data_Migration_Script_Stage_Table::_get_rows().
30
+	 * Eg "where column_name like '%some_value%'"
31
+	 *
32
+	 * @var string
33
+	 */
34
+	protected $_extra_where_sql;
35 35
 
36 36
 
37
-    /**
38
-     * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property
39
-     * accordingly. Note: it should not alter the count of items migrated. That is done in the public function that
40
-     * calls this. IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the
41
-     * last migration step, otherwise it should always return $num_items_to_migrate. (Eg, if we're migrating attendees
42
-     * rows from the database, and $num_items_to_migrate is set to 50, then we SHOULD actually migrate 50 rows,but at
43
-     * very least we MUST report/return 50 items migrated)
44
-     *
45
-     * @param int $num_items
46
-     * @return int number of items ACTUALLY migrated
47
-     */
48
-    public function _migration_step($num_items = 50)
49
-    {
50
-        $rows = $this->_get_rows($num_items);
51
-        $items_actually_migrated = 0;
52
-        foreach ($rows as $old_row) {
53
-            $this->_migrate_old_row($old_row);
54
-            $items_actually_migrated++;
55
-        }
56
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
57
-            $this->set_completed();
58
-        }
59
-        return $items_actually_migrated;
60
-    }
37
+	/**
38
+	 * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property
39
+	 * accordingly. Note: it should not alter the count of items migrated. That is done in the public function that
40
+	 * calls this. IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the
41
+	 * last migration step, otherwise it should always return $num_items_to_migrate. (Eg, if we're migrating attendees
42
+	 * rows from the database, and $num_items_to_migrate is set to 50, then we SHOULD actually migrate 50 rows,but at
43
+	 * very least we MUST report/return 50 items migrated)
44
+	 *
45
+	 * @param int $num_items
46
+	 * @return int number of items ACTUALLY migrated
47
+	 */
48
+	public function _migration_step($num_items = 50)
49
+	{
50
+		$rows = $this->_get_rows($num_items);
51
+		$items_actually_migrated = 0;
52
+		foreach ($rows as $old_row) {
53
+			$this->_migrate_old_row($old_row);
54
+			$items_actually_migrated++;
55
+		}
56
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
57
+			$this->set_completed();
58
+		}
59
+		return $items_actually_migrated;
60
+	}
61 61
 
62
-    /**
63
-     * Gets the rows for each migration stage from the old table
64
-     *
65
-     * @global wpdb $wpdb
66
-     * @param int   $limit
67
-     * @return array of arrays like $wpdb->get_results($sql, ARRAY_A)
68
-     */
69
-    protected function _get_rows($limit)
70
-    {
71
-        global $wpdb;
72
-        $start_at_record = $this->count_records_migrated();
73
-        $query = "SELECT {$this->select_expression} FROM {$this->_old_table} {$this->_extra_where_sql} " . $wpdb->prepare(
74
-            "LIMIT %d, %d",
75
-            $start_at_record,
76
-            $limit
77
-        );
78
-        return $wpdb->get_results($query, ARRAY_A);
79
-    }
62
+	/**
63
+	 * Gets the rows for each migration stage from the old table
64
+	 *
65
+	 * @global wpdb $wpdb
66
+	 * @param int   $limit
67
+	 * @return array of arrays like $wpdb->get_results($sql, ARRAY_A)
68
+	 */
69
+	protected function _get_rows($limit)
70
+	{
71
+		global $wpdb;
72
+		$start_at_record = $this->count_records_migrated();
73
+		$query = "SELECT {$this->select_expression} FROM {$this->_old_table} {$this->_extra_where_sql} " . $wpdb->prepare(
74
+			"LIMIT %d, %d",
75
+			$start_at_record,
76
+			$limit
77
+		);
78
+		return $wpdb->get_results($query, ARRAY_A);
79
+	}
80 80
 
81 81
 
82
-    /**
83
-     * Counts the records to migrate; the public version may cache it
84
-     *
85
-     * @return int
86
-     */
87
-    public function _count_records_to_migrate()
88
-    {
89
-        global $wpdb;
90
-        $query = "SELECT COUNT(*) FROM {$this->_old_table} {$this->_extra_where_sql}";
91
-        $count = $wpdb->get_var($query);
92
-        return $count;
93
-    }
82
+	/**
83
+	 * Counts the records to migrate; the public version may cache it
84
+	 *
85
+	 * @return int
86
+	 */
87
+	public function _count_records_to_migrate()
88
+	{
89
+		global $wpdb;
90
+		$query = "SELECT COUNT(*) FROM {$this->_old_table} {$this->_extra_where_sql}";
91
+		$count = $wpdb->get_var($query);
92
+		return $count;
93
+	}
94 94
 
95
-    /**
96
-     * takes care of migrating this particular row from the OLD table to whatever its
97
-     * representation is in the new database. If there are errors, use $this->add_error to log them. If there is a
98
-     * fatal error which prevents all future migrations, throw an exception describing it
99
-     *
100
-     * @param array $old_row an associative array where keys are column names and values are their values.
101
-     * @return null
102
-     */
103
-    abstract protected function _migrate_old_row($old_row);
95
+	/**
96
+	 * takes care of migrating this particular row from the OLD table to whatever its
97
+	 * representation is in the new database. If there are errors, use $this->add_error to log them. If there is a
98
+	 * fatal error which prevents all future migrations, throw an exception describing it
99
+	 *
100
+	 * @param array $old_row an associative array where keys are column names and values are their values.
101
+	 * @return null
102
+	 */
103
+	abstract protected function _migrate_old_row($old_row);
104 104
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@
 block discarded – undo
70 70
     {
71 71
         global $wpdb;
72 72
         $start_at_record = $this->count_records_migrated();
73
-        $query = "SELECT {$this->select_expression} FROM {$this->_old_table} {$this->_extra_where_sql} " . $wpdb->prepare(
73
+        $query = "SELECT {$this->select_expression} FROM {$this->_old_table} {$this->_extra_where_sql} ".$wpdb->prepare(
74 74
             "LIMIT %d, %d",
75 75
             $start_at_record,
76 76
             $limit
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.80.rc.028');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.80.rc.028');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.