Completed
Branch dev (fc935c)
by
unknown
22:17 queued 15:01
created
core/libraries/batch/Helpers/JobStepResponse.php 1 patch
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -14,107 +14,107 @@
 block discarded – undo
14 14
 class JobStepResponse
15 15
 {
16 16
 	// phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
17
-    /**
18
-     * Description fo what happened during this step
19
-     *
20
-     * @var array|string
21
-     */
22
-    protected $_update_text;
23
-
24
-    /**
25
-     * @var JobParameters
26
-     */
27
-    protected $_job_parameters;
28
-
29
-    /**
30
-     * Extra data to include as part of the response.
31
-     *
32
-     * @var array
33
-     */
34
-    protected $_extra_data = [];
17
+	/**
18
+	 * Description fo what happened during this step
19
+	 *
20
+	 * @var array|string
21
+	 */
22
+	protected $_update_text;
23
+
24
+	/**
25
+	 * @var JobParameters
26
+	 */
27
+	protected $_job_parameters;
28
+
29
+	/**
30
+	 * Extra data to include as part of the response.
31
+	 *
32
+	 * @var array
33
+	 */
34
+	protected $_extra_data = [];
35 35
 
36 36
 	// phpcs:enable
37 37
 
38 38
 	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
39
-    /**
40
-     * @param JobParameters $job_parameters
41
-     * @param array|string  $update_text
42
-     * @param array         $extra_data
43
-     */
44
-    public function __construct(JobParameters $job_parameters, $update_text = [], array $extra_data = [])
45
-    {
46
-        $this->_job_parameters = $job_parameters;
47
-        $this->_update_text    = (array) $update_text;
48
-        $this->_extra_data     = $extra_data;
49
-    }
50
-
51
-
52
-    /**
53
-     * @return JobParameters
54
-     */
55
-    public function job_parameters(): JobParameters
56
-    {
57
-        return $this->_job_parameters;
58
-    }
59
-
60
-
61
-    /**
62
-     * Gets the update_text of what happened in this job during the current step
63
-     *
64
-     * @return string
65
-     */
66
-    public function update_text(): string
67
-    {
68
-        return implode('', array_filter(array_map('trim', $this->_update_text)));
69
-    }
70
-
71
-
72
-    /**
73
-     * @param string $update_text
74
-     */
75
-    public function addUpdateText(string $update_text)
76
-    {
77
-        $this->_update_text[] = $update_text;
78
-    }
79
-
80
-
81
-    /**
82
-     * Returns any extra data we may want to include with this response
83
-     *
84
-     * @return array
85
-     */
86
-    public function extra_data(): array
87
-    {
88
-        return $this->_extra_data ?: [];
89
-    }
90
-
91
-
92
-    /**
93
-     * Converts this response into an array that can be easily serialized.
94
-     * This is most useful for serializing or json encoding
95
-     *
96
-     * @return array {
97
-     * @type string $status          , one of JobParameters::valid_stati()
98
-     * @type int    $units_processed count of units processed
99
-     * @type int    $job_size        total number of units TO process
100
-     * @type string $job_id          unique string identifying the job
101
-     * @type string $update_text     string describing what happened during this step
102
-     * } and any other items from $this->extra_data()
103
-     */
104
-    public function to_array(): array
105
-    {
106
-        return apply_filters(
107
-            'FHEE__EventEspressoBatchRequest\Helpers\JobStepResponse__to_array__return',
108
-            [
109
-                'status'          => $this->job_parameters()->status(),
110
-                'units_processed' => $this->job_parameters()->units_processed(),
111
-                'job_size'        => $this->job_parameters()->job_size(),
112
-                'job_id'          => $this->job_parameters()->job_id(),
113
-                'update_text'     => $this->update_text(),
114
-            ]
115
-            + $this->extra_data()
116
-            + $this->job_parameters()->extra_data(),
117
-            $this
118
-        );
119
-    }
39
+	/**
40
+	 * @param JobParameters $job_parameters
41
+	 * @param array|string  $update_text
42
+	 * @param array         $extra_data
43
+	 */
44
+	public function __construct(JobParameters $job_parameters, $update_text = [], array $extra_data = [])
45
+	{
46
+		$this->_job_parameters = $job_parameters;
47
+		$this->_update_text    = (array) $update_text;
48
+		$this->_extra_data     = $extra_data;
49
+	}
50
+
51
+
52
+	/**
53
+	 * @return JobParameters
54
+	 */
55
+	public function job_parameters(): JobParameters
56
+	{
57
+		return $this->_job_parameters;
58
+	}
59
+
60
+
61
+	/**
62
+	 * Gets the update_text of what happened in this job during the current step
63
+	 *
64
+	 * @return string
65
+	 */
66
+	public function update_text(): string
67
+	{
68
+		return implode('', array_filter(array_map('trim', $this->_update_text)));
69
+	}
70
+
71
+
72
+	/**
73
+	 * @param string $update_text
74
+	 */
75
+	public function addUpdateText(string $update_text)
76
+	{
77
+		$this->_update_text[] = $update_text;
78
+	}
79
+
80
+
81
+	/**
82
+	 * Returns any extra data we may want to include with this response
83
+	 *
84
+	 * @return array
85
+	 */
86
+	public function extra_data(): array
87
+	{
88
+		return $this->_extra_data ?: [];
89
+	}
90
+
91
+
92
+	/**
93
+	 * Converts this response into an array that can be easily serialized.
94
+	 * This is most useful for serializing or json encoding
95
+	 *
96
+	 * @return array {
97
+	 * @type string $status          , one of JobParameters::valid_stati()
98
+	 * @type int    $units_processed count of units processed
99
+	 * @type int    $job_size        total number of units TO process
100
+	 * @type string $job_id          unique string identifying the job
101
+	 * @type string $update_text     string describing what happened during this step
102
+	 * } and any other items from $this->extra_data()
103
+	 */
104
+	public function to_array(): array
105
+	{
106
+		return apply_filters(
107
+			'FHEE__EventEspressoBatchRequest\Helpers\JobStepResponse__to_array__return',
108
+			[
109
+				'status'          => $this->job_parameters()->status(),
110
+				'units_processed' => $this->job_parameters()->units_processed(),
111
+				'job_size'        => $this->job_parameters()->job_size(),
112
+				'job_id'          => $this->job_parameters()->job_id(),
113
+				'update_text'     => $this->update_text(),
114
+			]
115
+			+ $this->extra_data()
116
+			+ $this->job_parameters()->extra_data(),
117
+			$this
118
+		);
119
+	}
120 120
 }
Please login to merge, or discard this patch.
core/libraries/batch/Helpers/JobParametersWordPressOption.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -6,8 +6,8 @@
 block discarded – undo
6 6
 
7 7
 class JobParametersWordPressOption extends WordPressOption
8 8
 {
9
-    public function __construct($option_name)
10
-    {
11
-        parent::__construct($option_name, [], false);
12
-    }
9
+	public function __construct($option_name)
10
+	{
11
+		parent::__construct($option_name, [], false);
12
+	}
13 13
 }
Please login to merge, or discard this patch.
core/libraries/batch/Helpers/JobParameters.php 2 patches
Indentation   +438 added lines, -438 removed lines patch added patch discarded remove patch
@@ -21,442 +21,442 @@
 block discarded – undo
21 21
 	// phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
22 22
 
23 23
 
