@@ -14,110 +14,110 @@ |
||
14 | 14 | |
15 | 15 | |
16 | 16 | |
17 | - /** |
|
18 | - * Just initializes the status of the migration |
|
19 | - */ |
|
20 | - public function __construct() |
|
21 | - { |
|
22 | - global $wpdb; |
|
23 | - $this->_pretty_name = __('Event-Question Group Relations', 'event_espresso'); |
|
24 | - $this->_old_table = $wpdb->prefix.'esp_event_question_group'; |
|
25 | - $this->_extra_where_sql = "WHERE EQG_primary = 0 AND EQG_additional=0"; |
|
26 | - parent::__construct(); |
|
27 | - } |
|
17 | + /** |
|
18 | + * Just initializes the status of the migration |
|
19 | + */ |
|
20 | + public function __construct() |
|
21 | + { |
|
22 | + global $wpdb; |
|
23 | + $this->_pretty_name = __('Event-Question Group Relations', 'event_espresso'); |
|
24 | + $this->_old_table = $wpdb->prefix.'esp_event_question_group'; |
|
25 | + $this->_extra_where_sql = "WHERE EQG_primary = 0 AND EQG_additional=0"; |
|
26 | + parent::__construct(); |
|
27 | + } |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * Removes the duplicate event_question_group rows that only had EQG_primary=0. Now we just have one row |
|
32 | - * joining event-to-question-groups with two columns: EQG_primary and EQG_additional, indicating which question |
|
33 | - * groups apply to which category of registrant. |
|
34 | - * @param array $event_question_group an associative array where keys are column names and values are their values. |
|
35 | - * @return null |
|
36 | - */ |
|
37 | - protected function _migrate_old_row($event_question_group) |
|
38 | - { |
|
39 | - if (isset($event_question_group['EVT_ID'], $event_question_group['QSG_ID'])) { |
|
40 | - global $wpdb; |
|
41 | - $success = $wpdb->update( |
|
42 | - $this->_old_table, |
|
43 | - ['EQG_additional' => true], // data |
|
44 | - [ |
|
45 | - 'EVT_ID' => $event_question_group['EVT_ID'], |
|
46 | - 'QSG_ID' => $event_question_group['QSG_ID'] |
|
47 | - ], // where |
|
48 | - array( '%d' ), // data format |
|
49 | - array( '%d', '%d' ) // where format |
|
50 | - ); |
|
51 | - if (! $success) { |
|
52 | - $this->add_error( |
|
53 | - sprintf( |
|
54 | - __('Could not update event-question group relation for event "%1$s" and question group "%2$s" because "%3$s"', 'event_espresso'), |
|
55 | - $event_question_group['EVT_ID'], |
|
56 | - $event_question_group['QSG_ID'], |
|
57 | - $wpdb->last_error |
|
58 | - ) |
|
59 | - ); |
|
60 | - } |
|
61 | - // and delete the old row |
|
62 | - $successful_delete = $wpdb->delete( |
|
63 | - $this->_old_table, |
|
64 | - [ |
|
65 | - 'EQG_ID' => $event_question_group['EQG_ID'] |
|
66 | - ], |
|
67 | - ['%d'] |
|
68 | - ); |
|
69 | - if (! $successful_delete) { |
|
70 | - $this->add_error( |
|
71 | - sprintf( |
|
72 | - __('Could not delete old event-question group relation row "%1$s" because "%2$s"', 'event_espresso'), |
|
73 | - wp_json_encode($event_question_group), |
|
74 | - $wpdb->last_error |
|
75 | - ) |
|
76 | - ); |
|
77 | - } |
|
78 | - } |
|
79 | - } |
|
30 | + /** |
|
31 | + * Removes the duplicate event_question_group rows that only had EQG_primary=0. Now we just have one row |
|
32 | + * joining event-to-question-groups with two columns: EQG_primary and EQG_additional, indicating which question |
|
33 | + * groups apply to which category of registrant. |
|
34 | + * @param array $event_question_group an associative array where keys are column names and values are their values. |
|
35 | + * @return null |
|
36 | + */ |
|
37 | + protected function _migrate_old_row($event_question_group) |
|
38 | + { |
|
39 | + if (isset($event_question_group['EVT_ID'], $event_question_group['QSG_ID'])) { |
|
40 | + global $wpdb; |
|
41 | + $success = $wpdb->update( |
|
42 | + $this->_old_table, |
|
43 | + ['EQG_additional' => true], // data |
|
44 | + [ |
|
45 | + 'EVT_ID' => $event_question_group['EVT_ID'], |
|
46 | + 'QSG_ID' => $event_question_group['QSG_ID'] |
|
47 | + ], // where |
|
48 | + array( '%d' ), // data format |
|
49 | + array( '%d', '%d' ) // where format |
|
50 | + ); |
|
51 | + if (! $success) { |
|
52 | + $this->add_error( |
|
53 | + sprintf( |
|
54 | + __('Could not update event-question group relation for event "%1$s" and question group "%2$s" because "%3$s"', 'event_espresso'), |
|
55 | + $event_question_group['EVT_ID'], |
|
56 | + $event_question_group['QSG_ID'], |
|
57 | + $wpdb->last_error |
|
58 | + ) |
|
59 | + ); |
|
60 | + } |
|
61 | + // and delete the old row |
|
62 | + $successful_delete = $wpdb->delete( |
|
63 | + $this->_old_table, |
|
64 | + [ |
|
65 | + 'EQG_ID' => $event_question_group['EQG_ID'] |
|
66 | + ], |
|
67 | + ['%d'] |
|
68 | + ); |
|
69 | + if (! $successful_delete) { |
|
70 | + $this->add_error( |
|
71 | + sprintf( |
|
72 | + __('Could not delete old event-question group relation row "%1$s" because "%2$s"', 'event_espresso'), |
|
73 | + wp_json_encode($event_question_group), |
|
74 | + $wpdb->last_error |
|
75 | + ) |
|
76 | + ); |
|
77 | + } |
|
78 | + } |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Gets the rows for the existing table that shouldn't exist in 4.10. |
|
83 | - * Specifically the rows where EQG_primary=false and EQG_additional=false. |
|
84 | - * Gotcha: because the migration is REMOVING rows as it goes, we shouldn't use the offset. |
|
85 | - * |
|
86 | - * @global wpdb $wpdb |
|
87 | - * @param int $limit |
|
88 | - * @return array of arrays like $wpdb->get_results($sql, ARRAY_A) |
|
89 | - */ |
|
90 | - protected function _get_rows($limit) |
|
91 | - { |
|
92 | - global $wpdb; |
|
93 | - $query = "SELECT * FROM {$this->_old_table} {$this->_extra_where_sql} " . $wpdb->prepare( |
|
94 | - "LIMIT %d", |
|
95 | - $limit |
|
96 | - ); |
|
97 | - return $wpdb->get_results($query, ARRAY_A); |
|
98 | - } |
|
81 | + /** |
|
82 | + * Gets the rows for the existing table that shouldn't exist in 4.10. |
|
83 | + * Specifically the rows where EQG_primary=false and EQG_additional=false. |
|
84 | + * Gotcha: because the migration is REMOVING rows as it goes, we shouldn't use the offset. |
|
85 | + * |
|
86 | + * @global wpdb $wpdb |
|
87 | + * @param int $limit |
|
88 | + * @return array of arrays like $wpdb->get_results($sql, ARRAY_A) |
|
89 | + */ |
|
90 | + protected function _get_rows($limit) |
|
91 | + { |
|
92 | + global $wpdb; |
|
93 | + $query = "SELECT * FROM {$this->_old_table} {$this->_extra_where_sql} " . $wpdb->prepare( |
|
94 | + "LIMIT %d", |
|
95 | + $limit |
|
96 | + ); |
|
97 | + return $wpdb->get_results($query, ARRAY_A); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * Slight departure from the normal procedure here: because this removes rows from the DB, we need to ensure |
|
102 | - * we count the records first, then do the migration. |
|
103 | - * |
|
104 | - * @param int $num_items |
|
105 | - * @return int number of items ACTUALLY migrated |
|
106 | - */ |
|
107 | - public function _migration_step($num_items = 50) |
|
108 | - { |
|
109 | - // Count the items right away. This migration step will be removing those rows, so we need to count them |
|
110 | - // right away to get an accurate count. |
|
111 | - $this->count_records_to_migrate(); |
|
112 | - $rows = $this->_get_rows($num_items); |
|
113 | - $items_actually_migrated = 0; |
|
114 | - foreach ($rows as $old_row) { |
|
115 | - $this->_migrate_old_row($old_row); |
|
116 | - $items_actually_migrated++; |
|
117 | - } |
|
118 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
119 | - $this->set_completed(); |
|
120 | - } |
|
121 | - return $items_actually_migrated; |
|
122 | - } |
|
100 | + /** |
|
101 | + * Slight departure from the normal procedure here: because this removes rows from the DB, we need to ensure |
|
102 | + * we count the records first, then do the migration. |
|
103 | + * |
|
104 | + * @param int $num_items |
|
105 | + * @return int number of items ACTUALLY migrated |
|
106 | + */ |
|
107 | + public function _migration_step($num_items = 50) |
|
108 | + { |
|
109 | + // Count the items right away. This migration step will be removing those rows, so we need to count them |
|
110 | + // right away to get an accurate count. |
|
111 | + $this->count_records_to_migrate(); |
|
112 | + $rows = $this->_get_rows($num_items); |
|
113 | + $items_actually_migrated = 0; |
|
114 | + foreach ($rows as $old_row) { |
|
115 | + $this->_migrate_old_row($old_row); |
|
116 | + $items_actually_migrated++; |
|
117 | + } |
|
118 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
119 | + $this->set_completed(); |
|
120 | + } |
|
121 | + return $items_actually_migrated; |
|
122 | + } |
|
123 | 123 | } |