Completed
Branch BUG/fix-checkins-migration-fat... (bcc239)
by
unknown
17:25 queued 09:09
created
core/data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_checkins.dmsstage.php 2 patches
Indentation   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -26,159 +26,159 @@
 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__(
62
-                        /* translators: %1$s database row represented in JSON, %2$s number of registrations to check-in
54
+		// make sure registrations array is numerically indexed starting at 0 (it probably already is)
55
+		$new_registrations_for_attendee = array_values($new_registrations_for_attendee);
56
+		$new_checkin_ids = array();
57
+		for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) {
58
+			$new_reg_id = $new_registrations_for_attendee[ $i ];
59
+			if (! $new_reg_id) {
60
+				$this->add_error(sprintf(
61
+					esc_html__(
62
+						/* translators: %1$s database row represented in JSON, %2$s number of registrations to check-in
63 63
                         *  %3$s number of registrations for the attendee, %4$s new registration rows represented in JSON
64 64
                         */
65
-                        // @codingStandardsIgnoreStart
66
-                        'It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)',
67
-                        // @codingStandardsIgnoreEnd
68
-                        'event_espresso'
69
-                    ),
70
-                    $this->_json_encode($old_row),
71
-                    abs($num_to_checkin_at_this_time),
72
-                    count($new_registrations_for_attendee),
73
-                    $this->_json_encode($new_registrations_for_attendee)
74
-                ));
75
-                break;
76
-            }
77
-            $existing_checkin_record = $wpdb->get_var(
78
-                $wpdb->prepare(
79
-                    "SELECT CHK_ID FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1",
80
-                    $new_reg_id
81
-                )
82
-            );
83
-            if (! $existing_checkin_record) {
84
-                $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime);
85
-                if ($new_id) {
86
-                    $new_checkin_ids[]= $new_id;
87
-                }
88
-            }
89
-        }
90
-        if ($new_checkin_ids) {
91
-            $this->get_migration_script()->set_mapping(
92
-                $this->_old_table,
93
-                $old_row['id'],
94
-                $this->_new_table,
95
-                $new_checkin_ids
96
-            );
97
-        }
98
-    }
65
+						// @codingStandardsIgnoreStart
66
+						'It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)',
67
+						// @codingStandardsIgnoreEnd
68
+						'event_espresso'
69
+					),
70
+					$this->_json_encode($old_row),
71
+					abs($num_to_checkin_at_this_time),
72
+					count($new_registrations_for_attendee),
73
+					$this->_json_encode($new_registrations_for_attendee)
74
+				));
75
+				break;
76
+			}
77
+			$existing_checkin_record = $wpdb->get_var(
78
+				$wpdb->prepare(
79
+					"SELECT CHK_ID FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1",
80
+					$new_reg_id
81
+				)
82
+			);
83
+			if (! $existing_checkin_record) {
84
+				$new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime);
85
+				if ($new_id) {
86
+					$new_checkin_ids[]= $new_id;
87
+				}
88
+			}
89
+		}
90
+		if ($new_checkin_ids) {
91
+			$this->get_migration_script()->set_mapping(
92
+				$this->_old_table,
93
+				$old_row['id'],
94
+				$this->_new_table,
95
+				$new_checkin_ids
96
+			);
97
+		}
98
+	}
99 99
 
100 100
 
