@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('NO direct script access allowed'); |
|
3 | + exit('NO direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -28,636 +28,636 @@ discard block |
||
28 | 28 | { |
29 | 29 | |
30 | 30 | |
31 | - public function __construct($routing = true) |
|
32 | - { |
|
33 | - parent::__construct($routing); |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - |
|
38 | - protected function _init_page_props() |
|
39 | - { |
|
40 | - $this->page_slug = EE_MAINTENANCE_PG_SLUG; |
|
41 | - $this->page_label = EE_MAINTENANCE_LABEL; |
|
42 | - $this->_admin_base_url = EE_MAINTENANCE_ADMIN_URL; |
|
43 | - $this->_admin_base_path = EE_MAINTENANCE_ADMIN; |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - |
|
48 | - protected function _ajax_hooks() |
|
49 | - { |
|
50 | - add_action('wp_ajax_migration_step', array($this, 'migration_step')); |
|
51 | - add_action('wp_ajax_add_error_to_migrations_ran', array($this, 'add_error_to_migrations_ran')); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - protected function _define_page_props() |
|
57 | - { |
|
58 | - $this->_admin_page_title = EE_MAINTENANCE_LABEL; |
|
59 | - $this->_labels = array( |
|
60 | - 'buttons' => array( |
|
61 | - 'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'), |
|
62 | - 'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'), |
|
63 | - ), |
|
64 | - ); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - |
|
69 | - protected function _set_page_routes() |
|
70 | - { |
|
71 | - $this->_page_routes = array( |
|
72 | - 'default' => array( |
|
73 | - 'func' => '_maintenance', |
|
74 | - 'capability' => 'manage_options', |
|
75 | - ), |
|
76 | - 'change_maintenance_level' => array( |
|
77 | - 'func' => '_change_maintenance_level', |
|
78 | - 'capability' => 'manage_options', |
|
79 | - 'noheader' => true, |
|
80 | - ), |
|
81 | - 'system_status' => array( |
|
82 | - 'func' => '_system_status', |
|
83 | - 'capability' => 'manage_options', |
|
84 | - ), |
|
85 | - 'download_system_status' => array( |
|
86 | - 'func' => '_download_system_status', |
|
87 | - 'capability' => 'manage_options', |
|
88 | - 'noheader' => true, |
|
89 | - ), |
|
90 | - 'send_migration_crash_report' => array( |
|
91 | - 'func' => '_send_migration_crash_report', |
|
92 | - 'capability' => 'manage_options', |
|
93 | - 'noheader' => true, |
|
94 | - ), |
|
95 | - 'confirm_migration_crash_report_sent' => array( |
|
96 | - 'func' => '_confirm_migration_crash_report_sent', |
|
97 | - 'capability' => 'manage_options', |
|
98 | - ), |
|
99 | - 'data_reset' => array( |
|
100 | - 'func' => '_data_reset_and_delete', |
|
101 | - 'capability' => 'manage_options', |
|
102 | - ), |
|
103 | - 'reset_db' => array( |
|
104 | - 'func' => '_reset_db', |
|
105 | - 'capability' => 'manage_options', |
|
106 | - 'noheader' => true, |
|
107 | - 'args' => array('nuke_old_ee4_data' => true), |
|
108 | - ), |
|
109 | - 'start_with_fresh_ee4_db' => array( |
|
110 | - 'func' => '_reset_db', |
|
111 | - 'capability' => 'manage_options', |
|
112 | - 'noheader' => true, |
|
113 | - 'args' => array('nuke_old_ee4_data' => false), |
|
114 | - ), |
|
115 | - 'delete_db' => array( |
|
116 | - 'func' => '_delete_db', |
|
117 | - 'capability' => 'manage_options', |
|
118 | - 'noheader' => true, |
|
119 | - ), |
|
120 | - 'rerun_migration_from_ee3' => array( |
|
121 | - 'func' => '_rerun_migration_from_ee3', |
|
122 | - 'capability' => 'manage_options', |
|
123 | - 'noheader' => true, |
|
124 | - ), |
|
125 | - 'reset_reservations' => array( |
|
126 | - 'func' => '_reset_reservations', |
|
127 | - 'capability' => 'manage_options', |
|
128 | - 'noheader' => true, |
|
129 | - ), |
|
130 | - 'reset_capabilities' => array( |
|
131 | - 'func' => '_reset_capabilities', |
|
132 | - 'capability' => 'manage_options', |
|
133 | - 'noheader' => true, |
|
134 | - ), |
|
135 | - 'reattempt_migration' => array( |
|
136 | - 'func' => '_reattempt_migration', |
|
137 | - 'capability' => 'manage_options', |
|
138 | - 'noheader' => true, |
|
139 | - ), |
|
140 | - ); |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - |
|
145 | - protected function _set_page_config() |
|
146 | - { |
|
147 | - $this->_page_config = array( |
|
148 | - 'default' => array( |
|
149 | - 'nav' => array( |
|
150 | - 'label' => esc_html__('Maintenance', 'event_espresso'), |
|
151 | - 'order' => 10, |
|
152 | - ), |
|
153 | - 'require_nonce' => false, |
|
154 | - ), |
|
155 | - 'data_reset' => array( |
|
156 | - 'nav' => array( |
|
157 | - 'label' => esc_html__('Reset/Delete Data', 'event_espresso'), |
|
158 | - 'order' => 20, |
|
159 | - ), |
|
160 | - 'require_nonce' => false, |
|
161 | - ), |
|
162 | - 'system_status' => array( |
|
163 | - 'nav' => array( |
|
164 | - 'label' => esc_html__("System Information", "event_espresso"), |
|
165 | - 'order' => 30, |
|
166 | - ), |
|
167 | - 'require_nonce' => false, |
|
168 | - ), |
|
169 | - ); |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * default maintenance page. If we're in maintenance mode level 2, then we need to show |
|
176 | - * the migration scripts and all that UI. |
|
177 | - */ |
|
178 | - public function _maintenance() |
|
179 | - { |
|
180 | - //it all depends if we're in maintenance model level 1 (frontend-only) or |
|
181 | - //level 2 (everything except maintenance page) |
|
182 | - try { |
|
183 | - //get the current maintenance level and check if |
|
184 | - //we are removed |
|
185 | - $mm = EE_Maintenance_Mode::instance()->level(); |
|
186 | - $placed_in_mm = EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
187 | - if ($mm == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) { |
|
188 | - //we just took the site out of maintenance mode, so notify the user. |
|
189 | - //unfortunately this message appears to be echoed on the NEXT page load... |
|
190 | - //oh well, we should really be checking for this on addon deactivation anyways |
|
191 | - EE_Error::add_attention(__('Site taken out of maintenance mode because no data migration scripts are required', |
|
192 | - 'event_espresso')); |
|
193 | - $this->_process_notices(array('page' => 'espresso_maintenance_settings'), false); |
|
194 | - } |
|
195 | - //in case an exception is thrown while trying to handle migrations |
|
196 | - switch (EE_Maintenance_Mode::instance()->level()) { |
|
197 | - case EE_Maintenance_Mode::level_0_not_in_maintenance: |
|
198 | - case EE_Maintenance_Mode::level_1_frontend_only_maintenance: |
|
199 | - $show_maintenance_switch = true; |
|
200 | - $show_backup_db_text = false; |
|
201 | - $show_migration_progress = false; |
|
202 | - $script_names = array(); |
|
203 | - $addons_should_be_upgraded_first = false; |
|
204 | - break; |
|
205 | - case EE_Maintenance_Mode::level_2_complete_maintenance: |
|
206 | - $show_maintenance_switch = false; |
|
207 | - $show_migration_progress = true; |
|
208 | - if (isset($this->_req_data['continue_migration'])) { |
|
209 | - $show_backup_db_text = false; |
|
210 | - } else { |
|
211 | - $show_backup_db_text = true; |
|
212 | - } |
|
213 | - $scripts_needing_to_run = EE_Data_Migration_Manager::instance() |
|
214 | - ->check_for_applicable_data_migration_scripts(); |
|
215 | - $addons_should_be_upgraded_first = EE_Data_Migration_Manager::instance()->addons_need_updating(); |
|
216 | - $script_names = array(); |
|
217 | - $current_script = null; |
|
218 | - foreach ($scripts_needing_to_run as $script) { |
|
219 | - if ($script instanceof EE_Data_Migration_Script_Base) { |
|
220 | - if ( ! $current_script) { |
|
221 | - $current_script = $script; |
|
222 | - $current_script->migration_page_hooks(); |
|
223 | - } |
|
224 | - $script_names[] = $script->pretty_name(); |
|
225 | - } |
|
226 | - } |
|
227 | - break; |
|
228 | - } |
|
229 | - $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true); |
|
230 | - $exception_thrown = false; |
|
231 | - } catch (EE_Error $e) { |
|
232 | - EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage()); |
|
233 | - //now, just so we can display the page correctly, make a error migration script stage object |
|
234 | - //and also put the error on it. It only persists for the duration of this request |
|
235 | - $most_recent_migration = new EE_DMS_Unknown_1_0_0(); |
|
236 | - $most_recent_migration->add_error($e->getMessage()); |
|
237 | - $exception_thrown = true; |
|
238 | - } |
|
239 | - $current_db_state = EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set(); |
|
240 | - $current_db_state = str_replace('.decaf', '', $current_db_state); |
|
241 | - if ($exception_thrown |
|
242 | - || ($most_recent_migration |
|
243 | - && $most_recent_migration instanceof EE_Data_Migration_Script_Base |
|
244 | - && $most_recent_migration->is_broken() |
|
245 | - ) |
|
246 | - ) { |
|
247 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php'; |
|
248 | - $this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/'; |
|
249 | - $this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action' => 'confirm_migration_crash_report_sent', |
|
250 | - 'success' => '0', |
|
251 | - ), EE_MAINTENANCE_ADMIN_URL); |
|
252 | - } elseif ($addons_should_be_upgraded_first) { |
|
253 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php'; |
|
254 | - } else { |
|
255 | - if ($most_recent_migration |
|
256 | - && $most_recent_migration instanceof EE_Data_Migration_Script_Base |
|
257 | - && $most_recent_migration->can_continue() |
|
258 | - ) { |
|
259 | - $show_backup_db_text = false; |
|
260 | - $show_continue_current_migration_script = true; |
|
261 | - $show_most_recent_migration = true; |
|
262 | - } elseif (isset($this->_req_data['continue_migration'])) { |
|
263 | - $show_most_recent_migration = true; |
|
264 | - $show_continue_current_migration_script = false; |
|
265 | - } else { |
|
266 | - $show_most_recent_migration = false; |
|
267 | - $show_continue_current_migration_script = false; |
|
268 | - } |
|
269 | - if (isset($current_script)) { |
|
270 | - $migrates_to = $current_script->migrates_to_version(); |
|
271 | - $plugin_slug = $migrates_to['slug']; |
|
272 | - $new_version = $migrates_to['version']; |
|
273 | - $this->_template_args = array_merge($this->_template_args, array( |
|
274 | - 'current_db_state' => sprintf(__("EE%s (%s)", "event_espresso"), |
|
275 | - isset($current_db_state[$plugin_slug]) ? $current_db_state[$plugin_slug] : 3, $plugin_slug), |
|
276 | - 'next_db_state' => isset($current_script) ? sprintf(__("EE%s (%s)", 'event_espresso'), |
|
277 | - $new_version, $plugin_slug) : null, |
|
278 | - )); |
|
279 | - } else { |
|
280 | - $this->_template_args['current_db_state'] = null; |
|
281 | - $this->_template_args['next_db_state'] = null; |
|
282 | - } |
|
283 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php'; |
|
284 | - $this->_template_args = array_merge( |
|
285 | - $this->_template_args, |
|
286 | - array( |
|
287 | - 'show_most_recent_migration' => $show_most_recent_migration, |
|
288 | - //flag for showing the most recent migration's status and/or errors |
|
289 | - 'show_migration_progress' => $show_migration_progress, |
|
290 | - //flag for showing the option to run migrations and see their progress |
|
291 | - 'show_backup_db_text' => $show_backup_db_text, |
|
292 | - //flag for showing text telling the user to backup their DB |
|
293 | - 'show_maintenance_switch' => $show_maintenance_switch, |
|
294 | - //flag for showing the option to change maintenance mode between levels 0 and 1 |
|
295 | - 'script_names' => $script_names, |
|
296 | - //array of names of scripts that have run |
|
297 | - 'show_continue_current_migration_script' => $show_continue_current_migration_script, |
|
298 | - //flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0 |
|
299 | - 'reset_db_page_link' => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'), |
|
300 | - EE_MAINTENANCE_ADMIN_URL), |
|
301 | - 'data_reset_page' => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'), |
|
302 | - EE_MAINTENANCE_ADMIN_URL), |
|
303 | - 'update_migration_script_page_link' => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'change_maintenance_level'), |
|
304 | - EE_MAINTENANCE_ADMIN_URL), |
|
305 | - 'ultimate_db_state' => sprintf(__("EE%s", 'event_espresso'), |
|
306 | - espresso_version()), |
|
307 | - ) |
|
308 | - ); |
|
309 | - //make sure we have the form fields helper available. It usually is, but sometimes it isn't |
|
310 | - //localize script stuff |
|
311 | - wp_localize_script('ee-maintenance', 'ee_maintenance', array( |
|
312 | - 'migrating' => esc_html__("Updating Database...", "event_espresso"), |
|
313 | - 'next' => esc_html__("Next", "event_espresso"), |
|
314 | - 'fatal_error' => esc_html__("A Fatal Error Has Occurred", "event_espresso"), |
|
315 | - 'click_next_when_ready' => esc_html__("The current Database Update has ended. Click 'next' when ready to proceed", |
|
316 | - "event_espresso"), |
|
317 | - 'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts, |
|
318 | - 'status_fatal_error' => EE_Data_Migration_Manager::status_fatal_error, |
|
319 | - 'status_completed' => EE_Data_Migration_Manager::status_completed, |
|
320 | - )); |
|
321 | - } |
|
322 | - $this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration |
|
323 | - //now render the migration options part, and put it in a variable |
|
324 | - $migration_options_template_file = apply_filters( |
|
325 | - 'FHEE__ee_migration_page__migration_options_template', |
|
326 | - EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php' |
|
327 | - ); |
|
328 | - $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true); |
|
329 | - $this->_template_args['migration_options_html'] = $migration_options_html; |
|
330 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
331 | - $this->_template_args, true); |
|
332 | - $this->display_admin_page_with_sidebar(); |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * returns JSON and executes another step of the currently-executing data migration (called via ajax) |
|
339 | - */ |
|
340 | - public function migration_step() |
|
341 | - { |
|
342 | - $this->_template_args['data'] = EE_Data_Migration_Manager::instance()->response_to_migration_ajax_request(); |
|
343 | - $this->_return_json(); |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * Can be used by js when it notices a response with HTML in it in order |
|
350 | - * to log the malformed response |
|
351 | - */ |
|
352 | - public function add_error_to_migrations_ran() |
|
353 | - { |
|
354 | - EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($this->_req_data['message']); |
|
355 | - $this->_template_args['data'] = array('ok' => true); |
|
356 | - $this->_return_json(); |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * changes the maintenance level, provided there are still no migration scripts that should run |
|
363 | - */ |
|
364 | - public function _change_maintenance_level() |
|
365 | - { |
|
366 | - $new_level = absint($this->_req_data['maintenance_mode_level']); |
|
367 | - if ( ! EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) { |
|
368 | - EE_Maintenance_Mode::instance()->set_maintenance_level($new_level); |
|
369 | - $success = true; |
|
370 | - } else { |
|
371 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
372 | - $success = false; |
|
373 | - } |
|
374 | - $this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso")); |
|
375 | - } |
|
376 | - |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * a tab with options for resetting and/or deleting EE data |
|
381 | - * |
|
382 | - * @throws \EE_Error |
|
383 | - * @throws \DomainException |
|
384 | - */ |
|
385 | - public function _data_reset_and_delete() |
|
386 | - { |
|
387 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php'; |
|
388 | - $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button( |
|
389 | - 'reset_reservations', |
|
390 | - 'reset_reservations', |
|
391 | - array(), |
|
392 | - 'button button-primary', |
|
393 | - '', |
|
394 | - false |
|
395 | - ); |
|
396 | - $this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button( |
|
397 | - 'reset_capabilities', |
|
398 | - 'reset_capabilities', |
|
399 | - array(), |
|
400 | - 'button button-primary', |
|
401 | - '', |
|
402 | - false |
|
403 | - ); |
|
404 | - $this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
405 | - array('action' => 'delete_db'), |
|
406 | - EE_MAINTENANCE_ADMIN_URL |
|
407 | - ); |
|
408 | - $this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
409 | - array('action' => 'reset_db'), |
|
410 | - EE_MAINTENANCE_ADMIN_URL |
|
411 | - ); |
|
412 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
413 | - $this->_template_path, |
|
414 | - $this->_template_args, |
|
415 | - true |
|
416 | - ); |
|
417 | - $this->display_admin_page_with_sidebar(); |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - |
|
422 | - protected function _reset_reservations() |
|
423 | - { |
|
424 | - if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) { |
|
425 | - EE_Error::add_success( |
|
426 | - __( |
|
427 | - 'Ticket and datetime reserved counts have been successfully reset.', |
|
428 | - 'event_espresso' |
|
429 | - ) |
|
430 | - ); |
|
431 | - } else { |
|
432 | - EE_Error::add_success( |
|
433 | - __( |
|
434 | - 'Ticket and datetime reserved counts were correct and did not need resetting.', |
|
435 | - 'event_espresso' |
|
436 | - ) |
|
437 | - ); |
|
438 | - } |
|
439 | - $this->_redirect_after_action(true, '', '', array('action' => 'data_reset'), true); |
|
440 | - } |
|
441 | - |
|
442 | - |
|
443 | - |
|
444 | - protected function _reset_capabilities() |
|
445 | - { |
|
446 | - EE_Registry::instance()->CAP->init_caps(true); |
|
447 | - EE_Error::add_success(__('Default Event Espresso capabilities have been restored for all current roles.', |
|
448 | - 'event_espresso')); |
|
449 | - $this->_redirect_after_action(false, '', '', array('action' => 'data_reset'), true); |
|
450 | - } |
|
451 | - |
|
452 | - |
|
453 | - |
|
454 | - /** |
|
455 | - * resets the DMSs so we can attempt to continue migrating after a fatal error |
|
456 | - * (only a good idea when someone has somehow tried ot fix whatever caused |
|
457 | - * the fatal error in teh first place) |
|
458 | - */ |
|
459 | - protected function _reattempt_migration() |
|
460 | - { |
|
461 | - EE_Data_Migration_Manager::instance()->reattempt(); |
|
462 | - $this->_redirect_after_action(false, '', '', array('action' => 'default'), true); |
|
463 | - } |
|
464 | - |
|
465 | - |
|
466 | - |
|
467 | - /** |
|
468 | - * shows the big ol' System Information page |
|
469 | - */ |
|
470 | - public function _system_status() |
|
471 | - { |
|
472 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php'; |
|
473 | - $this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati(); |
|
474 | - $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
475 | - array( |
|
476 | - 'action' => 'download_system_status', |
|
477 | - ), |
|
478 | - EE_MAINTENANCE_ADMIN_URL |
|
479 | - ); |
|
480 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
481 | - $this->_template_args, true); |
|
482 | - $this->display_admin_page_with_sidebar(); |
|
483 | - } |
|
484 | - |
|
485 | - /** |
|
486 | - * Downloads an HTML file of the system status that can be easily stored or emailed |
|
487 | - */ |
|
488 | - public function _download_system_status() |
|
489 | - { |
|
490 | - $status_info = EEM_System_Status::instance()->get_system_stati(); |
|
491 | - header( 'Content-Disposition: attachment' ); |
|
492 | - header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" ); |
|
493 | - echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>"; |
|
494 | - echo "<h1>System Information for " . site_url() . "</h1>"; |
|
495 | - echo EEH_Template::layout_array_as_table( $status_info ); |
|
496 | - die; |
|
497 | - } |
|
498 | - |
|
499 | - |
|
500 | - |
|
501 | - public function _send_migration_crash_report() |
|
502 | - { |
|
503 | - $from = $this->_req_data['from']; |
|
504 | - $from_name = $this->_req_data['from_name']; |
|
505 | - $body = $this->_req_data['body']; |
|
506 | - try { |
|
507 | - $success = wp_mail(EE_SUPPORT_EMAIL, |
|
508 | - 'Migration Crash Report', |
|
509 | - $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true), |
|
510 | - array( |
|
511 | - "from:$from_name<$from>", |
|
512 | - // 'content-type:text/html charset=UTF-8' |
|
513 | - )); |
|
514 | - } catch (Exception $e) { |
|
515 | - $success = false; |
|
516 | - } |
|
517 | - $this->_redirect_after_action($success, esc_html__("Migration Crash Report", "event_espresso"), |
|
518 | - esc_html__("sent", "event_espresso"), |
|
519 | - array('success' => $success, 'action' => 'confirm_migration_crash_report_sent')); |
|
520 | - } |
|
521 | - |
|
522 | - |
|
523 | - |
|
524 | - public function _confirm_migration_crash_report_sent() |
|
525 | - { |
|
526 | - try { |
|
527 | - $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true); |
|
528 | - } catch (EE_Error $e) { |
|
529 | - EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage()); |
|
530 | - //now, just so we can display the page correctly, make a error migration script stage object |
|
531 | - //and also put the error on it. It only persists for the duration of this request |
|
532 | - $most_recent_migration = new EE_DMS_Unknown_1_0_0(); |
|
533 | - $most_recent_migration->add_error($e->getMessage()); |
|
534 | - } |
|
535 | - $success = $this->_req_data['success'] == '1' ? true : false; |
|
536 | - $this->_template_args['success'] = $success; |
|
537 | - $this->_template_args['most_recent_migration'] = $most_recent_migration; |
|
538 | - $this->_template_args['reset_db_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'), |
|
539 | - EE_MAINTENANCE_ADMIN_URL); |
|
540 | - $this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'), |
|
541 | - EE_MAINTENANCE_ADMIN_URL); |
|
542 | - $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'), |
|
543 | - EE_MAINTENANCE_ADMIN_URL); |
|
544 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php'; |
|
545 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
546 | - $this->_template_args, true); |
|
547 | - $this->display_admin_page_with_sidebar(); |
|
548 | - } |
|
549 | - |
|
550 | - |
|
551 | - |
|
552 | - /** |
|
553 | - * Resets the entire EE4 database. |
|
554 | - * Currently basically only sets up ee4 database for a fresh install- doesn't |
|
555 | - * actually clean out the old wp options, or cpts (although does erase old ee table data) |
|
556 | - * |
|
557 | - * @param boolean $nuke_old_ee4_data controls whether or not we |
|
558 | - * destroy the old ee4 data, or just try initializing ee4 default data |
|
559 | - */ |
|
560 | - public function _reset_db($nuke_old_ee4_data = true) |
|
561 | - { |
|
562 | - EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
563 | - if ($nuke_old_ee4_data) { |
|
564 | - EEH_Activation::delete_all_espresso_cpt_data(); |
|
565 | - EEH_Activation::delete_all_espresso_tables_and_data(false); |
|
566 | - EEH_Activation::remove_cron_tasks(); |
|
567 | - } |
|
568 | - //make sure when we reset the registry's config that it |
|
569 | - //switches to using the new singleton |
|
570 | - EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true); |
|
571 | - EE_System::instance()->initialize_db_if_no_migrations_required(true); |
|
572 | - EE_System::instance()->redirect_to_about_ee(); |
|
573 | - } |
|
574 | - |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * Deletes ALL EE tables, Records, and Options from the database. |
|
579 | - */ |
|
580 | - public function _delete_db() |
|
581 | - { |
|
582 | - EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
583 | - EEH_Activation::delete_all_espresso_cpt_data(); |
|
584 | - EEH_Activation::delete_all_espresso_tables_and_data(); |
|
585 | - EEH_Activation::remove_cron_tasks(); |
|
586 | - EEH_Activation::deactivate_event_espresso(); |
|
587 | - wp_safe_redirect(admin_url('plugins.php')); |
|
588 | - exit; |
|
589 | - } |
|
590 | - |
|
591 | - |
|
592 | - |
|
593 | - /** |
|
594 | - * sets up EE4 to rerun the migrations from ee3 to ee4 |
|
595 | - */ |
|
596 | - public function _rerun_migration_from_ee3() |
|
597 | - { |
|
598 | - EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
599 | - EEH_Activation::delete_all_espresso_cpt_data(); |
|
600 | - EEH_Activation::delete_all_espresso_tables_and_data(false); |
|
601 | - //set the db state to something that will require migrations |
|
602 | - update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0'); |
|
603 | - EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance); |
|
604 | - $this->_redirect_after_action(true, esc_html__("Database", 'event_espresso'), esc_html__("reset", 'event_espresso')); |
|
605 | - } |
|
606 | - |
|
607 | - |
|
608 | - |
|
609 | - //none of the below group are currently used for Gateway Settings |
|
610 | - protected function _add_screen_options() |
|
611 | - { |
|
612 | - } |
|
613 | - |
|
614 | - |
|
615 | - |
|
616 | - protected function _add_feature_pointers() |
|
617 | - { |
|
618 | - } |
|
619 | - |
|
31 | + public function __construct($routing = true) |
|
32 | + { |
|
33 | + parent::__construct($routing); |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + |
|
38 | + protected function _init_page_props() |
|
39 | + { |
|
40 | + $this->page_slug = EE_MAINTENANCE_PG_SLUG; |
|
41 | + $this->page_label = EE_MAINTENANCE_LABEL; |
|
42 | + $this->_admin_base_url = EE_MAINTENANCE_ADMIN_URL; |
|
43 | + $this->_admin_base_path = EE_MAINTENANCE_ADMIN; |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + |
|
48 | + protected function _ajax_hooks() |
|
49 | + { |
|
50 | + add_action('wp_ajax_migration_step', array($this, 'migration_step')); |
|
51 | + add_action('wp_ajax_add_error_to_migrations_ran', array($this, 'add_error_to_migrations_ran')); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + protected function _define_page_props() |
|
57 | + { |
|
58 | + $this->_admin_page_title = EE_MAINTENANCE_LABEL; |
|
59 | + $this->_labels = array( |
|
60 | + 'buttons' => array( |
|
61 | + 'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'), |
|
62 | + 'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'), |
|
63 | + ), |
|
64 | + ); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + |
|
69 | + protected function _set_page_routes() |
|
70 | + { |
|
71 | + $this->_page_routes = array( |
|
72 | + 'default' => array( |
|
73 | + 'func' => '_maintenance', |
|
74 | + 'capability' => 'manage_options', |
|
75 | + ), |
|
76 | + 'change_maintenance_level' => array( |
|
77 | + 'func' => '_change_maintenance_level', |
|
78 | + 'capability' => 'manage_options', |
|
79 | + 'noheader' => true, |
|
80 | + ), |
|
81 | + 'system_status' => array( |
|
82 | + 'func' => '_system_status', |
|
83 | + 'capability' => 'manage_options', |
|
84 | + ), |
|
85 | + 'download_system_status' => array( |
|
86 | + 'func' => '_download_system_status', |
|
87 | + 'capability' => 'manage_options', |
|
88 | + 'noheader' => true, |
|
89 | + ), |
|
90 | + 'send_migration_crash_report' => array( |
|
91 | + 'func' => '_send_migration_crash_report', |
|
92 | + 'capability' => 'manage_options', |
|
93 | + 'noheader' => true, |
|
94 | + ), |
|
95 | + 'confirm_migration_crash_report_sent' => array( |
|
96 | + 'func' => '_confirm_migration_crash_report_sent', |
|
97 | + 'capability' => 'manage_options', |
|
98 | + ), |
|
99 | + 'data_reset' => array( |
|
100 | + 'func' => '_data_reset_and_delete', |
|
101 | + 'capability' => 'manage_options', |
|
102 | + ), |
|
103 | + 'reset_db' => array( |
|
104 | + 'func' => '_reset_db', |
|
105 | + 'capability' => 'manage_options', |
|
106 | + 'noheader' => true, |
|
107 | + 'args' => array('nuke_old_ee4_data' => true), |
|
108 | + ), |
|
109 | + 'start_with_fresh_ee4_db' => array( |
|
110 | + 'func' => '_reset_db', |
|
111 | + 'capability' => 'manage_options', |
|
112 | + 'noheader' => true, |
|
113 | + 'args' => array('nuke_old_ee4_data' => false), |
|
114 | + ), |
|
115 | + 'delete_db' => array( |
|
116 | + 'func' => '_delete_db', |
|
117 | + 'capability' => 'manage_options', |
|
118 | + 'noheader' => true, |
|
119 | + ), |
|
120 | + 'rerun_migration_from_ee3' => array( |
|
121 | + 'func' => '_rerun_migration_from_ee3', |
|
122 | + 'capability' => 'manage_options', |
|
123 | + 'noheader' => true, |
|
124 | + ), |
|
125 | + 'reset_reservations' => array( |
|
126 | + 'func' => '_reset_reservations', |
|
127 | + 'capability' => 'manage_options', |
|
128 | + 'noheader' => true, |
|
129 | + ), |
|
130 | + 'reset_capabilities' => array( |
|
131 | + 'func' => '_reset_capabilities', |
|
132 | + 'capability' => 'manage_options', |
|
133 | + 'noheader' => true, |
|
134 | + ), |
|
135 | + 'reattempt_migration' => array( |
|
136 | + 'func' => '_reattempt_migration', |
|
137 | + 'capability' => 'manage_options', |
|
138 | + 'noheader' => true, |
|
139 | + ), |
|
140 | + ); |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + |
|
145 | + protected function _set_page_config() |
|
146 | + { |
|
147 | + $this->_page_config = array( |
|
148 | + 'default' => array( |
|
149 | + 'nav' => array( |
|
150 | + 'label' => esc_html__('Maintenance', 'event_espresso'), |
|
151 | + 'order' => 10, |
|
152 | + ), |
|
153 | + 'require_nonce' => false, |
|
154 | + ), |
|
155 | + 'data_reset' => array( |
|
156 | + 'nav' => array( |
|
157 | + 'label' => esc_html__('Reset/Delete Data', 'event_espresso'), |
|
158 | + 'order' => 20, |
|
159 | + ), |
|
160 | + 'require_nonce' => false, |
|
161 | + ), |
|
162 | + 'system_status' => array( |
|
163 | + 'nav' => array( |
|
164 | + 'label' => esc_html__("System Information", "event_espresso"), |
|
165 | + 'order' => 30, |
|
166 | + ), |
|
167 | + 'require_nonce' => false, |
|
168 | + ), |
|
169 | + ); |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * default maintenance page. If we're in maintenance mode level 2, then we need to show |
|
176 | + * the migration scripts and all that UI. |
|
177 | + */ |
|
178 | + public function _maintenance() |
|
179 | + { |
|
180 | + //it all depends if we're in maintenance model level 1 (frontend-only) or |
|
181 | + //level 2 (everything except maintenance page) |
|
182 | + try { |
|
183 | + //get the current maintenance level and check if |
|
184 | + //we are removed |
|
185 | + $mm = EE_Maintenance_Mode::instance()->level(); |
|
186 | + $placed_in_mm = EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
187 | + if ($mm == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) { |
|
188 | + //we just took the site out of maintenance mode, so notify the user. |
|
189 | + //unfortunately this message appears to be echoed on the NEXT page load... |
|
190 | + //oh well, we should really be checking for this on addon deactivation anyways |
|
191 | + EE_Error::add_attention(__('Site taken out of maintenance mode because no data migration scripts are required', |
|
192 | + 'event_espresso')); |
|
193 | + $this->_process_notices(array('page' => 'espresso_maintenance_settings'), false); |
|
194 | + } |
|
195 | + //in case an exception is thrown while trying to handle migrations |
|
196 | + switch (EE_Maintenance_Mode::instance()->level()) { |
|
197 | + case EE_Maintenance_Mode::level_0_not_in_maintenance: |
|
198 | + case EE_Maintenance_Mode::level_1_frontend_only_maintenance: |
|
199 | + $show_maintenance_switch = true; |
|
200 | + $show_backup_db_text = false; |
|
201 | + $show_migration_progress = false; |
|
202 | + $script_names = array(); |
|
203 | + $addons_should_be_upgraded_first = false; |
|
204 | + break; |
|
205 | + case EE_Maintenance_Mode::level_2_complete_maintenance: |
|
206 | + $show_maintenance_switch = false; |
|
207 | + $show_migration_progress = true; |
|
208 | + if (isset($this->_req_data['continue_migration'])) { |
|
209 | + $show_backup_db_text = false; |
|
210 | + } else { |
|
211 | + $show_backup_db_text = true; |
|
212 | + } |
|
213 | + $scripts_needing_to_run = EE_Data_Migration_Manager::instance() |
|
214 | + ->check_for_applicable_data_migration_scripts(); |
|
215 | + $addons_should_be_upgraded_first = EE_Data_Migration_Manager::instance()->addons_need_updating(); |
|
216 | + $script_names = array(); |
|
217 | + $current_script = null; |
|
218 | + foreach ($scripts_needing_to_run as $script) { |
|
219 | + if ($script instanceof EE_Data_Migration_Script_Base) { |
|
220 | + if ( ! $current_script) { |
|
221 | + $current_script = $script; |
|
222 | + $current_script->migration_page_hooks(); |
|
223 | + } |
|
224 | + $script_names[] = $script->pretty_name(); |
|
225 | + } |
|
226 | + } |
|
227 | + break; |
|
228 | + } |
|
229 | + $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true); |
|
230 | + $exception_thrown = false; |
|
231 | + } catch (EE_Error $e) { |
|
232 | + EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage()); |
|
233 | + //now, just so we can display the page correctly, make a error migration script stage object |
|
234 | + //and also put the error on it. It only persists for the duration of this request |
|
235 | + $most_recent_migration = new EE_DMS_Unknown_1_0_0(); |
|
236 | + $most_recent_migration->add_error($e->getMessage()); |
|
237 | + $exception_thrown = true; |
|
238 | + } |
|
239 | + $current_db_state = EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set(); |
|
240 | + $current_db_state = str_replace('.decaf', '', $current_db_state); |
|
241 | + if ($exception_thrown |
|
242 | + || ($most_recent_migration |
|
243 | + && $most_recent_migration instanceof EE_Data_Migration_Script_Base |
|
244 | + && $most_recent_migration->is_broken() |
|
245 | + ) |
|
246 | + ) { |
|
247 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php'; |
|
248 | + $this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/'; |
|
249 | + $this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action' => 'confirm_migration_crash_report_sent', |
|
250 | + 'success' => '0', |
|
251 | + ), EE_MAINTENANCE_ADMIN_URL); |
|
252 | + } elseif ($addons_should_be_upgraded_first) { |
|
253 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php'; |
|
254 | + } else { |
|
255 | + if ($most_recent_migration |
|
256 | + && $most_recent_migration instanceof EE_Data_Migration_Script_Base |
|
257 | + && $most_recent_migration->can_continue() |
|
258 | + ) { |
|
259 | + $show_backup_db_text = false; |
|
260 | + $show_continue_current_migration_script = true; |
|
261 | + $show_most_recent_migration = true; |
|
262 | + } elseif (isset($this->_req_data['continue_migration'])) { |
|
263 | + $show_most_recent_migration = true; |
|
264 | + $show_continue_current_migration_script = false; |
|
265 | + } else { |
|
266 | + $show_most_recent_migration = false; |
|
267 | + $show_continue_current_migration_script = false; |
|
268 | + } |
|
269 | + if (isset($current_script)) { |
|
270 | + $migrates_to = $current_script->migrates_to_version(); |
|
271 | + $plugin_slug = $migrates_to['slug']; |
|
272 | + $new_version = $migrates_to['version']; |
|
273 | + $this->_template_args = array_merge($this->_template_args, array( |
|
274 | + 'current_db_state' => sprintf(__("EE%s (%s)", "event_espresso"), |
|
275 | + isset($current_db_state[$plugin_slug]) ? $current_db_state[$plugin_slug] : 3, $plugin_slug), |
|
276 | + 'next_db_state' => isset($current_script) ? sprintf(__("EE%s (%s)", 'event_espresso'), |
|
277 | + $new_version, $plugin_slug) : null, |
|
278 | + )); |
|
279 | + } else { |
|
280 | + $this->_template_args['current_db_state'] = null; |
|
281 | + $this->_template_args['next_db_state'] = null; |
|
282 | + } |
|
283 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php'; |
|
284 | + $this->_template_args = array_merge( |
|
285 | + $this->_template_args, |
|
286 | + array( |
|
287 | + 'show_most_recent_migration' => $show_most_recent_migration, |
|
288 | + //flag for showing the most recent migration's status and/or errors |
|
289 | + 'show_migration_progress' => $show_migration_progress, |
|
290 | + //flag for showing the option to run migrations and see their progress |
|
291 | + 'show_backup_db_text' => $show_backup_db_text, |
|
292 | + //flag for showing text telling the user to backup their DB |
|
293 | + 'show_maintenance_switch' => $show_maintenance_switch, |
|
294 | + //flag for showing the option to change maintenance mode between levels 0 and 1 |
|
295 | + 'script_names' => $script_names, |
|
296 | + //array of names of scripts that have run |
|
297 | + 'show_continue_current_migration_script' => $show_continue_current_migration_script, |
|
298 | + //flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0 |
|
299 | + 'reset_db_page_link' => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'), |
|
300 | + EE_MAINTENANCE_ADMIN_URL), |
|
301 | + 'data_reset_page' => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'), |
|
302 | + EE_MAINTENANCE_ADMIN_URL), |
|
303 | + 'update_migration_script_page_link' => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'change_maintenance_level'), |
|
304 | + EE_MAINTENANCE_ADMIN_URL), |
|
305 | + 'ultimate_db_state' => sprintf(__("EE%s", 'event_espresso'), |
|
306 | + espresso_version()), |
|
307 | + ) |
|
308 | + ); |
|
309 | + //make sure we have the form fields helper available. It usually is, but sometimes it isn't |
|
310 | + //localize script stuff |
|
311 | + wp_localize_script('ee-maintenance', 'ee_maintenance', array( |
|
312 | + 'migrating' => esc_html__("Updating Database...", "event_espresso"), |
|
313 | + 'next' => esc_html__("Next", "event_espresso"), |
|
314 | + 'fatal_error' => esc_html__("A Fatal Error Has Occurred", "event_espresso"), |
|
315 | + 'click_next_when_ready' => esc_html__("The current Database Update has ended. Click 'next' when ready to proceed", |
|
316 | + "event_espresso"), |
|
317 | + 'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts, |
|
318 | + 'status_fatal_error' => EE_Data_Migration_Manager::status_fatal_error, |
|
319 | + 'status_completed' => EE_Data_Migration_Manager::status_completed, |
|
320 | + )); |
|
321 | + } |
|
322 | + $this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration |
|
323 | + //now render the migration options part, and put it in a variable |
|
324 | + $migration_options_template_file = apply_filters( |
|
325 | + 'FHEE__ee_migration_page__migration_options_template', |
|
326 | + EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php' |
|
327 | + ); |
|
328 | + $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true); |
|
329 | + $this->_template_args['migration_options_html'] = $migration_options_html; |
|
330 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
331 | + $this->_template_args, true); |
|
332 | + $this->display_admin_page_with_sidebar(); |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * returns JSON and executes another step of the currently-executing data migration (called via ajax) |
|
339 | + */ |
|
340 | + public function migration_step() |
|
341 | + { |
|
342 | + $this->_template_args['data'] = EE_Data_Migration_Manager::instance()->response_to_migration_ajax_request(); |
|
343 | + $this->_return_json(); |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * Can be used by js when it notices a response with HTML in it in order |
|
350 | + * to log the malformed response |
|
351 | + */ |
|
352 | + public function add_error_to_migrations_ran() |
|
353 | + { |
|
354 | + EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($this->_req_data['message']); |
|
355 | + $this->_template_args['data'] = array('ok' => true); |
|
356 | + $this->_return_json(); |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * changes the maintenance level, provided there are still no migration scripts that should run |
|
363 | + */ |
|
364 | + public function _change_maintenance_level() |
|
365 | + { |
|
366 | + $new_level = absint($this->_req_data['maintenance_mode_level']); |
|
367 | + if ( ! EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) { |
|
368 | + EE_Maintenance_Mode::instance()->set_maintenance_level($new_level); |
|
369 | + $success = true; |
|
370 | + } else { |
|
371 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
372 | + $success = false; |
|
373 | + } |
|
374 | + $this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso")); |
|
375 | + } |
|
376 | + |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * a tab with options for resetting and/or deleting EE data |
|
381 | + * |
|
382 | + * @throws \EE_Error |
|
383 | + * @throws \DomainException |
|
384 | + */ |
|
385 | + public function _data_reset_and_delete() |
|
386 | + { |
|
387 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php'; |
|
388 | + $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button( |
|
389 | + 'reset_reservations', |
|
390 | + 'reset_reservations', |
|
391 | + array(), |
|
392 | + 'button button-primary', |
|
393 | + '', |
|
394 | + false |
|
395 | + ); |
|
396 | + $this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button( |
|
397 | + 'reset_capabilities', |
|
398 | + 'reset_capabilities', |
|
399 | + array(), |
|
400 | + 'button button-primary', |
|
401 | + '', |
|
402 | + false |
|
403 | + ); |
|
404 | + $this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
405 | + array('action' => 'delete_db'), |
|
406 | + EE_MAINTENANCE_ADMIN_URL |
|
407 | + ); |
|
408 | + $this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
409 | + array('action' => 'reset_db'), |
|
410 | + EE_MAINTENANCE_ADMIN_URL |
|
411 | + ); |
|
412 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
413 | + $this->_template_path, |
|
414 | + $this->_template_args, |
|
415 | + true |
|
416 | + ); |
|
417 | + $this->display_admin_page_with_sidebar(); |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + |
|
422 | + protected function _reset_reservations() |
|
423 | + { |
|
424 | + if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) { |
|
425 | + EE_Error::add_success( |
|
426 | + __( |
|
427 | + 'Ticket and datetime reserved counts have been successfully reset.', |
|
428 | + 'event_espresso' |
|
429 | + ) |
|
430 | + ); |
|
431 | + } else { |
|
432 | + EE_Error::add_success( |
|
433 | + __( |
|
434 | + 'Ticket and datetime reserved counts were correct and did not need resetting.', |
|
435 | + 'event_espresso' |
|
436 | + ) |
|
437 | + ); |
|
438 | + } |
|
439 | + $this->_redirect_after_action(true, '', '', array('action' => 'data_reset'), true); |
|
440 | + } |
|
441 | + |
|
442 | + |
|
443 | + |
|
444 | + protected function _reset_capabilities() |
|
445 | + { |
|
446 | + EE_Registry::instance()->CAP->init_caps(true); |
|
447 | + EE_Error::add_success(__('Default Event Espresso capabilities have been restored for all current roles.', |
|
448 | + 'event_espresso')); |
|
449 | + $this->_redirect_after_action(false, '', '', array('action' => 'data_reset'), true); |
|
450 | + } |
|
451 | + |
|
452 | + |
|
453 | + |
|
454 | + /** |
|
455 | + * resets the DMSs so we can attempt to continue migrating after a fatal error |
|
456 | + * (only a good idea when someone has somehow tried ot fix whatever caused |
|
457 | + * the fatal error in teh first place) |
|
458 | + */ |
|
459 | + protected function _reattempt_migration() |
|
460 | + { |
|
461 | + EE_Data_Migration_Manager::instance()->reattempt(); |
|
462 | + $this->_redirect_after_action(false, '', '', array('action' => 'default'), true); |
|
463 | + } |
|
464 | + |
|
465 | + |
|
466 | + |
|
467 | + /** |
|
468 | + * shows the big ol' System Information page |
|
469 | + */ |
|
470 | + public function _system_status() |
|
471 | + { |
|
472 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php'; |
|
473 | + $this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati(); |
|
474 | + $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
475 | + array( |
|
476 | + 'action' => 'download_system_status', |
|
477 | + ), |
|
478 | + EE_MAINTENANCE_ADMIN_URL |
|
479 | + ); |
|
480 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
481 | + $this->_template_args, true); |
|
482 | + $this->display_admin_page_with_sidebar(); |
|
483 | + } |
|
484 | + |
|
485 | + /** |
|
486 | + * Downloads an HTML file of the system status that can be easily stored or emailed |
|
487 | + */ |
|
488 | + public function _download_system_status() |
|
489 | + { |
|
490 | + $status_info = EEM_System_Status::instance()->get_system_stati(); |
|
491 | + header( 'Content-Disposition: attachment' ); |
|
492 | + header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" ); |
|
493 | + echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>"; |
|
494 | + echo "<h1>System Information for " . site_url() . "</h1>"; |
|
495 | + echo EEH_Template::layout_array_as_table( $status_info ); |
|
496 | + die; |
|
497 | + } |
|
498 | + |
|
499 | + |
|
500 | + |
|
501 | + public function _send_migration_crash_report() |
|
502 | + { |
|
503 | + $from = $this->_req_data['from']; |
|
504 | + $from_name = $this->_req_data['from_name']; |
|
505 | + $body = $this->_req_data['body']; |
|
506 | + try { |
|
507 | + $success = wp_mail(EE_SUPPORT_EMAIL, |
|
508 | + 'Migration Crash Report', |
|
509 | + $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true), |
|
510 | + array( |
|
511 | + "from:$from_name<$from>", |
|
512 | + // 'content-type:text/html charset=UTF-8' |
|
513 | + )); |
|
514 | + } catch (Exception $e) { |
|
515 | + $success = false; |
|
516 | + } |
|
517 | + $this->_redirect_after_action($success, esc_html__("Migration Crash Report", "event_espresso"), |
|
518 | + esc_html__("sent", "event_espresso"), |
|
519 | + array('success' => $success, 'action' => 'confirm_migration_crash_report_sent')); |
|
520 | + } |
|
521 | + |
|
522 | + |
|
523 | + |
|
524 | + public function _confirm_migration_crash_report_sent() |
|
525 | + { |
|
526 | + try { |
|
527 | + $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true); |
|
528 | + } catch (EE_Error $e) { |
|
529 | + EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage()); |
|
530 | + //now, just so we can display the page correctly, make a error migration script stage object |
|
531 | + //and also put the error on it. It only persists for the duration of this request |
|
532 | + $most_recent_migration = new EE_DMS_Unknown_1_0_0(); |
|
533 | + $most_recent_migration->add_error($e->getMessage()); |
|
534 | + } |
|
535 | + $success = $this->_req_data['success'] == '1' ? true : false; |
|
536 | + $this->_template_args['success'] = $success; |
|
537 | + $this->_template_args['most_recent_migration'] = $most_recent_migration; |
|
538 | + $this->_template_args['reset_db_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'), |
|
539 | + EE_MAINTENANCE_ADMIN_URL); |
|
540 | + $this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'), |
|
541 | + EE_MAINTENANCE_ADMIN_URL); |
|
542 | + $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'), |
|
543 | + EE_MAINTENANCE_ADMIN_URL); |
|
544 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php'; |
|
545 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
546 | + $this->_template_args, true); |
|
547 | + $this->display_admin_page_with_sidebar(); |
|
548 | + } |
|
549 | + |
|
550 | + |
|
551 | + |
|
552 | + /** |
|
553 | + * Resets the entire EE4 database. |
|
554 | + * Currently basically only sets up ee4 database for a fresh install- doesn't |
|
555 | + * actually clean out the old wp options, or cpts (although does erase old ee table data) |
|
556 | + * |
|
557 | + * @param boolean $nuke_old_ee4_data controls whether or not we |
|
558 | + * destroy the old ee4 data, or just try initializing ee4 default data |
|
559 | + */ |
|
560 | + public function _reset_db($nuke_old_ee4_data = true) |
|
561 | + { |
|
562 | + EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
563 | + if ($nuke_old_ee4_data) { |
|
564 | + EEH_Activation::delete_all_espresso_cpt_data(); |
|
565 | + EEH_Activation::delete_all_espresso_tables_and_data(false); |
|
566 | + EEH_Activation::remove_cron_tasks(); |
|
567 | + } |
|
568 | + //make sure when we reset the registry's config that it |
|
569 | + //switches to using the new singleton |
|
570 | + EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true); |
|
571 | + EE_System::instance()->initialize_db_if_no_migrations_required(true); |
|
572 | + EE_System::instance()->redirect_to_about_ee(); |
|
573 | + } |
|
574 | + |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * Deletes ALL EE tables, Records, and Options from the database. |
|
579 | + */ |
|
580 | + public function _delete_db() |
|
581 | + { |
|
582 | + EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
583 | + EEH_Activation::delete_all_espresso_cpt_data(); |
|
584 | + EEH_Activation::delete_all_espresso_tables_and_data(); |
|
585 | + EEH_Activation::remove_cron_tasks(); |
|
586 | + EEH_Activation::deactivate_event_espresso(); |
|
587 | + wp_safe_redirect(admin_url('plugins.php')); |
|
588 | + exit; |
|
589 | + } |
|
590 | + |
|
591 | + |
|
592 | + |
|
593 | + /** |
|
594 | + * sets up EE4 to rerun the migrations from ee3 to ee4 |
|
595 | + */ |
|
596 | + public function _rerun_migration_from_ee3() |
|
597 | + { |
|
598 | + EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
599 | + EEH_Activation::delete_all_espresso_cpt_data(); |
|
600 | + EEH_Activation::delete_all_espresso_tables_and_data(false); |
|
601 | + //set the db state to something that will require migrations |
|
602 | + update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0'); |
|
603 | + EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance); |
|
604 | + $this->_redirect_after_action(true, esc_html__("Database", 'event_espresso'), esc_html__("reset", 'event_espresso')); |
|
605 | + } |
|
606 | + |
|
607 | + |
|
608 | + |
|
609 | + //none of the below group are currently used for Gateway Settings |
|
610 | + protected function _add_screen_options() |
|
611 | + { |
|
612 | + } |
|
613 | + |
|
614 | + |
|
615 | + |
|
616 | + protected function _add_feature_pointers() |
|
617 | + { |
|
618 | + } |
|
619 | + |
|
620 | 620 | |
621 | 621 | |
622 | - public function admin_init() |
|
623 | - { |
|
624 | - } |
|
625 | - |
|
626 | - |
|
627 | - |
|
628 | - public function admin_notices() |
|
629 | - { |
|
630 | - } |
|
631 | - |
|
622 | + public function admin_init() |
|
623 | + { |
|
624 | + } |
|
625 | + |
|
626 | + |
|
627 | + |
|
628 | + public function admin_notices() |
|
629 | + { |
|
630 | + } |
|
631 | + |
|
632 | 632 | |
633 | 633 | |
634 | - public function admin_footer_scripts() |
|
635 | - { |
|
636 | - } |
|
634 | + public function admin_footer_scripts() |
|
635 | + { |
|
636 | + } |
|
637 | 637 | |
638 | 638 | |
639 | 639 | |
640 | - public function load_scripts_styles() |
|
641 | - { |
|
642 | - wp_enqueue_script('ee_admin_js'); |
|
640 | + public function load_scripts_styles() |
|
641 | + { |
|
642 | + wp_enqueue_script('ee_admin_js'); |
|
643 | 643 | // wp_enqueue_media(); |
644 | 644 | // wp_enqueue_script('media-upload'); |
645 | - wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . '/ee-maintenance.js', array('jquery'), |
|
646 | - EVENT_ESPRESSO_VERSION, true); |
|
647 | - wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(), |
|
648 | - EVENT_ESPRESSO_VERSION); |
|
649 | - wp_enqueue_style('espresso_maintenance'); |
|
650 | - } |
|
645 | + wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . '/ee-maintenance.js', array('jquery'), |
|
646 | + EVENT_ESPRESSO_VERSION, true); |
|
647 | + wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(), |
|
648 | + EVENT_ESPRESSO_VERSION); |
|
649 | + wp_enqueue_style('espresso_maintenance'); |
|
650 | + } |
|
651 | 651 | |
652 | 652 | |
653 | 653 | |
654 | - public function load_scripts_styles_default() |
|
655 | - { |
|
656 | - //styles |
|
654 | + public function load_scripts_styles_default() |
|
655 | + { |
|
656 | + //styles |
|
657 | 657 | // wp_enqueue_style('ee-text-links'); |
658 | 658 | // //scripts |
659 | 659 | // wp_enqueue_script('ee-text-links'); |
660 | - } |
|
660 | + } |
|
661 | 661 | |
662 | 662 | |
663 | 663 |
@@ -244,13 +244,13 @@ discard block |
||
244 | 244 | && $most_recent_migration->is_broken() |
245 | 245 | ) |
246 | 246 | ) { |
247 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php'; |
|
247 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_migration_was_borked_page.template.php'; |
|
248 | 248 | $this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/'; |
249 | 249 | $this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action' => 'confirm_migration_crash_report_sent', |
250 | 250 | 'success' => '0', |
251 | 251 | ), EE_MAINTENANCE_ADMIN_URL); |
252 | 252 | } elseif ($addons_should_be_upgraded_first) { |
253 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php'; |
|
253 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_upgrade_addons_before_migrating.template.php'; |
|
254 | 254 | } else { |
255 | 255 | if ($most_recent_migration |
256 | 256 | && $most_recent_migration instanceof EE_Data_Migration_Script_Base |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | $this->_template_args['current_db_state'] = null; |
281 | 281 | $this->_template_args['next_db_state'] = null; |
282 | 282 | } |
283 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php'; |
|
283 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_migration_page.template.php'; |
|
284 | 284 | $this->_template_args = array_merge( |
285 | 285 | $this->_template_args, |
286 | 286 | array( |
@@ -319,13 +319,13 @@ discard block |
||
319 | 319 | 'status_completed' => EE_Data_Migration_Manager::status_completed, |
320 | 320 | )); |
321 | 321 | } |
322 | - $this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration |
|
322 | + $this->_template_args['most_recent_migration'] = $most_recent_migration; //the actual most recently ran migration |
|
323 | 323 | //now render the migration options part, and put it in a variable |
324 | 324 | $migration_options_template_file = apply_filters( |
325 | 325 | 'FHEE__ee_migration_page__migration_options_template', |
326 | - EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php' |
|
326 | + EE_MAINTENANCE_TEMPLATE_PATH.'migration_options_from_ee4.template.php' |
|
327 | 327 | ); |
328 | - $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true); |
|
328 | + $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args, true); |
|
329 | 329 | $this->_template_args['migration_options_html'] = $migration_options_html; |
330 | 330 | $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
331 | 331 | $this->_template_args, true); |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | */ |
385 | 385 | public function _data_reset_and_delete() |
386 | 386 | { |
387 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php'; |
|
387 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_data_reset_and_delete.template.php'; |
|
388 | 388 | $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button( |
389 | 389 | 'reset_reservations', |
390 | 390 | 'reset_reservations', |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | |
422 | 422 | protected function _reset_reservations() |
423 | 423 | { |
424 | - if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) { |
|
424 | + if (\EED_Ticket_Sales_Monitor::reset_reservation_counts()) { |
|
425 | 425 | EE_Error::add_success( |
426 | 426 | __( |
427 | 427 | 'Ticket and datetime reserved counts have been successfully reset.', |
@@ -469,7 +469,7 @@ discard block |
||
469 | 469 | */ |
470 | 470 | public function _system_status() |
471 | 471 | { |
472 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php'; |
|
472 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_system_stati_page.template.php'; |
|
473 | 473 | $this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati(); |
474 | 474 | $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce( |
475 | 475 | array( |
@@ -488,11 +488,11 @@ discard block |
||
488 | 488 | public function _download_system_status() |
489 | 489 | { |
490 | 490 | $status_info = EEM_System_Status::instance()->get_system_stati(); |
491 | - header( 'Content-Disposition: attachment' ); |
|
492 | - header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" ); |
|
491 | + header('Content-Disposition: attachment'); |
|
492 | + header("Content-Disposition: attachment; filename=system_status_".sanitize_key(site_url()).".html"); |
|
493 | 493 | echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>"; |
494 | - echo "<h1>System Information for " . site_url() . "</h1>"; |
|
495 | - echo EEH_Template::layout_array_as_table( $status_info ); |
|
494 | + echo "<h1>System Information for ".site_url()."</h1>"; |
|
495 | + echo EEH_Template::layout_array_as_table($status_info); |
|
496 | 496 | die; |
497 | 497 | } |
498 | 498 | |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | try { |
507 | 507 | $success = wp_mail(EE_SUPPORT_EMAIL, |
508 | 508 | 'Migration Crash Report', |
509 | - $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true), |
|
509 | + $body."/r/n<br>".print_r(EEM_System_Status::instance()->get_system_stati(), true), |
|
510 | 510 | array( |
511 | 511 | "from:$from_name<$from>", |
512 | 512 | // 'content-type:text/html charset=UTF-8' |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | EE_MAINTENANCE_ADMIN_URL); |
542 | 542 | $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'), |
543 | 543 | EE_MAINTENANCE_ADMIN_URL); |
544 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php'; |
|
544 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_confirm_migration_crash_report_sent.template.php'; |
|
545 | 545 | $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
546 | 546 | $this->_template_args, true); |
547 | 547 | $this->display_admin_page_with_sidebar(); |
@@ -642,9 +642,9 @@ discard block |
||
642 | 642 | wp_enqueue_script('ee_admin_js'); |
643 | 643 | // wp_enqueue_media(); |
644 | 644 | // wp_enqueue_script('media-upload'); |
645 | - wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . '/ee-maintenance.js', array('jquery'), |
|
645 | + wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL.'/ee-maintenance.js', array('jquery'), |
|
646 | 646 | EVENT_ESPRESSO_VERSION, true); |
647 | - wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(), |
|
647 | + wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL.'ee-maintenance.css', array(), |
|
648 | 648 | EVENT_ESPRESSO_VERSION); |
649 | 649 | wp_enqueue_style('espresso_maintenance'); |
650 | 650 | } |