Completed
Branch BUG-10626-DST-UNIT-TEST-2 (9b6d15)
by
unknown
62:42 queued 49:10
created

Maintenance_Admin_Page   C

Complexity

Total Complexity 56

Size/Duplication

Total Lines 635
Duplicated Lines 4.09 %

Coupling/Cohesion

Components 5
Dependencies 15

Importance

Changes 0
Metric Value
dl 26
loc 635
rs 5.1666
c 0
b 0
f 0
wmc 56
lcom 5
cbo 15

28 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A _init_page_props() 0 7 1
A _ajax_hooks() 0 5 1
A _define_page_props() 0 10 1
A _set_page_routes() 0 73 1
B _set_page_config() 26 26 1
F _maintenance() 0 153 23
A migration_step() 0 5 1
A add_error_to_migrations_ran() 0 6 1
A _change_maintenance_level() 0 12 2
B _data_reset_and_delete() 0 34 1
A _reset_reservations() 0 19 2
A _reset_capabilities() 0 7 1
A _reattempt_migration() 0 5 1
A _system_status() 0 14 1
A _download_system_status() 0 10 1
A _send_migration_crash_report() 0 20 2
B _confirm_migration_crash_report_sent() 0 25 3
A _reset_db() 0 14 2
A _delete_db() 0 10 1
A _rerun_migration_from_ee3() 0 10 1
A _add_screen_options() 0 3 1
A _add_feature_pointers() 0 3 1
A admin_init() 0 3 1
A admin_notices() 0 3 1
A admin_footer_scripts() 0 3 1
A load_scripts_styles() 0 11 1
A load_scripts_styles_default() 0 7 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Maintenance_Admin_Page often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Maintenance_Admin_Page, and based on these observations, apply Extract Interface, too.

1
<?php
2
if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
    exit('NO direct script access allowed');
4
}
5
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
    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 View Code Duplication
    protected function _set_page_config()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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) {
0 ignored issues
show
Bug introduced by
The variable $addons_should_be_upgraded_first does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
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
            }
280
            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
281
            $this->_template_args = array_merge(
282
                $this->_template_args,
283
                array(
284
                    'show_most_recent_migration'             => $show_most_recent_migration,
285
                    //flag for showing the most recent migration's status and/or errors
286
                    'show_migration_progress'                => $show_migration_progress,
0 ignored issues
show
Bug introduced by
The variable $show_migration_progress does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
287
                    //flag for showing the option to run migrations and see their progress
288
                    'show_backup_db_text'                    => $show_backup_db_text,
0 ignored issues
show
Bug introduced by
The variable $show_backup_db_text does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
289
                    //flag for showing text telling the user to backup their DB
290
                    'show_maintenance_switch'                => $show_maintenance_switch,
0 ignored issues
show
Bug introduced by
The variable $show_maintenance_switch does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
291
                    //flag for showing the option to change maintenance mode between levels 0 and 1
292
                    'script_names'                           => $script_names,
0 ignored issues
show
Bug introduced by
The variable $script_names does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
293
                    //array of names of scripts that have run
294
                    'show_continue_current_migration_script' => $show_continue_current_migration_script,
295
                    //flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0
296
                    'reset_db_page_link'                     => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'),
297
                        EE_MAINTENANCE_ADMIN_URL),
298
                    'data_reset_page'                        => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'),
299
                        EE_MAINTENANCE_ADMIN_URL),
300
                    'update_migration_script_page_link'      => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'change_maintenance_level'),
301
                        EE_MAINTENANCE_ADMIN_URL),
302
                    'ultimate_db_state'                      => sprintf(__("EE%s", 'event_espresso'),
303
                        espresso_version()),
304
                )
305
            );
306
            //make sure we have the form fields helper available. It usually is, but sometimes it isn't
307
            //localize script stuff
308
            wp_localize_script('ee-maintenance', 'ee_maintenance', array(
309
                'migrating'                        => esc_html__("Updating Database...", "event_espresso"),
310
                'next'                             => esc_html__("Next", "event_espresso"),
311
                'fatal_error'                      => esc_html__("A Fatal Error Has Occurred", "event_espresso"),
312
                'click_next_when_ready'            => esc_html__("The current Database Update has ended. Click 'next' when ready to proceed",
313
                    "event_espresso"),
314
                'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts,
315
                'status_fatal_error'               => EE_Data_Migration_Manager::status_fatal_error,
316
                'status_completed'                 => EE_Data_Migration_Manager::status_completed,
317
            ));
318
        }
319
        $this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration
320
        //now render the migration options part, and put it in a variable
321
        $migration_options_template_file = apply_filters(
322
            'FHEE__ee_migration_page__migration_options_template',
323
            EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
324
        );
325
        $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true);
326
        $this->_template_args['migration_options_html'] = $migration_options_html;
327
        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
328
            $this->_template_args, true);
