|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Maketok\DataMigration\Workflow; |
|
4
|
|
|
|
|
5
|
|
|
class Result implements ResultInterface |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @var array |
|
9
|
|
|
*/ |
|
10
|
|
|
protected $participants; |
|
11
|
|
|
/** |
|
12
|
|
|
* @var \DateTime |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $startTime; |
|
15
|
|
|
/** |
|
16
|
|
|
* @var \DateTime |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $endTime; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* {@inheritdoc} |
|
22
|
|
|
*/ |
|
23
|
3 |
|
public function getTotalRowsProcessed() |
|
24
|
|
|
{ |
|
25
|
3 |
|
$rows = 0; |
|
26
|
3 |
|
foreach ($this->participants as $key => $data) { |
|
27
|
3 |
|
$rows += $this->getActionProcessed($key); |
|
28
|
3 |
|
} |
|
29
|
3 |
|
return $rows; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
3 |
|
public function getAllErrors() |
|
36
|
|
|
{ |
|
37
|
3 |
|
$errors = []; |
|
38
|
3 |
|
foreach ($this->participants as $key => $data) { |
|
39
|
3 |
|
$errors = array_merge($errors, $this->getActionErrors($key)); |
|
40
|
3 |
|
} |
|
41
|
3 |
|
return $errors; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* {@inheritdoc} |
|
46
|
|
|
*/ |
|
47
|
1 |
|
public function getAllExceptions() |
|
48
|
|
|
{ |
|
49
|
1 |
|
$exceptions = []; |
|
50
|
1 |
|
foreach ($this->participants as $key => $data) { |
|
51
|
1 |
|
$exceptions = array_merge($exceptions, $this->getActionExceptions($key)); |
|
52
|
1 |
|
} |
|
53
|
1 |
|
return $exceptions; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* {@inheritdoc} |
|
58
|
|
|
*/ |
|
59
|
1 |
|
public function getParticipants() |
|
60
|
|
|
{ |
|
61
|
1 |
|
return $this->participants; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* {@inheritdoc} |
|
66
|
|
|
*/ |
|
67
|
4 |
|
public function getActionProcessed($code) |
|
68
|
|
|
{ |
|
69
|
4 |
|
return isset($this->participants[$code]['rows_processed']) ? |
|
70
|
4 |
|
$this->participants[$code]['rows_processed'] : 0; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* {@inheritdoc} |
|
75
|
|
|
*/ |
|
76
|
4 |
|
public function getActionErrors($code) |
|
77
|
|
|
{ |
|
78
|
4 |
|
return isset($this->participants[$code]['errors']) ? |
|
79
|
4 |
|
$this->participants[$code]['errors'] : []; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* {@inheritdoc} |
|
84
|
|
|
*/ |
|
85
|
2 |
|
public function getActionExceptions($code) |
|
86
|
|
|
{ |
|
87
|
2 |
|
return isset($this->participants[$code]['exceptions']) ? |
|
88
|
2 |
|
$this->participants[$code]['exceptions'] : []; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* {@inheritdoc} |
|
93
|
|
|
*/ |
|
94
|
4 |
|
public function addActionError($code, $message) |
|
95
|
|
|
{ |
|
96
|
4 |
|
if (isset($this->participants[$code]['errors'])) { |
|
97
|
1 |
|
$this->participants[$code]['errors'][] = $message; |
|
98
|
4 |
|
} elseif (isset($this->participants[$code])) { |
|
99
|
3 |
|
$this->participants[$code]['errors'] = [$message]; |
|
100
|
3 |
|
} else { |
|
101
|
2 |
|
$this->participants[$code] = ['errors' => [$message]]; |
|
102
|
|
|
} |
|
103
|
4 |
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* {@inheritdoc} |
|
107
|
|
|
*/ |
|
108
|
2 |
|
public function addActionException($code, \Exception $ex) |
|
|
|
|
|
|
109
|
|
|
{ |
|
110
|
2 |
|
if (isset($this->participants[$code]['exceptions'])) { |
|
111
|
1 |
|
$this->participants[$code]['exceptions'][] = $ex; |
|
112
|
2 |
|
} elseif (isset($this->participants[$code])) { |
|
113
|
1 |
|
$this->participants[$code]['exceptions'] = [$ex]; |
|
114
|
1 |
|
} else { |
|
115
|
1 |
|
$this->participants[$code] = ['exceptions' => [$ex]]; |
|
116
|
|
|
} |
|
117
|
2 |
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* {@inheritdoc} |
|
121
|
|
|
*/ |
|
122
|
12 |
|
public function incrementActionProcessed($code, $value = 1) |
|
123
|
|
|
{ |
|
124
|
12 |
|
if (isset($this->participants[$code]['rows_processed'])) { |
|
125
|
9 |
|
$this->participants[$code]['rows_processed'] += $value; |
|
126
|
12 |
|
} elseif (isset($this->participants[$code])) { |
|
127
|
10 |
|
$this->participants[$code]['rows_processed'] = $value; |
|
128
|
10 |
|
} else { |
|
129
|
3 |
|
$this->participants[$code] = ['rows_processed' => $value]; |
|
130
|
|
|
} |
|
131
|
12 |
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* {@inheritdoc} |
|
135
|
|
|
*/ |
|
136
|
1 |
|
public function getStartTime() |
|
137
|
|
|
{ |
|
138
|
1 |
|
return $this->startTime; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* {@inheritdoc} |
|
143
|
|
|
*/ |
|
144
|
1 |
|
public function getEndTime() |
|
145
|
|
|
{ |
|
146
|
1 |
|
return $this->endTime; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* {@inheritdoc} |
|
151
|
|
|
*/ |
|
152
|
1 |
|
public function getActionStartTime($code) |
|
153
|
|
|
{ |
|
154
|
1 |
|
return isset($this->participants[$code]['start_time']) ? |
|
155
|
1 |
|
$this->participants[$code]['start_time'] : null; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* {@inheritdoc} |
|
160
|
|
|
*/ |
|
161
|
1 |
|
public function getActionEndTime($code) |
|
162
|
|
|
{ |
|
163
|
1 |
|
return isset($this->participants[$code]['end_time']) ? |
|
164
|
1 |
|
$this->participants[$code]['end_time'] : null; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* {@inheritdoc} |
|
169
|
|
|
*/ |
|
170
|
10 |
|
public function setStartTime(\DateTime $time) |
|
171
|
|
|
{ |
|
172
|
10 |
|
$this->startTime = $time; |
|
173
|
10 |
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* {@inheritdoc} |
|
177
|
|
|
*/ |
|
178
|
10 |
|
public function setEndTime(\DateTime $time) |
|
179
|
|
|
{ |
|
180
|
10 |
|
$this->endTime = $time; |
|
181
|
10 |
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* {@inheritdoc} |
|
185
|
|
|
*/ |
|
186
|
13 |
|
public function setActionStartTime($code, \DateTime $time) |
|
187
|
|
|
{ |
|
188
|
13 |
|
if (isset($this->participants[$code])) { |
|
189
|
2 |
|
$this->participants[$code]['start_time'] = $time; |
|
190
|
2 |
|
} else { |
|
191
|
13 |
|
$this->participants[$code] = ['start_time' => $time]; |
|
192
|
|
|
} |
|
193
|
13 |
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* {@inheritdoc} |
|
197
|
|
|
*/ |
|
198
|
13 |
|
public function setActionEndTime($code, \DateTime $time) |
|
199
|
|
|
{ |
|
200
|
13 |
|
if (isset($this->participants[$code])) { |
|
201
|
12 |
|
$this->participants[$code]['end_time'] = $time; |
|
202
|
12 |
|
} else { |
|
203
|
1 |
|
$this->participants[$code] = ['end_time' => $time]; |
|
204
|
|
|
} |
|
205
|
13 |
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* {@inheritdoc} |
|
209
|
|
|
*/ |
|
210
|
1 |
|
public function getTotalRowsThrough() |
|
211
|
|
|
{ |
|
212
|
1 |
|
$rows = []; |
|
213
|
1 |
|
foreach ($this->participants as $key => $data) { |
|
214
|
1 |
|
$rows[] = $this->getActionProcessed($key); |
|
215
|
1 |
|
} |
|
216
|
1 |
|
return min($rows); |
|
217
|
|
|
} |
|
218
|
|
|
} |
|
219
|
|
|
|
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.