24
-    /**
25
-     * status indicating the job should advance to a secondary batch job (usually after an assessment phase)
26
-     */
27
-    const status_advance = 'advance';
28
-
29
-    /**
30
-     * status indicating the job has been cleaned up, and so this is probably the last
31
-     * time you'll see this job
32
-     */
33
-    const status_cleaned_up = 'cleaned_up';
34
-
35
-    /**
36
-     * status indicating the job should continue
37
-     */
38
-    const status_continue = 'continue';
39
-
40
-    /**
41
-     * status indicated the job has been completed successfully and should be cleaned up next
42
-     */
43
-    const status_complete = 'complete';
44
-
45
-    /**
46
-     * status indicating there was an error and the job should be cleaned up
47
-     */
48
-    const status_error = 'error';
49
-
50
-    /**
51
-     * status indicating to temporarily stop the current job
52
-     * so that feedback can be provided to the user and/or to prompt the user for input
53
-     */
54
-    const status_pause = 'pause';
55
-
56
-    /**
57
-     * status indicating that the current job needs to redirect to... somewhere else...
58
-     */
59
-    const status_redirect = 'redirect';
60
-
61
-    /**
62
-     * string prepended to job ID and used for saving job data to the WP options table
63
-     */
64
-    const wp_option_prefix = 'ee_job_parameters_';
65
-
66
-
67
-    /**
68
-     * String uniquely identifying the job
69
-     *
70
-     * @var string
71
-     */
72
-    protected $_job_id = '';
73
-
74
-    /**
75
-     * @var string
76
-     */
77
-    protected $_classname = '';
78
-
79
-    /**
80
-     * @var array
81
-     */
82
-    protected $_request_data = [];
83
-
84
-    /**
85
-     * Array of any extra data we want to remember about this request, that
86
-     * wasn't necessarily past in with the request data
87
-     *
88
-     * @var array
89
-     */
90
-    protected $_extra_data = [];
91
-
92
-    /**
93
-     * Estimate of how many units HAVE been processed
94
-     *
95
-     * @var int
96
-     */
97
-    protected $_units_processed = 0;
98
-
99
-    /**
100
-     * @var string
101
-     */
102
-    protected $_status = '';
103
-
104
-    /**
105
-     * The size of the total job in whatever units you want.
106
-     * If you can't provide an estimate leave as 0.
107
-     * Once _units_processed equals _job_size, we should be done
108
-     *
109
-     * @var int
110
-     */
111
-    protected $_job_size = 0;
112
-
113
-
114
-    /**
115
-     * @var JobParametersWordPressOption|null
116
-     */
117
-    private $job_record;
118
-
119
-    /**
120
-     * if set to false, then the job parameters record saved to the WordPress options will NOT be deleted
121
-     *
122
-     * @var bool
123
-     */
124
-    protected $delete_job_record = false;
125
-
126
-
127
-    /**
128
-     * @param string $job_id
129
-     * @param string $classname
130
-     * @param array  $request_data
131
-     * @param array  $extra_data
132
-     */
133
-    public function __construct(string $job_id, string $classname, array $request_data, array $extra_data = [])
134
-    {
135
-        $this->set_job_id($job_id);
136
-        $this->set_classname($classname);
137
-        $this->set_request_data($request_data);
138
-        $this->set_extra_data($extra_data);
139
-        $this->set_status(JobParameters::status_continue);
140
-        $this->job_record = new JobParametersWordPressOption($this->option_name());
141
-    }
142
-
143
-
144
-    /**
145
-     * Returns the array of strings of valid stati
146
-     *
147
-     * @return array
148
-     */
149
-    public static function valid_stati(): array
150
-    {
151
-        return [
152
-            JobParameters::status_complete,
153
-            JobParameters::status_continue,
154
-            JobParameters::status_error,
155
-            JobParameters::status_cleaned_up,
156
-        ];
157
-    }
158
-
159
-
160
-    /**
161
-     * Saves this option to the database (wordpress options table)
162
-     *
163
-     * @return bool success
164
-     */
165
-    public function save(): bool
166
-    {
167
-        $object_vars = get_object_vars($this);
168
-        unset($object_vars['job_record']);
169
-        return $this->job_record->updateOption($object_vars);
170
-    }
171
-
172
-
173
-    /**
174
-     * Deletes the job from the database if $this->delete_job_record is set to `true`,
175
-     * although this object is still usable for the rest of the request
176
-     *
177
-     * @return bool
178
-     */
179
-    public function delete(): bool
180
-    {
181
-        return $this->delete_job_record ? $this->job_record->deleteOption() : WordPressOption::UPDATE_NONE;
182
-    }
183
-
184
-
185
-    /**
186
-     * Loads the specified job from the database JobParametersWordPressOption
187
-     *
188
-     * @param string $job_id
189
-     * @return JobParameters
190
-     * @throws BatchRequestException
191
-     */
192
-    public static function load(string $job_id): JobParameters
193
-    {
194
-        $job_record         = new JobParametersWordPressOption(JobParameters::wp_option_prefix . $job_id);
195
-        $job_parameter_vars = $job_record->loadOption();
196
-        if (
197
-            ! is_array($job_parameter_vars)
198
-            || ! isset($job_parameter_vars['_classname'])
199
-            || ! isset($job_parameter_vars['_request_data'])
200
-        ) {
201
-            throw new BatchRequestException(
202
-                sprintf(
203
-                    esc_html__(
204
-                        'Could not retrieve valid data for job %1$s from the WordPress options table. The WordPress option was %2$s',
205
-                        'event_espresso'
206
-                    ),
207
-                    $job_id,
208
-                    JobParameters::wp_option_prefix . $job_id
209
-                )
210
-            );
211
-        }
212
-        $job_parameters = new JobParameters(
213
-            $job_id,
214
-            $job_parameter_vars['_classname'],
215
-            $job_parameter_vars['_request_data']
216
-        );
217
-        foreach ($job_parameter_vars as $key => $value) {
218
-            $job_parameters->{$key} = $value;
219
-        }
220
-        $job_parameters->job_record = $job_record;
221
-        // $job_parameters->save();
222
-        return $job_parameters;
223
-    }
224
-
225
-
226
-    /**
227
-     * Gets the job's unique string
228
-     *
229
-     * @return string
230
-     */
231
-    public function job_id(): string
232
-    {
233
-        return $this->_job_id;
234
-    }
235
-
236
-
237
-    /**
238
-     * Gets the classname that should run this job
239
-     *
240
-     * @return string
241
-     */
242
-    public function classname(): string
243
-    {
244
-        return $this->_classname;
245
-    }
246
-
247
-
248
-    /**
249
-     * Gets the original array of request data for this job
250
-     *
251
-     * @return array
252
-     */
253
-    public function request_data(): array
254
-    {
255
-        return $this->_request_data;
256
-    }
257
-
258
-
259
-    /**
260
-     * Gets a single item from the request data
261
-     *
262
-     * @param string       $key
263
-     * @param string|array $default
264
-     * @return string|array
265
-     */
266
-    public function request_datum(string $key, $default = '')
267
-    {
268
-        if (isset($this->_request_data[ $key ])) {
269
-            return $this->_request_data[ $key ];
270
-        }
271
-        return $default;
272
-    }
273
-
274
-
275
-    /**
276
-     * Gets a single item from the extra data
277
-     *
278
-     * @param string       $key
279
-     * @param string|array $default
280
-     * @return string|array
281
-     */
282
-    public function extra_datum(string $key, $default = '')
283
-    {
284
-        if (isset($this->_extra_data[ $key ])) {
285
-            return $this->_extra_data[ $key ];
286
-        }
287
-        return $default;
288
-    }
289
-
290
-
291
-    /**
292
-     * Adds an extra piece of extra data that we're going to want later during the job
293
-     *
294
-     * @param string                $key
295
-     * @param string|int|array|null $value almost any extra data you want to store
296
-     */
297
-    public function add_extra_data(string $key, $value)
298
-    {
299
-        $this->_extra_data[ $key ] = $value;
300
-    }
301
-
302
-
303
-    /**
304
-     * Array of any extra data we want to store
305
-     *
306
-     * @return array
307
-     */
308
-    public function extra_data(): array
309
-    {
310
-        return $this->_extra_data;
311
-    }
312
-
313
-
314
-    /**
315
-     * Returns the job size, in whatever units you want
316
-     *
317
-     * @return int
318
-     */
319
-    public function job_size(): int
320
-    {
321
-        return $this->_job_size;
322
-    }
323
-
324
-
325
-    /**
326
-     * Sets the job size. You decide what units to use
327
-     *
328
-     * @param int $size
329
-     */
330
-    public function set_job_size(int $size)
331
-    {
332
-        $this->_job_size = $size;
333
-    }
334
-
335
-
336
-    /**
337
-     * The number of "units" processed, in the same units as the "job size"
338
-     *
339
-     * @return int
340
-     */
341
-    public function units_processed(): int
342
-    {
343
-        return $this->_units_processed;
344
-    }
345
-
346
-
347
-    /**
348
-     * Marks more units as processed
349
-     *
350
-     * @param int $newly_processed
351
-     * @return int updated units processed
352
-     */
353
-    public function mark_processed(int $newly_processed): int
354
-    {
355
-        $this->_units_processed += $newly_processed;
356
-        return $this->_units_processed;
357
-    }
358
-
359
-
360
-    /**
361
-     * Sets the total count of units processed. You might prefer to use mark_processed
362
-     *
363
-     * @param int $total_units_processed
364
-     */
365
-    public function set_units_processed(int $total_units_processed)
366
-    {
367
-        $this->_units_processed = $total_units_processed;
368
-    }
369
-
370
-
371
-    /**
372
-     * Sets the job's ID
373
-     *
374
-     * @param string $job_id
375
-     */
376
-    public function set_job_id(string $job_id)
377
-    {
378
-        $this->_job_id = $job_id;
379
-    }
380
-
381
-
382
-    /**
383
-     * sets the classname
384
-     *
385
-     * @param string $classname
386
-     */
387
-    public function set_classname(string $classname)
388
-    {
389
-        $this->_classname = $classname;
390
-    }
391
-
392
-
393
-    /**
394
-     * Sets the request data
395
-     *
396
-     * @param array $request_data
397
-     */
398
-    public function set_request_data(array $request_data)
399
-    {
400
-        $this->_request_data = $request_data;
401
-    }
402
-
403
-
404
-    /**
405
-     * Sets the array of extra data we want to store on this request
406
-     *
407
-     * @param array $extra_data
408
-     */
409
-    public function set_extra_data(array $extra_data)
410
-    {
411
-        $this->_extra_data = $extra_data;
412
-    }
413
-
414
-
415
-    /**
416
-     * Gets the name of the wordpress option that should store these job parameters
417
-     *
418
-     * @return string
419
-     */
420
-    public function option_name(): string
421
-    {
422
-        return JobParameters::wp_option_prefix . $this->job_id();
423
-    }
424
-
425
-
426
-    /**
427
-     * Gets the job's current status. One of JobParameters::valid_stati();
428
-     *
429
-     * @return string
430
-     */
431
-    public function status(): string
432
-    {
433
-        return $this->_status;
434
-    }
435
-
436
-
437
-    /**
438
-     * @param string $status on eof JobParameters::valid_stati()
439
-     */
440
-    public function set_status(string $status)
441
-    {
442
-        $this->_status = $status;
443
-    }
444
-
445
-
446
-    /**
447
-     * @return void
448
-     */
449
-    public function deleteJobRecord()
450
-    {
451
-        $this->delete_job_record = true;
452
-    }
453
-
454
-
455
-    /**
456
-     * @return void
457
-     */
458
-    public function dontDeleteJobRecord()
459
-    {
460
-        $this->delete_job_record = false;
461
-    }
24
+	/**
25
+	 * status indicating the job should advance to a secondary batch job (usually after an assessment phase)
26
+	 */
27
+	const status_advance = 'advance';
28
+
29
+	/**
30
+	 * status indicating the job has been cleaned up, and so this is probably the last
31
+	 * time you'll see this job
32
+	 */
33
+	const status_cleaned_up = 'cleaned_up';
34
+
35
+	/**
36
+	 * status indicating the job should continue
37
+	 */
38
+	const status_continue = 'continue';
39
+
40
+	/**
41
+	 * status indicated the job has been completed successfully and should be cleaned up next
42
+	 */
43
+	const status_complete = 'complete';
44
+
45
+	/**
46
+	 * status indicating there was an error and the job should be cleaned up
47
+	 */
48
+	const status_error = 'error';
49
+
50
+	/**
51
+	 * status indicating to temporarily stop the current job
52
+	 * so that feedback can be provided to the user and/or to prompt the user for input
53
+	 */
54
+	const status_pause = 'pause';
55
+
56
+	/**
57
+	 * status indicating that the current job needs to redirect to... somewhere else...
58
+	 */
59
+	const status_redirect = 'redirect';
60
+
61
+	/**
62
+	 * string prepended to job ID and used for saving job data to the WP options table
63
+	 */
64
+	const wp_option_prefix = 'ee_job_parameters_';
65
+
66
+
67
+	/**
68
+	 * String uniquely identifying the job
69
+	 *
70
+	 * @var string
71
+	 */
72
+	protected $_job_id = '';
73
+
74
+	/**
75
+	 * @var string
76
+	 */
77
+	protected $_classname = '';
78
+
79
+	/**
80
+	 * @var array
81
+	 */
82
+	protected $_request_data = [];
83
+
84
+	/**
85
+	 * Array of any extra data we want to remember about this request, that
86
+	 * wasn't necessarily past in with the request data
87
+	 *
88
+	 * @var array
89
+	 */
90
+	protected $_extra_data = [];
91
+
92
+	/**
93
+	 * Estimate of how many units HAVE been processed
94
+	 *
95
+	 * @var int
96
+	 */
97
+	protected $_units_processed = 0;
98
+
99
+	/**
100
+	 * @var string
101
+	 */
102
+	protected $_status = '';
103
+
104
+	/**
105
+	 * The size of the total job in whatever units you want.
106
+	 * If you can't provide an estimate leave as 0.
107
+	 * Once _units_processed equals _job_size, we should be done
108
+	 *
109
+	 * @var int
110
+	 */
111
+	protected $_job_size = 0;
112
+
113
+
114
+	/**
115
+	 * @var JobParametersWordPressOption|null
116
+	 */
117
+	private $job_record;
118
+
119
+	/**
120
+	 * if set to false, then the job parameters record saved to the WordPress options will NOT be deleted
121
+	 *
122
+	 * @var bool
123
+	 */
124
+	protected $delete_job_record = false;
125
+
126
+
127
+	/**
128
+	 * @param string $job_id
129
+	 * @param string $classname
130
+	 * @param array  $request_data
131
+	 * @param array  $extra_data
132
+	 */
133
+	public function __construct(string $job_id, string $classname, array $request_data, array $extra_data = [])
134
+	{
135
+		$this->set_job_id($job_id);
136
+		$this->set_classname($classname);
137
+		$this->set_request_data($request_data);
138
+		$this->set_extra_data($extra_data);
139
+		$this->set_status(JobParameters::status_continue);
140
+		$this->job_record = new JobParametersWordPressOption($this->option_name());
141
+	}
142
+
143
+
144
+	/**
145
+	 * Returns the array of strings of valid stati
146
+	 *
147
+	 * @return array
148
+	 */
149
+	public static function valid_stati(): array
150
+	{
151
+		return [
152
+			JobParameters::status_complete,
153
+			JobParameters::status_continue,
154
+			JobParameters::status_error,
155
+			JobParameters::status_cleaned_up,
156
+		];
157
+	}
158
+
159
+
160
+	/**
161
+	 * Saves this option to the database (wordpress options table)
162
+	 *
163
+	 * @return bool success
164
+	 */
165
+	public function save(): bool
166
+	{
167
+		$object_vars = get_object_vars($this);
168
+		unset($object_vars['job_record']);
169
+		return $this->job_record->updateOption($object_vars);
170
+	}
171
+
172
+
173
+	/**
174
+	 * Deletes the job from the database if $this->delete_job_record is set to `true`,
175
+	 * although this object is still usable for the rest of the request
176
+	 *
177
+	 * @return bool
178
+	 */
179
+	public function delete(): bool
180
+	{
181
+		return $this->delete_job_record ? $this->job_record->deleteOption() : WordPressOption::UPDATE_NONE;
182
+	}
183
+
184
+
185
+	/**
186
+	 * Loads the specified job from the database JobParametersWordPressOption
187
+	 *
188
+	 * @param string $job_id
189
+	 * @return JobParameters
190
+	 * @throws BatchRequestException
191
+	 */
192
+	public static function load(string $job_id): JobParameters
193
+	{
194
+		$job_record         = new JobParametersWordPressOption(JobParameters::wp_option_prefix . $job_id);
195
+		$job_parameter_vars = $job_record->loadOption();
196
+		if (
197
+			! is_array($job_parameter_vars)
198
+			|| ! isset($job_parameter_vars['_classname'])
199
+			|| ! isset($job_parameter_vars['_request_data'])
200
+		) {
201
+			throw new BatchRequestException(
202
+				sprintf(
203
+					esc_html__(
204
+						'Could not retrieve valid data for job %1$s from the WordPress options table. The WordPress option was %2$s',
205
+						'event_espresso'
206
+					),
207
+					$job_id,
208
+					JobParameters::wp_option_prefix . $job_id
209
+				)
210
+			);
211
+		}
212
+		$job_parameters = new JobParameters(
213
+			$job_id,
214
+			$job_parameter_vars['_classname'],
215
+			$job_parameter_vars['_request_data']
216
+		);
217
+		foreach ($job_parameter_vars as $key => $value) {
218
+			$job_parameters->{$key} = $value;
219
+		}
220
+		$job_parameters->job_record = $job_record;
221
+		// $job_parameters->save();
222
+		return $job_parameters;
223
+	}
224
+
225
+
226
+	/**
227
+	 * Gets the job's unique string
228
+	 *
229
+	 * @return string
230
+	 */
231
+	public function job_id(): string
232
+	{
233
+		return $this->_job_id;
234
+	}
235
+
236
+
237
+	/**
238
+	 * Gets the classname that should run this job
239
+	 *
240
+	 * @return string
241
+	 */
242
+	public function classname(): string
243
+	{
244
+		return $this->_classname;
245
+	}
246
+
247
+
248
+	/**
249
+	 * Gets the original array of request data for this job
250
+	 *
251
+	 * @return array
252
+	 */
253
+	public function request_data(): array
254
+	{
255
+		return $this->_request_data;
256
+	}
257
+
258
+
259
+	/**
260
+	 * Gets a single item from the request data
261
+	 *
262
+	 * @param string       $key
263
+	 * @param string|array $default
264
+	 * @return string|array
265
+	 */
266
+	public function request_datum(string $key, $default = '')
267
+	{
268
+		if (isset($this->_request_data[ $key ])) {
269
+			return $this->_request_data[ $key ];
270
+		}
271
+		return $default;
272
+	}
273
+
274
+
275
+	/**
276
+	 * Gets a single item from the extra data
277
+	 *
278
+	 * @param string       $key
279
+	 * @param string|array $default
280
+	 * @return string|array
281
+	 */
282
+	public function extra_datum(string $key, $default = '')
283
+	{
284
+		if (isset($this->_extra_data[ $key ])) {
285
+			return $this->_extra_data[ $key ];
286
+		}
287
+		return $default;
288
+	}
289
+
290
+
291
+	/**
292
+	 * Adds an extra piece of extra data that we're going to want later during the job
293
+	 *
294
+	 * @param string                $key
295
+	 * @param string|int|array|null $value almost any extra data you want to store
296
+	 */
297
+	public function add_extra_data(string $key, $value)
298
+	{
299
+		$this->_extra_data[ $key ] = $value;
300
+	}
301
+
302
+
303
+	/**
304
+	 * Array of any extra data we want to store
305
+	 *
306
+	 * @return array
307
+	 */
308
+	public function extra_data(): array
309
+	{
310
+		return $this->_extra_data;
311
+	}
312
+
313
+
314
+	/**
315
+	 * Returns the job size, in whatever units you want
316
+	 *
317
+	 * @return int
318
+	 */
319
+	public function job_size(): int
320
+	{
321
+		return $this->_job_size;
322
+	}
323
+
324
+
325
+	/**
326
+	 * Sets the job size. You decide what units to use
327
+	 *
328
+	 * @param int $size
329
+	 */
330
+	public function set_job_size(int $size)
331
+	{
332
+		$this->_job_size = $size;
333
+	}
334
+
335
+
336
+	/**
337
+	 * The number of "units" processed, in the same units as the "job size"
338
+	 *
339
+	 * @return int
340
+	 */
341
+	public function units_processed(): int
342
+	{
343
+		return $this->_units_processed;
344
+	}
345
+
346
+
347
+	/**
348
+	 * Marks more units as processed
349
+	 *
350
+	 * @param int $newly_processed
351
+	 * @return int updated units processed
352
+	 */
353
+	public function mark_processed(int $newly_processed): int
354
+	{
355
+		$this->_units_processed += $newly_processed;
356
+		return $this->_units_processed;
357
+	}
358
+
359
+
360
+	/**
361
+	 * Sets the total count of units processed. You might prefer to use mark_processed
362
+	 *
363
+	 * @param int $total_units_processed
364
+	 */
365
+	public function set_units_processed(int $total_units_processed)
366
+	{
367
+		$this->_units_processed = $total_units_processed;
368
+	}
369
+
370
+
371
+	/**
372
+	 * Sets the job's ID
373
+	 *
374
+	 * @param string $job_id
375
+	 */
376
+	public function set_job_id(string $job_id)
377
+	{
378
+		$this->_job_id = $job_id;
379
+	}
380
+
381
+
382
+	/**
383
+	 * sets the classname
384
+	 *
385
+	 * @param string $classname
386
+	 */
387
+	public function set_classname(string $classname)
388
+	{
389
+		$this->_classname = $classname;
390
+	}
391
+
392
+
393
+	/**
394
+	 * Sets the request data
395
+	 *
396
+	 * @param array $request_data
397
+	 */
398
+	public function set_request_data(array $request_data)
399
+	{
400
+		$this->_request_data = $request_data;
401
+	}
402
+
403
+
404
+	/**
405
+	 * Sets the array of extra data we want to store on this request
406
+	 *
407
+	 * @param array $extra_data
408
+	 */
409
+	public function set_extra_data(array $extra_data)
410
+	{
411
+		$this->_extra_data = $extra_data;
412
+	}
413
+
414
+
415
+	/**
416
+	 * Gets the name of the wordpress option that should store these job parameters
417
+	 *
418
+	 * @return string
419
+	 */
420
+	public function option_name(): string
421
+	{
422
+		return JobParameters::wp_option_prefix . $this->job_id();
423
+	}
424
+
425
+
426
+	/**
427
+	 * Gets the job's current status. One of JobParameters::valid_stati();
428
+	 *
429
+	 * @return string
430
+	 */
431
+	public function status(): string
432
+	{
433
+		return $this->_status;
434
+	}
435
+
436
+
437
+	/**
438
+	 * @param string $status on eof JobParameters::valid_stati()
439
+	 */
440
+	public function set_status(string $status)
441
+	{
442
+		$this->_status = $status;
443
+	}
444
+
445
+
446
+	/**
447
+	 * @return void
448
+	 */
449
+	public function deleteJobRecord()
450
+	{
451
+		$this->delete_job_record = true;
452
+	}
453
+
454
+
455
+	/**
456
+	 * @return void
457
+	 */
458
+	public function dontDeleteJobRecord()
459
+	{
460
+		$this->delete_job_record = false;
461
+	}
462 462
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
      */
192 192
     public static function load(string $job_id): JobParameters
193 193
     {
194
-        $job_record         = new JobParametersWordPressOption(JobParameters::wp_option_prefix . $job_id);
194
+        $job_record         = new JobParametersWordPressOption(JobParameters::wp_option_prefix.$job_id);
195 195
         $job_parameter_vars = $job_record->loadOption();
196 196
         if (
197 197
             ! is_array($job_parameter_vars)
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
                         'event_espresso'
206 206
                     ),
207 207
                     $job_id,
208
-                    JobParameters::wp_option_prefix . $job_id
208
+                    JobParameters::wp_option_prefix.$job_id
209 209
                 )
210 210
             );
211 211
         }
@@ -265,8 +265,8 @@  discard block
 block discarded – undo
265 265
      */
266 266
     public function request_datum(string $key, $default = '')