101
-    /**
102
-     * Tries to find the new datetime the Check-in was for, based on the attendee row
103
-     * (because we know the attendee was for an event as a specific time, and we know
104
-     * the event's OLD ID...)
105
-     * @global type $wpdb
106
-     * @param array $old_attendee_row
107
-     * @return array row of datetime from DB
108
-     */
109
-    private function _try_to_find_datetime($old_attendee)
110
-    {
111
-        global $wpdb;
101
+	/**
102
+	 * Tries to find the new datetime the Check-in was for, based on the attendee row
103
+	 * (because we know the attendee was for an event as a specific time, and we know
104
+	 * the event's OLD ID...)
105
+	 * @global type $wpdb
106
+	 * @param array $old_attendee_row
107
+	 * @return array row of datetime from DB
108
+	 */
109
+	private function _try_to_find_datetime($old_attendee)
110
+	{
111
+		global $wpdb;
112 112
 
113
-        $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts);
114
-        if (! $new_event_id) {
115
-            $this->add_error(
116
-                sprintf(
117
-                    esc_html__(
118
-                        /* translators: 1: original event ID, 2: original attendee database row */
119
-                        // @codingStandardsIgnoreStart
120
-                        'Could not find new event ID with old event ID %1$d, on attendee row %2$s; and because of that couldn\'t find the correct datetime for Check-in',
121
-                        // @codingStandardsIgnoreEnd
122
-                        'event_espresso'
123
-                    ),
124
-                    $old_attendee['event_id'],
125
-                    $this->_json_encode($old_attendee)
126
-                )
127
-            );
128
-            return 0;
129
-        }
130
-        $old_att_start_date = $old_attendee['start_date'];
131
-        $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
132
-        $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00");
113
+		$new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts);
114
+		if (! $new_event_id) {
115
+			$this->add_error(
116
+				sprintf(
117
+					esc_html__(
118
+						/* translators: 1: original event ID, 2: original attendee database row */
119
+						// @codingStandardsIgnoreStart
120
+						'Could not find new event ID with old event ID %1$d, on attendee row %2$s; and because of that couldn\'t find the correct datetime for Check-in',
121
+						// @codingStandardsIgnoreEnd
122
+						'event_espresso'
123
+					),
124
+					$old_attendee['event_id'],
125
+					$this->_json_encode($old_attendee)
126
+				)
127
+			);
128
+			return 0;
129
+		}
130
+		$old_att_start_date = $old_attendee['start_date'];
131
+		$old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
132
+		$old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00");
133 133
 
134
-        $datetime_table = $wpdb->prefix."esp_datetime";
135
-        // add all conditions to an array from which we can SHIFT conditions off in order to widen our search
136
-        // the most important condition should be last, as it will be array_shift'ed off last
137
-        $conditions = array(
138
-            $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match?
139
-            $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match?
140
-        );
141
-        // start running queries, widening search each time by removing a condition
142
-        $datetime_found = null;
143
-        do {
144
-            $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1";
145
-            $datetime_found = $wpdb->get_row($full_query, ARRAY_A);
146
-            array_shift($conditions);
147
-        } while (! $datetime_found && $conditions);
148
-        return $datetime_found;
149
-    }
134
+		$datetime_table = $wpdb->prefix."esp_datetime";
135
+		// add all conditions to an array from which we can SHIFT conditions off in order to widen our search
136
+		// the most important condition should be last, as it will be array_shift'ed off last
137
+		$conditions = array(
138
+			$wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match?
139
+			$wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match?
140
+		);
141
+		// start running queries, widening search each time by removing a condition
142
+		$datetime_found = null;
143
+		do {
144
+			$full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1";
145
+			$datetime_found = $wpdb->get_row($full_query, ARRAY_A);
146
+			array_shift($conditions);
147
+		} while (! $datetime_found && $conditions);
148
+		return $datetime_found;
149
+	}
150 150
 