329
        $this->display_admin_page_with_sidebar();
330
    }
331
332
333
334
    /**
335
     * returns JSON and executes another step of the currently-executing data migration (called via ajax)
336
     */
337
    public function migration_step()
338
    {
339
        $this->_template_args['data'] = EE_Data_Migration_Manager::instance()->response_to_migration_ajax_request();
340
        $this->_return_json();
341
    }
342
343
344
345
    /**
346
     * Can be used by js when it notices a response with HTML in it in order
347
     * to log the malformed response
348
     */
349
    public function add_error_to_migrations_ran()
350
    {
351
        EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($this->_req_data['message']);
352
        $this->_template_args['data'] = array('ok' => true);
353
        $this->_return_json();
354
    }
355
356
357
358
    /**
359
     * changes the maintenance level, provided there are still no migration scripts that should run
360
     */
361
    public function _change_maintenance_level()
362
    {
363
        $new_level = absint($this->_req_data['maintenance_mode_level']);
364
        if ( ! EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) {
365
            EE_Maintenance_Mode::instance()->set_maintenance_level($new_level);
366
            $success = true;
367
        } else {
368
            EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
369
            $success = false;
370
        }
371
        $this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso"));
0 ignored issues
show
Documentation introduced by
$success is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
372
    }
373
374
375
376
    /**
377
     * a tab with options for resetting and/or deleting EE data
378
     *
379
     * @throws \EE_Error
380
     * @throws \DomainException
381
     */
382
    public function _data_reset_and_delete()
383
    {
384
        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
385
        $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
386
            'reset_reservations',
387
            'reset_reservations',
388
            array(),
389
            'button button-primary',
390
            '',
391
            false
392
        );
393
        $this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button(
394
            'reset_capabilities',
395
            'reset_capabilities',
396
            array(),
397
            'button button-primary',
398
            '',
399
            false
400
        );
401
        $this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
402
            array('action' => 'delete_db'),
403
            EE_MAINTENANCE_ADMIN_URL
404
        );
405
        $this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
406
            array('action' => 'reset_db'),
407
            EE_MAINTENANCE_ADMIN_URL
408
        );
409
        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
410
            $this->_template_path,
411
            $this->_template_args,
412
            true
413
        );
414
        $this->display_admin_page_with_sidebar();
415
    }
416
417
418
419
    protected function _reset_reservations()
420
    {
421
        if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
422
            EE_Error::add_success(
423
                __(
424
                    'Ticket and datetime reserved counts have been successfully reset.',
425
                    'event_espresso'
426
                )
427
            );
428
        } else {
429
            EE_Error::add_success(
430
                __(
431
                    'Ticket and datetime reserved counts were correct and did not need resetting.',
432
                    'event_espresso'
433
                )
434
            );
435
        }
436
        $this->_redirect_after_action(true, '', '', array('action' => 'data_reset'), true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
437
    }
438
439
440
441
    protected function _reset_capabilities()
442
    {
443
        EE_Registry::instance()->CAP->init_caps(true);
444
        EE_Error::add_success(__('Default Event Espresso capabilities have been restored for all current roles.',
445
            'event_espresso'));
446
        $this->_redirect_after_action(false, '', '', array('action' => 'data_reset'), true);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
447
    }
448
449
450
451
    /**
452
     * resets the DMSs so we can attempt to continue migrating after a fatal error
453
     * (only a good idea when someone has somehow tried ot fix whatever caused
454
     * the fatal error in teh first place)
455
     */
456
    protected function _reattempt_migration()
457
    {
458
        EE_Data_Migration_Manager::instance()->reattempt();
459
        $this->_redirect_after_action(false, '', '', array('action' => 'default'), true);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
460
    }
461
462
463
464
    /**
465
     * shows the big ol' System Information page
466
     */
467
    public function _system_status()
468
    {
469
        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
470
        $this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati();
471
        $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
472
            array(
473
                'action' => 'download_system_status',
474
            ),
475
            EE_MAINTENANCE_ADMIN_URL
476
        );
477
        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
478
            $this->_template_args, true);
479
        $this->display_admin_page_with_sidebar();
480
    }
481
482
    /**
483
     * Downloads an HTML file of the system status that can be easily stored or emailed
484
     */
485
    public function _download_system_status()
486
    {
487
        $status_info = EEM_System_Status::instance()->get_system_stati();
488
        header( 'Content-Disposition: attachment' );
489
        header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" );
490
        echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>";
491
        echo "<h1>System Information for " . site_url() . "</h1>";
492
        echo EEH_Template::layout_array_as_table( $status_info );
493
        die;
494
    }
495
496
497
498
    public function _send_migration_crash_report()
