1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* Class JobStepResponse |
5
|
|
|
* |
6
|
|
|
* Response object describing the current state of a job |
7
|
|
|
* |
8
|
|
|
* @package Event Espresso |
9
|
|
|
* @subpackage batch |
10
|
|
|
* @author Mike Nelson |
11
|
|
|
* @since 4.8.26 |
12
|
|
|
* |
13
|
|
|
*/ |
14
|
|
|
namespace EventEspressoBatchRequest\Helpers; |
15
|
|
|
|
16
|
|
|
if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
17
|
|
|
|
18
|
|
|
class JobStepResponse { |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Description fo what happened during this step |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $_update_text; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* |
28
|
|
|
* @var JobParameters |
29
|
|
|
*/ |
30
|
|
|
protected $_job_parameters; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Extra data to include as part of the response. |
34
|
|
|
* @var array |
35
|
|
|
*/ |
36
|
|
|
protected $_extra_data = array(); |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* |
42
|
|
|
* @param \EventEspressoBatchRequest\Helpers\JobParameters $job_parameters |
43
|
|
|
* @param string $update_text |
44
|
|
|
* @param array $extra_data |
45
|
|
|
*/ |
46
|
|
|
public function __construct(JobParameters $job_parameters, $update_text, $extra_data = array() ) { |
47
|
|
|
$this->_job_parameters = $job_parameters; |
48
|
|
|
$this->_update_text = $update_text; |
49
|
|
|
$this->_extra_data = (array)$extra_data; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* |
56
|
|
|
* @return JobParameters |
57
|
|
|
*/ |
58
|
|
|
public function job_parameters() { |
59
|
|
|
return $this->_job_parameters; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Gets the update_text of what happened in this job during the current step |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
|
|
public function update_text() { |
69
|
|
|
return $this->_update_text; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Returns any extra data we may want to include with this response |
76
|
|
|
* @return array |
77
|
|
|
*/ |
78
|
|
|
public function extra_data() { |
79
|
|
|
return $this->_extra_data; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Converts this response into an array that can be easily serialized. |
86
|
|
|
* This is most useful for serializing or json encoding |
87
|
|
|
* @return array { |
88
|
|
|
* @type string $status, one of JobParameters::valid_stati() |
89
|
|
|
* @type int $units_processed count of units processed |
90
|
|
|
* @type int $job_size total number of units TO process |
91
|
|
|
* @type string $job_id unique string identifying the job |
92
|
|
|
* @type string $update_text string describing what happened during this step |
93
|
|
|
* } and any other items from $this->extra_data() |
94
|
|
|
*/ |
95
|
|
|
public function to_array() { |
96
|
|
|
return apply_filters( |
97
|
|
|
'FHEE__EventEspressoBatchRequest\Helpers\JobStepResponse__to_array__return', |
98
|
|
|
array_merge( |
99
|
|
|
$this->extra_data(), |
100
|
|
|
array( |
101
|
|
|
'status' => $this->job_parameters()->status(), |
102
|
|
|
'units_processed' => $this->job_parameters()->units_processed(), |
103
|
|
|
'job_size' => $this->job_parameters()->job_size(), |
104
|
|
|
'job_id' => $this->job_parameters()->job_id(), |
105
|
|
|
'update_text' => $this->update_text(), |
106
|
|
|
) |
107
|
|
|
), |
108
|
|
|
$this |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|