@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
136 | 136 | { |
137 | 137 | $this->_migration_stages = (array) apply_filters( |
138 | - 'FHEE__' . get_class($this) . '__construct__migration_stages', |
|
138 | + 'FHEE__'.get_class($this).'__construct__migration_stages', |
|
139 | 139 | $this->_migration_stages |
140 | 140 | ); |
141 | 141 | foreach ($this->_migration_stages as $migration_stage) { |
@@ -170,10 +170,10 @@ discard block |
||
170 | 170 | public function set_mapping($old_table, $old_pk, $new_table, $new_pk) |
171 | 171 | { |
172 | 172 | // make sure it has the needed keys |
173 | - if (! isset($this->_mappings[ $old_table ]) || ! isset($this->_mappings[ $old_table ][ $new_table ])) { |
|
174 | - $this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table); |
|
173 | + if ( ! isset($this->_mappings[$old_table]) || ! isset($this->_mappings[$old_table][$new_table])) { |
|
174 | + $this->_mappings[$old_table][$new_table] = $this->_get_mapping_option($old_table, $new_table); |
|
175 | 175 | } |
176 | - $this->_mappings[ $old_table ][ $new_table ][ $old_pk ] = $new_pk; |
|
176 | + $this->_mappings[$old_table][$new_table][$old_pk] = $new_pk; |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | |
@@ -189,14 +189,14 @@ discard block |
||
189 | 189 | public function get_mapping_new_pk($old_table, $old_pk, $new_table) |
190 | 190 | { |
191 | 191 | if ( |
192 | - ! isset($this->_mappings[ $old_table ]) || |
|
193 | - ! isset($this->_mappings[ $old_table ][ $new_table ]) |
|
192 | + ! isset($this->_mappings[$old_table]) || |
|
193 | + ! isset($this->_mappings[$old_table][$new_table]) |
|
194 | 194 | ) { |
195 | 195 | // try fetching the option |
196 | - $this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table); |
|
196 | + $this->_mappings[$old_table][$new_table] = $this->_get_mapping_option($old_table, $new_table); |
|
197 | 197 | } |
198 | - return isset($this->_mappings[ $old_table ][ $new_table ][ $old_pk ]) |
|
199 | - ? $this->_mappings[ $old_table ][ $new_table ][ $old_pk ] : null; |
|
198 | + return isset($this->_mappings[$old_table][$new_table][$old_pk]) |
|
199 | + ? $this->_mappings[$old_table][$new_table][$old_pk] : null; |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | |
@@ -212,16 +212,16 @@ discard block |
||
212 | 212 | public function get_mapping_old_pk($old_table, $new_table, $new_pk) |
213 | 213 | { |
214 | 214 | if ( |
215 | - ! isset($this->_mappings[ $old_table ]) || |
|
216 | - ! isset($this->_mappings[ $old_table ][ $new_table ]) |
|
215 | + ! isset($this->_mappings[$old_table]) || |
|
216 | + ! isset($this->_mappings[$old_table][$new_table]) |
|
217 | 217 | ) { |
218 | 218 | // try fetching the option |
219 | - $this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table); |
|
219 | + $this->_mappings[$old_table][$new_table] = $this->_get_mapping_option($old_table, $new_table); |
|
220 | 220 | } |
221 | - if (isset($this->_mappings[ $old_table ][ $new_table ])) { |
|
222 | - $new_pk_to_old_pk = array_flip($this->_mappings[ $old_table ][ $new_table ]); |
|
223 | - if (isset($new_pk_to_old_pk[ $new_pk ])) { |
|
224 | - return $new_pk_to_old_pk[ $new_pk ]; |
|
221 | + if (isset($this->_mappings[$old_table][$new_table])) { |
|
222 | + $new_pk_to_old_pk = array_flip($this->_mappings[$old_table][$new_table]); |
|
223 | + if (isset($new_pk_to_old_pk[$new_pk])) { |
|
224 | + return $new_pk_to_old_pk[$new_pk]; |
|
225 | 225 | } |
226 | 226 | } |
227 | 227 | return null; |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | $new_table_name_sans_wp = str_replace($wpdb->prefix, "", $new_table_name); |
272 | 272 | $migrates_to = EE_Data_Migration_Manager::instance()->script_migrates_to_version(get_class($this)); |
273 | 273 | return substr( |
274 | - EE_Data_Migration_Manager::data_migration_script_mapping_option_prefix . $migrates_to ['slug'] . '_' . $migrates_to['version'] . '_' . $old_table_name_sans_wp . '_' . $new_table_name_sans_wp, |
|
274 | + EE_Data_Migration_Manager::data_migration_script_mapping_option_prefix.$migrates_to ['slug'].'_'.$migrates_to['version'].'_'.$old_table_name_sans_wp.'_'.$new_table_name_sans_wp, |
|
275 | 275 | 0, |
276 | 276 | 64 |
277 | 277 | ); |
@@ -343,12 +343,12 @@ discard block |
||
343 | 343 | $num_records_to_migrate_limit - $num_records_actually_migrated |
344 | 344 | ); |
345 | 345 | $num_records_actually_migrated += $records_migrated_during_stage; |
346 | - $records_migrated_per_stage[ $stage->pretty_name() ] = $records_migrated_during_stage; |
|
346 | + $records_migrated_per_stage[$stage->pretty_name()] = $records_migrated_during_stage; |
|
347 | 347 | } catch (Exception $e) { |
348 | 348 | // yes if we catch an exception here, we consider that migration stage borked. |
349 | 349 | $stage->set_status(EE_Data_Migration_Manager::status_fatal_error); |
350 | 350 | $this->set_status(EE_Data_Migration_Manager::status_fatal_error); |
351 | - $stage->add_error($e->getMessage() . ". Stack-trace:" . $e->getTraceAsString()); |
|
351 | + $stage->add_error($e->getMessage().". Stack-trace:".$e->getTraceAsString()); |
|
352 | 352 | throw $e; |
353 | 353 | } |
354 | 354 | // check that the migration stage didn't mark itself as having a fatal error |
@@ -421,8 +421,8 @@ discard block |
||
421 | 421 | private function _maybe_do_schema_changes($before = true) |
422 | 422 | { |
423 | 423 | // so this property will be either _schema_changes_after_migration_ran or _schema_changes_before_migration_ran |
424 | - $property_name = '_schema_changes_' . ($before ? 'before' : 'after') . '_migration_ran'; |
|
425 | - if (! $this->{$property_name}) { |
|
424 | + $property_name = '_schema_changes_'.($before ? 'before' : 'after').'_migration_ran'; |
|
425 | + if ( ! $this->{$property_name}) { |
|
426 | 426 | try { |
427 | 427 | ob_start(); |
428 | 428 | if ($before) { |
@@ -659,7 +659,7 @@ discard block |
||
659 | 659 | try { |
660 | 660 | EEH_Activation::create_table($table_name, $table_definition_sql, $engine_string, $drop_pre_existing_tables); |
661 | 661 | } catch (EE_Error $e) { |
662 | - $message = $e->getMessage() . '<br>Stack Trace:' . $e->getTraceAsString(); |
|
662 | + $message = $e->getMessage().'<br>Stack Trace:'.$e->getTraceAsString(); |
|
663 | 663 | $this->add_error($message); |
664 | 664 | $this->_feedback_message .= $message; |
665 | 665 | } |
@@ -705,7 +705,7 @@ discard block |
||
705 | 705 | public function get_errors() |
706 | 706 | { |
707 | 707 | $all_errors = $this->_errors; |
708 | - if (! is_array($all_errors)) { |
|
708 | + if ( ! is_array($all_errors)) { |
|
709 | 709 | $all_errors = array(); |
710 | 710 | } |
711 | 711 | foreach ($this->stages() as $stage) { |
@@ -739,7 +739,7 @@ discard block |
||
739 | 739 | */ |
740 | 740 | protected function stages() |
741 | 741 | { |
742 | - $stages = apply_filters('FHEE__' . get_class($this) . '__stages', $this->_migration_stages); |
|
742 | + $stages = apply_filters('FHEE__'.get_class($this).'__stages', $this->_migration_stages); |
|
743 | 743 | ksort($stages); |
744 | 744 | return $stages; |
745 | 745 | } |
@@ -768,7 +768,7 @@ discard block |
||
768 | 768 | $properties = parent::properties_as_array(); |
769 | 769 | $properties['_migration_stages'] = array(); |
770 | 770 | foreach ($this->_migration_stages as $migration_stage_priority => $migration_stage_class) { |
771 | - $properties['_migration_stages'][ $migration_stage_priority ] = $migration_stage_class->properties_as_array( |
|
771 | + $properties['_migration_stages'][$migration_stage_priority] = $migration_stage_class->properties_as_array( |
|
772 | 772 | ); |
773 | 773 | } |
774 | 774 | unset($properties['_mappings']); |
@@ -15,894 +15,894 @@ |
||
15 | 15 | abstract class EE_Data_Migration_Script_Base extends EE_Data_Migration_Class_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * Set by client code to indicate this DMS is being ran as part of a proper migration, |
|
20 | - * instead of being used to merely setup (or verify) the database structure. |
|
21 | - * Defaults to TRUE, so client code that's NOT using this DMS as part of a proper migration |
|
22 | - * should call EE_Data_Migration_Script_Base::set_migrating( FALSE ) |
|
23 | - * |
|
24 | - * @var boolean |
|
25 | - */ |
|
26 | - protected $_migrating = true; |
|
27 | - |
|
28 | - /** |
|
29 | - * numerically-indexed array where each value is EE_Data_Migration_Script_Stage object |
|
30 | - * |
|
31 | - * @var EE_Data_Migration_Script_Stage[] $migration_functions |
|
32 | - */ |
|
33 | - protected $_migration_stages = array(); |
|
34 | - |
|
35 | - /** |
|
36 | - * Indicates we've already ran the schema changes that needed to happen BEFORE the data migration |
|
37 | - * |
|
38 | - * @var boolean |
|
39 | - */ |
|
40 | - protected $_schema_changes_before_migration_ran = null; |
|
41 | - |
|
42 | - /** |
|
43 | - * Indicates we've already ran the schema changes that needed to happen AFTER the data migration |
|
44 | - * |
|
45 | - * @var boolean |
|
46 | - */ |
|
47 | - protected $_schema_changes_after_migration_ran = null; |
|
48 | - |
|
49 | - /** |
|
50 | - * String which describes what's currently happening in this migration |
|
51 | - * |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - protected $_feedback_message; |
|
55 | - |
|
56 | - /** |
|
57 | - * Indicates the script's priority. Like wp's add_action and add_filter, lower numbers |
|
58 | - * correspond to earlier execution |
|
59 | - * |
|
60 | - * @var int |
|
61 | - */ |
|
62 | - protected $_priority = 5; |
|
63 | - |
|
64 | - /** |
|
65 | - * Multi-dimensional array that defines the mapping from OLD table Primary Keys |
|
66 | - * to NEW table Primary Keys. |
|
67 | - * Top-level array keys are OLD table names (minus the "wp_" part), |
|
68 | - * 2nd-level array keys are NEW table names (again, minus the "wp_" part), |
|
69 | - * 3rd-level array keys are the OLD table primary keys |
|
70 | - * and 3rd-level array values are the NEW table primary keys |
|
71 | - * |
|
72 | - * @var array |
|
73 | - */ |
|
74 | - protected $_mappings = array(); |
|
75 | - |
|
76 | - /** |
|
77 | - * @var EE_Data_Migration_Script_Base |
|
78 | - */ |
|
79 | - protected $previous_dms; |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * Returns whether or not this data migration script can operate on the given version of the database. |
|
84 | - * Eg, if this migration script can migrate from 3.1.26 or higher (but not anything after 4.0.0), and |
|
85 | - * it's passed a string like '3.1.38B', it should return true. |
|
86 | - * If this DMS is to migrate data from an EE3 addon, you will probably want to use |
|
87 | - * EventEspresso\core\services\database\TableAnalysis::tableExists() to check for old EE3 tables, and |
|
88 | - * EE_Data_Migration_Manager::get_migration_ran() to check that core was already |
|
89 | - * migrated from EE3 to EE4 (ie, this DMS probably relies on some migration data generated |
|
90 | - * during the Core 4.1.0 DMS. If core didn't run that DMS, you probably don't want |
|
91 | - * to run this DMS). |
|
92 | - * If this DMS migrates data from a previous version of this EE4 addon, just |
|
93 | - * comparing $current_database_state_of[ $this->slug() ] will probably suffice. |
|
94 | - * If this DMS should never migrate data, because it's only used to define the initial |
|
95 | - * database state, just return FALSE (and core's activation process will take care |
|
96 | - * of calling its schema_changes_before_migration() and |
|
97 | - * schema_changes_after_migration() for you. ) |
|
98 | - * |
|
99 | - * @param array $current_database_state_of keys are EE plugin slugs (eg 'Core', 'Calendar', 'Mailchimp', etc) |
|
100 | - * @return boolean |
|
101 | - */ |
|
102 | - abstract public function can_migrate_from_version($current_database_state_of); |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * Performs database schema changes that need to occur BEFORE the data is migrated. |
|
107 | - * Eg, if we were going to change user passwords from plaintext to encoded versions |
|
108 | - * during this migration, this would probably add a new column called something like |
|
109 | - * "encoded_password". |
|
110 | - * |
|
111 | - * @return boolean of success |
|
112 | - */ |
|
113 | - abstract public function schema_changes_before_migration(); |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * Performs the database schema changes that need to occur AFTER the data has been migrated. |
|
118 | - * Usually this will mean we'll be removing old columns. Eg, if we were changing passwords |
|
119 | - * from plaintext to encoded versions, and we had added a column called "encoded_password", |
|
120 | - * this function would probably remove the old column "password" (which still holds the plaintext password) |
|
121 | - * and possibly rename "encoded_password" to "password" |
|
122 | - * |
|
123 | - * @return boolean of success |
|
124 | - */ |
|
125 | - abstract public function schema_changes_after_migration(); |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * All children of this must call parent::__construct() |
|
130 | - * at the end of their constructor or suffer the consequences! |
|
131 | - * |
|
132 | - * @param TableManager $table_manager |
|
133 | - * @param TableAnalysis $table_analysis |
|
134 | - */ |
|
135 | - public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
136 | - { |
|
137 | - $this->_migration_stages = (array) apply_filters( |
|
138 | - 'FHEE__' . get_class($this) . '__construct__migration_stages', |
|
139 | - $this->_migration_stages |
|
140 | - ); |
|
141 | - foreach ($this->_migration_stages as $migration_stage) { |
|
142 | - if ($migration_stage instanceof EE_Data_Migration_Script_Stage) { |
|
143 | - $migration_stage->_construct_finalize($this); |
|
144 | - } |
|
145 | - } |
|
146 | - parent::__construct($table_manager, $table_analysis); |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * Place to add hooks and filters for tweaking the migrations page, in order |
|
152 | - * to customize it |
|
153 | - */ |
|
154 | - public function migration_page_hooks() |
|
155 | - { |
|
156 | - // by default none are added because we normally like the default look of the migration page |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * Sets the mapping from old table primary keys to new table primary keys. |
|
162 | - * This mapping is automatically persisted as a property on the migration |
|
163 | - * |
|
164 | - * @param string $old_table with wpdb prefix (wp_). Eg: wp_events_detail |
|
165 | - * @param int|string $old_pk old primary key. Eg events_detail.id's value |
|
166 | - * @param string $new_table with wpdb prefix (wp_). Eg: wp_posts |
|
167 | - * @param int|string $new_pk eg posts.ID |
|
168 | - * @return void |
|
169 | - */ |
|
170 | - public function set_mapping($old_table, $old_pk, $new_table, $new_pk) |
|
171 | - { |
|
172 | - // make sure it has the needed keys |
|
173 | - if (! isset($this->_mappings[ $old_table ]) || ! isset($this->_mappings[ $old_table ][ $new_table ])) { |
|
174 | - $this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table); |
|
175 | - } |
|
176 | - $this->_mappings[ $old_table ][ $new_table ][ $old_pk ] = $new_pk; |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * Gets the new primary key, if provided with the OLD table and the primary key |
|
182 | - * of an item in the old table, and the new table |
|
183 | - * |
|
184 | - * @param string $old_table with wpdb prefix (wp_). Eg: wp_events_detail |
|
185 | - * @param int|string $old_pk old primary key. Eg events_detail.id's value |
|
186 | - * @param string $new_table with wpdb prefix (wp_). Eg: wp_posts |
|
187 | - * @return mixed the primary key on the new table |
|
188 | - */ |
|
189 | - public function get_mapping_new_pk($old_table, $old_pk, $new_table) |
|
190 | - { |
|
191 | - if ( |
|
192 | - ! isset($this->_mappings[ $old_table ]) || |
|
193 | - ! isset($this->_mappings[ $old_table ][ $new_table ]) |
|
194 | - ) { |
|
195 | - // try fetching the option |
|
196 | - $this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table); |
|
197 | - } |
|
198 | - return isset($this->_mappings[ $old_table ][ $new_table ][ $old_pk ]) |
|
199 | - ? $this->_mappings[ $old_table ][ $new_table ][ $old_pk ] : null; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * Gets the old primary key, if provided with the OLD table, |
|
205 | - * and the new table and the primary key of an item in the new table |
|
206 | - * |
|
207 | - * @param string $old_table with wpdb prefix (wp_). Eg: wp_events_detail |
|
208 | - * @param string $new_table with wpdb prefix (wp_). Eg: wp_posts |
|
209 | - * @param mixed $new_pk |
|
210 | - * @return mixed |
|
211 | - */ |
|
212 | - public function get_mapping_old_pk($old_table, $new_table, $new_pk) |
|
213 | - { |
|
214 | - if ( |
|
215 | - ! isset($this->_mappings[ $old_table ]) || |
|
216 | - ! isset($this->_mappings[ $old_table ][ $new_table ]) |
|
217 | - ) { |
|
218 | - // try fetching the option |
|
219 | - $this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table); |
|
220 | - } |
|
221 | - if (isset($this->_mappings[ $old_table ][ $new_table ])) { |
|
222 | - $new_pk_to_old_pk = array_flip($this->_mappings[ $old_table ][ $new_table ]); |
|
223 | - if (isset($new_pk_to_old_pk[ $new_pk ])) { |
|
224 | - return $new_pk_to_old_pk[ $new_pk ]; |
|
225 | - } |
|
226 | - } |
|
227 | - return null; |
|
228 | - } |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * Gets the mapping array option specified by the table names |
|
233 | - * |
|
234 | - * @param string $old_table_name |
|
235 | - * @param string $new_table_name |
|
236 | - * @return array |
|
237 | - */ |
|
238 | - protected function _get_mapping_option($old_table_name, $new_table_name) |
|
239 | - { |
|
240 | - $option = get_option($this->_get_mapping_option_name($old_table_name, $new_table_name), array()); |
|
241 | - return $option; |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * Updates the mapping option specified by the table names with the array provided |
|
247 | - * |
|
248 | - * @param string $old_table_name |
|
249 | - * @param string $new_table_name |
|
250 | - * @param array $mapping_array |
|
251 | - * @return boolean success of updating option |
|
252 | - */ |
|
253 | - protected function _set_mapping_option($old_table_name, $new_table_name, $mapping_array) |
|
254 | - { |
|
255 | - $success = update_option($this->_get_mapping_option_name($old_table_name, $new_table_name), $mapping_array, false); |
|
256 | - return $success; |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * Gets the option name for this script to map from $old_table_name to $new_table_name |
|
262 | - * |
|
263 | - * @param string $old_table_name |
|
264 | - * @param string $new_table_name |
|
265 | - * @return string |
|
266 | - */ |
|
267 | - protected function _get_mapping_option_name($old_table_name, $new_table_name) |
|
268 | - { |
|
269 | - global $wpdb; |
|
270 | - $old_table_name_sans_wp = str_replace($wpdb->prefix, "", $old_table_name); |
|
271 | - $new_table_name_sans_wp = str_replace($wpdb->prefix, "", $new_table_name); |
|
272 | - $migrates_to = EE_Data_Migration_Manager::instance()->script_migrates_to_version(get_class($this)); |
|
273 | - return substr( |
|
274 | - EE_Data_Migration_Manager::data_migration_script_mapping_option_prefix . $migrates_to ['slug'] . '_' . $migrates_to['version'] . '_' . $old_table_name_sans_wp . '_' . $new_table_name_sans_wp, |
|
275 | - 0, |
|
276 | - 64 |
|
277 | - ); |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * Counts all the records that will be migrated during this data migration. |
|
283 | - * For example, if we were changing old user passwords from plaintext to encoded versions, |
|
284 | - * this would be a count of all users who have passwords. If we were going to also split |
|
285 | - * attendee records into transactions, registrations, and attendee records, this would include |
|
286 | - * the count of all attendees currently in existence in the DB (ie, users + attendees). |
|
287 | - * If you can't determine how many records there are to migrate, just provide a guess: this |
|
288 | - * number will only be used in calculating the percent complete. If you estimate there to be |
|
289 | - * 100 records to migrate, and it turns out there's 120, we'll just show the migration as being at |
|
290 | - * 99% until the function "migration_step" returns EE_Data_Migration_Script_Base::status_complete. |
|
291 | - * |
|
292 | - * @return int |
|
293 | - */ |
|
294 | - protected function _count_records_to_migrate() |
|
295 | - { |
|
296 | - $count = 0; |
|
297 | - foreach ($this->stages() as $stage) { |
|
298 | - $count += $stage->count_records_to_migrate(); |
|
299 | - } |
|
300 | - return $count; |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * Returns the number of records updated so far. Usually this is easiest to do |
|
306 | - * by just setting a transient and updating it after each migration_step |
|
307 | - * |
|
308 | - * @return int |
|
309 | - */ |
|
310 | - public function count_records_migrated() |
|
311 | - { |
|
312 | - $count = 0; |
|
313 | - foreach ($this->stages() as $stage) { |
|
314 | - $count += $stage->count_records_migrated(); |
|
315 | - } |
|
316 | - $this->_records_migrated = $count; |
|
317 | - return $count; |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - /** |
|
322 | - * @param int $num_records_to_migrate_limit |
|
323 | - * @return int |
|
324 | - * @throws EE_Error |
|
325 | - * @throws Exception |
|
326 | - */ |
|
327 | - public function migration_step($num_records_to_migrate_limit) |
|
328 | - { |
|
329 | - // reset the feedback message |
|
330 | - $this->_feedback_message = ''; |
|
331 | - // if we haven't yet done the 1st schema changes, do them now. buffer any output |
|
332 | - $this->_maybe_do_schema_changes(true); |
|
333 | - |
|
334 | - $num_records_actually_migrated = 0; |
|
335 | - $records_migrated_per_stage = array(); |
|
336 | - // setup the 'stage' variable, which should hold the last run stage of the migration (or none at all if nothing runs) |
|
337 | - $stage = null; |
|
338 | - // get the next stage that isn't complete |
|
339 | - foreach ($this->stages() as $stage) { |
|
340 | - if ($stage->get_status() == EE_Data_Migration_Manager::status_continue) { |
|
341 | - try { |
|
342 | - $records_migrated_during_stage = $stage->migration_step( |
|
343 | - $num_records_to_migrate_limit - $num_records_actually_migrated |
|
344 | - ); |
|
345 | - $num_records_actually_migrated += $records_migrated_during_stage; |
|
346 | - $records_migrated_per_stage[ $stage->pretty_name() ] = $records_migrated_during_stage; |
|
347 | - } catch (Exception $e) { |
|
348 | - // yes if we catch an exception here, we consider that migration stage borked. |
|
349 | - $stage->set_status(EE_Data_Migration_Manager::status_fatal_error); |
|
350 | - $this->set_status(EE_Data_Migration_Manager::status_fatal_error); |
|
351 | - $stage->add_error($e->getMessage() . ". Stack-trace:" . $e->getTraceAsString()); |
|
352 | - throw $e; |
|
353 | - } |
|
354 | - // check that the migration stage didn't mark itself as having a fatal error |
|
355 | - if ($stage->is_broken()) { |
|
356 | - $this->set_broken(); |
|
357 | - throw new EE_Error($stage->get_last_error()); |
|
358 | - } |
|
359 | - } |
|
360 | - // once we've migrated all the number we intended to (possibly from different stages), stop migrating |
|
361 | - // or if we had a fatal error |
|
362 | - // or if the current script stopped early- its not done, but it's done all it thinks we should do on this step |
|
363 | - if ( |
|
364 | - $num_records_actually_migrated >= $num_records_to_migrate_limit |
|
365 | - || $stage->is_broken() |
|
366 | - || $stage->has_more_to_do() |
|
367 | - ) { |
|
368 | - break; |
|
369 | - } |
|
370 | - } |
|
371 | - // check if we're all done this data migration... |
|
372 | - // which is indicated by being done early AND the last stage claims to be done |
|
373 | - if ($stage == null) { |
|
374 | - // this migration script apparently has NO stages... which is super weird, but whatever |
|
375 | - $this->set_completed(); |
|
376 | - $this->_maybe_do_schema_changes(false); |
|
377 | - } elseif ($num_records_actually_migrated < $num_records_to_migrate_limit && ! $stage->has_more_to_do()) { |
|
378 | - // apparently we're done, because we couldn't migrate the number we intended to |
|
379 | - $this->set_completed(); |
|
380 | - $this->_update_feedback_message(array_reverse($records_migrated_per_stage)); |
|
381 | - // do schema changes for after the migration now |
|
382 | - // first double-check we haven't already done this |
|
383 | - $this->_maybe_do_schema_changes(false); |
|
384 | - } else { |
|
385 | - // update feedback message, keeping in mind that we show them with the most recent at the top |
|
386 | - $this->_update_feedback_message(array_reverse($records_migrated_per_stage)); |
|
387 | - } |
|
388 | - return $num_records_actually_migrated; |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - /** |
|
393 | - * Updates the feedback message according to what was done during this migration stage. |
|
394 | - * |
|
395 | - * @param array $records_migrated_per_stage KEYS are pretty names for each stage; values are the count of records |
|
396 | - * migrated from that stage |
|
397 | - * @return void |
|
398 | - */ |
|
399 | - private function _update_feedback_message($records_migrated_per_stage) |
|
400 | - { |
|
401 | - $feedback_message_array = array(); |
|
402 | - foreach ($records_migrated_per_stage as $migration_stage_name => $num_records_migrated) { |
|
403 | - $feedback_message_array[] = sprintf( |
|
404 | - esc_html__("Migrated %d records successfully during %s", "event_espresso"), |
|
405 | - $num_records_migrated, |
|
406 | - $migration_stage_name |
|
407 | - ); |
|
408 | - } |
|
409 | - $this->_feedback_message .= implode("<br>", $feedback_message_array); |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - /** |
|
414 | - * Calls either schema_changes_before_migration() (if $before==true) or schema_changes_after_migration |
|
415 | - * (if $before==false). Buffers their outputs and stores them on the class. |
|
416 | - * |
|
417 | - * @param boolean $before |
|
418 | - * @throws Exception |
|
419 | - * @return void |
|
420 | - */ |
|
421 | - private function _maybe_do_schema_changes($before = true) |
|
422 | - { |
|
423 | - // so this property will be either _schema_changes_after_migration_ran or _schema_changes_before_migration_ran |
|
424 | - $property_name = '_schema_changes_' . ($before ? 'before' : 'after') . '_migration_ran'; |
|
425 | - if (! $this->{$property_name}) { |
|
426 | - try { |
|
427 | - ob_start(); |
|
428 | - if ($before) { |
|
429 | - $this->schema_changes_before_migration(); |
|
430 | - } else { |
|
431 | - $this->schema_changes_after_migration(); |
|
432 | - } |
|
433 | - $output = ob_get_contents(); |
|
434 | - ob_end_clean(); |
|
435 | - } catch (Exception $e) { |
|
436 | - $this->set_status(EE_Data_Migration_Manager::status_fatal_error); |
|
437 | - throw $e; |
|
438 | - } |
|
439 | - // record that we've done these schema changes |
|
440 | - $this->{$property_name} = true; |
|
441 | - // if there were any warnings etc, record them as non-fatal errors |
|
442 | - if ($output) { |
|
443 | - // there were some warnings |
|
444 | - $this->_errors[] = $output; |
|
445 | - } |
|
446 | - } |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - /** |
|
451 | - * Wrapper for EEH_Activation::create_table. However, takes into account the request type when |
|
452 | - * deciding what to pass for its 4th arg, $drop_pre_existing_tables. Using this function, instead |
|
453 | - * of _table_should_exist_previously, indicates that this table should be new to the EE version being migrated to |
|
454 | - * or |
|
455 | - * activated currently. If this is a brand new activation or a migration, and we're indicating this table should |
|
456 | - * not |
|
457 | - * previously exist, then we want to set $drop_pre_existing_tables to TRUE (ie, we shouldn't discover that this |
|
458 | - * table exists in the DB in EEH_Activation::create_table- if it DOES exist, something's wrong and the old table |
|
459 | - * should be nuked. |
|
460 | - * |
|
461 | - * Just for a bit of context, the migration script's db_schema_changes_* methods |
|
462 | - * are called basically in 3 cases: on brand new activation of EE4 (ie no previous version of EE existed and the |
|
463 | - * plugin is being activated and we want to add all the brand new tables), upon reactivation of EE4 (it was |
|
464 | - * deactivated and then reactivated, in which case we want to just verify the DB structure is ok) that table should |
|
465 | - * be dropped), and during a migration when we're moving the DB to the state of the migration script |
|
466 | - * |
|
467 | - * @param string $table_name |
|
468 | - * @param string $table_definition_sql |
|
469 | - * @param string $engine_string |
|
470 | - */ |
|
471 | - protected function _table_is_new_in_this_version( |
|
472 | - $table_name, |
|
473 | - $table_definition_sql, |
|
474 | - $engine_string = 'ENGINE=InnoDB ' |
|
475 | - ) { |
|
476 | - $this->_create_table_and_catch_errors( |
|
477 | - $table_name, |
|
478 | - $table_definition_sql, |
|
479 | - $engine_string, |
|
480 | - $this->_pre_existing_table_should_be_dropped(true) |
|
481 | - ); |
|
482 | - } |
|
483 | - |
|
484 | - /** |
|
485 | - * Like _table_is_new_in_this_version and _table_should_exist_previously, this function verifies the given table |
|
486 | - * exists. But we understand that this table has CHANGED in this version since the previous version. So it's not |
|
487 | - * completely new, but it's different. So we need to treat it like a new table in terms of verifying it's schema is |
|
488 | - * correct on activations, migrations, upgrades; but if it exists when it shouldn't, we need to be as lenient as |
|
489 | - * _table_should_exist_previously. |
|
490 | - * 8656]{Assumes only this plugin could have added this table (ie, if its a new activation of this plugin, the |
|
491 | - * table shouldn't exist). |
|
492 | - * |
|
493 | - * @param string $table_name |
|
494 | - * @param string $table_definition_sql |
|
495 | - * @param string $engine_string |
|
496 | - */ |
|
497 | - protected function _table_is_changed_in_this_version( |
|
498 | - $table_name, |
|
499 | - $table_definition_sql, |
|
500 | - $engine_string = 'ENGINE=MyISAM' |
|
501 | - ) { |
|
502 | - $this->_create_table_and_catch_errors( |
|
503 | - $table_name, |
|
504 | - $table_definition_sql, |
|
505 | - $engine_string, |
|
506 | - $this->_pre_existing_table_should_be_dropped(false) |
|
507 | - ); |
|
508 | - } |
|
509 | - |
|
510 | - |
|
511 | - /** |
|
512 | - * _old_table_exists |
|
513 | - * returns TRUE if the requested table exists in the current database |
|
514 | - * |
|
515 | - * @param string $table_name |
|
516 | - * @return boolean |
|
517 | - */ |
|
518 | - protected function _old_table_exists($table_name) |
|
519 | - { |
|
520 | - return $this->_get_table_analysis()->tableExists($table_name); |
|
521 | - } |
|
522 | - |
|
523 | - |
|
524 | - /** |
|
525 | - * _delete_table_if_empty |
|
526 | - * returns TRUE if the requested table was empty and successfully empty |
|
527 | - * |
|
528 | - * @param string $table_name |
|
529 | - * @return boolean |
|
530 | - */ |
|
531 | - protected function _delete_table_if_empty($table_name) |
|
532 | - { |
|
533 | - return EEH_Activation::delete_db_table_if_empty($table_name); |
|
534 | - } |
|
535 | - |
|
536 | - |
|
537 | - /** |
|
538 | - * It is preferred to use _table_has_not_changed_since_previous or _table_is_changed_in_this_version |
|
539 | - * as these are significantly more efficient or explicit. |
|
540 | - * Please see description of _table_is_new_in_this_version. This function will only set |
|
541 | - * EEH_Activation::create_table's $drop_pre_existing_tables to TRUE if it's a brand |
|
542 | - * new activation. ie, a more accurate name for this method would be "_table_added_previously_by_this_plugin" |
|
543 | - * because the table will be cleared out if this is a new activation (ie, if its a new activation, it actually |
|
544 | - * should exist previously). Otherwise, we'll always set $drop_pre_existing_tables to FALSE because the table |
|
545 | - * should have existed. Note, if the table is being MODIFIED in this version being activated or migrated to, then |
|
546 | - * you want _table_is_changed_in_this_version NOT this one. We don't check this table's structure during migrations |
|
547 | - * because apparently it hasn't changed since the previous one, right? |
|
548 | - * |
|
549 | - * @param string $table_name |
|
550 | - * @param string $table_definition_sql |
|
551 | - * @param string $engine_string |
|
552 | - */ |
|
553 | - protected function _table_should_exist_previously( |
|
554 | - $table_name, |
|
555 | - $table_definition_sql, |
|
556 | - $engine_string = 'ENGINE=MyISAM' |
|
557 | - ) { |
|
558 | - $this->_create_table_and_catch_errors( |
|
559 | - $table_name, |
|
560 | - $table_definition_sql, |
|
561 | - $engine_string, |
|
562 | - $this->_pre_existing_table_should_be_dropped(false) |
|
563 | - ); |
|
564 | - } |
|
565 | - |
|
566 | - /** |
|
567 | - * Exactly the same as _table_should_exist_previously(), except if this migration script is currently doing |
|
568 | - * a migration, we skip checking this table's structure in the database and just assume it's correct. |
|
569 | - * So this is useful only to improve efficiency when doing migrations (not a big deal for single site installs, |
|
570 | - * but important for multisite where migrations can take a very long time otherwise). |
|
571 | - * If the table is known to have changed since previous version, use _table_is_changed_in_this_version(). |
|
572 | - * Assumes only this plugin could have added this table (ie, if its a new activation of this plugin, the table |
|
573 | - * shouldn't exist). |
|
574 | - * |
|
575 | - * @param string $table_name |
|
576 | - * @param string $table_definition_sql |
|
577 | - * @param string $engine_string |
|
578 | - */ |
|
579 | - protected function _table_has_not_changed_since_previous( |
|
580 | - $table_name, |
|
581 | - $table_definition_sql, |
|
582 | - $engine_string = 'ENGINE=MyISAM' |
|
583 | - ) { |
|
584 | - if ($this->_currently_migrating()) { |
|
585 | - // if we're doing a migration, and this table apparently already exists, then we don't need do anything right? |
|
586 | - return; |
|
587 | - } |
|
588 | - $this->_create_table_and_catch_errors( |
|
589 | - $table_name, |
|
590 | - $table_definition_sql, |
|
591 | - $engine_string, |
|
592 | - $this->_pre_existing_table_should_be_dropped(false) |
|
593 | - ); |
|
594 | - } |
|
595 | - |
|
596 | - /** |
|
597 | - * Returns whether or not this migration script is being used as part of an actual migration |
|
598 | - * |
|
599 | - * @return boolean |
|
600 | - */ |
|
601 | - protected function _currently_migrating() |
|
602 | - { |
|
603 | - // we want to know if we are currently performing a migration. We could just believe what was set on the _migrating property, but let's double-check (ie the script should apply and we should be in MM) |
|
604 | - return $this->_migrating && |
|
605 | - $this->can_migrate_from_version( |
|
606 | - EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set() |
|
607 | - ) && |
|
608 | - EE_Maintenance_Mode::instance()->real_level() == EE_Maintenance_Mode::level_2_complete_maintenance; |
|
609 | - } |
|
610 | - |
|
611 | - /** |
|
612 | - * Determines if a table should be dropped, based on whether it's reported to be new in $table_is_new, |
|
613 | - * and the plugin's request type. |
|
614 | - * Assumes only this plugin could have added the table (ie, if its a new activation of this plugin, the table |
|
615 | - * shouldn't exist no matter what). |
|
616 | - * |
|
617 | - * @param boolean $table_is_new |
|
618 | - * @return boolean |
|
619 | - */ |
|
620 | - protected function _pre_existing_table_should_be_dropped($table_is_new) |
|
621 | - { |
|
622 | - if ($table_is_new) { |
|
623 | - if ( |
|
624 | - $this->_get_req_type_for_plugin_corresponding_to_this_dms() == EE_System::req_type_new_activation |
|
625 | - || $this->_currently_migrating() |
|
626 | - ) { |
|
627 | - return true; |
|
628 | - } else { |
|
629 | - return false; |
|
630 | - } |
|
631 | - } else { |
|
632 | - if ( |
|
633 | - in_array( |
|
634 | - $this->_get_req_type_for_plugin_corresponding_to_this_dms(), |
|
635 | - array(EE_System::req_type_new_activation) |
|
636 | - ) |
|
637 | - ) { |
|
638 | - return true; |
|
639 | - } else { |
|
640 | - return false; |
|
641 | - } |
|
642 | - } |
|
643 | - } |
|
644 | - |
|
645 | - /** |
|
646 | - * Just wraps EEH_Activation::create_table, but catches any errors it may throw and adds them as errors on the DMS |
|
647 | - * |
|
648 | - * @param string $table_name |
|
649 | - * @param string $table_definition_sql |
|
650 | - * @param string $engine_string |
|
651 | - * @param boolean $drop_pre_existing_tables |
|
652 | - */ |
|
653 | - private function _create_table_and_catch_errors( |
|
654 | - $table_name, |
|
655 | - $table_definition_sql, |
|
656 | - $engine_string = 'ENGINE=MyISAM', |
|
657 | - $drop_pre_existing_tables = false |
|
658 | - ) { |
|
659 | - try { |
|
660 | - EEH_Activation::create_table($table_name, $table_definition_sql, $engine_string, $drop_pre_existing_tables); |
|
661 | - } catch (EE_Error $e) { |
|
662 | - $message = $e->getMessage() . '<br>Stack Trace:' . $e->getTraceAsString(); |
|
663 | - $this->add_error($message); |
|
664 | - $this->_feedback_message .= $message; |
|
665 | - } |
|
666 | - } |
|
667 | - |
|
668 | - |
|
669 | - /** |
|
670 | - * Gets the request type for the plugin (core or addon) that corresponds to this DMS |
|
671 | - * |
|
672 | - * @return int one of EE_System::_req_type_* constants |
|
673 | - * @throws EE_Error |
|
674 | - */ |
|
675 | - private function _get_req_type_for_plugin_corresponding_to_this_dms() |
|
676 | - { |
|
677 | - if ($this->slug() == 'Core') { |
|
678 | - return EE_System::instance()->detect_req_type(); |
|
679 | - } else {// it must be for an addon |
|
680 | - $addon_name = $this->slug(); |
|
681 | - if (EE_Registry::instance()->get_addon_by_name($addon_name)) { |
|
682 | - return EE_Registry::instance()->get_addon_by_name($addon_name)->detect_req_type(); |
|
683 | - } else { |
|
684 | - throw new EE_Error( |
|
685 | - sprintf( |
|
686 | - esc_html__( |
|
687 | - "The DMS slug '%s' should correspond to the addon's name, which should also be '%s', but no such addon was registered. These are the registered addons' names: %s", |
|
688 | - "event_espresso" |
|
689 | - ), |
|
690 | - $this->slug(), |
|
691 | - $addon_name, |
|
692 | - implode(",", array_keys(EE_Registry::instance()->get_addons_by_name())) |
|
693 | - ) |
|
694 | - ); |
|
695 | - } |
|
696 | - } |
|
697 | - } |
|
698 | - |
|
699 | - |
|
700 | - /** |
|
701 | - * returns an array of strings describing errors by all the script's stages |
|
702 | - * |
|
703 | - * @return array |
|
704 | - */ |
|
705 | - public function get_errors() |
|
706 | - { |
|
707 | - $all_errors = $this->_errors; |
|
708 | - if (! is_array($all_errors)) { |
|
709 | - $all_errors = array(); |
|
710 | - } |
|
711 | - foreach ($this->stages() as $stage) { |
|
712 | - $all_errors = array_merge($stage->get_errors(), $all_errors); |
|
713 | - } |
|
714 | - return $all_errors; |
|
715 | - } |
|
716 | - |
|
717 | - |
|
718 | - /** |
|
719 | - * Indicates whether or not this migration script should continue |
|
720 | - * |
|
721 | - * @return boolean |
|
722 | - */ |
|
723 | - public function can_continue() |
|
724 | - { |
|
725 | - return in_array( |
|
726 | - $this->get_status(), |
|
727 | - EE_Data_Migration_Manager::instance()->stati_that_indicate_to_continue_single_migration_script |
|
728 | - ); |
|
729 | - } |
|
730 | - |
|
731 | - |
|
732 | - /** |
|
733 | - * Gets all the data migration stages associated with this script. Note: |
|
734 | - * addons can filter this list to add their own stages, and because the list is |
|
735 | - * numerically-indexed, they can insert their stage wherever they like and it will |
|
736 | - * get ordered by the indexes |
|
737 | - * |
|
738 | - * @return EE_Data_Migration_Script_Stage[] |
|
739 | - */ |
|
740 | - protected function stages() |
|
741 | - { |
|
742 | - $stages = apply_filters('FHEE__' . get_class($this) . '__stages', $this->_migration_stages); |
|
743 | - ksort($stages); |
|
744 | - return $stages; |
|
745 | - } |
|
746 | - |
|
747 | - |
|
748 | - /** |
|
749 | - * Gets a string which should describe what's going on currently with this migration, which |
|
750 | - * can be displayed to the user |
|
751 | - * |
|
752 | - * @return string |
|
753 | - */ |
|
754 | - public function get_feedback_message() |
|
755 | - { |
|
756 | - return $this->_feedback_message; |
|
757 | - } |
|
758 | - |
|
759 | - |
|
760 | - /** |
|
761 | - * A lot like "__sleep()" magic method in purpose, this is meant for persisting this class' |
|
762 | - * properties to the DB. However, we don't want to use __sleep() because its quite |
|
763 | - * possible that this class is defined when it goes to sleep, but NOT available when it |
|
764 | - * awakes (eg, this class is part of an addon that is deactivated at some point). |
|
765 | - */ |
|
766 | - public function properties_as_array() |
|
767 | - { |
|
768 | - $properties = parent::properties_as_array(); |
|
769 | - $properties['_migration_stages'] = array(); |
|
770 | - foreach ($this->_migration_stages as $migration_stage_priority => $migration_stage_class) { |
|
771 | - $properties['_migration_stages'][ $migration_stage_priority ] = $migration_stage_class->properties_as_array( |
|
772 | - ); |
|
773 | - } |
|
774 | - unset($properties['_mappings']); |
|
775 | - unset($properties['previous_dms']); |
|
776 | - |
|
777 | - foreach ($this->_mappings as $old_table_name => $mapping_to_new_table) { |
|
778 | - foreach ($mapping_to_new_table as $new_table_name => $mapping) { |
|
779 | - $this->_set_mapping_option($old_table_name, $new_table_name, $mapping); |
|
780 | - } |
|
781 | - } |
|
782 | - return $properties; |
|
783 | - } |
|
784 | - |
|
785 | - |
|
786 | - /** |
|
787 | - * Sets all of the properties of this script stage to match what's in the array, which is assumed |
|
788 | - * to have been made from the properties_as_array() function. |
|
789 | - * |
|
790 | - * @param array $array_of_properties like what's produced from properties_as_array() method |
|
791 | - * @return void |
|
792 | - */ |
|
793 | - public function instantiate_from_array_of_properties($array_of_properties) |
|
794 | - { |
|
795 | - $stages_properties_arrays = $array_of_properties['_migration_stages']; |
|
796 | - unset($array_of_properties['_migration_stages']); |
|
797 | - unset($array_of_properties['class']); |
|
798 | - foreach ($array_of_properties as $property_name => $property_value) { |
|
799 | - $this->{$property_name} = $property_value; |
|
800 | - } |
|
801 | - // _migration_stages are already instantiated, but have only default data |
|
802 | - foreach ($this->_migration_stages as $stage) { |
|
803 | - $stage_data = $this->_find_migration_stage_data_with_classname( |
|
804 | - get_class($stage), |
|
805 | - $stages_properties_arrays |
|
806 | - ); |
|
807 | - // SO, if we found the stage data that was saved, use it. Otherwise, I guess the stage is new? (maybe added by |
|
808 | - // an addon? Unlikely... not sure why it wouldn't exist, but if it doesn't just treat it like it was never started yet) |
|
809 | - if ($stage_data) { |
|
810 | - $stage->instantiate_from_array_of_properties($stage_data); |
|
811 | - } |
|
812 | - } |
|
813 | - } |
|
814 | - |
|
815 | - |
|
816 | - /** |
|
817 | - * Gets the migration data from the array $migration_stage_data_arrays (which is an array of arrays, each of which |
|
818 | - * is pretty well identical to EE_Data_Migration_Stage objects except all their properties are array indexes) |
|
819 | - * for the given classname |
|
820 | - * |
|
821 | - * @param string $classname |
|
822 | - * @param array $migration_stage_data_arrays |
|
823 | - * @return null |
|
824 | - */ |
|
825 | - private function _find_migration_stage_data_with_classname($classname, $migration_stage_data_arrays) |
|
826 | - { |
|
827 | - foreach ($migration_stage_data_arrays as $migration_stage_data_array) { |
|
828 | - if (isset($migration_stage_data_array['class']) && $migration_stage_data_array['class'] == $classname) { |
|
829 | - return $migration_stage_data_array; |
|
830 | - } |
|
831 | - } |
|
832 | - return null; |
|
833 | - } |
|
834 | - |
|
835 | - |
|
836 | - /** |
|
837 | - * Returns the version that this script migrates to, based on the script's name. |
|
838 | - * Cannot be overwritten because lots of code needs to know which version a script |
|
839 | - * migrates to knowing only its name. |
|
840 | - * |
|
841 | - * @return array where the first key is the plugin's slug, the 2nd is the version of that plugin |
|
842 | - * that will be updated to. Eg array('Core','4.1.0') |
|
843 | - */ |
|
844 | - final public function migrates_to_version() |
|
845 | - { |
|
846 | - return EE_Data_Migration_Manager::instance()->script_migrates_to_version(get_class($this)); |
|
847 | - } |
|
848 | - |
|
849 | - |
|
850 | - /** |
|
851 | - * Gets this addon's slug as it would appear in the current_db_state wp option, |
|
852 | - * and if this migration script is for an addon, it SHOULD match the addon's slug |
|
853 | - * (and also the addon's classname, minus the 'EE_' prefix.). Eg, 'Calendar' for the EE_Calendar addon. |
|
854 | - * Or 'Core' for core (non-addon). |
|
855 | - * |
|
856 | - * @return string |
|
857 | - */ |
|
858 | - public function slug() |
|
859 | - { |
|
860 | - $migrates_to_version_info = $this->migrates_to_version(); |
|
861 | - // the slug is the first part of the array |
|
862 | - return $migrates_to_version_info['slug']; |
|
863 | - } |
|
864 | - |
|
865 | - |
|
866 | - /** |
|
867 | - * Returns the script's priority relative to DMSs from other addons. However, when |
|
868 | - * two DMSs from the same addon/core apply, this is ignored (and instead the version that |
|
869 | - * the script migrates to is used to determine which to run first). The default is 5, but all core DMSs |
|
870 | - * normally have priority 10. (So if you want a DMS "A" to run before DMS "B", both of which are from addons, |
|
871 | - * and both of which CAN run at the same time (ie, "B" doesn't depend on "A" to set |
|
872 | - * the database up so it can run), then you can set "A" to priority 3 or something. |
|
873 | - * |
|
874 | - * @return int |
|
875 | - */ |
|
876 | - public function priority() |
|
877 | - { |
|
878 | - return $this->_priority; |
|
879 | - } |
|
880 | - |
|
881 | - |
|
882 | - /** |
|
883 | - * Sets whether or not this DMS is being ran as part of a migration, instead of |
|
884 | - * just being used to setup (or verify) the current database structure matches |
|
885 | - * what the latest DMS indicates it should be |
|
886 | - * |
|
887 | - * @param boolean $migrating |
|
888 | - * @return void |
|
889 | - */ |
|
890 | - public function set_migrating($migrating = true) |
|
891 | - { |
|
892 | - $this->_migrating = $migrating; |
|
893 | - } |
|
894 | - |
|
895 | - /** |
|
896 | - * Marks that we think this migration class can continue to migrate |
|
897 | - */ |
|
898 | - public function reattempt() |
|
899 | - { |
|
900 | - parent::reattempt(); |
|
901 | - // also, we want to reattempt any stages that were marked as borked |
|
902 | - foreach ($this->stages() as $stage) { |
|
903 | - if ($stage->is_broken()) { |
|
904 | - $stage->reattempt(); |
|
905 | - } |
|
906 | - } |
|
907 | - } |
|
18 | + /** |
|
19 | + * Set by client code to indicate this DMS is being ran as part of a proper migration, |
|
20 | + * instead of being used to merely setup (or verify) the database structure. |
|
21 | + * Defaults to TRUE, so client code that's NOT using this DMS as part of a proper migration |
|
22 | + * should call EE_Data_Migration_Script_Base::set_migrating( FALSE ) |
|
23 | + * |
|
24 | + * @var boolean |
|
25 | + */ |
|
26 | + protected $_migrating = true; |
|
27 | + |
|
28 | + /** |
|
29 | + * numerically-indexed array where each value is EE_Data_Migration_Script_Stage object |
|
30 | + * |
|
31 | + * @var EE_Data_Migration_Script_Stage[] $migration_functions |
|
32 | + */ |
|
33 | + protected $_migration_stages = array(); |
|
34 | + |
|
35 | + /** |
|
36 | + * Indicates we've already ran the schema changes that needed to happen BEFORE the data migration |
|
37 | + * |
|
38 | + * @var boolean |
|
39 | + */ |
|
40 | + protected $_schema_changes_before_migration_ran = null; |
|
41 | + |
|
42 | + /** |
|
43 | + * Indicates we've already ran the schema changes that needed to happen AFTER the data migration |
|
44 | + * |
|
45 | + * @var boolean |
|
46 | + */ |
|
47 | + protected $_schema_changes_after_migration_ran = null; |
|
48 | + |
|
49 | + /** |
|
50 | + * String which describes what's currently happening in this migration |
|
51 | + * |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + protected $_feedback_message; |
|
55 | + |
|
56 | + /** |
|
57 | + * Indicates the script's priority. Like wp's add_action and add_filter, lower numbers |
|
58 | + * correspond to earlier execution |
|
59 | + * |
|
60 | + * @var int |
|
61 | + */ |
|
62 | + protected $_priority = 5; |
|
63 | + |
|
64 | + /** |
|
65 | + * Multi-dimensional array that defines the mapping from OLD table Primary Keys |
|
66 | + * to NEW table Primary Keys. |
|
67 | + * Top-level array keys are OLD table names (minus the "wp_" part), |
|
68 | + * 2nd-level array keys are NEW table names (again, minus the "wp_" part), |
|
69 | + * 3rd-level array keys are the OLD table primary keys |
|
70 | + * and 3rd-level array values are the NEW table primary keys |
|
71 | + * |
|
72 | + * @var array |
|
73 | + */ |
|
74 | + protected $_mappings = array(); |
|
75 | + |
|
76 | + /** |
|
77 | + * @var EE_Data_Migration_Script_Base |
|
78 | + */ |
|
79 | + protected $previous_dms; |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * Returns whether or not this data migration script can operate on the given version of the database. |
|
84 | + * Eg, if this migration script can migrate from 3.1.26 or higher (but not anything after 4.0.0), and |
|
85 | + * it's passed a string like '3.1.38B', it should return true. |
|
86 | + * If this DMS is to migrate data from an EE3 addon, you will probably want to use |
|
87 | + * EventEspresso\core\services\database\TableAnalysis::tableExists() to check for old EE3 tables, and |
|
88 | + * EE_Data_Migration_Manager::get_migration_ran() to check that core was already |
|
89 | + * migrated from EE3 to EE4 (ie, this DMS probably relies on some migration data generated |
|
90 | + * during the Core 4.1.0 DMS. If core didn't run that DMS, you probably don't want |
|
91 | + * to run this DMS). |
|
92 | + * If this DMS migrates data from a previous version of this EE4 addon, just |
|
93 | + * comparing $current_database_state_of[ $this->slug() ] will probably suffice. |
|
94 | + * If this DMS should never migrate data, because it's only used to define the initial |
|
95 | + * database state, just return FALSE (and core's activation process will take care |
|
96 | + * of calling its schema_changes_before_migration() and |
|
97 | + * schema_changes_after_migration() for you. ) |
|
98 | + * |
|
99 | + * @param array $current_database_state_of keys are EE plugin slugs (eg 'Core', 'Calendar', 'Mailchimp', etc) |
|
100 | + * @return boolean |
|
101 | + */ |
|
102 | + abstract public function can_migrate_from_version($current_database_state_of); |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * Performs database schema changes that need to occur BEFORE the data is migrated. |
|
107 | + * Eg, if we were going to change user passwords from plaintext to encoded versions |
|
108 | + * during this migration, this would probably add a new column called something like |
|
109 | + * "encoded_password". |
|
110 | + * |
|
111 | + * @return boolean of success |
|
112 | + */ |
|
113 | + abstract public function schema_changes_before_migration(); |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * Performs the database schema changes that need to occur AFTER the data has been migrated. |
|
118 | + * Usually this will mean we'll be removing old columns. Eg, if we were changing passwords |
|
119 | + * from plaintext to encoded versions, and we had added a column called "encoded_password", |
|
120 | + * this function would probably remove the old column "password" (which still holds the plaintext password) |
|
121 | + * and possibly rename "encoded_password" to "password" |
|
122 | + * |
|
123 | + * @return boolean of success |
|
124 | + */ |
|
125 | + abstract public function schema_changes_after_migration(); |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * All children of this must call parent::__construct() |
|
130 | + * at the end of their constructor or suffer the consequences! |
|
131 | + * |
|
132 | + * @param TableManager $table_manager |
|
133 | + * @param TableAnalysis $table_analysis |
|
134 | + */ |
|
135 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
136 | + { |
|
137 | + $this->_migration_stages = (array) apply_filters( |
|
138 | + 'FHEE__' . get_class($this) . '__construct__migration_stages', |
|
139 | + $this->_migration_stages |
|
140 | + ); |
|
141 | + foreach ($this->_migration_stages as $migration_stage) { |
|
142 | + if ($migration_stage instanceof EE_Data_Migration_Script_Stage) { |
|
143 | + $migration_stage->_construct_finalize($this); |
|
144 | + } |
|
145 | + } |
|
146 | + parent::__construct($table_manager, $table_analysis); |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * Place to add hooks and filters for tweaking the migrations page, in order |
|
152 | + * to customize it |
|
153 | + */ |
|
154 | + public function migration_page_hooks() |
|
155 | + { |
|
156 | + // by default none are added because we normally like the default look of the migration page |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * Sets the mapping from old table primary keys to new table primary keys. |
|
162 | + * This mapping is automatically persisted as a property on the migration |
|
163 | + * |
|
164 | + * @param string $old_table with wpdb prefix (wp_). Eg: wp_events_detail |
|
165 | + * @param int|string $old_pk old primary key. Eg events_detail.id's value |
|
166 | + * @param string $new_table with wpdb prefix (wp_). Eg: wp_posts |
|
167 | + * @param int|string $new_pk eg posts.ID |
|
168 | + * @return void |
|
169 | + */ |
|
170 | + public function set_mapping($old_table, $old_pk, $new_table, $new_pk) |
|
171 | + { |
|
172 | + // make sure it has the needed keys |
|
173 | + if (! isset($this->_mappings[ $old_table ]) || ! isset($this->_mappings[ $old_table ][ $new_table ])) { |
|
174 | + $this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table); |
|
175 | + } |
|
176 | + $this->_mappings[ $old_table ][ $new_table ][ $old_pk ] = $new_pk; |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * Gets the new primary key, if provided with the OLD table and the primary key |
|
182 | + * of an item in the old table, and the new table |
|
183 | + * |
|
184 | + * @param string $old_table with wpdb prefix (wp_). Eg: wp_events_detail |
|
185 | + * @param int|string $old_pk old primary key. Eg events_detail.id's value |
|
186 | + * @param string $new_table with wpdb prefix (wp_). Eg: wp_posts |
|
187 | + * @return mixed the primary key on the new table |
|
188 | + */ |
|
189 | + public function get_mapping_new_pk($old_table, $old_pk, $new_table) |
|
190 | + { |
|
191 | + if ( |
|
192 | + ! isset($this->_mappings[ $old_table ]) || |
|
193 | + ! isset($this->_mappings[ $old_table ][ $new_table ]) |
|
194 | + ) { |
|
195 | + // try fetching the option |
|
196 | + $this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table); |
|
197 | + } |
|
198 | + return isset($this->_mappings[ $old_table ][ $new_table ][ $old_pk ]) |
|
199 | + ? $this->_mappings[ $old_table ][ $new_table ][ $old_pk ] : null; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * Gets the old primary key, if provided with the OLD table, |
|
205 | + * and the new table and the primary key of an item in the new table |
|
206 | + * |
|
207 | + * @param string $old_table with wpdb prefix (wp_). Eg: wp_events_detail |
|
208 | + * @param string $new_table with wpdb prefix (wp_). Eg: wp_posts |
|
209 | + * @param mixed $new_pk |
|
210 | + * @return mixed |
|
211 | + */ |
|
212 | + public function get_mapping_old_pk($old_table, $new_table, $new_pk) |
|
213 | + { |
|
214 | + if ( |
|
215 | + ! isset($this->_mappings[ $old_table ]) || |
|
216 | + ! isset($this->_mappings[ $old_table ][ $new_table ]) |
|
217 | + ) { |
|
218 | + // try fetching the option |
|
219 | + $this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table); |
|
220 | + } |
|
221 | + if (isset($this->_mappings[ $old_table ][ $new_table ])) { |
|
222 | + $new_pk_to_old_pk = array_flip($this->_mappings[ $old_table ][ $new_table ]); |
|
223 | + if (isset($new_pk_to_old_pk[ $new_pk ])) { |
|
224 | + return $new_pk_to_old_pk[ $new_pk ]; |
|
225 | + } |
|
226 | + } |
|
227 | + return null; |
|
228 | + } |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * Gets the mapping array option specified by the table names |
|
233 | + * |
|
234 | + * @param string $old_table_name |
|
235 | + * @param string $new_table_name |
|
236 | + * @return array |
|
237 | + */ |
|
238 | + protected function _get_mapping_option($old_table_name, $new_table_name) |
|
239 | + { |
|
240 | + $option = get_option($this->_get_mapping_option_name($old_table_name, $new_table_name), array()); |
|
241 | + return $option; |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * Updates the mapping option specified by the table names with the array provided |
|
247 | + * |
|
248 | + * @param string $old_table_name |
|
249 | + * @param string $new_table_name |
|
250 | + * @param array $mapping_array |
|
251 | + * @return boolean success of updating option |
|
252 | + */ |
|
253 | + protected function _set_mapping_option($old_table_name, $new_table_name, $mapping_array) |
|
254 | + { |
|
255 | + $success = update_option($this->_get_mapping_option_name($old_table_name, $new_table_name), $mapping_array, false); |
|
256 | + return $success; |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * Gets the option name for this script to map from $old_table_name to $new_table_name |
|
262 | + * |
|
263 | + * @param string $old_table_name |
|
264 | + * @param string $new_table_name |
|
265 | + * @return string |
|
266 | + */ |
|
267 | + protected function _get_mapping_option_name($old_table_name, $new_table_name) |
|
268 | + { |
|
269 | + global $wpdb; |
|
270 | + $old_table_name_sans_wp = str_replace($wpdb->prefix, "", $old_table_name); |
|
271 | + $new_table_name_sans_wp = str_replace($wpdb->prefix, "", $new_table_name); |
|
272 | + $migrates_to = EE_Data_Migration_Manager::instance()->script_migrates_to_version(get_class($this)); |
|
273 | + return substr( |
|
274 | + EE_Data_Migration_Manager::data_migration_script_mapping_option_prefix . $migrates_to ['slug'] . '_' . $migrates_to['version'] . '_' . $old_table_name_sans_wp . '_' . $new_table_name_sans_wp, |
|
275 | + 0, |
|
276 | + 64 |
|
277 | + ); |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * Counts all the records that will be migrated during this data migration. |
|
283 | + * For example, if we were changing old user passwords from plaintext to encoded versions, |
|
284 | + * this would be a count of all users who have passwords. If we were going to also split |
|
285 | + * attendee records into transactions, registrations, and attendee records, this would include |
|
286 | + * the count of all attendees currently in existence in the DB (ie, users + attendees). |
|
287 | + * If you can't determine how many records there are to migrate, just provide a guess: this |
|
288 | + * number will only be used in calculating the percent complete. If you estimate there to be |
|
289 | + * 100 records to migrate, and it turns out there's 120, we'll just show the migration as being at |
|
290 | + * 99% until the function "migration_step" returns EE_Data_Migration_Script_Base::status_complete. |
|
291 | + * |
|
292 | + * @return int |
|
293 | + */ |
|
294 | + protected function _count_records_to_migrate() |
|
295 | + { |
|
296 | + $count = 0; |
|
297 | + foreach ($this->stages() as $stage) { |
|
298 | + $count += $stage->count_records_to_migrate(); |
|
299 | + } |
|
300 | + return $count; |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * Returns the number of records updated so far. Usually this is easiest to do |
|
306 | + * by just setting a transient and updating it after each migration_step |
|
307 | + * |
|
308 | + * @return int |
|
309 | + */ |
|
310 | + public function count_records_migrated() |
|
311 | + { |
|
312 | + $count = 0; |
|
313 | + foreach ($this->stages() as $stage) { |
|
314 | + $count += $stage->count_records_migrated(); |
|
315 | + } |
|
316 | + $this->_records_migrated = $count; |
|
317 | + return $count; |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + /** |
|
322 | + * @param int $num_records_to_migrate_limit |
|
323 | + * @return int |
|
324 | + * @throws EE_Error |
|
325 | + * @throws Exception |
|
326 | + */ |
|
327 | + public function migration_step($num_records_to_migrate_limit) |
|
328 | + { |
|
329 | + // reset the feedback message |
|
330 | + $this->_feedback_message = ''; |
|
331 | + // if we haven't yet done the 1st schema changes, do them now. buffer any output |
|
332 | + $this->_maybe_do_schema_changes(true); |
|
333 | + |
|
334 | + $num_records_actually_migrated = 0; |
|
335 | + $records_migrated_per_stage = array(); |
|
336 | + // setup the 'stage' variable, which should hold the last run stage of the migration (or none at all if nothing runs) |
|
337 | + $stage = null; |
|
338 | + // get the next stage that isn't complete |
|
339 | + foreach ($this->stages() as $stage) { |
|
340 | + if ($stage->get_status() == EE_Data_Migration_Manager::status_continue) { |
|
341 | + try { |
|
342 | + $records_migrated_during_stage = $stage->migration_step( |
|
343 | + $num_records_to_migrate_limit - $num_records_actually_migrated |
|
344 | + ); |
|
345 | + $num_records_actually_migrated += $records_migrated_during_stage; |
|
346 | + $records_migrated_per_stage[ $stage->pretty_name() ] = $records_migrated_during_stage; |
|
347 | + } catch (Exception $e) { |
|
348 | + // yes if we catch an exception here, we consider that migration stage borked. |
|
349 | + $stage->set_status(EE_Data_Migration_Manager::status_fatal_error); |
|
350 | + $this->set_status(EE_Data_Migration_Manager::status_fatal_error); |
|
351 | + $stage->add_error($e->getMessage() . ". Stack-trace:" . $e->getTraceAsString()); |
|
352 | + throw $e; |
|
353 | + } |
|
354 | + // check that the migration stage didn't mark itself as having a fatal error |
|
355 | + if ($stage->is_broken()) { |
|
356 | + $this->set_broken(); |
|
357 | + throw new EE_Error($stage->get_last_error()); |
|
358 | + } |
|
359 | + } |
|
360 | + // once we've migrated all the number we intended to (possibly from different stages), stop migrating |
|
361 | + // or if we had a fatal error |
|
362 | + // or if the current script stopped early- its not done, but it's done all it thinks we should do on this step |
|
363 | + if ( |
|
364 | + $num_records_actually_migrated >= $num_records_to_migrate_limit |
|
365 | + || $stage->is_broken() |
|
366 | + || $stage->has_more_to_do() |
|
367 | + ) { |
|
368 | + break; |
|
369 | + } |
|
370 | + } |
|
371 | + // check if we're all done this data migration... |
|
372 | + // which is indicated by being done early AND the last stage claims to be done |
|
373 | + if ($stage == null) { |
|
374 | + // this migration script apparently has NO stages... which is super weird, but whatever |
|
375 | + $this->set_completed(); |
|
376 | + $this->_maybe_do_schema_changes(false); |
|
377 | + } elseif ($num_records_actually_migrated < $num_records_to_migrate_limit && ! $stage->has_more_to_do()) { |
|
378 | + // apparently we're done, because we couldn't migrate the number we intended to |
|
379 | + $this->set_completed(); |
|
380 | + $this->_update_feedback_message(array_reverse($records_migrated_per_stage)); |
|
381 | + // do schema changes for after the migration now |
|
382 | + // first double-check we haven't already done this |
|
383 | + $this->_maybe_do_schema_changes(false); |
|
384 | + } else { |
|
385 | + // update feedback message, keeping in mind that we show them with the most recent at the top |
|
386 | + $this->_update_feedback_message(array_reverse($records_migrated_per_stage)); |
|
387 | + } |
|
388 | + return $num_records_actually_migrated; |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + /** |
|
393 | + * Updates the feedback message according to what was done during this migration stage. |
|
394 | + * |
|
395 | + * @param array $records_migrated_per_stage KEYS are pretty names for each stage; values are the count of records |
|
396 | + * migrated from that stage |
|
397 | + * @return void |
|
398 | + */ |
|
399 | + private function _update_feedback_message($records_migrated_per_stage) |
|
400 | + { |
|
401 | + $feedback_message_array = array(); |
|
402 | + foreach ($records_migrated_per_stage as $migration_stage_name => $num_records_migrated) { |
|
403 | + $feedback_message_array[] = sprintf( |
|
404 | + esc_html__("Migrated %d records successfully during %s", "event_espresso"), |
|
405 | + $num_records_migrated, |
|
406 | + $migration_stage_name |
|
407 | + ); |
|
408 | + } |
|
409 | + $this->_feedback_message .= implode("<br>", $feedback_message_array); |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + /** |
|
414 | + * Calls either schema_changes_before_migration() (if $before==true) or schema_changes_after_migration |
|
415 | + * (if $before==false). Buffers their outputs and stores them on the class. |
|
416 | + * |
|
417 | + * @param boolean $before |
|
418 | + * @throws Exception |
|
419 | + * @return void |
|
420 | + */ |
|
421 | + private function _maybe_do_schema_changes($before = true) |
|
422 | + { |
|
423 | + // so this property will be either _schema_changes_after_migration_ran or _schema_changes_before_migration_ran |
|
424 | + $property_name = '_schema_changes_' . ($before ? 'before' : 'after') . '_migration_ran'; |
|
425 | + if (! $this->{$property_name}) { |
|
426 | + try { |
|
427 | + ob_start(); |
|
428 | + if ($before) { |
|
429 | + $this->schema_changes_before_migration(); |
|
430 | + } else { |
|
431 | + $this->schema_changes_after_migration(); |
|
432 | + } |
|
433 | + $output = ob_get_contents(); |
|
434 | + ob_end_clean(); |
|
435 | + } catch (Exception $e) { |
|
436 | + $this->set_status(EE_Data_Migration_Manager::status_fatal_error); |
|
437 | + throw $e; |
|
438 | + } |
|
439 | + // record that we've done these schema changes |
|
440 | + $this->{$property_name} = true; |
|
441 | + // if there were any warnings etc, record them as non-fatal errors |
|
442 | + if ($output) { |
|
443 | + // there were some warnings |
|
444 | + $this->_errors[] = $output; |
|
445 | + } |
|
446 | + } |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + /** |
|
451 | + * Wrapper for EEH_Activation::create_table. However, takes into account the request type when |
|
452 | + * deciding what to pass for its 4th arg, $drop_pre_existing_tables. Using this function, instead |
|
453 | + * of _table_should_exist_previously, indicates that this table should be new to the EE version being migrated to |
|
454 | + * or |
|
455 | + * activated currently. If this is a brand new activation or a migration, and we're indicating this table should |
|
456 | + * not |
|
457 | + * previously exist, then we want to set $drop_pre_existing_tables to TRUE (ie, we shouldn't discover that this |
|
458 | + * table exists in the DB in EEH_Activation::create_table- if it DOES exist, something's wrong and the old table |
|
459 | + * should be nuked. |
|
460 | + * |
|
461 | + * Just for a bit of context, the migration script's db_schema_changes_* methods |
|
462 | + * are called basically in 3 cases: on brand new activation of EE4 (ie no previous version of EE existed and the |
|
463 | + * plugin is being activated and we want to add all the brand new tables), upon reactivation of EE4 (it was |
|
464 | + * deactivated and then reactivated, in which case we want to just verify the DB structure is ok) that table should |
|
465 | + * be dropped), and during a migration when we're moving the DB to the state of the migration script |
|
466 | + * |
|
467 | + * @param string $table_name |
|
468 | + * @param string $table_definition_sql |
|
469 | + * @param string $engine_string |
|
470 | + */ |
|
471 | + protected function _table_is_new_in_this_version( |
|
472 | + $table_name, |
|
473 | + $table_definition_sql, |
|
474 | + $engine_string = 'ENGINE=InnoDB ' |
|
475 | + ) { |
|
476 | + $this->_create_table_and_catch_errors( |
|
477 | + $table_name, |
|
478 | + $table_definition_sql, |
|
479 | + $engine_string, |
|
480 | + $this->_pre_existing_table_should_be_dropped(true) |
|
481 | + ); |
|
482 | + } |
|
483 | + |
|
484 | + /** |
|
485 | + * Like _table_is_new_in_this_version and _table_should_exist_previously, this function verifies the given table |
|
486 | + * exists. But we understand that this table has CHANGED in this version since the previous version. So it's not |
|
487 | + * completely new, but it's different. So we need to treat it like a new table in terms of verifying it's schema is |
|
488 | + * correct on activations, migrations, upgrades; but if it exists when it shouldn't, we need to be as lenient as |
|
489 | + * _table_should_exist_previously. |
|
490 | + * 8656]{Assumes only this plugin could have added this table (ie, if its a new activation of this plugin, the |
|
491 | + * table shouldn't exist). |
|
492 | + * |
|
493 | + * @param string $table_name |
|
494 | + * @param string $table_definition_sql |
|
495 | + * @param string $engine_string |
|
496 | + */ |
|
497 | + protected function _table_is_changed_in_this_version( |
|
498 | + $table_name, |
|
499 | + $table_definition_sql, |
|
500 | + $engine_string = 'ENGINE=MyISAM' |
|
501 | + ) { |
|
502 | + $this->_create_table_and_catch_errors( |
|
503 | + $table_name, |
|
504 | + $table_definition_sql, |
|
505 | + $engine_string, |
|
506 | + $this->_pre_existing_table_should_be_dropped(false) |
|
507 | + ); |
|
508 | + } |
|
509 | + |
|
510 | + |
|
511 | + /** |
|
512 | + * _old_table_exists |
|
513 | + * returns TRUE if the requested table exists in the current database |
|
514 | + * |
|
515 | + * @param string $table_name |
|
516 | + * @return boolean |
|
517 | + */ |
|
518 | + protected function _old_table_exists($table_name) |
|
519 | + { |
|
520 | + return $this->_get_table_analysis()->tableExists($table_name); |
|
521 | + } |
|
522 | + |
|
523 | + |
|
524 | + /** |
|
525 | + * _delete_table_if_empty |
|
526 | + * returns TRUE if the requested table was empty and successfully empty |
|
527 | + * |
|
528 | + * @param string $table_name |
|
529 | + * @return boolean |
|
530 | + */ |
|
531 | + protected function _delete_table_if_empty($table_name) |
|
532 | + { |
|
533 | + return EEH_Activation::delete_db_table_if_empty($table_name); |
|
534 | + } |
|
535 | + |
|
536 | + |
|
537 | + /** |
|
538 | + * It is preferred to use _table_has_not_changed_since_previous or _table_is_changed_in_this_version |
|
539 | + * as these are significantly more efficient or explicit. |
|
540 | + * Please see description of _table_is_new_in_this_version. This function will only set |
|
541 | + * EEH_Activation::create_table's $drop_pre_existing_tables to TRUE if it's a brand |
|
542 | + * new activation. ie, a more accurate name for this method would be "_table_added_previously_by_this_plugin" |
|
543 | + * because the table will be cleared out if this is a new activation (ie, if its a new activation, it actually |
|
544 | + * should exist previously). Otherwise, we'll always set $drop_pre_existing_tables to FALSE because the table |
|
545 | + * should have existed. Note, if the table is being MODIFIED in this version being activated or migrated to, then |
|
546 | + * you want _table_is_changed_in_this_version NOT this one. We don't check this table's structure during migrations |
|
547 | + * because apparently it hasn't changed since the previous one, right? |
|
548 | + * |
|
549 | + * @param string $table_name |
|
550 | + * @param string $table_definition_sql |
|
551 | + * @param string $engine_string |
|
552 | + */ |
|
553 | + protected function _table_should_exist_previously( |
|
554 | + $table_name, |
|
555 | + $table_definition_sql, |
|
556 | + $engine_string = 'ENGINE=MyISAM' |
|
557 | + ) { |
|
558 | + $this->_create_table_and_catch_errors( |
|
559 | + $table_name, |
|
560 | + $table_definition_sql, |
|
561 | + $engine_string, |
|
562 | + $this->_pre_existing_table_should_be_dropped(false) |
|
563 | + ); |
|
564 | + } |
|
565 | + |
|
566 | + /** |
|
567 | + * Exactly the same as _table_should_exist_previously(), except if this migration script is currently doing |
|
568 | + * a migration, we skip checking this table's structure in the database and just assume it's correct. |
|
569 | + * So this is useful only to improve efficiency when doing migrations (not a big deal for single site installs, |
|
570 | + * but important for multisite where migrations can take a very long time otherwise). |
|
571 | + * If the table is known to have changed since previous version, use _table_is_changed_in_this_version(). |
|
572 | + * Assumes only this plugin could have added this table (ie, if its a new activation of this plugin, the table |
|
573 | + * shouldn't exist). |
|
574 | + * |
|
575 | + * @param string $table_name |
|
576 | + * @param string $table_definition_sql |
|
577 | + * @param string $engine_string |
|
578 | + */ |
|
579 | + protected function _table_has_not_changed_since_previous( |
|
580 | + $table_name, |
|
581 | + $table_definition_sql, |
|
582 | + $engine_string = 'ENGINE=MyISAM' |
|
583 | + ) { |
|
584 | + if ($this->_currently_migrating()) { |
|
585 | + // if we're doing a migration, and this table apparently already exists, then we don't need do anything right? |
|
586 | + return; |
|
587 | + } |
|
588 | + $this->_create_table_and_catch_errors( |
|
589 | + $table_name, |
|
590 | + $table_definition_sql, |
|
591 | + $engine_string, |
|
592 | + $this->_pre_existing_table_should_be_dropped(false) |
|
593 | + ); |
|
594 | + } |
|
595 | + |
|
596 | + /** |
|
597 | + * Returns whether or not this migration script is being used as part of an actual migration |
|
598 | + * |
|
599 | + * @return boolean |
|
600 | + */ |
|
601 | + protected function _currently_migrating() |
|
602 | + { |
|
603 | + // we want to know if we are currently performing a migration. We could just believe what was set on the _migrating property, but let's double-check (ie the script should apply and we should be in MM) |
|
604 | + return $this->_migrating && |
|
605 | + $this->can_migrate_from_version( |
|
606 | + EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set() |
|
607 | + ) && |
|
608 | + EE_Maintenance_Mode::instance()->real_level() == EE_Maintenance_Mode::level_2_complete_maintenance; |
|
609 | + } |
|
610 | + |
|
611 | + /** |
|
612 | + * Determines if a table should be dropped, based on whether it's reported to be new in $table_is_new, |
|
613 | + * and the plugin's request type. |
|
614 | + * Assumes only this plugin could have added the table (ie, if its a new activation of this plugin, the table |
|
615 | + * shouldn't exist no matter what). |
|
616 | + * |
|
617 | + * @param boolean $table_is_new |
|
618 | + * @return boolean |
|
619 | + */ |
|
620 | + protected function _pre_existing_table_should_be_dropped($table_is_new) |
|
621 | + { |
|
622 | + if ($table_is_new) { |
|
623 | + if ( |
|
624 | + $this->_get_req_type_for_plugin_corresponding_to_this_dms() == EE_System::req_type_new_activation |
|
625 | + || $this->_currently_migrating() |
|
626 | + ) { |
|
627 | + return true; |
|
628 | + } else { |
|
629 | + return false; |
|
630 | + } |
|
631 | + } else { |
|
632 | + if ( |
|
633 | + in_array( |
|
634 | + $this->_get_req_type_for_plugin_corresponding_to_this_dms(), |
|
635 | + array(EE_System::req_type_new_activation) |
|
636 | + ) |
|
637 | + ) { |
|
638 | + return true; |
|
639 | + } else { |
|
640 | + return false; |
|
641 | + } |
|
642 | + } |
|
643 | + } |
|
644 | + |
|
645 | + /** |
|
646 | + * Just wraps EEH_Activation::create_table, but catches any errors it may throw and adds them as errors on the DMS |
|
647 | + * |
|
648 | + * @param string $table_name |
|
649 | + * @param string $table_definition_sql |
|
650 | + * @param string $engine_string |
|
651 | + * @param boolean $drop_pre_existing_tables |
|
652 | + */ |
|
653 | + private function _create_table_and_catch_errors( |
|
654 | + $table_name, |
|
655 | + $table_definition_sql, |
|
656 | + $engine_string = 'ENGINE=MyISAM', |
|
657 | + $drop_pre_existing_tables = false |
|
658 | + ) { |
|
659 | + try { |
|
660 | + EEH_Activation::create_table($table_name, $table_definition_sql, $engine_string, $drop_pre_existing_tables); |
|
661 | + } catch (EE_Error $e) { |
|
662 | + $message = $e->getMessage() . '<br>Stack Trace:' . $e->getTraceAsString(); |
|
663 | + $this->add_error($message); |
|
664 | + $this->_feedback_message .= $message; |
|
665 | + } |
|
666 | + } |
|
667 | + |
|
668 | + |
|
669 | + /** |
|
670 | + * Gets the request type for the plugin (core or addon) that corresponds to this DMS |
|
671 | + * |
|
672 | + * @return int one of EE_System::_req_type_* constants |
|
673 | + * @throws EE_Error |
|
674 | + */ |
|
675 | + private function _get_req_type_for_plugin_corresponding_to_this_dms() |
|
676 | + { |
|
677 | + if ($this->slug() == 'Core') { |
|
678 | + return EE_System::instance()->detect_req_type(); |
|
679 | + } else {// it must be for an addon |
|
680 | + $addon_name = $this->slug(); |
|
681 | + if (EE_Registry::instance()->get_addon_by_name($addon_name)) { |
|
682 | + return EE_Registry::instance()->get_addon_by_name($addon_name)->detect_req_type(); |
|
683 | + } else { |
|
684 | + throw new EE_Error( |
|
685 | + sprintf( |
|
686 | + esc_html__( |
|
687 | + "The DMS slug '%s' should correspond to the addon's name, which should also be '%s', but no such addon was registered. These are the registered addons' names: %s", |
|
688 | + "event_espresso" |
|
689 | + ), |
|
690 | + $this->slug(), |
|
691 | + $addon_name, |
|
692 | + implode(",", array_keys(EE_Registry::instance()->get_addons_by_name())) |
|
693 | + ) |
|
694 | + ); |
|
695 | + } |
|
696 | + } |
|
697 | + } |
|
698 | + |
|
699 | + |
|
700 | + /** |
|
701 | + * returns an array of strings describing errors by all the script's stages |
|
702 | + * |
|
703 | + * @return array |
|
704 | + */ |
|
705 | + public function get_errors() |
|
706 | + { |
|
707 | + $all_errors = $this->_errors; |
|
708 | + if (! is_array($all_errors)) { |
|
709 | + $all_errors = array(); |
|
710 | + } |
|
711 | + foreach ($this->stages() as $stage) { |
|
712 | + $all_errors = array_merge($stage->get_errors(), $all_errors); |
|
713 | + } |
|
714 | + return $all_errors; |
|
715 | + } |
|
716 | + |
|
717 | + |
|
718 | + /** |
|
719 | + * Indicates whether or not this migration script should continue |
|
720 | + * |
|
721 | + * @return boolean |
|
722 | + */ |
|
723 | + public function can_continue() |
|
724 | + { |
|
725 | + return in_array( |
|
726 | + $this->get_status(), |
|
727 | + EE_Data_Migration_Manager::instance()->stati_that_indicate_to_continue_single_migration_script |
|
728 | + ); |
|
729 | + } |
|
730 | + |
|
731 | + |
|
732 | + /** |
|
733 | + * Gets all the data migration stages associated with this script. Note: |
|
734 | + * addons can filter this list to add their own stages, and because the list is |
|
735 | + * numerically-indexed, they can insert their stage wherever they like and it will |
|
736 | + * get ordered by the indexes |
|
737 | + * |
|
738 | + * @return EE_Data_Migration_Script_Stage[] |
|
739 | + */ |
|
740 | + protected function stages() |
|
741 | + { |
|
742 | + $stages = apply_filters('FHEE__' . get_class($this) . '__stages', $this->_migration_stages); |
|
743 | + ksort($stages); |
|
744 | + return $stages; |
|
745 | + } |
|
746 | + |
|
747 | + |
|
748 | + /** |
|
749 | + * Gets a string which should describe what's going on currently with this migration, which |
|
750 | + * can be displayed to the user |
|
751 | + * |
|
752 | + * @return string |
|
753 | + */ |
|
754 | + public function get_feedback_message() |
|
755 | + { |
|
756 | + return $this->_feedback_message; |
|
757 | + } |
|
758 | + |
|
759 | + |
|
760 | + /** |
|
761 | + * A lot like "__sleep()" magic method in purpose, this is meant for persisting this class' |
|
762 | + * properties to the DB. However, we don't want to use __sleep() because its quite |
|
763 | + * possible that this class is defined when it goes to sleep, but NOT available when it |
|
764 | + * awakes (eg, this class is part of an addon that is deactivated at some point). |
|
765 | + */ |
|
766 | + public function properties_as_array() |
|
767 | + { |
|
768 | + $properties = parent::properties_as_array(); |
|
769 | + $properties['_migration_stages'] = array(); |
|
770 | + foreach ($this->_migration_stages as $migration_stage_priority => $migration_stage_class) { |
|
771 | + $properties['_migration_stages'][ $migration_stage_priority ] = $migration_stage_class->properties_as_array( |
|
772 | + ); |
|
773 | + } |
|
774 | + unset($properties['_mappings']); |
|
775 | + unset($properties['previous_dms']); |
|
776 | + |
|
777 | + foreach ($this->_mappings as $old_table_name => $mapping_to_new_table) { |
|
778 | + foreach ($mapping_to_new_table as $new_table_name => $mapping) { |
|
779 | + $this->_set_mapping_option($old_table_name, $new_table_name, $mapping); |
|
780 | + } |
|
781 | + } |
|
782 | + return $properties; |
|
783 | + } |
|
784 | + |
|
785 | + |
|
786 | + /** |
|
787 | + * Sets all of the properties of this script stage to match what's in the array, which is assumed |
|
788 | + * to have been made from the properties_as_array() function. |
|
789 | + * |
|
790 | + * @param array $array_of_properties like what's produced from properties_as_array() method |
|
791 | + * @return void |
|
792 | + */ |
|
793 | + public function instantiate_from_array_of_properties($array_of_properties) |
|
794 | + { |
|
795 | + $stages_properties_arrays = $array_of_properties['_migration_stages']; |
|
796 | + unset($array_of_properties['_migration_stages']); |
|
797 | + unset($array_of_properties['class']); |
|
798 | + foreach ($array_of_properties as $property_name => $property_value) { |
|
799 | + $this->{$property_name} = $property_value; |
|
800 | + } |
|
801 | + // _migration_stages are already instantiated, but have only default data |
|
802 | + foreach ($this->_migration_stages as $stage) { |
|
803 | + $stage_data = $this->_find_migration_stage_data_with_classname( |
|
804 | + get_class($stage), |
|
805 | + $stages_properties_arrays |
|
806 | + ); |
|
807 | + // SO, if we found the stage data that was saved, use it. Otherwise, I guess the stage is new? (maybe added by |
|
808 | + // an addon? Unlikely... not sure why it wouldn't exist, but if it doesn't just treat it like it was never started yet) |
|
809 | + if ($stage_data) { |
|
810 | + $stage->instantiate_from_array_of_properties($stage_data); |
|
811 | + } |
|
812 | + } |
|
813 | + } |
|
814 | + |
|
815 | + |
|
816 | + /** |
|
817 | + * Gets the migration data from the array $migration_stage_data_arrays (which is an array of arrays, each of which |
|
818 | + * is pretty well identical to EE_Data_Migration_Stage objects except all their properties are array indexes) |
|
819 | + * for the given classname |
|
820 | + * |
|
821 | + * @param string $classname |
|
822 | + * @param array $migration_stage_data_arrays |
|
823 | + * @return null |
|
824 | + */ |
|
825 | + private function _find_migration_stage_data_with_classname($classname, $migration_stage_data_arrays) |
|
826 | + { |
|
827 | + foreach ($migration_stage_data_arrays as $migration_stage_data_array) { |
|
828 | + if (isset($migration_stage_data_array['class']) && $migration_stage_data_array['class'] == $classname) { |
|
829 | + return $migration_stage_data_array; |
|
830 | + } |
|
831 | + } |
|
832 | + return null; |
|
833 | + } |
|
834 | + |
|
835 | + |
|
836 | + /** |
|
837 | + * Returns the version that this script migrates to, based on the script's name. |
|
838 | + * Cannot be overwritten because lots of code needs to know which version a script |
|
839 | + * migrates to knowing only its name. |
|
840 | + * |
|
841 | + * @return array where the first key is the plugin's slug, the 2nd is the version of that plugin |
|
842 | + * that will be updated to. Eg array('Core','4.1.0') |
|
843 | + */ |
|
844 | + final public function migrates_to_version() |
|
845 | + { |
|
846 | + return EE_Data_Migration_Manager::instance()->script_migrates_to_version(get_class($this)); |
|
847 | + } |
|
848 | + |
|
849 | + |
|
850 | + /** |
|
851 | + * Gets this addon's slug as it would appear in the current_db_state wp option, |
|
852 | + * and if this migration script is for an addon, it SHOULD match the addon's slug |
|
853 | + * (and also the addon's classname, minus the 'EE_' prefix.). Eg, 'Calendar' for the EE_Calendar addon. |
|
854 | + * Or 'Core' for core (non-addon). |
|
855 | + * |
|
856 | + * @return string |
|
857 | + */ |
|
858 | + public function slug() |
|
859 | + { |
|
860 | + $migrates_to_version_info = $this->migrates_to_version(); |
|
861 | + // the slug is the first part of the array |
|
862 | + return $migrates_to_version_info['slug']; |
|
863 | + } |
|
864 | + |
|
865 | + |
|
866 | + /** |
|
867 | + * Returns the script's priority relative to DMSs from other addons. However, when |
|
868 | + * two DMSs from the same addon/core apply, this is ignored (and instead the version that |
|
869 | + * the script migrates to is used to determine which to run first). The default is 5, but all core DMSs |
|
870 | + * normally have priority 10. (So if you want a DMS "A" to run before DMS "B", both of which are from addons, |
|
871 | + * and both of which CAN run at the same time (ie, "B" doesn't depend on "A" to set |
|
872 | + * the database up so it can run), then you can set "A" to priority 3 or something. |
|
873 | + * |
|
874 | + * @return int |
|
875 | + */ |
|
876 | + public function priority() |
|
877 | + { |
|
878 | + return $this->_priority; |
|
879 | + } |
|
880 | + |
|
881 | + |
|
882 | + /** |
|
883 | + * Sets whether or not this DMS is being ran as part of a migration, instead of |
|
884 | + * just being used to setup (or verify) the current database structure matches |
|
885 | + * what the latest DMS indicates it should be |
|
886 | + * |
|
887 | + * @param boolean $migrating |
|
888 | + * @return void |
|
889 | + */ |
|
890 | + public function set_migrating($migrating = true) |
|
891 | + { |
|
892 | + $this->_migrating = $migrating; |
|
893 | + } |
|
894 | + |
|
895 | + /** |
|
896 | + * Marks that we think this migration class can continue to migrate |
|
897 | + */ |
|
898 | + public function reattempt() |
|
899 | + { |
|
900 | + parent::reattempt(); |
|
901 | + // also, we want to reattempt any stages that were marked as borked |
|
902 | + foreach ($this->stages() as $stage) { |
|
903 | + if ($stage->is_broken()) { |
|
904 | + $stage->reattempt(); |
|
905 | + } |
|
906 | + } |
|
907 | + } |
|
908 | 908 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | { |
19 | 19 | $new_post_content = $this->_change_event_list_shortcode($old_row['post_content']); |
20 | 20 | global $wpdb; |
21 | - $wpdb->query($wpdb->prepare("UPDATE " . $this->_old_table . " SET post_content=%s WHERE ID=%d", $new_post_content, $old_row['ID'])); |
|
21 | + $wpdb->query($wpdb->prepare("UPDATE ".$this->_old_table." SET post_content=%s WHERE ID=%d", $new_post_content, $old_row['ID'])); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | public function _count_records_to_migrate() |
49 | 49 | { |
50 | 50 | global $wpdb; |
51 | - $count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table . $this->_sql_to_only_select_non_drafts()); |
|
51 | + $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table.$this->_sql_to_only_select_non_drafts()); |
|
52 | 52 | return $count; |
53 | 53 | } |
54 | 54 |
@@ -2,58 +2,57 @@ |
||
2 | 2 | |
3 | 3 | /** |
4 | 4 | * Goes through all the posts and pages, and converts old shortcodes to new ones |
5 | - |
|
6 | -*/ |
|
5 | + */ |
|
7 | 6 | |
8 | 7 | class EE_DMS_4_1_0_shortcodes extends EE_Data_Migration_Script_Stage |
9 | 8 | { |
10 | - public function __construct() |
|
11 | - { |
|
12 | - global $wpdb; |
|
13 | - $this->_pretty_name = esc_html__("Shortcodes", "event_espresso"); |
|
14 | - $this->_old_table = $wpdb->posts; |
|
15 | - parent::__construct(); |
|
16 | - } |
|
17 | - protected function _migrate_old_row($old_row) |
|
18 | - { |
|
19 | - $new_post_content = $this->_change_event_list_shortcode($old_row['post_content']); |
|
20 | - global $wpdb; |
|
21 | - $wpdb->query($wpdb->prepare("UPDATE " . $this->_old_table . " SET post_content=%s WHERE ID=%d", $new_post_content, $old_row['ID'])); |
|
22 | - } |
|
9 | + public function __construct() |
|
10 | + { |
|
11 | + global $wpdb; |
|
12 | + $this->_pretty_name = esc_html__("Shortcodes", "event_espresso"); |
|
13 | + $this->_old_table = $wpdb->posts; |
|
14 | + parent::__construct(); |
|
15 | + } |
|
16 | + protected function _migrate_old_row($old_row) |
|
17 | + { |
|
18 | + $new_post_content = $this->_change_event_list_shortcode($old_row['post_content']); |
|
19 | + global $wpdb; |
|
20 | + $wpdb->query($wpdb->prepare("UPDATE " . $this->_old_table . " SET post_content=%s WHERE ID=%d", $new_post_content, $old_row['ID'])); |
|
21 | + } |
|
23 | 22 | |
24 | - /** |
|
25 | - * replaces [EVENT_LIST... with [ESPRESSO_EVENTS...] |
|
26 | - * @param string $old_content |
|
27 | - */ |
|
28 | - private function _change_event_list_shortcode($old_content) |
|
29 | - { |
|
30 | - return str_replace("[EVENT_LIST", "[ESPRESSO_EVENTS", $old_content); |
|
31 | - } |
|
23 | + /** |
|
24 | + * replaces [EVENT_LIST... with [ESPRESSO_EVENTS...] |
|
25 | + * @param string $old_content |
|
26 | + */ |
|
27 | + private function _change_event_list_shortcode($old_content) |
|
28 | + { |
|
29 | + return str_replace("[EVENT_LIST", "[ESPRESSO_EVENTS", $old_content); |
|
30 | + } |
|
32 | 31 | |
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 {$this->_sql_to_only_select_non_drafts()} LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A); |
|
38 | - $items_actually_migrated = 0; |
|
39 | - foreach ($rows as $old_row) { |
|
40 | - $this->_migrate_old_row($old_row); |
|
41 | - $items_actually_migrated++; |
|
42 | - } |
|
43 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
44 | - $this->set_completed(); |
|
45 | - } |
|
46 | - return $items_actually_migrated; |
|
47 | - } |
|
48 | - public function _count_records_to_migrate() |
|
49 | - { |
|
50 | - global $wpdb; |
|
51 | - $count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table . $this->_sql_to_only_select_non_drafts()); |
|
52 | - return $count; |
|
53 | - } |
|
32 | + public function _migration_step($num_items = 50) |
|
33 | + { |
|
34 | + global $wpdb; |
|
35 | + $start_at_record = $this->count_records_migrated(); |
|
36 | + $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table {$this->_sql_to_only_select_non_drafts()} LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A); |
|
37 | + $items_actually_migrated = 0; |
|
38 | + foreach ($rows as $old_row) { |
|
39 | + $this->_migrate_old_row($old_row); |
|
40 | + $items_actually_migrated++; |
|
41 | + } |
|
42 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
43 | + $this->set_completed(); |
|
44 | + } |
|
45 | + return $items_actually_migrated; |
|
46 | + } |
|
47 | + public function _count_records_to_migrate() |
|
48 | + { |
|
49 | + global $wpdb; |
|
50 | + $count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table . $this->_sql_to_only_select_non_drafts()); |
|
51 | + return $count; |
|
52 | + } |
|
54 | 53 | |
55 | - private function _sql_to_only_select_non_drafts() |
|
56 | - { |
|
57 | - return " WHERE post_type NOT IN ('revision','auto-draft','attachment','nav_menu_item') "; |
|
58 | - } |
|
54 | + private function _sql_to_only_select_non_drafts() |
|
55 | + { |
|
56 | + return " WHERE post_type NOT IN ('revision','auto-draft','attachment','nav_menu_item') "; |
|
57 | + } |
|
59 | 58 | } |
@@ -26,160 +26,160 @@ |
||
26 | 26 | |
27 | 27 | class EE_DMS_4_1_0_checkins extends EE_Data_Migration_Script_Stage_Table |
28 | 28 | { |
29 | - private $_new_table; |
|
30 | - public function __construct() |
|
31 | - { |
|
32 | - global $wpdb; |
|
33 | - $this->_pretty_name = esc_html__('Checkins', 'event_espresso'); |
|
34 | - $this->_old_table = $wpdb->prefix . "events_attendee"; |
|
35 | - $this->select_expression = 'att.*, e.event_status'; |
|
36 | - $this->_extra_where_sql = 'AS att |
|
29 | + private $_new_table; |
|
30 | + public function __construct() |
|
31 | + { |
|
32 | + global $wpdb; |
|
33 | + $this->_pretty_name = esc_html__('Checkins', 'event_espresso'); |
|
34 | + $this->_old_table = $wpdb->prefix . "events_attendee"; |
|
35 | + $this->select_expression = 'att.*, e.event_status'; |
|
36 | + $this->_extra_where_sql = 'AS att |
|
37 | 37 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
38 | 38 | WHERE e.event_status!="D"'; |
39 | - $this->_new_table = $wpdb->prefix . "esp_checkin"; |
|
40 | - parent::__construct(); |
|
41 | - } |
|
42 | - protected function _migrate_old_row($old_row) |
|
43 | - { |
|
44 | - global $wpdb; |
|
45 | - $new_reg_table = $wpdb->prefix . "esp_registration"; |
|
39 | + $this->_new_table = $wpdb->prefix . "esp_checkin"; |
|
40 | + parent::__construct(); |
|
41 | + } |
|
42 | + protected function _migrate_old_row($old_row) |
|
43 | + { |
|
44 | + global $wpdb; |
|
45 | + $new_reg_table = $wpdb->prefix . "esp_registration"; |
|
46 | 46 | |
47 | - $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ; |
|
47 | + $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ; |
|
48 | 48 | |
49 | - $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
|
50 | - if (! $new_registrations_for_attendee) { |
|
51 | - $new_registrations_for_attendee = array(); |
|
52 | - } |
|
53 | - $new_datetime = $this->_try_to_find_datetime($old_row); |
|
49 | + $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
|
50 | + if (! $new_registrations_for_attendee) { |
|
51 | + $new_registrations_for_attendee = array(); |
|
52 | + } |
|
53 | + $new_datetime = $this->_try_to_find_datetime($old_row); |
|
54 | 54 | |
55 | - // make sure registrations array is numerically indexed starting at 0 (it probably already is) |
|
56 | - $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
|
57 | - $new_checkin_ids = array(); |
|
58 | - for ($i = 0; $i < abs($num_to_checkin_at_this_time); $i++) { |
|
59 | - $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
60 | - if (! $new_reg_id) { |
|
61 | - $this->add_error(sprintf( |
|
62 | - esc_html__( |
|
63 | - /* translators: %1$s database row represented in JSON, %2$s number of registrations to check-in |
|
55 | + // make sure registrations array is numerically indexed starting at 0 (it probably already is) |
|
56 | + $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
|
57 | + $new_checkin_ids = array(); |
|
58 | + for ($i = 0; $i < abs($num_to_checkin_at_this_time); $i++) { |
|
59 | + $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
60 | + if (! $new_reg_id) { |
|
61 | + $this->add_error(sprintf( |
|
62 | + esc_html__( |
|
63 | + /* translators: %1$s database row represented in JSON, %2$s number of registrations to check-in |
|
64 | 64 | * %3$s number of registrations for the attendee, %4$s new registration rows represented in JSON |
65 | 65 | */ |
66 | - // @codingStandardsIgnoreStart |
|
67 | - 'It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)', |
|
68 | - // @codingStandardsIgnoreEnd |
|
69 | - 'event_espresso' |
|
70 | - ), |
|
71 | - $this->_json_encode($old_row), |
|
72 | - abs($num_to_checkin_at_this_time), |
|
73 | - count($new_registrations_for_attendee), |
|
74 | - $this->_json_encode($new_registrations_for_attendee) |
|
75 | - )); |
|
76 | - break; |
|
77 | - } |
|
78 | - $existing_checkin_record = $wpdb->get_var( |
|
79 | - $wpdb->prepare( |
|
80 | - "SELECT CHK_ID FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", |
|
81 | - $new_reg_id |
|
82 | - ) |
|
83 | - ); |
|
84 | - if (! $existing_checkin_record) { |
|
85 | - $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
|
86 | - if ($new_id) { |
|
87 | - $new_checkin_ids[] = $new_id; |
|
88 | - } |
|
89 | - } |
|
90 | - } |
|
91 | - if ($new_checkin_ids) { |
|
92 | - $this->get_migration_script()->set_mapping( |
|
93 | - $this->_old_table, |
|
94 | - $old_row['id'], |
|
95 | - $this->_new_table, |
|
96 | - $new_checkin_ids |
|
97 | - ); |
|
98 | - } |
|
99 | - } |
|
66 | + // @codingStandardsIgnoreStart |
|
67 | + 'It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)', |
|
68 | + // @codingStandardsIgnoreEnd |
|
69 | + 'event_espresso' |
|
70 | + ), |
|
71 | + $this->_json_encode($old_row), |
|
72 | + abs($num_to_checkin_at_this_time), |
|
73 | + count($new_registrations_for_attendee), |
|
74 | + $this->_json_encode($new_registrations_for_attendee) |
|
75 | + )); |
|
76 | + break; |
|
77 | + } |
|
78 | + $existing_checkin_record = $wpdb->get_var( |
|
79 | + $wpdb->prepare( |
|
80 | + "SELECT CHK_ID FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", |
|
81 | + $new_reg_id |
|
82 | + ) |
|
83 | + ); |
|
84 | + if (! $existing_checkin_record) { |
|
85 | + $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
|
86 | + if ($new_id) { |
|
87 | + $new_checkin_ids[] = $new_id; |
|
88 | + } |
|
89 | + } |
|
90 | + } |
|
91 | + if ($new_checkin_ids) { |
|
92 | + $this->get_migration_script()->set_mapping( |
|
93 | + $this->_old_table, |
|
94 | + $old_row['id'], |
|
95 | + $this->_new_table, |
|
96 | + $new_checkin_ids |
|
97 | + ); |
|
98 | + } |
|
99 | + } |
|
100 | 100 | |
101 | 101 | |
102 | - /** |
|
103 | - * Tries to find the new datetime the Check-in was for, based on the attendee row |
|
104 | - * (because we know the attendee was for an event as a specific time, and we know |
|
105 | - * the event's OLD ID...) |
|
106 | - * @global type $wpdb |
|
107 | - * @param array $old_attendee_row |
|
108 | - * @return array row of datetime from DB |
|
109 | - */ |
|
110 | - private function _try_to_find_datetime($old_attendee) |
|
111 | - { |
|
112 | - global $wpdb; |
|
102 | + /** |
|
103 | + * Tries to find the new datetime the Check-in was for, based on the attendee row |
|
104 | + * (because we know the attendee was for an event as a specific time, and we know |
|
105 | + * the event's OLD ID...) |
|
106 | + * @global type $wpdb |
|
107 | + * @param array $old_attendee_row |
|
108 | + * @return array row of datetime from DB |
|
109 | + */ |
|
110 | + private function _try_to_find_datetime($old_attendee) |
|
111 | + { |
|
112 | + global $wpdb; |
|
113 | 113 | |
114 | - $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_detail", $old_attendee['event_id'], $wpdb->posts); |
|
115 | - if (! $new_event_id) { |
|
116 | - $this->add_error( |
|
117 | - sprintf( |
|
118 | - esc_html__( |
|
119 | - /* translators: 1: original event ID, 2: original attendee database row */ |
|
120 | - // @codingStandardsIgnoreStart |
|
121 | - 'Could not find new event ID with old event ID %1$d, on attendee row %2$s; and because of that couldn\'t find the correct datetime for Check-in', |
|
122 | - // @codingStandardsIgnoreEnd |
|
123 | - 'event_espresso' |
|
124 | - ), |
|
125 | - $old_attendee['event_id'], |
|
126 | - $this->_json_encode($old_attendee) |
|
127 | - ) |
|
128 | - ); |
|
129 | - return 0; |
|
130 | - } |
|
131 | - $old_att_start_date = $old_attendee['start_date']; |
|
132 | - $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
133 | - $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
114 | + $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_detail", $old_attendee['event_id'], $wpdb->posts); |
|
115 | + if (! $new_event_id) { |
|
116 | + $this->add_error( |
|
117 | + sprintf( |
|
118 | + esc_html__( |
|
119 | + /* translators: 1: original event ID, 2: original attendee database row */ |
|
120 | + // @codingStandardsIgnoreStart |
|
121 | + 'Could not find new event ID with old event ID %1$d, on attendee row %2$s; and because of that couldn\'t find the correct datetime for Check-in', |
|
122 | + // @codingStandardsIgnoreEnd |
|
123 | + 'event_espresso' |
|
124 | + ), |
|
125 | + $old_attendee['event_id'], |
|
126 | + $this->_json_encode($old_attendee) |
|
127 | + ) |
|
128 | + ); |
|
129 | + return 0; |
|
130 | + } |
|
131 | + $old_att_start_date = $old_attendee['start_date']; |
|
132 | + $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
133 | + $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
134 | 134 | |
135 | - $datetime_table = $wpdb->prefix . "esp_datetime"; |
|
136 | - // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
137 | - // the most important condition should be last, as it will be array_shift'ed off last |
|
138 | - $conditions = array( |
|
139 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
140 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
141 | - ); |
|
142 | - // start running queries, widening search each time by removing a condition |
|
143 | - $datetime_found = null; |
|
144 | - do { |
|
145 | - $full_query = "SELECT * FROM $datetime_table WHERE " . implode(" AND ", $conditions) . " LIMIT 1"; |
|
146 | - $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
|
147 | - array_shift($conditions); |
|
148 | - } while (! $datetime_found && $conditions); |
|
149 | - return $datetime_found; |
|
150 | - } |
|
135 | + $datetime_table = $wpdb->prefix . "esp_datetime"; |
|
136 | + // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
137 | + // the most important condition should be last, as it will be array_shift'ed off last |
|
138 | + $conditions = array( |
|
139 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
140 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
141 | + ); |
|
142 | + // start running queries, widening search each time by removing a condition |
|
143 | + $datetime_found = null; |
|
144 | + do { |
|
145 | + $full_query = "SELECT * FROM $datetime_table WHERE " . implode(" AND ", $conditions) . " LIMIT 1"; |
|
146 | + $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
|
147 | + array_shift($conditions); |
|
148 | + } while (! $datetime_found && $conditions); |
|
149 | + return $datetime_found; |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap |
|
154 | - * @param int $new_reg_id |
|
155 | - * @param int $new_datetime_id |
|
156 | - * @param string $timestamp mysql datetime |
|
157 | - * @return int new Check-in id |
|
158 | - */ |
|
159 | - private function _insert_checkin_record($new_reg_id, $new_datetime) |
|
160 | - { |
|
161 | - global $wpdb; |
|
152 | + /** |
|
153 | + * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap |
|
154 | + * @param int $new_reg_id |
|
155 | + * @param int $new_datetime_id |
|
156 | + * @param string $timestamp mysql datetime |
|
157 | + * @return int new Check-in id |
|
158 | + */ |
|
159 | + private function _insert_checkin_record($new_reg_id, $new_datetime) |
|
160 | + { |
|
161 | + global $wpdb; |
|
162 | 162 | |
163 | 163 | |
164 | - // ok we can actually do what we set out to do: add a checkin/checkout record |
|
165 | - $cols_n_values = array( |
|
166 | - 'REG_ID' => $new_reg_id, |
|
167 | - 'DTT_ID' => $new_datetime['DTT_ID'], |
|
168 | - 'CHK_in' => true, |
|
169 | - 'CHK_timestamp' => $new_datetime['DTT_EVT_start'] |
|
170 | - ); |
|
171 | - $datatypes = array( |
|
172 | - '%d',// REG_ID |
|
173 | - '%d',// DTT_ID |
|
174 | - '%d',// CHK_in |
|
175 | - '%s',// CHK_timestamp |
|
176 | - ); |
|
177 | - $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
178 | - if (! $success) { |
|
179 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes)); |
|
180 | - return 0; |
|
181 | - } |
|
182 | - $new_id = $wpdb->insert_id; |
|
183 | - return $new_id; |
|
184 | - } |
|
164 | + // ok we can actually do what we set out to do: add a checkin/checkout record |
|
165 | + $cols_n_values = array( |
|
166 | + 'REG_ID' => $new_reg_id, |
|
167 | + 'DTT_ID' => $new_datetime['DTT_ID'], |
|
168 | + 'CHK_in' => true, |
|
169 | + 'CHK_timestamp' => $new_datetime['DTT_EVT_start'] |
|
170 | + ); |
|
171 | + $datatypes = array( |
|
172 | + '%d',// REG_ID |
|
173 | + '%d',// DTT_ID |
|
174 | + '%d',// CHK_in |
|
175 | + '%s',// CHK_timestamp |
|
176 | + ); |
|
177 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
178 | + if (! $success) { |
|
179 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes)); |
|
180 | + return 0; |
|
181 | + } |
|
182 | + $new_id = $wpdb->insert_id; |
|
183 | + return $new_id; |
|
184 | + } |
|
185 | 185 | } |
@@ -31,23 +31,23 @@ discard block |
||
31 | 31 | { |
32 | 32 | global $wpdb; |
33 | 33 | $this->_pretty_name = esc_html__('Checkins', 'event_espresso'); |
34 | - $this->_old_table = $wpdb->prefix . "events_attendee"; |
|
34 | + $this->_old_table = $wpdb->prefix."events_attendee"; |
|
35 | 35 | $this->select_expression = 'att.*, e.event_status'; |
36 | 36 | $this->_extra_where_sql = 'AS att |
37 | - INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
|
37 | + INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id=e.id |
|
38 | 38 | WHERE e.event_status!="D"'; |
39 | - $this->_new_table = $wpdb->prefix . "esp_checkin"; |
|
39 | + $this->_new_table = $wpdb->prefix."esp_checkin"; |
|
40 | 40 | parent::__construct(); |
41 | 41 | } |
42 | 42 | protected function _migrate_old_row($old_row) |
43 | 43 | { |
44 | 44 | global $wpdb; |
45 | - $new_reg_table = $wpdb->prefix . "esp_registration"; |
|
45 | + $new_reg_table = $wpdb->prefix."esp_registration"; |
|
46 | 46 | |
47 | - $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ; |
|
47 | + $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']), intval($old_row['checked_in']))); |
|
48 | 48 | |
49 | 49 | $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
50 | - if (! $new_registrations_for_attendee) { |
|
50 | + if ( ! $new_registrations_for_attendee) { |
|
51 | 51 | $new_registrations_for_attendee = array(); |
52 | 52 | } |
53 | 53 | $new_datetime = $this->_try_to_find_datetime($old_row); |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
57 | 57 | $new_checkin_ids = array(); |
58 | 58 | for ($i = 0; $i < abs($num_to_checkin_at_this_time); $i++) { |
59 | - $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
60 | - if (! $new_reg_id) { |
|
59 | + $new_reg_id = $new_registrations_for_attendee[$i]; |
|
60 | + if ( ! $new_reg_id) { |
|
61 | 61 | $this->add_error(sprintf( |
62 | 62 | esc_html__( |
63 | 63 | /* translators: %1$s database row represented in JSON, %2$s number of registrations to check-in |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | $new_reg_id |
82 | 82 | ) |
83 | 83 | ); |
84 | - if (! $existing_checkin_record) { |
|
84 | + if ( ! $existing_checkin_record) { |
|
85 | 85 | $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
86 | 86 | if ($new_id) { |
87 | 87 | $new_checkin_ids[] = $new_id; |
@@ -111,8 +111,8 @@ discard block |
||
111 | 111 | { |
112 | 112 | global $wpdb; |
113 | 113 | |
114 | - $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_detail", $old_attendee['event_id'], $wpdb->posts); |
|
115 | - if (! $new_event_id) { |
|
114 | + $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts); |
|
115 | + if ( ! $new_event_id) { |
|
116 | 116 | $this->add_error( |
117 | 117 | sprintf( |
118 | 118 | esc_html__( |
@@ -132,20 +132,20 @@ discard block |
||
132 | 132 | $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
133 | 133 | $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
134 | 134 | |
135 | - $datetime_table = $wpdb->prefix . "esp_datetime"; |
|
135 | + $datetime_table = $wpdb->prefix."esp_datetime"; |
|
136 | 136 | // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
137 | 137 | // the most important condition should be last, as it will be array_shift'ed off last |
138 | 138 | $conditions = array( |
139 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
140 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
139 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime), // times match? |
|
140 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id), // events match? |
|
141 | 141 | ); |
142 | 142 | // start running queries, widening search each time by removing a condition |
143 | 143 | $datetime_found = null; |
144 | 144 | do { |
145 | - $full_query = "SELECT * FROM $datetime_table WHERE " . implode(" AND ", $conditions) . " LIMIT 1"; |
|
145 | + $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
|
146 | 146 | $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
147 | 147 | array_shift($conditions); |
148 | - } while (! $datetime_found && $conditions); |
|
148 | + }while ( ! $datetime_found && $conditions); |
|
149 | 149 | return $datetime_found; |
150 | 150 | } |
151 | 151 | |
@@ -169,13 +169,13 @@ discard block |
||
169 | 169 | 'CHK_timestamp' => $new_datetime['DTT_EVT_start'] |
170 | 170 | ); |
171 | 171 | $datatypes = array( |
172 | - '%d',// REG_ID |
|
173 | - '%d',// DTT_ID |
|
174 | - '%d',// CHK_in |
|
175 | - '%s',// CHK_timestamp |
|
172 | + '%d', // REG_ID |
|
173 | + '%d', // DTT_ID |
|
174 | + '%d', // CHK_in |
|
175 | + '%s', // CHK_timestamp |
|
176 | 176 | ); |
177 | 177 | $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
178 | - if (! $success) { |
|
178 | + if ( ! $success) { |
|
179 | 179 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes)); |
180 | 180 | return 0; |
181 | 181 | } |
@@ -12,9 +12,9 @@ discard block |
||
12 | 12 | $stages = glob(EE_CORE . 'data_migration_scripts/4_9_0_stages/*'); |
13 | 13 | $class_to_filepath = array(); |
14 | 14 | foreach ($stages as $filepath) { |
15 | - $matches = array(); |
|
16 | - preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
17 | - $class_to_filepath[ $matches[1] ] = $filepath; |
|
15 | + $matches = array(); |
|
16 | + preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
17 | + $class_to_filepath[ $matches[1] ] = $filepath; |
|
18 | 18 | } |
19 | 19 | // give addons a chance to autoload their stages too |
20 | 20 | $class_to_filepath = apply_filters('FHEE__EE_DMS_4_9_0__autoloaded_stages', $class_to_filepath); |
@@ -34,68 +34,68 @@ discard block |
||
34 | 34 | class EE_DMS_Core_4_9_0 extends EE_Data_Migration_Script_Base |
35 | 35 | { |
36 | 36 | |
37 | - /** |
|
38 | - * return EE_DMS_Core_4_9_0 |
|
39 | - * |
|
40 | - * @param TableManager $table_manager |
|
41 | - * @param TableAnalysis $table_analysis |
|
42 | - */ |
|
43 | - public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
44 | - { |
|
45 | - $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso"); |
|
46 | - $this->_priority = 10; |
|
47 | - $this->_migration_stages = array( |
|
48 | - new EE_DMS_4_9_0_Email_System_Question(), |
|
49 | - new EE_DMS_4_9_0_Answers_With_No_Registration(), |
|
50 | - ); |
|
51 | - parent::__construct($table_manager, $table_analysis); |
|
52 | - } |
|
37 | + /** |
|
38 | + * return EE_DMS_Core_4_9_0 |
|
39 | + * |
|
40 | + * @param TableManager $table_manager |
|
41 | + * @param TableAnalysis $table_analysis |
|
42 | + */ |
|
43 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
44 | + { |
|
45 | + $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso"); |
|
46 | + $this->_priority = 10; |
|
47 | + $this->_migration_stages = array( |
|
48 | + new EE_DMS_4_9_0_Email_System_Question(), |
|
49 | + new EE_DMS_4_9_0_Answers_With_No_Registration(), |
|
50 | + ); |
|
51 | + parent::__construct($table_manager, $table_analysis); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * Whether to migrate or not. |
|
58 | - * |
|
59 | - * @param array $version_array |
|
60 | - * @return bool |
|
61 | - */ |
|
62 | - public function can_migrate_from_version($version_array) |
|
63 | - { |
|
64 | - $version_string = $version_array['Core']; |
|
65 | - if (version_compare($version_string, '4.9.0.decaf', '<') && version_compare($version_string, '4.8.0.decaf', '>=')) { |
|
66 | - // echo "$version_string can be migrated from"; |
|
67 | - return true; |
|
68 | - } elseif (! $version_string) { |
|
69 | - // echo "no version string provided: $version_string"; |
|
70 | - // no version string provided... this must be pre 4.3 |
|
71 | - return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
72 | - } else { |
|
73 | - // echo "$version_string doesnt apply"; |
|
74 | - return false; |
|
75 | - } |
|
76 | - } |
|
56 | + /** |
|
57 | + * Whether to migrate or not. |
|
58 | + * |
|
59 | + * @param array $version_array |
|
60 | + * @return bool |
|
61 | + */ |
|
62 | + public function can_migrate_from_version($version_array) |
|
63 | + { |
|
64 | + $version_string = $version_array['Core']; |
|
65 | + if (version_compare($version_string, '4.9.0.decaf', '<') && version_compare($version_string, '4.8.0.decaf', '>=')) { |
|
66 | + // echo "$version_string can be migrated from"; |
|
67 | + return true; |
|
68 | + } elseif (! $version_string) { |
|
69 | + // echo "no version string provided: $version_string"; |
|
70 | + // no version string provided... this must be pre 4.3 |
|
71 | + return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
72 | + } else { |
|
73 | + // echo "$version_string doesnt apply"; |
|
74 | + return false; |
|
75 | + } |
|
76 | + } |
|
77 | 77 | |
78 | 78 | |
79 | 79 | |
80 | - /** |
|
81 | - * @return bool |
|
82 | - */ |
|
83 | - public function schema_changes_before_migration() |
|
84 | - { |
|
85 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
86 | - $now_in_mysql = current_time('mysql', true); |
|
87 | - $table_name = 'esp_answer'; |
|
88 | - $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
80 | + /** |
|
81 | + * @return bool |
|
82 | + */ |
|
83 | + public function schema_changes_before_migration() |
|
84 | + { |
|
85 | + require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
86 | + $now_in_mysql = current_time('mysql', true); |
|
87 | + $table_name = 'esp_answer'; |
|
88 | + $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
89 | 89 | REG_ID int(10) unsigned NOT NULL, |
90 | 90 | QST_ID int(10) unsigned NOT NULL, |
91 | 91 | ANS_value text NOT NULL, |
92 | 92 | PRIMARY KEY (ANS_ID), |
93 | 93 | KEY REG_ID (REG_ID), |
94 | 94 | KEY QST_ID (QST_ID)"; |
95 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
96 | - $table_name = 'esp_attendee_meta'; |
|
97 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email'); |
|
98 | - $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
95 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
96 | + $table_name = 'esp_attendee_meta'; |
|
97 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email'); |
|
98 | + $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
99 | 99 | ATT_ID bigint(20) unsigned NOT NULL, |
100 | 100 | ATT_fname varchar(45) NOT NULL, |
101 | 101 | ATT_lname varchar(45) NOT NULL, |
@@ -112,9 +112,9 @@ discard block |
||
112 | 112 | KEY ATT_email (ATT_email(191)), |
113 | 113 | KEY ATT_lname (ATT_lname), |
114 | 114 | KEY ATT_fname (ATT_fname)"; |
115 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
116 | - $table_name = 'esp_checkin'; |
|
117 | - $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
115 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
116 | + $table_name = 'esp_checkin'; |
|
117 | + $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
118 | 118 | REG_ID int(10) unsigned NOT NULL, |
119 | 119 | DTT_ID int(10) unsigned NOT NULL, |
120 | 120 | CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -122,9 +122,9 @@ discard block |
||
122 | 122 | PRIMARY KEY (CHK_ID), |
123 | 123 | KEY REG_ID (REG_ID), |
124 | 124 | KEY DTT_ID (DTT_ID)"; |
125 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
126 | - $table_name = 'esp_country'; |
|
127 | - $sql = "CNT_ISO varchar(2) NOT NULL, |
|
125 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
126 | + $table_name = 'esp_country'; |
|
127 | + $sql = "CNT_ISO varchar(2) NOT NULL, |
|
128 | 128 | CNT_ISO3 varchar(3) NOT NULL, |
129 | 129 | RGN_ID tinyint(3) unsigned DEFAULT NULL, |
130 | 130 | CNT_name varchar(45) NOT NULL, |
@@ -140,29 +140,29 @@ discard block |
||
140 | 140 | CNT_is_EU tinyint(1) DEFAULT '0', |
141 | 141 | CNT_active tinyint(1) DEFAULT '0', |
142 | 142 | PRIMARY KEY (CNT_ISO)"; |
143 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
144 | - $table_name = 'esp_currency'; |
|
145 | - $sql = "CUR_code varchar(6) NOT NULL, |
|
143 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
144 | + $table_name = 'esp_currency'; |
|
145 | + $sql = "CUR_code varchar(6) NOT NULL, |
|
146 | 146 | CUR_single varchar(45) DEFAULT 'dollar', |
147 | 147 | CUR_plural varchar(45) DEFAULT 'dollars', |
148 | 148 | CUR_sign varchar(45) DEFAULT '$', |
149 | 149 | CUR_dec_plc varchar(1) NOT NULL DEFAULT '2', |
150 | 150 | CUR_active tinyint(1) DEFAULT '0', |
151 | 151 | PRIMARY KEY (CUR_code)"; |
152 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
153 | - // note: although this table is no longer in use, |
|
154 | - // it hasn't been removed because then queries to the model will have errors. |
|
155 | - // but you should expect this table and its corresponding model to be removed in |
|
156 | - // the next few months |
|
157 | - $table_name = 'esp_currency_payment_method'; |
|
158 | - $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
152 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
153 | + // note: although this table is no longer in use, |
|
154 | + // it hasn't been removed because then queries to the model will have errors. |
|
155 | + // but you should expect this table and its corresponding model to be removed in |
|
156 | + // the next few months |
|
157 | + $table_name = 'esp_currency_payment_method'; |
|
158 | + $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
159 | 159 | CUR_code varchar(6) NOT NULL, |
160 | 160 | PMD_ID int(11) NOT NULL, |
161 | 161 | PRIMARY KEY (CPM_ID), |
162 | 162 | KEY PMD_ID (PMD_ID)"; |
163 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
164 | - $table_name = 'esp_datetime'; |
|
165 | - $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
163 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
164 | + $table_name = 'esp_datetime'; |
|
165 | + $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
166 | 166 | EVT_ID bigint(20) unsigned NOT NULL, |
167 | 167 | DTT_name varchar(255) NOT NULL DEFAULT '', |
168 | 168 | DTT_description text NOT NULL, |
@@ -179,25 +179,25 @@ discard block |
||
179 | 179 | KEY DTT_EVT_start (DTT_EVT_start), |
180 | 180 | KEY EVT_ID (EVT_ID), |
181 | 181 | KEY DTT_is_primary (DTT_is_primary)"; |
182 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
183 | - $table_name = "esp_datetime_ticket"; |
|
184 | - $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
182 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
183 | + $table_name = "esp_datetime_ticket"; |
|
184 | + $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
185 | 185 | DTT_ID int(10) unsigned NOT NULL, |
186 | 186 | TKT_ID int(10) unsigned NOT NULL, |
187 | 187 | PRIMARY KEY (DTK_ID), |
188 | 188 | KEY DTT_ID (DTT_ID), |
189 | 189 | KEY TKT_ID (TKT_ID)"; |
190 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
191 | - $table_name = 'esp_event_message_template'; |
|
192 | - $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
190 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
191 | + $table_name = 'esp_event_message_template'; |
|
192 | + $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
193 | 193 | EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
194 | 194 | GRP_ID int(10) unsigned NOT NULL DEFAULT 0, |
195 | 195 | PRIMARY KEY (EMT_ID), |
196 | 196 | KEY EVT_ID (EVT_ID), |
197 | 197 | KEY GRP_ID (GRP_ID)"; |
198 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
199 | - $table_name = 'esp_event_meta'; |
|
200 | - $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
198 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
199 | + $table_name = 'esp_event_meta'; |
|
200 | + $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
201 | 201 | EVT_ID bigint(20) unsigned NOT NULL, |
202 | 202 | EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1, |
203 | 203 | EVT_display_ticket_selector tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -212,34 +212,34 @@ discard block |
||
212 | 212 | EVT_donations tinyint(1) NULL, |
213 | 213 | PRIMARY KEY (EVTM_ID), |
214 | 214 | KEY EVT_ID (EVT_ID)"; |
215 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
216 | - $table_name = 'esp_event_question_group'; |
|
217 | - $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
215 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
216 | + $table_name = 'esp_event_question_group'; |
|
217 | + $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
218 | 218 | EVT_ID bigint(20) unsigned NOT NULL, |
219 | 219 | QSG_ID int(10) unsigned NOT NULL, |
220 | 220 | EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
221 | 221 | PRIMARY KEY (EQG_ID), |
222 | 222 | KEY EVT_ID (EVT_ID), |
223 | 223 | KEY QSG_ID (QSG_ID)"; |
224 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
225 | - $table_name = 'esp_event_venue'; |
|
226 | - $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
224 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
225 | + $table_name = 'esp_event_venue'; |
|
226 | + $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
227 | 227 | EVT_ID bigint(20) unsigned NOT NULL, |
228 | 228 | VNU_ID bigint(20) unsigned NOT NULL, |
229 | 229 | EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
230 | 230 | PRIMARY KEY (EVV_ID)"; |
231 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
232 | - $table_name = 'esp_extra_meta'; |
|
233 | - $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
231 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
232 | + $table_name = 'esp_extra_meta'; |
|
233 | + $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
234 | 234 | OBJ_ID int(11) DEFAULT NULL, |
235 | 235 | EXM_type varchar(45) DEFAULT NULL, |
236 | 236 | EXM_key varchar(45) DEFAULT NULL, |
237 | 237 | EXM_value text, |
238 | 238 | PRIMARY KEY (EXM_ID), |
239 | 239 | KEY EXM_type (EXM_type,OBJ_ID,EXM_key)"; |
240 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
241 | - $table_name = 'esp_extra_join'; |
|
242 | - $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
240 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
241 | + $table_name = 'esp_extra_join'; |
|
242 | + $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
243 | 243 | EXJ_first_model_id varchar(6) NOT NULL, |
244 | 244 | EXJ_first_model_name varchar(20) NOT NULL, |
245 | 245 | EXJ_second_model_id varchar(6) NOT NULL, |
@@ -247,9 +247,9 @@ discard block |
||
247 | 247 | PRIMARY KEY (EXJ_ID), |
248 | 248 | KEY first_model (EXJ_first_model_name,EXJ_first_model_id), |
249 | 249 | KEY second_model (EXJ_second_model_name,EXJ_second_model_id)"; |
250 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
251 | - $table_name = 'esp_line_item'; |
|
252 | - $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
250 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
251 | + $table_name = 'esp_line_item'; |
|
252 | + $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
253 | 253 | LIN_code varchar(245) NOT NULL DEFAULT '', |
254 | 254 | TXN_ID int(11) DEFAULT NULL, |
255 | 255 | LIN_name varchar(245) NOT NULL DEFAULT '', |
@@ -270,11 +270,11 @@ discard block |
||
270 | 270 | KEY txn_type_timestamp (TXN_ID,LIN_type,LIN_timestamp), |
271 | 271 | KEY txn_obj_id_obj_type (TXN_ID,OBJ_ID,OBJ_type), |
272 | 272 | KEY obj_id_obj_type (OBJ_ID,OBJ_type)"; |
273 | - $this->_get_table_manager()->dropIndex('esp_line_item', 'TXN_ID'); |
|
274 | - $this->_get_table_manager()->dropIndex('esp_line_item', 'LIN_code'); |
|
275 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
276 | - $table_name = 'esp_log'; |
|
277 | - $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
273 | + $this->_get_table_manager()->dropIndex('esp_line_item', 'TXN_ID'); |
|
274 | + $this->_get_table_manager()->dropIndex('esp_line_item', 'LIN_code'); |
|
275 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
276 | + $table_name = 'esp_log'; |
|
277 | + $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
278 | 278 | LOG_time datetime DEFAULT NULL, |
279 | 279 | OBJ_ID varchar(45) DEFAULT NULL, |
280 | 280 | OBJ_type varchar(45) DEFAULT NULL, |
@@ -285,12 +285,12 @@ discard block |
||
285 | 285 | KEY LOG_time (LOG_time), |
286 | 286 | KEY OBJ (OBJ_type,OBJ_ID), |
287 | 287 | KEY LOG_type (LOG_type)"; |
288 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
289 | - $table_name = 'esp_message'; |
|
290 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to'); |
|
291 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from'); |
|
292 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject'); |
|
293 | - $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
288 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
289 | + $table_name = 'esp_message'; |
|
290 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to'); |
|
291 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from'); |
|
292 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject'); |
|
293 | + $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
294 | 294 | GRP_ID int(10) unsigned NULL, |
295 | 295 | MSG_token varchar(255) NULL, |
296 | 296 | TXN_ID int(10) unsigned NULL, |
@@ -322,18 +322,18 @@ discard block |
||
322 | 322 | KEY STS_ID (STS_ID), |
323 | 323 | KEY MSG_created (MSG_created), |
324 | 324 | KEY MSG_modified (MSG_modified)"; |
325 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
326 | - $table_name = 'esp_message_template'; |
|
327 | - $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
325 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
326 | + $table_name = 'esp_message_template'; |
|
327 | + $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
328 | 328 | GRP_ID int(10) unsigned NOT NULL, |
329 | 329 | MTP_context varchar(50) NOT NULL, |
330 | 330 | MTP_template_field varchar(30) NOT NULL, |
331 | 331 | MTP_content text NOT NULL, |
332 | 332 | PRIMARY KEY (MTP_ID), |
333 | 333 | KEY GRP_ID (GRP_ID)"; |
334 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
335 | - $table_name = 'esp_message_template_group'; |
|
336 | - $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
334 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
335 | + $table_name = 'esp_message_template_group'; |
|
336 | + $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
337 | 337 | MTP_user_id int(10) NOT NULL DEFAULT '1', |
338 | 338 | MTP_name varchar(245) NOT NULL DEFAULT '', |
339 | 339 | MTP_description varchar(245) NOT NULL DEFAULT '', |
@@ -345,9 +345,9 @@ discard block |
||
345 | 345 | MTP_is_active tinyint(1) NOT NULL DEFAULT '1', |
346 | 346 | PRIMARY KEY (GRP_ID), |
347 | 347 | KEY MTP_user_id (MTP_user_id)"; |
348 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
349 | - $table_name = 'esp_payment'; |
|
350 | - $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
348 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
349 | + $table_name = 'esp_payment'; |
|
350 | + $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
351 | 351 | TXN_ID int(10) unsigned DEFAULT NULL, |
352 | 352 | STS_ID varchar(3) DEFAULT NULL, |
353 | 353 | PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -364,9 +364,9 @@ discard block |
||
364 | 364 | PRIMARY KEY (PAY_ID), |
365 | 365 | KEY PAY_timestamp (PAY_timestamp), |
366 | 366 | KEY TXN_ID (TXN_ID)"; |
367 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
368 | - $table_name = 'esp_payment_method'; |
|
369 | - $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
367 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
368 | + $table_name = 'esp_payment_method'; |
|
369 | + $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
370 | 370 | PMD_type varchar(124) DEFAULT NULL, |
371 | 371 | PMD_name varchar(255) DEFAULT NULL, |
372 | 372 | PMD_desc text, |
@@ -382,24 +382,24 @@ discard block |
||
382 | 382 | PRIMARY KEY (PMD_ID), |
383 | 383 | UNIQUE KEY PMD_slug_UNIQUE (PMD_slug), |
384 | 384 | KEY PMD_type (PMD_type)"; |
385 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
386 | - $table_name = "esp_ticket_price"; |
|
387 | - $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
385 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
386 | + $table_name = "esp_ticket_price"; |
|
387 | + $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
388 | 388 | TKT_ID int(10) unsigned NOT NULL, |
389 | 389 | PRC_ID int(10) unsigned NOT NULL, |
390 | 390 | PRIMARY KEY (TKP_ID), |
391 | 391 | KEY TKT_ID (TKT_ID), |
392 | 392 | KEY PRC_ID (PRC_ID)"; |
393 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
394 | - $table_name = "esp_ticket_template"; |
|
395 | - $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
393 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
394 | + $table_name = "esp_ticket_template"; |
|
395 | + $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
396 | 396 | TTM_name varchar(45) NOT NULL, |
397 | 397 | TTM_description text, |
398 | 398 | TTM_file varchar(45), |
399 | 399 | PRIMARY KEY (TTM_ID)"; |
400 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
401 | - $table_name = 'esp_question'; |
|
402 | - $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
400 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
401 | + $table_name = 'esp_question'; |
|
402 | + $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
403 | 403 | QST_display_text text NOT NULL, |
404 | 404 | QST_admin_label varchar(255) NOT NULL, |
405 | 405 | QST_system varchar(25) DEFAULT NULL, |
@@ -413,18 +413,18 @@ discard block |
||
413 | 413 | QST_deleted tinyint(2) unsigned NOT NULL DEFAULT 0, |
414 | 414 | PRIMARY KEY (QST_ID), |
415 | 415 | KEY QST_order (QST_order)'; |
416 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
417 | - $table_name = 'esp_question_group_question'; |
|
418 | - $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
416 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
417 | + $table_name = 'esp_question_group_question'; |
|
418 | + $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
419 | 419 | QSG_ID int(10) unsigned NOT NULL, |
420 | 420 | QST_ID int(10) unsigned NOT NULL, |
421 | 421 | QGQ_order int(10) unsigned NOT NULL DEFAULT 0, |
422 | 422 | PRIMARY KEY (QGQ_ID), |
423 | 423 | KEY QST_ID (QST_ID), |
424 | 424 | KEY QSG_ID_order (QSG_ID,QGQ_order)"; |
425 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
426 | - $table_name = 'esp_question_option'; |
|
427 | - $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
425 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
426 | + $table_name = 'esp_question_option'; |
|
427 | + $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
428 | 428 | QSO_value varchar(255) NOT NULL, |
429 | 429 | QSO_desc text NOT NULL, |
430 | 430 | QST_ID int(10) unsigned NOT NULL, |
@@ -434,9 +434,9 @@ discard block |
||
434 | 434 | PRIMARY KEY (QSO_ID), |
435 | 435 | KEY QST_ID (QST_ID), |
436 | 436 | KEY QSO_order (QSO_order)"; |
437 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
438 | - $table_name = 'esp_registration'; |
|
439 | - $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
437 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
438 | + $table_name = 'esp_registration'; |
|
439 | + $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
440 | 440 | EVT_ID bigint(20) unsigned NOT NULL, |
441 | 441 | ATT_ID bigint(20) unsigned NOT NULL, |
442 | 442 | TXN_ID int(10) unsigned NOT NULL, |
@@ -460,18 +460,18 @@ discard block |
||
460 | 460 | KEY TKT_ID (TKT_ID), |
461 | 461 | KEY EVT_ID (EVT_ID), |
462 | 462 | KEY STS_ID (STS_ID)"; |
463 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
464 | - $table_name = 'esp_registration_payment'; |
|
465 | - $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
463 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
464 | + $table_name = 'esp_registration_payment'; |
|
465 | + $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
466 | 466 | REG_ID int(10) unsigned NOT NULL, |
467 | 467 | PAY_ID int(10) unsigned NULL, |
468 | 468 | RPY_amount decimal(12,3) NOT NULL DEFAULT '0.00', |
469 | 469 | PRIMARY KEY (RPY_ID), |
470 | 470 | KEY REG_ID (REG_ID), |
471 | 471 | KEY PAY_ID (PAY_ID)"; |
472 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
473 | - $table_name = 'esp_state'; |
|
474 | - $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
472 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
473 | + $table_name = 'esp_state'; |
|
474 | + $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
475 | 475 | CNT_ISO varchar(2) NOT NULL, |
476 | 476 | STA_abbrev varchar(24) NOT NULL, |
477 | 477 | STA_name varchar(100) NOT NULL, |
@@ -479,9 +479,9 @@ discard block |
||
479 | 479 | PRIMARY KEY (STA_ID), |
480 | 480 | KEY STA_abbrev (STA_abbrev), |
481 | 481 | KEY CNT_ISO (CNT_ISO)"; |
482 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
483 | - $table_name = 'esp_status'; |
|
484 | - $sql = "STS_ID varchar(3) NOT NULL, |
|
482 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
483 | + $table_name = 'esp_status'; |
|
484 | + $sql = "STS_ID varchar(3) NOT NULL, |
|
485 | 485 | STS_code varchar(45) NOT NULL, |
486 | 486 | STS_type varchar(45) NOT NULL, |
487 | 487 | STS_can_edit tinyint(1) NOT NULL DEFAULT 0, |
@@ -489,9 +489,9 @@ discard block |
||
489 | 489 | STS_open tinyint(1) NOT NULL DEFAULT 1, |
490 | 490 | UNIQUE KEY STS_ID_UNIQUE (STS_ID), |
491 | 491 | KEY STS_type (STS_type)"; |
492 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
493 | - $table_name = 'esp_transaction'; |
|
494 | - $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
492 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
493 | + $table_name = 'esp_transaction'; |
|
494 | + $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
495 | 495 | TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
496 | 496 | TXN_total decimal(12,3) DEFAULT '0.00', |
497 | 497 | TXN_paid decimal(12,3) NOT NULL DEFAULT '0.00', |
@@ -503,9 +503,9 @@ discard block |
||
503 | 503 | PRIMARY KEY (TXN_ID), |
504 | 504 | KEY TXN_timestamp (TXN_timestamp), |
505 | 505 | KEY STS_ID (STS_ID)"; |
506 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
507 | - $table_name = 'esp_venue_meta'; |
|
508 | - $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
506 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
507 | + $table_name = 'esp_venue_meta'; |
|
508 | + $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
509 | 509 | VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
510 | 510 | VNU_address varchar(255) DEFAULT NULL, |
511 | 511 | VNU_address2 varchar(255) DEFAULT NULL, |
@@ -524,10 +524,10 @@ discard block |
||
524 | 524 | KEY VNU_ID (VNU_ID), |
525 | 525 | KEY STA_ID (STA_ID), |
526 | 526 | KEY CNT_ISO (CNT_ISO)"; |
527 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
528 | - // modified tables |
|
529 | - $table_name = "esp_price"; |
|
530 | - $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
527 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
528 | + // modified tables |
|
529 | + $table_name = "esp_price"; |
|
530 | + $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
531 | 531 | PRT_ID tinyint(3) unsigned NOT NULL, |
532 | 532 | PRC_amount decimal(12,3) NOT NULL DEFAULT '0.00', |
533 | 533 | PRC_name varchar(245) NOT NULL, |
@@ -540,9 +540,9 @@ discard block |
||
540 | 540 | PRC_parent int(10) unsigned DEFAULT 0, |
541 | 541 | PRIMARY KEY (PRC_ID), |
542 | 542 | KEY PRT_ID (PRT_ID)"; |
543 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
544 | - $table_name = "esp_price_type"; |
|
545 | - $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
543 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
544 | + $table_name = "esp_price_type"; |
|
545 | + $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
546 | 546 | PRT_name varchar(45) NOT NULL, |
547 | 547 | PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1', |
548 | 548 | PRT_is_percent tinyint(1) NOT NULL DEFAULT '0', |
@@ -551,9 +551,9 @@ discard block |
||
551 | 551 | PRT_deleted tinyint(1) NOT NULL DEFAULT '0', |
552 | 552 | UNIQUE KEY PRT_name_UNIQUE (PRT_name), |
553 | 553 | PRIMARY KEY (PRT_ID)"; |
554 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
555 | - $table_name = "esp_ticket"; |
|
556 | - $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
554 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
555 | + $table_name = "esp_ticket"; |
|
556 | + $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
557 | 557 | TTM_ID int(10) unsigned NOT NULL, |
558 | 558 | TKT_name varchar(245) NOT NULL DEFAULT '', |
559 | 559 | TKT_description text NOT NULL, |
@@ -576,9 +576,9 @@ discard block |
||
576 | 576 | TKT_deleted tinyint(1) NOT NULL DEFAULT '0', |
577 | 577 | PRIMARY KEY (TKT_ID), |
578 | 578 | KEY TKT_start_date (TKT_start_date)"; |
579 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
580 | - $table_name = 'esp_question_group'; |
|
581 | - $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
579 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
580 | + $table_name = 'esp_question_group'; |
|
581 | + $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
582 | 582 | QSG_name varchar(255) NOT NULL, |
583 | 583 | QSG_identifier varchar(100) NOT NULL, |
584 | 584 | QSG_desc text NULL, |
@@ -591,165 +591,165 @@ discard block |
||
591 | 591 | PRIMARY KEY (QSG_ID), |
592 | 592 | UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier), |
593 | 593 | KEY QSG_order (QSG_order)'; |
594 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
595 | - $this->insert_default_data(); |
|
596 | - return true; |
|
597 | - } |
|
594 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
595 | + $this->insert_default_data(); |
|
596 | + return true; |
|
597 | + } |
|
598 | 598 | |
599 | - /** |
|
600 | - * Inserts default data after parent was called. |
|
601 | - * @since 4.10.0.p |
|
602 | - * @throws EE_Error |
|
603 | - * @throws InvalidArgumentException |
|
604 | - * @throws ReflectionException |
|
605 | - * @throws InvalidDataTypeException |
|
606 | - * @throws InvalidInterfaceException |
|
607 | - */ |
|
608 | - public function insert_default_data() |
|
609 | - { |
|
610 | - /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */ |
|
611 | - $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0'); |
|
612 | - // (because many need to convert old string states to foreign keys into the states table) |
|
613 | - $script_4_1_defaults->insert_default_states(); |
|
614 | - $script_4_1_defaults->insert_default_countries(); |
|
615 | - /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */ |
|
616 | - $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0'); |
|
617 | - $script_4_5_defaults->insert_default_price_types(); |
|
618 | - $script_4_5_defaults->insert_default_prices(); |
|
619 | - $script_4_5_defaults->insert_default_tickets(); |
|
620 | - /** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */ |
|
621 | - $script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0'); |
|
622 | - $script_4_6_defaults->add_default_admin_only_payments(); |
|
623 | - $script_4_6_defaults->insert_default_currencies(); |
|
624 | - /** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */ |
|
625 | - $script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0'); |
|
626 | - $script_4_8_defaults->verify_new_countries(); |
|
627 | - $script_4_8_defaults->verify_new_currencies(); |
|
628 | - $this->verify_db_collations(); |
|
629 | - $this->verify_db_collations_again(); |
|
630 | - } |
|
599 | + /** |
|
600 | + * Inserts default data after parent was called. |
|
601 | + * @since 4.10.0.p |
|
602 | + * @throws EE_Error |
|
603 | + * @throws InvalidArgumentException |
|
604 | + * @throws ReflectionException |
|
605 | + * @throws InvalidDataTypeException |
|
606 | + * @throws InvalidInterfaceException |
|
607 | + */ |
|
608 | + public function insert_default_data() |
|
609 | + { |
|
610 | + /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */ |
|
611 | + $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0'); |
|
612 | + // (because many need to convert old string states to foreign keys into the states table) |
|
613 | + $script_4_1_defaults->insert_default_states(); |
|
614 | + $script_4_1_defaults->insert_default_countries(); |
|
615 | + /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */ |
|
616 | + $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0'); |
|
617 | + $script_4_5_defaults->insert_default_price_types(); |
|
618 | + $script_4_5_defaults->insert_default_prices(); |
|
619 | + $script_4_5_defaults->insert_default_tickets(); |
|
620 | + /** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */ |
|
621 | + $script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0'); |
|
622 | + $script_4_6_defaults->add_default_admin_only_payments(); |
|
623 | + $script_4_6_defaults->insert_default_currencies(); |
|
624 | + /** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */ |
|
625 | + $script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0'); |
|
626 | + $script_4_8_defaults->verify_new_countries(); |
|
627 | + $script_4_8_defaults->verify_new_currencies(); |
|
628 | + $this->verify_db_collations(); |
|
629 | + $this->verify_db_collations_again(); |
|
630 | + } |
|
631 | 631 | |
632 | 632 | |
633 | 633 | |
634 | - /** |
|
635 | - * @return boolean |
|
636 | - */ |
|
637 | - public function schema_changes_after_migration() |
|
638 | - { |
|
639 | - return true; |
|
640 | - } |
|
634 | + /** |
|
635 | + * @return boolean |
|
636 | + */ |
|
637 | + public function schema_changes_after_migration() |
|
638 | + { |
|
639 | + return true; |
|
640 | + } |
|
641 | 641 | |
642 | 642 | |
643 | 643 | |
644 | - public function migration_page_hooks() |
|
645 | - { |
|
646 | - } |
|
644 | + public function migration_page_hooks() |
|
645 | + { |
|
646 | + } |
|
647 | 647 | |
648 | 648 | |
649 | 649 | |
650 | - /** |
|
651 | - * Verify all EE4 models' tables use utf8mb4 collation |
|
652 | - * |
|
653 | - * @return void |
|
654 | - */ |
|
655 | - public function verify_db_collations() |
|
656 | - { |
|
657 | - global $wpdb; |
|
658 | - // double-check we haven't already done it or that that the DB doesn't support utf8mb4 |
|
659 | - if ( |
|
660 | - 'utf8mb4' !== $wpdb->charset |
|
661 | - || get_option('ee_verified_db_collations', false) |
|
662 | - ) { |
|
663 | - return; |
|
664 | - } |
|
665 | - // grab tables from each model |
|
666 | - $tables_to_check = array(); |
|
667 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
668 | - if (method_exists($model_name, 'instance')) { |
|
669 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
670 | - if ($model_obj instanceof EEM_Base) { |
|
671 | - foreach ($model_obj->get_tables() as $table) { |
|
672 | - if ( |
|
673 | - strpos($table->get_table_name(), 'esp_') |
|
674 | - && (is_main_site()// for main tables, verify global tables |
|
675 | - || ! $table->is_global()// if not the main site, then only verify non-global tables (avoid doubling up) |
|
676 | - ) |
|
677 | - && function_exists('maybe_convert_table_to_utf8mb4') |
|
678 | - ) { |
|
679 | - $tables_to_check[] = $table->get_table_name(); |
|
680 | - } |
|
681 | - } |
|
682 | - } |
|
683 | - } |
|
684 | - } |
|
685 | - // and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active |
|
686 | - // when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead |
|
687 | - // of hard-coding this |
|
688 | - $addon_tables = array( |
|
689 | - // mailchimp |
|
690 | - 'esp_event_mailchimp_list_group', |
|
691 | - 'esp_event_question_mailchimp_field', |
|
692 | - // multisite |
|
693 | - 'esp_blog_meta', |
|
694 | - // people |
|
695 | - 'esp_people_to_post', |
|
696 | - // promotions |
|
697 | - 'esp_promotion', |
|
698 | - 'esp_promotion_object', |
|
699 | - ); |
|
700 | - foreach ($addon_tables as $table_name) { |
|
701 | - $tables_to_check[] = $table_name; |
|
702 | - } |
|
703 | - $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
704 | - // ok and now let's remember this was done (without needing to check the db schemas all over again) |
|
705 | - add_option('ee_verified_db_collations', true, null, 'no'); |
|
706 | - // seeing how this ran with the fix from 10435, no need to check again |
|
707 | - add_option('ee_verified_db_collations_again', true, null, 'no'); |
|
708 | - } |
|
650 | + /** |
|
651 | + * Verify all EE4 models' tables use utf8mb4 collation |
|
652 | + * |
|
653 | + * @return void |
|
654 | + */ |
|
655 | + public function verify_db_collations() |
|
656 | + { |
|
657 | + global $wpdb; |
|
658 | + // double-check we haven't already done it or that that the DB doesn't support utf8mb4 |
|
659 | + if ( |
|
660 | + 'utf8mb4' !== $wpdb->charset |
|
661 | + || get_option('ee_verified_db_collations', false) |
|
662 | + ) { |
|
663 | + return; |
|
664 | + } |
|
665 | + // grab tables from each model |
|
666 | + $tables_to_check = array(); |
|
667 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
668 | + if (method_exists($model_name, 'instance')) { |
|
669 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
670 | + if ($model_obj instanceof EEM_Base) { |
|
671 | + foreach ($model_obj->get_tables() as $table) { |
|
672 | + if ( |
|
673 | + strpos($table->get_table_name(), 'esp_') |
|
674 | + && (is_main_site()// for main tables, verify global tables |
|
675 | + || ! $table->is_global()// if not the main site, then only verify non-global tables (avoid doubling up) |
|
676 | + ) |
|
677 | + && function_exists('maybe_convert_table_to_utf8mb4') |
|
678 | + ) { |
|
679 | + $tables_to_check[] = $table->get_table_name(); |
|
680 | + } |
|
681 | + } |
|
682 | + } |
|
683 | + } |
|
684 | + } |
|
685 | + // and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active |
|
686 | + // when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead |
|
687 | + // of hard-coding this |
|
688 | + $addon_tables = array( |
|
689 | + // mailchimp |
|
690 | + 'esp_event_mailchimp_list_group', |
|
691 | + 'esp_event_question_mailchimp_field', |
|
692 | + // multisite |
|
693 | + 'esp_blog_meta', |
|
694 | + // people |
|
695 | + 'esp_people_to_post', |
|
696 | + // promotions |
|
697 | + 'esp_promotion', |
|
698 | + 'esp_promotion_object', |
|
699 | + ); |
|
700 | + foreach ($addon_tables as $table_name) { |
|
701 | + $tables_to_check[] = $table_name; |
|
702 | + } |
|
703 | + $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
704 | + // ok and now let's remember this was done (without needing to check the db schemas all over again) |
|
705 | + add_option('ee_verified_db_collations', true, null, 'no'); |
|
706 | + // seeing how this ran with the fix from 10435, no need to check again |
|
707 | + add_option('ee_verified_db_collations_again', true, null, 'no'); |
|
708 | + } |
|
709 | 709 | |
710 | 710 | |
711 | 711 | |
712 | - /** |
|
713 | - * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435 |
|
714 | - * which meant some DB collations might not have been updated |
|
715 | - * @return void |
|
716 | - */ |
|
717 | - public function verify_db_collations_again() |
|
718 | - { |
|
719 | - global $wpdb; |
|
720 | - // double-check we haven't already done this or that the DB doesn't support it |
|
721 | - // compare to how WordPress' upgrade_430() function does this check |
|
722 | - if ( |
|
723 | - 'utf8mb4' !== $wpdb->charset |
|
724 | - || get_option('ee_verified_db_collations_again', false) |
|
725 | - ) { |
|
726 | - return; |
|
727 | - } |
|
728 | - $tables_to_check = array( |
|
729 | - 'esp_attendee_meta', |
|
730 | - 'esp_message' |
|
731 | - ); |
|
732 | - $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
733 | - add_option('ee_verified_db_collations_again', true, null, 'no'); |
|
734 | - } |
|
712 | + /** |
|
713 | + * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435 |
|
714 | + * which meant some DB collations might not have been updated |
|
715 | + * @return void |
|
716 | + */ |
|
717 | + public function verify_db_collations_again() |
|
718 | + { |
|
719 | + global $wpdb; |
|
720 | + // double-check we haven't already done this or that the DB doesn't support it |
|
721 | + // compare to how WordPress' upgrade_430() function does this check |
|
722 | + if ( |
|
723 | + 'utf8mb4' !== $wpdb->charset |
|
724 | + || get_option('ee_verified_db_collations_again', false) |
|
725 | + ) { |
|
726 | + return; |
|
727 | + } |
|
728 | + $tables_to_check = array( |
|
729 | + 'esp_attendee_meta', |
|
730 | + 'esp_message' |
|
731 | + ); |
|
732 | + $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
733 | + add_option('ee_verified_db_collations_again', true, null, 'no'); |
|
734 | + } |
|
735 | 735 | |
736 | 736 | |
737 | 737 | |
738 | - /** |
|
739 | - * Runs maybe_convert_table_to_utf8mb4 on the specified tables |
|
740 | - * @param $tables_to_check |
|
741 | - * @return boolean true if logic ran, false if it didn't |
|
742 | - */ |
|
743 | - protected function _verify_db_collations_for_tables($tables_to_check) |
|
744 | - { |
|
745 | - foreach ($tables_to_check as $table_name) { |
|
746 | - $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name); |
|
747 | - if ( |
|
748 | - ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name) |
|
749 | - && $this->_get_table_analysis()->tableExists($table_name) |
|
750 | - ) { |
|
751 | - maybe_convert_table_to_utf8mb4($table_name); |
|
752 | - } |
|
753 | - } |
|
754 | - } |
|
738 | + /** |
|
739 | + * Runs maybe_convert_table_to_utf8mb4 on the specified tables |
|
740 | + * @param $tables_to_check |
|
741 | + * @return boolean true if logic ran, false if it didn't |
|
742 | + */ |
|
743 | + protected function _verify_db_collations_for_tables($tables_to_check) |
|
744 | + { |
|
745 | + foreach ($tables_to_check as $table_name) { |
|
746 | + $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name); |
|
747 | + if ( |
|
748 | + ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name) |
|
749 | + && $this->_get_table_analysis()->tableExists($table_name) |
|
750 | + ) { |
|
751 | + maybe_convert_table_to_utf8mb4($table_name); |
|
752 | + } |
|
753 | + } |
|
754 | + } |
|
755 | 755 | } |
@@ -9,12 +9,12 @@ discard block |
||
9 | 9 | // unfortunately, this needs to be done upon INCLUSION of this file, |
10 | 10 | // instead of construction, because it only gets constructed on first page load |
11 | 11 | // (all other times it gets resurrected from a wordpress option) |
12 | -$stages = glob(EE_CORE . 'data_migration_scripts/4_9_0_stages/*'); |
|
12 | +$stages = glob(EE_CORE.'data_migration_scripts/4_9_0_stages/*'); |
|
13 | 13 | $class_to_filepath = array(); |
14 | 14 | foreach ($stages as $filepath) { |
15 | 15 | $matches = array(); |
16 | 16 | preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
17 | - $class_to_filepath[ $matches[1] ] = $filepath; |
|
17 | + $class_to_filepath[$matches[1]] = $filepath; |
|
18 | 18 | } |
19 | 19 | // give addons a chance to autoload their stages too |
20 | 20 | $class_to_filepath = apply_filters('FHEE__EE_DMS_4_9_0__autoloaded_stages', $class_to_filepath); |
@@ -65,10 +65,10 @@ discard block |
||
65 | 65 | if (version_compare($version_string, '4.9.0.decaf', '<') && version_compare($version_string, '4.8.0.decaf', '>=')) { |
66 | 66 | // echo "$version_string can be migrated from"; |
67 | 67 | return true; |
68 | - } elseif (! $version_string) { |
|
68 | + } elseif ( ! $version_string) { |
|
69 | 69 | // echo "no version string provided: $version_string"; |
70 | 70 | // no version string provided... this must be pre 4.3 |
71 | - return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
71 | + return false; // changed mind. dont want people thinking they should migrate yet because they cant |
|
72 | 72 | } else { |
73 | 73 | // echo "$version_string doesnt apply"; |
74 | 74 | return false; |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function schema_changes_before_migration() |
84 | 84 | { |
85 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
85 | + require_once(EE_HELPERS.'EEH_Activation.helper.php'); |
|
86 | 86 | $now_in_mysql = current_time('mysql', true); |
87 | 87 | $table_name = 'esp_answer'; |
88 | 88 | $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
@@ -66,8 +66,8 @@ |
||
66 | 66 | { |
67 | 67 | |
68 | 68 | $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
69 | - $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true); |
|
70 | - $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true); |
|
69 | + $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path.'invoice_body.template.php', null, false, false, true); |
|
70 | + $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path.'receipt_body.template.php', null, false, false, true); |
|
71 | 71 | if ($overridden_invoice_body || $overridden_receipt_body) { |
72 | 72 | new PersistentAdminNotice( |
73 | 73 | 'invoice_overriding_templates', |
@@ -28,59 +28,59 @@ |
||
28 | 28 | class EE_DMS_4_6_0_invoice_settings extends EE_Data_Migration_Script_Stage |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * Just initializes the status of the migration |
|
33 | - */ |
|
34 | - public function __construct() |
|
35 | - { |
|
36 | - $this->_pretty_name = esc_html__('Update Invoice Settings', 'event_espresso'); |
|
37 | - parent::__construct(); |
|
38 | - } |
|
31 | + /** |
|
32 | + * Just initializes the status of the migration |
|
33 | + */ |
|
34 | + public function __construct() |
|
35 | + { |
|
36 | + $this->_pretty_name = esc_html__('Update Invoice Settings', 'event_espresso'); |
|
37 | + parent::__construct(); |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * _count_records_to_migrate |
|
44 | - * Counts the records to migrate; the public version may cache it |
|
45 | - * |
|
46 | - * @access protected |
|
47 | - * @return int |
|
48 | - */ |
|
49 | - protected function _count_records_to_migrate() |
|
50 | - { |
|
51 | - return 1; |
|
52 | - } |
|
42 | + /** |
|
43 | + * _count_records_to_migrate |
|
44 | + * Counts the records to migrate; the public version may cache it |
|
45 | + * |
|
46 | + * @access protected |
|
47 | + * @return int |
|
48 | + */ |
|
49 | + protected function _count_records_to_migrate() |
|
50 | + { |
|
51 | + return 1; |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * _migration_step |
|
58 | - * |
|
59 | - * @access protected |
|
60 | - * @param int $num_items |
|
61 | - * @throws EE_Error |
|
62 | - * @return int number of items ACTUALLY migrated |
|
63 | - * @throws InvalidDataTypeException |
|
64 | - */ |
|
65 | - protected function _migration_step($num_items = 1) |
|
66 | - { |
|
56 | + /** |
|
57 | + * _migration_step |
|
58 | + * |
|
59 | + * @access protected |
|
60 | + * @param int $num_items |
|
61 | + * @throws EE_Error |
|
62 | + * @return int number of items ACTUALLY migrated |
|
63 | + * @throws InvalidDataTypeException |
|
64 | + */ |
|
65 | + protected function _migration_step($num_items = 1) |
|
66 | + { |
|
67 | 67 | |
68 | - $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
|
69 | - $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true); |
|
70 | - $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true); |
|
71 | - if ($overridden_invoice_body || $overridden_receipt_body) { |
|
72 | - new PersistentAdminNotice( |
|
73 | - 'invoice_overriding_templates', |
|
74 | - esc_html__( |
|
75 | - 'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents (but this will be removed in an upcoming version). We recommend deleting your old Invoice/Receipt templates and using the new messages system. Then modify the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.', |
|
76 | - 'event_espresso' |
|
77 | - ), |
|
78 | - true |
|
79 | - ); |
|
80 | - } |
|
68 | + $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
|
69 | + $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true); |
|
70 | + $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true); |
|
71 | + if ($overridden_invoice_body || $overridden_receipt_body) { |
|
72 | + new PersistentAdminNotice( |
|
73 | + 'invoice_overriding_templates', |
|
74 | + esc_html__( |
|
75 | + 'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents (but this will be removed in an upcoming version). We recommend deleting your old Invoice/Receipt templates and using the new messages system. Then modify the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.', |
|
76 | + 'event_espresso' |
|
77 | + ), |
|
78 | + true |
|
79 | + ); |
|
80 | + } |
|
81 | 81 | |
82 | - // regardless of whether it worked or not, we ought to continue the migration |
|
83 | - $this->set_completed(); |
|
84 | - return 1; |
|
85 | - } |
|
82 | + // regardless of whether it worked or not, we ought to continue the migration |
|
83 | + $this->set_completed(); |
|
84 | + return 1; |
|
85 | + } |
|
86 | 86 | } |
@@ -13,105 +13,105 @@ |
||
13 | 13 | class EE_Load_Textdomain extends EE_Base |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * holds the current lang in WP |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - private static $locale; |
|
16 | + /** |
|
17 | + * holds the current lang in WP |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + private static $locale; |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * this takes care of retrieving a matching textdomain for event espresso for the current WPLANG from EE GitHub |
|
26 | - * repo (if necessary) and then loading it for translations. should only be called in wp plugins_loaded callback |
|
27 | - * |
|
28 | - * @return void |
|
29 | - * @throws EE_Error |
|
30 | - * @throws InvalidArgumentException |
|
31 | - * @throws ReflectionException |
|
32 | - * @throws InvalidDataTypeException |
|
33 | - * @throws InvalidInterfaceException |
|
34 | - */ |
|
35 | - public static function load_textdomain() |
|
36 | - { |
|
37 | - EE_Load_Textdomain::loadTranslationsForLocale(); |
|
38 | - // now load the textdomain |
|
39 | - if (!empty(EE_Load_Textdomain::$locale)) { |
|
40 | - $github_mo_path = EE_LANGUAGES_SAFE_DIR . 'event_espresso-' . EE_Load_Textdomain::$locale . '.mo'; |
|
41 | - if (is_readable($github_mo_path)) { |
|
42 | - load_plugin_textdomain('event_espresso', false, EE_LANGUAGES_SAFE_LOC); |
|
43 | - return; |
|
44 | - } |
|
45 | - $glotpress_mo_path = EE_LANGUAGES_SAFE_DIR . 'event-espresso-4-' . EE_Load_Textdomain::$locale . '.mo'; |
|
46 | - if (is_readable($glotpress_mo_path)) { |
|
47 | - load_textdomain('event_espresso', $glotpress_mo_path); |
|
48 | - return; |
|
49 | - } |
|
50 | - } |
|
51 | - load_plugin_textdomain('event_espresso', false, dirname(EE_PLUGIN_BASENAME) . '/languages/'); |
|
52 | - } |
|
24 | + /** |
|
25 | + * this takes care of retrieving a matching textdomain for event espresso for the current WPLANG from EE GitHub |
|
26 | + * repo (if necessary) and then loading it for translations. should only be called in wp plugins_loaded callback |
|
27 | + * |
|
28 | + * @return void |
|
29 | + * @throws EE_Error |
|
30 | + * @throws InvalidArgumentException |
|
31 | + * @throws ReflectionException |
|
32 | + * @throws InvalidDataTypeException |
|
33 | + * @throws InvalidInterfaceException |
|
34 | + */ |
|
35 | + public static function load_textdomain() |
|
36 | + { |
|
37 | + EE_Load_Textdomain::loadTranslationsForLocale(); |
|
38 | + // now load the textdomain |
|
39 | + if (!empty(EE_Load_Textdomain::$locale)) { |
|
40 | + $github_mo_path = EE_LANGUAGES_SAFE_DIR . 'event_espresso-' . EE_Load_Textdomain::$locale . '.mo'; |
|
41 | + if (is_readable($github_mo_path)) { |
|
42 | + load_plugin_textdomain('event_espresso', false, EE_LANGUAGES_SAFE_LOC); |
|
43 | + return; |
|
44 | + } |
|
45 | + $glotpress_mo_path = EE_LANGUAGES_SAFE_DIR . 'event-espresso-4-' . EE_Load_Textdomain::$locale . '.mo'; |
|
46 | + if (is_readable($glotpress_mo_path)) { |
|
47 | + load_textdomain('event_espresso', $glotpress_mo_path); |
|
48 | + return; |
|
49 | + } |
|
50 | + } |
|
51 | + load_plugin_textdomain('event_espresso', false, dirname(EE_PLUGIN_BASENAME) . '/languages/'); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * The purpose of this method is to sideload all of the lang files for EE, this includes the POT file and also the PO/MO files for the given WPLANG locale (if necessary). |
|
57 | - * |
|
58 | - * @access private |
|
59 | - * @static |
|
60 | - * @return void |
|
61 | - * @throws EE_Error |
|
62 | - * @throws InvalidArgumentException |
|
63 | - * @throws ReflectionException |
|
64 | - * @throws InvalidDataTypeException |
|
65 | - * @throws InvalidInterfaceException |
|
66 | - */ |
|
67 | - private static function loadTranslationsForLocale() |
|
68 | - { |
|
69 | - EE_Load_Textdomain::$locale = get_locale(); |
|
70 | - // can't download a language file if a language isn't set <taps temple> |
|
71 | - if (empty(EE_Load_Textdomain::$locale)) { |
|
72 | - return; |
|
73 | - } |
|
74 | - $language_check_option_name = 'ee_lang_check_' . EE_Load_Textdomain::$locale . '_' . EVENT_ESPRESSO_VERSION; |
|
75 | - // check if language files has already been sideloaded |
|
76 | - if (get_option($language_check_option_name)) { |
|
77 | - return; |
|
78 | - } |
|
55 | + /** |
|
56 | + * The purpose of this method is to sideload all of the lang files for EE, this includes the POT file and also the PO/MO files for the given WPLANG locale (if necessary). |
|
57 | + * |
|
58 | + * @access private |
|
59 | + * @static |
|
60 | + * @return void |
|
61 | + * @throws EE_Error |
|
62 | + * @throws InvalidArgumentException |
|
63 | + * @throws ReflectionException |
|
64 | + * @throws InvalidDataTypeException |
|
65 | + * @throws InvalidInterfaceException |
|
66 | + */ |
|
67 | + private static function loadTranslationsForLocale() |
|
68 | + { |
|
69 | + EE_Load_Textdomain::$locale = get_locale(); |
|
70 | + // can't download a language file if a language isn't set <taps temple> |
|
71 | + if (empty(EE_Load_Textdomain::$locale)) { |
|
72 | + return; |
|
73 | + } |
|
74 | + $language_check_option_name = 'ee_lang_check_' . EE_Load_Textdomain::$locale . '_' . EVENT_ESPRESSO_VERSION; |
|
75 | + // check if language files has already been sideloaded |
|
76 | + if (get_option($language_check_option_name)) { |
|
77 | + return; |
|
78 | + } |
|
79 | 79 | |
80 | - $repo_base_URL = 'https://github.com/eventespresso/languages-ee4/blob/master/event_espresso'; |
|
80 | + $repo_base_URL = 'https://github.com/eventespresso/languages-ee4/blob/master/event_espresso'; |
|
81 | 81 | |
82 | - // load sideloader and sideload the .POT file as this should always be included. |
|
83 | - $sideloader_args = array( |
|
84 | - '_upload_to' => EE_PLUGIN_DIR_PATH . 'languages/', |
|
85 | - '_download_from' => $repo_base_URL . '.pot?raw=true', |
|
86 | - '_new_file_name' => 'event_espresso.pot', |
|
87 | - ); |
|
88 | - /** @var EEH_Sideloader $sideloader */ |
|
89 | - $sideloader = EE_Registry::instance()->load_helper('Sideloader', $sideloader_args, false); |
|
90 | - // sideload the .POT file only for main site of the network, or if not running Multisite. |
|
91 | - if (is_main_site()) { |
|
92 | - $sideloader->sideload(); |
|
93 | - } |
|
82 | + // load sideloader and sideload the .POT file as this should always be included. |
|
83 | + $sideloader_args = array( |
|
84 | + '_upload_to' => EE_PLUGIN_DIR_PATH . 'languages/', |
|
85 | + '_download_from' => $repo_base_URL . '.pot?raw=true', |
|
86 | + '_new_file_name' => 'event_espresso.pot', |
|
87 | + ); |
|
88 | + /** @var EEH_Sideloader $sideloader */ |
|
89 | + $sideloader = EE_Registry::instance()->load_helper('Sideloader', $sideloader_args, false); |
|
90 | + // sideload the .POT file only for main site of the network, or if not running Multisite. |
|
91 | + if (is_main_site()) { |
|
92 | + $sideloader->sideload(); |
|
93 | + } |
|
94 | 94 | |
95 | - // if locale is "en_US" then lets just get out, since Event Espresso core is already "en_US" |
|
96 | - if (EE_Load_Textdomain::$locale === 'en_US') { |
|
97 | - // but set option first else we'll forever be downloading the pot file |
|
98 | - update_option($language_check_option_name, 1); |
|
99 | - return; |
|
100 | - } |
|
101 | - $repo_locale_URL = $repo_base_URL . '-' . EE_Load_Textdomain::$locale; |
|
102 | - $file_name_base = 'event_espresso-' . EE_Load_Textdomain::$locale; |
|
95 | + // if locale is "en_US" then lets just get out, since Event Espresso core is already "en_US" |
|
96 | + if (EE_Load_Textdomain::$locale === 'en_US') { |
|
97 | + // but set option first else we'll forever be downloading the pot file |
|
98 | + update_option($language_check_option_name, 1); |
|
99 | + return; |
|
100 | + } |
|
101 | + $repo_locale_URL = $repo_base_URL . '-' . EE_Load_Textdomain::$locale; |
|
102 | + $file_name_base = 'event_espresso-' . EE_Load_Textdomain::$locale; |
|
103 | 103 | |
104 | - // made it here so let's get the language files from the github repo, first the .mo file |
|
105 | - $sideloader->set_download_from("{$repo_locale_URL}.mo?raw=true"); |
|
106 | - $sideloader->set_new_file_name("{$file_name_base}.mo"); |
|
107 | - $sideloader->sideload(); |
|
104 | + // made it here so let's get the language files from the github repo, first the .mo file |
|
105 | + $sideloader->set_download_from("{$repo_locale_URL}.mo?raw=true"); |
|
106 | + $sideloader->set_new_file_name("{$file_name_base}.mo"); |
|
107 | + $sideloader->sideload(); |
|
108 | 108 | |
109 | - // now the .po file: |
|
110 | - $sideloader->set_download_from("{$repo_locale_URL}.po?raw=true"); |
|
111 | - $sideloader->set_new_file_name("{$file_name_base}.po"); |
|
112 | - $sideloader->sideload(); |
|
109 | + // now the .po file: |
|
110 | + $sideloader->set_download_from("{$repo_locale_URL}.po?raw=true"); |
|
111 | + $sideloader->set_new_file_name("{$file_name_base}.po"); |
|
112 | + $sideloader->sideload(); |
|
113 | 113 | |
114 | - // set option so the above only runs when EE updates. |
|
115 | - update_option($language_check_option_name, 1); |
|
116 | - } |
|
114 | + // set option so the above only runs when EE updates. |
|
115 | + update_option($language_check_option_name, 1); |
|
116 | + } |
|
117 | 117 | } |
@@ -36,19 +36,19 @@ discard block |
||
36 | 36 | { |
37 | 37 | EE_Load_Textdomain::loadTranslationsForLocale(); |
38 | 38 | // now load the textdomain |
39 | - if (!empty(EE_Load_Textdomain::$locale)) { |
|
40 | - $github_mo_path = EE_LANGUAGES_SAFE_DIR . 'event_espresso-' . EE_Load_Textdomain::$locale . '.mo'; |
|
39 | + if ( ! empty(EE_Load_Textdomain::$locale)) { |
|
40 | + $github_mo_path = EE_LANGUAGES_SAFE_DIR.'event_espresso-'.EE_Load_Textdomain::$locale.'.mo'; |
|
41 | 41 | if (is_readable($github_mo_path)) { |
42 | 42 | load_plugin_textdomain('event_espresso', false, EE_LANGUAGES_SAFE_LOC); |
43 | 43 | return; |
44 | 44 | } |
45 | - $glotpress_mo_path = EE_LANGUAGES_SAFE_DIR . 'event-espresso-4-' . EE_Load_Textdomain::$locale . '.mo'; |
|
45 | + $glotpress_mo_path = EE_LANGUAGES_SAFE_DIR.'event-espresso-4-'.EE_Load_Textdomain::$locale.'.mo'; |
|
46 | 46 | if (is_readable($glotpress_mo_path)) { |
47 | 47 | load_textdomain('event_espresso', $glotpress_mo_path); |
48 | 48 | return; |
49 | 49 | } |
50 | 50 | } |
51 | - load_plugin_textdomain('event_espresso', false, dirname(EE_PLUGIN_BASENAME) . '/languages/'); |
|
51 | + load_plugin_textdomain('event_espresso', false, dirname(EE_PLUGIN_BASENAME).'/languages/'); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | if (empty(EE_Load_Textdomain::$locale)) { |
72 | 72 | return; |
73 | 73 | } |
74 | - $language_check_option_name = 'ee_lang_check_' . EE_Load_Textdomain::$locale . '_' . EVENT_ESPRESSO_VERSION; |
|
74 | + $language_check_option_name = 'ee_lang_check_'.EE_Load_Textdomain::$locale.'_'.EVENT_ESPRESSO_VERSION; |
|
75 | 75 | // check if language files has already been sideloaded |
76 | 76 | if (get_option($language_check_option_name)) { |
77 | 77 | return; |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | |
82 | 82 | // load sideloader and sideload the .POT file as this should always be included. |
83 | 83 | $sideloader_args = array( |
84 | - '_upload_to' => EE_PLUGIN_DIR_PATH . 'languages/', |
|
85 | - '_download_from' => $repo_base_URL . '.pot?raw=true', |
|
84 | + '_upload_to' => EE_PLUGIN_DIR_PATH.'languages/', |
|
85 | + '_download_from' => $repo_base_URL.'.pot?raw=true', |
|
86 | 86 | '_new_file_name' => 'event_espresso.pot', |
87 | 87 | ); |
88 | 88 | /** @var EEH_Sideloader $sideloader */ |
@@ -98,8 +98,8 @@ discard block |
||
98 | 98 | update_option($language_check_option_name, 1); |
99 | 99 | return; |
100 | 100 | } |
101 | - $repo_locale_URL = $repo_base_URL . '-' . EE_Load_Textdomain::$locale; |
|
102 | - $file_name_base = 'event_espresso-' . EE_Load_Textdomain::$locale; |
|
101 | + $repo_locale_URL = $repo_base_URL.'-'.EE_Load_Textdomain::$locale; |
|
102 | + $file_name_base = 'event_espresso-'.EE_Load_Textdomain::$locale; |
|
103 | 103 | |
104 | 104 | // made it here so let's get the language files from the github repo, first the .mo file |
105 | 105 | $sideloader->set_download_from("{$repo_locale_URL}.mo?raw=true"); |
@@ -12,42 +12,42 @@ |
||
12 | 12 | class EE_Base |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * @ override magic methods |
|
17 | - * @ return void |
|
18 | - */ |
|
19 | - public function __get($a) |
|
20 | - { |
|
21 | - return false; |
|
22 | - } |
|
23 | - |
|
24 | - public function __set($a, $b) |
|
25 | - { |
|
26 | - return false; |
|
27 | - } |
|
28 | - |
|
29 | - public function __isset($a) |
|
30 | - { |
|
31 | - return false; |
|
32 | - } |
|
33 | - |
|
34 | - public function __unset($a) |
|
35 | - { |
|
36 | - return false; |
|
37 | - } |
|
38 | - |
|
39 | - public function __clone() |
|
40 | - { |
|
41 | - return false; |
|
42 | - } |
|
43 | - |
|
44 | - public function __wakeup() |
|
45 | - { |
|
46 | - return false; |
|
47 | - } |
|
48 | - |
|
49 | - public function __destruct() |
|
50 | - { |
|
51 | - return false; |
|
52 | - } |
|
15 | + /** |
|
16 | + * @ override magic methods |
|
17 | + * @ return void |
|
18 | + */ |
|
19 | + public function __get($a) |
|
20 | + { |
|
21 | + return false; |
|
22 | + } |
|
23 | + |
|
24 | + public function __set($a, $b) |
|
25 | + { |
|
26 | + return false; |
|
27 | + } |
|
28 | + |
|
29 | + public function __isset($a) |
|
30 | + { |
|
31 | + return false; |
|
32 | + } |
|
33 | + |
|
34 | + public function __unset($a) |
|
35 | + { |
|
36 | + return false; |
|
37 | + } |
|
38 | + |
|
39 | + public function __clone() |
|
40 | + { |
|
41 | + return false; |
|
42 | + } |
|
43 | + |
|
44 | + public function __wakeup() |
|
45 | + { |
|
46 | + return false; |
|
47 | + } |
|
48 | + |
|
49 | + public function __destruct() |
|
50 | + { |
|
51 | + return false; |
|
52 | + } |
|
53 | 53 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | { |
97 | 97 | $class = parent::_get_row_class($transaction); |
98 | 98 | // add status class |
99 | - $class .= ' ee-status-strip txn-status-' . $transaction->status_ID(); |
|
99 | + $class .= ' ee-status-strip txn-status-'.$transaction->status_ID(); |
|
100 | 100 | if ($this->_has_checkbox_column) { |
101 | 101 | $class .= ' has-checkbox-column'; |
102 | 102 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | protected function _add_view_counts() |
150 | 150 | { |
151 | 151 | foreach ($this->_views as $view) { |
152 | - $this->_views[ $view['slug'] ]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']); |
|
152 | + $this->_views[$view['slug']]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']); |
|
153 | 153 | } |
154 | 154 | } |
155 | 155 | |
@@ -170,13 +170,13 @@ discard block |
||
170 | 170 | ), |
171 | 171 | TXN_ADMIN_URL |
172 | 172 | ); |
173 | - $content = '<a href="' . $view_lnk_url . '"' |
|
174 | - . ' title="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">' |
|
173 | + $content = '<a href="'.$view_lnk_url.'"' |
|
174 | + . ' title="'.esc_attr__('Go to Transaction Details', 'event_espresso').'">' |
|
175 | 175 | . $transaction->ID() |
176 | 176 | . '</a>'; |
177 | 177 | |
178 | 178 | // txn timestamp |
179 | - $content .= ' <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>'; |
|
179 | + $content .= ' <span class="show-on-mobile-view-only">'.$this->_get_txn_timestamp($transaction).'</span>'; |
|
180 | 180 | return $content; |
181 | 181 | } |
182 | 182 | |
@@ -237,9 +237,9 @@ discard block |
||
237 | 237 | ), |
238 | 238 | TXN_ADMIN_URL |
239 | 239 | ); |
240 | - $txn_date = '<a href="' . $view_lnk_url . '"' |
|
240 | + $txn_date = '<a href="'.$view_lnk_url.'"' |
|
241 | 241 | . ' title="' |
242 | - . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID() . '">' |
|
242 | + . esc_attr__('View Transaction Details for TXN #', 'event_espresso').$transaction->ID().'">' |
|
243 | 243 | . $this->_get_txn_timestamp($transaction) |
244 | 244 | . '</a>'; |
245 | 245 | // status |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | ) |
273 | 273 | . '</span>'; |
274 | 274 | } else { |
275 | - return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>'; |
|
275 | + return '<span class="txn-overview-free-event-spn">'.esc_html__('free', 'event_espresso').'</span>'; |
|
276 | 276 | } |
277 | 277 | } |
278 | 278 | |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | ? $payment_method->admin_name() |
310 | 310 | : esc_html__('Unknown', 'event_espresso'); |
311 | 311 | |
312 | - $content = '<span class="' . $span_class . ' txn-pad-rght">' |
|
312 | + $content = '<span class="'.$span_class.' txn-pad-rght">' |
|
313 | 313 | . $transaction->get_pretty('TXN_paid') |
314 | 314 | . '</span>'; |
315 | 315 | if ($transaction_paid > 0) { |
@@ -351,12 +351,12 @@ discard block |
||
351 | 351 | 'espresso_registrations_view_registration', |
352 | 352 | $primary_reg->ID() |
353 | 353 | ) |
354 | - ? '<a href="' . $edit_lnk_url . '"' |
|
355 | - . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
354 | + ? '<a href="'.$edit_lnk_url.'"' |
|
355 | + . ' title="'.esc_attr__('View Registration Details', 'event_espresso').'">' |
|
356 | 356 | . $attendee->full_name() |
357 | 357 | . '</a>' |
358 | 358 | : $attendee->full_name(); |
359 | - $content .= '<br>' . $attendee->email(); |
|
359 | + $content .= '<br>'.$attendee->email(); |
|
360 | 360 | return $content; |
361 | 361 | } |
362 | 362 | return $transaction->failed() || $transaction->is_abandoned() |
@@ -378,8 +378,8 @@ discard block |
||
378 | 378 | public function column_ATT_email(EE_Transaction $transaction) |
379 | 379 | { |
380 | 380 | $attendee = $transaction->primary_registration()->get_first_related('Attendee'); |
381 | - if (! empty($attendee)) { |
|
382 | - return '<a href="mailto:' . $attendee->get('ATT_email') . '">' |
|
381 | + if ( ! empty($attendee)) { |
|
382 | + return '<a href="mailto:'.$attendee->get('ATT_email').'">' |
|
383 | 383 | . $attendee->get('ATT_email') |
384 | 384 | . '</a>'; |
385 | 385 | } else { |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | { |
408 | 408 | $actions = array(); |
409 | 409 | $event = $transaction->primary_registration()->get_first_related('Event'); |
410 | - if (! empty($event)) { |
|
410 | + if ( ! empty($event)) { |
|
411 | 411 | $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( |
412 | 412 | array('action' => 'edit', 'post' => $event->ID()), |
413 | 413 | EVENTS_ADMIN_URL |
@@ -429,11 +429,11 @@ discard block |
||
429 | 429 | $event->ID() |
430 | 430 | ) |
431 | 431 | ) { |
432 | - $actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '"' |
|
433 | - . ' title="' . esc_attr__( |
|
432 | + $actions['filter_by_event'] = '<a href="'.$txn_by_event_lnk.'"' |
|
433 | + . ' title="'.esc_attr__( |
|
434 | 434 | 'Filter transactions by this event', |
435 | 435 | 'event_espresso' |
436 | - ) . '">' |
|
436 | + ).'">' |
|
437 | 437 | . esc_html__('View Transactions for this event', 'event_espresso') |
438 | 438 | . '</a>'; |
439 | 439 | } |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | 'espresso_events_edit', |
446 | 446 | $event->ID() |
447 | 447 | ) |
448 | - ? '<a href="' . $edit_event_url . '"' |
|
448 | + ? '<a href="'.$edit_event_url.'"' |
|
449 | 449 | . ' title="' |
450 | 450 | . sprintf( |
451 | 451 | esc_attr__('Edit Event: %s', 'event_espresso'), |
@@ -512,8 +512,8 @@ discard block |
||
512 | 512 | ); |
513 | 513 | return ' |
514 | 514 | <li> |
515 | - <a href="' . $url . '"' |
|
516 | - . ' title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text"> |
|
515 | + <a href="' . $url.'"' |
|
516 | + . ' title="'.esc_attr__('View Transaction Details', 'event_espresso').'" class="tiny-text"> |
|
517 | 517 | <span class="dashicons dashicons-cart"></span> |
518 | 518 | </a> |
519 | 519 | </li>'; |
@@ -539,8 +539,8 @@ discard block |
||
539 | 539 | ) { |
540 | 540 | return ' |
541 | 541 | <li> |
542 | - <a title="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '"' |
|
543 | - . ' target="_blank" href="' . $url . '" class="tiny-text"> |
|
542 | + <a title="' . esc_attr__('View Transaction Invoice', 'event_espresso').'"' |
|
543 | + . ' target="_blank" href="'.$url.'" class="tiny-text"> |
|
544 | 544 | <span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span> |
545 | 545 | </a> |
546 | 546 | </li>'; |
@@ -569,8 +569,8 @@ discard block |
||
569 | 569 | ) { |
570 | 570 | return ' |
571 | 571 | <li> |
572 | - <a title="' . esc_attr__('View Transaction Receipt', 'event_espresso') . '"' |
|
573 | - . ' target="_blank" href="' . $url . '" class="tiny-text"> |
|
572 | + <a title="' . esc_attr__('View Transaction Receipt', 'event_espresso').'"' |
|
573 | + . ' target="_blank" href="'.$url.'" class="tiny-text"> |
|
574 | 574 | <span class="dashicons dashicons-media-default ee-icon-size-18"></span> |
575 | 575 | </a> |
576 | 576 | </li>'; |
@@ -608,8 +608,8 @@ discard block |
||
608 | 608 | ) |
609 | 609 | ? ' |
610 | 610 | <li> |
611 | - <a href="' . $url . '"' |
|
612 | - . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text"> |
|
611 | + <a href="' . $url.'"' |
|
612 | + . ' title="'.esc_attr__('View Registration Details', 'event_espresso').'" class="tiny-text"> |
|
613 | 613 | <span class="dashicons dashicons-clipboard"></span> |
614 | 614 | </a> |
615 | 615 | </li>' |
@@ -655,8 +655,8 @@ discard block |
||
655 | 655 | ); |
656 | 656 | return ' |
657 | 657 | <li> |
658 | - <a href="' . $url . '"' |
|
659 | - . ' title="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" class="tiny-text"> |
|
658 | + <a href="' . $url.'"' |
|
659 | + . ' title="'.esc_attr__('Send Payment Reminder', 'event_espresso').'" class="tiny-text"> |
|
660 | 660 | <span class="dashicons dashicons-email-alt"></span> |
661 | 661 | </a> |
662 | 662 | </li>'; |
@@ -686,7 +686,7 @@ discard block |
||
686 | 686 | 'ee_read_global_messages', |
687 | 687 | 'view_filtered_messages' |
688 | 688 | ) |
689 | - ? '<li>' . $url . '</li>' |
|
689 | + ? '<li>'.$url.'</li>' |
|
690 | 690 | : ''; |
691 | 691 | } |
692 | 692 | |
@@ -708,8 +708,8 @@ discard block |
||
708 | 708 | ) { |
709 | 709 | return ' |
710 | 710 | <li> |
711 | - <a title="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso') . '"' |
|
712 | - . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"' |
|
711 | + <a title="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso').'"' |
|
712 | + . ' target="_blank" href="'.$registration->payment_overview_url(true).'"' |
|
713 | 713 | . ' class="tiny-text"> |
714 | 714 | <span class="dashicons dashicons-money ee-icon-size-18"></span> |
715 | 715 | </a> |
@@ -15,121 +15,121 @@ discard block |
||
15 | 15 | class EE_Admin_Transactions_List_Table extends EE_Admin_List_Table |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @var SessionLifespan $session_lifespan |
|
20 | - */ |
|
21 | - private $session_lifespan; |
|
22 | - |
|
23 | - private $_status; |
|
24 | - |
|
25 | - |
|
26 | - /** |
|
27 | - * @param \Transactions_Admin_Page $admin_page |
|
28 | - * @param SessionLifespan $lifespan |
|
29 | - */ |
|
30 | - public function __construct(\Transactions_Admin_Page $admin_page, SessionLifespan $lifespan) |
|
31 | - { |
|
32 | - parent::__construct($admin_page); |
|
33 | - $this->session_lifespan = $lifespan; |
|
34 | - $this->_status = $this->_admin_page->get_transaction_status_array(); |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - *_setup_data |
|
40 | - */ |
|
41 | - protected function _setup_data() |
|
42 | - { |
|
43 | - $this->_data = $this->_admin_page->get_transactions($this->_per_page); |
|
44 | - $status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all'; |
|
45 | - $this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status); |
|
46 | - } |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - *_set_properties |
|
51 | - */ |
|
52 | - protected function _set_properties() |
|
53 | - { |
|
54 | - $this->_wp_list_args = array( |
|
55 | - 'singular' => esc_html__('transaction', 'event_espresso'), |
|
56 | - 'plural' => esc_html__('transactions', 'event_espresso'), |
|
57 | - 'ajax' => true, |
|
58 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
59 | - ); |
|
60 | - $ID_column_name = esc_html__('ID', 'event_espresso'); |
|
61 | - $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; |
|
62 | - $ID_column_name .= esc_html__('Transaction Date', 'event_espresso'); |
|
63 | - $ID_column_name .= '</span> '; |
|
64 | - $this->_columns = array( |
|
65 | - 'TXN_ID' => $ID_column_name, |
|
66 | - 'TXN_timestamp' => esc_html__('Transaction Date', 'event_espresso'), |
|
67 | - 'TXN_total' => esc_html__('Total', 'event_espresso'), |
|
68 | - 'TXN_paid' => esc_html__('Paid', 'event_espresso'), |
|
69 | - 'ATT_fname' => esc_html__('Primary Registrant', 'event_espresso'), |
|
70 | - 'event_name' => esc_html__('Event', 'event_espresso'), |
|
71 | - 'actions' => esc_html__('Actions', 'event_espresso'), |
|
72 | - ); |
|
73 | - |
|
74 | - $this->_sortable_columns = array( |
|
75 | - 'TXN_ID' => array('TXN_ID' => false), |
|
76 | - 'event_name' => array('event_name' => false), |
|
77 | - 'ATT_fname' => array('ATT_fname' => false), |
|
78 | - 'TXN_timestamp' => array('TXN_timestamp' => true) // true means its already sorted |
|
79 | - ); |
|
80 | - |
|
81 | - $this->_primary_column = 'TXN_ID'; |
|
82 | - |
|
83 | - $this->_hidden_columns = array(); |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * This simply sets up the row class for the table rows. |
|
89 | - * Allows for easier overriding of child methods for setting up sorting. |
|
90 | - * |
|
91 | - * @param EE_Transaction $transaction the current item |
|
92 | - * @return string |
|
93 | - * @throws \EE_Error |
|
94 | - */ |
|
95 | - protected function _get_row_class($transaction) |
|
96 | - { |
|
97 | - $class = parent::_get_row_class($transaction); |
|
98 | - // add status class |
|
99 | - $class .= ' ee-status-strip txn-status-' . $transaction->status_ID(); |
|
100 | - if ($this->_has_checkbox_column) { |
|
101 | - $class .= ' has-checkbox-column'; |
|
102 | - } |
|
103 | - return $class; |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * _get_table_filters |
|
109 | - * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
110 | - * get's shown in the table. |
|
111 | - * |
|
112 | - * @abstract |
|
113 | - * @access protected |
|
114 | - * @return array |
|
115 | - */ |
|
116 | - protected function _get_table_filters() |
|
117 | - { |
|
118 | - $filters = array(); |
|
119 | - $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
120 | - ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
121 | - : date( |
|
122 | - 'm/d/Y', |
|
123 | - strtotime('-10 year') |
|
124 | - ); |
|
125 | - $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
126 | - ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
127 | - : date( |
|
128 | - 'm/d/Y', |
|
129 | - current_time('timestamp') |
|
130 | - ); |
|
131 | - ob_start(); |
|
132 | - ?> |
|
18 | + /** |
|
19 | + * @var SessionLifespan $session_lifespan |
|
20 | + */ |
|
21 | + private $session_lifespan; |
|
22 | + |
|
23 | + private $_status; |
|
24 | + |
|
25 | + |
|
26 | + /** |
|
27 | + * @param \Transactions_Admin_Page $admin_page |
|
28 | + * @param SessionLifespan $lifespan |
|
29 | + */ |
|
30 | + public function __construct(\Transactions_Admin_Page $admin_page, SessionLifespan $lifespan) |
|
31 | + { |
|
32 | + parent::__construct($admin_page); |
|
33 | + $this->session_lifespan = $lifespan; |
|
34 | + $this->_status = $this->_admin_page->get_transaction_status_array(); |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + *_setup_data |
|
40 | + */ |
|
41 | + protected function _setup_data() |
|
42 | + { |
|
43 | + $this->_data = $this->_admin_page->get_transactions($this->_per_page); |
|
44 | + $status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all'; |
|
45 | + $this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status); |
|
46 | + } |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + *_set_properties |
|
51 | + */ |
|
52 | + protected function _set_properties() |
|
53 | + { |
|
54 | + $this->_wp_list_args = array( |
|
55 | + 'singular' => esc_html__('transaction', 'event_espresso'), |
|
56 | + 'plural' => esc_html__('transactions', 'event_espresso'), |
|
57 | + 'ajax' => true, |
|
58 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
59 | + ); |
|
60 | + $ID_column_name = esc_html__('ID', 'event_espresso'); |
|
61 | + $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; |
|
62 | + $ID_column_name .= esc_html__('Transaction Date', 'event_espresso'); |
|
63 | + $ID_column_name .= '</span> '; |
|
64 | + $this->_columns = array( |
|
65 | + 'TXN_ID' => $ID_column_name, |
|
66 | + 'TXN_timestamp' => esc_html__('Transaction Date', 'event_espresso'), |
|
67 | + 'TXN_total' => esc_html__('Total', 'event_espresso'), |
|
68 | + 'TXN_paid' => esc_html__('Paid', 'event_espresso'), |
|
69 | + 'ATT_fname' => esc_html__('Primary Registrant', 'event_espresso'), |
|
70 | + 'event_name' => esc_html__('Event', 'event_espresso'), |
|
71 | + 'actions' => esc_html__('Actions', 'event_espresso'), |
|
72 | + ); |
|
73 | + |
|
74 | + $this->_sortable_columns = array( |
|
75 | + 'TXN_ID' => array('TXN_ID' => false), |
|
76 | + 'event_name' => array('event_name' => false), |
|
77 | + 'ATT_fname' => array('ATT_fname' => false), |
|
78 | + 'TXN_timestamp' => array('TXN_timestamp' => true) // true means its already sorted |
|
79 | + ); |
|
80 | + |
|
81 | + $this->_primary_column = 'TXN_ID'; |
|
82 | + |
|
83 | + $this->_hidden_columns = array(); |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * This simply sets up the row class for the table rows. |
|
89 | + * Allows for easier overriding of child methods for setting up sorting. |
|
90 | + * |
|
91 | + * @param EE_Transaction $transaction the current item |
|
92 | + * @return string |
|
93 | + * @throws \EE_Error |
|
94 | + */ |
|
95 | + protected function _get_row_class($transaction) |
|
96 | + { |
|
97 | + $class = parent::_get_row_class($transaction); |
|
98 | + // add status class |
|
99 | + $class .= ' ee-status-strip txn-status-' . $transaction->status_ID(); |
|
100 | + if ($this->_has_checkbox_column) { |
|
101 | + $class .= ' has-checkbox-column'; |
|
102 | + } |
|
103 | + return $class; |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * _get_table_filters |
|
109 | + * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
110 | + * get's shown in the table. |
|
111 | + * |
|
112 | + * @abstract |
|
113 | + * @access protected |
|
114 | + * @return array |
|
115 | + */ |
|
116 | + protected function _get_table_filters() |
|
117 | + { |
|
118 | + $filters = array(); |
|
119 | + $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
120 | + ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
121 | + : date( |
|
122 | + 'm/d/Y', |
|
123 | + strtotime('-10 year') |
|
124 | + ); |
|
125 | + $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
126 | + ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
127 | + : date( |
|
128 | + 'm/d/Y', |
|
129 | + current_time('timestamp') |
|
130 | + ); |
|
131 | + ob_start(); |
|
132 | + ?> |
|
133 | 133 | <label for="txn-filter-start-date">Display Transactions from </label> |
134 | 134 | <input class="datepicker" |
135 | 135 | id="txn-filter-start-date" |
@@ -147,585 +147,585 @@ discard block |
||
147 | 147 | value="<?php echo esc_html($end_date); ?>" |
148 | 148 | /> |
149 | 149 | <?php |
150 | - $filters[] = ob_get_contents(); |
|
151 | - ob_end_clean(); |
|
152 | - return $filters; |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - *_add_view_counts |
|
158 | - */ |
|
159 | - protected function _add_view_counts() |
|
160 | - { |
|
161 | - foreach ($this->_views as $view) { |
|
162 | - $this->_views[ $view['slug'] ]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']); |
|
163 | - } |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * column TXN_ID |
|
169 | - * |
|
170 | - * @param \EE_Transaction $transaction |
|
171 | - * @return string |
|
172 | - * @throws \EE_Error |
|
173 | - */ |
|
174 | - public function column_TXN_ID(EE_Transaction $transaction) |
|
175 | - { |
|
176 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
177 | - array( |
|
178 | - 'action' => 'view_transaction', |
|
179 | - 'TXN_ID' => $transaction->ID(), |
|
180 | - ), |
|
181 | - TXN_ADMIN_URL |
|
182 | - ); |
|
183 | - $content = '<a href="' . $view_lnk_url . '"' |
|
184 | - . ' title="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">' |
|
185 | - . $transaction->ID() |
|
186 | - . '</a>'; |
|
187 | - |
|
188 | - // txn timestamp |
|
189 | - $content .= ' <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>'; |
|
190 | - return $content; |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * @param \EE_Transaction $transaction |
|
196 | - * @return string |
|
197 | - * @throws EE_Error |
|
198 | - * @throws InvalidArgumentException |
|
199 | - * @throws InvalidDataTypeException |
|
200 | - * @throws InvalidInterfaceException |
|
201 | - */ |
|
202 | - protected function _get_txn_timestamp(EE_Transaction $transaction) |
|
203 | - { |
|
204 | - // is TXN less than 2 hours old ? |
|
205 | - if ( |
|
206 | - ($transaction->failed() || $transaction->is_abandoned()) |
|
207 | - && $this->session_lifespan->expiration() < $transaction->datetime(false, true) |
|
208 | - ) { |
|
209 | - $timestamp = esc_html__('TXN in progress...', 'event_espresso'); |
|
210 | - } else { |
|
211 | - $timestamp = $transaction->get_i18n_datetime('TXN_timestamp'); |
|
212 | - } |
|
213 | - return $timestamp; |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * column_cb |
|
219 | - * |
|
220 | - * @param \EE_Transaction $transaction |
|
221 | - * @return string |
|
222 | - * @throws \EE_Error |
|
223 | - */ |
|
224 | - public function column_cb($transaction) |
|
225 | - { |
|
226 | - return sprintf( |
|
227 | - '<input type="checkbox" name="%1$s[]" value="%2$s" />', |
|
228 | - $this->_wp_list_args['singular'], |
|
229 | - $transaction->ID() |
|
230 | - ); |
|
231 | - } |
|
232 | - |
|
233 | - |
|
234 | - /** |
|
235 | - * column_TXN_timestamp |
|
236 | - * |
|
237 | - * @param \EE_Transaction $transaction |
|
238 | - * @return string |
|
239 | - * @throws \EE_Error |
|
240 | - */ |
|
241 | - public function column_TXN_timestamp(EE_Transaction $transaction) |
|
242 | - { |
|
243 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
244 | - array( |
|
245 | - 'action' => 'view_transaction', |
|
246 | - 'TXN_ID' => $transaction->ID(), |
|
247 | - ), |
|
248 | - TXN_ADMIN_URL |
|
249 | - ); |
|
250 | - $txn_date = '<a href="' . $view_lnk_url . '"' |
|
251 | - . ' title="' |
|
252 | - . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID() . '">' |
|
253 | - . $this->_get_txn_timestamp($transaction) |
|
254 | - . '</a>'; |
|
255 | - // status |
|
256 | - $txn_date .= '<br><span class="ee-status-text-small">' |
|
257 | - . EEH_Template::pretty_status( |
|
258 | - $transaction->status_ID(), |
|
259 | - false, |
|
260 | - 'sentence' |
|
261 | - ) |
|
262 | - . '</span>'; |
|
263 | - return $txn_date; |
|
264 | - } |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * column_TXN_total |
|
269 | - * |
|
270 | - * @param \EE_Transaction $transaction |
|
271 | - * @return string |
|
272 | - * @throws \EE_Error |
|
273 | - */ |
|
274 | - public function column_TXN_total(EE_Transaction $transaction) |
|
275 | - { |
|
276 | - if ($transaction->get('TXN_total') > 0) { |
|
277 | - return '<span class="txn-pad-rght">' |
|
278 | - . apply_filters( |
|
279 | - 'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total', |
|
280 | - $transaction->get_pretty('TXN_total'), |
|
281 | - $transaction |
|
282 | - ) |
|
283 | - . '</span>'; |
|
284 | - } else { |
|
285 | - return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>'; |
|
286 | - } |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * column_TXN_paid |
|
292 | - * |
|
293 | - * @param \EE_Transaction $transaction |
|
294 | - * @return mixed|string |
|
295 | - * @throws \EE_Error |
|
296 | - */ |
|
297 | - public function column_TXN_paid(EE_Transaction $transaction) |
|
298 | - { |
|
299 | - $transaction_total = $transaction->get('TXN_total'); |
|
300 | - $transaction_paid = $transaction->get('TXN_paid'); |
|
301 | - |
|
302 | - if (\EEH_Money::compare_floats($transaction_total, 0, '>')) { |
|
303 | - // monies owing |
|
304 | - $span_class = 'txn-overview-part-payment-spn'; |
|
305 | - if (\EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) { |
|
306 | - // paid in full |
|
307 | - $span_class = 'txn-overview-full-payment-spn'; |
|
308 | - } elseif (\EEH_Money::compare_floats($transaction_paid, 0, '==')) { |
|
309 | - // no payments made |
|
310 | - $span_class = 'txn-overview-no-payment-spn'; |
|
311 | - } |
|
312 | - } else { |
|
313 | - // transaction_total == 0 so this is a free event |
|
314 | - $span_class = 'txn-overview-free-event-spn'; |
|
315 | - } |
|
316 | - |
|
317 | - $payment_method = $transaction->payment_method(); |
|
318 | - $payment_method_name = $payment_method instanceof EE_Payment_Method |
|
319 | - ? $payment_method->admin_name() |
|
320 | - : esc_html__('Unknown', 'event_espresso'); |
|
321 | - |
|
322 | - $content = '<span class="' . $span_class . ' txn-pad-rght">' |
|
323 | - . $transaction->get_pretty('TXN_paid') |
|
324 | - . '</span>'; |
|
325 | - if ($transaction_paid > 0) { |
|
326 | - $content .= '<br><span class="ee-status-text-small">' |
|
327 | - . sprintf( |
|
328 | - esc_html__('...via %s', 'event_espresso'), |
|
329 | - $payment_method_name |
|
330 | - ) |
|
331 | - . '</span>'; |
|
332 | - } |
|
333 | - return $content; |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * column_ATT_fname |
|
339 | - * |
|
340 | - * @param \EE_Transaction $transaction |
|
341 | - * @return string |
|
342 | - * @throws EE_Error |
|
343 | - * @throws InvalidArgumentException |
|
344 | - * @throws InvalidDataTypeException |
|
345 | - * @throws InvalidInterfaceException |
|
346 | - */ |
|
347 | - public function column_ATT_fname(EE_Transaction $transaction) |
|
348 | - { |
|
349 | - $primary_reg = $transaction->primary_registration(); |
|
350 | - $attendee = $primary_reg->get_first_related('Attendee'); |
|
351 | - if ($attendee instanceof EE_Attendee) { |
|
352 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
353 | - array( |
|
354 | - 'action' => 'view_registration', |
|
355 | - '_REG_ID' => $primary_reg->ID(), |
|
356 | - ), |
|
357 | - REG_ADMIN_URL |
|
358 | - ); |
|
359 | - $content = EE_Registry::instance()->CAP->current_user_can( |
|
360 | - 'ee_read_registration', |
|
361 | - 'espresso_registrations_view_registration', |
|
362 | - $primary_reg->ID() |
|
363 | - ) |
|
364 | - ? '<a href="' . $edit_lnk_url . '"' |
|
365 | - . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
366 | - . $attendee->full_name() |
|
367 | - . '</a>' |
|
368 | - : $attendee->full_name(); |
|
369 | - $content .= '<br>' . $attendee->email(); |
|
370 | - return $content; |
|
371 | - } |
|
372 | - return $transaction->failed() || $transaction->is_abandoned() |
|
373 | - ? esc_html__('no contact record.', 'event_espresso') |
|
374 | - : esc_html__( |
|
375 | - 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
376 | - 'event_espresso' |
|
377 | - ); |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * column_ATT_email |
|
383 | - * |
|
384 | - * @param \EE_Transaction $transaction |
|
385 | - * @return string |
|
386 | - * @throws \EE_Error |
|
387 | - */ |
|
388 | - public function column_ATT_email(EE_Transaction $transaction) |
|
389 | - { |
|
390 | - $attendee = $transaction->primary_registration()->get_first_related('Attendee'); |
|
391 | - if (! empty($attendee)) { |
|
392 | - return '<a href="mailto:' . $attendee->get('ATT_email') . '">' |
|
393 | - . $attendee->get('ATT_email') |
|
394 | - . '</a>'; |
|
395 | - } else { |
|
396 | - return $transaction->failed() || $transaction->is_abandoned() |
|
397 | - ? esc_html__('no contact record.', 'event_espresso') |
|
398 | - : esc_html__( |
|
399 | - 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
400 | - 'event_espresso' |
|
401 | - ); |
|
402 | - } |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * column_event_name |
|
408 | - * |
|
409 | - * @param \EE_Transaction $transaction |
|
410 | - * @return string |
|
411 | - * @throws EE_Error |
|
412 | - * @throws InvalidArgumentException |
|
413 | - * @throws InvalidDataTypeException |
|
414 | - * @throws InvalidInterfaceException |
|
415 | - */ |
|
416 | - public function column_event_name(EE_Transaction $transaction) |
|
417 | - { |
|
418 | - $actions = array(); |
|
419 | - $event = $transaction->primary_registration()->get_first_related('Event'); |
|
420 | - if (! empty($event)) { |
|
421 | - $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( |
|
422 | - array('action' => 'edit', 'post' => $event->ID()), |
|
423 | - EVENTS_ADMIN_URL |
|
424 | - ); |
|
425 | - $event_name = $event->get('EVT_name'); |
|
426 | - |
|
427 | - // filter this view by transactions for this event |
|
428 | - $txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce( |
|
429 | - array( |
|
430 | - 'action' => 'default', |
|
431 | - 'EVT_ID' => $event->ID(), |
|
432 | - ) |
|
433 | - ); |
|
434 | - if ( |
|
435 | - empty($this->_req_data['EVT_ID']) |
|
436 | - && EE_Registry::instance()->CAP->current_user_can( |
|
437 | - 'ee_edit_event', |
|
438 | - 'espresso_events_edit', |
|
439 | - $event->ID() |
|
440 | - ) |
|
441 | - ) { |
|
442 | - $actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '"' |
|
443 | - . ' title="' . esc_attr__( |
|
444 | - 'Filter transactions by this event', |
|
445 | - 'event_espresso' |
|
446 | - ) . '">' |
|
447 | - . esc_html__('View Transactions for this event', 'event_espresso') |
|
448 | - . '</a>'; |
|
449 | - } |
|
450 | - |
|
451 | - return sprintf( |
|
452 | - '%1$s %2$s', |
|
453 | - EE_Registry::instance()->CAP->current_user_can( |
|
454 | - 'ee_edit_event', |
|
455 | - 'espresso_events_edit', |
|
456 | - $event->ID() |
|
457 | - ) |
|
458 | - ? '<a href="' . $edit_event_url . '"' |
|
459 | - . ' title="' |
|
460 | - . sprintf( |
|
461 | - esc_attr__('Edit Event: %s', 'event_espresso'), |
|
462 | - $event->get('EVT_name') |
|
463 | - ) |
|
464 | - . '">' |
|
465 | - . wp_trim_words( |
|
466 | - $event_name, |
|
467 | - 30, |
|
468 | - '...' |
|
469 | - ) |
|
470 | - . '</a>' |
|
471 | - : wp_trim_words($event_name, 30, '...'), |
|
472 | - $this->row_actions($actions) |
|
473 | - ); |
|
474 | - } else { |
|
475 | - return esc_html__( |
|
476 | - 'The event associated with this transaction via the primary registration cannot be retrieved.', |
|
477 | - 'event_espresso' |
|
478 | - ); |
|
479 | - } |
|
480 | - } |
|
481 | - |
|
482 | - |
|
483 | - /** |
|
484 | - * column_actions |
|
485 | - * |
|
486 | - * @param \EE_Transaction $transaction |
|
487 | - * @return string |
|
488 | - * @throws \EE_Error |
|
489 | - */ |
|
490 | - public function column_actions(EE_Transaction $transaction) |
|
491 | - { |
|
492 | - return $this->_action_string( |
|
493 | - $this->get_transaction_details_link($transaction) |
|
494 | - . $this->get_invoice_link($transaction) |
|
495 | - . $this->get_receipt_link($transaction) |
|
496 | - . $this->get_primary_registration_details_link($transaction) |
|
497 | - . $this->get_send_payment_reminder_trigger_link($transaction) |
|
498 | - . $this->get_payment_overview_link($transaction) |
|
499 | - . $this->get_related_messages_link($transaction), |
|
500 | - $transaction, |
|
501 | - 'ul', |
|
502 | - 'txn-overview-actions-ul' |
|
503 | - ); |
|
504 | - } |
|
505 | - |
|
506 | - |
|
507 | - /** |
|
508 | - * Get the transaction details link. |
|
509 | - * |
|
510 | - * @param EE_Transaction $transaction |
|
511 | - * @return string |
|
512 | - * @throws EE_Error |
|
513 | - */ |
|
514 | - protected function get_transaction_details_link(EE_Transaction $transaction) |
|
515 | - { |
|
516 | - $url = EE_Admin_Page::add_query_args_and_nonce( |
|
517 | - array( |
|
518 | - 'action' => 'view_transaction', |
|
519 | - 'TXN_ID' => $transaction->ID(), |
|
520 | - ), |
|
521 | - TXN_ADMIN_URL |
|
522 | - ); |
|
523 | - return ' |
|
150 | + $filters[] = ob_get_contents(); |
|
151 | + ob_end_clean(); |
|
152 | + return $filters; |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + *_add_view_counts |
|
158 | + */ |
|
159 | + protected function _add_view_counts() |
|
160 | + { |
|
161 | + foreach ($this->_views as $view) { |
|
162 | + $this->_views[ $view['slug'] ]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']); |
|
163 | + } |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * column TXN_ID |
|
169 | + * |
|
170 | + * @param \EE_Transaction $transaction |
|
171 | + * @return string |
|
172 | + * @throws \EE_Error |
|
173 | + */ |
|
174 | + public function column_TXN_ID(EE_Transaction $transaction) |
|
175 | + { |
|
176 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
177 | + array( |
|
178 | + 'action' => 'view_transaction', |
|
179 | + 'TXN_ID' => $transaction->ID(), |
|
180 | + ), |
|
181 | + TXN_ADMIN_URL |
|
182 | + ); |
|
183 | + $content = '<a href="' . $view_lnk_url . '"' |
|
184 | + . ' title="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">' |
|
185 | + . $transaction->ID() |
|
186 | + . '</a>'; |
|
187 | + |
|
188 | + // txn timestamp |
|
189 | + $content .= ' <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>'; |
|
190 | + return $content; |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * @param \EE_Transaction $transaction |
|
196 | + * @return string |
|
197 | + * @throws EE_Error |
|
198 | + * @throws InvalidArgumentException |
|
199 | + * @throws InvalidDataTypeException |
|
200 | + * @throws InvalidInterfaceException |
|
201 | + */ |
|
202 | + protected function _get_txn_timestamp(EE_Transaction $transaction) |
|
203 | + { |
|
204 | + // is TXN less than 2 hours old ? |
|
205 | + if ( |
|
206 | + ($transaction->failed() || $transaction->is_abandoned()) |
|
207 | + && $this->session_lifespan->expiration() < $transaction->datetime(false, true) |
|
208 | + ) { |
|
209 | + $timestamp = esc_html__('TXN in progress...', 'event_espresso'); |
|
210 | + } else { |
|
211 | + $timestamp = $transaction->get_i18n_datetime('TXN_timestamp'); |
|
212 | + } |
|
213 | + return $timestamp; |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * column_cb |
|
219 | + * |
|
220 | + * @param \EE_Transaction $transaction |
|
221 | + * @return string |
|
222 | + * @throws \EE_Error |
|
223 | + */ |
|
224 | + public function column_cb($transaction) |
|
225 | + { |
|
226 | + return sprintf( |
|
227 | + '<input type="checkbox" name="%1$s[]" value="%2$s" />', |
|
228 | + $this->_wp_list_args['singular'], |
|
229 | + $transaction->ID() |
|
230 | + ); |
|
231 | + } |
|
232 | + |
|
233 | + |
|
234 | + /** |
|
235 | + * column_TXN_timestamp |
|
236 | + * |
|
237 | + * @param \EE_Transaction $transaction |
|
238 | + * @return string |
|
239 | + * @throws \EE_Error |
|
240 | + */ |
|
241 | + public function column_TXN_timestamp(EE_Transaction $transaction) |
|
242 | + { |
|
243 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
244 | + array( |
|
245 | + 'action' => 'view_transaction', |
|
246 | + 'TXN_ID' => $transaction->ID(), |
|
247 | + ), |
|
248 | + TXN_ADMIN_URL |
|
249 | + ); |
|
250 | + $txn_date = '<a href="' . $view_lnk_url . '"' |
|
251 | + . ' title="' |
|
252 | + . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID() . '">' |
|
253 | + . $this->_get_txn_timestamp($transaction) |
|
254 | + . '</a>'; |
|
255 | + // status |
|
256 | + $txn_date .= '<br><span class="ee-status-text-small">' |
|
257 | + . EEH_Template::pretty_status( |
|
258 | + $transaction->status_ID(), |
|
259 | + false, |
|
260 | + 'sentence' |
|
261 | + ) |
|
262 | + . '</span>'; |
|
263 | + return $txn_date; |
|
264 | + } |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * column_TXN_total |
|
269 | + * |
|
270 | + * @param \EE_Transaction $transaction |
|
271 | + * @return string |
|
272 | + * @throws \EE_Error |
|
273 | + */ |
|
274 | + public function column_TXN_total(EE_Transaction $transaction) |
|
275 | + { |
|
276 | + if ($transaction->get('TXN_total') > 0) { |
|
277 | + return '<span class="txn-pad-rght">' |
|
278 | + . apply_filters( |
|
279 | + 'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total', |
|
280 | + $transaction->get_pretty('TXN_total'), |
|
281 | + $transaction |
|
282 | + ) |
|
283 | + . '</span>'; |
|
284 | + } else { |
|
285 | + return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>'; |
|
286 | + } |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * column_TXN_paid |
|
292 | + * |
|
293 | + * @param \EE_Transaction $transaction |
|
294 | + * @return mixed|string |
|
295 | + * @throws \EE_Error |
|
296 | + */ |
|
297 | + public function column_TXN_paid(EE_Transaction $transaction) |
|
298 | + { |
|
299 | + $transaction_total = $transaction->get('TXN_total'); |
|
300 | + $transaction_paid = $transaction->get('TXN_paid'); |
|
301 | + |
|
302 | + if (\EEH_Money::compare_floats($transaction_total, 0, '>')) { |
|
303 | + // monies owing |
|
304 | + $span_class = 'txn-overview-part-payment-spn'; |
|
305 | + if (\EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) { |
|
306 | + // paid in full |
|
307 | + $span_class = 'txn-overview-full-payment-spn'; |
|
308 | + } elseif (\EEH_Money::compare_floats($transaction_paid, 0, '==')) { |
|
309 | + // no payments made |
|
310 | + $span_class = 'txn-overview-no-payment-spn'; |
|
311 | + } |
|
312 | + } else { |
|
313 | + // transaction_total == 0 so this is a free event |
|
314 | + $span_class = 'txn-overview-free-event-spn'; |
|
315 | + } |
|
316 | + |
|
317 | + $payment_method = $transaction->payment_method(); |
|
318 | + $payment_method_name = $payment_method instanceof EE_Payment_Method |
|
319 | + ? $payment_method->admin_name() |
|
320 | + : esc_html__('Unknown', 'event_espresso'); |
|
321 | + |
|
322 | + $content = '<span class="' . $span_class . ' txn-pad-rght">' |
|
323 | + . $transaction->get_pretty('TXN_paid') |
|
324 | + . '</span>'; |
|
325 | + if ($transaction_paid > 0) { |
|
326 | + $content .= '<br><span class="ee-status-text-small">' |
|
327 | + . sprintf( |
|
328 | + esc_html__('...via %s', 'event_espresso'), |
|
329 | + $payment_method_name |
|
330 | + ) |
|
331 | + . '</span>'; |
|
332 | + } |
|
333 | + return $content; |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * column_ATT_fname |
|
339 | + * |
|
340 | + * @param \EE_Transaction $transaction |
|
341 | + * @return string |
|
342 | + * @throws EE_Error |
|
343 | + * @throws InvalidArgumentException |
|
344 | + * @throws InvalidDataTypeException |
|
345 | + * @throws InvalidInterfaceException |
|
346 | + */ |
|
347 | + public function column_ATT_fname(EE_Transaction $transaction) |
|
348 | + { |
|
349 | + $primary_reg = $transaction->primary_registration(); |
|
350 | + $attendee = $primary_reg->get_first_related('Attendee'); |
|
351 | + if ($attendee instanceof EE_Attendee) { |
|
352 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
353 | + array( |
|
354 | + 'action' => 'view_registration', |
|
355 | + '_REG_ID' => $primary_reg->ID(), |
|
356 | + ), |
|
357 | + REG_ADMIN_URL |
|
358 | + ); |
|
359 | + $content = EE_Registry::instance()->CAP->current_user_can( |
|
360 | + 'ee_read_registration', |
|
361 | + 'espresso_registrations_view_registration', |
|
362 | + $primary_reg->ID() |
|
363 | + ) |
|
364 | + ? '<a href="' . $edit_lnk_url . '"' |
|
365 | + . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
366 | + . $attendee->full_name() |
|
367 | + . '</a>' |
|
368 | + : $attendee->full_name(); |
|
369 | + $content .= '<br>' . $attendee->email(); |
|
370 | + return $content; |
|
371 | + } |
|
372 | + return $transaction->failed() || $transaction->is_abandoned() |
|
373 | + ? esc_html__('no contact record.', 'event_espresso') |
|
374 | + : esc_html__( |
|
375 | + 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
376 | + 'event_espresso' |
|
377 | + ); |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * column_ATT_email |
|
383 | + * |
|
384 | + * @param \EE_Transaction $transaction |
|
385 | + * @return string |
|
386 | + * @throws \EE_Error |
|
387 | + */ |
|
388 | + public function column_ATT_email(EE_Transaction $transaction) |
|
389 | + { |
|
390 | + $attendee = $transaction->primary_registration()->get_first_related('Attendee'); |
|
391 | + if (! empty($attendee)) { |
|
392 | + return '<a href="mailto:' . $attendee->get('ATT_email') . '">' |
|
393 | + . $attendee->get('ATT_email') |
|
394 | + . '</a>'; |
|
395 | + } else { |
|
396 | + return $transaction->failed() || $transaction->is_abandoned() |
|
397 | + ? esc_html__('no contact record.', 'event_espresso') |
|
398 | + : esc_html__( |
|
399 | + 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
400 | + 'event_espresso' |
|
401 | + ); |
|
402 | + } |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * column_event_name |
|
408 | + * |
|
409 | + * @param \EE_Transaction $transaction |
|
410 | + * @return string |
|
411 | + * @throws EE_Error |
|
412 | + * @throws InvalidArgumentException |
|
413 | + * @throws InvalidDataTypeException |
|
414 | + * @throws InvalidInterfaceException |
|
415 | + */ |
|
416 | + public function column_event_name(EE_Transaction $transaction) |
|
417 | + { |
|
418 | + $actions = array(); |
|
419 | + $event = $transaction->primary_registration()->get_first_related('Event'); |
|
420 | + if (! empty($event)) { |
|
421 | + $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( |
|
422 | + array('action' => 'edit', 'post' => $event->ID()), |
|
423 | + EVENTS_ADMIN_URL |
|
424 | + ); |
|
425 | + $event_name = $event->get('EVT_name'); |
|
426 | + |
|
427 | + // filter this view by transactions for this event |
|
428 | + $txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce( |
|
429 | + array( |
|
430 | + 'action' => 'default', |
|
431 | + 'EVT_ID' => $event->ID(), |
|
432 | + ) |
|
433 | + ); |
|
434 | + if ( |
|
435 | + empty($this->_req_data['EVT_ID']) |
|
436 | + && EE_Registry::instance()->CAP->current_user_can( |
|
437 | + 'ee_edit_event', |
|
438 | + 'espresso_events_edit', |
|
439 | + $event->ID() |
|
440 | + ) |
|
441 | + ) { |
|
442 | + $actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '"' |
|
443 | + . ' title="' . esc_attr__( |
|
444 | + 'Filter transactions by this event', |
|
445 | + 'event_espresso' |
|
446 | + ) . '">' |
|
447 | + . esc_html__('View Transactions for this event', 'event_espresso') |
|
448 | + . '</a>'; |
|
449 | + } |
|
450 | + |
|
451 | + return sprintf( |
|
452 | + '%1$s %2$s', |
|
453 | + EE_Registry::instance()->CAP->current_user_can( |
|
454 | + 'ee_edit_event', |
|
455 | + 'espresso_events_edit', |
|
456 | + $event->ID() |
|
457 | + ) |
|
458 | + ? '<a href="' . $edit_event_url . '"' |
|
459 | + . ' title="' |
|
460 | + . sprintf( |
|
461 | + esc_attr__('Edit Event: %s', 'event_espresso'), |
|
462 | + $event->get('EVT_name') |
|
463 | + ) |
|
464 | + . '">' |
|
465 | + . wp_trim_words( |
|
466 | + $event_name, |
|
467 | + 30, |
|
468 | + '...' |
|
469 | + ) |
|
470 | + . '</a>' |
|
471 | + : wp_trim_words($event_name, 30, '...'), |
|
472 | + $this->row_actions($actions) |
|
473 | + ); |
|
474 | + } else { |
|
475 | + return esc_html__( |
|
476 | + 'The event associated with this transaction via the primary registration cannot be retrieved.', |
|
477 | + 'event_espresso' |
|
478 | + ); |
|
479 | + } |
|
480 | + } |
|
481 | + |
|
482 | + |
|
483 | + /** |
|
484 | + * column_actions |
|
485 | + * |
|
486 | + * @param \EE_Transaction $transaction |
|
487 | + * @return string |
|
488 | + * @throws \EE_Error |
|
489 | + */ |
|
490 | + public function column_actions(EE_Transaction $transaction) |
|
491 | + { |
|
492 | + return $this->_action_string( |
|
493 | + $this->get_transaction_details_link($transaction) |
|
494 | + . $this->get_invoice_link($transaction) |
|
495 | + . $this->get_receipt_link($transaction) |
|
496 | + . $this->get_primary_registration_details_link($transaction) |
|
497 | + . $this->get_send_payment_reminder_trigger_link($transaction) |
|
498 | + . $this->get_payment_overview_link($transaction) |
|
499 | + . $this->get_related_messages_link($transaction), |
|
500 | + $transaction, |
|
501 | + 'ul', |
|
502 | + 'txn-overview-actions-ul' |
|
503 | + ); |
|
504 | + } |
|
505 | + |
|
506 | + |
|
507 | + /** |
|
508 | + * Get the transaction details link. |
|
509 | + * |
|
510 | + * @param EE_Transaction $transaction |
|
511 | + * @return string |
|
512 | + * @throws EE_Error |
|
513 | + */ |
|
514 | + protected function get_transaction_details_link(EE_Transaction $transaction) |
|
515 | + { |
|
516 | + $url = EE_Admin_Page::add_query_args_and_nonce( |
|
517 | + array( |
|
518 | + 'action' => 'view_transaction', |
|
519 | + 'TXN_ID' => $transaction->ID(), |
|
520 | + ), |
|
521 | + TXN_ADMIN_URL |
|
522 | + ); |
|
523 | + return ' |
|
524 | 524 | <li> |
525 | 525 | <a href="' . $url . '"' |
526 | - . ' title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text"> |
|
526 | + . ' title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text"> |
|
527 | 527 | <span class="dashicons dashicons-cart"></span> |
528 | 528 | </a> |
529 | 529 | </li>'; |
530 | - } |
|
531 | - |
|
532 | - |
|
533 | - /** |
|
534 | - * Get the invoice link for the given registration. |
|
535 | - * |
|
536 | - * @param EE_Transaction $transaction |
|
537 | - * @return string |
|
538 | - * @throws EE_Error |
|
539 | - */ |
|
540 | - protected function get_invoice_link(EE_Transaction $transaction) |
|
541 | - { |
|
542 | - $registration = $transaction->primary_registration(); |
|
543 | - if ($registration instanceof EE_Registration) { |
|
544 | - $url = $registration->invoice_url(); |
|
545 | - // only show invoice link if message type is active. |
|
546 | - if ( |
|
547 | - $registration->attendee() instanceof EE_Attendee |
|
548 | - && EEH_MSG_Template::is_mt_active('invoice') |
|
549 | - ) { |
|
550 | - return ' |
|
530 | + } |
|
531 | + |
|
532 | + |
|
533 | + /** |
|
534 | + * Get the invoice link for the given registration. |
|
535 | + * |
|
536 | + * @param EE_Transaction $transaction |
|
537 | + * @return string |
|
538 | + * @throws EE_Error |
|
539 | + */ |
|
540 | + protected function get_invoice_link(EE_Transaction $transaction) |
|
541 | + { |
|
542 | + $registration = $transaction->primary_registration(); |
|
543 | + if ($registration instanceof EE_Registration) { |
|
544 | + $url = $registration->invoice_url(); |
|
545 | + // only show invoice link if message type is active. |
|
546 | + if ( |
|
547 | + $registration->attendee() instanceof EE_Attendee |
|
548 | + && EEH_MSG_Template::is_mt_active('invoice') |
|
549 | + ) { |
|
550 | + return ' |
|
551 | 551 | <li> |
552 | 552 | <a title="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '"' |
553 | - . ' target="_blank" href="' . $url . '" class="tiny-text"> |
|
553 | + . ' target="_blank" href="' . $url . '" class="tiny-text"> |
|
554 | 554 | <span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span> |
555 | 555 | </a> |
556 | 556 | </li>'; |
557 | - } |
|
558 | - } |
|
559 | - return ''; |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - /** |
|
564 | - * Get the receipt link for the transaction. |
|
565 | - * |
|
566 | - * @param EE_Transaction $transaction |
|
567 | - * @return string |
|
568 | - * @throws EE_Error |
|
569 | - */ |
|
570 | - protected function get_receipt_link(EE_Transaction $transaction) |
|
571 | - { |
|
572 | - $registration = $transaction->primary_registration(); |
|
573 | - if ($registration instanceof EE_Registration) { |
|
574 | - $url = $registration->receipt_url(); |
|
575 | - // only show receipt link if message type is active. |
|
576 | - if ( |
|
577 | - $registration->attendee() instanceof EE_Attendee |
|
578 | - && EEH_MSG_Template::is_mt_active('receipt') |
|
579 | - ) { |
|
580 | - return ' |
|
557 | + } |
|
558 | + } |
|
559 | + return ''; |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + /** |
|
564 | + * Get the receipt link for the transaction. |
|
565 | + * |
|
566 | + * @param EE_Transaction $transaction |
|
567 | + * @return string |
|
568 | + * @throws EE_Error |
|
569 | + */ |
|
570 | + protected function get_receipt_link(EE_Transaction $transaction) |
|
571 | + { |
|
572 | + $registration = $transaction->primary_registration(); |
|
573 | + if ($registration instanceof EE_Registration) { |
|
574 | + $url = $registration->receipt_url(); |
|
575 | + // only show receipt link if message type is active. |
|
576 | + if ( |
|
577 | + $registration->attendee() instanceof EE_Attendee |
|
578 | + && EEH_MSG_Template::is_mt_active('receipt') |
|
579 | + ) { |
|
580 | + return ' |
|
581 | 581 | <li> |
582 | 582 | <a title="' . esc_attr__('View Transaction Receipt', 'event_espresso') . '"' |
583 | - . ' target="_blank" href="' . $url . '" class="tiny-text"> |
|
583 | + . ' target="_blank" href="' . $url . '" class="tiny-text"> |
|
584 | 584 | <span class="dashicons dashicons-media-default ee-icon-size-18"></span> |
585 | 585 | </a> |
586 | 586 | </li>'; |
587 | - } |
|
588 | - } |
|
589 | - return ''; |
|
590 | - } |
|
591 | - |
|
592 | - |
|
593 | - /** |
|
594 | - * Get the link to view the details for the primary registration. |
|
595 | - * |
|
596 | - * @param EE_Transaction $transaction |
|
597 | - * @return string |
|
598 | - * @throws EE_Error |
|
599 | - * @throws InvalidArgumentException |
|
600 | - * @throws InvalidDataTypeException |
|
601 | - * @throws InvalidInterfaceException |
|
602 | - */ |
|
603 | - protected function get_primary_registration_details_link(EE_Transaction $transaction) |
|
604 | - { |
|
605 | - $registration = $transaction->primary_registration(); |
|
606 | - if ($registration instanceof EE_Registration) { |
|
607 | - $url = EE_Admin_Page::add_query_args_and_nonce( |
|
608 | - array( |
|
609 | - 'action' => 'view_registration', |
|
610 | - '_REG_ID' => $registration->ID(), |
|
611 | - ), |
|
612 | - REG_ADMIN_URL |
|
613 | - ); |
|
614 | - return EE_Registry::instance()->CAP->current_user_can( |
|
615 | - 'ee_read_registration', |
|
616 | - 'espresso_registrations_view_registration', |
|
617 | - $registration->ID() |
|
618 | - ) |
|
619 | - ? ' |
|
587 | + } |
|
588 | + } |
|
589 | + return ''; |
|
590 | + } |
|
591 | + |
|
592 | + |
|
593 | + /** |
|
594 | + * Get the link to view the details for the primary registration. |
|
595 | + * |
|
596 | + * @param EE_Transaction $transaction |
|
597 | + * @return string |
|
598 | + * @throws EE_Error |
|
599 | + * @throws InvalidArgumentException |
|
600 | + * @throws InvalidDataTypeException |
|
601 | + * @throws InvalidInterfaceException |
|
602 | + */ |
|
603 | + protected function get_primary_registration_details_link(EE_Transaction $transaction) |
|
604 | + { |
|
605 | + $registration = $transaction->primary_registration(); |
|
606 | + if ($registration instanceof EE_Registration) { |
|
607 | + $url = EE_Admin_Page::add_query_args_and_nonce( |
|
608 | + array( |
|
609 | + 'action' => 'view_registration', |
|
610 | + '_REG_ID' => $registration->ID(), |
|
611 | + ), |
|
612 | + REG_ADMIN_URL |
|
613 | + ); |
|
614 | + return EE_Registry::instance()->CAP->current_user_can( |
|
615 | + 'ee_read_registration', |
|
616 | + 'espresso_registrations_view_registration', |
|
617 | + $registration->ID() |
|
618 | + ) |
|
619 | + ? ' |
|
620 | 620 | <li> |
621 | 621 | <a href="' . $url . '"' |
622 | - . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text"> |
|
622 | + . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text"> |
|
623 | 623 | <span class="dashicons dashicons-clipboard"></span> |
624 | 624 | </a> |
625 | 625 | </li>' |
626 | - : ''; |
|
627 | - } |
|
628 | - return ''; |
|
629 | - } |
|
630 | - |
|
631 | - |
|
632 | - /** |
|
633 | - * Get send payment reminder trigger link |
|
634 | - * |
|
635 | - * @param EE_Transaction $transaction |
|
636 | - * @return string |
|
637 | - * @throws EE_Error |
|
638 | - * @throws InvalidArgumentException |
|
639 | - * @throws InvalidDataTypeException |
|
640 | - * @throws InvalidInterfaceException |
|
641 | - */ |
|
642 | - protected function get_send_payment_reminder_trigger_link(EE_Transaction $transaction) |
|
643 | - { |
|
644 | - $registration = $transaction->primary_registration(); |
|
645 | - if ( |
|
646 | - $registration instanceof EE_Registration |
|
647 | - && $registration->attendee() instanceof EE_Attendee |
|
648 | - && EEH_MSG_Template::is_mt_active('payment_reminder') |
|
649 | - && ! in_array( |
|
650 | - $transaction->status_ID(), |
|
651 | - array(EEM_Transaction::complete_status_code, EEM_Transaction::overpaid_status_code), |
|
652 | - true |
|
653 | - ) |
|
654 | - && EE_Registry::instance()->CAP->current_user_can( |
|
655 | - 'ee_send_message', |
|
656 | - 'espresso_transactions_send_payment_reminder' |
|
657 | - ) |
|
658 | - ) { |
|
659 | - $url = EE_Admin_Page::add_query_args_and_nonce( |
|
660 | - array( |
|
661 | - 'action' => 'send_payment_reminder', |
|
662 | - 'TXN_ID' => $transaction->ID(), |
|
663 | - ), |
|
664 | - TXN_ADMIN_URL |
|
665 | - ); |
|
666 | - return ' |
|
626 | + : ''; |
|
627 | + } |
|
628 | + return ''; |
|
629 | + } |
|
630 | + |
|
631 | + |
|
632 | + /** |
|
633 | + * Get send payment reminder trigger link |
|
634 | + * |
|
635 | + * @param EE_Transaction $transaction |
|
636 | + * @return string |
|
637 | + * @throws EE_Error |
|
638 | + * @throws InvalidArgumentException |
|
639 | + * @throws InvalidDataTypeException |
|
640 | + * @throws InvalidInterfaceException |
|
641 | + */ |
|
642 | + protected function get_send_payment_reminder_trigger_link(EE_Transaction $transaction) |
|
643 | + { |
|
644 | + $registration = $transaction->primary_registration(); |
|
645 | + if ( |
|
646 | + $registration instanceof EE_Registration |
|
647 | + && $registration->attendee() instanceof EE_Attendee |
|
648 | + && EEH_MSG_Template::is_mt_active('payment_reminder') |
|
649 | + && ! in_array( |
|
650 | + $transaction->status_ID(), |
|
651 | + array(EEM_Transaction::complete_status_code, EEM_Transaction::overpaid_status_code), |
|
652 | + true |
|
653 | + ) |
|
654 | + && EE_Registry::instance()->CAP->current_user_can( |
|
655 | + 'ee_send_message', |
|
656 | + 'espresso_transactions_send_payment_reminder' |
|
657 | + ) |
|
658 | + ) { |
|
659 | + $url = EE_Admin_Page::add_query_args_and_nonce( |
|
660 | + array( |
|
661 | + 'action' => 'send_payment_reminder', |
|
662 | + 'TXN_ID' => $transaction->ID(), |
|
663 | + ), |
|
664 | + TXN_ADMIN_URL |
|
665 | + ); |
|
666 | + return ' |
|
667 | 667 | <li> |
668 | 668 | <a href="' . $url . '"' |
669 | - . ' title="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" class="tiny-text"> |
|
669 | + . ' title="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" class="tiny-text"> |
|
670 | 670 | <span class="dashicons dashicons-email-alt"></span> |
671 | 671 | </a> |
672 | 672 | </li>'; |
673 | - } |
|
674 | - return ''; |
|
675 | - } |
|
676 | - |
|
677 | - |
|
678 | - /** |
|
679 | - * Get link to filtered view in the message activity list table of messages for this transaction. |
|
680 | - * |
|
681 | - * @param EE_Transaction $transaction |
|
682 | - * @return string |
|
683 | - * @throws EE_Error |
|
684 | - * @throws InvalidArgumentException |
|
685 | - * @throws InvalidDataTypeException |
|
686 | - * @throws InvalidInterfaceException |
|
687 | - */ |
|
688 | - protected function get_related_messages_link(EE_Transaction $transaction) |
|
689 | - { |
|
690 | - $url = EEH_MSG_Template::get_message_action_link( |
|
691 | - 'see_notifications_for', |
|
692 | - null, |
|
693 | - array('TXN_ID' => $transaction->ID()) |
|
694 | - ); |
|
695 | - return EE_Registry::instance()->CAP->current_user_can( |
|
696 | - 'ee_read_global_messages', |
|
697 | - 'view_filtered_messages' |
|
698 | - ) |
|
699 | - ? '<li>' . $url . '</li>' |
|
700 | - : ''; |
|
701 | - } |
|
702 | - |
|
703 | - |
|
704 | - /** |
|
705 | - * Return the link to make a payment on the frontend |
|
706 | - * |
|
707 | - * @param EE_Transaction $transaction |
|
708 | - * @return string |
|
709 | - * @throws EE_Error |
|
710 | - */ |
|
711 | - protected function get_payment_overview_link(EE_Transaction $transaction) |
|
712 | - { |
|
713 | - $registration = $transaction->primary_registration(); |
|
714 | - if ( |
|
715 | - $registration instanceof EE_Registration |
|
716 | - && $transaction->status_ID() !== EEM_Transaction::complete_status_code |
|
717 | - && $registration->owes_monies_and_can_pay() |
|
718 | - ) { |
|
719 | - return ' |
|
673 | + } |
|
674 | + return ''; |
|
675 | + } |
|
676 | + |
|
677 | + |
|
678 | + /** |
|
679 | + * Get link to filtered view in the message activity list table of messages for this transaction. |
|
680 | + * |
|
681 | + * @param EE_Transaction $transaction |
|
682 | + * @return string |
|
683 | + * @throws EE_Error |
|
684 | + * @throws InvalidArgumentException |
|
685 | + * @throws InvalidDataTypeException |
|
686 | + * @throws InvalidInterfaceException |
|
687 | + */ |
|
688 | + protected function get_related_messages_link(EE_Transaction $transaction) |
|
689 | + { |
|
690 | + $url = EEH_MSG_Template::get_message_action_link( |
|
691 | + 'see_notifications_for', |
|
692 | + null, |
|
693 | + array('TXN_ID' => $transaction->ID()) |
|
694 | + ); |
|
695 | + return EE_Registry::instance()->CAP->current_user_can( |
|
696 | + 'ee_read_global_messages', |
|
697 | + 'view_filtered_messages' |
|
698 | + ) |
|
699 | + ? '<li>' . $url . '</li>' |
|
700 | + : ''; |
|
701 | + } |
|
702 | + |
|
703 | + |
|
704 | + /** |
|
705 | + * Return the link to make a payment on the frontend |
|
706 | + * |
|
707 | + * @param EE_Transaction $transaction |
|
708 | + * @return string |
|
709 | + * @throws EE_Error |
|
710 | + */ |
|
711 | + protected function get_payment_overview_link(EE_Transaction $transaction) |
|
712 | + { |
|
713 | + $registration = $transaction->primary_registration(); |
|
714 | + if ( |
|
715 | + $registration instanceof EE_Registration |
|
716 | + && $transaction->status_ID() !== EEM_Transaction::complete_status_code |
|
717 | + && $registration->owes_monies_and_can_pay() |
|
718 | + ) { |
|
719 | + return ' |
|
720 | 720 | <li> |
721 | 721 | <a title="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso') . '"' |
722 | - . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"' |
|
723 | - . ' class="tiny-text"> |
|
722 | + . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"' |
|
723 | + . ' class="tiny-text"> |
|
724 | 724 | <span class="dashicons dashicons-money ee-icon-size-18"></span> |
725 | 725 | </a> |
726 | 726 | </li> |
727 | 727 | '; |
728 | - } |
|
729 | - return ''; |
|
730 | - } |
|
728 | + } |
|
729 | + return ''; |
|
730 | + } |
|
731 | 731 | } |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | $class = parent::_get_row_class($item); |
115 | 115 | // add status class |
116 | 116 | $class .= $item instanceof EE_Event |
117 | - ? ' ee-status-strip event-status-' . $item->get_active_status() |
|
117 | + ? ' ee-status-strip event-status-'.$item->get_active_status() |
|
118 | 118 | : ''; |
119 | 119 | if ($this->_has_checkbox_column) { |
120 | 120 | $class .= ' has-checkbox-column'; |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | */ |
144 | 144 | public function column_cb($item) |
145 | 145 | { |
146 | - if (! $item instanceof EE_Event) { |
|
146 | + if ( ! $item instanceof EE_Event) { |
|
147 | 147 | return ''; |
148 | 148 | } |
149 | 149 | $this->_dtt = $item->primary_datetime(); // set this for use in other columns |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | public function column_id(EE_Event $item) |
167 | 167 | { |
168 | 168 | $content = $item->ID(); |
169 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
169 | + $content .= ' <span class="show-on-mobile-view-only">'.$item->name().'</span>'; |
|
170 | 170 | return $content; |
171 | 171 | } |
172 | 172 | |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | $actions = $this->_column_name_action_setup($item); |
190 | 190 | $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
191 | 191 | $content = '<strong><a class="row-title" href="' |
192 | - . $edit_link . '">' |
|
192 | + . $edit_link.'">' |
|
193 | 193 | . $item->name() |
194 | 194 | . '</a></strong>' |
195 | 195 | . $status; |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | protected function _column_name_action_setup(EE_Event $item) |
219 | 219 | { |
220 | 220 | // todo: remove when attendees is active |
221 | - if (! defined('REG_ADMIN_URL')) { |
|
221 | + if ( ! defined('REG_ADMIN_URL')) { |
|
222 | 222 | define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
223 | 223 | } |
224 | 224 | $actions = array(); |
@@ -237,8 +237,8 @@ discard block |
||
237 | 237 | 'post' => $item->ID(), |
238 | 238 | ); |
239 | 239 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
240 | - $actions['edit'] = '<a href="' . $edit_link . '"' |
|
241 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
240 | + $actions['edit'] = '<a href="'.$edit_link.'"' |
|
241 | + . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">' |
|
242 | 242 | . esc_html__('Edit', 'event_espresso') |
243 | 243 | . '</a>'; |
244 | 244 | } |
@@ -258,8 +258,8 @@ discard block |
||
258 | 258 | 'event_id' => $item->ID(), |
259 | 259 | ); |
260 | 260 | $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
261 | - $actions['attendees'] = '<a href="' . $attendees_link . '"' |
|
262 | - . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
261 | + $actions['attendees'] = '<a href="'.$attendees_link.'"' |
|
262 | + . ' title="'.esc_attr__('View Registrations', 'event_espresso').'">' |
|
263 | 263 | . esc_html__('Registrations', 'event_espresso') |
264 | 264 | . '</a>'; |
265 | 265 | } |
@@ -312,8 +312,8 @@ discard block |
||
312 | 312 | ); |
313 | 313 | } |
314 | 314 | $view_link = get_permalink($item->ID()); |
315 | - $actions['view'] = '<a href="' . $view_link . '"' |
|
316 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
315 | + $actions['view'] = '<a href="'.$view_link.'"' |
|
316 | + . ' title="'.esc_attr__('View Event', 'event_espresso').'">' |
|
317 | 317 | . esc_html__('View', 'event_espresso') |
318 | 318 | . '</a>'; |
319 | 319 | if ($item->get('status') === 'trash') { |
@@ -324,8 +324,8 @@ discard block |
||
324 | 324 | $item->ID() |
325 | 325 | ) |
326 | 326 | ) { |
327 | - $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"' |
|
328 | - . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
327 | + $actions['restore_from_trash'] = '<a href="'.$restore_event_link.'"' |
|
328 | + . ' title="'.esc_attr__('Restore from Trash', 'event_espresso') |
|
329 | 329 | . '">' |
330 | 330 | . esc_html__('Restore from Trash', 'event_espresso') |
331 | 331 | . '</a>'; |
@@ -338,8 +338,8 @@ discard block |
||
338 | 338 | $item->ID() |
339 | 339 | ) |
340 | 340 | ) { |
341 | - $actions['delete'] = '<a href="' . $delete_event_link . '"' |
|
342 | - . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
341 | + $actions['delete'] = '<a href="'.$delete_event_link.'"' |
|
342 | + . ' title="'.esc_attr__('Delete Permanently', 'event_espresso').'">' |
|
343 | 343 | . esc_html__('Delete Permanently', 'event_espresso') |
344 | 344 | . '</a>'; |
345 | 345 | } |
@@ -351,8 +351,8 @@ discard block |
||
351 | 351 | $item->ID() |
352 | 352 | ) |
353 | 353 | ) { |
354 | - $actions['move to trash'] = '<a href="' . $trash_event_link . '"' |
|
355 | - . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
354 | + $actions['move to trash'] = '<a href="'.$trash_event_link.'"' |
|
355 | + . ' title="'.esc_attr__('Trash Event', 'event_espresso').'">' |
|
356 | 356 | . esc_html__('Trash', 'event_espresso') |
357 | 357 | . '</a>'; |
358 | 358 | } |
@@ -377,8 +377,8 @@ discard block |
||
377 | 377 | 'EVT_wp_user' => $item->wp_user(), |
378 | 378 | ); |
379 | 379 | $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
380 | - return $gravatar . ' <a href="' . $filter_url . '"' |
|
381 | - . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
380 | + return $gravatar.' <a href="'.$filter_url.'"' |
|
381 | + . ' title="'.esc_attr__('Click to filter events by this author.', 'event_espresso').'">' |
|
382 | 382 | . $event_author->display_name |
383 | 383 | . '</a>'; |
384 | 384 | } |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | return implode( |
396 | 396 | ', ', |
397 | 397 | array_map( |
398 | - function (EE_Term $category) { |
|
398 | + function(EE_Term $category) { |
|
399 | 399 | return $category->name(); |
400 | 400 | }, |
401 | 401 | $event_categories |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | 'ee_read_registrations', |
471 | 471 | 'espresso_registrations_view_registration' |
472 | 472 | ) |
473 | - ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
473 | + ? '<a href="'.$attendees_link.'">'.$registered_attendees.'</a>' |
|
474 | 474 | : $registered_attendees; |
475 | 475 | } |
476 | 476 | |
@@ -500,13 +500,13 @@ discard block |
||
500 | 500 | public function column_actions(EE_Event $item) |
501 | 501 | { |
502 | 502 | // todo: remove when attendees is active |
503 | - if (! defined('REG_ADMIN_URL')) { |
|
503 | + if ( ! defined('REG_ADMIN_URL')) { |
|
504 | 504 | define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
505 | 505 | } |
506 | 506 | $action_links = array(); |
507 | 507 | $view_link = get_permalink($item->ID()); |
508 | - $action_links[] = '<a href="' . $view_link . '"' |
|
509 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; |
|
508 | + $action_links[] = '<a href="'.$view_link.'"' |
|
509 | + . ' title="'.esc_attr__('View Event', 'event_espresso').'" target="_blank">'; |
|
510 | 510 | $action_links[] = '<div class="dashicons dashicons-search"></div></a>'; |
511 | 511 | if ( |
512 | 512 | EE_Registry::instance()->CAP->current_user_can( |
@@ -520,8 +520,8 @@ discard block |
||
520 | 520 | 'post' => $item->ID(), |
521 | 521 | ); |
522 | 522 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
523 | - $action_links[] = '<a href="' . $edit_link . '"' |
|
524 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
523 | + $action_links[] = '<a href="'.$edit_link.'"' |
|
524 | + . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">' |
|
525 | 525 | . '<div class="ee-icon ee-icon-calendar-edit"></div>' |
526 | 526 | . '</a>'; |
527 | 527 | } |
@@ -540,8 +540,8 @@ discard block |
||
540 | 540 | 'event_id' => $item->ID(), |
541 | 541 | ); |
542 | 542 | $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
543 | - $action_links[] = '<a href="' . $attendees_link . '"' |
|
544 | - . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
543 | + $action_links[] = '<a href="'.$attendees_link.'"' |
|
544 | + . ' title="'.esc_attr__('View Registrants', 'event_espresso').'">' |
|
545 | 545 | . '<div class="dashicons dashicons-groups"></div>' |
546 | 546 | . '</a>'; |
547 | 547 | } |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | } |
577 | 577 | $column_array = []; |
578 | 578 | foreach ($this->_columns as $column => $column_label) { |
579 | - $column_array[ $column ] = $column_label; |
|
579 | + $column_array[$column] = $column_label; |
|
580 | 580 | if ($column === 'venue') { |
581 | 581 | $column_array['event_category'] = esc_html__('Event Category', 'event_espresso'); |
582 | 582 | } |
@@ -15,567 +15,567 @@ |
||
15 | 15 | class Events_Admin_List_Table extends EE_Admin_List_Table |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @var EE_Datetime |
|
20 | - */ |
|
21 | - private $_dtt; |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * Initial setup of data properties for the list table. |
|
26 | - */ |
|
27 | - protected function _setup_data() |
|
28 | - { |
|
29 | - $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page); |
|
30 | - $this->_all_data_count = $this->_admin_page->get_events(0, 0, true); |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * Set up of additional properties for the list table. |
|
36 | - */ |
|
37 | - protected function _set_properties() |
|
38 | - { |
|
39 | - $this->_wp_list_args = array( |
|
40 | - 'singular' => esc_html__('event', 'event_espresso'), |
|
41 | - 'plural' => esc_html__('events', 'event_espresso'), |
|
42 | - 'ajax' => true, // for now |
|
43 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
44 | - ); |
|
45 | - $this->_columns = array( |
|
46 | - 'cb' => '<input type="checkbox" />', |
|
47 | - 'id' => esc_html__('ID', 'event_espresso'), |
|
48 | - 'name' => esc_html__('Name', 'event_espresso'), |
|
49 | - 'author' => esc_html__('Author', 'event_espresso'), |
|
50 | - 'venue' => esc_html__('Venue', 'event_espresso'), |
|
51 | - 'start_date_time' => esc_html__('Event Start', 'event_espresso'), |
|
52 | - 'reg_begins' => esc_html__('On Sale', 'event_espresso'), |
|
53 | - 'attendees' => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">' |
|
54 | - . '<span class="screen-reader-text">' |
|
55 | - . esc_html__('Approved Registrations', 'event_espresso') |
|
56 | - . '</span>' |
|
57 | - . '</span>', |
|
58 | - // 'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'), |
|
59 | - 'actions' => esc_html__('Actions', 'event_espresso'), |
|
60 | - ); |
|
61 | - $this->addConditionalColumns(); |
|
62 | - $this->_sortable_columns = array( |
|
63 | - 'id' => array('EVT_ID' => true), |
|
64 | - 'name' => array('EVT_name' => false), |
|
65 | - 'author' => array('EVT_wp_user' => false), |
|
66 | - 'venue' => array('Venue.VNU_name' => false), |
|
67 | - 'start_date_time' => array('Datetime.DTT_EVT_start' => false), |
|
68 | - 'reg_begins' => array('Datetime.Ticket.TKT_start_date' => false), |
|
69 | - ); |
|
70 | - |
|
71 | - $this->_primary_column = 'id'; |
|
72 | - $this->_hidden_columns = array('author', 'event_category'); |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * @return array |
|
78 | - */ |
|
79 | - protected function _get_table_filters() |
|
80 | - { |
|
81 | - return array(); // no filters with decaf |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * Setup of views properties. |
|
87 | - * |
|
88 | - * @throws InvalidDataTypeException |
|
89 | - * @throws InvalidInterfaceException |
|
90 | - * @throws InvalidArgumentException |
|
91 | - */ |
|
92 | - protected function _add_view_counts() |
|
93 | - { |
|
94 | - $this->_views['all']['count'] = $this->_admin_page->total_events(); |
|
95 | - $this->_views['draft']['count'] = $this->_admin_page->total_events_draft(); |
|
96 | - if ( |
|
97 | - EE_Registry::instance()->CAP->current_user_can( |
|
98 | - 'ee_delete_events', |
|
99 | - 'espresso_events_trash_events' |
|
100 | - ) |
|
101 | - ) { |
|
102 | - $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events(); |
|
103 | - } |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * @param EE_Event $item |
|
109 | - * @return string |
|
110 | - * @throws EE_Error |
|
111 | - */ |
|
112 | - protected function _get_row_class($item) |
|
113 | - { |
|
114 | - $class = parent::_get_row_class($item); |
|
115 | - // add status class |
|
116 | - $class .= $item instanceof EE_Event |
|
117 | - ? ' ee-status-strip event-status-' . $item->get_active_status() |
|
118 | - : ''; |
|
119 | - if ($this->_has_checkbox_column) { |
|
120 | - $class .= ' has-checkbox-column'; |
|
121 | - } |
|
122 | - return $class; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @param EE_Event $item |
|
128 | - * @return string |
|
129 | - * @throws EE_Error |
|
130 | - */ |
|
131 | - public function column_status(EE_Event $item) |
|
132 | - { |
|
133 | - return '<span class="ee-status-strip ee-status-strip-td event-status-' |
|
134 | - . $item->get_active_status() |
|
135 | - . '"></span>'; |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @param EE_Event $item |
|
141 | - * @return string |
|
142 | - * @throws EE_Error |
|
143 | - */ |
|
144 | - public function column_cb($item) |
|
145 | - { |
|
146 | - if (! $item instanceof EE_Event) { |
|
147 | - return ''; |
|
148 | - } |
|
149 | - $this->_dtt = $item->primary_datetime(); // set this for use in other columns |
|
150 | - return sprintf( |
|
151 | - '<input type="checkbox" name="EVT_IDs[]" value="%s" />', |
|
152 | - $item->ID() |
|
153 | - ); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * @param EE_Event $item |
|
159 | - * @return mixed|string |
|
160 | - * @throws EE_Error |
|
161 | - */ |
|
162 | - public function column_id(EE_Event $item) |
|
163 | - { |
|
164 | - $content = $item->ID(); |
|
165 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
166 | - return $content; |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * @param EE_Event $item |
|
172 | - * @return string |
|
173 | - * @throws EE_Error |
|
174 | - * @throws InvalidArgumentException |
|
175 | - * @throws InvalidDataTypeException |
|
176 | - * @throws InvalidInterfaceException |
|
177 | - */ |
|
178 | - public function column_name(EE_Event $item) |
|
179 | - { |
|
180 | - $edit_query_args = array( |
|
181 | - 'action' => 'edit', |
|
182 | - 'post' => $item->ID(), |
|
183 | - ); |
|
184 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
185 | - $actions = $this->_column_name_action_setup($item); |
|
186 | - $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
|
187 | - $content = '<strong><a class="row-title" href="' |
|
188 | - . $edit_link . '">' |
|
189 | - . $item->name() |
|
190 | - . '</a></strong>' |
|
191 | - . $status; |
|
192 | - $content .= '<br><span class="ee-status-text-small">' |
|
193 | - . EEH_Template::pretty_status( |
|
194 | - $item->get_active_status(), |
|
195 | - false, |
|
196 | - 'sentence' |
|
197 | - ) |
|
198 | - . '</span>'; |
|
199 | - $content .= $this->row_actions($actions); |
|
200 | - return $content; |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * Just a method for setting up the actions for the name column |
|
206 | - * |
|
207 | - * @param EE_Event $item |
|
208 | - * @return array array of actions |
|
209 | - * @throws EE_Error |
|
210 | - * @throws InvalidArgumentException |
|
211 | - * @throws InvalidDataTypeException |
|
212 | - * @throws InvalidInterfaceException |
|
213 | - */ |
|
214 | - protected function _column_name_action_setup(EE_Event $item) |
|
215 | - { |
|
216 | - // todo: remove when attendees is active |
|
217 | - if (! defined('REG_ADMIN_URL')) { |
|
218 | - define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
219 | - } |
|
220 | - $actions = array(); |
|
221 | - $restore_event_link = ''; |
|
222 | - $delete_event_link = ''; |
|
223 | - $trash_event_link = ''; |
|
224 | - if ( |
|
225 | - EE_Registry::instance()->CAP->current_user_can( |
|
226 | - 'ee_edit_event', |
|
227 | - 'espresso_events_edit', |
|
228 | - $item->ID() |
|
229 | - ) |
|
230 | - ) { |
|
231 | - $edit_query_args = array( |
|
232 | - 'action' => 'edit', |
|
233 | - 'post' => $item->ID(), |
|
234 | - ); |
|
235 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
236 | - $actions['edit'] = '<a href="' . $edit_link . '"' |
|
237 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
238 | - . esc_html__('Edit', 'event_espresso') |
|
239 | - . '</a>'; |
|
240 | - } |
|
241 | - if ( |
|
242 | - EE_Registry::instance()->CAP->current_user_can( |
|
243 | - 'ee_read_registrations', |
|
244 | - 'espresso_registrations_view_registration' |
|
245 | - ) |
|
246 | - && EE_Registry::instance()->CAP->current_user_can( |
|
247 | - 'ee_read_event', |
|
248 | - 'espresso_registrations_view_registration', |
|
249 | - $item->ID() |
|
250 | - ) |
|
251 | - ) { |
|
252 | - $attendees_query_args = array( |
|
253 | - 'action' => 'default', |
|
254 | - 'event_id' => $item->ID(), |
|
255 | - ); |
|
256 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
257 | - $actions['attendees'] = '<a href="' . $attendees_link . '"' |
|
258 | - . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
259 | - . esc_html__('Registrations', 'event_espresso') |
|
260 | - . '</a>'; |
|
261 | - } |
|
262 | - if ( |
|
263 | - EE_Registry::instance()->CAP->current_user_can( |
|
264 | - 'ee_delete_event', |
|
265 | - 'espresso_events_trash_event', |
|
266 | - $item->ID() |
|
267 | - ) |
|
268 | - ) { |
|
269 | - $trash_event_query_args = array( |
|
270 | - 'action' => 'trash_event', |
|
271 | - 'EVT_ID' => $item->ID(), |
|
272 | - ); |
|
273 | - $trash_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
274 | - $trash_event_query_args, |
|
275 | - EVENTS_ADMIN_URL |
|
276 | - ); |
|
277 | - } |
|
278 | - if ( |
|
279 | - EE_Registry::instance()->CAP->current_user_can( |
|
280 | - 'ee_delete_event', |
|
281 | - 'espresso_events_restore_event', |
|
282 | - $item->ID() |
|
283 | - ) |
|
284 | - ) { |
|
285 | - $restore_event_query_args = array( |
|
286 | - 'action' => 'restore_event', |
|
287 | - 'EVT_ID' => $item->ID(), |
|
288 | - ); |
|
289 | - $restore_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
290 | - $restore_event_query_args, |
|
291 | - EVENTS_ADMIN_URL |
|
292 | - ); |
|
293 | - } |
|
294 | - if ( |
|
295 | - EE_Registry::instance()->CAP->current_user_can( |
|
296 | - 'ee_delete_event', |
|
297 | - 'espresso_events_delete_event', |
|
298 | - $item->ID() |
|
299 | - ) |
|
300 | - ) { |
|
301 | - $delete_event_query_args = array( |
|
302 | - 'action' => 'delete_event', |
|
303 | - 'EVT_ID' => $item->ID(), |
|
304 | - ); |
|
305 | - $delete_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
306 | - $delete_event_query_args, |
|
307 | - EVENTS_ADMIN_URL |
|
308 | - ); |
|
309 | - } |
|
310 | - $view_link = get_permalink($item->ID()); |
|
311 | - $actions['view'] = '<a href="' . $view_link . '"' |
|
312 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
313 | - . esc_html__('View', 'event_espresso') |
|
314 | - . '</a>'; |
|
315 | - if ($item->get('status') === 'trash') { |
|
316 | - if ( |
|
317 | - EE_Registry::instance()->CAP->current_user_can( |
|
318 | - 'ee_delete_event', |
|
319 | - 'espresso_events_restore_event', |
|
320 | - $item->ID() |
|
321 | - ) |
|
322 | - ) { |
|
323 | - $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"' |
|
324 | - . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
325 | - . '">' |
|
326 | - . esc_html__('Restore from Trash', 'event_espresso') |
|
327 | - . '</a>'; |
|
328 | - } |
|
329 | - if ( |
|
330 | - EE_Registry::instance()->CAP->current_user_can( |
|
331 | - 'ee_delete_event', |
|
332 | - 'espresso_events_delete_event', |
|
333 | - $item->ID() |
|
334 | - ) |
|
335 | - ) { |
|
336 | - $actions['delete'] = '<a href="' . $delete_event_link . '"' |
|
337 | - . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
338 | - . esc_html__('Delete Permanently', 'event_espresso') |
|
339 | - . '</a>'; |
|
340 | - } |
|
341 | - } else { |
|
342 | - if ( |
|
343 | - EE_Registry::instance()->CAP->current_user_can( |
|
344 | - 'ee_delete_event', |
|
345 | - 'espresso_events_trash_event', |
|
346 | - $item->ID() |
|
347 | - ) |
|
348 | - ) { |
|
349 | - $actions['move to trash'] = '<a href="' . $trash_event_link . '"' |
|
350 | - . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
351 | - . esc_html__('Trash', 'event_espresso') |
|
352 | - . '</a>'; |
|
353 | - } |
|
354 | - } |
|
355 | - return $actions; |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * @param EE_Event $item |
|
361 | - * @return string |
|
362 | - * @throws EE_Error |
|
363 | - */ |
|
364 | - public function column_author(EE_Event $item) |
|
365 | - { |
|
366 | - // user author info |
|
367 | - $event_author = get_userdata($item->wp_user()); |
|
368 | - $gravatar = get_avatar($item->wp_user(), '15'); |
|
369 | - // filter link |
|
370 | - $query_args = array( |
|
371 | - 'action' => 'default', |
|
372 | - 'EVT_wp_user' => $item->wp_user(), |
|
373 | - ); |
|
374 | - $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
|
375 | - return $gravatar . ' <a href="' . $filter_url . '"' |
|
376 | - . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
377 | - . $event_author->display_name |
|
378 | - . '</a>'; |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * @param EE_Event $event |
|
384 | - * @return string |
|
385 | - * @throws EE_Error |
|
386 | - */ |
|
387 | - public function column_event_category(EE_Event $event) |
|
388 | - { |
|
389 | - $event_categories = $event->get_all_event_categories(); |
|
390 | - return implode( |
|
391 | - ', ', |
|
392 | - array_map( |
|
393 | - function (EE_Term $category) { |
|
394 | - return $category->name(); |
|
395 | - }, |
|
396 | - $event_categories |
|
397 | - ) |
|
398 | - ); |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - /** |
|
403 | - * @param EE_Event $item |
|
404 | - * @return string |
|
405 | - * @throws EE_Error |
|
406 | - */ |
|
407 | - public function column_venue(EE_Event $item) |
|
408 | - { |
|
409 | - $venue = $item->get_first_related('Venue'); |
|
410 | - return ! empty($venue) |
|
411 | - ? $venue->name() |
|
412 | - : ''; |
|
413 | - } |
|
414 | - |
|
415 | - |
|
416 | - /** |
|
417 | - * @param EE_Event $item |
|
418 | - * @return string |
|
419 | - * @throws EE_Error |
|
420 | - */ |
|
421 | - public function column_start_date_time(EE_Event $item) |
|
422 | - { |
|
423 | - return $this->_dtt instanceof EE_Datetime |
|
424 | - ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') |
|
425 | - : esc_html__('No Date was saved for this Event', 'event_espresso'); |
|
426 | - } |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * @param EE_Event $item |
|
431 | - * @return string |
|
432 | - * @throws EE_Error |
|
433 | - */ |
|
434 | - public function column_reg_begins(EE_Event $item) |
|
435 | - { |
|
436 | - $reg_start = $item->get_ticket_with_earliest_start_time(); |
|
437 | - return $reg_start instanceof EE_Ticket |
|
438 | - ? $reg_start->get_i18n_datetime('TKT_start_date') |
|
439 | - : esc_html__('No Tickets have been setup for this Event', 'event_espresso'); |
|
440 | - } |
|
441 | - |
|
442 | - |
|
443 | - /** |
|
444 | - * @param EE_Event $item |
|
445 | - * @return int|string |
|
446 | - * @throws EE_Error |
|
447 | - * @throws InvalidArgumentException |
|
448 | - * @throws InvalidDataTypeException |
|
449 | - * @throws InvalidInterfaceException |
|
450 | - */ |
|
451 | - public function column_attendees(EE_Event $item) |
|
452 | - { |
|
453 | - $attendees_query_args = array( |
|
454 | - 'action' => 'default', |
|
455 | - 'event_id' => $item->ID(), |
|
456 | - ); |
|
457 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
458 | - $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID()); |
|
459 | - return EE_Registry::instance()->CAP->current_user_can( |
|
460 | - 'ee_read_event', |
|
461 | - 'espresso_registrations_view_registration', |
|
462 | - $item->ID() |
|
463 | - ) |
|
464 | - && EE_Registry::instance()->CAP->current_user_can( |
|
465 | - 'ee_read_registrations', |
|
466 | - 'espresso_registrations_view_registration' |
|
467 | - ) |
|
468 | - ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
469 | - : $registered_attendees; |
|
470 | - } |
|
471 | - |
|
472 | - |
|
473 | - /** |
|
474 | - * @param EE_Event $item |
|
475 | - * @return float |
|
476 | - * @throws EE_Error |
|
477 | - * @throws InvalidArgumentException |
|
478 | - * @throws InvalidDataTypeException |
|
479 | - * @throws InvalidInterfaceException |
|
480 | - */ |
|
481 | - public function column_tkts_sold(EE_Event $item) |
|
482 | - { |
|
483 | - return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold'); |
|
484 | - } |
|
485 | - |
|
486 | - |
|
487 | - /** |
|
488 | - * @param EE_Event $item |
|
489 | - * @return string |
|
490 | - * @throws EE_Error |
|
491 | - * @throws InvalidArgumentException |
|
492 | - * @throws InvalidDataTypeException |
|
493 | - * @throws InvalidInterfaceException |
|
494 | - */ |
|
495 | - public function column_actions(EE_Event $item) |
|
496 | - { |
|
497 | - // todo: remove when attendees is active |
|
498 | - if (! defined('REG_ADMIN_URL')) { |
|
499 | - define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
500 | - } |
|
501 | - $action_links = array(); |
|
502 | - $view_link = get_permalink($item->ID()); |
|
503 | - $action_links[] = '<a href="' . $view_link . '"' |
|
504 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; |
|
505 | - $action_links[] = '<div class="dashicons dashicons-search"></div></a>'; |
|
506 | - if ( |
|
507 | - EE_Registry::instance()->CAP->current_user_can( |
|
508 | - 'ee_edit_event', |
|
509 | - 'espresso_events_edit', |
|
510 | - $item->ID() |
|
511 | - ) |
|
512 | - ) { |
|
513 | - $edit_query_args = array( |
|
514 | - 'action' => 'edit', |
|
515 | - 'post' => $item->ID(), |
|
516 | - ); |
|
517 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
518 | - $action_links[] = '<a href="' . $edit_link . '"' |
|
519 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
520 | - . '<div class="ee-icon ee-icon-calendar-edit"></div>' |
|
521 | - . '</a>'; |
|
522 | - } |
|
523 | - if ( |
|
524 | - EE_Registry::instance()->CAP->current_user_can( |
|
525 | - 'ee_read_registrations', |
|
526 | - 'espresso_registrations_view_registration' |
|
527 | - ) && EE_Registry::instance()->CAP->current_user_can( |
|
528 | - 'ee_read_event', |
|
529 | - 'espresso_registrations_view_registration', |
|
530 | - $item->ID() |
|
531 | - ) |
|
532 | - ) { |
|
533 | - $attendees_query_args = array( |
|
534 | - 'action' => 'default', |
|
535 | - 'event_id' => $item->ID(), |
|
536 | - ); |
|
537 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
538 | - $action_links[] = '<a href="' . $attendees_link . '"' |
|
539 | - . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
540 | - . '<div class="dashicons dashicons-groups"></div>' |
|
541 | - . '</a>'; |
|
542 | - } |
|
543 | - $action_links = apply_filters( |
|
544 | - 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
545 | - $action_links, |
|
546 | - $item |
|
547 | - ); |
|
548 | - return $this->_action_string( |
|
549 | - implode("\n\t", $action_links), |
|
550 | - $item, |
|
551 | - 'div' |
|
552 | - ); |
|
553 | - } |
|
554 | - |
|
555 | - |
|
556 | - /** |
|
557 | - * Helper for adding columns conditionally |
|
558 | - * |
|
559 | - * @throws EE_Error |
|
560 | - * @throws InvalidArgumentException |
|
561 | - * @throws InvalidDataTypeException |
|
562 | - * @throws InvalidInterfaceException |
|
563 | - */ |
|
564 | - private function addConditionalColumns() |
|
565 | - { |
|
566 | - $event_category_count = EEM_Term::instance()->count( |
|
567 | - [['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]] |
|
568 | - ); |
|
569 | - if ($event_category_count === 0) { |
|
570 | - return; |
|
571 | - } |
|
572 | - $column_array = []; |
|
573 | - foreach ($this->_columns as $column => $column_label) { |
|
574 | - $column_array[ $column ] = $column_label; |
|
575 | - if ($column === 'venue') { |
|
576 | - $column_array['event_category'] = esc_html__('Event Category', 'event_espresso'); |
|
577 | - } |
|
578 | - } |
|
579 | - $this->_columns = $column_array; |
|
580 | - } |
|
18 | + /** |
|
19 | + * @var EE_Datetime |
|
20 | + */ |
|
21 | + private $_dtt; |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * Initial setup of data properties for the list table. |
|
26 | + */ |
|
27 | + protected function _setup_data() |
|
28 | + { |
|
29 | + $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page); |
|
30 | + $this->_all_data_count = $this->_admin_page->get_events(0, 0, true); |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * Set up of additional properties for the list table. |
|
36 | + */ |
|
37 | + protected function _set_properties() |
|
38 | + { |
|
39 | + $this->_wp_list_args = array( |
|
40 | + 'singular' => esc_html__('event', 'event_espresso'), |
|
41 | + 'plural' => esc_html__('events', 'event_espresso'), |
|
42 | + 'ajax' => true, // for now |
|
43 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
44 | + ); |
|
45 | + $this->_columns = array( |
|
46 | + 'cb' => '<input type="checkbox" />', |
|
47 | + 'id' => esc_html__('ID', 'event_espresso'), |
|
48 | + 'name' => esc_html__('Name', 'event_espresso'), |
|
49 | + 'author' => esc_html__('Author', 'event_espresso'), |
|
50 | + 'venue' => esc_html__('Venue', 'event_espresso'), |
|
51 | + 'start_date_time' => esc_html__('Event Start', 'event_espresso'), |
|
52 | + 'reg_begins' => esc_html__('On Sale', 'event_espresso'), |
|
53 | + 'attendees' => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">' |
|
54 | + . '<span class="screen-reader-text">' |
|
55 | + . esc_html__('Approved Registrations', 'event_espresso') |
|
56 | + . '</span>' |
|
57 | + . '</span>', |
|
58 | + // 'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'), |
|
59 | + 'actions' => esc_html__('Actions', 'event_espresso'), |
|
60 | + ); |
|
61 | + $this->addConditionalColumns(); |
|
62 | + $this->_sortable_columns = array( |
|
63 | + 'id' => array('EVT_ID' => true), |
|
64 | + 'name' => array('EVT_name' => false), |
|
65 | + 'author' => array('EVT_wp_user' => false), |
|
66 | + 'venue' => array('Venue.VNU_name' => false), |
|
67 | + 'start_date_time' => array('Datetime.DTT_EVT_start' => false), |
|
68 | + 'reg_begins' => array('Datetime.Ticket.TKT_start_date' => false), |
|
69 | + ); |
|
70 | + |
|
71 | + $this->_primary_column = 'id'; |
|
72 | + $this->_hidden_columns = array('author', 'event_category'); |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * @return array |
|
78 | + */ |
|
79 | + protected function _get_table_filters() |
|
80 | + { |
|
81 | + return array(); // no filters with decaf |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * Setup of views properties. |
|
87 | + * |
|
88 | + * @throws InvalidDataTypeException |
|
89 | + * @throws InvalidInterfaceException |
|
90 | + * @throws InvalidArgumentException |
|
91 | + */ |
|
92 | + protected function _add_view_counts() |
|
93 | + { |
|
94 | + $this->_views['all']['count'] = $this->_admin_page->total_events(); |
|
95 | + $this->_views['draft']['count'] = $this->_admin_page->total_events_draft(); |
|
96 | + if ( |
|
97 | + EE_Registry::instance()->CAP->current_user_can( |
|
98 | + 'ee_delete_events', |
|
99 | + 'espresso_events_trash_events' |
|
100 | + ) |
|
101 | + ) { |
|
102 | + $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events(); |
|
103 | + } |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * @param EE_Event $item |
|
109 | + * @return string |
|
110 | + * @throws EE_Error |
|
111 | + */ |
|
112 | + protected function _get_row_class($item) |
|
113 | + { |
|
114 | + $class = parent::_get_row_class($item); |
|
115 | + // add status class |
|
116 | + $class .= $item instanceof EE_Event |
|
117 | + ? ' ee-status-strip event-status-' . $item->get_active_status() |
|
118 | + : ''; |
|
119 | + if ($this->_has_checkbox_column) { |
|
120 | + $class .= ' has-checkbox-column'; |
|
121 | + } |
|
122 | + return $class; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @param EE_Event $item |
|
128 | + * @return string |
|
129 | + * @throws EE_Error |
|
130 | + */ |
|
131 | + public function column_status(EE_Event $item) |
|
132 | + { |
|
133 | + return '<span class="ee-status-strip ee-status-strip-td event-status-' |
|
134 | + . $item->get_active_status() |
|
135 | + . '"></span>'; |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @param EE_Event $item |
|
141 | + * @return string |
|
142 | + * @throws EE_Error |
|
143 | + */ |
|
144 | + public function column_cb($item) |
|
145 | + { |
|
146 | + if (! $item instanceof EE_Event) { |
|
147 | + return ''; |
|
148 | + } |
|
149 | + $this->_dtt = $item->primary_datetime(); // set this for use in other columns |
|
150 | + return sprintf( |
|
151 | + '<input type="checkbox" name="EVT_IDs[]" value="%s" />', |
|
152 | + $item->ID() |
|
153 | + ); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * @param EE_Event $item |
|
159 | + * @return mixed|string |
|
160 | + * @throws EE_Error |
|
161 | + */ |
|
162 | + public function column_id(EE_Event $item) |
|
163 | + { |
|
164 | + $content = $item->ID(); |
|
165 | + $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
166 | + return $content; |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * @param EE_Event $item |
|
172 | + * @return string |
|
173 | + * @throws EE_Error |
|
174 | + * @throws InvalidArgumentException |
|
175 | + * @throws InvalidDataTypeException |
|
176 | + * @throws InvalidInterfaceException |
|
177 | + */ |
|
178 | + public function column_name(EE_Event $item) |
|
179 | + { |
|
180 | + $edit_query_args = array( |
|
181 | + 'action' => 'edit', |
|
182 | + 'post' => $item->ID(), |
|
183 | + ); |
|
184 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
185 | + $actions = $this->_column_name_action_setup($item); |
|
186 | + $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
|
187 | + $content = '<strong><a class="row-title" href="' |
|
188 | + . $edit_link . '">' |
|
189 | + . $item->name() |
|
190 | + . '</a></strong>' |
|
191 | + . $status; |
|
192 | + $content .= '<br><span class="ee-status-text-small">' |
|
193 | + . EEH_Template::pretty_status( |
|
194 | + $item->get_active_status(), |
|
195 | + false, |
|
196 | + 'sentence' |
|
197 | + ) |
|
198 | + . '</span>'; |
|
199 | + $content .= $this->row_actions($actions); |
|
200 | + return $content; |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * Just a method for setting up the actions for the name column |
|
206 | + * |
|
207 | + * @param EE_Event $item |
|
208 | + * @return array array of actions |
|
209 | + * @throws EE_Error |
|
210 | + * @throws InvalidArgumentException |
|
211 | + * @throws InvalidDataTypeException |
|
212 | + * @throws InvalidInterfaceException |
|
213 | + */ |
|
214 | + protected function _column_name_action_setup(EE_Event $item) |
|
215 | + { |
|
216 | + // todo: remove when attendees is active |
|
217 | + if (! defined('REG_ADMIN_URL')) { |
|
218 | + define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
219 | + } |
|
220 | + $actions = array(); |
|
221 | + $restore_event_link = ''; |
|
222 | + $delete_event_link = ''; |
|
223 | + $trash_event_link = ''; |
|
224 | + if ( |
|
225 | + EE_Registry::instance()->CAP->current_user_can( |
|
226 | + 'ee_edit_event', |
|
227 | + 'espresso_events_edit', |
|
228 | + $item->ID() |
|
229 | + ) |
|
230 | + ) { |
|
231 | + $edit_query_args = array( |
|
232 | + 'action' => 'edit', |
|
233 | + 'post' => $item->ID(), |
|
234 | + ); |
|
235 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
236 | + $actions['edit'] = '<a href="' . $edit_link . '"' |
|
237 | + . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
238 | + . esc_html__('Edit', 'event_espresso') |
|
239 | + . '</a>'; |
|
240 | + } |
|
241 | + if ( |
|
242 | + EE_Registry::instance()->CAP->current_user_can( |
|
243 | + 'ee_read_registrations', |
|
244 | + 'espresso_registrations_view_registration' |
|
245 | + ) |
|
246 | + && EE_Registry::instance()->CAP->current_user_can( |
|
247 | + 'ee_read_event', |
|
248 | + 'espresso_registrations_view_registration', |
|
249 | + $item->ID() |
|
250 | + ) |
|
251 | + ) { |
|
252 | + $attendees_query_args = array( |
|
253 | + 'action' => 'default', |
|
254 | + 'event_id' => $item->ID(), |
|
255 | + ); |
|
256 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
257 | + $actions['attendees'] = '<a href="' . $attendees_link . '"' |
|
258 | + . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
259 | + . esc_html__('Registrations', 'event_espresso') |
|
260 | + . '</a>'; |
|
261 | + } |
|
262 | + if ( |
|
263 | + EE_Registry::instance()->CAP->current_user_can( |
|
264 | + 'ee_delete_event', |
|
265 | + 'espresso_events_trash_event', |
|
266 | + $item->ID() |
|
267 | + ) |
|
268 | + ) { |
|
269 | + $trash_event_query_args = array( |
|
270 | + 'action' => 'trash_event', |
|
271 | + 'EVT_ID' => $item->ID(), |
|
272 | + ); |
|
273 | + $trash_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
274 | + $trash_event_query_args, |
|
275 | + EVENTS_ADMIN_URL |
|
276 | + ); |
|
277 | + } |
|
278 | + if ( |
|
279 | + EE_Registry::instance()->CAP->current_user_can( |
|
280 | + 'ee_delete_event', |
|
281 | + 'espresso_events_restore_event', |
|
282 | + $item->ID() |
|
283 | + ) |
|
284 | + ) { |
|
285 | + $restore_event_query_args = array( |
|
286 | + 'action' => 'restore_event', |
|
287 | + 'EVT_ID' => $item->ID(), |
|
288 | + ); |
|
289 | + $restore_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
290 | + $restore_event_query_args, |
|
291 | + EVENTS_ADMIN_URL |
|
292 | + ); |
|
293 | + } |
|
294 | + if ( |
|
295 | + EE_Registry::instance()->CAP->current_user_can( |
|
296 | + 'ee_delete_event', |
|
297 | + 'espresso_events_delete_event', |
|
298 | + $item->ID() |
|
299 | + ) |
|
300 | + ) { |
|
301 | + $delete_event_query_args = array( |
|
302 | + 'action' => 'delete_event', |
|
303 | + 'EVT_ID' => $item->ID(), |
|
304 | + ); |
|
305 | + $delete_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
306 | + $delete_event_query_args, |
|
307 | + EVENTS_ADMIN_URL |
|
308 | + ); |
|
309 | + } |
|
310 | + $view_link = get_permalink($item->ID()); |
|
311 | + $actions['view'] = '<a href="' . $view_link . '"' |
|
312 | + . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
313 | + . esc_html__('View', 'event_espresso') |
|
314 | + . '</a>'; |
|
315 | + if ($item->get('status') === 'trash') { |
|
316 | + if ( |
|
317 | + EE_Registry::instance()->CAP->current_user_can( |
|
318 | + 'ee_delete_event', |
|
319 | + 'espresso_events_restore_event', |
|
320 | + $item->ID() |
|
321 | + ) |
|
322 | + ) { |
|
323 | + $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"' |
|
324 | + . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
325 | + . '">' |
|
326 | + . esc_html__('Restore from Trash', 'event_espresso') |
|
327 | + . '</a>'; |
|
328 | + } |
|
329 | + if ( |
|
330 | + EE_Registry::instance()->CAP->current_user_can( |
|
331 | + 'ee_delete_event', |
|
332 | + 'espresso_events_delete_event', |
|
333 | + $item->ID() |
|
334 | + ) |
|
335 | + ) { |
|
336 | + $actions['delete'] = '<a href="' . $delete_event_link . '"' |
|
337 | + . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
338 | + . esc_html__('Delete Permanently', 'event_espresso') |
|
339 | + . '</a>'; |
|
340 | + } |
|
341 | + } else { |
|
342 | + if ( |
|
343 | + EE_Registry::instance()->CAP->current_user_can( |
|
344 | + 'ee_delete_event', |
|
345 | + 'espresso_events_trash_event', |
|
346 | + $item->ID() |
|
347 | + ) |
|
348 | + ) { |
|
349 | + $actions['move to trash'] = '<a href="' . $trash_event_link . '"' |
|
350 | + . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
351 | + . esc_html__('Trash', 'event_espresso') |
|
352 | + . '</a>'; |
|
353 | + } |
|
354 | + } |
|
355 | + return $actions; |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * @param EE_Event $item |
|
361 | + * @return string |
|
362 | + * @throws EE_Error |
|
363 | + */ |
|
364 | + public function column_author(EE_Event $item) |
|
365 | + { |
|
366 | + // user author info |
|
367 | + $event_author = get_userdata($item->wp_user()); |
|
368 | + $gravatar = get_avatar($item->wp_user(), '15'); |
|
369 | + // filter link |
|
370 | + $query_args = array( |
|
371 | + 'action' => 'default', |
|
372 | + 'EVT_wp_user' => $item->wp_user(), |
|
373 | + ); |
|
374 | + $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
|
375 | + return $gravatar . ' <a href="' . $filter_url . '"' |
|
376 | + . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
377 | + . $event_author->display_name |
|
378 | + . '</a>'; |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * @param EE_Event $event |
|
384 | + * @return string |
|
385 | + * @throws EE_Error |
|
386 | + */ |
|
387 | + public function column_event_category(EE_Event $event) |
|
388 | + { |
|
389 | + $event_categories = $event->get_all_event_categories(); |
|
390 | + return implode( |
|
391 | + ', ', |
|
392 | + array_map( |
|
393 | + function (EE_Term $category) { |
|
394 | + return $category->name(); |
|
395 | + }, |
|
396 | + $event_categories |
|
397 | + ) |
|
398 | + ); |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + /** |
|
403 | + * @param EE_Event $item |
|
404 | + * @return string |
|
405 | + * @throws EE_Error |
|
406 | + */ |
|
407 | + public function column_venue(EE_Event $item) |
|
408 | + { |
|
409 | + $venue = $item->get_first_related('Venue'); |
|
410 | + return ! empty($venue) |
|
411 | + ? $venue->name() |
|
412 | + : ''; |
|
413 | + } |
|
414 | + |
|
415 | + |
|
416 | + /** |
|
417 | + * @param EE_Event $item |
|
418 | + * @return string |
|
419 | + * @throws EE_Error |
|
420 | + */ |
|
421 | + public function column_start_date_time(EE_Event $item) |
|
422 | + { |
|
423 | + return $this->_dtt instanceof EE_Datetime |
|
424 | + ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') |
|
425 | + : esc_html__('No Date was saved for this Event', 'event_espresso'); |
|
426 | + } |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * @param EE_Event $item |
|
431 | + * @return string |
|
432 | + * @throws EE_Error |
|
433 | + */ |
|
434 | + public function column_reg_begins(EE_Event $item) |
|
435 | + { |
|
436 | + $reg_start = $item->get_ticket_with_earliest_start_time(); |
|
437 | + return $reg_start instanceof EE_Ticket |
|
438 | + ? $reg_start->get_i18n_datetime('TKT_start_date') |
|
439 | + : esc_html__('No Tickets have been setup for this Event', 'event_espresso'); |
|
440 | + } |
|
441 | + |
|
442 | + |
|
443 | + /** |
|
444 | + * @param EE_Event $item |
|
445 | + * @return int|string |
|
446 | + * @throws EE_Error |
|
447 | + * @throws InvalidArgumentException |
|
448 | + * @throws InvalidDataTypeException |
|
449 | + * @throws InvalidInterfaceException |
|
450 | + */ |
|
451 | + public function column_attendees(EE_Event $item) |
|
452 | + { |
|
453 | + $attendees_query_args = array( |
|
454 | + 'action' => 'default', |
|
455 | + 'event_id' => $item->ID(), |
|
456 | + ); |
|
457 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
458 | + $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID()); |
|
459 | + return EE_Registry::instance()->CAP->current_user_can( |
|
460 | + 'ee_read_event', |
|
461 | + 'espresso_registrations_view_registration', |
|
462 | + $item->ID() |
|
463 | + ) |
|
464 | + && EE_Registry::instance()->CAP->current_user_can( |
|
465 | + 'ee_read_registrations', |
|
466 | + 'espresso_registrations_view_registration' |
|
467 | + ) |
|
468 | + ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
469 | + : $registered_attendees; |
|
470 | + } |
|
471 | + |
|
472 | + |
|
473 | + /** |
|
474 | + * @param EE_Event $item |
|
475 | + * @return float |
|
476 | + * @throws EE_Error |
|
477 | + * @throws InvalidArgumentException |
|
478 | + * @throws InvalidDataTypeException |
|
479 | + * @throws InvalidInterfaceException |
|
480 | + */ |
|
481 | + public function column_tkts_sold(EE_Event $item) |
|
482 | + { |
|
483 | + return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold'); |
|
484 | + } |
|
485 | + |
|
486 | + |
|
487 | + /** |
|
488 | + * @param EE_Event $item |
|
489 | + * @return string |
|
490 | + * @throws EE_Error |
|
491 | + * @throws InvalidArgumentException |
|
492 | + * @throws InvalidDataTypeException |
|
493 | + * @throws InvalidInterfaceException |
|
494 | + */ |
|
495 | + public function column_actions(EE_Event $item) |
|
496 | + { |
|
497 | + // todo: remove when attendees is active |
|
498 | + if (! defined('REG_ADMIN_URL')) { |
|
499 | + define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
500 | + } |
|
501 | + $action_links = array(); |
|
502 | + $view_link = get_permalink($item->ID()); |
|
503 | + $action_links[] = '<a href="' . $view_link . '"' |
|
504 | + . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; |
|
505 | + $action_links[] = '<div class="dashicons dashicons-search"></div></a>'; |
|
506 | + if ( |
|
507 | + EE_Registry::instance()->CAP->current_user_can( |
|
508 | + 'ee_edit_event', |
|
509 | + 'espresso_events_edit', |
|
510 | + $item->ID() |
|
511 | + ) |
|
512 | + ) { |
|
513 | + $edit_query_args = array( |
|
514 | + 'action' => 'edit', |
|
515 | + 'post' => $item->ID(), |
|
516 | + ); |
|
517 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
518 | + $action_links[] = '<a href="' . $edit_link . '"' |
|
519 | + . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
520 | + . '<div class="ee-icon ee-icon-calendar-edit"></div>' |
|
521 | + . '</a>'; |
|
522 | + } |
|
523 | + if ( |
|
524 | + EE_Registry::instance()->CAP->current_user_can( |
|
525 | + 'ee_read_registrations', |
|
526 | + 'espresso_registrations_view_registration' |
|
527 | + ) && EE_Registry::instance()->CAP->current_user_can( |
|
528 | + 'ee_read_event', |
|
529 | + 'espresso_registrations_view_registration', |
|
530 | + $item->ID() |
|
531 | + ) |
|
532 | + ) { |
|
533 | + $attendees_query_args = array( |
|
534 | + 'action' => 'default', |
|
535 | + 'event_id' => $item->ID(), |
|
536 | + ); |
|
537 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
538 | + $action_links[] = '<a href="' . $attendees_link . '"' |
|
539 | + . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
540 | + . '<div class="dashicons dashicons-groups"></div>' |
|
541 | + . '</a>'; |
|
542 | + } |
|
543 | + $action_links = apply_filters( |
|
544 | + 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
545 | + $action_links, |
|
546 | + $item |
|
547 | + ); |
|
548 | + return $this->_action_string( |
|
549 | + implode("\n\t", $action_links), |
|
550 | + $item, |
|
551 | + 'div' |
|
552 | + ); |
|
553 | + } |
|
554 | + |
|
555 | + |
|
556 | + /** |
|
557 | + * Helper for adding columns conditionally |
|
558 | + * |
|
559 | + * @throws EE_Error |
|
560 | + * @throws InvalidArgumentException |
|
561 | + * @throws InvalidDataTypeException |
|
562 | + * @throws InvalidInterfaceException |
|
563 | + */ |
|
564 | + private function addConditionalColumns() |
|
565 | + { |
|
566 | + $event_category_count = EEM_Term::instance()->count( |
|
567 | + [['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]] |
|
568 | + ); |
|
569 | + if ($event_category_count === 0) { |
|
570 | + return; |
|
571 | + } |
|
572 | + $column_array = []; |
|
573 | + foreach ($this->_columns as $column => $column_label) { |
|
574 | + $column_array[ $column ] = $column_label; |
|
575 | + if ($column === 'venue') { |
|
576 | + $column_array['event_category'] = esc_html__('Event Category', 'event_espresso'); |
|
577 | + } |
|
578 | + } |
|
579 | + $this->_columns = $column_array; |
|
580 | + } |
|
581 | 581 | } |