499
    {
500
        $from = $this->_req_data['from'];
501
        $from_name = $this->_req_data['from_name'];
502
        $body = $this->_req_data['body'];
503
        try {
504
            $success = wp_mail(EE_SUPPORT_EMAIL,
505
                'Migration Crash Report',
506
                $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
507
                array(
508
                    "from:$from_name<$from>",
509
                    //					'content-type:text/html charset=UTF-8'
510
                ));
511
        } catch (Exception $e) {
512
            $success = false;
513
        }
514
        $this->_redirect_after_action($success, esc_html__("Migration Crash Report", "event_espresso"),
515
            esc_html__("sent", "event_espresso"),
516
            array('success' => $success, 'action' => 'confirm_migration_crash_report_sent'));
517
    }
518
519
520
521
    public function _confirm_migration_crash_report_sent()
522
    {
523
        try {
524
            $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
525
        } catch (EE_Error $e) {
526
            EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
527
            //now, just so we can display the page correctly, make a error migration script stage object
528
            //and also put the error on it. It only persists for the duration of this request
529
            $most_recent_migration = new EE_DMS_Unknown_1_0_0();
530
            $most_recent_migration->add_error($e->getMessage());
531
        }
532
        $success = $this->_req_data['success'] == '1' ? true : false;
533
        $this->_template_args['success'] = $success;
534
        $this->_template_args['most_recent_migration'] = $most_recent_migration;
535
        $this->_template_args['reset_db_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'),
536
            EE_MAINTENANCE_ADMIN_URL);
537
        $this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'),
538
            EE_MAINTENANCE_ADMIN_URL);
539
        $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'),
540
            EE_MAINTENANCE_ADMIN_URL);
541
        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
542
        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
543
            $this->_template_args, true);
544
        $this->display_admin_page_with_sidebar();
545
    }
546
547
548
549
    /**
550
     * Resets the entire EE4 database.
551
     * Currently basically only sets up ee4 database for a fresh install- doesn't
552
     * actually clean out the old wp options, or cpts (although does erase old ee table data)
553
     *
554
     * @param boolean $nuke_old_ee4_data controls whether or not we
555
     *                                   destroy the old ee4 data, or just try initializing ee4 default data
556
     */
557
    public function _reset_db($nuke_old_ee4_data = true)
558
    {
559
        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
560
        if ($nuke_old_ee4_data) {
561
            EEH_Activation::delete_all_espresso_cpt_data();
562
            EEH_Activation::delete_all_espresso_tables_and_data(false);
563
            EEH_Activation::remove_cron_tasks();
564
        }
565
        //make sure when we reset the registry's config that it
566
        //switches to using the new singleton
567
        EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true);
568
        EE_System::instance()->initialize_db_if_no_migrations_required(true);
569
        EE_System::instance()->redirect_to_about_ee();
570
    }
571
572
573
574
    /**
575
     * Deletes ALL EE tables, Records, and Options from the database.
576
     */
577
    public function _delete_db()
578
    {
579
        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
580
        EEH_Activation::delete_all_espresso_cpt_data();
581
        EEH_Activation::delete_all_espresso_tables_and_data();
582
        EEH_Activation::remove_cron_tasks();
583
        EEH_Activation::deactivate_event_espresso();
584
        wp_safe_redirect(admin_url('plugins.php'));
585
        exit;
586
    }
587
588
589
590
    /**
591
     * sets up EE4 to rerun the migrations from ee3 to ee4
592
     */
593
    public function _rerun_migration_from_ee3()
594
    {
595
        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
596
        EEH_Activation::delete_all_espresso_cpt_data();
597
        EEH_Activation::delete_all_espresso_tables_and_data(false);
598
        //set the db state to something that will require migrations
599
        update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0');
600
        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance);
601
        $this->_redirect_after_action(true, esc_html__("Database", 'event_espresso'), esc_html__("reset", 'event_espresso'));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
602
    }
603
604
605
606
    //none of the below group are currently used for Gateway Settings
607
    protected function _add_screen_options()
608
    {
609
    }
610
611
612
613
    protected function _add_feature_pointers()
614
    {
615
    }
616
617
618
619
    public function admin_init()
620
    {
621
    }
622
623
624
625
    public function admin_notices()
626
    {
627
    }
628
629
630
631
    public function admin_footer_scripts()
632
    {
633
    }
634
635
636
637
    public function load_scripts_styles()
638
    {
639
        wp_enqueue_script('ee_admin_js');
640
//		wp_enqueue_media();
641
//		wp_enqueue_script('media-upload');
642
        wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . '/ee-maintenance.js', array('jquery'),
643
            EVENT_ESPRESSO_VERSION, true);
644
        wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(),
645
            EVENT_ESPRESSO_VERSION);
646
        wp_enqueue_style('espresso_maintenance');
647
    }
648
649
650
651
    public function load_scripts_styles_default()
652
    {
653
        //styles
654
//		wp_enqueue_style('ee-text-links');
655
//		//scripts
656
//		wp_enqueue_script('ee-text-links');
657
    }
658
659
660
661
} //end Maintenance_Admin_Page class
662