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