267 267
     {
268
-        if (isset($this->_request_data[ $key ])) {
269
-            return $this->_request_data[ $key ];
268
+        if (isset($this->_request_data[$key])) {
269
+            return $this->_request_data[$key];
270 270
         }
271 271
         return $default;
272 272
     }
@@ -281,8 +281,8 @@  discard block
 block discarded – undo
281 281
      */
282 282
     public function extra_datum(string $key, $default = '')
283 283
     {
284
-        if (isset($this->_extra_data[ $key ])) {
285
-            return $this->_extra_data[ $key ];
284
+        if (isset($this->_extra_data[$key])) {
285
+            return $this->_extra_data[$key];
286 286
         }
287 287
         return $default;
288 288
     }
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
      */
297 297
     public function add_extra_data(string $key, $value)
298 298
     {
299
-        $this->_extra_data[ $key ] = $value;
299
+        $this->_extra_data[$key] = $value;
300 300
     }
301 301
 
302 302
 
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
      */
420 420
     public function option_name(): string
421 421
     {
422
-        return JobParameters::wp_option_prefix . $this->job_id();
422
+        return JobParameters::wp_option_prefix.$this->job_id();
423 423
     }
424 424
 
425 425
 
Please login to merge, or discard this patch.
core/domain/services/admin/notices/status_change/StatusChangeNotice.php 2 patches
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -16,112 +16,112 @@
 block discarded – undo
16 16
  */
17 17
 class StatusChangeNotice extends WordPressOption
18 18
 {
19
-    public function __construct()
20
-    {
21
-        parent::__construct('ee_hide_status_change_notices_for_users', [], false);
22
-    }
19
+	public function __construct()
20
+	{
21
+		parent::__construct('ee_hide_status_change_notices_for_users', [], false);
22
+	}
23 23
 
24 24
 
25
-    public static function loadAssets()
26
-    {
27
-        wp_enqueue_style(
28
-            'status_change_notice',
29
-            EE_PLUGIN_DIR_URL . 'core/domain/services/admin/notices/status_change/status_change_notice.css',
30
-            ['espresso_menu'],
31
-            EVENT_ESPRESSO_VERSION
32
-        );
33
-        wp_enqueue_script(
34
-            'status_change_notice',
35
-            EE_PLUGIN_DIR_URL . 'core/domain/services/admin/notices/status_change/status_change_notice.js',
36
-            ['jquery'],
37
-            EVENT_ESPRESSO_VERSION,
38
-            true
39
-        );
40
-        wp_localize_script(
41
-            'status_change_notice',
42
-            'eeStatusChangeNotice',
43
-            [
44
-                'failed_request_msg' => wp_strip_all_tags(
45
-                    __(
46
-                        'Request failed. The server returned status code: ',
47
-                        'event_espresso'
48
-                    )
49
-                ),
50
-                'unknown_error_msg' => wp_strip_all_tags(
51
-                    __(
52
-                        'Oops... an unknown error has occurred on the server and this notice could not be dismissed.',
53
-                        'event_espresso'
54
-                    )
55
-                ),
56
-            ]
57
-        );
58
-    }
25
+	public static function loadAssets()
26
+	{
27
+		wp_enqueue_style(
28
+			'status_change_notice',
29
+			EE_PLUGIN_DIR_URL . 'core/domain/services/admin/notices/status_change/status_change_notice.css',
30
+			['espresso_menu'],
31
+			EVENT_ESPRESSO_VERSION
32
+		);
33
+		wp_enqueue_script(
34
+			'status_change_notice',
35
+			EE_PLUGIN_DIR_URL . 'core/domain/services/admin/notices/status_change/status_change_notice.js',
36
+			['jquery'],
37
+			EVENT_ESPRESSO_VERSION,
38
+			true
39
+		);
40
+		wp_localize_script(
41
+			'status_change_notice',
42
+			'eeStatusChangeNotice',
43
+			[
44
+				'failed_request_msg' => wp_strip_all_tags(
45
+					__(
46
+						'Request failed. The server returned status code: ',
47
+						'event_espresso'
48
+					)
49
+				),
50
+				'unknown_error_msg' => wp_strip_all_tags(
51
+					__(
52
+						'Oops... an unknown error has occurred on the server and this notice could not be dismissed.',
53
+						'event_espresso'
54
+					)
55
+				),
56
+			]
57
+		);
58
+	}
59 59
 
60 60
 
61
-    public function display(string $context, string $page_slug): string
62
-    {
63
-        return $this->isNotDismissed()
64
-            ? EEH_Template::display_template(
65
-                __DIR__ . '/status_change_notice.template.php',
66
-                [
67
-                    'context'   => $context,
68
-                    'page_slug' => ! empty($page_slug) ? "$page_slug-page" : '',
69
-                ],
70
-                true
71
-            )
72
-            : '';
73
-    }
61
+	public function display(string $context, string $page_slug): string
62
+	{
63
+		return $this->isNotDismissed()
64
+			? EEH_Template::display_template(
65
+				__DIR__ . '/status_change_notice.template.php',
66
+				[
67
+					'context'   => $context,
68
+					'page_slug' => ! empty($page_slug) ? "$page_slug-page" : '',
69
+				],
70
+				true
71
+			)
72
+			: '';
73
+	}
74 74
 
75 75
 
76
-    /**
77
-     * @return int
78
-     * @throws RuntimeException
79
-     */
80
-    public function dismiss(): int
81
-    {
82
-        $user      = $this->getCurrentUser();
83
-        $dismissed = (array) $this->loadOption();
84
-        if (! in_array($user, $dismissed)) {
85
-            $dismissed[] = $user;
86
-        }
87
-        return $this->updateOption($dismissed);
88
-    }
76
+	/**
77
+	 * @return int
78
+	 * @throws RuntimeException
79
+	 */
80
+	public function dismiss(): int
81
+	{
82
+		$user      = $this->getCurrentUser();
83
+		$dismissed = (array) $this->loadOption();
84
+		if (! in_array($user, $dismissed)) {
85
+			$dismissed[] = $user;
86
+		}
87
+		return $this->updateOption($dismissed);
88
+	}
89 89
 
90 90
 
91
-    /**
92
-     * @return bool
93
-     * @throws RuntimeException
94
-     */
95
-    public function isDismissed(): bool
96
-    {
97
-        $user      = $this->getCurrentUser();
98
-        $dismissed = (array) $this->loadOption();
99
-        return in_array($user, $dismissed);
100
-    }
91
+	/**
92
+	 * @return bool
93
+	 * @throws RuntimeException
94
+	 */
95
+	public function isDismissed(): bool
96
+	{
97
+		$user      = $this->getCurrentUser();
98
+		$dismissed = (array) $this->loadOption();
99
+		return in_array($user, $dismissed);
100
+	}
101 101
 
102 102
 
103
-    /**
104
-     * @return bool
105
-     * @throws RuntimeException
106
-     */
107
-    public function isNotDismissed(): bool
108
-    {
109
-        return ! $this->isDismissed();
110
-    }
103
+	/**
104
+	 * @return bool
105
+	 * @throws RuntimeException
106
+	 */
107
+	public function isNotDismissed(): bool
108
+	{
109
+		return ! $this->isDismissed();
110
+	}
111 111
 
112 112
 
113
-    /**
114
-     * @return string
115
-     * @throws RuntimeException
116
-     */
117
-    private function getCurrentUser(): string
118
-    {
119
-        $user = wp_get_current_user();
120
-        if (! $user instanceof WP_User || ! $user->exists()) {
121
-            throw new RuntimeException(
122
-                esc_html__('A valid WP User could not be retrieved.', 'event_espresso')
123
-            );
124
-        }
125
-        return $user->user_login;
126
-    }
113
+	/**
114
+	 * @return string
115
+	 * @throws RuntimeException
116
+	 */
117
+	private function getCurrentUser(): string
118
+	{
119
+		$user = wp_get_current_user();
120
+		if (! $user instanceof WP_User || ! $user->exists()) {
121
+			throw new RuntimeException(
122
+				esc_html__('A valid WP User could not be retrieved.', 'event_espresso')
123
+			);
124
+		}
125
+		return $user->user_login;
126
+	}
127 127
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -26,13 +26,13 @@  discard block
 block discarded – undo
26 26
     {
27 27
         wp_enqueue_style(
28 28
             'status_change_notice',
29
-            EE_PLUGIN_DIR_URL . 'core/domain/services/admin/notices/status_change/status_change_notice.css',
29
+            EE_PLUGIN_DIR_URL.'core/domain/services/admin/notices/status_change/status_change_notice.css',
30 30
             ['espresso_menu'],
31 31
             EVENT_ESPRESSO_VERSION
32 32
         );
33 33
         wp_enqueue_script(
34 34
             'status_change_notice',
35
-            EE_PLUGIN_DIR_URL . 'core/domain/services/admin/notices/status_change/status_change_notice.js',
35
+            EE_PLUGIN_DIR_URL.'core/domain/services/admin/notices/status_change/status_change_notice.js',
36 36
             ['jquery'],
37 37
             EVENT_ESPRESSO_VERSION,
38 38
             true
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
     {
63 63
         return $this->isNotDismissed()
64 64
             ? EEH_Template::display_template(
65
-                __DIR__ . '/status_change_notice.template.php',
65
+                __DIR__.'/status_change_notice.template.php',
66 66
                 [
67 67
                     'context'   => $context,
68 68
                     'page_slug' => ! empty($page_slug) ? "$page_slug-page" : '',
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
     {
82 82
         $user      = $this->getCurrentUser();
83 83
         $dismissed = (array) $this->loadOption();
84
-        if (! in_array($user, $dismissed)) {
84
+        if ( ! in_array($user, $dismissed)) {
85 85
             $dismissed[] = $user;
86 86
         }
87 87
         return $this->updateOption($dismissed);
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
     private function getCurrentUser(): string
118 118
     {
119 119
         $user = wp_get_current_user();
120
-        if (! $user instanceof WP_User || ! $user->exists()) {
120
+        if ( ! $user instanceof WP_User || ! $user->exists()) {
121 121
             throw new RuntimeException(
122 122
                 esc_html__('A valid WP User could not be retrieved.', 'event_espresso')
123 123
             );
Please login to merge, or discard this patch.
core/services/json/JsonDataWordpressOption.php 2 patches
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -15,97 +15,97 @@
 block discarded – undo
15 15
  */
16 16
 abstract class JsonDataWordpressOption extends WordPressOption
17 17
 {
18
-    /**
19
-     * @var array|mixed|stdClass
20
-     */
21
-    private $options = [];
22
-
23
-    /**
24
-     * @var JsonDataHandler|null
25
-     */
26
-    private $json_data_handler;
27
-
28
-
29
-    /**
30
-     * JsonDataWordpressOption constructor.
31
-     *
32
-     * @param JsonDataHandler $json_data_handler
33
-     * @param string          $option_name
34
-     * @param                 $default_value
35
-     * @param bool            $autoload
36
-     */
37
-    public function __construct(
38
-        JsonDataHandler $json_data_handler,
39
-        string $option_name,
40
-        $default_value,
41
-        bool $autoload = false
42
-    ) {
43
-        $this->json_data_handler = $json_data_handler;
44
-        if (! $this->json_data_handler->dataType()) {
45
-            $this->json_data_handler->configure(JsonDataHandler::DATA_TYPE_OBJECT);
46
-        }
47
-        parent::__construct($option_name, $default_value, $autoload);
48
-    }
49
-
50
-
51
-    /**
52
-     * @param $value
53
-     * @return int
54
-     */
55
-    public function updateOption($value): int
56
-    {
57
-        if (parent::updateOption($this->json_data_handler->encodeData($value))) {
58
-            $this->options = $value;
59
-            return WordPressOption::UPDATE_SUCCESS;
60
-        }
61
-        return WordPressOption::UPDATE_ERROR;
62
-    }
63
-
64
-
65
-    /**
66
-     * @param string $property
67
-     * @param mixed  $value
68
-     * @return void
69
-     */
70
-    public function addProperty(string $property, $value)
71
-    {
72
-        $options = $this->getAll();
73
-        $options->{$property} = $value;
74
-        $this->updateOption($options);
75
-    }
76
-
77
-
78
-    /**
79
-     * @param string $property
80
-     * @return mixed
81
-     */
82
-    public function getProperty(string $property)
83
-    {
84
-        $options = $this->getAll();
85
-        return property_exists($options, $property) ? $options->{$property} : null;
86
-    }
87
-
88
-
89
-    /**
90
-     * @return array|mixed|stdClass
91
-     */
92
-    public function getAll()
93
-    {
94
-        if (empty($this->options)) {
95
-            $this->options = $this->json_data_handler->decodeJson($this->loadOption());
96
-        }
97
-        return $this->options;
98
-    }
99
-
100
-
101
-    /**
102
-     * @param string $property
103
-     * @return void
104
-     */
105
-    public function removeProperty(string $property)
106
-    {
107
-        $options = $this->getAll();
108
-        unset($options->{$property});
109
-        $this->updateOption($options);
110
-    }
18
+	/**
19
+	 * @var array|mixed|stdClass
20
+	 */
21
+	private $options = [];
22
+
23
+	/**
24
+	 * @var JsonDataHandler|null
25
+	 */
26
+	private $json_data_handler;
27
+
28
+
29
+	/**
30
+	 * JsonDataWordpressOption constructor.
31
+	 *
32
+	 * @param JsonDataHandler $json_data_handler
33
+	 * @param string          $option_name
34
+	 * @param                 $default_value
35
+	 * @param bool            $autoload
36
+	 */
37
+	public function __construct(
38
+		JsonDataHandler $json_data_handler,
39
+		string $option_name,
40
+		$default_value,
41
+		bool $autoload = false
42
+	) {
43
+		$this->json_data_handler = $json_data_handler;
44
+		if (! $this->json_data_handler->dataType()) {
45
+			$this->json_data_handler->configure(JsonDataHandler::DATA_TYPE_OBJECT);
46
+		}
47
+		parent::__construct($option_name, $default_value, $autoload);
48
+	}
49
+
50
+
51
+	/**
52
+	 * @param $value
53
+	 * @return int
54
+	 */
55
+	public function updateOption($value): int
56
+	{
57
+		if (parent::updateOption($this->json_data_handler->encodeData($value))) {
58
+			$this->options = $value;
59
+			return WordPressOption::UPDATE_SUCCESS;
60
+		}
61
+		return WordPressOption::UPDATE_ERROR;
62
+	}
63
+
64
+
65
+	/**
66
+	 * @param string $property
67
+	 * @param mixed  $value
68
+	 * @return void
69
+	 */
70
+	public function addProperty(string $property, $value)
71
+	{
72
+		$options = $this->getAll();
73
+		$options->{$property} = $value;
74
+		$this->updateOption($options);
75
+	}
76
+
77
+
78
+	/**
79
+	 * @param string $property
80
+	 * @return mixed
81
+	 */
82
+	public function getProperty(string $property)
83
+	{
84
+		$options = $this->getAll();
85
+		return property_exists($options, $property) ? $options->{$property} : null;
86
+	}
87
+
88
+
89
+	/**
90
+	 * @return array|mixed|stdClass
91
+	 */
92
+	public function getAll()
93
+	{
94
+		if (empty($this->options)) {
95
+			$this->options = $this->json_data_handler->decodeJson($this->loadOption());
96
+		}
97
+		return $this->options;
98
+	}
99
+
100
+
101
+	/**
102
+	 * @param string $property
103
+	 * @return void
104
+	 */
105
+	public function removeProperty(string $property)
106
+	{
107
+		$options = $this->getAll();
108
+		unset($options->{$property});
109
+		$this->updateOption($options);
110
+	}
111 111
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@
 block discarded – undo
41 41
         bool $autoload = false
42 42
     ) {
43 43
         $this->json_data_handler = $json_data_handler;
44
-        if (! $this->json_data_handler->dataType()) {
44
+        if ( ! $this->json_data_handler->dataType()) {
45 45
             $this->json_data_handler->configure(JsonDataHandler::DATA_TYPE_OBJECT);
46 46
         }
47 47
         parent::__construct($option_name, $default_value, $autoload);
Please login to merge, or discard this patch.
core/services/json/JsonDataHandler.php 1 patch
Indentation   +342 added lines, -342 removed lines patch added patch discarded remove patch
@@ -14,346 +14,346 @@
 block discarded – undo
14 14
  */
15 15
 class JsonDataHandler
16 16
 {
17
-    const DATA_TYPE_ARRAY     = 'array';
18
-
19
-    const DATA_TYPE_OBJECT    = 'object';
20
-
21
-    const DATA_TYPE_USE_FLAGS = 'flags';
22
-
23
-    const NO_ERROR_MSG        = 'No error';
24
-
25
-    /**
26
-     * @var string|null
27
-     */
28
-    private $data_type = null;
29
-
30
-    /**
31
-     * @var array|stdClass|null
32
-     */
33
-    private $decoded_data = null;
34
-
35
-    /**
36
-     * JSON_BIGINT_AS_STRING,
37
-     * JSON_INVALID_UTF8_IGNORE,
38
-     * JSON_INVALID_UTF8_SUBSTITUTE,
39
-     * JSON_OBJECT_AS_ARRAY,
40
-     * JSON_THROW_ON_ERROR
41
-     *
42
-     * @var int
43
-     */
44
-    private $decode_flags = 0;
45
-
46
-    /**
47
-     * @var int
48
-     */
49
-    private $depth = 512;
50
-
51
-    /**
52
-     * @var string
53
-     */
54
-    private $encoded_data = '';
55
-
56
-    /**
57
-     * JSON_FORCE_OBJECT,
58
-     * JSON_HEX_QUOT,
59
-     * JSON_HEX_TAG,
60
-     * JSON_HEX_AMP,
61
-     * JSON_HEX_APOS,
62
-     * JSON_INVALID_UTF8_IGNORE,
63
-     * JSON_INVALID_UTF8_SUBSTITUTE,
64
-     * JSON_NUMERIC_CHECK,
65
-     * JSON_PARTIAL_OUTPUT_ON_ERROR,
66
-     * JSON_PRESERVE_ZERO_FRACTION,
67
-     * JSON_PRETTY_PRINT,
68
-     * JSON_UNESCAPED_LINE_TERMINATORS,
69
-     * JSON_UNESCAPED_SLASHES,
70
-     * JSON_UNESCAPED_UNICODE,
71
-     * JSON_THROW_ON_ERROR.
72
-     *
73
-     * @var int
74
-     */
75
-    private $encode_flags = 0;
76
-
77
-    /**
78
-     * @var int
79
-     */
80
-    private $last_error_code = JSON_ERROR_NONE;
81
-
82
-    /**
83
-     * @var string
84
-     */
85
-    private $last_error_msg = JsonDataHandler::NO_ERROR_MSG;
86
-
87
-
88
-    /**
89
-     * JsonDataHandler constructor.
90
-     */
91
-    public function __construct()
92
-    {
93
-        if (! defined('JSON_INVALID_UTF8_IGNORE')) {
94
-            define('JSON_INVALID_UTF8_IGNORE', 1048576);
95
-        }
96
-        if (! defined('JSON_INVALID_UTF8_SUBSTITUTE')) {
97
-            define('JSON_INVALID_UTF8_SUBSTITUTE', 2097152);
98
-        }
99
-        if (! defined('JSON_THROW_ON_ERROR')) {
100
-            define('JSON_THROW_ON_ERROR', 4194304);
101
-        }
102
-    }
103
-
104
-
105
-    /**
106
-     * set $data_type, $decode_flags, $encode_flags, and depth all in one shot
107
-     *
108
-     * @param string $data_type
109
-     * @param int    $decode_flags
110
-     * @param int    $encode_flags
111
-     * @param int    $depth
112
-     */
113
-    public function configure(
114
-        string $data_type = JsonDataHandler::DATA_TYPE_USE_FLAGS,
115
-        int $decode_flags = 0,
116
-        int $encode_flags = 0,
117
-        int $depth = 512
118
-    ) {
119
-        $this->setDataType($data_type);
120
-        $this->setDecodeFlags($decode_flags);
121
-        $this->setDepth($depth);
122
-        $this->setEncodeFlags($encode_flags);
123
-    }
124
-
125
-
126
-    /**
127
-     * @param string $data_type
128
-     */
129
-    public function setDataType(string $data_type): void
130
-    {
131
-        $this->data_type = $data_type === JsonDataHandler::DATA_TYPE_ARRAY
132
-                           || $data_type === JsonDataHandler::DATA_TYPE_OBJECT
133
-                           || $data_type === JsonDataHandler::DATA_TYPE_USE_FLAGS
134
-            ? $data_type
135
-            : JsonDataHandler::DATA_TYPE_USE_FLAGS;
136
-    }
137
-
138
-
139
-    /**
140
-     * One or more Bitmask values:
141
-     * JSON_BIGINT_AS_STRING,
142
-     * JSON_INVALID_UTF8_IGNORE,        PHP >= 7.2
143
-     * JSON_INVALID_UTF8_SUBSTITUTE,    PHP >= 7.2
144
-     * JSON_OBJECT_AS_ARRAY,
145
-     * JSON_THROW_ON_ERROR              PHP >= 7.3
146
-     *
147
-     * pass multiple values separated with |
148
-     * ex: JSON_BIGINT_AS_STRING | JSON_INVALID_UTF8_IGNORE | JSON_OBJECT_AS_ARRAY
149
-     *
150
-     * @param int $decode_flags
151
-     */
152
-    public function setDecodeFlags(int $decode_flags): void
153
-    {
154
-        $this->decode_flags = $decode_flags === JSON_BIGINT_AS_STRING
155
-                              || $decode_flags === JSON_OBJECT_AS_ARRAY
156
-                              // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_ignoreFound
157
-                              || $decode_flags === JSON_INVALID_UTF8_IGNORE
158
-                              // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_substituteFound
159
-                              || $decode_flags === JSON_INVALID_UTF8_SUBSTITUTE
160
-                              // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_throw_on_errorFound
161
-                              || $decode_flags === JSON_THROW_ON_ERROR
162
-            ? $decode_flags
163
-            : 0;
164
-    }
165
-
166
-
167
-    /**
168
-     * @param int $depth
169
-     */
170
-    public function setDepth(int $depth): void
171
-    {
172
-        $depth       = absint($depth);
173
-        $this->depth = $depth ?: 512;
174
-    }
175
-
176
-
177
-    /**
178
-     * One or more Bitmask values:
179
-     * JSON_FORCE_OBJECT,
180
-     * JSON_HEX_QUOT,
181
-     * JSON_HEX_TAG,
182
-     * JSON_HEX_AMP,
183
-     * JSON_HEX_APOS,
184
-     * JSON_INVALID_UTF8_IGNORE,        PHP >= 7.2
185
-     * JSON_INVALID_UTF8_SUBSTITUTE,    PHP >= 7.2
186
-     * JSON_NUMERIC_CHECK,
187
-     * JSON_PARTIAL_OUTPUT_ON_ERROR,
188
-     * JSON_PRESERVE_ZERO_FRACTION,
189
-     * JSON_PRETTY_PRINT,
190
-     * JSON_UNESCAPED_LINE_TERMINATORS,
191
-     * JSON_UNESCAPED_SLASHES,
192
-     * JSON_UNESCAPED_UNICODE,
193
-     * JSON_THROW_ON_ERROR.             PHP >= 7.3
194
-     *
195
-     * pass multiple values separated with |
196
-     * ex: JSON_FORCE_OBJECT | JSON_INVALID_UTF8_IGNORE | JSON_THROW_ON_ERROR
197
-     *
198
-     * @param int $encode_flags
199
-     */
200
-    public function setEncodeFlags(int $encode_flags): void
201
-    {
202
-        $this->encode_flags = $encode_flags === JSON_FORCE_OBJECT
203
-                              || $encode_flags === JSON_HEX_QUOT
204
-                              || $encode_flags === JSON_HEX_TAG
205
-                              || $encode_flags === JSON_HEX_AMP
206
-                              || $encode_flags === JSON_HEX_APOS
207
-                              || $encode_flags === JSON_NUMERIC_CHECK
208
-                              || $encode_flags === JSON_PARTIAL_OUTPUT_ON_ERROR
209
-                              || $encode_flags === JSON_PRESERVE_ZERO_FRACTION
210
-                              || $encode_flags === JSON_PRETTY_PRINT
211
-                              || $encode_flags === JSON_UNESCAPED_LINE_TERMINATORS
212
-                              || $encode_flags === JSON_UNESCAPED_SLASHES
213
-                              || $encode_flags === JSON_UNESCAPED_UNICODE
214
-                              // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_ignoreFound
215
-                              || $encode_flags === JSON_INVALID_UTF8_IGNORE
216
-                              // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_substituteFound
217
-                              || $encode_flags === JSON_INVALID_UTF8_SUBSTITUTE
218
-                              // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_throw_on_errorFound
219
-                              || $encode_flags === JSON_THROW_ON_ERROR
220
-            ? $encode_flags
221
-            : 0;
222
-    }
223
-
224
-
225
-    /**
226
-     * @return string|null
227
-     */
228
-    public function dataType(): ?string
229
-    {
230
-        return $this->data_type;
231
-    }
232
-
233
-
234
-    /**
235
-     * @return bool|null
236
-     */
237
-    private function asAssociative(): ?bool
238
-    {
239
-        switch ($this->data_type) {
240
-            case JsonDataHandler::DATA_TYPE_ARRAY:
241
-                return true;
242
-            case JsonDataHandler::DATA_TYPE_OBJECT:
243
-                return false;
244
-            case JsonDataHandler::DATA_TYPE_USE_FLAGS:
245
-                return null;
246
-        }
247
-        return null;
248
-    }
249
-
250
-
251
-    /**
252
-     * @param array|string $json
253
-     * @return array|mixed|stdClass
254
-     */
255
-    public function decodeJson($json)
256
-    {
257
-        $this->resetErrors();
258
-        if ($this->isJson($json)) {
259
-            $this->decoded_data    = json_decode($json, $this->asAssociative(), $this->depth, $this->decode_flags);
260
-            $this->last_error_code = json_last_error();
261
-            $this->last_error_msg  = json_last_error_msg();
262
-        } else {
263
-            $this->decoded_data    = $json;
264
-            $this->last_error_code = JSON_ERROR_NONE;
265
-            $this->last_error_msg  = JsonDataHandler::NO_ERROR_MSG;
266
-        }
267
-        return $this->decoded_data;
268
-    }
269
-
270
-
271
-    /**
272
-     * @param $data
273
-     * @return string
274
-     */
275
-    public function encodeData($data): string
276
-    {
277
-        $this->resetErrors();
278
-        if ($this->isJson($data)) {
279
-            $this->encoded_data = $data;
280
-            $this->last_error_code = JSON_ERROR_NONE;
281
-            $this->last_error_msg  = JsonDataHandler::NO_ERROR_MSG;
282
-        } else {
283
-            $this->encoded_data = json_encode($data, $this->encode_flags, $this->depth);
284
-            $this->last_error_code = json_last_error();
285
-            $this->last_error_msg  = json_last_error_msg();
286
-        }
287
-        return $this->encoded_data ?: '{}';
288
-    }
289
-
290
-
291
-    /**
292
-     * @return array|stdClass
293
-     */
294
-    public function getDecodedData()
295
-    {
296
-        return $this->decoded_data;
297
-    }
298
-
299
-
300
-    /**
301
-     * @return string
302
-     */
303
-    public function getEncodedData(): string
304
-    {
305
-        return $this->encoded_data;
306
-    }
307
-
308
-
309
-    /**
310
-     * @param bool $reset
311
-     * @return int
312
-     */
313
-    public function getLastErrorCode(bool $reset = false): int
314
-    {
315
-        $last_error = $this->last_error_code;
316
-        if ($reset) {
317
-            $this->resetErrors();
318
-        }
319
-        return $last_error;
320
-    }
321
-
322
-
323
-    /**
324
-     * @param bool $reset
325
-     * @return string
326
-     */
327
-    public function getLastErrorMessage(bool $reset = false): string
328
-    {
329
-        $last_error = $this->last_error_msg;
330
-        if ($reset) {
331
-            $this->resetErrors();
332
-        }
333
-        return $last_error;
334
-    }
335
-
336
-
337
-    /**
338
-     * @param array|string $maybe_json
339
-     * @return bool
340
-     */
341
-    public function isJson($maybe_json): bool
342
-    {
343
-        if (! is_string($maybe_json)) {
344
-            return false;
345
-        }
346
-        $decoded = json_decode($maybe_json, $this->asAssociative(), $this->depth, $this->decode_flags);
347
-        return json_last_error() === JSON_ERROR_NONE && ! ($decoded === null && ! empty($maybe_json));
348
-    }
349
-
350
-
351
-    /**
352
-     * @since $VID:$
353
-     */
354
-    public function resetErrors()
355
-    {
356
-        $this->last_error_code = JSON_ERROR_NONE;
357
-        $this->last_error_msg  = JsonDataHandler::NO_ERROR_MSG;
358
-    }
17
+	const DATA_TYPE_ARRAY     = 'array';
18
+
19
+	const DATA_TYPE_OBJECT    = 'object';
20
+
21
+	const DATA_TYPE_USE_FLAGS = 'flags';
22
+
23
+	const NO_ERROR_MSG        = 'No error';
24
+
25
+	/**
26
+	 * @var string|null
27
+	 */
28
+	private $data_type = null;
29
+
30
+	/**
31
+	 * @var array|stdClass|null
32
+	 */
33
+	private $decoded_data = null;
34
+
35
+	/**
36
+	 * JSON_BIGINT_AS_STRING,
37
+	 * JSON_INVALID_UTF8_IGNORE,
38
+	 * JSON_INVALID_UTF8_SUBSTITUTE,
39
+	 * JSON_OBJECT_AS_ARRAY,
40
+	 * JSON_THROW_ON_ERROR
41
+	 *
42
+	 * @var int
43
+	 */
44
+	private $decode_flags = 0;
45
+
46
+	/**
47
+	 * @var int
48
+	 */
49
+	private $depth = 512;
50
+
51
+	/**
52
+	 * @var string
53
+	 */
54
+	private $encoded_data = '';
55
+
56
+	/**
57
+	 * JSON_FORCE_OBJECT,
58
+	 * JSON_HEX_QUOT,
59
+	 * JSON_HEX_TAG,
60
+	 * JSON_HEX_AMP,
61
+	 * JSON_HEX_APOS,
62
+	 * JSON_INVALID_UTF8_IGNORE,
63
+	 * JSON_INVALID_UTF8_SUBSTITUTE,
64
+	 * JSON_NUMERIC_CHECK,
65
+	 * JSON_PARTIAL_OUTPUT_ON_ERROR,
66
+	 * JSON_PRESERVE_ZERO_FRACTION,
67
+	 * JSON_PRETTY_PRINT,
68
+	 * JSON_UNESCAPED_LINE_TERMINATORS,
69
+	 * JSON_UNESCAPED_SLASHES,
70
+	 * JSON_UNESCAPED_UNICODE,
71
+	 * JSON_THROW_ON_ERROR.
72
+	 *
73
+	 * @var int
74
+	 */
75
+	private $encode_flags = 0;
76
+
77
+	/**
78
+	 * @var int
79
+	 */
80
+	private $last_error_code = JSON_ERROR_NONE;
81
+
82
+	/**
83
+	 * @var string
84
+	 */
85
+	private $last_error_msg = JsonDataHandler::NO_ERROR_MSG;
86
+
87
+
88
+	/**
89
+	 * JsonDataHandler constructor.
90
+	 */
91
+	public function __construct()
92
+	{
93
+		if (! defined('JSON_INVALID_UTF8_IGNORE')) {
94
+			define('JSON_INVALID_UTF8_IGNORE', 1048576);
95
+		}
96
+		if (! defined('JSON_INVALID_UTF8_SUBSTITUTE')) {
97
+			define('JSON_INVALID_UTF8_SUBSTITUTE', 2097152);
98
+		}
99
+		if (! defined('JSON_THROW_ON_ERROR')) {
100
+			define('JSON_THROW_ON_ERROR', 4194304);
101
+		}
102
+	}
103
+
104
+
105
+	/**
106
+	 * set $data_type, $decode_flags, $encode_flags, and depth all in one shot
107
+	 *
108
+	 * @param string $data_type
109
+	 * @param int    $decode_flags
110
+	 * @param int    $encode_flags
111
+	 * @param int    $depth
112
+	 */
113
+	public function configure(
114
+		string $data_type = JsonDataHandler::DATA_TYPE_USE_FLAGS,
115
+		int $decode_flags = 0,
116
+		int $encode_flags = 0,
117
+		int $depth = 512
118
+	) {
119
+		$this->setDataType($data_type);
120
+		$this->setDecodeFlags($decode_flags);
121
+		$this->setDepth($depth);
122
+		$this->setEncodeFlags($encode_flags);
123
+	}
124
+
125
+
126
+	/**
127
+	 * @param string $data_type
128
+	 */
129
+	public function setDataType(string $data_type): void
130
+	{
131
+		$this->data_type = $data_type === JsonDataHandler::DATA_TYPE_ARRAY
132
+						   || $data_type === JsonDataHandler::DATA_TYPE_OBJECT
133
+						   || $data_type === JsonDataHandler::DATA_TYPE_USE_FLAGS
134
+			? $data_type
135
+			: JsonDataHandler::DATA_TYPE_USE_FLAGS;
136
+	}
137
+
138
+
139
+	/**
140
+	 * One or more Bitmask values:
141
+	 * JSON_BIGINT_AS_STRING,
142
+	 * JSON_INVALID_UTF8_IGNORE,        PHP >= 7.2
143
+	 * JSON_INVALID_UTF8_SUBSTITUTE,    PHP >= 7.2
144
+	 * JSON_OBJECT_AS_ARRAY,
145
+	 * JSON_THROW_ON_ERROR              PHP >= 7.3
146
+	 *
147
+	 * pass multiple values separated with |
148
+	 * ex: JSON_BIGINT_AS_STRING | JSON_INVALID_UTF8_IGNORE | JSON_OBJECT_AS_ARRAY
149
+	 *
150
+	 * @param int $decode_flags
151
+	 */
152
+	public function setDecodeFlags(int $decode_flags): void
153
+	{
154
+		$this->decode_flags = $decode_flags === JSON_BIGINT_AS_STRING
155
+							  || $decode_flags === JSON_OBJECT_AS_ARRAY
156
+							  // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_ignoreFound
157
+							  || $decode_flags === JSON_INVALID_UTF8_IGNORE
158
+							  // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_substituteFound
159
+							  || $decode_flags === JSON_INVALID_UTF8_SUBSTITUTE
160
+							  // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_throw_on_errorFound
161
+							  || $decode_flags === JSON_THROW_ON_ERROR
162
+			? $decode_flags
163
+			: 0;
164
+	}
165
+
166
+
167
+	/**
168
+	 * @param int $depth
169
+	 */
170
+	public function setDepth(int $depth): void
171
+	{
172
+		$depth       = absint($depth);
173
+		$this->depth = $depth ?: 512;
174
+	}
175
+
176
+
177
+	/**
178
+	 * One or more Bitmask values:
179
+	 * JSON_FORCE_OBJECT,
180
+	 * JSON_HEX_QUOT,
181
+	 * JSON_HEX_TAG,
182
+	 * JSON_HEX_AMP,
183
+	 * JSON_HEX_APOS,
184
+	 * JSON_INVALID_UTF8_IGNORE,        PHP >= 7.2
185
+	 * JSON_INVALID_UTF8_SUBSTITUTE,    PHP >= 7.2
186
+	 * JSON_NUMERIC_CHECK,
187
+	 * JSON_PARTIAL_OUTPUT_ON_ERROR,
188
+	 * JSON_PRESERVE_ZERO_FRACTION,
189
+	 * JSON_PRETTY_PRINT,
190
+	 * JSON_UNESCAPED_LINE_TERMINATORS,
191
+	 * JSON_UNESCAPED_SLASHES,
192
+	 * JSON_UNESCAPED_UNICODE,
193
+	 * JSON_THROW_ON_ERROR.             PHP >= 7.3
194
+	 *
195
+	 * pass multiple values separated with |
196
+	 * ex: JSON_FORCE_OBJECT | JSON_INVALID_UTF8_IGNORE | JSON_THROW_ON_ERROR
197
+	 *
198
+	 * @param int $encode_flags
199
+	 */
200
+	public function setEncodeFlags(int $encode_flags): void
201
+	{
202
+		$this->encode_flags = $encode_flags === JSON_FORCE_OBJECT
203
+							  || $encode_flags === JSON_HEX_QUOT
204
+							  || $encode_flags === JSON_HEX_TAG
205
+							  || $encode_flags === JSON_HEX_AMP
206
+							  || $encode_flags === JSON_HEX_APOS
207
+							  || $encode_flags === JSON_NUMERIC_CHECK
208
+							  || $encode_flags === JSON_PARTIAL_OUTPUT_ON_ERROR
209
+							  || $encode_flags === JSON_PRESERVE_ZERO_FRACTION
210
+							  || $encode_flags === JSON_PRETTY_PRINT
211
+							  || $encode_flags === JSON_UNESCAPED_LINE_TERMINATORS
212
+							  || $encode_flags === JSON_UNESCAPED_SLASHES
213
+							  || $encode_flags === JSON_UNESCAPED_UNICODE
214
+							  // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_ignoreFound
215
+							  || $encode_flags === JSON_INVALID_UTF8_IGNORE
216
+							  // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_substituteFound
217
+							  || $encode_flags === JSON_INVALID_UTF8_SUBSTITUTE
218
+							  // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_throw_on_errorFound
219
+							  || $encode_flags === JSON_THROW_ON_ERROR
220
+			? $encode_flags
221
+			: 0;
222
+	}
223
+
224
+
225
+	/**
226
+	 * @return string|null
227
+	 */
228
+	public function dataType(): ?string
229
+	{
230
+		return $this->data_type;
231
+	}
232
+
233
+
234
+	/**
235
+	 * @return bool|null
236
+	 */
237
+	private function asAssociative(): ?bool
238
+	{
239
+		switch ($this->data_type) {
240
+			case JsonDataHandler::DATA_TYPE_ARRAY:
241
+				return true;
242
+			case JsonDataHandler::DATA_TYPE_OBJECT:
243
+				return false;
244
+			case JsonDataHandler::DATA_TYPE_USE_FLAGS:
245
+				return null;
246
+		}
247
+		return null;
248
+	}
249
+
250
+
251
+	/**
252
+	 * @param array|string $json
253
+	 * @return array|mixed|stdClass
254
+	 */
255
+	public function decodeJson($json)
256
+	{
257
+		$this->resetErrors();
258
+		if ($this->isJson($json)) {
259
+			$this->decoded_data    = json_decode($json, $this->asAssociative(), $this->depth, $this->decode_flags);
260
+			$this->last_error_code = json_last_error();
261
+			$this->last_error_msg  = json_last_error_msg();
262
+		} else {
263
+			$this->decoded_data    = $json;
264
+			$this->last_error_code = JSON_ERROR_NONE;
265
+			$this->last_error_msg  = JsonDataHandler::NO_ERROR_MSG;
266
+		}
267
+		return $this->decoded_data;
268
+	}
269
+
270
+
271
+	/**
272
+	 * @param $data
273
+	 * @return string
274
+	 */
275
+	public function encodeData($data): string
276
+	{
277
+		$this->resetErrors();
278
+		if ($this->isJson($data)) {
279
+			$this->encoded_data = $data;
280
+			$this->last_error_code = JSON_ERROR_NONE;
281
+			$this->last_error_msg  = JsonDataHandler::NO_ERROR_MSG;
282
+		} else {
283
+			$this->encoded_data = json_encode($data, $this->encode_flags, $this->depth);
284
+			$this->last_error_code = json_last_error();
285
+			$this->last_error_msg  = json_last_error_msg();
286
+		}
287
+		return $this->encoded_data ?: '{}';
288
+	}
289
+
290
+
291
+	/**
292
+	 * @return array|stdClass
293
+	 */
294
+	public function getDecodedData()
295
+	{
296
+		return $this->decoded_data;
297
+	}
298
+
299
+
300
+	/**
301
+	 * @return string
302
+	 */
303
+	public function getEncodedData(): string
304
+	{
305
+		return $this->encoded_data;
306
+	}
307
+
308
+
309
+	/**
310
+	 * @param bool $reset
311
+	 * @return int
312
+	 */
313
+	public function getLastErrorCode(bool $reset = false): int
314
+	{
315
+		$last_error = $this->last_error_code;
316
+		if ($reset) {
317
+			$this->resetErrors();
318
+		}
319
+		return $last_error;
320
+	}
321
+
322
+
323
+	/**
324
+	 * @param bool $reset
325
+	 * @return string
326
+	 */
327
+	public function getLastErrorMessage(bool $reset = false): string
328
+	{
329
+		$last_error = $this->last_error_msg;
330
+		if ($reset) {
331
+			$this->resetErrors();
332
+		}
333
+		return $last_error;
334
+	}
335
+
336
+
337
+	/**
338
+	 * @param array|string $maybe_json
339
+	 * @return bool
340
+	 */
341
+	public function isJson($maybe_json): bool
342
+	{
343
+		if (! is_string($maybe_json)) {
344
+			return false;
345
+		}
346
+		$decoded = json_decode($maybe_json, $this->asAssociative(), $this->depth, $this->decode_flags);
347
+		return json_last_error() === JSON_ERROR_NONE && ! ($decoded === null && ! empty($maybe_json));
348
+	}
349
+
350
+
351
+	/**
352
+	 * @since $VID:$
353
+	 */
354
+	public function resetErrors()
355
+	{
356
+		$this->last_error_code = JSON_ERROR_NONE;
357
+		$this->last_error_msg  = JsonDataHandler::NO_ERROR_MSG;
358
+	}
359 359
 }
Please login to merge, or discard this patch.
admin_pages/maintenance/Maintenance_Admin_Page.core.php 1 patch
Indentation   +948 added lines, -948 removed lines patch added patch discarded remove patch
@@ -14,952 +14,952 @@
 block discarded – undo
14 14
  */
15 15
 class Maintenance_Admin_Page extends EE_Admin_Page
16 16
 {
17
-    /**
18
-     * @var EE_Data_Migration_Manager
19
-     */
20
-    protected $migration_manager;
21
-
22
-    /**
23
-     * @var EE_Maintenance_Mode
24
-     */
25
-    protected $maintenance_mode;
26
-
27
-    /**
28
-     * @var EE_Form_Section_Proper
29
-     */
30
-    protected $datetime_fix_offset_form;
31
-
32
-
33
-    /**
34
-     * @param bool $routing
35
-     * @throws EE_Error
36
-     * @throws ReflectionException
37
-     */
38
-    public function __construct($routing = true)
39
-    {
40
-        $this->migration_manager = EE_Data_Migration_Manager::instance();
41
-        $this->maintenance_mode  = EE_Maintenance_Mode::instance();
42
-        parent::__construct($routing);
43
-    }
44
-
45
-
46
-    protected function _init_page_props()
47
-    {
48
-        $this->page_slug        = EE_MAINTENANCE_PG_SLUG;
49
-        $this->page_label       = EE_MAINTENANCE_LABEL;
50
-        $this->_admin_base_url  = EE_MAINTENANCE_ADMIN_URL;
51
-        $this->_admin_base_path = EE_MAINTENANCE_ADMIN;
52
-    }
53
-
54
-
55
-    protected function _ajax_hooks()
56
-    {
57
-        add_action('wp_ajax_migration_step', [$this, 'migration_step']);
58
-        add_action('wp_ajax_add_error_to_migrations_ran', [$this, 'add_error_to_migrations_ran']);
59
-    }
60
-
61
-
62
-    protected function _define_page_props()
63
-    {
64
-        $this->_admin_page_title = EE_MAINTENANCE_LABEL;
65
-        $this->_labels           = [
66
-            'buttons' => [
67
-                'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'),
68
-                'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'),
69
-            ],
70
-        ];
71
-    }
72
-
73
-
74
-    protected function _set_page_routes()
75
-    {
76
-        $this->_page_routes = [
77
-            'default'                             => [
78
-                'func'       => '_maintenance',
79
-                'capability' => 'manage_options',
80
-            ],
81
-            'change_maintenance_level'            => [
82
-                'func'       => '_change_maintenance_level',
83
-                'capability' => 'manage_options',
84
-                'noheader'   => true,
85
-            ],
86
-            'system_status'                       => [
87
-                'func'       => '_system_status',
88
-                'capability' => 'manage_options',
89
-            ],
90
-            'download_system_status'              => [
91
-                'func'       => '_download_system_status',
92
-                'capability' => 'manage_options',
93
-                'noheader'   => true,
94
-            ],
95
-            'send_migration_crash_report'         => [
96
-                'func'       => '_send_migration_crash_report',
97
-                'capability' => 'manage_options',
98
-                'noheader'   => true,
99
-            ],
100
-            'confirm_migration_crash_report_sent' => [
101
-                'func'       => '_confirm_migration_crash_report_sent',
102
-                'capability' => 'manage_options',
103
-            ],
104
-            'data_reset'                          => [
105
-                'func'       => '_data_reset_and_delete',
106
-                'capability' => 'manage_options',
107
-            ],
108
-            'reset_db'                            => [
109
-                'func'       => '_reset_db',
110
-                'capability' => 'manage_options',
111
-                'noheader'   => true,
112
-                'args'       => ['nuke_old_ee4_data' => true],
113
-            ],
114
-            'start_with_fresh_ee4_db'             => [
115
-                'func'       => '_reset_db',
116
-                'capability' => 'manage_options',
117
-                'noheader'   => true,
118
-                'args'       => ['nuke_old_ee4_data' => false],
119
-            ],
120
-            'delete_db'                           => [
121
-                'func'       => '_delete_db',
122
-                'capability' => 'manage_options',
123
-                'noheader'   => true,
124
-            ],
125
-            'rerun_migration_from_ee3'            => [
126
-                'func'       => '_rerun_migration_from_ee3',
127
-                'capability' => 'manage_options',
128
-                'noheader'   => true,
129
-            ],
130
-            'reset_reservations'                  => [
131
-                'func'       => '_reset_reservations',
132
-                'capability' => 'manage_options',
133
-                'noheader'   => true,
134
-            ],
135
-            'reset_capabilities'                  => [
136
-                'func'       => '_reset_capabilities',
137
-                'capability' => 'manage_options',
138
-                'noheader'   => true,
139
-            ],
140
-            'reattempt_migration'                 => [
141
-                'func'       => '_reattempt_migration',
142
-                'capability' => 'manage_options',
143
-                'noheader'   => true,
144
-            ],
145
-            'datetime_tools'                      => [
146
-                'func'       => '_datetime_tools',
147
-                'capability' => 'manage_options',
148
-            ],
149
-            'run_datetime_offset_fix'             => [
150
-                'func'               => '_apply_datetime_offset',
151
-                'noheader'           => true,
152
-                'headers_sent_route' => 'datetime_tools',
153
-                'capability'         => 'manage_options',
154
-            ],
155
-        ];
156
-    }
157
-
158
-
159
-    protected function _set_page_config()
160
-    {
161
-        $this->_page_config = [
162
-            'default'        => [
163
-                'nav'           => [
164
-                    'label' => esc_html__('Maintenance', 'event_espresso'),
165
-                    'order' => 10,
166
-                ],
167
-                'require_nonce' => false,
168
-            ],
169
-            'data_reset'     => [
170
-                'nav'           => [
171
-                    'label' => esc_html__('Reset/Delete Data', 'event_espresso'),
172
-                    'order' => 20,
173
-                ],
174
-                'require_nonce' => false,
175
-            ],
176
-            'datetime_tools' => [
177
-                'nav'           => [
178
-                    'label' => esc_html__('Datetime Utilities', 'event_espresso'),
179
-                    'order' => 25,
180
-                ],
181
-                'require_nonce' => false,
182
-            ],
183
-            'system_status'  => [
184
-                'nav'           => [
185
-                    'label' => esc_html__("System Information", "event_espresso"),
186
-                    'order' => 30,
187
-                ],
188
-                'require_nonce' => false,
189
-            ],
190
-        ];
191
-    }
192
-
193
-
194
-    /**
195
-     * default maintenance page.
196
-     * If we're in maintenance mode level 2, then we need to show the migration scripts and all that UI.
197
-     *
198
-     * @throws EE_Error
199
-     */
200
-    public function _maintenance()
201
-    {
202
-        $show_maintenance_switch         = true;
203
-        $show_backup_db_text             = false;
204
-        $show_migration_progress         = false;
205
-        $script_names                    = [];
206
-        $addons_should_be_upgraded_first = false;
207
-        // it all depends on if we're in maintenance model level 1 (frontend-only) or
208
-        // level 2 (everything except maintenance page)
209
-        try {
210
-            // get the current maintenance level and check if
211
-            // we are removed
212
-            $mMode_level  = $this->maintenance_mode->level();
213
-            $placed_in_mm = $this->maintenance_mode->set_maintenance_mode_if_db_old();
214
-            if ($mMode_level == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) {
215
-                // we just took the site out of maintenance mode, so notify the user.
216
-                // unfortunately this message appears to be echoed on the NEXT page load...
217
-                // oh well, we should really be checking for this on addon deactivation anyways
218
-                EE_Error::add_attention(
219
-                    esc_html__(
220
-                        'Site taken out of maintenance mode because no data migration scripts are required',
221
-                        'event_espresso'
222
-                    )
223
-                );
224
-                $this->_process_notices(['page' => 'espresso_maintenance_settings']);
225
-            }
226
-            // in case an exception is thrown while trying to handle migrations
227
-            if ($mMode_level === EE_Maintenance_Mode::level_2_complete_maintenance) {
228
-                $show_maintenance_switch = false;
229
-                $show_migration_progress = true;
230
-                if (isset($this->_req_data['continue_migration'])) {
231
-                    $show_backup_db_text = false;
232
-                } else {
233
-                    $show_backup_db_text = true;
234
-                }
235
-                $scripts_needing_to_run          =
236
-                    $this->migration_manager->check_for_applicable_data_migration_scripts();
237
-                $addons_should_be_upgraded_first = $this->migration_manager->addons_need_updating();
238
-                $script_names                    = [];
239
-                $current_script                  = null;
240
-                foreach ($scripts_needing_to_run as $script) {
241
-                    if ($script instanceof EE_Data_Migration_Script_Base) {
242
-                        if (! $current_script) {
243
-                            $current_script = $script;
244
-                            $current_script->migration_page_hooks();
245
-                        }
246
-                        $script_names[] = $script->pretty_name();
247
-                    }
248
-                }
249
-            }
250
-            $most_recent_migration = $this->migration_manager->get_last_ran_script(true);
251
-            $exception_thrown      = false;
252
-        } catch (EE_Error $e) {
253
-            $this->migration_manager->add_error_to_migrations_ran($e->getMessage());
254
-            // now, just so we can display the page correctly, make an error migration script stage object
255
-            // and also put the error on it. It only persists for the duration of this request
256
-            $most_recent_migration = new EE_DMS_Unknown_1_0_0();
257
-            $most_recent_migration->add_error($e->getMessage());
258
-            $exception_thrown = true;
259
-        }
260
-        $current_db_state = $this->migration_manager->ensure_current_database_state_is_set();
261
-        $current_db_state = str_replace('.decaf', '', $current_db_state);
262
-        if (
263
-            $exception_thrown
264
-            || (
265
-                $most_recent_migration instanceof EE_Data_Migration_Script_Base
266
-                && $most_recent_migration->is_broken()
267
-            )
268
-        ) {
269
-            $this->_template_path                =
270
-                EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
271
-            $this->_template_args['support_url'] = 'https://eventespresso.com/support/forums/';
272
-            $this->_template_args['next_url']    = EEH_URL::add_query_args_and_nonce(
273
-                [
274
-                    'action'  => 'confirm_migration_crash_report_sent',
275
-                    'success' => '0',
276
-                ],
277
-                EE_MAINTENANCE_ADMIN_URL
278
-            );
279
-        } elseif ($addons_should_be_upgraded_first) {
280
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
281
-        } else {
282
-            if (
283
-                $most_recent_migration instanceof EE_Data_Migration_Script_Base
284
-                && $most_recent_migration->can_continue()
285
-            ) {
286
-                $show_backup_db_text                    = false;
287
-                $show_continue_current_migration_script = true;
288
-                $show_most_recent_migration             = true;
289
-            } elseif (isset($this->_req_data['continue_migration'])) {
290
-                $show_most_recent_migration             = true;
291
-                $show_continue_current_migration_script = false;
292
-            } else {
293
-                $show_most_recent_migration             = false;
294
-                $show_continue_current_migration_script = false;
295
-            }
296
-            if (isset($current_script)) {
297
-                $migrates_to          = $current_script->migrates_to_version();
298
-                $plugin_slug          = $migrates_to['slug'];
299
-                $new_version          = $migrates_to['version'];
300
-                $this->_template_args = array_merge(
301
-                    $this->_template_args,
302
-                    [
303
-                        'current_db_state' => sprintf(
304
-                            esc_html__("EE%s (%s)", "event_espresso"),
305
-                            isset($current_db_state[ $plugin_slug ]) ? $current_db_state[ $plugin_slug ] : 3,
306
-                            $plugin_slug
307
-                        ),
308
-                        'next_db_state'    => sprintf(
309
-                            esc_html__("EE%s (%s)", 'event_espresso'),
310
-                            $new_version,
311
-                            $plugin_slug
312
-                        ),
313
-                    ]
314
-                );
315
-            } else {
316
-                $this->_template_args['current_db_state'] = null;
317
-                $this->_template_args['next_db_state']    = null;
318
-            }
319
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
320
-            $this->_template_args = array_merge(
321
-                $this->_template_args,
322
-                [
323
-                    'show_most_recent_migration'             => $show_most_recent_migration,
324
-                    // flag for showing the most recent migration's status and/or errors
325
-                    'show_migration_progress'                => $show_migration_progress,
326
-                    // flag for showing the option to run migrations and see their progress
327
-                    'show_backup_db_text'                    => $show_backup_db_text,
328
-                    // flag for showing text telling the user to back up their DB
329
-                    'show_maintenance_switch'                => $show_maintenance_switch,
330
-                    // flag for showing the option to change maintenance mode between levels 0 and 1
331
-                    'script_names'                           => $script_names,
332
-                    // array of names of scripts that have run
333
-                    'show_continue_current_migration_script' => $show_continue_current_migration_script,
334
-                    // flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0
335
-                    'reset_db_page_link'                     => EE_Admin_Page::add_query_args_and_nonce(
336
-                        ['action' => 'reset_db'],
337
-                        EE_MAINTENANCE_ADMIN_URL
338
-                    ),
339
-                    'data_reset_page'                        => EE_Admin_Page::add_query_args_and_nonce(
340
-                        ['action' => 'data_reset'],
341
-                        EE_MAINTENANCE_ADMIN_URL
342
-                    ),
343
-                    'update_migration_script_page_link'      => EE_Admin_Page::add_query_args_and_nonce(
344
-                        ['action' => 'change_maintenance_level'],
345
-                        EE_MAINTENANCE_ADMIN_URL
346
-                    ),
347
-                    'ultimate_db_state'                      => sprintf(
348
-                        esc_html__("EE%s", 'event_espresso'),
349
-                        espresso_version()
350
-                    ),
351
-                ]
352
-            );
353
-        }
354
-        $this->_template_args['most_recent_migration'] =
355
-            $most_recent_migration;// the actual most recently ran migration
356
-        // now render the migration options part, and put it in a variable
357
-        $migration_options_template_file                = apply_filters(
358
-            'FHEE__ee_migration_page__migration_options_template',
359
-            EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
360
-        );
361
-        $migration_options_html                         = EEH_Template::display_template(
362
-            $migration_options_template_file,
363
-            $this->_template_args,
364
-            true
365
-        );
366
-        $this->_template_args['migration_options_html'] = $migration_options_html;
367
-        $this->_template_args['admin_page_content']     = EEH_Template::display_template(
368
-            $this->_template_path,
369
-            $this->_template_args,
370
-            true
371
-        );
372
-        $this->display_admin_page_with_sidebar();
373
-    }
374
-
375
-
376
-    /**
377
-     * returns JSON and executes another step of the currently-executing data migration (called via ajax)
378
-     *
379
-     * @throws EE_Error
380
-     */
381
-    public function migration_step()
382
-    {
383
-        $this->_template_args['data'] = $this->migration_manager->response_to_migration_ajax_request();
384
-        $this->_return_json();
385
-    }
386
-
387
-
388
-    /**
389
-     * Can be used by js when it notices a response with HTML in it in order
390
-     * to log the malformed response
391
-     *
392
-     * @throws EE_Error
393
-     */
394
-    public function add_error_to_migrations_ran()
395
-    {
396
-        $this->migration_manager->add_error_to_migrations_ran($this->_req_data['message']);
397
-        $this->_template_args['data'] = ['ok' => true];
398
-        $this->_return_json();
399
-    }
400
-
401
-
402
-    /**
403
-     * changes the maintenance level, provided there are still no migration scripts that should run
404
-     *
405
-     * @throws EE_Error
406
-     */
407
-    public function _change_maintenance_level()
408
-    {
409
-        $new_level = absint($this->_req_data['maintenance_mode_level']);
410
-        if (! $this->migration_manager->check_for_applicable_data_migration_scripts()) {
411
-            $this->maintenance_mode->set_maintenance_level($new_level);
412
-            $success = true;
413
-        } else {
414
-            $this->maintenance_mode->set_maintenance_mode_if_db_old();
415
-            $success = false;
416
-        }
417
-        $this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso"));
418
-    }
419
-
420
-
421
-    /**
422
-     * a tab with options for resetting and/or deleting EE data
423
-     *
424
-     * @throws EE_Error
425
-     * @throws DomainException
426
-     */
427
-    public function _data_reset_and_delete()
428
-    {
429
-        $this->_template_path                              =
430
-            EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
431
-        $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
432
-            'reset_reservations',
433
-            'reset_reservations',
434
-            [],
435
-            'button button--caution ee-confirm'
436
-        );
437
-        $this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button(
438
-            'reset_capabilities',
439
-            'reset_capabilities',
440
-            [],
441
-            'button button--caution ee-confirm'
442
-        );
443
-        $this->_template_args['delete_db_url']             = EE_Admin_Page::add_query_args_and_nonce(
444
-            ['action' => 'delete_db'],
445
-            EE_MAINTENANCE_ADMIN_URL
446
-        );
447
-        $this->_template_args['reset_db_url']              = EE_Admin_Page::add_query_args_and_nonce(
448
-            ['action' => 'reset_db'],
449
-            EE_MAINTENANCE_ADMIN_URL
450
-        );
451
-        $this->_template_args['admin_page_content']        = EEH_Template::display_template(
452
-            $this->_template_path,
453
-            $this->_template_args,
454
-            true
455
-        );
456
-        $this->display_admin_page_with_no_sidebar();
457
-    }
458
-
459
-
460
-    /**
461
-     * @throws EE_Error
462
-     * @throws ReflectionException
463
-     */
464
-    protected function _reset_reservations()
465
-    {
466
-        if (EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
467
-            EE_Error::add_success(
468
-                esc_html__(
469
-                    'Ticket and datetime reserved counts have been successfully reset.',
470
-                    'event_espresso'
471
-                )
472
-            );
473
-        } else {
474
-            EE_Error::add_success(
475
-                esc_html__(
476
-                    'Ticket and datetime reserved counts were correct and did not need resetting.',
477
-                    'event_espresso'
478
-                )
479
-            );
480
-        }
481
-        $this->_redirect_after_action(true, '', '', ['action' => 'data_reset'], true);
482
-    }
483
-
484
-
485
-    /**
486
-     * @throws EE_Error
487
-     */
488
-    protected function _reset_capabilities()
489
-    {
490
-        EE_Registry::instance()->CAP->init_caps(true);
491
-        EE_Error::add_success(
492
-            esc_html__(
493
-                'Default Event Espresso capabilities have been restored for all current roles.',
494
-                'event_espresso'
495
-            )
496
-        );
497
-        $this->_redirect_after_action(false, '', '', ['action' => 'data_reset'], true);
498
-    }
499
-
500
-
501
-    /**
502
-     * resets the DMSs, so we can attempt to continue migrating after a fatal error
503
-     * (only a good idea when someone has somehow tried ot fix whatever caused
504
-     * the fatal error in teh first place)
505
-     *
506
-     * @throws EE_Error
507
-     */
508
-    protected function _reattempt_migration()
509
-    {
510
-        $this->migration_manager->reattempt();
511
-        $this->_redirect_after_action(false, '', '', ['action' => 'default'], true);
512
-    }
513
-
514
-
515
-    /**
516
-     * shows the big ol' System Information page
517
-     *
518
-     * @throws EE_Error
519
-     */
520
-    public function _system_status()
521
-    {
522
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
523
-        $this->_template_args['system_stati']               = EEM_System_Status::instance()->get_system_stati();
524
-        $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
525
-            [
526
-                'action' => 'download_system_status',
527
-            ],
528
-            EE_MAINTENANCE_ADMIN_URL
529
-        );
530
-        $this->_template_args['admin_page_content']         = EEH_Template::display_template(
531
-            $this->_template_path,
532
-            $this->_template_args,
533
-            true
534
-        );
535
-        $this->display_admin_page_with_no_sidebar();
536
-    }
537
-
538
-
539
-    /**
540
-     * Downloads an HTML file of the system status that can be easily stored or emailed
541
-     */
542
-    public function _download_system_status()
543
-    {
544
-        $status_info = EEM_System_Status::instance()->get_system_stati();
545
-        header('Content-Disposition: attachment');
546
-        header("Content-Disposition: attachment; filename=system_status_" . sanitize_key(site_url()) . ".html");
547
-        $output = '<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>';
548
-        $output .= '<h1>' . sprintf(
549
-            __('System Information for %1$s', 'event_espresso'),
550
-            esc_url_raw(site_url())
551
-        ) . '</h1>';
552
-        $output .= EEH_Template::layout_array_as_table($status_info);
553
-        echo esc_html($output);
554
-        die;
555
-    }
556
-
557
-
558
-    /**
559
-     * @throws EE_Error
560
-     */
561
-    public function _send_migration_crash_report()
562
-    {
563
-        $from      = $this->_req_data['from'];
564
-        $from_name = $this->_req_data['from_name'];
565
-        $body      = $this->_req_data['body'];
566
-        try {
567
-            $success = wp_mail(
568
-                EE_SUPPORT_EMAIL,
569
-                'Migration Crash Report',
570
-                $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
571
-                [
572
-                    "from:$from_name<$from>",
573
-                ]
574
-            );
575
-        } catch (Exception $e) {
576
-            $success = false;
577
-        }
578
-        $this->_redirect_after_action(
579
-            $success,
580
-            esc_html__("Migration Crash Report", "event_espresso"),
581
-            esc_html__("sent", "event_espresso"),
582
-            ['success' => $success, 'action' => 'confirm_migration_crash_report_sent']
583
-        );
584
-    }
585
-
586
-
587
-    /**
588
-     * @throws EE_Error
589
-     */
590
-    public function _confirm_migration_crash_report_sent()
591
-    {
592
-        try {
593
-            $most_recent_migration = $this->migration_manager->get_last_ran_script(true);
594
-        } catch (EE_Error $e) {
595
-            $this->migration_manager->add_error_to_migrations_ran($e->getMessage());
596
-            // now, just so we can display the page correctly, make an error migration script stage object
597
-            // and also put the error on it. It only persists for the duration of this request
598
-            $most_recent_migration = new EE_DMS_Unknown_1_0_0();
599
-            $most_recent_migration->add_error($e->getMessage());
600
-        }
601
-        $success                                       = $this->_req_data['success'] === '1';
602
-        $this->_template_args['success']               = $success;
603
-        $this->_template_args['most_recent_migration'] = $most_recent_migration;
604
-        $this->_template_args['reset_db_action_url']   = EE_Admin_Page::add_query_args_and_nonce(
605
-            ['action' => 'reset_db'],
606
-            EE_MAINTENANCE_ADMIN_URL
607
-        );
608
-        $this->_template_args['reset_db_page_url']     = EE_Admin_Page::add_query_args_and_nonce(
609
-            ['action' => 'data_reset'],
610
-            EE_MAINTENANCE_ADMIN_URL
611
-        );
612
-        $this->_template_args['reattempt_action_url']  = EE_Admin_Page::add_query_args_and_nonce(
613
-            ['action' => 'reattempt_migration'],
614
-            EE_MAINTENANCE_ADMIN_URL
615
-        );
616
-        $this->_template_path                          =
617
-            EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
618
-        $this->_template_args['admin_page_content']    = EEH_Template::display_template(
619
-            $this->_template_path,
620
-            $this->_template_args,
621
-            true
622
-        );
623
-        $this->display_admin_page_with_sidebar();
624
-    }
625
-
626
-
627
-    /**
628
-     * Resets the entire EE4 database.
629
-     * only sets up ee4 database for a fresh install-
630
-     * doesn't actually clean out the old wp options, or cpts
631
-     * (although it does erase old ee table data)
632
-     *
633
-     * @param boolean $nuke_old_ee4_data controls whether we destroy the old ee4 data,
634
-     *                                   or just try initializing ee4 default data
635
-     * @throws EE_Error
636
-     * @throws ReflectionException
637
-     */
638
-    public function _reset_db($nuke_old_ee4_data = true)
639
-    {
640
-        $this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
641
-        if ($nuke_old_ee4_data) {
642
-            EEH_Activation::delete_all_espresso_cpt_data();
643
-            EEH_Activation::delete_all_espresso_tables_and_data(false);
644
-            EEH_Activation::remove_cron_tasks();
645
-        }
646
-        // make sure when we reset the registry's config that it
647
-        // switches to using the new singleton
648
-        EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true);
649
-        EE_System::instance()->initialize_db_if_no_migrations_required(true);
650
-        EE_System::instance()->redirect_to_about_ee();
651
-    }
652
-
653
-
654
-    /**
655
-     * Deletes ALL EE tables, Records, and Options from the database.
656
-     *
657
-     * @throws EE_Error
658
-     * @throws ReflectionException
659
-     */
660
-    public function _delete_db()
661
-    {
662
-        $this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
663
-        EEH_Activation::delete_all_espresso_cpt_data();
664
-        EEH_Activation::delete_all_espresso_tables_and_data();
665
-        EEH_Activation::remove_cron_tasks();
666
-        EEH_Activation::deactivate_event_espresso();
667
-        wp_safe_redirect(admin_url('plugins.php'));
668
-        exit;
669
-    }
670
-
671
-
672
-    /**
673
-     * sets up EE4 to rerun the migrations from ee3 to ee4
674
-     *
675
-     * @throws EE_Error
676
-     * @throws ReflectionException
677
-     */
678
-    public function _rerun_migration_from_ee3()
679
-    {
680
-        $this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
681
-        EEH_Activation::delete_all_espresso_cpt_data();
682
-        EEH_Activation::delete_all_espresso_tables_and_data(false);
683
-        // set the db state to something that will require migrations
684
-        update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0');
685
-        $this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance);
686
-        $this->_redirect_after_action(
687
-            true,
688
-            esc_html__("Database", 'event_espresso'),
689
-            esc_html__("reset", 'event_espresso')
690
-        );
691
-    }
692
-
693
-
694
-    // none of the below group are currently used for Gateway Settings
695
-    protected function _add_screen_options()
696
-    {
697
-    }
698
-
699
-
700
-    protected function _add_feature_pointers()
701
-    {
702
-    }
703
-
704
-
705
-    public function admin_init()
706
-    {
707
-    }
708
-
709
-
710
-    public function admin_notices()
711
-    {
712
-    }
713
-
714
-
715
-    public function admin_footer_scripts()
716
-    {
717
-    }
718
-
719
-
720
-    public function load_scripts_styles()
721
-    {
722
-        wp_enqueue_script('ee_admin_js');
723
-        wp_enqueue_script(
724
-            'ee-maintenance',
725
-            EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.js',
726
-            ['jquery'],
727
-            EVENT_ESPRESSO_VERSION,
728
-            true
729
-        );
730
-        wp_register_style(
731
-            'espresso_maintenance',
732
-            EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css',
733
-            [],
734
-            EVENT_ESPRESSO_VERSION
735
-        );
736
-        wp_enqueue_style('espresso_maintenance');
737
-        // localize script stuff
738
-        wp_localize_script(
739
-            'ee-maintenance',
740
-            'ee_maintenance',
741
-            [
742
-                'migrating'                        => wp_strip_all_tags(__("Updating Database...", "event_espresso")),
743
-                'next'                             => wp_strip_all_tags(__("Next", "event_espresso")),
744
-                'fatal_error'                      => wp_strip_all_tags(__(
745
-                    "A Fatal Error Has Occurred",
746
-                    "event_espresso"
747
-                )),
748
-                'click_next_when_ready'            => wp_strip_all_tags(
749
-                    __(
750
-                        "The current Database Update has ended. Click 'next' when ready to proceed",
751
-                        "event_espresso"
752
-                    )
753
-                ),
754
-                'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts,
755
-                'status_fatal_error'               => EE_Data_Migration_Manager::status_fatal_error,
756
-                'status_completed'                 => EE_Data_Migration_Manager::status_completed,
757
-                'confirm'                          => wp_strip_all_tags(
758
-                    __(
759
-                        'Are you sure you want to do this? It CANNOT be undone!',
760
-                        'event_espresso'
761
-                    )
762
-                ),
763
-                'confirm_skip_migration'           => wp_strip_all_tags(
764
-                    __(
765
-                        'You have chosen to NOT migrate your existing data. Are you sure you want to continue?',
766
-                        'event_espresso'
767
-                    )
768
-                ),
769
-            ]
770
-        );
771
-    }
772
-
773
-
774
-    public function load_scripts_styles_default()
775
-    {
776
-    }
777
-
778
-
779
-    /**
780
-     * Enqueue scripts and styles for the datetime tools page.
781
-     */
782
-    public function load_scripts_styles_datetime_tools()
783
-    {
784
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
785
-    }
786
-
787
-
788
-    /**
789
-     * @throws EE_Error
790
-     */
791
-    protected function _datetime_tools()
792
-    {
793
-        $form_action                                = EE_Admin_Page::add_query_args_and_nonce(
794
-            [
795
-                'action'        => 'run_datetime_offset_fix',
796
-                'return_action' => $this->_req_action,
797
-            ],
798
-            EE_MAINTENANCE_ADMIN_URL
799
-        );
800
-        $form                                       = $this->_get_datetime_offset_fix_form();
801
-        $this->_admin_page_title                    = esc_html__('Datetime Utilities', 'event_espresso');
802
-        $this->_template_args['admin_page_content'] = $form->form_open($form_action, 'post')
803
-                                                      . $form->get_html_and_js()
804
-                                                      . $form->form_close();
805
-        $this->display_admin_page_with_sidebar();
806
-    }
807
-
808
-
809
-    /**
810
-     * @throws EE_Error
811
-     */
812
-    protected function _get_datetime_offset_fix_form()
813
-    {
814
-        if (! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) {
815
-            $this->datetime_fix_offset_form = new EE_Form_Section_Proper(
816
-                [
817
-                    'name'            => 'datetime_offset_fix_option',
818
-                    'layout_strategy' => new EE_Admin_Two_Column_Layout(),
819
-                    'subsections'     => [
820
-                        'title'                  => new EE_Form_Section_HTML(
821
-                            EEH_HTML::h2(
822
-                                esc_html__('Datetime Offset Tool', 'event_espresso')
823
-                            )
824
-                        ),
825
-                        'explanation'            => new EE_Form_Section_HTML(
826
-                            EEH_HTML::p(
827
-                                esc_html__(
828
-                                    'Use this tool to automatically apply the provided offset to all Event Espresso records in your database that involve dates and times.',
829
-                                    'event_espresso'
830
-                                )
831
-                            )
832
-                            . EEH_HTML::p(
833
-                                esc_html__(
834
-                                    '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.',
835
-                                    'event_espresso'
836
-                                )
837
-                            )
838
-                        ),
839
-                        'offset_input'           => new EE_Float_Input(
840
-                            [
841
-                                'html_name'       => 'offset_for_datetimes',
842
-                                'html_label_text' => esc_html__(
843
-                                    'Offset to apply (in hours):',
844
-                                    'event_espresso'
845
-                                ),
846
-                                'min_value'       => '-12',
847
-                                'max_value'       => '14',
848
-                                'step_value'      => '.25',
849
-                                'default'         => DatetimeOffsetFix::getOffset(),
850
-                            ]
851
-                        ),
852
-                        'date_range_explanation' => new EE_Form_Section_HTML(
853
-                            EEH_HTML::p(
854
-                                esc_html__(
855
-                                    'Leave the following fields blank if you want the offset to be applied to all dates. If however, you want to just apply the offset to a specific range of dates you can restrict the offset application using these fields.',
856
-                                    'event_espresso'
857
-                                )
858
-                            )
859
-                            . EEH_HTML::p(
860
-                                EEH_HTML::strong(
861
-                                    sprintf(
862
-                                        esc_html__(
863
-                                            'Note: please enter the dates in UTC (You can use %1$sthis online tool%2$s to assist with conversions).',
864
-                                            'event_espresso'
865
-                                        ),
866
-                                        '<a href="https://www.timeanddate.com/worldclock/converter.html">',
867
-                                        '</a>'
868
-                                    )
869
-                                )
870
-                            )
871
-                        ),
872
-                        'date_range_start_date'  => new EE_Datepicker_Input(
873
-                            [
874
-                                'html_name'       => 'offset_date_start_range',
875
-                                'html_label_text' => esc_html__(
876
-                                    'Start Date for dates the offset applied to:',
877
-                                    'event_espresso'
878
-                                ),
879
-                            ]
880
-                        ),
881
-                        'date_range_end_date'    => new EE_Datepicker_Input(
882
-                            [
883
-                                'html_name'       => 'offset_date_end_range',
884
-                                'html_label_text' => esc_html__(
885
-                                    'End Date for dates the offset is applied to:',
886
-                                    'event_espresso'
887
-                                ),
888
-                            ]
889
-                        ),
890
-                        'submit'                 => new EE_Submit_Input(
891
-                            [
892
-                                'html_label_text' => '',
893
-                                'default'         => esc_html__('Apply Offset', 'event_espresso'),
894
-                            ]
895
-                        ),
896
-                    ],
897
-                ]
898
-            );
899
-        }
900
-        return $this->datetime_fix_offset_form;
901
-    }
902
-
903
-
904
-    /**
905
-     * Callback for the run_datetime_offset_fix route.
906
-     *
907
-     * @throws EE_Error
908
-     */
909
-    protected function _apply_datetime_offset()
910
-    {
911
-        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
912
-            $form = $this->_get_datetime_offset_fix_form();
913
-            $form->receive_form_submission($this->_req_data);
914
-            if ($form->is_valid()) {
915
-                // save offset data so batch processor can get it.
916
-                DatetimeOffsetFix::updateOffset($form->get_input_value('offset_input'));
917
-                $utc_timezone          = new DateTimeZone('UTC');
918
-                $date_range_start_date = DateTime::createFromFormat(
919
-                    'm/d/Y H:i:s',
920
-                    $form->get_input_value('date_range_start_date') . ' 00:00:00',
921
-                    $utc_timezone
922
-                );
923
-                $date_range_end_date   = DateTime::createFromFormat(
924
-                    'm/d/Y H:i:s',
925
-                    $form->get_input_value('date_range_end_date') . ' 23:59:59',
926
-                    $utc_timezone
927
-                );
928
-                if ($date_range_start_date instanceof DateTime) {
929
-                    DatetimeOffsetFix::updateStartDateRange(DbSafeDateTime::createFromDateTime($date_range_start_date));
930
-                }
931
-                if ($date_range_end_date instanceof DateTime) {
932
-                    DatetimeOffsetFix::updateEndDateRange(DbSafeDateTime::createFromDateTime($date_range_end_date));
933
-                }
934
-                // redirect to batch tool
935
-                wp_redirect(
936
-                    EE_Admin_Page::add_query_args_and_nonce(
937
-                        [
938
-                            'page'        => EED_Batch::PAGE_SLUG,
939
-                            'batch'       => EED_Batch::batch_job,
940
-                            'label'       => esc_html__('Applying Offset', 'event_espresso'),
941
-                            'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\DatetimeOffsetFix'),
942
-                            'return_url'  => urlencode(
943
-                                add_query_arg(
944
-                                    [
945
-                                        'action' => 'datetime_tools',
946
-                                    ],
947
-                                    EEH_URL::current_url_without_query_paramaters(
948
-                                        [
949
-                                            'return_action',
950
-                                            'run_datetime_offset_fix_nonce',
951
-                                            'return',
952
-                                            'datetime_tools_nonce',
953
-                                        ]
954
-                                    )
955
-                                )
956
-                            ),
957
-                        ],
958
-                        admin_url()
959
-                    )
960
-                );
961
-                exit;
962
-            }
963
-        }
964
-    }
17
+	/**
18
+	 * @var EE_Data_Migration_Manager
19
+	 */
20
+	protected $migration_manager;
21
+
22
+	/**
23
+	 * @var EE_Maintenance_Mode
24
+	 */
25
+	protected $maintenance_mode;
26
+
27
+	/**
28
+	 * @var EE_Form_Section_Proper
29
+	 */
30
+	protected $datetime_fix_offset_form;
31
+
32
+
33
+	/**
34
+	 * @param bool $routing
35
+	 * @throws EE_Error
36
+	 * @throws ReflectionException
37
+	 */
38
+	public function __construct($routing = true)
39
+	{
40
+		$this->migration_manager = EE_Data_Migration_Manager::instance();
41
+		$this->maintenance_mode  = EE_Maintenance_Mode::instance();
42
+		parent::__construct($routing);
43
+	}
44
+
45
+
46
+	protected function _init_page_props()
47
+	{
48
+		$this->page_slug        = EE_MAINTENANCE_PG_SLUG;
49
+		$this->page_label       = EE_MAINTENANCE_LABEL;
50
+		$this->_admin_base_url  = EE_MAINTENANCE_ADMIN_URL;
51
+		$this->_admin_base_path = EE_MAINTENANCE_ADMIN;
52
+	}
53
+
54
+
55
+	protected function _ajax_hooks()
56
+	{
57
+		add_action('wp_ajax_migration_step', [$this, 'migration_step']);
58
+		add_action('wp_ajax_add_error_to_migrations_ran', [$this, 'add_error_to_migrations_ran']);
59
+	}
60
+
61
+
62
+	protected function _define_page_props()
63
+	{
64
+		$this->_admin_page_title = EE_MAINTENANCE_LABEL;
65
+		$this->_labels           = [
66
+			'buttons' => [
67
+				'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'),
68
+				'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'),
69
+			],
70
+		];
71
+	}
72
+
73
+
74
+	protected function _set_page_routes()
75
+	{
76
+		$this->_page_routes = [
77
+			'default'                             => [
78
+				'func'       => '_maintenance',
79
+				'capability' => 'manage_options',
80
+			],
81
+			'change_maintenance_level'            => [
82
+				'func'       => '_change_maintenance_level',
83
+				'capability' => 'manage_options',
84
+				'noheader'   => true,
85
+			],
86
+			'system_status'                       => [
87
+				'func'       => '_system_status',
88
+				'capability' => 'manage_options',
89
+			],
90
+			'download_system_status'              => [
91
+				'func'       => '_download_system_status',
92
+				'capability' => 'manage_options',
93
+				'noheader'   => true,
94
+			],
95
+			'send_migration_crash_report'         => [
96
+				'func'       => '_send_migration_crash_report',
97
+				'capability' => 'manage_options',
98
+				'noheader'   => true,
99
+			],
100
+			'confirm_migration_crash_report_sent' => [
101
+				'func'       => '_confirm_migration_crash_report_sent',
102
+				'capability' => 'manage_options',
103
+			],
104
+			'data_reset'                          => [
105
+				'func'       => '_data_reset_and_delete',
106
+				'capability' => 'manage_options',
107
+			],
108
+			'reset_db'                            => [
109
+				'func'       => '_reset_db',
110
+				'capability' => 'manage_options',
111
+				'noheader'   => true,
112
+				'args'       => ['nuke_old_ee4_data' => true],
113
+			],
114
+			'start_with_fresh_ee4_db'             => [
115
+				'func'       => '_reset_db',
116
+				'capability' => 'manage_options',
117
+				'noheader'   => true,
118
+				'args'       => ['nuke_old_ee4_data' => false],
119
+			],
120
+			'delete_db'                           => [
121
+				'func'       => '_delete_db',
122
+				'capability' => 'manage_options',
123
+				'noheader'   => true,
124
+			],
125
+			'rerun_migration_from_ee3'            => [
126
+				'func'       => '_rerun_migration_from_ee3',
127
+				'capability' => 'manage_options',
128
+				'noheader'   => true,
129
+			],
130
+			'reset_reservations'                  => [
131
+				'func'       => '_reset_reservations',
132
+				'capability' => 'manage_options',
133
+				'noheader'   => true,
134
+			],
135
+			'reset_capabilities'                  => [
136
+				'func'       => '_reset_capabilities',
137
+				'capability' => 'manage_options',
138
+				'noheader'   => true,
139
+			],
140
+			'reattempt_migration'                 => [
141
+				'func'       => '_reattempt_migration',
142
+				'capability' => 'manage_options',
143
+				'noheader'   => true,
144
+			],
145
+			'datetime_tools'                      => [
146
+				'func'       => '_datetime_tools',
147
+				'capability' => 'manage_options',
148
+			],
149
+			'run_datetime_offset_fix'             => [
150
+				'func'               => '_apply_datetime_offset',
151
+				'noheader'           => true,
152
+				'headers_sent_route' => 'datetime_tools',
153
+				'capability'         => 'manage_options',
154
+			],
155
+		];
156
+	}
157
+
158
+
159
+	protected function _set_page_config()
160
+	{
161
+		$this->_page_config = [
162
+			'default'        => [
163
+				'nav'           => [
164
+					'label' => esc_html__('Maintenance', 'event_espresso'),
165
+					'order' => 10,
166
+				],
167
+				'require_nonce' => false,
168
+			],
169
+			'data_reset'     => [
170
+				'nav'           => [
171
+					'label' => esc_html__('Reset/Delete Data', 'event_espresso'),
172
+					'order' => 20,
173
+				],
174
+				'require_nonce' => false,
175
+			],
176
+			'datetime_tools' => [
177
+				'nav'           => [
178
+					'label' => esc_html__('Datetime Utilities', 'event_espresso'),
179
+					'order' => 25,
180
+				],
181
+				'require_nonce' => false,
182
+			],
183
+			'system_status'  => [
184
+				'nav'           => [
185
+					'label' => esc_html__("System Information", "event_espresso"),
186
+					'order' => 30,
187
+				],
188
+				'require_nonce' => false,
189
+			],
190
+		];
191
+	}
192
+
193
+
194
+	/**
195
+	 * default maintenance page.
196
+	 * If we're in maintenance mode level 2, then we need to show the migration scripts and all that UI.
197
+	 *
198
+	 * @throws EE_Error
199
+	 */
200
+	public function _maintenance()
201
+	{
202
+		$show_maintenance_switch         = true;
203
+		$show_backup_db_text             = false;
204
+		$show_migration_progress         = false;
205
+		$script_names                    = [];
206
+		$addons_should_be_upgraded_first = false;
207
+		// it all depends on if we're in maintenance model level 1 (frontend-only) or
208
+		// level 2 (everything except maintenance page)
209
+		try {
210
+			// get the current maintenance level and check if
211
+			// we are removed
212
+			$mMode_level  = $this->maintenance_mode->level();
213
+			$placed_in_mm = $this->maintenance_mode->set_maintenance_mode_if_db_old();
214
+			if ($mMode_level == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) {
215
+				// we just took the site out of maintenance mode, so notify the user.
216
+				// unfortunately this message appears to be echoed on the NEXT page load...
217
+				// oh well, we should really be checking for this on addon deactivation anyways
218
+				EE_Error::add_attention(
219
+					esc_html__(
220
+						'Site taken out of maintenance mode because no data migration scripts are required',
221
+						'event_espresso'
222
+					)
223
+				);
224
+				$this->_process_notices(['page' => 'espresso_maintenance_settings']);
225
+			}
226
+			// in case an exception is thrown while trying to handle migrations
227
+			if ($mMode_level === EE_Maintenance_Mode::level_2_complete_maintenance) {
228
+				$show_maintenance_switch = false;
229
+				$show_migration_progress = true;
230
+				if (isset($this->_req_data['continue_migration'])) {
231
+					$show_backup_db_text = false;
232
+				} else {
233
+					$show_backup_db_text = true;
234
+				}
235
+				$scripts_needing_to_run          =
236
+					$this->migration_manager->check_for_applicable_data_migration_scripts();
237
+				$addons_should_be_upgraded_first = $this->migration_manager->addons_need_updating();
238
+				$script_names                    = [];
239
+				$current_script                  = null;
240
+				foreach ($scripts_needing_to_run as $script) {
241
+					if ($script instanceof EE_Data_Migration_Script_Base) {
242
+						if (! $current_script) {
243
+							$current_script = $script;
244
+							$current_script->migration_page_hooks();
245
+						}
246
+						$script_names[] = $script->pretty_name();
247
+					}
248
+				}
249
+			}
250
+			$most_recent_migration = $this->migration_manager->get_last_ran_script(true);
251
+			$exception_thrown      = false;
252
+		} catch (EE_Error $e) {
253
+			$this->migration_manager->add_error_to_migrations_ran($e->getMessage());
254
+			// now, just so we can display the page correctly, make an error migration script stage object
255
+			// and also put the error on it. It only persists for the duration of this request
256
+			$most_recent_migration = new EE_DMS_Unknown_1_0_0();
257
+			$most_recent_migration->add_error($e->getMessage());
258
+			$exception_thrown = true;
259
+		}
260
+		$current_db_state = $this->migration_manager->ensure_current_database_state_is_set();
261
+		$current_db_state = str_replace('.decaf', '', $current_db_state);
262
+		if (
263
+			$exception_thrown
264
+			|| (
265
+				$most_recent_migration instanceof EE_Data_Migration_Script_Base
266
+				&& $most_recent_migration->is_broken()
267
+			)
268
+		) {
269
+			$this->_template_path                =
270
+				EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
271
+			$this->_template_args['support_url'] = 'https://eventespresso.com/support/forums/';
272
+			$this->_template_args['next_url']    = EEH_URL::add_query_args_and_nonce(
273
+				[
274
+					'action'  => 'confirm_migration_crash_report_sent',
275
+					'success' => '0',
276
+				],
277
+				EE_MAINTENANCE_ADMIN_URL
278
+			);
279
+		} elseif ($addons_should_be_upgraded_first) {
280
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
281
+		} else {
282
+			if (
283
+				$most_recent_migration instanceof EE_Data_Migration_Script_Base
284
+				&& $most_recent_migration->can_continue()
285
+			) {
286
+				$show_backup_db_text                    = false;
287
+				$show_continue_current_migration_script = true;
288
+				$show_most_recent_migration             = true;
289
+			} elseif (isset($this->_req_data['continue_migration'])) {
290
+				$show_most_recent_migration             = true;
291
+				$show_continue_current_migration_script = false;
292
+			} else {
293
+				$show_most_recent_migration             = false;
294
+				$show_continue_current_migration_script = false;
295
+			}
296
+			if (isset($current_script)) {
297
+				$migrates_to          = $current_script->migrates_to_version();
298
+				$plugin_slug          = $migrates_to['slug'];
299
+				$new_version          = $migrates_to['version'];
300
+				$this->_template_args = array_merge(
301
+					$this->_template_args,
302
+					[
303
+						'current_db_state' => sprintf(
304
+							esc_html__("EE%s (%s)", "event_espresso"),
305
+							isset($current_db_state[ $plugin_slug ]) ? $current_db_state[ $plugin_slug ] : 3,
306
+							$plugin_slug
307
+						),
308
+						'next_db_state'    => sprintf(
309
+							esc_html__("EE%s (%s)", 'event_espresso'),
310
+							$new_version,
311
+							$plugin_slug
312
+						),
313
+					]
314
+				);
315
+			} else {
316
+				$this->_template_args['current_db_state'] = null;
317
+				$this->_template_args['next_db_state']    = null;
318
+			}
319
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
320
+			$this->_template_args = array_merge(
321
+				$this->_template_args,
322
+				[
323
+					'show_most_recent_migration'             => $show_most_recent_migration,
324
+					// flag for showing the most recent migration's status and/or errors
325
+					'show_migration_progress'                => $show_migration_progress,
326
+					// flag for showing the option to run migrations and see their progress
327
+					'show_backup_db_text'                    => $show_backup_db_text,
328
+					// flag for showing text telling the user to back up their DB
329
+					'show_maintenance_switch'                => $show_maintenance_switch,
330
+					// flag for showing the option to change maintenance mode between levels 0 and 1
331
+					'script_names'                           => $script_names,
332
+					// array of names of scripts that have run
333
+					'show_continue_current_migration_script' => $show_continue_current_migration_script,
334
+					// flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0
335
+					'reset_db_page_link'                     => EE_Admin_Page::add_query_args_and_nonce(
336
+						['action' => 'reset_db'],
337
+						EE_MAINTENANCE_ADMIN_URL
338
+					),
339
+					'data_reset_page'                        => EE_Admin_Page::add_query_args_and_nonce(
340
+						['action' => 'data_reset'],
341
+						EE_MAINTENANCE_ADMIN_URL
342
+					),
343
+					'update_migration_script_page_link'      => EE_Admin_Page::add_query_args_and_nonce(
344
+						['action' => 'change_maintenance_level'],
345
+						EE_MAINTENANCE_ADMIN_URL
346
+					),
347
+					'ultimate_db_state'                      => sprintf(
348
+						esc_html__("EE%s", 'event_espresso'),
349
+						espresso_version()
350
+					),
351
+				]
352
+			);
353
+		}
354
+		$this->_template_args['most_recent_migration'] =
355
+			$most_recent_migration;// the actual most recently ran migration
356
+		// now render the migration options part, and put it in a variable
357
+		$migration_options_template_file                = apply_filters(
358
+			'FHEE__ee_migration_page__migration_options_template',
359
+			EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
360
+		);
361
+		$migration_options_html                         = EEH_Template::display_template(
362
+			$migration_options_template_file,
363
+			$this->_template_args,
364
+			true
365
+		);
366
+		$this->_template_args['migration_options_html'] = $migration_options_html;
367
+		$this->_template_args['admin_page_content']     = EEH_Template::display_template(
368
+			$this->_template_path,
369
+			$this->_template_args,
370
+			true
371
+		);
372
+		$this->display_admin_page_with_sidebar();
373
+	}
374
+
375
+
376
+	/**
377
+	 * returns JSON and executes another step of the currently-executing data migration (called via ajax)
378
+	 *
379
+	 * @throws EE_Error
380
+	 */
381
+	public function migration_step()
382
+	{
383
+		$this->_template_args['data'] = $this->migration_manager->response_to_migration_ajax_request();
384
+		$this->_return_json();
385
+	}
386
+
387
+
388
+	/**
389
+	 * Can be used by js when it notices a response with HTML in it in order
390
+	 * to log the malformed response
391
+	 *
392
+	 * @throws EE_Error
393
+	 */
394
+	public function add_error_to_migrations_ran()
395
+	{
396
+		$this->migration_manager->add_error_to_migrations_ran($this->_req_data['message']);
397
+		$this->_template_args['data'] = ['ok' => true];
398
+		$this->_return_json();
399
+	}
400
+
401
+
402
+	/**
403
+	 * changes the maintenance level, provided there are still no migration scripts that should run
404
+	 *
405
+	 * @throws EE_Error
406
+	 */
407
+	public function _change_maintenance_level()
408
+	{
409
+		$new_level = absint($this->_req_data['maintenance_mode_level']);
410
+		if (! $this->migration_manager->check_for_applicable_data_migration_scripts()) {
411
+			$this->maintenance_mode->set_maintenance_level($new_level);
412
+			$success = true;
413
+		} else {
414
+			$this->maintenance_mode->set_maintenance_mode_if_db_old();
415
+			$success = false;
416
+		}
417
+		$this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso"));
418
+	}
419
+
420
+
421
+	/**
422
+	 * a tab with options for resetting and/or deleting EE data
423
+	 *
424
+	 * @throws EE_Error
425
+	 * @throws DomainException
426
+	 */
427
+	public function _data_reset_and_delete()
428
+	{
429
+		$this->_template_path                              =
430
+			EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
431
+		$this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
432
+			'reset_reservations',
433
+			'reset_reservations',
434
+			[],
435
+			'button button--caution ee-confirm'
436
+		);
437
+		$this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button(
438
+			'reset_capabilities',
439
+			'reset_capabilities',
440
+			[],
441
+			'button button--caution ee-confirm'
442
+		);
443
+		$this->_template_args['delete_db_url']             = EE_Admin_Page::add_query_args_and_nonce(
444
+			['action' => 'delete_db'],
445
+			EE_MAINTENANCE_ADMIN_URL
446
+		);
447
+		$this->_template_args['reset_db_url']              = EE_Admin_Page::add_query_args_and_nonce(
448
+			['action' => 'reset_db'],
449
+			EE_MAINTENANCE_ADMIN_URL
450
+		);
451
+		$this->_template_args['admin_page_content']        = EEH_Template::display_template(
452
+			$this->_template_path,
453
+			$this->_template_args,
454
+			true
455
+		);
456
+		$this->display_admin_page_with_no_sidebar();
457
+	}
458
+
459
+
460
+	/**
461
+	 * @throws EE_Error
462
+	 * @throws ReflectionException
463
+	 */
464
+	protected function _reset_reservations()
465
+	{
466
+		if (EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
467
+			EE_Error::add_success(
468
+				esc_html__(
469
+					'Ticket and datetime reserved counts have been successfully reset.',
470
+					'event_espresso'
471
+				)
472
+			);
473
+		} else {
474
+			EE_Error::add_success(
475
+				esc_html__(
476
+					'Ticket and datetime reserved counts were correct and did not need resetting.',
477
+					'event_espresso'
478
+				)
479
+			);
480
+		}
481
+		$this->_redirect_after_action(true, '', '', ['action' => 'data_reset'], true);
482
+	}
483
+
484
+
485
+	/**
486
+	 * @throws EE_Error
487
+	 */
488
+	protected function _reset_capabilities()
489
+	{
490
+		EE_Registry::instance()->CAP->init_caps(true);
491
+		EE_Error::add_success(
492
+			esc_html__(
493
+				'Default Event Espresso capabilities have been restored for all current roles.',
494
+				'event_espresso'
495
+			)
496
+		);
497
+		$this->_redirect_after_action(false, '', '', ['action' => 'data_reset'], true);
498
+	}
499
+
500
+
501
+	/**
502
+	 * resets the DMSs, so we can attempt to continue migrating after a fatal error
503
+	 * (only a good idea when someone has somehow tried ot fix whatever caused
504
+	 * the fatal error in teh first place)
505
+	 *
506
+	 * @throws EE_Error
507
+	 */
508
+	protected function _reattempt_migration()
509
+	{
510
+		$this->migration_manager->reattempt();
511
+		$this->_redirect_after_action(false, '', '', ['action' => 'default'], true);
512
+	}
513
+
514
+
515
+	/**
516
+	 * shows the big ol' System Information page
517
+	 *
518
+	 * @throws EE_Error
519
+	 */
520
+	public function _system_status()
521
+	{
522
+		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
523
+		$this->_template_args['system_stati']               = EEM_System_Status::instance()->get_system_stati();
524
+		$this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
525
+			[
526
+				'action' => 'download_system_status',
527
+			],
528
+			EE_MAINTENANCE_ADMIN_URL
529
+		);
530
+		$this->_template_args['admin_page_content']         = EEH_Template::display_template(
531
+			$this->_template_path,
532
+			$this->_template_args,
533
+			true
534
+		);
535
+		$this->display_admin_page_with_no_sidebar();
536
+	}
537
+
538
+
539
+	/**
540
+	 * Downloads an HTML file of the system status that can be easily stored or emailed
541
+	 */
542
+	public function _download_system_status()
543
+	{
544
+		$status_info = EEM_System_Status::instance()->get_system_stati();
545
+		header('Content-Disposition: attachment');
546
+		header("Content-Disposition: attachment; filename=system_status_" . sanitize_key(site_url()) . ".html");
547
+		$output = '<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>';
548
+		$output .= '<h1>' . sprintf(
549
+			__('System Information for %1$s', 'event_espresso'),
550
+			esc_url_raw(site_url())
551
+		) . '</h1>';
552
+		$output .= EEH_Template::layout_array_as_table($status_info);
553
+		echo esc_html($output);
554
+		die;
555
+	}
556
+
557
+
558
+	/**
559
+	 * @throws EE_Error
560
+	 */
561
+	public function _send_migration_crash_report()
562
+	{
563
+		$from      = $this->_req_data['from'];
564
+		$from_name = $this->_req_data['from_name'];
565
+		$body      = $this->_req_data['body'];
566
+		try {
567
+			$success = wp_mail(
568
+				EE_SUPPORT_EMAIL,
569
+				'Migration Crash Report',
570
+				$body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
571
+				[
572
+					"from:$from_name<$from>",
573
+				]
574
+			);
575
+		} catch (Exception $e) {
576
+			$success = false;
577
+		}
578
+		$this->_redirect_after_action(
579
+			$success,
580
+			esc_html__("Migration Crash Report", "event_espresso"),
581
+			esc_html__("sent", "event_espresso"),
582
+			['success' => $success, 'action' => 'confirm_migration_crash_report_sent']
583
+		);
584
+	}
585
+
586
+
587
+	/**
588
+	 * @throws EE_Error
589
+	 */
590
+	public function _confirm_migration_crash_report_sent()
591
+	{
592
+		try {
593
+			$most_recent_migration = $this->migration_manager->get_last_ran_script(true);
594
+		} catch (EE_Error $e) {
595
+			$this->migration_manager->add_error_to_migrations_ran($e->getMessage());
596
+			// now, just so we can display the page correctly, make an error migration script stage object
597
+			// and also put the error on it. It only persists for the duration of this request
598
+			$most_recent_migration = new EE_DMS_Unknown_1_0_0();
599
+			$most_recent_migration->add_error($e->getMessage());
600
+		}
601
+		$success                                       = $this->_req_data['success'] === '1';
602
+		$this->_template_args['success']               = $success;
603
+		$this->_template_args['most_recent_migration'] = $most_recent_migration;
604
+		$this->_template_args['reset_db_action_url']   = EE_Admin_Page::add_query_args_and_nonce(
605
+			['action' => 'reset_db'],
606
+			EE_MAINTENANCE_ADMIN_URL
607
+		);
608
+		$this->_template_args['reset_db_page_url']     = EE_Admin_Page::add_query_args_and_nonce(
609
+			['action' => 'data_reset'],
610
+			EE_MAINTENANCE_ADMIN_URL
611
+		);
612
+		$this->_template_args['reattempt_action_url']  = EE_Admin_Page::add_query_args_and_nonce(
613
+			['action' => 'reattempt_migration'],
614
+			EE_MAINTENANCE_ADMIN_URL
615
+		);
616
+		$this->_template_path                          =
617
+			EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
618
+		$this->_template_args['admin_page_content']    = EEH_Template::display_template(
619
+			$this->_template_path,
620
+			$this->_template_args,
621
+			true
622
+		);
623
+		$this->display_admin_page_with_sidebar();
624
+	}
625
+
626
+
627
+	/**
628
+	 * Resets the entire EE4 database.
629
+	 * only sets up ee4 database for a fresh install-
630
+	 * doesn't actually clean out the old wp options, or cpts
631
+	 * (although it does erase old ee table data)
632
+	 *
633
+	 * @param boolean $nuke_old_ee4_data controls whether we destroy the old ee4 data,
634
+	 *                                   or just try initializing ee4 default data
635
+	 * @throws EE_Error
636
+	 * @throws ReflectionException
637
+	 */
638
+	public function _reset_db($nuke_old_ee4_data = true)
639
+	{
640
+		$this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
641
+		if ($nuke_old_ee4_data) {
642
+			EEH_Activation::delete_all_espresso_cpt_data();
643
+			EEH_Activation::delete_all_espresso_tables_and_data(false);
644
+			EEH_Activation::remove_cron_tasks();
645
+		}
646
+		// make sure when we reset the registry's config that it
647
+		// switches to using the new singleton
648
+		EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true);
649
+		EE_System::instance()->initialize_db_if_no_migrations_required(true);
650
+		EE_System::instance()->redirect_to_about_ee();
651
+	}
652
+
653
+
654
+	/**
655
+	 * Deletes ALL EE tables, Records, and Options from the database.
656
+	 *
657
+	 * @throws EE_Error
658
+	 * @throws ReflectionException
659
+	 */
660
+	public function _delete_db()
661
+	{
662
+		$this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
663
+		EEH_Activation::delete_all_espresso_cpt_data();
664
+		EEH_Activation::delete_all_espresso_tables_and_data();
665
+		EEH_Activation::remove_cron_tasks();
666
+		EEH_Activation::deactivate_event_espresso();
667
+		wp_safe_redirect(admin_url('plugins.php'));
668
+		exit;
669
+	}
670
+
671
+
672
+	/**
673
+	 * sets up EE4 to rerun the migrations from ee3 to ee4
674
+	 *
675
+	 * @throws EE_Error
676
+	 * @throws ReflectionException
677
+	 */
678
+	public function _rerun_migration_from_ee3()
679
+	{
680
+		$this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
681
+		EEH_Activation::delete_all_espresso_cpt_data();
682
+		EEH_Activation::delete_all_espresso_tables_and_data(false);
683
+		// set the db state to something that will require migrations
684
+		update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0');
685
+		$this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance);
686
+		$this->_redirect_after_action(
687
+			true,
688
+			esc_html__("Database", 'event_espresso'),
689
+			esc_html__("reset", 'event_espresso')
690
+		);
691
+	}
692
+
693
+
694
+	// none of the below group are currently used for Gateway Settings
695
+	protected function _add_screen_options()
696
+	{
697
+	}
698
+
699
+
700
+	protected function _add_feature_pointers()
701
+	{
702
+	}
703
+
704
+
705
+	public function admin_init()
706
+	{
707
+	}
708
+
709
+
710
+	public function admin_notices()
711
+	{
712
+	}
713
+
714
+
715
+	public function admin_footer_scripts()
716
+	{
717
+	}
718
+
719
+
720
+	public function load_scripts_styles()
721
+	{
722
+		wp_enqueue_script('ee_admin_js');
723
+		wp_enqueue_script(
724
+			'ee-maintenance',
725
+			EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.js',
726
+			['jquery'],
727
+			EVENT_ESPRESSO_VERSION,
728
+			true
729
+		);
730
+		wp_register_style(
731
+			'espresso_maintenance',
732
+			EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css',
733
+			[],
734
+			EVENT_ESPRESSO_VERSION
735
+		);
736
+		wp_enqueue_style('espresso_maintenance');
737
+		// localize script stuff
738
+		wp_localize_script(
739
+			'ee-maintenance',
740
+			'ee_maintenance',
741
+			[
742
+				'migrating'                        => wp_strip_all_tags(__("Updating Database...", "event_espresso")),
743
+				'next'                             => wp_strip_all_tags(__("Next", "event_espresso")),
744
+				'fatal_error'                      => wp_strip_all_tags(__(
745
+					"A Fatal Error Has Occurred",
746
+					"event_espresso"
747
+				)),
748
+				'click_next_when_ready'            => wp_strip_all_tags(
749
+					__(
750
+						"The current Database Update has ended. Click 'next' when ready to proceed",
751
+						"event_espresso"
752
+					)
753
+				),
754
+				'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts,
755
+				'status_fatal_error'               => EE_Data_Migration_Manager::status_fatal_error,
756
+				'status_completed'                 => EE_Data_Migration_Manager::status_completed,
757
+				'confirm'                          => wp_strip_all_tags(
758
+					__(
759
+						'Are you sure you want to do this? It CANNOT be undone!',
760
+						'event_espresso'
761
+					)
762
+				),
763
+				'confirm_skip_migration'           => wp_strip_all_tags(
764
+					__(
765
+						'You have chosen to NOT migrate your existing data. Are you sure you want to continue?',
766
+						'event_espresso'
767
+					)
768
+				),
769
+			]
770
+		);
771
+	}
772
+
773
+
774
+	public function load_scripts_styles_default()
775
+	{
776
+	}
777
+
778
+
779
+	/**
780
+	 * Enqueue scripts and styles for the datetime tools page.
781
+	 */
782
+	public function load_scripts_styles_datetime_tools()
783
+	{
784
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
785
+	}
786
+
787
+
788
+	/**
789
+	 * @throws EE_Error
790
+	 */
791
+	protected function _datetime_tools()
792
+	{
793
+		$form_action                                = EE_Admin_Page::add_query_args_and_nonce(
794
+			[
795
+				'action'        => 'run_datetime_offset_fix',
796
+				'return_action' => $this->_req_action,
797
+			],
798
+			EE_MAINTENANCE_ADMIN_URL
799
+		);
800
+		$form                                       = $this->_get_datetime_offset_fix_form();
801
+		$this->_admin_page_title                    = esc_html__('Datetime Utilities', 'event_espresso');
802
+		$this->_template_args['admin_page_content'] = $form->form_open($form_action, 'post')
803
+													  . $form->get_html_and_js()
804
+													  . $form->form_close();
805
+		$this->display_admin_page_with_sidebar();
806
+	}
807
+
808
+
809
+	/**
810
+	 * @throws EE_Error
811
+	 */
812
+	protected function _get_datetime_offset_fix_form()
813
+	{
814
+		if (! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) {
815
+			$this->datetime_fix_offset_form = new EE_Form_Section_Proper(
816
+				[
817
+					'name'            => 'datetime_offset_fix_option',
818
+					'layout_strategy' => new EE_Admin_Two_Column_Layout(),
819
+					'subsections'     => [
820
+						'title'                  => new EE_Form_Section_HTML(
821
+							EEH_HTML::h2(
822
+								esc_html__('Datetime Offset Tool', 'event_espresso')
823
+							)
824
+						),
825
+						'explanation'            => new EE_Form_Section_HTML(
826
+							EEH_HTML::p(
827
+								esc_html__(
828
+									'Use this tool to automatically apply the provided offset to all Event Espresso records in your database that involve dates and times.',
829
+									'event_espresso'
830
+								)
831
+							)
832
+							. EEH_HTML::p(
833
+								esc_html__(
834
+									'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.',
835
+									'event_espresso'
836
+								)
837
+							)
838
+						),
839
+						'offset_input'           => new EE_Float_Input(
840
+							[
841
+								'html_name'       => 'offset_for_datetimes',
842
+								'html_label_text' => esc_html__(
843
+									'Offset to apply (in hours):',
844
+									'event_espresso'
845
+								),
846
+								'min_value'       => '-12',
847
+								'max_value'       => '14',
848
+								'step_value'      => '.25',
849
+								'default'         => DatetimeOffsetFix::getOffset(),
850
+							]
851
+						),
852
+						'date_range_explanation' => new EE_Form_Section_HTML(
853
+							EEH_HTML::p(
854
+								esc_html__(
855
+									'Leave the following fields blank if you want the offset to be applied to all dates. If however, you want to just apply the offset to a specific range of dates you can restrict the offset application using these fields.',
856
+									'event_espresso'
857
+								)
858
+							)
859
+							. EEH_HTML::p(
860
+								EEH_HTML::strong(
861
+									sprintf(
862
+										esc_html__(
863
+											'Note: please enter the dates in UTC (You can use %1$sthis online tool%2$s to assist with conversions).',
864
+											'event_espresso'
865
+										),
866
+										'<a href="https://www.timeanddate.com/worldclock/converter.html">',
867
+										'</a>'
868
+									)
869
+								)
870
+							)
871
+						),
872
+						'date_range_start_date'  => new EE_Datepicker_Input(
873
+							[
874
+								'html_name'       => 'offset_date_start_range',
875
+								'html_label_text' => esc_html__(
876
+									'Start Date for dates the offset applied to:',
877
+									'event_espresso'
878
+								),
879
+							]
880
+						),
881
+						'date_range_end_date'    => new EE_Datepicker_Input(
882
+							[
883
+								'html_name'       => 'offset_date_end_range',
884
+								'html_label_text' => esc_html__(
885
+									'End Date for dates the offset is applied to:',
886
+									'event_espresso'
887
+								),
888
+							]
889
+						),
890
+						'submit'                 => new EE_Submit_Input(
891
+							[
892
+								'html_label_text' => '',
893
+								'default'         => esc_html__('Apply Offset', 'event_espresso'),
894
+							]
895
+						),
896
+					],
897
+				]
898
+			);
899
+		}
900
+		return $this->datetime_fix_offset_form;
901
+	}
902
+
903
+
904
+	/**
905
+	 * Callback for the run_datetime_offset_fix route.
906
+	 *
907
+	 * @throws EE_Error
908
+	 */
909
+	protected function _apply_datetime_offset()
910
+	{
911
+		if ($_SERVER['REQUEST_METHOD'] === 'POST') {
912
+			$form = $this->_get_datetime_offset_fix_form();
913
+			$form->receive_form_submission($this->_req_data);
914
+			if ($form->is_valid()) {
915
+				// save offset data so batch processor can get it.
916
+				DatetimeOffsetFix::updateOffset($form->get_input_value('offset_input'));
917
+				$utc_timezone          = new DateTimeZone('UTC');
918
+				$date_range_start_date = DateTime::createFromFormat(
919
+					'm/d/Y H:i:s',
920
+					$form->get_input_value('date_range_start_date') . ' 00:00:00',
921
+					$utc_timezone
922
+				);
923
+				$date_range_end_date   = DateTime::createFromFormat(
924
+					'm/d/Y H:i:s',
925
+					$form->get_input_value('date_range_end_date') . ' 23:59:59',
926
+					$utc_timezone
927
+				);
928
+				if ($date_range_start_date instanceof DateTime) {
929
+					DatetimeOffsetFix::updateStartDateRange(DbSafeDateTime::createFromDateTime($date_range_start_date));
930
+				}
931
+				if ($date_range_end_date instanceof DateTime) {
932
+					DatetimeOffsetFix::updateEndDateRange(DbSafeDateTime::createFromDateTime($date_range_end_date));
933
+				}
934
+				// redirect to batch tool
935
+				wp_redirect(
936
+					EE_Admin_Page::add_query_args_and_nonce(
937
+						[
938
+							'page'        => EED_Batch::PAGE_SLUG,
939
+							'batch'       => EED_Batch::batch_job,
940
+							'label'       => esc_html__('Applying Offset', 'event_espresso'),
941
+							'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\DatetimeOffsetFix'),
942
+							'return_url'  => urlencode(
943
+								add_query_arg(
944
+									[
945
+										'action' => 'datetime_tools',
946
+									],
947
+									EEH_URL::current_url_without_query_paramaters(
948
+										[
949
+											'return_action',
950
+											'run_datetime_offset_fix_nonce',
951
+											'return',
952
+											'datetime_tools_nonce',
953
+										]
954
+									)
955
+								)
956
+							),
957
+						],
958
+						admin_url()
959
+					)
960
+				);
961
+				exit;
962
+			}
963
+		}
964
+	}
965 965
 }
