@@ -12,73 +12,73 @@ discard block |
||
12 | 12 | class EE_DMS_4_7_0_Add_Taxes_To_REG_Final_Price extends EE_Data_Migration_Script_Stage_Table |
13 | 13 | { |
14 | 14 | |
15 | - protected $_ticket_table; |
|
16 | - |
|
17 | - protected $_line_item_table; |
|
18 | - |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - /** @type WPDB $wpdb */ |
|
22 | - global $wpdb; |
|
23 | - $this->_pretty_name = __('Registration Final Price Tax Calculations', 'event_espresso'); |
|
24 | - // define tables |
|
25 | - $this->_old_table = $wpdb->prefix . 'esp_registration'; |
|
26 | - $this->_ticket_table = $wpdb->prefix . 'esp_ticket'; |
|
27 | - $this->_line_item_table = $wpdb->prefix . 'esp_line_item'; |
|
28 | - parent::__construct(); |
|
29 | - } |
|
30 | - |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * @return string |
|
35 | - */ |
|
36 | - protected function _get_rest_of_sql_for_query() |
|
37 | - { |
|
38 | - $SQL = "FROM {$this->_old_table} AS reg "; |
|
39 | - $SQL .= "JOIN {$this->_ticket_table} as tkt ON reg.TKT_ID = tkt.TKT_ID "; |
|
40 | - $SQL .= "JOIN {$this->_line_item_table} as line ON reg.TXN_ID = line.TXN_ID "; |
|
41 | - $SQL .= "WHERE tkt.TKT_taxable = 1 "; |
|
42 | - $SQL .= "AND line.LIN_code = 'total' "; |
|
43 | - $SQL .= "AND reg.REG_final_price > 0 "; |
|
44 | - return $SQL; |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * Counts the records to migrate; the public version may cache it |
|
51 | - * @return int |
|
52 | - */ |
|
53 | - public function _count_records_to_migrate() |
|
54 | - { |
|
55 | - /** @type WPDB $wpdb */ |
|
56 | - global $wpdb; |
|
57 | - $SQL = "SELECT count( reg.REG_ID ) "; |
|
58 | - $SQL .= $this->_get_rest_of_sql_for_query(); |
|
59 | - $count = $wpdb->get_var($SQL); |
|
60 | - return $count; |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * Gets data for all registrations with taxable tickets in the esp_line_item table |
|
67 | - * @global wpdb $wpdb |
|
68 | - * @param int $limit |
|
69 | - * @return array of arrays like $wpdb->get_results($sql, ARRAY_A) |
|
70 | - */ |
|
71 | - protected function _get_rows($limit) |
|
72 | - { |
|
73 | - /** @type WPDB $wpdb */ |
|
74 | - global $wpdb; |
|
75 | - $start_at_record = $this->count_records_migrated(); |
|
76 | - $SQL = "SELECT reg.REG_ID, reg.REG_final_price, line.LIN_ID "; |
|
77 | - $SQL .= $this->_get_rest_of_sql_for_query(); |
|
78 | - $SQL .= $wpdb->prepare("LIMIT %d, %d", $start_at_record, $limit); |
|
79 | - |
|
80 | - // produces something like: |
|
81 | - /* |
|
15 | + protected $_ticket_table; |
|
16 | + |
|
17 | + protected $_line_item_table; |
|
18 | + |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + /** @type WPDB $wpdb */ |
|
22 | + global $wpdb; |
|
23 | + $this->_pretty_name = __('Registration Final Price Tax Calculations', 'event_espresso'); |
|
24 | + // define tables |
|
25 | + $this->_old_table = $wpdb->prefix . 'esp_registration'; |
|
26 | + $this->_ticket_table = $wpdb->prefix . 'esp_ticket'; |
|
27 | + $this->_line_item_table = $wpdb->prefix . 'esp_line_item'; |
|
28 | + parent::__construct(); |
|
29 | + } |
|
30 | + |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * @return string |
|
35 | + */ |
|
36 | + protected function _get_rest_of_sql_for_query() |
|
37 | + { |
|
38 | + $SQL = "FROM {$this->_old_table} AS reg "; |
|
39 | + $SQL .= "JOIN {$this->_ticket_table} as tkt ON reg.TKT_ID = tkt.TKT_ID "; |
|
40 | + $SQL .= "JOIN {$this->_line_item_table} as line ON reg.TXN_ID = line.TXN_ID "; |
|
41 | + $SQL .= "WHERE tkt.TKT_taxable = 1 "; |
|
42 | + $SQL .= "AND line.LIN_code = 'total' "; |
|
43 | + $SQL .= "AND reg.REG_final_price > 0 "; |
|
44 | + return $SQL; |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * Counts the records to migrate; the public version may cache it |
|
51 | + * @return int |
|
52 | + */ |
|
53 | + public function _count_records_to_migrate() |
|
54 | + { |
|
55 | + /** @type WPDB $wpdb */ |
|
56 | + global $wpdb; |
|
57 | + $SQL = "SELECT count( reg.REG_ID ) "; |
|
58 | + $SQL .= $this->_get_rest_of_sql_for_query(); |
|
59 | + $count = $wpdb->get_var($SQL); |
|
60 | + return $count; |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * Gets data for all registrations with taxable tickets in the esp_line_item table |
|
67 | + * @global wpdb $wpdb |
|
68 | + * @param int $limit |
|
69 | + * @return array of arrays like $wpdb->get_results($sql, ARRAY_A) |
|
70 | + */ |
|
71 | + protected function _get_rows($limit) |
|
72 | + { |
|
73 | + /** @type WPDB $wpdb */ |
|
74 | + global $wpdb; |
|
75 | + $start_at_record = $this->count_records_migrated(); |
|
76 | + $SQL = "SELECT reg.REG_ID, reg.REG_final_price, line.LIN_ID "; |
|
77 | + $SQL .= $this->_get_rest_of_sql_for_query(); |
|
78 | + $SQL .= $wpdb->prepare("LIMIT %d, %d", $start_at_record, $limit); |
|
79 | + |
|
80 | + // produces something like: |
|
81 | + /* |
|
82 | 82 | SELECT |
83 | 83 | reg.REG_ID, |
84 | 84 | reg.REG_final_price, |
@@ -95,137 +95,137 @@ discard block |
||
95 | 95 | LIMIT 1, 50 |
96 | 96 | */ |
97 | 97 | |
98 | - return $wpdb->get_results($SQL, ARRAY_A); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * @param array $row |
|
105 | - * @return void |
|
106 | - */ |
|
107 | - protected function _migrate_old_row($row) |
|
108 | - { |
|
109 | - /** @type WPDB $wpdb */ |
|
110 | - global $wpdb; |
|
111 | - // ensure all required values are present |
|
112 | - if (! isset($row['REG_ID'], $row['REG_final_price'], $row['LIN_ID'])) { |
|
113 | - $this->add_error( |
|
114 | - sprintf( |
|
115 | - __('Invalid query results returned with the following data:%1$s REG_ID=%2$d, REG_final_price=%3$d, LIN_ID=%4$f. Error: "%5$s"', 'event_espresso'), |
|
116 | - '<br />', |
|
117 | - isset($row['REG_ID']) ? $row['REG_ID'] : '', |
|
118 | - isset($row['REG_final_price']) ? $row['REG_final_price'] : '', |
|
119 | - isset($row['LIN_ID']) ? $row['LIN_ID'] : '', |
|
120 | - $wpdb->last_error |
|
121 | - ) |
|
122 | - ); |
|
123 | - return; |
|
124 | - } |
|
125 | - // get tax subtotal |
|
126 | - $tax_subtotal_line_item_ID = $this->_get_line_item_ID_for_tax_subtotal($row['LIN_ID']); |
|
127 | - if (! $tax_subtotal_line_item_ID) { |
|
128 | - $this->add_error( |
|
129 | - sprintf( |
|
130 | - __('Invalid line item ID returned. Error: "%1$s"', 'event_espresso'), |
|
131 | - $wpdb->last_error |
|
132 | - ) |
|
133 | - ); |
|
134 | - return; |
|
135 | - } |
|
136 | - // now get taxes |
|
137 | - $taxes = $this->_get_tax_amounts($tax_subtotal_line_item_ID); |
|
138 | - // apply taxes to registration final price |
|
139 | - $this->_apply_taxes($row['REG_ID'], $row['REG_final_price'], $taxes); |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * _get_tax_subtotal |
|
146 | - * |
|
147 | - * @param int $LIN_ID |
|
148 | - * @return int |
|
149 | - */ |
|
150 | - protected function _get_line_item_ID_for_tax_subtotal($LIN_ID) |
|
151 | - { |
|
152 | - /** @type WPDB $wpdb */ |
|
153 | - global $wpdb; |
|
154 | - $SQL = "SELECT LIN_ID "; |
|
155 | - $SQL .= "FROM {$this->_line_item_table} "; |
|
156 | - $SQL .= "WHERE LIN_parent = %d "; |
|
157 | - $SQL .= "AND LIN_code = 'taxes'"; |
|
158 | - return $wpdb->get_var($wpdb->prepare($SQL, $LIN_ID)); |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * _get_tax_subtotal |
|
165 | - * |
|
166 | - * @param int $LIN_ID |
|
167 | - * @return array |
|
168 | - */ |
|
169 | - protected function _get_tax_amounts($LIN_ID) |
|
170 | - { |
|
171 | - /** @type WPDB $wpdb */ |
|
172 | - global $wpdb; |
|
173 | - $SQL = "SELECT LIN_percent "; |
|
174 | - $SQL .= "FROM {$this->_line_item_table} "; |
|
175 | - $SQL .= "WHERE LIN_parent = %d"; |
|
176 | - return $wpdb->get_results($wpdb->prepare($SQL, $LIN_ID), OBJECT_K); |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * _apply_taxes |
|
183 | - * |
|
184 | - * @param int $REG_ID |
|
185 | - * @param float $final_price |
|
186 | - * @param array $taxes |
|
187 | - * @return void |
|
188 | - */ |
|
189 | - protected function _apply_taxes($REG_ID = 0, $final_price = 0.00, $taxes = array()) |
|
190 | - { |
|
191 | - if (is_array($taxes) && ! empty($taxes)) { |
|
192 | - $total_taxes = 0; |
|
193 | - foreach ($taxes as $tax) { |
|
194 | - $total_taxes += $final_price * ( $tax->LIN_percent / 100 ); |
|
195 | - } |
|
196 | - $final_price += $total_taxes; |
|
197 | - $this->_update_registration_final_price($REG_ID, $final_price); |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * _update_registration_final_price |
|
205 | - * |
|
206 | - * @param int $REG_ID |
|
207 | - * @param float $REG_final_price |
|
208 | - * @return void |
|
209 | - */ |
|
210 | - protected function _update_registration_final_price($REG_ID = 0, $REG_final_price = 0.00) |
|
211 | - { |
|
212 | - /** @type WPDB $wpdb */ |
|
213 | - global $wpdb; |
|
214 | - $success = $wpdb->update( |
|
215 | - $this->_old_table, |
|
216 | - array( 'REG_final_price' => $REG_final_price ), // data |
|
217 | - array( 'REG_ID' => $REG_ID ), // where |
|
218 | - array( '%f' ), // data format |
|
219 | - array( '%d' ) // where format |
|
220 | - ); |
|
221 | - if ($success === false) { |
|
222 | - $this->add_error( |
|
223 | - sprintf( |
|
224 | - __('Could not update registration final price value for registration ID=%1$d because "%2$s"', 'event_espresso'), |
|
225 | - $REG_ID, |
|
226 | - $wpdb->last_error |
|
227 | - ) |
|
228 | - ); |
|
229 | - } |
|
230 | - } |
|
98 | + return $wpdb->get_results($SQL, ARRAY_A); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * @param array $row |
|
105 | + * @return void |
|
106 | + */ |
|
107 | + protected function _migrate_old_row($row) |
|
108 | + { |
|
109 | + /** @type WPDB $wpdb */ |
|
110 | + global $wpdb; |
|
111 | + // ensure all required values are present |
|
112 | + if (! isset($row['REG_ID'], $row['REG_final_price'], $row['LIN_ID'])) { |
|
113 | + $this->add_error( |
|
114 | + sprintf( |
|
115 | + __('Invalid query results returned with the following data:%1$s REG_ID=%2$d, REG_final_price=%3$d, LIN_ID=%4$f. Error: "%5$s"', 'event_espresso'), |
|
116 | + '<br />', |
|
117 | + isset($row['REG_ID']) ? $row['REG_ID'] : '', |
|
118 | + isset($row['REG_final_price']) ? $row['REG_final_price'] : '', |
|
119 | + isset($row['LIN_ID']) ? $row['LIN_ID'] : '', |
|
120 | + $wpdb->last_error |
|
121 | + ) |
|
122 | + ); |
|
123 | + return; |
|
124 | + } |
|
125 | + // get tax subtotal |
|
126 | + $tax_subtotal_line_item_ID = $this->_get_line_item_ID_for_tax_subtotal($row['LIN_ID']); |
|
127 | + if (! $tax_subtotal_line_item_ID) { |
|
128 | + $this->add_error( |
|
129 | + sprintf( |
|
130 | + __('Invalid line item ID returned. Error: "%1$s"', 'event_espresso'), |
|
131 | + $wpdb->last_error |
|
132 | + ) |
|
133 | + ); |
|
134 | + return; |
|
135 | + } |
|
136 | + // now get taxes |
|
137 | + $taxes = $this->_get_tax_amounts($tax_subtotal_line_item_ID); |
|
138 | + // apply taxes to registration final price |
|
139 | + $this->_apply_taxes($row['REG_ID'], $row['REG_final_price'], $taxes); |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * _get_tax_subtotal |
|
146 | + * |
|
147 | + * @param int $LIN_ID |
|
148 | + * @return int |
|
149 | + */ |
|
150 | + protected function _get_line_item_ID_for_tax_subtotal($LIN_ID) |
|
151 | + { |
|
152 | + /** @type WPDB $wpdb */ |
|
153 | + global $wpdb; |
|
154 | + $SQL = "SELECT LIN_ID "; |
|
155 | + $SQL .= "FROM {$this->_line_item_table} "; |
|
156 | + $SQL .= "WHERE LIN_parent = %d "; |
|
157 | + $SQL .= "AND LIN_code = 'taxes'"; |
|
158 | + return $wpdb->get_var($wpdb->prepare($SQL, $LIN_ID)); |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * _get_tax_subtotal |
|
165 | + * |
|
166 | + * @param int $LIN_ID |
|
167 | + * @return array |
|
168 | + */ |
|
169 | + protected function _get_tax_amounts($LIN_ID) |
|
170 | + { |
|
171 | + /** @type WPDB $wpdb */ |
|
172 | + global $wpdb; |
|
173 | + $SQL = "SELECT LIN_percent "; |
|
174 | + $SQL .= "FROM {$this->_line_item_table} "; |
|
175 | + $SQL .= "WHERE LIN_parent = %d"; |
|
176 | + return $wpdb->get_results($wpdb->prepare($SQL, $LIN_ID), OBJECT_K); |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * _apply_taxes |
|
183 | + * |
|
184 | + * @param int $REG_ID |
|
185 | + * @param float $final_price |
|
186 | + * @param array $taxes |
|
187 | + * @return void |
|
188 | + */ |
|
189 | + protected function _apply_taxes($REG_ID = 0, $final_price = 0.00, $taxes = array()) |
|
190 | + { |
|
191 | + if (is_array($taxes) && ! empty($taxes)) { |
|
192 | + $total_taxes = 0; |
|
193 | + foreach ($taxes as $tax) { |
|
194 | + $total_taxes += $final_price * ( $tax->LIN_percent / 100 ); |
|
195 | + } |
|
196 | + $final_price += $total_taxes; |
|
197 | + $this->_update_registration_final_price($REG_ID, $final_price); |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * _update_registration_final_price |
|
205 | + * |
|
206 | + * @param int $REG_ID |
|
207 | + * @param float $REG_final_price |
|
208 | + * @return void |
|
209 | + */ |
|
210 | + protected function _update_registration_final_price($REG_ID = 0, $REG_final_price = 0.00) |
|
211 | + { |
|
212 | + /** @type WPDB $wpdb */ |
|
213 | + global $wpdb; |
|
214 | + $success = $wpdb->update( |
|
215 | + $this->_old_table, |
|
216 | + array( 'REG_final_price' => $REG_final_price ), // data |
|
217 | + array( 'REG_ID' => $REG_ID ), // where |
|
218 | + array( '%f' ), // data format |
|
219 | + array( '%d' ) // where format |
|
220 | + ); |
|
221 | + if ($success === false) { |
|
222 | + $this->add_error( |
|
223 | + sprintf( |
|
224 | + __('Could not update registration final price value for registration ID=%1$d because "%2$s"', 'event_espresso'), |
|
225 | + $REG_ID, |
|
226 | + $wpdb->last_error |
|
227 | + ) |
|
228 | + ); |
|
229 | + } |
|
230 | + } |
|
231 | 231 | } |
@@ -22,9 +22,9 @@ discard block |
||
22 | 22 | global $wpdb; |
23 | 23 | $this->_pretty_name = __('Registration Final Price Tax Calculations', 'event_espresso'); |
24 | 24 | // define tables |
25 | - $this->_old_table = $wpdb->prefix . 'esp_registration'; |
|
26 | - $this->_ticket_table = $wpdb->prefix . 'esp_ticket'; |
|
27 | - $this->_line_item_table = $wpdb->prefix . 'esp_line_item'; |
|
25 | + $this->_old_table = $wpdb->prefix.'esp_registration'; |
|
26 | + $this->_ticket_table = $wpdb->prefix.'esp_ticket'; |
|
27 | + $this->_line_item_table = $wpdb->prefix.'esp_line_item'; |
|
28 | 28 | parent::__construct(); |
29 | 29 | } |
30 | 30 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | /** @type WPDB $wpdb */ |
110 | 110 | global $wpdb; |
111 | 111 | // ensure all required values are present |
112 | - if (! isset($row['REG_ID'], $row['REG_final_price'], $row['LIN_ID'])) { |
|
112 | + if ( ! isset($row['REG_ID'], $row['REG_final_price'], $row['LIN_ID'])) { |
|
113 | 113 | $this->add_error( |
114 | 114 | sprintf( |
115 | 115 | __('Invalid query results returned with the following data:%1$s REG_ID=%2$d, REG_final_price=%3$d, LIN_ID=%4$f. Error: "%5$s"', 'event_espresso'), |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | } |
125 | 125 | // get tax subtotal |
126 | 126 | $tax_subtotal_line_item_ID = $this->_get_line_item_ID_for_tax_subtotal($row['LIN_ID']); |
127 | - if (! $tax_subtotal_line_item_ID) { |
|
127 | + if ( ! $tax_subtotal_line_item_ID) { |
|
128 | 128 | $this->add_error( |
129 | 129 | sprintf( |
130 | 130 | __('Invalid line item ID returned. Error: "%1$s"', 'event_espresso'), |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | if (is_array($taxes) && ! empty($taxes)) { |
192 | 192 | $total_taxes = 0; |
193 | 193 | foreach ($taxes as $tax) { |
194 | - $total_taxes += $final_price * ( $tax->LIN_percent / 100 ); |
|
194 | + $total_taxes += $final_price * ($tax->LIN_percent / 100); |
|
195 | 195 | } |
196 | 196 | $final_price += $total_taxes; |
197 | 197 | $this->_update_registration_final_price($REG_ID, $final_price); |
@@ -213,10 +213,10 @@ discard block |
||
213 | 213 | global $wpdb; |
214 | 214 | $success = $wpdb->update( |
215 | 215 | $this->_old_table, |
216 | - array( 'REG_final_price' => $REG_final_price ), // data |
|
217 | - array( 'REG_ID' => $REG_ID ), // where |
|
218 | - array( '%f' ), // data format |
|
219 | - array( '%d' ) // where format |
|
216 | + array('REG_final_price' => $REG_final_price), // data |
|
217 | + array('REG_ID' => $REG_ID), // where |
|
218 | + array('%f'), // data format |
|
219 | + array('%d') // where format |
|
220 | 220 | ); |
221 | 221 | if ($success === false) { |
222 | 222 | $this->add_error( |
@@ -18,44 +18,44 @@ |
||
18 | 18 | class EE_DMS_Unknown_1_0_0 extends EE_Data_Migration_Script_Base |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * Returns whether or not this data migration script can operate on the given version of the database. |
|
23 | - * Eg, if this migration script can migrate from 3.1.26 or higher (but not anything after 4.0.0), and |
|
24 | - * it's passed a string like '3.1.38B', it should return true |
|
25 | - * |
|
26 | - * @param string $version_string |
|
27 | - * @return boolean |
|
28 | - */ |
|
29 | - public function can_migrate_from_version($version_string) |
|
30 | - { |
|
31 | - return false; |
|
32 | - } |
|
33 | - |
|
34 | - public function schema_changes_after_migration() |
|
35 | - { |
|
36 | - return; |
|
37 | - } |
|
38 | - |
|
39 | - public function schema_changes_before_migration() |
|
40 | - { |
|
41 | - return; |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * All children of this must call parent::__construct() at the end of their constructor or suffer the consequences! |
|
47 | - * |
|
48 | - * @param TableManager $table_manager |
|
49 | - * @param TableAnalysis $table_analysis |
|
50 | - */ |
|
51 | - public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
52 | - { |
|
53 | - $this->_migration_stages = array(); |
|
54 | - $this->_pretty_name = __("Fatal Uncatchable Error Occurred", "event_espresso"); |
|
55 | - parent::__construct($table_manager, $table_analysis); |
|
56 | - } |
|
57 | - |
|
58 | - public function migration_page_hooks() |
|
59 | - { |
|
60 | - } |
|
21 | + /** |
|
22 | + * Returns whether or not this data migration script can operate on the given version of the database. |
|
23 | + * Eg, if this migration script can migrate from 3.1.26 or higher (but not anything after 4.0.0), and |
|
24 | + * it's passed a string like '3.1.38B', it should return true |
|
25 | + * |
|
26 | + * @param string $version_string |
|
27 | + * @return boolean |
|
28 | + */ |
|
29 | + public function can_migrate_from_version($version_string) |
|
30 | + { |
|
31 | + return false; |
|
32 | + } |
|
33 | + |
|
34 | + public function schema_changes_after_migration() |
|
35 | + { |
|
36 | + return; |
|
37 | + } |
|
38 | + |
|
39 | + public function schema_changes_before_migration() |
|
40 | + { |
|
41 | + return; |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * All children of this must call parent::__construct() at the end of their constructor or suffer the consequences! |
|
47 | + * |
|
48 | + * @param TableManager $table_manager |
|
49 | + * @param TableAnalysis $table_analysis |
|
50 | + */ |
|
51 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
52 | + { |
|
53 | + $this->_migration_stages = array(); |
|
54 | + $this->_pretty_name = __("Fatal Uncatchable Error Occurred", "event_espresso"); |
|
55 | + parent::__construct($table_manager, $table_analysis); |
|
56 | + } |
|
57 | + |
|
58 | + public function migration_page_hooks() |
|
59 | + { |
|
60 | + } |
|
61 | 61 | } |
@@ -15,44 +15,44 @@ |
||
15 | 15 | |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * Just initializes the status of the migration |
|
20 | - * |
|
21 | - * @return EE_DMS_4_9_0_Answers_With_No_Registration |
|
22 | - */ |
|
23 | - public function __construct() |
|
24 | - { |
|
25 | - $this->_pretty_name = __('Answer Cleanup', 'event_espresso'); |
|
26 | - parent::__construct(); |
|
27 | - } |
|
18 | + /** |
|
19 | + * Just initializes the status of the migration |
|
20 | + * |
|
21 | + * @return EE_DMS_4_9_0_Answers_With_No_Registration |
|
22 | + */ |
|
23 | + public function __construct() |
|
24 | + { |
|
25 | + $this->_pretty_name = __('Answer Cleanup', 'event_espresso'); |
|
26 | + parent::__construct(); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Counts the records to migrate; the public version may cache it |
|
31 | - * @return int |
|
32 | - */ |
|
33 | - protected function _count_records_to_migrate() |
|
34 | - { |
|
35 | - return 1; |
|
36 | - } |
|
29 | + /** |
|
30 | + * Counts the records to migrate; the public version may cache it |
|
31 | + * @return int |
|
32 | + */ |
|
33 | + protected function _count_records_to_migrate() |
|
34 | + { |
|
35 | + return 1; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property accordingly. |
|
40 | - * Note: it should not alter the count of items migrated. That is done in the public function that calls this. |
|
41 | - * IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the last migration step, otherwise it |
|
42 | - * should always return $num_items_to_migrate. (Eg, if we're migrating attendees rows from the database, and $num_items_to_migrate is set to 50, |
|
43 | - * then we SHOULD actually migrate 50 rows,but at very least we MUST report/return 50 items migrated) |
|
44 | - * @param int $num_items_to_migrate |
|
45 | - * @return int number of items ACTUALLY migrated |
|
46 | - */ |
|
47 | - protected function _migration_step($num_items_to_migrate = 50) |
|
48 | - { |
|
49 | - global $wpdb; |
|
50 | - $wpdb->delete( |
|
51 | - $wpdb->prefix . 'esp_answer', |
|
52 | - array( 'REG_ID' => 0 ), |
|
53 | - array( '%d' ) |
|
54 | - ); |
|
55 | - $this->set_completed(); |
|
56 | - return 1; |
|
57 | - } |
|
38 | + /** |
|
39 | + * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property accordingly. |
|
40 | + * Note: it should not alter the count of items migrated. That is done in the public function that calls this. |
|
41 | + * IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the last migration step, otherwise it |
|
42 | + * should always return $num_items_to_migrate. (Eg, if we're migrating attendees rows from the database, and $num_items_to_migrate is set to 50, |
|
43 | + * then we SHOULD actually migrate 50 rows,but at very least we MUST report/return 50 items migrated) |
|
44 | + * @param int $num_items_to_migrate |
|
45 | + * @return int number of items ACTUALLY migrated |
|
46 | + */ |
|
47 | + protected function _migration_step($num_items_to_migrate = 50) |
|
48 | + { |
|
49 | + global $wpdb; |
|
50 | + $wpdb->delete( |
|
51 | + $wpdb->prefix . 'esp_answer', |
|
52 | + array( 'REG_ID' => 0 ), |
|
53 | + array( '%d' ) |
|
54 | + ); |
|
55 | + $this->set_completed(); |
|
56 | + return 1; |
|
57 | + } |
|
58 | 58 | } |
@@ -48,9 +48,9 @@ |
||
48 | 48 | { |
49 | 49 | global $wpdb; |
50 | 50 | $wpdb->delete( |
51 | - $wpdb->prefix . 'esp_answer', |
|
52 | - array( 'REG_ID' => 0 ), |
|
53 | - array( '%d' ) |
|
51 | + $wpdb->prefix.'esp_answer', |
|
52 | + array('REG_ID' => 0), |
|
53 | + array('%d') |
|
54 | 54 | ); |
55 | 55 | $this->set_completed(); |
56 | 56 | return 1; |
@@ -14,48 +14,48 @@ |
||
14 | 14 | |
15 | 15 | |
16 | 16 | |
17 | - /** |
|
18 | - * Just initializes the status of the migration |
|
19 | - * |
|
20 | - * @return EE_DMS_4_9_0_Email_System_Question |
|
21 | - */ |
|
22 | - public function __construct() |
|
23 | - { |
|
24 | - global $wpdb; |
|
25 | - $this->_pretty_name = __('Email - System Question', 'event_espresso'); |
|
26 | - $this->_old_table = $wpdb->prefix.'esp_question'; |
|
27 | - $this->_extra_where_sql = "WHERE QST_system = 'email'"; |
|
28 | - parent::__construct(); |
|
29 | - } |
|
17 | + /** |
|
18 | + * Just initializes the status of the migration |
|
19 | + * |
|
20 | + * @return EE_DMS_4_9_0_Email_System_Question |
|
21 | + */ |
|
22 | + public function __construct() |
|
23 | + { |
|
24 | + global $wpdb; |
|
25 | + $this->_pretty_name = __('Email - System Question', 'event_espresso'); |
|
26 | + $this->_old_table = $wpdb->prefix.'esp_question'; |
|
27 | + $this->_extra_where_sql = "WHERE QST_system = 'email'"; |
|
28 | + parent::__construct(); |
|
29 | + } |
|
30 | 30 | |
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * updates the question with the new question type |
|
35 | - * @param array $question an associative array where keys are column names and values are their values. |
|
36 | - * @return null |
|
37 | - */ |
|
38 | - protected function _migrate_old_row($question) |
|
39 | - { |
|
40 | - if ($question['QST_ID'] && $question['QST_system'] == 'email') { |
|
41 | - global $wpdb; |
|
42 | - $success = $wpdb->update( |
|
43 | - $this->_old_table, |
|
44 | - array( 'QST_type' => 'EMAIL' ), // data |
|
45 | - array( 'QST_ID' => $question['QST_ID'] ), // where |
|
46 | - array( '%s' ), // data format |
|
47 | - array( '%d' ) // where format |
|
48 | - ); |
|
49 | - if (! $success) { |
|
50 | - $this->add_error( |
|
51 | - sprintf( |
|
52 | - __('Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso'), |
|
53 | - wp_json_encode($question['QST_system']), |
|
54 | - $question['QST_ID'], |
|
55 | - $wpdb->last_error |
|
56 | - ) |
|
57 | - ); |
|
58 | - } |
|
59 | - } |
|
60 | - } |
|
33 | + /** |
|
34 | + * updates the question with the new question type |
|
35 | + * @param array $question an associative array where keys are column names and values are their values. |
|
36 | + * @return null |
|
37 | + */ |
|
38 | + protected function _migrate_old_row($question) |
|
39 | + { |
|
40 | + if ($question['QST_ID'] && $question['QST_system'] == 'email') { |
|
41 | + global $wpdb; |
|
42 | + $success = $wpdb->update( |
|
43 | + $this->_old_table, |
|
44 | + array( 'QST_type' => 'EMAIL' ), // data |
|
45 | + array( 'QST_ID' => $question['QST_ID'] ), // where |
|
46 | + array( '%s' ), // data format |
|
47 | + array( '%d' ) // where format |
|
48 | + ); |
|
49 | + if (! $success) { |
|
50 | + $this->add_error( |
|
51 | + sprintf( |
|
52 | + __('Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso'), |
|
53 | + wp_json_encode($question['QST_system']), |
|
54 | + $question['QST_ID'], |
|
55 | + $wpdb->last_error |
|
56 | + ) |
|
57 | + ); |
|
58 | + } |
|
59 | + } |
|
60 | + } |
|
61 | 61 | } |
@@ -41,12 +41,12 @@ |
||
41 | 41 | global $wpdb; |
42 | 42 | $success = $wpdb->update( |
43 | 43 | $this->_old_table, |
44 | - array( 'QST_type' => 'EMAIL' ), // data |
|
45 | - array( 'QST_ID' => $question['QST_ID'] ), // where |
|
46 | - array( '%s' ), // data format |
|
47 | - array( '%d' ) // where format |
|
44 | + array('QST_type' => 'EMAIL'), // data |
|
45 | + array('QST_ID' => $question['QST_ID']), // where |
|
46 | + array('%s'), // data format |
|
47 | + array('%d') // where format |
|
48 | 48 | ); |
49 | - if (! $success) { |
|
49 | + if ( ! $success) { |
|
50 | 50 | $this->add_error( |
51 | 51 | sprintf( |
52 | 52 | __('Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso'), |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | */ |
186 | 186 | public function add_error($error, $force = false) |
187 | 187 | { |
188 | - if (! defined('EE_DMS_ERROR_LIMIT')) { |
|
188 | + if ( ! defined('EE_DMS_ERROR_LIMIT')) { |
|
189 | 189 | $limit = 50; |
190 | 190 | } else { |
191 | 191 | $limit = EE_DMS_ERROR_LIMIT; |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | $this->_errors[] = "Limit reached; removed first half of errors to save space"; |
202 | 202 | $this->_errors[] = $error; |
203 | 203 | } else { |
204 | - $this->_errors[ $limit ] = 'More, but limit reached...'; |
|
204 | + $this->_errors[$limit] = 'More, but limit reached...'; |
|
205 | 205 | } |
206 | 206 | } else { |
207 | 207 | $this->_errors[] = $error; |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | $new_columns_and_values_for_string = array(); |
344 | 344 | $count = 0; |
345 | 345 | foreach ($new_row_as_array as $column => $value) { |
346 | - $new_columns_and_values_for_string[] = " $column => $value (" . $data_types[ $count++ ] . ")"; |
|
346 | + $new_columns_and_values_for_string[] = " $column => $value (".$data_types[$count++].")"; |
|
347 | 347 | } |
348 | 348 | return sprintf( |
349 | 349 | __( |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | foreach ($array_of_data as $name => $value) { |
375 | 375 | $unserialized_data = @unserialize($value); |
376 | 376 | if ($unserialized_data === false) { |
377 | - $fields_to_include[ $name ] = $value; |
|
377 | + $fields_to_include[$name] = $value; |
|
378 | 378 | } |
379 | 379 | } |
380 | 380 | return wp_json_encode($fields_to_include); |
@@ -17,408 +17,408 @@ |
||
17 | 17 | abstract class EE_Data_Migration_Class_Base |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var $records_to_migrate int count of all that have been migrated |
|
22 | - */ |
|
23 | - protected $_records_to_migrate = 0; |
|
24 | - |
|
25 | - /** |
|
26 | - * |
|
27 | - * @var $records_migrated int |
|
28 | - */ |
|
29 | - protected $_records_migrated = 0; |
|
30 | - |
|
31 | - /** |
|
32 | - * Whether this migration script is done or not. This COULD be deduced by |
|
33 | - * _records_to_migrate and _records_migrated, but that might nto be accurate |
|
34 | - * |
|
35 | - * @var string one of EE_Data_migration_Manager::status_* constants |
|
36 | - */ |
|
37 | - protected $_status = null; |
|
38 | - |
|
39 | - /** |
|
40 | - * internationalized name of this class. Convention is to NOT restate that |
|
41 | - * this class if a migration script or a migration script stage |
|
42 | - * |
|
43 | - * @var string (i18ned) |
|
44 | - */ |
|
45 | - protected $_pretty_name = null; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var array |
|
49 | - */ |
|
50 | - protected $_errors = array(); |
|
51 | - |
|
52 | - /** |
|
53 | - * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
54 | - */ |
|
55 | - protected $_table_manager; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
59 | - */ |
|
60 | - protected $_table_analysis; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * Just initializes the status of the migration |
|
65 | - * |
|
66 | - * @param TableManager $table_manager |
|
67 | - * @param TableAnalysis $table_analysis |
|
68 | - */ |
|
69 | - public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
70 | - { |
|
71 | - $this->_table_manager = $table_manager; |
|
72 | - $this->_table_analysis = $table_analysis; |
|
73 | - $this->set_status(EE_Data_Migration_Manager::status_continue); |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * Just gets the pretty name for this migration script or stage |
|
79 | - * |
|
80 | - * @throws EE_Error |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public function pretty_name() |
|
84 | - { |
|
85 | - if ($this->_pretty_name === null) { |
|
86 | - throw new EE_Error( |
|
87 | - sprintf( |
|
88 | - __( |
|
89 | - "Please give a pretty name to the migration script stage %s by assigning the property _pretty_name in the constructor", |
|
90 | - "event_espresso" |
|
91 | - ), |
|
92 | - get_class($this) |
|
93 | - ) |
|
94 | - ); |
|
95 | - } |
|
96 | - return $this->_pretty_name; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * |
|
101 | - * @return int |
|
102 | - */ |
|
103 | - public function count_records_to_migrate() |
|
104 | - { |
|
105 | - if ($this->_records_to_migrate == null) { |
|
106 | - $this->_records_to_migrate = $this->_count_records_to_migrate(); |
|
107 | - } |
|
108 | - return $this->_records_to_migrate; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Counts records already migrated. This should only be implemented by EE_Data_Migration_Script_base and |
|
113 | - * EE_Data_migration_Script_Stage |
|
114 | - * |
|
115 | - * @return int |
|
116 | - */ |
|
117 | - abstract public function count_records_migrated(); |
|
118 | - |
|
119 | - /** |
|
120 | - * Counts the records to migrate; the public version may cache it |
|
121 | - * |
|
122 | - * @return int |
|
123 | - */ |
|
124 | - abstract protected function _count_records_to_migrate(); |
|
125 | - |
|
126 | - /** |
|
127 | - * Returns a string indicating the migration script's status. |
|
128 | - * |
|
129 | - * @return string one of EE_Data_Migration_Manager::status_* constants |
|
130 | - * @throws EE_Error |
|
131 | - */ |
|
132 | - public function get_status() |
|
133 | - { |
|
134 | - if ($this->_status === null) { |
|
135 | - throw new EE_Error( |
|
136 | - sprintf( |
|
137 | - __( |
|
138 | - "Trying to get status of Migration class %s, but it has not been initialized yet. It should be set in the constructor.", |
|
139 | - "event_espresso" |
|
140 | - ), |
|
141 | - get_class($this) |
|
142 | - ) |
|
143 | - ); |
|
144 | - } |
|
145 | - return $this->_status; |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * |
|
150 | - * @param string $status |
|
151 | - * @return void |
|
152 | - */ |
|
153 | - protected function set_status($status) |
|
154 | - { |
|
155 | - $this->_status = $status; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @return array of strings |
|
160 | - */ |
|
161 | - abstract public function get_errors(); |
|
162 | - |
|
163 | - /** |
|
164 | - * Returns the last error that occurred. If none occurred, returns null |
|
165 | - * |
|
166 | - * @return string |
|
167 | - */ |
|
168 | - public function get_last_error() |
|
169 | - { |
|
170 | - $errors = $this->get_errors(); |
|
171 | - if ($errors) { |
|
172 | - return end($errors); |
|
173 | - } else { |
|
174 | - return null; |
|
175 | - } |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Adds an error to the array of errors on this class. |
|
180 | - * |
|
181 | - * @param string $error a string describing the error that will be useful for debugging. Consider including all |
|
182 | - * the data that led to the error, and a stack trace etc. |
|
183 | - * @param boolean $force force the error to be added (because otherwise we have a limit). If forcing and errors are |
|
184 | - * already at their limit, we will purposefully forget the first half |
|
185 | - */ |
|
186 | - public function add_error($error, $force = false) |
|
187 | - { |
|
188 | - if (! defined('EE_DMS_ERROR_LIMIT')) { |
|
189 | - $limit = 50; |
|
190 | - } else { |
|
191 | - $limit = EE_DMS_ERROR_LIMIT; |
|
192 | - } |
|
193 | - // make sure errors is an array, see ticket #8261 |
|
194 | - if (is_string($this->_errors)) { |
|
195 | - $this->_errors = array($this->_errors); |
|
196 | - } |
|
197 | - if (count($this->_errors) >= $limit) { |
|
198 | - if ($force) { |
|
199 | - // get rid of the first half of the errors and any above the limit |
|
200 | - $this->_errors = array_slice($this->_errors, $limit / 2, $limit / 2); |
|
201 | - $this->_errors[] = "Limit reached; removed first half of errors to save space"; |
|
202 | - $this->_errors[] = $error; |
|
203 | - } else { |
|
204 | - $this->_errors[ $limit ] = 'More, but limit reached...'; |
|
205 | - } |
|
206 | - } else { |
|
207 | - $this->_errors[] = $error; |
|
208 | - } |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * Indicates there was a fatal error and the migration cannot possibly continue |
|
213 | - * |
|
214 | - * @return boolean |
|
215 | - */ |
|
216 | - public function is_broken() |
|
217 | - { |
|
218 | - return $this->get_status() == EE_Data_Migration_Manager::status_fatal_error; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * @deprecated since 4.6.12 |
|
223 | - */ |
|
224 | - public function is_borked() |
|
225 | - { |
|
226 | - EE_Error::doing_it_wrong( |
|
227 | - 'is_borked', |
|
228 | - __( |
|
229 | - 'The cheeky "is_borked" method had been replaced with the more proper "is_broken"', |
|
230 | - 'event_espresso' |
|
231 | - ), |
|
232 | - '4.6.12' |
|
233 | - ); |
|
234 | - return $this->is_broken(); |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * Sets the status to as having a fatal error |
|
239 | - */ |
|
240 | - public function set_broken() |
|
241 | - { |
|
242 | - $this->_status = EE_Data_Migration_Manager::status_fatal_error; |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * |
|
247 | - * @deprecated since 4.6.12 |
|
248 | - */ |
|
249 | - public function set_borked() |
|
250 | - { |
|
251 | - EE_Error::doing_it_wrong( |
|
252 | - 'is_borked', |
|
253 | - __( |
|
254 | - 'The cheeky "is_borked" method had been replaced with the more proper "is_broken"', |
|
255 | - 'event_espresso' |
|
256 | - ), |
|
257 | - '4.6.12' |
|
258 | - ); |
|
259 | - return $this->set_broken(); |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Checks if this thing believes it is completed |
|
264 | - * |
|
265 | - * @return boolean |
|
266 | - */ |
|
267 | - public function is_completed() |
|
268 | - { |
|
269 | - return $this->get_status() == EE_Data_Migration_Manager::status_completed; |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Checks if the current script has more to do or not (ie, if it's status is CONTINUE) |
|
274 | - * |
|
275 | - * @return boolean |
|
276 | - */ |
|
277 | - public function has_more_to_do() |
|
278 | - { |
|
279 | - return $this->get_status() == EE_Data_Migration_Manager::status_continue; |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * Marks that we believe this migration thing is completed |
|
284 | - */ |
|
285 | - public function set_completed() |
|
286 | - { |
|
287 | - $this->_status = EE_Data_Migration_Manager::status_completed; |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Marks that we think this migration class can continue to migrate |
|
292 | - */ |
|
293 | - public function reattempt() |
|
294 | - { |
|
295 | - $this->_status = EE_Data_Migration_Manager::status_continue; |
|
296 | - $this->add_error(__('Reattempt migration', 'event_espresso'), true); |
|
297 | - } |
|
298 | - |
|
299 | - /** |
|
300 | - * A lot like "__sleep()" magic method in purpose, this is meant for persisting this class' |
|
301 | - * properties to the DB. However, we don't want to use __sleep() because its quite |
|
302 | - * possible that this class is defined when it goes to sleep, but NOT available when it |
|
303 | - * awakes (eg, this class is part of an addon that is deactivated at some point). |
|
304 | - */ |
|
305 | - public function properties_as_array() |
|
306 | - { |
|
307 | - $properties = get_object_vars($this); |
|
308 | - $properties['class'] = get_class($this); |
|
309 | - unset($properties['_migration_script']); |
|
310 | - unset($properties['_table_manager']); |
|
311 | - unset($properties['_table_analysis']); |
|
312 | - return $properties; |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * Sets all of the properties of this script stage to match what's in the array, which is assumed |
|
317 | - * to have been made from the properties_as_array() function. |
|
318 | - * |
|
319 | - * @param array $array_of_properties like what's produced from properties_as_array() method |
|
320 | - */ |
|
321 | - abstract public function instantiate_from_array_of_properties($array_of_properties); |
|
322 | - |
|
323 | - /** |
|
324 | - * Convenience method for showing a database insertion error |
|
325 | - * |
|
326 | - * @param string $old_table |
|
327 | - * @param array $old_row_as_array |
|
328 | - * @param string $new_table |
|
329 | - * @param array $new_row_as_array columns=>values like used in wpdb->insert |
|
330 | - * @param array $data_types numerically indexed |
|
331 | - * @return string |
|
332 | - */ |
|
333 | - protected function _create_error_message_for_db_insertion( |
|
334 | - $old_table, |
|
335 | - $old_row_as_array, |
|
336 | - $new_table, |
|
337 | - $new_row_as_array, |
|
338 | - $data_types |
|
339 | - ) { |
|
340 | - global $wpdb; |
|
341 | - $old_columns_and_values_for_string = array(); |
|
342 | - foreach ($old_row_as_array as $column => $value) { |
|
343 | - $old_columns_and_values_for_string[] = "$column => $value"; |
|
344 | - } |
|
345 | - $new_columns_and_values_for_string = array(); |
|
346 | - $count = 0; |
|
347 | - foreach ($new_row_as_array as $column => $value) { |
|
348 | - $new_columns_and_values_for_string[] = " $column => $value (" . $data_types[ $count++ ] . ")"; |
|
349 | - } |
|
350 | - return sprintf( |
|
351 | - __( |
|
352 | - 'Received error "%6$s" inserting row %5$s %1$s %5$s into table %2$s.%5$s Data used was %5$s %3$s %5$s from table %4$s.', |
|
353 | - 'event_espresso' |
|
354 | - ), |
|
355 | - implode(", ", $new_columns_and_values_for_string), |
|
356 | - $new_table, |
|
357 | - implode(", ", $old_columns_and_values_for_string), |
|
358 | - $old_table, |
|
359 | - '<br/>', |
|
360 | - $wpdb->last_error |
|
361 | - ); |
|
362 | - } |
|
363 | - |
|
364 | - |
|
365 | - /** |
|
366 | - * Same as json_encode, just avoids putting |
|
367 | - * serialized arrays into the http build query, as that would |
|
368 | - * |
|
369 | - * @param array $array_of_data |
|
370 | - * @return string |
|
371 | - */ |
|
372 | - protected function _json_encode($array_of_data) |
|
373 | - { |
|
374 | - // we'd rather NOT serialize the transaction details |
|
375 | - $fields_to_include = array(); |
|
376 | - foreach ($array_of_data as $name => $value) { |
|
377 | - $unserialized_data = @unserialize($value); |
|
378 | - if ($unserialized_data === false) { |
|
379 | - $fields_to_include[ $name ] = $value; |
|
380 | - } |
|
381 | - } |
|
382 | - return wp_json_encode($fields_to_include); |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * Gets the table manager (or throws an exception if it cannot be retrieved) |
|
387 | - * |
|
388 | - * @return TableManager |
|
389 | - * @throws EE_Error |
|
390 | - */ |
|
391 | - protected function _get_table_manager() |
|
392 | - { |
|
393 | - if ($this->_table_manager instanceof TableManager) { |
|
394 | - return $this->_table_manager; |
|
395 | - } else { |
|
396 | - throw new EE_Error( |
|
397 | - sprintf( |
|
398 | - __('Table manager on migration class %1$s is not set properly.', 'event_espresso'), |
|
399 | - get_class($this) |
|
400 | - ) |
|
401 | - ); |
|
402 | - } |
|
403 | - } |
|
404 | - |
|
405 | - /** |
|
406 | - * Gets the injected table analyzer, or throws an exception |
|
407 | - * |
|
408 | - * @return TableAnalysis |
|
409 | - * @throws EE_Error |
|
410 | - */ |
|
411 | - protected function _get_table_analysis() |
|
412 | - { |
|
413 | - if ($this->_table_analysis instanceof TableAnalysis) { |
|
414 | - return $this->_table_analysis; |
|
415 | - } else { |
|
416 | - throw new EE_Error( |
|
417 | - sprintf( |
|
418 | - __('Table analysis class on migration class %1$s is not set properly.', 'event_espresso'), |
|
419 | - get_class($this) |
|
420 | - ) |
|
421 | - ); |
|
422 | - } |
|
423 | - } |
|
20 | + /** |
|
21 | + * @var $records_to_migrate int count of all that have been migrated |
|
22 | + */ |
|
23 | + protected $_records_to_migrate = 0; |
|
24 | + |
|
25 | + /** |
|
26 | + * |
|
27 | + * @var $records_migrated int |
|
28 | + */ |
|
29 | + protected $_records_migrated = 0; |
|
30 | + |
|
31 | + /** |
|
32 | + * Whether this migration script is done or not. This COULD be deduced by |
|
33 | + * _records_to_migrate and _records_migrated, but that might nto be accurate |
|
34 | + * |
|
35 | + * @var string one of EE_Data_migration_Manager::status_* constants |
|
36 | + */ |
|
37 | + protected $_status = null; |
|
38 | + |
|
39 | + /** |
|
40 | + * internationalized name of this class. Convention is to NOT restate that |
|
41 | + * this class if a migration script or a migration script stage |
|
42 | + * |
|
43 | + * @var string (i18ned) |
|
44 | + */ |
|
45 | + protected $_pretty_name = null; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var array |
|
49 | + */ |
|
50 | + protected $_errors = array(); |
|
51 | + |
|
52 | + /** |
|
53 | + * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
54 | + */ |
|
55 | + protected $_table_manager; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
59 | + */ |
|
60 | + protected $_table_analysis; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * Just initializes the status of the migration |
|
65 | + * |
|
66 | + * @param TableManager $table_manager |
|
67 | + * @param TableAnalysis $table_analysis |
|
68 | + */ |
|
69 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
70 | + { |
|
71 | + $this->_table_manager = $table_manager; |
|
72 | + $this->_table_analysis = $table_analysis; |
|
73 | + $this->set_status(EE_Data_Migration_Manager::status_continue); |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * Just gets the pretty name for this migration script or stage |
|
79 | + * |
|
80 | + * @throws EE_Error |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public function pretty_name() |
|
84 | + { |
|
85 | + if ($this->_pretty_name === null) { |
|
86 | + throw new EE_Error( |
|
87 | + sprintf( |
|
88 | + __( |
|
89 | + "Please give a pretty name to the migration script stage %s by assigning the property _pretty_name in the constructor", |
|
90 | + "event_espresso" |
|
91 | + ), |
|
92 | + get_class($this) |
|
93 | + ) |
|
94 | + ); |
|
95 | + } |
|
96 | + return $this->_pretty_name; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * |
|
101 | + * @return int |
|
102 | + */ |
|
103 | + public function count_records_to_migrate() |
|
104 | + { |
|
105 | + if ($this->_records_to_migrate == null) { |
|
106 | + $this->_records_to_migrate = $this->_count_records_to_migrate(); |
|
107 | + } |
|
108 | + return $this->_records_to_migrate; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Counts records already migrated. This should only be implemented by EE_Data_Migration_Script_base and |
|
113 | + * EE_Data_migration_Script_Stage |
|
114 | + * |
|
115 | + * @return int |
|
116 | + */ |
|
117 | + abstract public function count_records_migrated(); |
|
118 | + |
|
119 | + /** |
|
120 | + * Counts the records to migrate; the public version may cache it |
|
121 | + * |
|
122 | + * @return int |
|
123 | + */ |
|
124 | + abstract protected function _count_records_to_migrate(); |
|
125 | + |
|
126 | + /** |
|
127 | + * Returns a string indicating the migration script's status. |
|
128 | + * |
|
129 | + * @return string one of EE_Data_Migration_Manager::status_* constants |
|
130 | + * @throws EE_Error |
|
131 | + */ |
|
132 | + public function get_status() |
|
133 | + { |
|
134 | + if ($this->_status === null) { |
|
135 | + throw new EE_Error( |
|
136 | + sprintf( |
|
137 | + __( |
|
138 | + "Trying to get status of Migration class %s, but it has not been initialized yet. It should be set in the constructor.", |
|
139 | + "event_espresso" |
|
140 | + ), |
|
141 | + get_class($this) |
|
142 | + ) |
|
143 | + ); |
|
144 | + } |
|
145 | + return $this->_status; |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * |
|
150 | + * @param string $status |
|
151 | + * @return void |
|
152 | + */ |
|
153 | + protected function set_status($status) |
|
154 | + { |
|
155 | + $this->_status = $status; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @return array of strings |
|
160 | + */ |
|
161 | + abstract public function get_errors(); |
|
162 | + |
|
163 | + /** |
|
164 | + * Returns the last error that occurred. If none occurred, returns null |
|
165 | + * |
|
166 | + * @return string |
|
167 | + */ |
|
168 | + public function get_last_error() |
|
169 | + { |
|
170 | + $errors = $this->get_errors(); |
|
171 | + if ($errors) { |
|
172 | + return end($errors); |
|
173 | + } else { |
|
174 | + return null; |
|
175 | + } |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Adds an error to the array of errors on this class. |
|
180 | + * |
|
181 | + * @param string $error a string describing the error that will be useful for debugging. Consider including all |
|
182 | + * the data that led to the error, and a stack trace etc. |
|
183 | + * @param boolean $force force the error to be added (because otherwise we have a limit). If forcing and errors are |
|
184 | + * already at their limit, we will purposefully forget the first half |
|
185 | + */ |
|
186 | + public function add_error($error, $force = false) |
|
187 | + { |
|
188 | + if (! defined('EE_DMS_ERROR_LIMIT')) { |
|
189 | + $limit = 50; |
|
190 | + } else { |
|
191 | + $limit = EE_DMS_ERROR_LIMIT; |
|
192 | + } |
|
193 | + // make sure errors is an array, see ticket #8261 |
|
194 | + if (is_string($this->_errors)) { |
|
195 | + $this->_errors = array($this->_errors); |
|
196 | + } |
|
197 | + if (count($this->_errors) >= $limit) { |
|
198 | + if ($force) { |
|
199 | + // get rid of the first half of the errors and any above the limit |
|
200 | + $this->_errors = array_slice($this->_errors, $limit / 2, $limit / 2); |
|
201 | + $this->_errors[] = "Limit reached; removed first half of errors to save space"; |
|
202 | + $this->_errors[] = $error; |
|
203 | + } else { |
|
204 | + $this->_errors[ $limit ] = 'More, but limit reached...'; |
|
205 | + } |
|
206 | + } else { |
|
207 | + $this->_errors[] = $error; |
|
208 | + } |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * Indicates there was a fatal error and the migration cannot possibly continue |
|
213 | + * |
|
214 | + * @return boolean |
|
215 | + */ |
|
216 | + public function is_broken() |
|
217 | + { |
|
218 | + return $this->get_status() == EE_Data_Migration_Manager::status_fatal_error; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * @deprecated since 4.6.12 |
|
223 | + */ |
|
224 | + public function is_borked() |
|
225 | + { |
|
226 | + EE_Error::doing_it_wrong( |
|
227 | + 'is_borked', |
|
228 | + __( |
|
229 | + 'The cheeky "is_borked" method had been replaced with the more proper "is_broken"', |
|
230 | + 'event_espresso' |
|
231 | + ), |
|
232 | + '4.6.12' |
|
233 | + ); |
|
234 | + return $this->is_broken(); |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Sets the status to as having a fatal error |
|
239 | + */ |
|
240 | + public function set_broken() |
|
241 | + { |
|
242 | + $this->_status = EE_Data_Migration_Manager::status_fatal_error; |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * |
|
247 | + * @deprecated since 4.6.12 |
|
248 | + */ |
|
249 | + public function set_borked() |
|
250 | + { |
|
251 | + EE_Error::doing_it_wrong( |
|
252 | + 'is_borked', |
|
253 | + __( |
|
254 | + 'The cheeky "is_borked" method had been replaced with the more proper "is_broken"', |
|
255 | + 'event_espresso' |
|
256 | + ), |
|
257 | + '4.6.12' |
|
258 | + ); |
|
259 | + return $this->set_broken(); |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Checks if this thing believes it is completed |
|
264 | + * |
|
265 | + * @return boolean |
|
266 | + */ |
|
267 | + public function is_completed() |
|
268 | + { |
|
269 | + return $this->get_status() == EE_Data_Migration_Manager::status_completed; |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Checks if the current script has more to do or not (ie, if it's status is CONTINUE) |
|
274 | + * |
|
275 | + * @return boolean |
|
276 | + */ |
|
277 | + public function has_more_to_do() |
|
278 | + { |
|
279 | + return $this->get_status() == EE_Data_Migration_Manager::status_continue; |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * Marks that we believe this migration thing is completed |
|
284 | + */ |
|
285 | + public function set_completed() |
|
286 | + { |
|
287 | + $this->_status = EE_Data_Migration_Manager::status_completed; |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Marks that we think this migration class can continue to migrate |
|
292 | + */ |
|
293 | + public function reattempt() |
|
294 | + { |
|
295 | + $this->_status = EE_Data_Migration_Manager::status_continue; |
|
296 | + $this->add_error(__('Reattempt migration', 'event_espresso'), true); |
|
297 | + } |
|
298 | + |
|
299 | + /** |
|
300 | + * A lot like "__sleep()" magic method in purpose, this is meant for persisting this class' |
|
301 | + * properties to the DB. However, we don't want to use __sleep() because its quite |
|
302 | + * possible that this class is defined when it goes to sleep, but NOT available when it |
|
303 | + * awakes (eg, this class is part of an addon that is deactivated at some point). |
|
304 | + */ |
|
305 | + public function properties_as_array() |
|
306 | + { |
|
307 | + $properties = get_object_vars($this); |
|
308 | + $properties['class'] = get_class($this); |
|
309 | + unset($properties['_migration_script']); |
|
310 | + unset($properties['_table_manager']); |
|
311 | + unset($properties['_table_analysis']); |
|
312 | + return $properties; |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * Sets all of the properties of this script stage to match what's in the array, which is assumed |
|
317 | + * to have been made from the properties_as_array() function. |
|
318 | + * |
|
319 | + * @param array $array_of_properties like what's produced from properties_as_array() method |
|
320 | + */ |
|
321 | + abstract public function instantiate_from_array_of_properties($array_of_properties); |
|
322 | + |
|
323 | + /** |
|
324 | + * Convenience method for showing a database insertion error |
|
325 | + * |
|
326 | + * @param string $old_table |
|
327 | + * @param array $old_row_as_array |
|
328 | + * @param string $new_table |
|
329 | + * @param array $new_row_as_array columns=>values like used in wpdb->insert |
|
330 | + * @param array $data_types numerically indexed |
|
331 | + * @return string |
|
332 | + */ |
|
333 | + protected function _create_error_message_for_db_insertion( |
|
334 | + $old_table, |
|
335 | + $old_row_as_array, |
|
336 | + $new_table, |
|
337 | + $new_row_as_array, |
|
338 | + $data_types |
|
339 | + ) { |
|
340 | + global $wpdb; |
|
341 | + $old_columns_and_values_for_string = array(); |
|
342 | + foreach ($old_row_as_array as $column => $value) { |
|
343 | + $old_columns_and_values_for_string[] = "$column => $value"; |
|
344 | + } |
|
345 | + $new_columns_and_values_for_string = array(); |
|
346 | + $count = 0; |
|
347 | + foreach ($new_row_as_array as $column => $value) { |
|
348 | + $new_columns_and_values_for_string[] = " $column => $value (" . $data_types[ $count++ ] . ")"; |
|
349 | + } |
|
350 | + return sprintf( |
|
351 | + __( |
|
352 | + 'Received error "%6$s" inserting row %5$s %1$s %5$s into table %2$s.%5$s Data used was %5$s %3$s %5$s from table %4$s.', |
|
353 | + 'event_espresso' |
|
354 | + ), |
|
355 | + implode(", ", $new_columns_and_values_for_string), |
|
356 | + $new_table, |
|
357 | + implode(", ", $old_columns_and_values_for_string), |
|
358 | + $old_table, |
|
359 | + '<br/>', |
|
360 | + $wpdb->last_error |
|
361 | + ); |
|
362 | + } |
|
363 | + |
|
364 | + |
|
365 | + /** |
|
366 | + * Same as json_encode, just avoids putting |
|
367 | + * serialized arrays into the http build query, as that would |
|
368 | + * |
|
369 | + * @param array $array_of_data |
|
370 | + * @return string |
|
371 | + */ |
|
372 | + protected function _json_encode($array_of_data) |
|
373 | + { |
|
374 | + // we'd rather NOT serialize the transaction details |
|
375 | + $fields_to_include = array(); |
|
376 | + foreach ($array_of_data as $name => $value) { |
|
377 | + $unserialized_data = @unserialize($value); |
|
378 | + if ($unserialized_data === false) { |
|
379 | + $fields_to_include[ $name ] = $value; |
|
380 | + } |
|
381 | + } |
|
382 | + return wp_json_encode($fields_to_include); |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * Gets the table manager (or throws an exception if it cannot be retrieved) |
|
387 | + * |
|
388 | + * @return TableManager |
|
389 | + * @throws EE_Error |
|
390 | + */ |
|
391 | + protected function _get_table_manager() |
|
392 | + { |
|
393 | + if ($this->_table_manager instanceof TableManager) { |
|
394 | + return $this->_table_manager; |
|
395 | + } else { |
|
396 | + throw new EE_Error( |
|
397 | + sprintf( |
|
398 | + __('Table manager on migration class %1$s is not set properly.', 'event_espresso'), |
|
399 | + get_class($this) |
|
400 | + ) |
|
401 | + ); |
|
402 | + } |
|
403 | + } |
|
404 | + |
|
405 | + /** |
|
406 | + * Gets the injected table analyzer, or throws an exception |
|
407 | + * |
|
408 | + * @return TableAnalysis |
|
409 | + * @throws EE_Error |
|
410 | + */ |
|
411 | + protected function _get_table_analysis() |
|
412 | + { |
|
413 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
414 | + return $this->_table_analysis; |
|
415 | + } else { |
|
416 | + throw new EE_Error( |
|
417 | + sprintf( |
|
418 | + __('Table analysis class on migration class %1$s is not set properly.', 'event_espresso'), |
|
419 | + get_class($this) |
|
420 | + ) |
|
421 | + ); |
|
422 | + } |
|
423 | + } |
|
424 | 424 | } |
@@ -8,53 +8,53 @@ |
||
8 | 8 | */ |
9 | 9 | class EE_DMS_4_1_0_category_details extends EE_Data_Migration_Script_Stage |
10 | 10 | { |
11 | - private $_old_table; |
|
12 | - private $_new_table; |
|
13 | - private $_new_term_table; |
|
14 | - public function _migration_step($num_items = 50) |
|
15 | - { |
|
16 | - global $wpdb; |
|
17 | - $start_at_record = $this->count_records_migrated(); |
|
18 | - $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A); |
|
19 | - $items_actually_migrated = 0; |
|
20 | - foreach ($rows as $category_detail_row) { |
|
21 | - $term_and_taxonomy_ids = wp_insert_term( |
|
22 | - stripslashes($category_detail_row['category_name']), |
|
23 | - 'espresso_event_categories', |
|
24 | - array( |
|
25 | - 'description'=> stripslashes($category_detail_row['category_desc']), |
|
26 | - 'slug'=>$category_detail_row['category_identifier'] |
|
27 | - ) |
|
28 | - ); |
|
29 | - if ($term_and_taxonomy_ids instanceof WP_Error) { |
|
30 | - $this->add_error(sprintf(__("Could not create WP Term_Taxonomy from old category: %s. The Error was: %s", "event_espresso"), $this->_json_encode($category_detail_row), $term_and_taxonomy_ids->get_error_message())); |
|
31 | - $items_actually_migrated++; |
|
32 | - continue; |
|
33 | - } |
|
34 | - $term_id = $term_and_taxonomy_ids['term_id']; |
|
35 | - $term_taxonomy_id = $term_and_taxonomy_ids['term_taxonomy_id']; |
|
36 | - $this->get_migration_script()->set_mapping($this->_old_table, $category_detail_row['id'], $this->_new_term_table, $term_id); |
|
37 | - $this->get_migration_script()->set_mapping($this->_old_table, $category_detail_row['id'], $this->_new_table, $term_taxonomy_id); |
|
38 | - $items_actually_migrated++; |
|
39 | - } |
|
40 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
41 | - $this->set_completed(); |
|
42 | - } |
|
43 | - return $items_actually_migrated; |
|
44 | - } |
|
45 | - public function _count_records_to_migrate() |
|
46 | - { |
|
47 | - global $wpdb; |
|
48 | - $count = $wpdb->get_var("SELECT COUNT(id) FROM $this->_old_table"); |
|
49 | - return $count; |
|
50 | - } |
|
51 | - public function __construct() |
|
52 | - { |
|
53 | - $this->_pretty_name = __("Category Details", "event_espresso"); |
|
54 | - global $wpdb; |
|
55 | - $this->_old_table = $wpdb->prefix."events_category_detail"; |
|
56 | - $this->_new_table = $wpdb->prefix."term_taxonomy"; |
|
57 | - $this->_new_term_table = $wpdb->prefix."terms"; |
|
58 | - parent::__construct(); |
|
59 | - } |
|
11 | + private $_old_table; |
|
12 | + private $_new_table; |
|
13 | + private $_new_term_table; |
|
14 | + public function _migration_step($num_items = 50) |
|
15 | + { |
|
16 | + global $wpdb; |
|
17 | + $start_at_record = $this->count_records_migrated(); |
|
18 | + $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A); |
|
19 | + $items_actually_migrated = 0; |
|
20 | + foreach ($rows as $category_detail_row) { |
|
21 | + $term_and_taxonomy_ids = wp_insert_term( |
|
22 | + stripslashes($category_detail_row['category_name']), |
|
23 | + 'espresso_event_categories', |
|
24 | + array( |
|
25 | + 'description'=> stripslashes($category_detail_row['category_desc']), |
|
26 | + 'slug'=>$category_detail_row['category_identifier'] |
|
27 | + ) |
|
28 | + ); |
|
29 | + if ($term_and_taxonomy_ids instanceof WP_Error) { |
|
30 | + $this->add_error(sprintf(__("Could not create WP Term_Taxonomy from old category: %s. The Error was: %s", "event_espresso"), $this->_json_encode($category_detail_row), $term_and_taxonomy_ids->get_error_message())); |
|
31 | + $items_actually_migrated++; |
|
32 | + continue; |
|
33 | + } |
|
34 | + $term_id = $term_and_taxonomy_ids['term_id']; |
|
35 | + $term_taxonomy_id = $term_and_taxonomy_ids['term_taxonomy_id']; |
|
36 | + $this->get_migration_script()->set_mapping($this->_old_table, $category_detail_row['id'], $this->_new_term_table, $term_id); |
|
37 | + $this->get_migration_script()->set_mapping($this->_old_table, $category_detail_row['id'], $this->_new_table, $term_taxonomy_id); |
|
38 | + $items_actually_migrated++; |
|
39 | + } |
|
40 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
41 | + $this->set_completed(); |
|
42 | + } |
|
43 | + return $items_actually_migrated; |
|
44 | + } |
|
45 | + public function _count_records_to_migrate() |
|
46 | + { |
|
47 | + global $wpdb; |
|
48 | + $count = $wpdb->get_var("SELECT COUNT(id) FROM $this->_old_table"); |
|
49 | + return $count; |
|
50 | + } |
|
51 | + public function __construct() |
|
52 | + { |
|
53 | + $this->_pretty_name = __("Category Details", "event_espresso"); |
|
54 | + global $wpdb; |
|
55 | + $this->_old_table = $wpdb->prefix."events_category_detail"; |
|
56 | + $this->_new_table = $wpdb->prefix."term_taxonomy"; |
|
57 | + $this->_new_term_table = $wpdb->prefix."terms"; |
|
58 | + parent::__construct(); |
|
59 | + } |
|
60 | 60 | } |
@@ -24,87 +24,85 @@ |
||
24 | 24 | 'term_taxonomy_id'=>new EE_Foreign_Key_Int_Field('term_taxonomy_id', __('Term (in context of a taxonomy) ID','event_espresso'), false, 0, 'Term_Taxonomy'), |
25 | 25 | 'term_order'=>new EE_Integer_Field('term_order', __('Term Order','event_espresso'), false, 0) |
26 | 26 | )); |
27 | - |
|
28 | - |
|
29 | 27 | * |
30 | 28 | */ |
31 | 29 | class EE_DMS_4_1_0_event_category extends EE_Data_Migration_Script_Stage |
32 | 30 | { |
33 | - private $_old_table; |
|
34 | - private $_new_table; |
|
35 | - public function _migration_step($num_items = 50) |
|
36 | - { |
|
37 | - global $wpdb; |
|
38 | - $start_at_record = $this->count_records_migrated(); |
|
39 | - $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A); |
|
40 | - $items_actually_migrated = 0; |
|
41 | - foreach ($rows as $event_venue_rel) { |
|
42 | - $term_relation_id = $this->_add_relation_from_event_to_term_taxonomy($event_venue_rel); |
|
43 | - if ($term_relation_id) { |
|
44 | - $this->get_migration_script()->set_mapping($this->_old_table, $event_venue_rel['id'], $this->_new_table, $term_relation_id); |
|
45 | - } |
|
46 | - $items_actually_migrated++; |
|
47 | - } |
|
48 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
49 | - $this->set_completed(); |
|
50 | - } |
|
51 | - return $items_actually_migrated; |
|
52 | - } |
|
53 | - public function _count_records_to_migrate() |
|
54 | - { |
|
55 | - global $wpdb; |
|
56 | - $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table); |
|
57 | - return $count; |
|
58 | - } |
|
59 | - public function __construct() |
|
60 | - { |
|
61 | - global $wpdb; |
|
62 | - $this->_old_table = $wpdb->prefix."events_category_rel"; |
|
63 | - $this->_new_table = $wpdb->prefix."term_relationships"; |
|
64 | - $this->_pretty_name = __("Event to Category (4.1 Term Relationships)", "event_espresso"); |
|
65 | - parent::__construct(); |
|
66 | - } |
|
31 | + private $_old_table; |
|
32 | + private $_new_table; |
|
33 | + public function _migration_step($num_items = 50) |
|
34 | + { |
|
35 | + global $wpdb; |
|
36 | + $start_at_record = $this->count_records_migrated(); |
|
37 | + $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A); |
|
38 | + $items_actually_migrated = 0; |
|
39 | + foreach ($rows as $event_venue_rel) { |
|
40 | + $term_relation_id = $this->_add_relation_from_event_to_term_taxonomy($event_venue_rel); |
|
41 | + if ($term_relation_id) { |
|
42 | + $this->get_migration_script()->set_mapping($this->_old_table, $event_venue_rel['id'], $this->_new_table, $term_relation_id); |
|
43 | + } |
|
44 | + $items_actually_migrated++; |
|
45 | + } |
|
46 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
47 | + $this->set_completed(); |
|
48 | + } |
|
49 | + return $items_actually_migrated; |
|
50 | + } |
|
51 | + public function _count_records_to_migrate() |
|
52 | + { |
|
53 | + global $wpdb; |
|
54 | + $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table); |
|
55 | + return $count; |
|
56 | + } |
|
57 | + public function __construct() |
|
58 | + { |
|
59 | + global $wpdb; |
|
60 | + $this->_old_table = $wpdb->prefix."events_category_rel"; |
|
61 | + $this->_new_table = $wpdb->prefix."term_relationships"; |
|
62 | + $this->_pretty_name = __("Event to Category (4.1 Term Relationships)", "event_espresso"); |
|
63 | + parent::__construct(); |
|
64 | + } |
|
67 | 65 | |
68 | - /** |
|
69 | - * Attempts to insert a new question group inthe new format given an old one |
|
70 | - * @global type $wpdb |
|
71 | - * @param array $old_event_cat_relation |
|
72 | - * @return int |
|
73 | - */ |
|
74 | - private function _add_relation_from_event_to_term_taxonomy($old_event_cat_relation) |
|
75 | - { |
|
76 | - global $wpdb; |
|
77 | - $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", intval($old_event_cat_relation['event_id']), $wpdb->prefix."posts"); |
|
78 | - $new_term_taxonomy_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_category_detail", intval($old_event_cat_relation['cat_id']), $wpdb->prefix."term_taxonomy"); |
|
79 | - if (! $new_event_id) { |
|
80 | - $this->add_error(sprintf(__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $old_event_cat_relation['event_id'])); |
|
81 | - return 0; |
|
82 | - } |
|
83 | - if (! $new_term_taxonomy_id) { |
|
84 | - $this->add_error(sprintf(__("Could not find 4.1 term-taxonomy id for 3.1 category #%d.", "event_espresso"), $old_event_cat_relation['cat_id'])); |
|
85 | - return 0; |
|
86 | - } |
|
87 | - $cols_n_values = array( |
|
88 | - 'object_id'=>$new_event_id, |
|
89 | - 'term_taxonomy_id'=>$new_term_taxonomy_id, |
|
90 | - 'term_order'=>0 |
|
91 | - ); |
|
92 | - $datatypes = array( |
|
93 | - '%d',// object_id |
|
94 | - '%d',// term_taxonomy_id |
|
95 | - '%d',// term_order |
|
96 | - ); |
|
97 | - $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
98 | - if (! $success) { |
|
99 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event_cat_relation, $this->_new_table, $cols_n_values, $datatypes)); |
|
100 | - return 0; |
|
101 | - } else { |
|
102 | - // increment the term-taxonomie's count |
|
103 | - $success = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->term_taxonomy} SET count = count +1 WHERE term_taxonomy_id=%d", $new_term_taxonomy_id)); |
|
104 | - if (! $success) { |
|
105 | - $this->add_error(sprintf(__('Could not increment term_taxonomy\'s count because %s', 'event_espresso'), $wpdb->last_error)); |
|
106 | - } |
|
107 | - } |
|
108 | - return $wpdb->insert_id; |
|
109 | - } |
|
66 | + /** |
|
67 | + * Attempts to insert a new question group inthe new format given an old one |
|
68 | + * @global type $wpdb |
|
69 | + * @param array $old_event_cat_relation |
|
70 | + * @return int |
|
71 | + */ |
|
72 | + private function _add_relation_from_event_to_term_taxonomy($old_event_cat_relation) |
|
73 | + { |
|
74 | + global $wpdb; |
|
75 | + $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", intval($old_event_cat_relation['event_id']), $wpdb->prefix."posts"); |
|
76 | + $new_term_taxonomy_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_category_detail", intval($old_event_cat_relation['cat_id']), $wpdb->prefix."term_taxonomy"); |
|
77 | + if (! $new_event_id) { |
|
78 | + $this->add_error(sprintf(__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $old_event_cat_relation['event_id'])); |
|
79 | + return 0; |
|
80 | + } |
|
81 | + if (! $new_term_taxonomy_id) { |
|
82 | + $this->add_error(sprintf(__("Could not find 4.1 term-taxonomy id for 3.1 category #%d.", "event_espresso"), $old_event_cat_relation['cat_id'])); |
|
83 | + return 0; |
|
84 | + } |
|
85 | + $cols_n_values = array( |
|
86 | + 'object_id'=>$new_event_id, |
|
87 | + 'term_taxonomy_id'=>$new_term_taxonomy_id, |
|
88 | + 'term_order'=>0 |
|
89 | + ); |
|
90 | + $datatypes = array( |
|
91 | + '%d',// object_id |
|
92 | + '%d',// term_taxonomy_id |
|
93 | + '%d',// term_order |
|
94 | + ); |
|
95 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
96 | + if (! $success) { |
|
97 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event_cat_relation, $this->_new_table, $cols_n_values, $datatypes)); |
|
98 | + return 0; |
|
99 | + } else { |
|
100 | + // increment the term-taxonomie's count |
|
101 | + $success = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->term_taxonomy} SET count = count +1 WHERE term_taxonomy_id=%d", $new_term_taxonomy_id)); |
|
102 | + if (! $success) { |
|
103 | + $this->add_error(sprintf(__('Could not increment term_taxonomy\'s count because %s', 'event_espresso'), $wpdb->last_error)); |
|
104 | + } |
|
105 | + } |
|
106 | + return $wpdb->insert_id; |
|
107 | + } |
|
110 | 108 | } |
@@ -76,11 +76,11 @@ discard block |
||
76 | 76 | global $wpdb; |
77 | 77 | $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", intval($old_event_cat_relation['event_id']), $wpdb->prefix."posts"); |
78 | 78 | $new_term_taxonomy_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_category_detail", intval($old_event_cat_relation['cat_id']), $wpdb->prefix."term_taxonomy"); |
79 | - if (! $new_event_id) { |
|
79 | + if ( ! $new_event_id) { |
|
80 | 80 | $this->add_error(sprintf(__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $old_event_cat_relation['event_id'])); |
81 | 81 | return 0; |
82 | 82 | } |
83 | - if (! $new_term_taxonomy_id) { |
|
83 | + if ( ! $new_term_taxonomy_id) { |
|
84 | 84 | $this->add_error(sprintf(__("Could not find 4.1 term-taxonomy id for 3.1 category #%d.", "event_espresso"), $old_event_cat_relation['cat_id'])); |
85 | 85 | return 0; |
86 | 86 | } |
@@ -90,18 +90,18 @@ discard block |
||
90 | 90 | 'term_order'=>0 |
91 | 91 | ); |
92 | 92 | $datatypes = array( |
93 | - '%d',// object_id |
|
94 | - '%d',// term_taxonomy_id |
|
95 | - '%d',// term_order |
|
93 | + '%d', // object_id |
|
94 | + '%d', // term_taxonomy_id |
|
95 | + '%d', // term_order |
|
96 | 96 | ); |
97 | 97 | $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
98 | - if (! $success) { |
|
98 | + if ( ! $success) { |
|
99 | 99 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event_cat_relation, $this->_new_table, $cols_n_values, $datatypes)); |
100 | 100 | return 0; |
101 | 101 | } else { |
102 | 102 | // increment the term-taxonomie's count |
103 | 103 | $success = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->term_taxonomy} SET count = count +1 WHERE term_taxonomy_id=%d", $new_term_taxonomy_id)); |
104 | - if (! $success) { |
|
104 | + if ( ! $success) { |
|
105 | 105 | $this->add_error(sprintf(__('Could not increment term_taxonomy\'s count because %s', 'event_espresso'), $wpdb->last_error)); |
106 | 106 | } |
107 | 107 | } |
@@ -40,119 +40,119 @@ |
||
40 | 40 | */ |
41 | 41 | class EE_DMS_4_1_0_question_groups extends EE_Data_Migration_Script_Stage |
42 | 42 | { |
43 | - private $_old_table; |
|
44 | - private $_new_table; |
|
45 | - /** |
|
46 | - * Keeps track of whether or not we've already added a system question group, |
|
47 | - * in order to avoid adding more than 1 (basically, in 3.1 this would happen |
|
48 | - * with the Roles & Permissions addon, because each user had their own set of |
|
49 | - * question groups and questions), |
|
50 | - * @var boolean |
|
51 | - */ |
|
52 | - private $_already_got_system_question_group_1 = false; |
|
53 | - public function _migration_step($num_items = 50) |
|
54 | - { |
|
43 | + private $_old_table; |
|
44 | + private $_new_table; |
|
45 | + /** |
|
46 | + * Keeps track of whether or not we've already added a system question group, |
|
47 | + * in order to avoid adding more than 1 (basically, in 3.1 this would happen |
|
48 | + * with the Roles & Permissions addon, because each user had their own set of |
|
49 | + * question groups and questions), |
|
50 | + * @var boolean |
|
51 | + */ |
|
52 | + private $_already_got_system_question_group_1 = false; |
|
53 | + public function _migration_step($num_items = 50) |
|
54 | + { |
|
55 | 55 | |
56 | - global $wpdb; |
|
57 | - $start_at_record = $this->count_records_migrated(); |
|
58 | - $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A); |
|
59 | - $items_actually_migrated = 0; |
|
60 | - foreach ($rows as $question_group) { |
|
61 | - $new_id = $this->_insert_new_question_group($question_group); |
|
56 | + global $wpdb; |
|
57 | + $start_at_record = $this->count_records_migrated(); |
|
58 | + $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A); |
|
59 | + $items_actually_migrated = 0; |
|
60 | + foreach ($rows as $question_group) { |
|
61 | + $new_id = $this->_insert_new_question_group($question_group); |
|
62 | 62 | |
63 | - $this->get_migration_script()->set_mapping($this->_old_table, $question_group['id'], $this->_new_table, $new_id); |
|
64 | - $items_actually_migrated++; |
|
65 | - } |
|
66 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
67 | - $this->set_completed(); |
|
68 | - } |
|
69 | - return $items_actually_migrated; |
|
70 | - } |
|
71 | - public function _count_records_to_migrate() |
|
72 | - { |
|
73 | - global $wpdb; |
|
74 | - $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table); |
|
75 | - return $count; |
|
76 | - } |
|
77 | - public function __construct() |
|
78 | - { |
|
79 | - global $wpdb; |
|
80 | - $this->_old_table = $wpdb->prefix."events_qst_group"; |
|
81 | - $this->_new_table = $wpdb->prefix."esp_question_group"; |
|
82 | - $this->_pretty_name = __("Question Groups", "event_espresso"); |
|
83 | - parent::__construct(); |
|
84 | - } |
|
63 | + $this->get_migration_script()->set_mapping($this->_old_table, $question_group['id'], $this->_new_table, $new_id); |
|
64 | + $items_actually_migrated++; |
|
65 | + } |
|
66 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
67 | + $this->set_completed(); |
|
68 | + } |
|
69 | + return $items_actually_migrated; |
|
70 | + } |
|
71 | + public function _count_records_to_migrate() |
|
72 | + { |
|
73 | + global $wpdb; |
|
74 | + $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table); |
|
75 | + return $count; |
|
76 | + } |
|
77 | + public function __construct() |
|
78 | + { |
|
79 | + global $wpdb; |
|
80 | + $this->_old_table = $wpdb->prefix."events_qst_group"; |
|
81 | + $this->_new_table = $wpdb->prefix."esp_question_group"; |
|
82 | + $this->_pretty_name = __("Question Groups", "event_espresso"); |
|
83 | + parent::__construct(); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Attempts to insert a new question group inthe new format given an old one |
|
88 | - * @global type $wpdb |
|
89 | - * @param array $old_question_group |
|
90 | - * @return int |
|
91 | - */ |
|
92 | - private function _insert_new_question_group($old_question_group) |
|
93 | - { |
|
94 | - global $wpdb; |
|
95 | - // try to guess what the QST_system int should be... finding the Personal info system |
|
96 | - // question group is quite easy. But in 3.1 address info WASN'T a system group, it just exitsed by default but |
|
97 | - // could be easily removed. |
|
98 | - if ($old_question_group['system_group'] && ! $this->_already_got_system_question_group_1()) { |
|
99 | - $guess_at_system_number = 1; |
|
100 | - } elseif ($old_question_group['id'] == '2' && strpos($old_question_group['group_name'], 'Address')!==false) { |
|
101 | - $guess_at_system_number = 2; |
|
102 | - } else { |
|
103 | - $guess_at_system_number = 0; |
|
104 | - } |
|
105 | - // if the question group wasn't made by the normal admin, |
|
106 | - // we'd like to keep track of who made it |
|
107 | - if (intval($old_question_group['wp_user'])!=1) { |
|
108 | - $username = $wpdb->get_var($wpdb->prepare("SELECT user_nicename FROM ".$wpdb->users." WHERE ID = %d", $old_question_group['wp_user'])); |
|
109 | - $identifier = $old_question_group['group_identifier']."-by-".$username; |
|
110 | - } else { |
|
111 | - $identifier = $old_question_group['group_identifier']; |
|
112 | - } |
|
113 | - $cols_n_values = array( |
|
114 | - 'QSG_name'=>stripslashes($old_question_group['group_name']), |
|
115 | - 'QSG_identifier'=>$identifier, |
|
116 | - 'QSG_desc'=>stripslashes($old_question_group['group_description']), |
|
117 | - 'QSG_order'=>$old_question_group['group_order'], |
|
118 | - 'QSG_show_group_name'=>$old_question_group['show_group_name'], |
|
119 | - 'QSG_show_group_desc'=>$old_question_group['show_group_description'], |
|
120 | - 'QSG_system'=>$guess_at_system_number, |
|
121 | - 'QSG_deleted'=>false |
|
122 | - ); |
|
123 | - $datatypes = array( |
|
124 | - '%s',// QSG_name |
|
125 | - '%s',// QSG_identifier |
|
126 | - '%s',// QSG_desc |
|
127 | - '%d',// QSG_order |
|
128 | - '%d',// QSG_show_group_name |
|
129 | - '%d',// QSG_show_group_desc |
|
130 | - '%d',// QSG_system |
|
131 | - '%d',// QSG_deleted |
|
132 | - ); |
|
133 | - $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
134 | - if (! $success) { |
|
135 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question_group, $this->_new_table, $cols_n_values, $datatypes)); |
|
136 | - return 0; |
|
137 | - } |
|
138 | - return $wpdb->insert_id; |
|
139 | - } |
|
86 | + /** |
|
87 | + * Attempts to insert a new question group inthe new format given an old one |
|
88 | + * @global type $wpdb |
|
89 | + * @param array $old_question_group |
|
90 | + * @return int |
|
91 | + */ |
|
92 | + private function _insert_new_question_group($old_question_group) |
|
93 | + { |
|
94 | + global $wpdb; |
|
95 | + // try to guess what the QST_system int should be... finding the Personal info system |
|
96 | + // question group is quite easy. But in 3.1 address info WASN'T a system group, it just exitsed by default but |
|
97 | + // could be easily removed. |
|
98 | + if ($old_question_group['system_group'] && ! $this->_already_got_system_question_group_1()) { |
|
99 | + $guess_at_system_number = 1; |
|
100 | + } elseif ($old_question_group['id'] == '2' && strpos($old_question_group['group_name'], 'Address')!==false) { |
|
101 | + $guess_at_system_number = 2; |
|
102 | + } else { |
|
103 | + $guess_at_system_number = 0; |
|
104 | + } |
|
105 | + // if the question group wasn't made by the normal admin, |
|
106 | + // we'd like to keep track of who made it |
|
107 | + if (intval($old_question_group['wp_user'])!=1) { |
|
108 | + $username = $wpdb->get_var($wpdb->prepare("SELECT user_nicename FROM ".$wpdb->users." WHERE ID = %d", $old_question_group['wp_user'])); |
|
109 | + $identifier = $old_question_group['group_identifier']."-by-".$username; |
|
110 | + } else { |
|
111 | + $identifier = $old_question_group['group_identifier']; |
|
112 | + } |
|
113 | + $cols_n_values = array( |
|
114 | + 'QSG_name'=>stripslashes($old_question_group['group_name']), |
|
115 | + 'QSG_identifier'=>$identifier, |
|
116 | + 'QSG_desc'=>stripslashes($old_question_group['group_description']), |
|
117 | + 'QSG_order'=>$old_question_group['group_order'], |
|
118 | + 'QSG_show_group_name'=>$old_question_group['show_group_name'], |
|
119 | + 'QSG_show_group_desc'=>$old_question_group['show_group_description'], |
|
120 | + 'QSG_system'=>$guess_at_system_number, |
|
121 | + 'QSG_deleted'=>false |
|
122 | + ); |
|
123 | + $datatypes = array( |
|
124 | + '%s',// QSG_name |
|
125 | + '%s',// QSG_identifier |
|
126 | + '%s',// QSG_desc |
|
127 | + '%d',// QSG_order |
|
128 | + '%d',// QSG_show_group_name |
|
129 | + '%d',// QSG_show_group_desc |
|
130 | + '%d',// QSG_system |
|
131 | + '%d',// QSG_deleted |
|
132 | + ); |
|
133 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
134 | + if (! $success) { |
|
135 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question_group, $this->_new_table, $cols_n_values, $datatypes)); |
|
136 | + return 0; |
|
137 | + } |
|
138 | + return $wpdb->insert_id; |
|
139 | + } |
|
140 | 140 | |
141 | - /** |
|
142 | - * Checks if we've already added a system question 1 to the new question groups table |
|
143 | - * @global type $wpdb |
|
144 | - * @return boolean |
|
145 | - */ |
|
146 | - private function _already_got_system_question_group_1() |
|
147 | - { |
|
148 | - if (! $this->_already_got_system_question_group_1) { |
|
149 | - // check the db |
|
150 | - global $wpdb; |
|
151 | - $exists = $wpdb->get_var("SELECT COUNT(*) FROM {$this->_new_table} WHERE QSG_system=1"); |
|
152 | - if (intval($exists)>0) { |
|
153 | - $this->_already_got_system_question_group_1 = true; |
|
154 | - } |
|
155 | - } |
|
156 | - return $this->_already_got_system_question_group_1; |
|
157 | - } |
|
141 | + /** |
|
142 | + * Checks if we've already added a system question 1 to the new question groups table |
|
143 | + * @global type $wpdb |
|
144 | + * @return boolean |
|
145 | + */ |
|
146 | + private function _already_got_system_question_group_1() |
|
147 | + { |
|
148 | + if (! $this->_already_got_system_question_group_1) { |
|
149 | + // check the db |
|
150 | + global $wpdb; |
|
151 | + $exists = $wpdb->get_var("SELECT COUNT(*) FROM {$this->_new_table} WHERE QSG_system=1"); |
|
152 | + if (intval($exists)>0) { |
|
153 | + $this->_already_got_system_question_group_1 = true; |
|
154 | + } |
|
155 | + } |
|
156 | + return $this->_already_got_system_question_group_1; |
|
157 | + } |
|
158 | 158 | } |
@@ -97,14 +97,14 @@ discard block |
||
97 | 97 | // could be easily removed. |
98 | 98 | if ($old_question_group['system_group'] && ! $this->_already_got_system_question_group_1()) { |
99 | 99 | $guess_at_system_number = 1; |
100 | - } elseif ($old_question_group['id'] == '2' && strpos($old_question_group['group_name'], 'Address')!==false) { |
|
100 | + } elseif ($old_question_group['id'] == '2' && strpos($old_question_group['group_name'], 'Address') !== false) { |
|
101 | 101 | $guess_at_system_number = 2; |
102 | 102 | } else { |
103 | 103 | $guess_at_system_number = 0; |
104 | 104 | } |
105 | 105 | // if the question group wasn't made by the normal admin, |
106 | 106 | // we'd like to keep track of who made it |
107 | - if (intval($old_question_group['wp_user'])!=1) { |
|
107 | + if (intval($old_question_group['wp_user']) != 1) { |
|
108 | 108 | $username = $wpdb->get_var($wpdb->prepare("SELECT user_nicename FROM ".$wpdb->users." WHERE ID = %d", $old_question_group['wp_user'])); |
109 | 109 | $identifier = $old_question_group['group_identifier']."-by-".$username; |
110 | 110 | } else { |
@@ -121,17 +121,17 @@ discard block |
||
121 | 121 | 'QSG_deleted'=>false |
122 | 122 | ); |
123 | 123 | $datatypes = array( |
124 | - '%s',// QSG_name |
|
125 | - '%s',// QSG_identifier |
|
126 | - '%s',// QSG_desc |
|
127 | - '%d',// QSG_order |
|
128 | - '%d',// QSG_show_group_name |
|
129 | - '%d',// QSG_show_group_desc |
|
130 | - '%d',// QSG_system |
|
131 | - '%d',// QSG_deleted |
|
124 | + '%s', // QSG_name |
|
125 | + '%s', // QSG_identifier |
|
126 | + '%s', // QSG_desc |
|
127 | + '%d', // QSG_order |
|
128 | + '%d', // QSG_show_group_name |
|
129 | + '%d', // QSG_show_group_desc |
|
130 | + '%d', // QSG_system |
|
131 | + '%d', // QSG_deleted |
|
132 | 132 | ); |
133 | 133 | $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
134 | - if (! $success) { |
|
134 | + if ( ! $success) { |
|
135 | 135 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question_group, $this->_new_table, $cols_n_values, $datatypes)); |
136 | 136 | return 0; |
137 | 137 | } |
@@ -145,11 +145,11 @@ discard block |
||
145 | 145 | */ |
146 | 146 | private function _already_got_system_question_group_1() |
147 | 147 | { |
148 | - if (! $this->_already_got_system_question_group_1) { |
|
148 | + if ( ! $this->_already_got_system_question_group_1) { |
|
149 | 149 | // check the db |
150 | 150 | global $wpdb; |
151 | 151 | $exists = $wpdb->get_var("SELECT COUNT(*) FROM {$this->_new_table} WHERE QSG_system=1"); |
152 | - if (intval($exists)>0) { |
|
152 | + if (intval($exists) > 0) { |
|
153 | 153 | $this->_already_got_system_question_group_1 = true; |
154 | 154 | } |
155 | 155 | } |
@@ -24,20 +24,20 @@ discard block |
||
24 | 24 | // convert settings |
25 | 25 | $gateways_to_deal_with = array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone); |
26 | 26 | // just do a part of them on this request |
27 | - $gateways_to_deal_with = array_slice($gateways_to_deal_with, $this->count_records_migrated(), $num_items);// $this->_gateways_we_know_how_to_migrate; |
|
27 | + $gateways_to_deal_with = array_slice($gateways_to_deal_with, $this->count_records_migrated(), $num_items); // $this->_gateways_we_know_how_to_migrate; |
|
28 | 28 | foreach ($gateways_to_deal_with as $old_gateway_slug => $new_gateway_slug) { |
29 | 29 | $old_gateway_wp_option_name = $this->_get_old_gateway_option_name($new_gateway_slug); |
30 | - if (isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) { |
|
30 | + if (isset($this->_gateways_we_know_how_to_migrate[$old_gateway_slug])) { |
|
31 | 31 | // determine the old option's name |
32 | 32 | $old_gateway_settings = $this->_get_old_gateway_option($new_gateway_slug); |
33 | - if (! $old_gateway_settings) { |
|
33 | + if ( ! $old_gateway_settings) { |
|
34 | 34 | // no settings existed for this gateway anyways... weird... |
35 | 35 | $items_actually_migrated++; |
36 | 36 | continue; |
37 | 37 | } |
38 | 38 | // now prepare the settings to make sure they're in the 4.1 format |
39 | 39 | $new_gateway_settings = $this->_convert_gateway_settings($old_gateway_settings, $new_gateway_slug); |
40 | - $new_gateway_config_obj->payment_settings[ $new_gateway_slug ] = $new_gateway_settings; |
|
40 | + $new_gateway_config_obj->payment_settings[$new_gateway_slug] = $new_gateway_settings; |
|
41 | 41 | // and when we're done, remove the old option. Sometimes we'd prefer to do this in a different stage, but |
42 | 42 | // I think it's ok to do right away this time (we wont need gateway settings elsewhere) |
43 | 43 | delete_option($old_gateway_wp_option_name); |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | $items_actually_migrated++; |
52 | 52 | } |
53 | 53 | // if we can keep going, and it hasn' tbeen done yet, convert active gateways |
54 | - if ($items_actually_migrated < $num_items && ! $this->_converted_active_gateways) { |
|
54 | + if ($items_actually_migrated < $num_items && ! $this->_converted_active_gateways) { |
|
55 | 55 | $this->_convert_active_gateways(); |
56 | 56 | $this->_converted_active_gateways = true; |
57 | 57 | $items_actually_migrated++; |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | $step_of_setting_active_gateways = 1; |
70 | 70 | $count_of_gateways_to_leave_alone = count($this->_gateways_we_leave_alone); |
71 | 71 | // $button_images_to_update = |
72 | - return $count_of_gateways_to_convert + $step_of_setting_active_gateways + $count_of_gateways_to_leave_alone; |
|
72 | + return $count_of_gateways_to_convert + $step_of_setting_active_gateways + $count_of_gateways_to_leave_alone; |
|
73 | 73 | } |
74 | 74 | public function __construct() |
75 | 75 | { |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | private function _get_old_gateway_option($new_gateway_slug) |
116 | 116 | { |
117 | 117 | $option_name = $this->_get_old_gateway_option_name($new_gateway_slug); |
118 | - $settings = get_option($option_name, null); |
|
118 | + $settings = get_option($option_name, null); |
|
119 | 119 | // if( ! $settings){ |
120 | 120 | // $this->add_error(sprintf(__("There is no wordpress option named %s for gateway %s", "event_espresso"),$option_name,$new_gateway_slug)); |
121 | 121 | // } |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | private function _get_old_gateway_option_name($new_gateway_slug) |
131 | 131 | { |
132 | 132 | $new_gateway_slugs_to_new = array_flip(array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone)); |
133 | - $old_gateway_slug = $new_gateway_slugs_to_new[ $new_gateway_slug ]; |
|
133 | + $old_gateway_slug = $new_gateway_slugs_to_new[$new_gateway_slug]; |
|
134 | 134 | $normal_option_prefix = 'event_espresso_'; |
135 | 135 | $normal_option_postfix = '_settings'; |
136 | 136 | switch ($new_gateway_slug) { |
@@ -170,14 +170,14 @@ discard block |
||
170 | 170 | $old_active_gateways = get_option('event_espresso_active_gateways'); |
171 | 171 | $new_active_gateways = EE_Config::instance()->gateway->active_gateways; |
172 | 172 | foreach ($old_active_gateways as $old_gateway_slug => $filepath) { |
173 | - if (! isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) { |
|
173 | + if ( ! isset($this->_gateways_we_know_how_to_migrate[$old_gateway_slug])) { |
|
174 | 174 | $this->add_error(sprintf(__("The %s gateway does not exist in EE 4.1", "event_espresso"), $old_gateway_slug)); |
175 | 175 | continue; |
176 | 176 | } |
177 | - $new_gateway_slug = $this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ]; |
|
177 | + $new_gateway_slug = $this->_gateways_we_know_how_to_migrate[$old_gateway_slug]; |
|
178 | 178 | |
179 | 179 | // in the new format we can also upload gateways to the uploads directory and |
180 | - $new_active_gateways[ $new_gateway_slug ] = false; |
|
180 | + $new_active_gateways[$new_gateway_slug] = false; |
|
181 | 181 | } |
182 | 182 | EE_Config::instance()->gateway->active_gateways = $new_active_gateways; |
183 | 183 | } |
@@ -14,68 +14,68 @@ discard block |
||
14 | 14 | class EE_DMS_4_1_0_gateways extends EE_Data_Migration_Script_Stage |
15 | 15 | { |
16 | 16 | |
17 | - private $_converted_active_gateways = false; |
|
17 | + private $_converted_active_gateways = false; |
|
18 | 18 | |
19 | - public function _migration_step($num_items = 50) |
|
20 | - { |
|
21 | - // loads existing EE_CONfig from DB, if it exists |
|
22 | - $new_gateway_config_obj = EE_Config::instance()->gateway; |
|
23 | - $items_actually_migrated = 0; |
|
24 | - // convert settings |
|
25 | - $gateways_to_deal_with = array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone); |
|
26 | - // just do a part of them on this request |
|
27 | - $gateways_to_deal_with = array_slice($gateways_to_deal_with, $this->count_records_migrated(), $num_items);// $this->_gateways_we_know_how_to_migrate; |
|
28 | - foreach ($gateways_to_deal_with as $old_gateway_slug => $new_gateway_slug) { |
|
29 | - $old_gateway_wp_option_name = $this->_get_old_gateway_option_name($new_gateway_slug); |
|
30 | - if (isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) { |
|
31 | - // determine the old option's name |
|
32 | - $old_gateway_settings = $this->_get_old_gateway_option($new_gateway_slug); |
|
33 | - if (! $old_gateway_settings) { |
|
34 | - // no settings existed for this gateway anyways... weird... |
|
35 | - $items_actually_migrated++; |
|
36 | - continue; |
|
37 | - } |
|
38 | - // now prepare the settings to make sure they're in the 4.1 format |
|
39 | - $new_gateway_settings = $this->_convert_gateway_settings($old_gateway_settings, $new_gateway_slug); |
|
40 | - $new_gateway_config_obj->payment_settings[ $new_gateway_slug ] = $new_gateway_settings; |
|
41 | - // and when we're done, remove the old option. Sometimes we'd prefer to do this in a different stage, but |
|
42 | - // I think it's ok to do right away this time (we wont need gateway settings elsewhere) |
|
43 | - delete_option($old_gateway_wp_option_name); |
|
44 | - } else {// it must be one of the ones we mostly leave alone |
|
45 | - global $wpdb; |
|
46 | - // yeah we could do this all in one query... and if you're reading this and would liek to, go ahead. Although you'll |
|
47 | - // only be saving users 50 milliseconds the one time this runs... |
|
48 | - $wpdb->query($wpdb->prepare("UPDATE ".$wpdb->options." SET autoload='no' WHERE option_name=%s", $old_gateway_wp_option_name)); |
|
49 | - } |
|
19 | + public function _migration_step($num_items = 50) |
|
20 | + { |
|
21 | + // loads existing EE_CONfig from DB, if it exists |
|
22 | + $new_gateway_config_obj = EE_Config::instance()->gateway; |
|
23 | + $items_actually_migrated = 0; |
|
24 | + // convert settings |
|
25 | + $gateways_to_deal_with = array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone); |
|
26 | + // just do a part of them on this request |
|
27 | + $gateways_to_deal_with = array_slice($gateways_to_deal_with, $this->count_records_migrated(), $num_items);// $this->_gateways_we_know_how_to_migrate; |
|
28 | + foreach ($gateways_to_deal_with as $old_gateway_slug => $new_gateway_slug) { |
|
29 | + $old_gateway_wp_option_name = $this->_get_old_gateway_option_name($new_gateway_slug); |
|
30 | + if (isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) { |
|
31 | + // determine the old option's name |
|
32 | + $old_gateway_settings = $this->_get_old_gateway_option($new_gateway_slug); |
|
33 | + if (! $old_gateway_settings) { |
|
34 | + // no settings existed for this gateway anyways... weird... |
|
35 | + $items_actually_migrated++; |
|
36 | + continue; |
|
37 | + } |
|
38 | + // now prepare the settings to make sure they're in the 4.1 format |
|
39 | + $new_gateway_settings = $this->_convert_gateway_settings($old_gateway_settings, $new_gateway_slug); |
|
40 | + $new_gateway_config_obj->payment_settings[ $new_gateway_slug ] = $new_gateway_settings; |
|
41 | + // and when we're done, remove the old option. Sometimes we'd prefer to do this in a different stage, but |
|
42 | + // I think it's ok to do right away this time (we wont need gateway settings elsewhere) |
|
43 | + delete_option($old_gateway_wp_option_name); |
|
44 | + } else {// it must be one of the ones we mostly leave alone |
|
45 | + global $wpdb; |
|
46 | + // yeah we could do this all in one query... and if you're reading this and would liek to, go ahead. Although you'll |
|
47 | + // only be saving users 50 milliseconds the one time this runs... |
|
48 | + $wpdb->query($wpdb->prepare("UPDATE ".$wpdb->options." SET autoload='no' WHERE option_name=%s", $old_gateway_wp_option_name)); |
|
49 | + } |
|
50 | 50 | |
51 | - $items_actually_migrated++; |
|
52 | - } |
|
53 | - // if we can keep going, and it hasn' tbeen done yet, convert active gateways |
|
54 | - if ($items_actually_migrated < $num_items && ! $this->_converted_active_gateways) { |
|
55 | - $this->_convert_active_gateways(); |
|
56 | - $this->_converted_active_gateways = true; |
|
57 | - $items_actually_migrated++; |
|
58 | - } |
|
51 | + $items_actually_migrated++; |
|
52 | + } |
|
53 | + // if we can keep going, and it hasn' tbeen done yet, convert active gateways |
|
54 | + if ($items_actually_migrated < $num_items && ! $this->_converted_active_gateways) { |
|
55 | + $this->_convert_active_gateways(); |
|
56 | + $this->_converted_active_gateways = true; |
|
57 | + $items_actually_migrated++; |
|
58 | + } |
|
59 | 59 | |
60 | - EE_Config::instance()->update_espresso_config(false, false); |
|
61 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
62 | - $this->set_completed(); |
|
63 | - } |
|
64 | - return $items_actually_migrated; |
|
65 | - } |
|
66 | - public function _count_records_to_migrate() |
|
67 | - { |
|
68 | - $count_of_gateways_to_convert = count($this->_gateways_we_know_how_to_migrate); |
|
69 | - $step_of_setting_active_gateways = 1; |
|
70 | - $count_of_gateways_to_leave_alone = count($this->_gateways_we_leave_alone); |
|
71 | - // $button_images_to_update = |
|
72 | - return $count_of_gateways_to_convert + $step_of_setting_active_gateways + $count_of_gateways_to_leave_alone; |
|
73 | - } |
|
74 | - public function __construct() |
|
75 | - { |
|
76 | - $this->_pretty_name = __("Gateways", "event_espresso"); |
|
77 | - parent::__construct(); |
|
78 | - } |
|
60 | + EE_Config::instance()->update_espresso_config(false, false); |
|
61 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
62 | + $this->set_completed(); |
|
63 | + } |
|
64 | + return $items_actually_migrated; |
|
65 | + } |
|
66 | + public function _count_records_to_migrate() |
|
67 | + { |
|
68 | + $count_of_gateways_to_convert = count($this->_gateways_we_know_how_to_migrate); |
|
69 | + $step_of_setting_active_gateways = 1; |
|
70 | + $count_of_gateways_to_leave_alone = count($this->_gateways_we_leave_alone); |
|
71 | + // $button_images_to_update = |
|
72 | + return $count_of_gateways_to_convert + $step_of_setting_active_gateways + $count_of_gateways_to_leave_alone; |
|
73 | + } |
|
74 | + public function __construct() |
|
75 | + { |
|
76 | + $this->_pretty_name = __("Gateways", "event_espresso"); |
|
77 | + parent::__construct(); |
|
78 | + } |
|
79 | 79 | |
80 | 80 | /** |
81 | 81 | * Takes the old array of 3.1 gateway settings for this gateway and converts it |
@@ -85,148 +85,148 @@ discard block |
||
85 | 85 | * @param string $new_gateway_slug |
86 | 86 | * @return array |
87 | 87 | */ |
88 | - private function _convert_gateway_settings($old_gateway_settings, $new_gateway_slug) |
|
89 | - { |
|
90 | - $new_gateway_settings = $old_gateway_settings; |
|
91 | - switch ($new_gateway_slug) { |
|
92 | - case 'Bank': |
|
93 | - $new_gateway_settings['account_number'] = $old_gateway_settings['bank_account']; |
|
94 | - $new_gateway_settings['page_title'] = $old_gateway_settings['bank_title']; |
|
95 | - break; |
|
96 | - case 'Invoice': |
|
97 | - $new_gateway_settings['invoice_logo_url'] = $old_gateway_settings['image_url']; |
|
98 | - // Dont' migrate the old invoice payee address. It was usually given dummy data. And in EE4 |
|
99 | - // it gets used in the receipts which are available to everyone. So usually it's best to not |
|
100 | - // migrate this. |
|
101 | - unset($new_gateway_settings['payment_address']); |
|
102 | - break; |
|
103 | - case 'Paypal_Pro': |
|
104 | - $new_gateway_settings['email'] = $old_gateway_settings['paypal_pro_email']; |
|
105 | - $new_gateway_settings['username'] = $old_gateway_settings['paypal_api_username']; |
|
106 | - $new_gateway_settings['password'] = $old_gateway_settings['paypal_api_password']; |
|
107 | - $new_gateway_settings['signature'] = $old_gateway_settings['paypal_api_signature']; |
|
108 | - $new_gateway_settings['credit_cards'] = explode(",", $old_gateway_settings['paypal_api_credit_cards']); |
|
109 | - $new_gateway_settings['use_sandbox'] = $old_gateway_settings['paypal_pro_use_sandbox']; |
|
110 | - break; |
|
111 | - } |
|
112 | - return $new_gateway_settings; |
|
113 | - } |
|
88 | + private function _convert_gateway_settings($old_gateway_settings, $new_gateway_slug) |
|
89 | + { |
|
90 | + $new_gateway_settings = $old_gateway_settings; |
|
91 | + switch ($new_gateway_slug) { |
|
92 | + case 'Bank': |
|
93 | + $new_gateway_settings['account_number'] = $old_gateway_settings['bank_account']; |
|
94 | + $new_gateway_settings['page_title'] = $old_gateway_settings['bank_title']; |
|
95 | + break; |
|
96 | + case 'Invoice': |
|
97 | + $new_gateway_settings['invoice_logo_url'] = $old_gateway_settings['image_url']; |
|
98 | + // Dont' migrate the old invoice payee address. It was usually given dummy data. And in EE4 |
|
99 | + // it gets used in the receipts which are available to everyone. So usually it's best to not |
|
100 | + // migrate this. |
|
101 | + unset($new_gateway_settings['payment_address']); |
|
102 | + break; |
|
103 | + case 'Paypal_Pro': |
|
104 | + $new_gateway_settings['email'] = $old_gateway_settings['paypal_pro_email']; |
|
105 | + $new_gateway_settings['username'] = $old_gateway_settings['paypal_api_username']; |
|
106 | + $new_gateway_settings['password'] = $old_gateway_settings['paypal_api_password']; |
|
107 | + $new_gateway_settings['signature'] = $old_gateway_settings['paypal_api_signature']; |
|
108 | + $new_gateway_settings['credit_cards'] = explode(",", $old_gateway_settings['paypal_api_credit_cards']); |
|
109 | + $new_gateway_settings['use_sandbox'] = $old_gateway_settings['paypal_pro_use_sandbox']; |
|
110 | + break; |
|
111 | + } |
|
112 | + return $new_gateway_settings; |
|
113 | + } |
|
114 | 114 | /** |
115 | - * Figures out the correct 3.1 gateway settings option name for the given 4.1 gateway |
|
116 | - * @param string $new_gateway_slug |
|
117 | - * @return string |
|
118 | - */ |
|
119 | - private function _get_old_gateway_option($new_gateway_slug) |
|
120 | - { |
|
121 | - $option_name = $this->_get_old_gateway_option_name($new_gateway_slug); |
|
122 | - $settings = get_option($option_name, null); |
|
123 | - // if( ! $settings){ |
|
124 | - // $this->add_error(sprintf(__("There is no wordpress option named %s for gateway %s", "event_espresso"),$option_name,$new_gateway_slug)); |
|
125 | - // } |
|
126 | - return $settings; |
|
127 | - } |
|
115 | + * Figures out the correct 3.1 gateway settings option name for the given 4.1 gateway |
|
116 | + * @param string $new_gateway_slug |
|
117 | + * @return string |
|
118 | + */ |
|
119 | + private function _get_old_gateway_option($new_gateway_slug) |
|
120 | + { |
|
121 | + $option_name = $this->_get_old_gateway_option_name($new_gateway_slug); |
|
122 | + $settings = get_option($option_name, null); |
|
123 | + // if( ! $settings){ |
|
124 | + // $this->add_error(sprintf(__("There is no wordpress option named %s for gateway %s", "event_espresso"),$option_name,$new_gateway_slug)); |
|
125 | + // } |
|
126 | + return $settings; |
|
127 | + } |
|
128 | 128 | |
129 | 129 | /** |
130 | 130 | * Just gets the old gateways slug |
131 | 131 | * @param string $new_gateway_slug |
132 | 132 | * @return string |
133 | 133 | */ |
134 | - private function _get_old_gateway_option_name($new_gateway_slug) |
|
135 | - { |
|
136 | - $new_gateway_slugs_to_new = array_flip(array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone)); |
|
137 | - $old_gateway_slug = $new_gateway_slugs_to_new[ $new_gateway_slug ]; |
|
138 | - $normal_option_prefix = 'event_espresso_'; |
|
139 | - $normal_option_postfix = '_settings'; |
|
140 | - switch ($new_gateway_slug) { |
|
141 | - case 'Bank': |
|
142 | - $option_name = $normal_option_prefix.'bank_deposit'.$normal_option_postfix; |
|
143 | - break; |
|
144 | - case 'Aim': |
|
145 | - $option_name = $normal_option_prefix.'authnet_aim'.$normal_option_postfix; |
|
146 | - break; |
|
147 | - case 'Check': |
|
148 | - $option_name = $normal_option_prefix.'check_payment'.$normal_option_postfix; |
|
149 | - break; |
|
150 | - case 'Ideal': |
|
151 | - $option_name = $normal_option_prefix.'ideal_mollie'.$normal_option_postfix; |
|
152 | - break; |
|
153 | - case 'Invoice': |
|
154 | - $option_name = $normal_option_prefix.'invoice_payment'.$normal_option_postfix; |
|
155 | - break; |
|
156 | - case 'Purchase_Order': |
|
157 | - $option_name = $normal_option_prefix.'purchase_order_payment'.$normal_option_postfix; |
|
158 | - break; |
|
159 | - case 'USAePay_Offsite': |
|
160 | - $option_name = 'espresso_usaepay_offsite'.$normal_option_postfix; |
|
161 | - break; |
|
162 | - case 'USAePay_Onsite': |
|
163 | - $option_name = 'espresso_usaepay_onsite'.$normal_option_postfix; |
|
164 | - break; |
|
165 | - default: |
|
166 | - $option_name = apply_filters('FHEE__EE_DMS_4_1_0_gateways__get_old_gateway_option', $normal_option_prefix.$old_gateway_slug.$normal_option_postfix); |
|
167 | - } |
|
168 | - return $option_name; |
|
169 | - } |
|
134 | + private function _get_old_gateway_option_name($new_gateway_slug) |
|
135 | + { |
|
136 | + $new_gateway_slugs_to_new = array_flip(array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone)); |
|
137 | + $old_gateway_slug = $new_gateway_slugs_to_new[ $new_gateway_slug ]; |
|
138 | + $normal_option_prefix = 'event_espresso_'; |
|
139 | + $normal_option_postfix = '_settings'; |
|
140 | + switch ($new_gateway_slug) { |
|
141 | + case 'Bank': |
|
142 | + $option_name = $normal_option_prefix.'bank_deposit'.$normal_option_postfix; |
|
143 | + break; |
|
144 | + case 'Aim': |
|
145 | + $option_name = $normal_option_prefix.'authnet_aim'.$normal_option_postfix; |
|
146 | + break; |
|
147 | + case 'Check': |
|
148 | + $option_name = $normal_option_prefix.'check_payment'.$normal_option_postfix; |
|
149 | + break; |
|
150 | + case 'Ideal': |
|
151 | + $option_name = $normal_option_prefix.'ideal_mollie'.$normal_option_postfix; |
|
152 | + break; |
|
153 | + case 'Invoice': |
|
154 | + $option_name = $normal_option_prefix.'invoice_payment'.$normal_option_postfix; |
|
155 | + break; |
|
156 | + case 'Purchase_Order': |
|
157 | + $option_name = $normal_option_prefix.'purchase_order_payment'.$normal_option_postfix; |
|
158 | + break; |
|
159 | + case 'USAePay_Offsite': |
|
160 | + $option_name = 'espresso_usaepay_offsite'.$normal_option_postfix; |
|
161 | + break; |
|
162 | + case 'USAePay_Onsite': |
|
163 | + $option_name = 'espresso_usaepay_onsite'.$normal_option_postfix; |
|
164 | + break; |
|
165 | + default: |
|
166 | + $option_name = apply_filters('FHEE__EE_DMS_4_1_0_gateways__get_old_gateway_option', $normal_option_prefix.$old_gateway_slug.$normal_option_postfix); |
|
167 | + } |
|
168 | + return $option_name; |
|
169 | + } |
|
170 | 170 | |
171 | - private function _convert_active_gateways() |
|
172 | - { |
|
173 | - // just does it all one big swoop |
|
174 | - $old_active_gateways = get_option('event_espresso_active_gateways'); |
|
175 | - $new_active_gateways = EE_Config::instance()->gateway->active_gateways; |
|
176 | - foreach ($old_active_gateways as $old_gateway_slug => $filepath) { |
|
177 | - if (! isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) { |
|
178 | - $this->add_error(sprintf(__("The %s gateway does not exist in EE 4.1", "event_espresso"), $old_gateway_slug)); |
|
179 | - continue; |
|
180 | - } |
|
181 | - $new_gateway_slug = $this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ]; |
|
171 | + private function _convert_active_gateways() |
|
172 | + { |
|
173 | + // just does it all one big swoop |
|
174 | + $old_active_gateways = get_option('event_espresso_active_gateways'); |
|
175 | + $new_active_gateways = EE_Config::instance()->gateway->active_gateways; |
|
176 | + foreach ($old_active_gateways as $old_gateway_slug => $filepath) { |
|
177 | + if (! isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) { |
|
178 | + $this->add_error(sprintf(__("The %s gateway does not exist in EE 4.1", "event_espresso"), $old_gateway_slug)); |
|
179 | + continue; |
|
180 | + } |
|
181 | + $new_gateway_slug = $this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ]; |
|
182 | 182 | |
183 | - // in the new format we can also upload gateways to the uploads directory and |
|
184 | - $new_active_gateways[ $new_gateway_slug ] = false; |
|
185 | - } |
|
186 | - EE_Config::instance()->gateway->active_gateways = $new_active_gateways; |
|
187 | - } |
|
183 | + // in the new format we can also upload gateways to the uploads directory and |
|
184 | + $new_active_gateways[ $new_gateway_slug ] = false; |
|
185 | + } |
|
186 | + EE_Config::instance()->gateway->active_gateways = $new_active_gateways; |
|
187 | + } |
|
188 | 188 | |
189 | - protected $_gateways_we_know_how_to_migrate = array( |
|
190 | - 'aim'=>'Aim', |
|
191 | - 'bank'=>'Bank', |
|
192 | - 'check'=>'Check', |
|
193 | - 'invoice'=>'Invoice', |
|
194 | - 'paypal'=>'Paypal_Standard', |
|
195 | - 'paypal_pro'=>'Paypal_Pro', |
|
189 | + protected $_gateways_we_know_how_to_migrate = array( |
|
190 | + 'aim'=>'Aim', |
|
191 | + 'bank'=>'Bank', |
|
192 | + 'check'=>'Check', |
|
193 | + 'invoice'=>'Invoice', |
|
194 | + 'paypal'=>'Paypal_Standard', |
|
195 | + 'paypal_pro'=>'Paypal_Pro', |
|
196 | 196 | |
197 | - ); |
|
197 | + ); |
|
198 | 198 | |
199 | - protected $_gateways_we_leave_alone = array( |
|
200 | - '2checkout'=>'2checkout', |
|
201 | - 'anz'=>'Anz', |
|
202 | - 'atos'=>'Atos', |
|
203 | - 'authnet'=>'Authnet', |
|
204 | - 'beanstream'=>'Beanstream', |
|
205 | - 'evertec'=>'Evertec', |
|
206 | - 'eway'=>'Eway', |
|
207 | - 'eway_rapid3'=>'Eway_Rapid3', |
|
208 | - 'exact'=>'Exact', |
|
209 | - 'firstdata'=>'Firstdata', |
|
210 | - 'firstdat_e4'=>'Firstdata_E4', |
|
211 | - 'ideal'=>'Ideal', |
|
212 | - 'infusion_payment'=>'InfusionSoft', |
|
213 | - 'luottokunta'=>'Luottokunta', |
|
214 | - 'megasoft'=>'Megasoft', |
|
215 | - 'moneris_hpp'=>'Moneris_HPP', |
|
216 | - 'mwarrior'=>'Mwarrior', |
|
217 | - 'nab'=>'NAB', |
|
218 | - 'paychoice'=>'Paychoice', |
|
219 | - 'paytrace'=>'Paytrace', |
|
220 | - 'psigate'=>'Psigate', |
|
221 | - 'purchase_order'=>'Purchase_Order', |
|
222 | - 'qbms'=>'QBMS', |
|
223 | - 'quickpay'=>'Quickpay', |
|
224 | - 'realauth'=>'Realauth', |
|
225 | - 'securepay_aus'=>'Securepay_Aus', |
|
226 | - 'stripe'=>'Stripe', |
|
227 | - 'usaepay_offsite'=>'USAePay_Offsite', |
|
228 | - 'usaepay_onsite'=>'USAePay_Onsite', |
|
229 | - 'wepay'=>'Wepay', |
|
230 | - 'worldpay'=>'Worldpay' |
|
231 | - ); |
|
199 | + protected $_gateways_we_leave_alone = array( |
|
200 | + '2checkout'=>'2checkout', |
|
201 | + 'anz'=>'Anz', |
|
202 | + 'atos'=>'Atos', |
|
203 | + 'authnet'=>'Authnet', |
|
204 | + 'beanstream'=>'Beanstream', |
|
205 | + 'evertec'=>'Evertec', |
|
206 | + 'eway'=>'Eway', |
|
207 | + 'eway_rapid3'=>'Eway_Rapid3', |
|
208 | + 'exact'=>'Exact', |
|
209 | + 'firstdata'=>'Firstdata', |
|
210 | + 'firstdat_e4'=>'Firstdata_E4', |
|
211 | + 'ideal'=>'Ideal', |
|
212 | + 'infusion_payment'=>'InfusionSoft', |
|
213 | + 'luottokunta'=>'Luottokunta', |
|
214 | + 'megasoft'=>'Megasoft', |
|
215 | + 'moneris_hpp'=>'Moneris_HPP', |
|
216 | + 'mwarrior'=>'Mwarrior', |
|
217 | + 'nab'=>'NAB', |
|
218 | + 'paychoice'=>'Paychoice', |
|
219 | + 'paytrace'=>'Paytrace', |
|
220 | + 'psigate'=>'Psigate', |
|
221 | + 'purchase_order'=>'Purchase_Order', |
|
222 | + 'qbms'=>'QBMS', |
|
223 | + 'quickpay'=>'Quickpay', |
|
224 | + 'realauth'=>'Realauth', |
|
225 | + 'securepay_aus'=>'Securepay_Aus', |
|
226 | + 'stripe'=>'Stripe', |
|
227 | + 'usaepay_offsite'=>'USAePay_Offsite', |
|
228 | + 'usaepay_onsite'=>'USAePay_Onsite', |
|
229 | + 'wepay'=>'Wepay', |
|
230 | + 'worldpay'=>'Worldpay' |
|
231 | + ); |
|
232 | 232 | } |