1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace HDNET\Importr\Domain\Model; |
6
|
|
|
|
7
|
|
|
use HDNET\Importr\Service\Targets\TargetInterface; |
8
|
|
|
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Description of Strategy |
12
|
|
|
* |
13
|
|
|
* @author timlochmueller |
14
|
|
|
*/ |
15
|
|
|
class Import extends AbstractEntity |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var \HDNET\Importr\Domain\Model\Strategy |
20
|
|
|
*/ |
21
|
|
|
protected $strategy; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $filepath; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var \DateTime |
30
|
|
|
*/ |
31
|
|
|
protected $starttime; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var \DateTime |
35
|
|
|
*/ |
36
|
|
|
protected $endtime; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var int |
40
|
|
|
*/ |
41
|
|
|
protected $pointer; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var int |
45
|
|
|
*/ |
46
|
|
|
protected $amount; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var int |
50
|
|
|
*/ |
51
|
|
|
protected $inserted; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var int |
55
|
|
|
*/ |
56
|
|
|
protected $updated; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var int |
60
|
|
|
*/ |
61
|
|
|
protected $ignored; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var int |
65
|
|
|
*/ |
66
|
|
|
protected $unknowns; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @var int |
70
|
|
|
*/ |
71
|
|
|
protected $errors; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return \HDNET\Importr\Domain\Model\Strategy |
75
|
|
|
*/ |
76
|
|
|
public function getStrategy() |
77
|
|
|
{ |
78
|
|
|
return $this->strategy; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return string |
83
|
|
|
*/ |
84
|
|
|
public function getFilepath() |
85
|
|
|
{ |
86
|
|
|
return $this->filepath; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return \DateTime |
91
|
|
|
*/ |
92
|
|
|
public function getStarttime() |
93
|
|
|
{ |
94
|
|
|
return $this->starttime; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return \DateTime |
99
|
|
|
*/ |
100
|
|
|
public function getEndtime() |
101
|
|
|
{ |
102
|
|
|
return $this->endtime; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return int |
107
|
|
|
*/ |
108
|
|
|
public function getPointer() |
109
|
|
|
{ |
110
|
|
|
return $this->pointer; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return int |
115
|
|
|
*/ |
116
|
|
|
public function getAmount() |
117
|
|
|
{ |
118
|
|
|
return $this->amount; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param \HDNET\Importr\Domain\Model\Strategy $strategy |
123
|
|
|
*/ |
124
|
|
|
public function setStrategy(Strategy $strategy) |
125
|
|
|
{ |
126
|
|
|
$this->strategy = $strategy; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param string $filepath |
131
|
|
|
*/ |
132
|
|
|
public function setFilepath($filepath) |
133
|
|
|
{ |
134
|
|
|
$this->filepath = $filepath; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param \DateTime $starttime |
139
|
|
|
*/ |
140
|
|
|
public function setStarttime($starttime) |
141
|
|
|
{ |
142
|
|
|
$this->starttime = $starttime; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @param \DateTime $endtime |
147
|
|
|
*/ |
148
|
|
|
public function setEndtime($endtime) |
149
|
|
|
{ |
150
|
|
|
$this->endtime = $endtime; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param int $pointer |
155
|
|
|
*/ |
156
|
|
|
public function setPointer($pointer) |
157
|
|
|
{ |
158
|
|
|
$this->pointer = $pointer; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @param int $amount |
163
|
|
|
*/ |
164
|
|
|
public function setAmount($amount) |
165
|
|
|
{ |
166
|
|
|
$this->amount = $amount; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @return float|int |
171
|
|
|
*/ |
172
|
|
|
public function getPercentage() |
173
|
|
|
{ |
174
|
|
|
if ($this->getAmount() == 0) { |
175
|
|
|
return 100; |
176
|
|
|
} |
177
|
|
|
return $this->getPointer() / $this->getAmount() * 100; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @param int $errors |
182
|
|
|
*/ |
183
|
1 |
|
public function setErrors($errors) |
184
|
|
|
{ |
185
|
1 |
|
$this->errors = $errors; |
186
|
1 |
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @return int |
190
|
|
|
*/ |
191
|
1 |
|
public function getErrors() |
192
|
|
|
{ |
193
|
1 |
|
return (int)$this->errors; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @return float|int |
198
|
|
|
*/ |
199
|
|
|
public function getErrorsPercentage() |
200
|
|
|
{ |
201
|
|
|
if ($this->getAmount() == 0) { |
202
|
|
|
return 0; |
203
|
|
|
} |
204
|
|
|
return $this->getErrors() / $this->getAmount() * 100; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @param int $ignored |
209
|
|
|
*/ |
210
|
1 |
|
public function setIgnored($ignored) |
211
|
|
|
{ |
212
|
1 |
|
$this->ignored = $ignored; |
213
|
1 |
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @return int |
217
|
|
|
*/ |
218
|
1 |
|
public function getIgnored() |
219
|
|
|
{ |
220
|
1 |
|
return (int)$this->ignored; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @return float|int |
225
|
|
|
*/ |
226
|
|
|
public function getIgnoredPercentage() |
227
|
|
|
{ |
228
|
|
|
if ($this->getAmount() == 0) { |
229
|
|
|
return 0; |
230
|
|
|
} |
231
|
|
|
return $this->getIgnored() / $this->getAmount() * 100; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* @param int $inserted |
236
|
|
|
*/ |
237
|
1 |
|
public function setInserted($inserted) |
238
|
|
|
{ |
239
|
1 |
|
$this->inserted = $inserted; |
240
|
1 |
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @return int |
244
|
|
|
*/ |
245
|
1 |
|
public function getInserted() |
246
|
|
|
{ |
247
|
1 |
|
return (int)$this->inserted; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @param int $unknowns |
252
|
|
|
*/ |
253
|
1 |
|
public function setUnknowns($unknowns) |
254
|
|
|
{ |
255
|
1 |
|
$this->unknowns = $unknowns; |
256
|
1 |
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @return int |
260
|
|
|
*/ |
261
|
1 |
|
public function getUnknowns() |
262
|
|
|
{ |
263
|
1 |
|
return (int)$this->unknowns; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @return float|int |
268
|
|
|
*/ |
269
|
|
|
public function getUnknownsPercentage() |
270
|
|
|
{ |
271
|
|
|
if ($this->getAmount() == 0) { |
272
|
|
|
return 0; |
273
|
|
|
} |
274
|
|
|
return $this->getUnknowns() / $this->getAmount() * 100; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* @return float|int |
279
|
|
|
*/ |
280
|
|
|
public function getInsertedPercentage() |
281
|
|
|
{ |
282
|
|
|
if ($this->getAmount() == 0) { |
283
|
|
|
return 0; |
284
|
|
|
} |
285
|
|
|
return $this->getInserted() / $this->getAmount() * 100; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* @param int $updated |
290
|
|
|
*/ |
291
|
1 |
|
public function setUpdated($updated) |
292
|
|
|
{ |
293
|
1 |
|
$this->updated = $updated; |
294
|
1 |
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* @return int |
298
|
|
|
*/ |
299
|
1 |
|
public function getUpdated() |
300
|
|
|
{ |
301
|
1 |
|
return (int)$this->updated; |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* @return float|int |
306
|
|
|
*/ |
307
|
|
|
public function getUpdatedPercentage() |
308
|
|
|
{ |
309
|
|
|
if ($this->getAmount() == 0) { |
310
|
|
|
return 0; |
311
|
|
|
} |
312
|
|
|
return $this->getUpdated() / $this->getAmount() * 100; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* @param int $type |
317
|
|
|
*/ |
318
|
1 |
|
public function increaseCount($type) |
319
|
|
|
{ |
320
|
|
|
switch ($type) { |
321
|
1 |
|
case TargetInterface::RESULT_INSERT: |
322
|
1 |
|
$this->setInserted($this->getInserted() + 1); |
323
|
1 |
|
break; |
324
|
1 |
|
case TargetInterface::RESULT_UPDATE: |
325
|
1 |
|
$this->setUpdated($this->getUpdated() + 1); |
326
|
1 |
|
break; |
327
|
1 |
|
case TargetInterface::RESULT_IGNORED: |
328
|
1 |
|
$this->setIgnored($this->getIgnored() + 1); |
329
|
1 |
|
break; |
330
|
1 |
|
case TargetInterface::RESULT_UNSURE: |
331
|
1 |
|
$this->setUnknowns($this->getUnknowns() + 1); |
332
|
1 |
|
break; |
333
|
1 |
|
case TargetInterface::RESULT_ERROR: |
334
|
1 |
|
$this->setErrors($this->getErrors() + 1); |
335
|
1 |
|
break; |
336
|
|
|
} |
337
|
1 |
|
} |
338
|
|
|
|
339
|
|
|
public function reset() |
340
|
|
|
{ |
341
|
|
|
$this->endtime = 0; |
|
|
|
|
342
|
|
|
$this->amount = 0; |
343
|
|
|
$this->errors = 0; |
344
|
|
|
$this->ignored = 0; |
345
|
|
|
$this->inserted = 0; |
346
|
|
|
$this->updated = 0; |
347
|
|
|
$this->unknowns = 0; |
348
|
|
|
$this->pointer = 0; |
349
|
|
|
} |
350
|
|
|
} |
351
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..