1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
defined('EVENT_ESPRESSO_VERSION') || exit('No direct access allowed.'); |
4
|
|
|
|
5
|
|
|
use EventEspressoBatchRequest\JobHandlers\DatetimeOffsetFix; |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Event Espresso |
10
|
|
|
* Event Registration and Management Plugin for Wordpress |
11
|
|
|
* |
12
|
|
|
* @package Event Espresso |
13
|
|
|
* @author Seth Shoultes |
14
|
|
|
* @copyright (c)2009-2012 Event Espresso All Rights Reserved. |
15
|
|
|
* @license http://eventespresso.com/support/terms-conditions/ ** see Plugin Licensing ** |
16
|
|
|
* @link http://www.eventespresso.com |
17
|
|
|
* @version 4.0 |
18
|
|
|
* ------------------------------------------------------------------------ |
19
|
|
|
* Maintenance_Admin_Page |
20
|
|
|
* This contains the logic for setting up the Event Maintenance related admin pages. Any methods |
21
|
|
|
* without phpdoc comments have inline docs with parent class. |
22
|
|
|
* @package Maintenance_Admin_Page |
23
|
|
|
* @subpackage includes/core/admin/Maintenance_Admin_Page.core.php |
24
|
|
|
* @author Darren Ethier |
25
|
|
|
* ------------------------------------------------------------------------ |
26
|
|
|
*/ |
27
|
|
|
class Maintenance_Admin_Page extends EE_Admin_Page |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var EE_Datetime_Offset_Fix_Form |
33
|
|
|
*/ |
34
|
|
|
protected $datetime_fix_offset_form; |
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
|
|
|
'datetime_tools' => array( |
141
|
|
|
'func' => '_datetime_tools', |
142
|
|
|
'capability' => 'manage_options' |
143
|
|
|
), |
144
|
|
|
'run_datetime_offset_fix' => array( |
145
|
|
|
'func' => '_apply_datetime_offset', |
146
|
|
|
'noheader' => true, |
147
|
|
|
'headers_sent_route' => 'datetime_tools', |
148
|
|
|
'capability' => 'manage_options' |
149
|
|
|
) |
150
|
|
|
); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
|
154
|
|
|
|
155
|
|
|
protected function _set_page_config() |
156
|
|
|
{ |
157
|
|
|
$this->_page_config = array( |
158
|
|
|
'default' => array( |
159
|
|
|
'nav' => array( |
160
|
|
|
'label' => esc_html__('Maintenance', 'event_espresso'), |
161
|
|
|
'order' => 10, |
162
|
|
|
), |
163
|
|
|
'require_nonce' => false, |
164
|
|
|
), |
165
|
|
|
'data_reset' => array( |
166
|
|
|
'nav' => array( |
167
|
|
|
'label' => esc_html__('Reset/Delete Data', 'event_espresso'), |
168
|
|
|
'order' => 20, |
169
|
|
|
), |
170
|
|
|
'require_nonce' => false, |
171
|
|
|
), |
172
|
|
|
'datetime_tools' => array( |
173
|
|
|
'nav' => array( |
174
|
|
|
'label' => esc_html__('Datetime Utilities', 'event_espresso'), |
175
|
|
|
'order' => 25 |
176
|
|
|
), |
177
|
|
|
'require_nonce' => false, |
178
|
|
|
), |
179
|
|
|
'system_status' => array( |
180
|
|
|
'nav' => array( |
181
|
|
|
'label' => esc_html__("System Information", "event_espresso"), |
182
|
|
|
'order' => 30, |
183
|
|
|
), |
184
|
|
|
'require_nonce' => false, |
185
|
|
|
), |
186
|
|
|
); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
|
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* default maintenance page. If we're in maintenance mode level 2, then we need to show |
193
|
|
|
* the migration scripts and all that UI. |
194
|
|
|
*/ |
195
|
|
|
public function _maintenance() |
196
|
|
|
{ |
197
|
|
|
//it all depends if we're in maintenance model level 1 (frontend-only) or |
198
|
|
|
//level 2 (everything except maintenance page) |
199
|
|
|
try { |
200
|
|
|
//get the current maintenance level and check if |
201
|
|
|
//we are removed |
202
|
|
|
$mm = EE_Maintenance_Mode::instance()->level(); |
203
|
|
|
$placed_in_mm = EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
204
|
|
|
if ($mm == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) { |
205
|
|
|
//we just took the site out of maintenance mode, so notify the user. |
206
|
|
|
//unfortunately this message appears to be echoed on the NEXT page load... |
207
|
|
|
//oh well, we should really be checking for this on addon deactivation anyways |
208
|
|
|
EE_Error::add_attention(__('Site taken out of maintenance mode because no data migration scripts are required', |
209
|
|
|
'event_espresso')); |
210
|
|
|
$this->_process_notices(array('page' => 'espresso_maintenance_settings'), false); |
211
|
|
|
} |
212
|
|
|
//in case an exception is thrown while trying to handle migrations |
213
|
|
|
switch (EE_Maintenance_Mode::instance()->level()) { |
214
|
|
|
case EE_Maintenance_Mode::level_0_not_in_maintenance: |
215
|
|
|
case EE_Maintenance_Mode::level_1_frontend_only_maintenance: |
216
|
|
|
$show_maintenance_switch = true; |
217
|
|
|
$show_backup_db_text = false; |
218
|
|
|
$show_migration_progress = false; |
219
|
|
|
$script_names = array(); |
220
|
|
|
$addons_should_be_upgraded_first = false; |
221
|
|
|
break; |
222
|
|
|
case EE_Maintenance_Mode::level_2_complete_maintenance: |
223
|
|
|
$show_maintenance_switch = false; |
224
|
|
|
$show_migration_progress = true; |
225
|
|
|
if (isset($this->_req_data['continue_migration'])) { |
226
|
|
|
$show_backup_db_text = false; |
227
|
|
|
} else { |
228
|
|
|
$show_backup_db_text = true; |
229
|
|
|
} |
230
|
|
|
$scripts_needing_to_run = EE_Data_Migration_Manager::instance() |
231
|
|
|
->check_for_applicable_data_migration_scripts(); |
232
|
|
|
$addons_should_be_upgraded_first = EE_Data_Migration_Manager::instance()->addons_need_updating(); |
233
|
|
|
$script_names = array(); |
234
|
|
|
$current_script = null; |
235
|
|
|
foreach ($scripts_needing_to_run as $script) { |
236
|
|
|
if ($script instanceof EE_Data_Migration_Script_Base) { |
237
|
|
|
if ( ! $current_script) { |
238
|
|
|
$current_script = $script; |
239
|
|
|
$current_script->migration_page_hooks(); |
240
|
|
|
} |
241
|
|
|
$script_names[] = $script->pretty_name(); |
242
|
|
|
} |
243
|
|
|
} |
244
|
|
|
break; |
245
|
|
|
} |
246
|
|
|
$most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true); |
247
|
|
|
$exception_thrown = false; |
248
|
|
|
} catch (EE_Error $e) { |
249
|
|
|
EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage()); |
250
|
|
|
//now, just so we can display the page correctly, make a error migration script stage object |
251
|
|
|
//and also put the error on it. It only persists for the duration of this request |
252
|
|
|
$most_recent_migration = new EE_DMS_Unknown_1_0_0(); |
253
|
|
|
$most_recent_migration->add_error($e->getMessage()); |
254
|
|
|
$exception_thrown = true; |
255
|
|
|
} |
256
|
|
|
$current_db_state = EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set(); |
257
|
|
|
$current_db_state = str_replace('.decaf', '', $current_db_state); |
258
|
|
|
if ($exception_thrown |
259
|
|
|
|| ($most_recent_migration |
260
|
|
|
&& $most_recent_migration instanceof EE_Data_Migration_Script_Base |
261
|
|
|
&& $most_recent_migration->is_broken() |
262
|
|
|
) |
263
|
|
|
) { |
264
|
|
|
$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php'; |
265
|
|
|
$this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/'; |
266
|
|
|
$this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action' => 'confirm_migration_crash_report_sent', |
267
|
|
|
'success' => '0', |
268
|
|
|
), EE_MAINTENANCE_ADMIN_URL); |
269
|
|
|
} elseif ($addons_should_be_upgraded_first) { |
270
|
|
|
$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php'; |
271
|
|
|
} else { |
272
|
|
|
if ($most_recent_migration |
273
|
|
|
&& $most_recent_migration instanceof EE_Data_Migration_Script_Base |
274
|
|
|
&& $most_recent_migration->can_continue() |
275
|
|
|
) { |
276
|
|
|
$show_backup_db_text = false; |
277
|
|
|
$show_continue_current_migration_script = true; |
278
|
|
|
$show_most_recent_migration = true; |
279
|
|
|
} elseif (isset($this->_req_data['continue_migration'])) { |
280
|
|
|
$show_most_recent_migration = true; |
281
|
|
|
$show_continue_current_migration_script = false; |
282
|
|
|
} else { |
283
|
|
|
$show_most_recent_migration = false; |
284
|
|
|
$show_continue_current_migration_script = false; |
285
|
|
|
} |
286
|
|
|
if (isset($current_script)) { |
287
|
|
|
$migrates_to = $current_script->migrates_to_version(); |
288
|
|
|
$plugin_slug = $migrates_to['slug']; |
289
|
|
|
$new_version = $migrates_to['version']; |
290
|
|
|
$this->_template_args = array_merge($this->_template_args, array( |
291
|
|
|
'current_db_state' => sprintf(__("EE%s (%s)", "event_espresso"), |
292
|
|
|
isset($current_db_state[$plugin_slug]) ? $current_db_state[$plugin_slug] : 3, $plugin_slug), |
293
|
|
|
'next_db_state' => isset($current_script) ? sprintf(__("EE%s (%s)", 'event_espresso'), |
294
|
|
|
$new_version, $plugin_slug) : null, |
295
|
|
|
)); |
296
|
|
|
} else { |
297
|
|
|
$this->_template_args['current_db_state'] = null; |
298
|
|
|
$this->_template_args['next_db_state'] = null; |
299
|
|
|
} |
300
|
|
|
$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php'; |
301
|
|
|
$this->_template_args = array_merge( |
302
|
|
|
$this->_template_args, |
303
|
|
|
array( |
304
|
|
|
'show_most_recent_migration' => $show_most_recent_migration, |
305
|
|
|
//flag for showing the most recent migration's status and/or errors |
306
|
|
|
'show_migration_progress' => $show_migration_progress, |
307
|
|
|
//flag for showing the option to run migrations and see their progress |
308
|
|
|
'show_backup_db_text' => $show_backup_db_text, |
309
|
|
|
//flag for showing text telling the user to backup their DB |
310
|
|
|
'show_maintenance_switch' => $show_maintenance_switch, |
311
|
|
|
//flag for showing the option to change maintenance mode between levels 0 and 1 |
312
|
|
|
'script_names' => $script_names, |
313
|
|
|
//array of names of scripts that have run |
314
|
|
|
'show_continue_current_migration_script' => $show_continue_current_migration_script, |
315
|
|
|
//flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0 |
316
|
|
|
'reset_db_page_link' => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'), |
317
|
|
|
EE_MAINTENANCE_ADMIN_URL), |
318
|
|
|
'data_reset_page' => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'), |
319
|
|
|
EE_MAINTENANCE_ADMIN_URL), |
320
|
|
|
'update_migration_script_page_link' => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'change_maintenance_level'), |
321
|
|
|
EE_MAINTENANCE_ADMIN_URL), |
322
|
|
|
'ultimate_db_state' => sprintf(__("EE%s", 'event_espresso'), |
323
|
|
|
espresso_version()), |
324
|
|
|
) |
325
|
|
|
); |
326
|
|
|
//make sure we have the form fields helper available. It usually is, but sometimes it isn't |
327
|
|
|
//localize script stuff |
328
|
|
|
wp_localize_script('ee-maintenance', 'ee_maintenance', array( |
329
|
|
|
'migrating' => esc_html__("Updating Database...", "event_espresso"), |
330
|
|
|
'next' => esc_html__("Next", "event_espresso"), |
331
|
|
|
'fatal_error' => esc_html__("A Fatal Error Has Occurred", "event_espresso"), |
332
|
|
|
'click_next_when_ready' => esc_html__("The current Database Update has ended. Click 'next' when ready to proceed", |
333
|
|
|
"event_espresso"), |
334
|
|
|
'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts, |
335
|
|
|
'status_fatal_error' => EE_Data_Migration_Manager::status_fatal_error, |
336
|
|
|
'status_completed' => EE_Data_Migration_Manager::status_completed, |
337
|
|
|
)); |
338
|
|
|
} |
339
|
|
|
$this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration |
340
|
|
|
//now render the migration options part, and put it in a variable |
341
|
|
|
$migration_options_template_file = apply_filters( |
342
|
|
|
'FHEE__ee_migration_page__migration_options_template', |
343
|
|
|
EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php' |
344
|
|
|
); |
345
|
|
|
$migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true); |
346
|
|
|
$this->_template_args['migration_options_html'] = $migration_options_html; |
347
|
|
|
$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
348
|
|
|
$this->_template_args, true); |
349
|
|
|
$this->display_admin_page_with_sidebar(); |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
|
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* returns JSON and executes another step of the currently-executing data migration (called via ajax) |
356
|
|
|
*/ |
357
|
|
|
public function migration_step() |
358
|
|
|
{ |
359
|
|
|
$this->_template_args['data'] = EE_Data_Migration_Manager::instance()->response_to_migration_ajax_request(); |
360
|
|
|
$this->_return_json(); |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
|
364
|
|
|
|
365
|
|
|
/** |
366
|
|
|
* Can be used by js when it notices a response with HTML in it in order |
367
|
|
|
* to log the malformed response |
368
|
|
|
*/ |
369
|
|
|
public function add_error_to_migrations_ran() |
370
|
|
|
{ |
371
|
|
|
EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($this->_req_data['message']); |
372
|
|
|
$this->_template_args['data'] = array('ok' => true); |
373
|
|
|
$this->_return_json(); |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
|
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* changes the maintenance level, provided there are still no migration scripts that should run |
380
|
|
|
*/ |
381
|
|
|
public function _change_maintenance_level() |
382
|
|
|
{ |
383
|
|
|
$new_level = absint($this->_req_data['maintenance_mode_level']); |
384
|
|
|
if ( ! EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) { |
385
|
|
|
EE_Maintenance_Mode::instance()->set_maintenance_level($new_level); |
386
|
|
|
$success = true; |
387
|
|
|
} else { |
388
|
|
|
EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
389
|
|
|
$success = false; |
390
|
|
|
} |
391
|
|
|
$this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso")); |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
|
395
|
|
|
|
396
|
|
|
/** |
397
|
|
|
* a tab with options for resetting and/or deleting EE data |
398
|
|
|
* |
399
|
|
|
* @throws \EE_Error |
400
|
|
|
* @throws \DomainException |
401
|
|
|
*/ |
402
|
|
|
public function _data_reset_and_delete() |
403
|
|
|
{ |
404
|
|
|
$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php'; |
405
|
|
|
$this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button( |
406
|
|
|
'reset_reservations', |
407
|
|
|
'reset_reservations', |
408
|
|
|
array(), |
409
|
|
|
'button button-primary', |
410
|
|
|
'', |
411
|
|
|
false |
412
|
|
|
); |
413
|
|
|
$this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button( |
414
|
|
|
'reset_capabilities', |
415
|
|
|
'reset_capabilities', |
416
|
|
|
array(), |
417
|
|
|
'button button-primary', |
418
|
|
|
'', |
419
|
|
|
false |
420
|
|
|
); |
421
|
|
|
$this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce( |
422
|
|
|
array('action' => 'delete_db'), |
423
|
|
|
EE_MAINTENANCE_ADMIN_URL |
424
|
|
|
); |
425
|
|
|
$this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce( |
426
|
|
|
array('action' => 'reset_db'), |
427
|
|
|
EE_MAINTENANCE_ADMIN_URL |
428
|
|
|
); |
429
|
|
|
$this->_template_args['admin_page_content'] = EEH_Template::display_template( |
430
|
|
|
$this->_template_path, |
431
|
|
|
$this->_template_args, |
432
|
|
|
true |
433
|
|
|
); |
434
|
|
|
$this->display_admin_page_with_sidebar(); |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
|
438
|
|
|
|
439
|
|
|
protected function _reset_reservations() |
440
|
|
|
{ |
441
|
|
|
if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) { |
442
|
|
|
EE_Error::add_success( |
443
|
|
|
__( |
444
|
|
|
'Ticket and datetime reserved counts have been successfully reset.', |
445
|
|
|
'event_espresso' |
446
|
|
|
) |
447
|
|
|
); |
448
|
|
|
} else { |
449
|
|
|
EE_Error::add_success( |
450
|
|
|
__( |
451
|
|
|
'Ticket and datetime reserved counts were correct and did not need resetting.', |
452
|
|
|
'event_espresso' |
453
|
|
|
) |
454
|
|
|
); |
455
|
|
|
} |
456
|
|
|
$this->_redirect_after_action(true, '', '', array('action' => 'data_reset'), true); |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
|
460
|
|
|
|
461
|
|
|
protected function _reset_capabilities() |
462
|
|
|
{ |
463
|
|
|
EE_Registry::instance()->CAP->init_caps(true); |
464
|
|
|
EE_Error::add_success(__('Default Event Espresso capabilities have been restored for all current roles.', |
465
|
|
|
'event_espresso')); |
466
|
|
|
$this->_redirect_after_action(false, '', '', array('action' => 'data_reset'), true); |
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
|
470
|
|
|
|
471
|
|
|
/** |
472
|
|
|
* resets the DMSs so we can attempt to continue migrating after a fatal error |
473
|
|
|
* (only a good idea when someone has somehow tried ot fix whatever caused |
474
|
|
|
* the fatal error in teh first place) |
475
|
|
|
*/ |
476
|
|
|
protected function _reattempt_migration() |
477
|
|
|
{ |
478
|
|
|
EE_Data_Migration_Manager::instance()->reattempt(); |
479
|
|
|
$this->_redirect_after_action(false, '', '', array('action' => 'default'), true); |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
|
483
|
|
|
|
484
|
|
|
/** |
485
|
|
|
* shows the big ol' System Information page |
486
|
|
|
*/ |
487
|
|
|
public function _system_status() |
488
|
|
|
{ |
489
|
|
|
$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php'; |
490
|
|
|
$this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati(); |
491
|
|
|
$this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce( |
492
|
|
|
array( |
493
|
|
|
'action' => 'download_system_status', |
494
|
|
|
), |
495
|
|
|
EE_MAINTENANCE_ADMIN_URL |
496
|
|
|
); |
497
|
|
|
$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
498
|
|
|
$this->_template_args, true); |
499
|
|
|
$this->display_admin_page_with_sidebar(); |
500
|
|
|
} |
501
|
|
|
|
502
|
|
|
/** |
503
|
|
|
* Downloads an HTML file of the system status that can be easily stored or emailed |
504
|
|
|
*/ |
505
|
|
|
public function _download_system_status() |
506
|
|
|
{ |
507
|
|
|
$status_info = EEM_System_Status::instance()->get_system_stati(); |
508
|
|
|
header( 'Content-Disposition: attachment' ); |
509
|
|
|
header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" ); |
510
|
|
|
echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>"; |
511
|
|
|
echo "<h1>System Information for " . site_url() . "</h1>"; |
512
|
|
|
echo EEH_Template::layout_array_as_table( $status_info ); |
513
|
|
|
die; |
514
|
|
|
} |
515
|
|
|
|
516
|
|
|
|
517
|
|
|
|
518
|
|
|
public function _send_migration_crash_report() |
519
|
|
|
{ |
520
|
|
|
$from = $this->_req_data['from']; |
521
|
|
|
$from_name = $this->_req_data['from_name']; |
522
|
|
|
$body = $this->_req_data['body']; |
523
|
|
|
try { |
524
|
|
|
$success = wp_mail(EE_SUPPORT_EMAIL, |
525
|
|
|
'Migration Crash Report', |
526
|
|
|
$body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true), |
527
|
|
|
array( |
528
|
|
|
"from:$from_name<$from>", |
529
|
|
|
// 'content-type:text/html charset=UTF-8' |
530
|
|
|
)); |
531
|
|
|
} catch (Exception $e) { |
532
|
|
|
$success = false; |
533
|
|
|
} |
534
|
|
|
$this->_redirect_after_action($success, esc_html__("Migration Crash Report", "event_espresso"), |
535
|
|
|
esc_html__("sent", "event_espresso"), |
536
|
|
|
array('success' => $success, 'action' => 'confirm_migration_crash_report_sent')); |
537
|
|
|
} |
538
|
|
|
|
539
|
|
|
|
540
|
|
|
|
541
|
|
|
public function _confirm_migration_crash_report_sent() |
542
|
|
|
{ |
543
|
|
|
try { |
544
|
|
|
$most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true); |
545
|
|
|
} catch (EE_Error $e) { |
546
|
|
|
EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage()); |
547
|
|
|
//now, just so we can display the page correctly, make a error migration script stage object |
548
|
|
|
//and also put the error on it. It only persists for the duration of this request |
549
|
|
|
$most_recent_migration = new EE_DMS_Unknown_1_0_0(); |
550
|
|
|
$most_recent_migration->add_error($e->getMessage()); |
551
|
|
|
} |
552
|
|
|
$success = $this->_req_data['success'] == '1' ? true : false; |
553
|
|
|
$this->_template_args['success'] = $success; |
554
|
|
|
$this->_template_args['most_recent_migration'] = $most_recent_migration; |
555
|
|
|
$this->_template_args['reset_db_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'), |
556
|
|
|
EE_MAINTENANCE_ADMIN_URL); |
557
|
|
|
$this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'), |
558
|
|
|
EE_MAINTENANCE_ADMIN_URL); |
559
|
|
|
$this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'), |
560
|
|
|
EE_MAINTENANCE_ADMIN_URL); |
561
|
|
|
$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php'; |
562
|
|
|
$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
563
|
|
|
$this->_template_args, true); |
564
|
|
|
$this->display_admin_page_with_sidebar(); |
565
|
|
|
} |
566
|
|
|
|
567
|
|
|
|
568
|
|
|
|
569
|
|
|
/** |
570
|
|
|
* Resets the entire EE4 database. |
571
|
|
|
* Currently basically only sets up ee4 database for a fresh install- doesn't |
572
|
|
|
* actually clean out the old wp options, or cpts (although does erase old ee table data) |
573
|
|
|
* |
574
|
|
|
* @param boolean $nuke_old_ee4_data controls whether or not we |
575
|
|
|
* destroy the old ee4 data, or just try initializing ee4 default data |
576
|
|
|
*/ |
577
|
|
|
public function _reset_db($nuke_old_ee4_data = true) |
578
|
|
|
{ |
579
|
|
|
EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance); |
580
|
|
|
if ($nuke_old_ee4_data) { |
581
|
|
|
EEH_Activation::delete_all_espresso_cpt_data(); |
582
|
|
|
EEH_Activation::delete_all_espresso_tables_and_data(false); |
583
|
|
|
EEH_Activation::remove_cron_tasks(); |
584
|
|
|
} |
585
|
|
|
//make sure when we reset the registry's config that it |
586
|
|
|
//switches to using the new singleton |
587
|
|
|
EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true); |
588
|
|
|
EE_System::instance()->initialize_db_if_no_migrations_required(true); |
589
|
|
|
EE_System::instance()->redirect_to_about_ee(); |
590
|
|
|
} |
591
|
|
|
|
592
|
|
|
|
593
|
|
|
|
594
|
|
|
/** |
595
|
|
|
* Deletes ALL EE tables, Records, and Options from the database. |
596
|
|
|
*/ |
597
|
|
|
public function _delete_db() |
598
|
|
|
{ |
599
|
|
|
EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance); |
600
|
|
|
EEH_Activation::delete_all_espresso_cpt_data(); |
601
|
|
|
EEH_Activation::delete_all_espresso_tables_and_data(); |
602
|
|
|
EEH_Activation::remove_cron_tasks(); |
603
|
|
|
EEH_Activation::deactivate_event_espresso(); |
604
|
|
|
wp_safe_redirect(admin_url('plugins.php')); |
605
|
|
|
exit; |
606
|
|
|
} |
607
|
|
|
|
608
|
|
|
|
609
|
|
|
|
610
|
|
|
/** |
611
|
|
|
* sets up EE4 to rerun the migrations from ee3 to ee4 |
612
|
|
|
*/ |
613
|
|
|
public function _rerun_migration_from_ee3() |
614
|
|
|
{ |
615
|
|
|
EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance); |
616
|
|
|
EEH_Activation::delete_all_espresso_cpt_data(); |
617
|
|
|
EEH_Activation::delete_all_espresso_tables_and_data(false); |
618
|
|
|
//set the db state to something that will require migrations |
619
|
|
|
update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0'); |
620
|
|
|
EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance); |
621
|
|
|
$this->_redirect_after_action(true, esc_html__("Database", 'event_espresso'), esc_html__("reset", 'event_espresso')); |
622
|
|
|
} |
623
|
|
|
|
624
|
|
|
|
625
|
|
|
|
626
|
|
|
//none of the below group are currently used for Gateway Settings |
627
|
|
|
protected function _add_screen_options() |
628
|
|
|
{ |
629
|
|
|
} |
630
|
|
|
|
631
|
|
|
|
632
|
|
|
|
633
|
|
|
protected function _add_feature_pointers() |
634
|
|
|
{ |
635
|
|
|
} |
636
|
|
|
|
637
|
|
|
|
638
|
|
|
|
639
|
|
|
public function admin_init() |
640
|
|
|
{ |
641
|
|
|
} |
642
|
|
|
|
643
|
|
|
|
644
|
|
|
|
645
|
|
|
public function admin_notices() |
646
|
|
|
{ |
647
|
|
|
} |
648
|
|
|
|
649
|
|
|
|
650
|
|
|
|
651
|
|
|
public function admin_footer_scripts() |
652
|
|
|
{ |
653
|
|
|
} |
654
|
|
|
|
655
|
|
|
|
656
|
|
|
|
657
|
|
|
public function load_scripts_styles() |
658
|
|
|
{ |
659
|
|
|
wp_enqueue_script('ee_admin_js'); |
660
|
|
|
// wp_enqueue_media(); |
661
|
|
|
// wp_enqueue_script('media-upload'); |
662
|
|
|
wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . '/ee-maintenance.js', array('jquery'), |
663
|
|
|
EVENT_ESPRESSO_VERSION, true); |
664
|
|
|
wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(), |
665
|
|
|
EVENT_ESPRESSO_VERSION); |
666
|
|
|
wp_enqueue_style('espresso_maintenance'); |
667
|
|
|
} |
668
|
|
|
|
669
|
|
|
|
670
|
|
|
|
671
|
|
|
public function load_scripts_styles_default() |
672
|
|
|
{ |
673
|
|
|
//styles |
674
|
|
|
// wp_enqueue_style('ee-text-links'); |
675
|
|
|
// //scripts |
676
|
|
|
// wp_enqueue_script('ee-text-links'); |
677
|
|
|
} |
678
|
|
|
|
679
|
|
|
|
680
|
|
|
protected function _datetime_tools() |
681
|
|
|
{ |
682
|
|
|
$form_action = EE_Admin_Page::add_query_args_and_nonce( |
683
|
|
|
array( |
684
|
|
|
'action' => 'run_datetime_offset_fix', |
685
|
|
|
'return_action' => $this->_req_action |
686
|
|
|
), |
687
|
|
|
EE_MAINTENANCE_ADMIN_URL |
688
|
|
|
); |
689
|
|
|
$form = $this->_get_datetime_offset_fix_form(); |
690
|
|
|
$this->_admin_page_title = esc_html__('Datetime Utilities', 'event_espresso'); |
691
|
|
|
$this->_template_args['admin_page_content'] = $form->form_open($form_action, 'post') |
692
|
|
|
. $form->get_html_and_js() |
693
|
|
|
. $form->form_close(); |
694
|
|
|
$this->display_admin_page_with_no_sidebar(); |
695
|
|
|
} |
696
|
|
|
|
697
|
|
|
|
698
|
|
|
|
699
|
|
|
protected function _get_datetime_offset_fix_form() |
700
|
|
|
{ |
701
|
|
|
if (! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) { |
702
|
|
|
$this->datetime_fix_offset_form = new EE_Form_Section_Proper( |
703
|
|
|
array( |
704
|
|
|
'name' => 'datetime_offset_fix_option', |
705
|
|
|
'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
706
|
|
|
'subsections' => array( |
707
|
|
|
'title' => new EE_Form_Section_HTML( |
708
|
|
|
EEH_HTML::h2( |
709
|
|
|
esc_html__('Datetime Offset Tool', 'event_espresso') |
710
|
|
|
) |
711
|
|
|
), |
712
|
|
|
'explanation' => new EE_Form_Section_HTML( |
713
|
|
|
EEH_HTML::p( |
714
|
|
|
esc_html__( |
715
|
|
|
'Use this tool to automatically apply the provided offset to all Event Espresso records in your database that involve dates and times.', |
716
|
|
|
'event_espresso' |
717
|
|
|
) |
718
|
|
|
) |
719
|
|
|
. EEH_HTML::p( |
720
|
|
|
esc_html__( |
721
|
|
|
'Note: If you enter 1.25, that will result in the offset of 1 hour 15 minutes being applied. Decimals represent the fraction of hours, not minutes.', |
722
|
|
|
'event_espresso' |
723
|
|
|
) |
724
|
|
|
) |
725
|
|
|
), |
726
|
|
|
'offset_input' => new EE_Float_Input( |
727
|
|
|
array( |
728
|
|
|
'html_name' => 'offset_for_datetimes', |
729
|
|
|
'html_label_text' => esc_html__( |
730
|
|
|
'Offset to apply (in hours):', |
731
|
|
|
'event_espresso' |
732
|
|
|
), |
733
|
|
|
'min_value' => '-12', |
734
|
|
|
'max_value' => '14', |
735
|
|
|
'step_value' => '.25', |
736
|
|
|
'default' => DatetimeOffsetFix::getOffset() |
737
|
|
|
) |
738
|
|
|
), |
739
|
|
|
'submit' => new EE_Submit_Input( |
740
|
|
|
array( |
741
|
|
|
'html_label_text' => '', |
742
|
|
|
'default' => esc_html__('Apply Offset', 'event_espresso') |
743
|
|
|
) |
744
|
|
|
) |
745
|
|
|
) |
746
|
|
|
) |
747
|
|
|
); |
748
|
|
|
} |
749
|
|
|
return $this->datetime_fix_offset_form; |
750
|
|
|
} |
751
|
|
|
|
752
|
|
|
|
753
|
|
|
/** |
754
|
|
|
* Callback for the run_datetime_offset_fix route. |
755
|
|
|
* @throws EE_Error |
756
|
|
|
*/ |
757
|
|
|
protected function _apply_datetime_offset() |
758
|
|
|
{ |
759
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') { |
760
|
|
|
$form = $this->_get_datetime_offset_fix_form(); |
761
|
|
|
$form->receive_form_submission($this->_req_data); |
762
|
|
|
if ($form->is_valid()) { |
763
|
|
|
//save offset so batch processor can get it. |
764
|
|
|
DatetimeOffsetFix::updateOffset($form->get_input_value('offset_input')); |
765
|
|
|
//redirect to batch tool |
766
|
|
|
wp_redirect( |
767
|
|
|
EE_Admin_Page::add_query_args_and_nonce( |
768
|
|
|
array( |
769
|
|
|
'page' => 'espresso_batch', |
770
|
|
|
'batch' => 'job', |
771
|
|
|
'label' => esc_html__('Applying Offset', 'event_espresso'), |
772
|
|
|
'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\DatetimeOffsetFix'), |
773
|
|
|
'return_url' => urlencode(home_url(add_query_arg(null, null))), |
774
|
|
|
), |
775
|
|
|
admin_url() |
776
|
|
|
) |
777
|
|
|
); |
778
|
|
|
exit; |
779
|
|
|
} |
780
|
|
|
} |
781
|
|
|
} |
782
|
|
|
} //end Maintenance_Admin_Page class |
783
|
|
|
|