Please login to merge, or discard this patch.
modules/batch/templates/batch_runner.template.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@
 block discarded – undo
4 4
 
5 5
 <div class="ee-batch-runner__wrapper ee-admin-container">
6 6
     <div class="padding">
7
-        <h1><?php esc_html_e('Running Batch Job...', 'event_espresso');?></h1>
7
+        <h1><?php esc_html_e('Running Batch Job...', 'event_espresso'); ?></h1>
8 8
         <div class="progress-bar-wrapper">
9 9
             <div id='batch-progress' class='progress-responsive'></div>
10 10
             <label><?php esc_html_e('progress', 'event_espresso'); ?></label>
Please login to merge, or discard this patch.
modules/batch/templates/batch_wrapper.template.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@
 block discarded – undo
3 3
 // just makes the template conditional on the batch request type
4 4
 $batch_request_type = EED_Batch::instance()->batch_request_type();
5 5
 if ($batch_request_type == EED_Batch::batch_job) {
6
-    require('batch_runner.template.php');
6
+	require('batch_runner.template.php');
7 7
 } elseif ($batch_request_type == EED_Batch::batch_file_job) {
8
-    require('batch_file_runner.template.php');
8
+	require('batch_file_runner.template.php');
9 9
 }
Please login to merge, or discard this patch.