151
-    /**
152
-     * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap
153
-     * @param int $new_reg_id
154
-     * @param int $new_datetime_id
155
-     * @param string $timestamp mysql datetime
156
-     * @return int new Check-in id
157
-     */
158
-    private function _insert_checkin_record($new_reg_id, $new_datetime)
159
-    {
160
-        global $wpdb;
151
+	/**
152
+	 * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap
153
+	 * @param int $new_reg_id
154
+	 * @param int $new_datetime_id
155
+	 * @param string $timestamp mysql datetime
156
+	 * @return int new Check-in id
157
+	 */
158
+	private function _insert_checkin_record($new_reg_id, $new_datetime)
159
+	{
160
+		global $wpdb;
161 161
 
162 162
 
163
-        // ok we can actually do what we set out to do: add a checkin/checkout record
164
-        $cols_n_values = array(
165
-            'REG_ID'=>$new_reg_id,
166
-            'DTT_ID'=>$new_datetime['DTT_ID'],
167
-            'CHK_in'=>true,
168
-            'CHK_timestamp'=>$new_datetime['DTT_EVT_start']
169
-        );
170
-        $datatypes = array(
171
-            '%d',// REG_ID
172
-            '%d',// DTT_ID
173
-            '%d',// CHK_in
174
-            '%s',// CHK_timestamp
175
-        );
176
-        $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
177
-        if (! $success) {
178
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes));
179
-            return 0;
180
-        }
181
-        $new_id = $wpdb->insert_id;
182
-        return $new_id;
183
-    }
163
+		// ok we can actually do what we set out to do: add a checkin/checkout record
164
+		$cols_n_values = array(
165
+			'REG_ID'=>$new_reg_id,
166
+			'DTT_ID'=>$new_datetime['DTT_ID'],
167
+			'CHK_in'=>true,
168
+			'CHK_timestamp'=>$new_datetime['DTT_EVT_start']
169
+		);
170
+		$datatypes = array(
171
+			'%d',// REG_ID
172
+			'%d',// DTT_ID
173
+			'%d',// CHK_in
174
+			'%s',// CHK_timestamp
175
+		);
176
+		$success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
177
+		if (! $success) {
178
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes));
179
+			return 0;
180
+		}
181
+		$new_id = $wpdb->insert_id;
182
+		return $new_id;
183
+	}
184 184
 }
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__(
62 62
                         /* translators: %1$s database row represented in JSON, %2$s number of registrations to check-in
@@ -80,10 +80,10 @@  discard block
 block discarded – undo
80 80
                     $new_reg_id
81 81
                 )
82 82
             );
83
-            if (! $existing_checkin_record) {
83
+            if ( ! $existing_checkin_record) {
84 84
                 $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime);
85 85
                 if ($new_id) {
86
-                    $new_checkin_ids[]= $new_id;
86
+                    $new_checkin_ids[] = $new_id;
87 87
                 }
88 88
             }
89 89
         }
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
         global $wpdb;
112 112
 
113 113
         $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts);
114
-        if (! $new_event_id) {
114
+        if ( ! $new_event_id) {
115 115
             $this->add_error(
116 116
                 sprintf(
117 117
                     esc_html__(
@@ -135,8 +135,8 @@  discard block
 block discarded – undo
135 135
         // add all conditions to an array from which we can SHIFT conditions off in order to widen our search
136 136
         // the most important condition should be last, as it will be array_shift'ed off last
137 137
         $conditions = array(
138
-            $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match?
139
-            $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match?
138
+            $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime), // times match?
139
+            $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id), // events match?
140 140
         );
141 141
         // start running queries, widening search each time by removing a condition
142 142
         $datetime_found = null;
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
             $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1";
145 145
             $datetime_found = $wpdb->get_row($full_query, ARRAY_A);
146 146
             array_shift($conditions);
147
-        } while (! $datetime_found && $conditions);
147
+        }while ( ! $datetime_found && $conditions);
148 148
         return $datetime_found;
149 149
     }
150 150
 
@@ -168,13 +168,13 @@  discard block
 block discarded – undo
168 168
             'CHK_timestamp'=>$new_datetime['DTT_EVT_start']
169 169
         );
170 170
         $datatypes = array(
171
-            '%d',// REG_ID
172
-            '%d',// DTT_ID
173
-            '%d',// CHK_in
174
-            '%s',// CHK_timestamp
171
+            '%d', // REG_ID
172
+            '%d', // DTT_ID
173
+            '%d', // CHK_in
174
+            '%s', // CHK_timestamp
175 175
         );
176 176
         $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
177
-        if (! $success) {
177
+        if ( ! $success) {
178 178
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes));
179 179
             return 0;
180 180
         }
Please login to merge, or discard this patch.