PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 3.3.3
WP STAGING – WordPress Backups, Restore, Migration & Clone v3.3.3
4.11.2 4.11.1 4.11.0 4.10.0 4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Backup / Dto / JobDataDto.php
wp-staging / Backup / Dto Last commit date
Interfaces 2 years ago Job 2 years ago Service 2 years ago Task 2 years ago Traits 2 years ago AbstractDto.php 3 years ago AbstractTaskDto.php 2 years ago JobDataDto.php 2 years ago StepsDto.php 2 years ago TaskResponseDto.php 2 years ago
JobDataDto.php
544 lines
1 <?php
2
3 namespace WPStaging\Backup\Dto;
4
5 use WPStaging\Framework\Queue\FinishedQueueException;
6
7 use function WPStaging\functions\debug_log;
8
9 class JobDataDto extends AbstractDto
10 {
11 /** @var string|int|null */
12 protected $id;
13
14 /** @var bool */
15 protected $init;
16
17 /** @var bool */
18 protected $finished;
19
20 /** @var bool */
21 protected $statusCheck;
22
23 /** @var string */
24 protected $lastQueryInfoJSON;
25
26 /** @var bool */
27 protected $isSlowMySqlServer = false;
28
29 /** @var double */
30 protected $dbRequestTime = 0;
31
32 /** @var int */
33 protected $batchSize = 0;
34
35 /** @var int */
36 private $tableAverageRowLength = 0;
37
38 /** @var string The name of the task we are checking the health */
39 protected $taskHealthName = '';
40
41 /** @var int How many times this task failed in sequence */
42 protected $taskHealthSequentialFailedRetries = 0;
43
44 /** @var bool Whether the task has responded */
45 protected $taskHealthResponded = false;
46
47 /** @var bool Whether the task is currently retrying a request that failed */
48 protected $taskHealthIsRetrying = false;
49
50 /** @var int Where to set the Task queue offset */
51 protected $queueOffset = 0;
52
53 /** @var int Calculating the queue count is expensive, so we store it here as a metadata */
54 protected $queueCount = 0;
55
56 /** @var bool Whether this backup contains only a database */
57 protected $databaseOnlyBackup = false;
58
59 /** @var string The reason why a requirement fail, if it failed. */
60 protected $requirementFailReason = '';
61
62 /** @var int Unix timestamp of when this job started. */
63 protected $startTime;
64
65 /** @var int Unix timestamp of when this job finished, if it finished at all. */
66 protected $endTime;
67
68 /** @var int How long this job took to run, in seconds. */
69 protected $duration;
70
71 /** @var bool Whether this job cleaned. */
72 protected $cleaned;
73
74 /** @var array list of tasks to be performed in this job */
75 protected $taskQueue;
76
77 /** @var int pointer|index to the current task in the queue */
78 protected $currentTaskIndex;
79
80 /** @var int how often a request is retried */
81 protected $retries;
82
83 /** @var int How many chunks of compressed data this backup has. */
84 protected $totalChunks = 0;
85
86 /** @var array Data for the current task. */
87 protected $currentTaskData = [];
88
89 /** @var bool */
90 protected $isWpCliRequest = false;
91
92 /**
93 * @return string|int|null
94 */
95 public function getId()
96 {
97 if (empty($this->id)) {
98 throw new \UnexpectedValueException('ID is not set');
99 }
100
101 return $this->id;
102 }
103
104 /**
105 * @param string|int|null $id
106 */
107 public function setId($id)
108 {
109 $this->id = $id;
110 }
111
112 /**
113 * @return bool
114 */
115 public function isInit()
116 {
117 return $this->init;
118 }
119
120 /**
121 * @param bool $init
122 */
123 public function setInit($init)
124 {
125 $this->init = $init;
126 }
127
128 /**
129 * @return bool
130 */
131 public function isFinished()
132 {
133 return $this->finished;
134 }
135
136 /**
137 * @param bool $finished
138 */
139 public function setFinished($finished)
140 {
141 $this->finished = $finished;
142 }
143
144 /**
145 * @return bool
146 */
147 public function isStatusCheck()
148 {
149 return $this->statusCheck;
150 }
151
152 /**
153 * @param bool $statusCheck
154 */
155 public function setStatusCheck($statusCheck)
156 {
157 $this->statusCheck = $statusCheck;
158 }
159
160 /**
161 * @return bool
162 */
163 public function getIsSlowMySqlServer()
164 {
165 return $this->isSlowMySqlServer;
166 }
167
168 /**
169 * @param bool
170 * @return void
171 */
172 public function setIsSlowMySqlServer($isSlowMySqlServer)
173 {
174 $this->isSlowMySqlServer = $isSlowMySqlServer;
175 }
176
177 /**
178 * @return float|int
179 */
180 public function getDbRequestTime()
181 {
182 return $this->dbRequestTime;
183 }
184
185 /**
186 * @param float|int $dbRequestTime
187 */
188 public function setDbRequestTime($dbRequestTime)
189 {
190 $this->dbRequestTime = $dbRequestTime;
191 }
192
193 /**
194 * @return int
195 */
196 public function getBatchSize()
197 {
198 return $this->batchSize;
199 }
200
201 /**
202 * @param int $batchSize
203 */
204 public function setBatchSize($batchSize)
205 {
206 $this->batchSize = $batchSize;
207 }
208
209 /**
210 * @return string
211 */
212 public function getLastQueryInfoJSON()
213 {
214 return $this->lastQueryInfoJSON;
215 }
216
217 /**
218 * @param string $lastQueryInfoJSON
219 */
220 public function setLastQueryInfoJSON($lastQueryInfoJSON)
221 {
222 if (is_array($lastQueryInfoJSON)) {
223 $lastQueryInfoJSON = json_encode($lastQueryInfoJSON);
224 debug_log('Trying to hydrate lastqueryinfoJSON with an array. String expected.');
225 }
226
227 $this->lastQueryInfoJSON = $lastQueryInfoJSON;
228 }
229
230 /**
231 * @return int
232 */
233 public function getTableAverageRowLength()
234 {
235 return $this->tableAverageRowLength;
236 }
237
238 /**
239 * @param int $tableAverageRowLength
240 */
241 public function setTableAverageRowLength($tableAverageRowLength)
242 {
243 $this->tableAverageRowLength = $tableAverageRowLength;
244 }
245
246 /**
247 * @return string
248 */
249 public function getTaskHealthName()
250 {
251 return $this->taskHealthName;
252 }
253
254 /**
255 * @param string $taskHealthName
256 */
257 public function setTaskHealthName($taskHealthName)
258 {
259 $this->taskHealthName = $taskHealthName;
260 }
261
262 /**
263 * @return int
264 */
265 public function getTaskHealthSequentialFailedRetries()
266 {
267 return $this->taskHealthSequentialFailedRetries;
268 }
269
270 /**
271 * @param int $taskHealthSequentialFailedRetries
272 */
273 public function setTaskHealthSequentialFailedRetries($taskHealthSequentialFailedRetries)
274 {
275 $this->taskHealthSequentialFailedRetries = $taskHealthSequentialFailedRetries;
276 }
277
278 /**
279 * @return bool
280 */
281 public function getTaskHealthResponded()
282 {
283 return $this->taskHealthResponded;
284 }
285
286 /**
287 * @param bool $taskHealthResponded
288 */
289 public function setTaskHealthResponded($taskHealthResponded)
290 {
291 $this->taskHealthResponded = $taskHealthResponded;
292 }
293
294 /**
295 * @return bool
296 */
297 public function getTaskHealthIsRetrying()
298 {
299 return $this->taskHealthIsRetrying;
300 }
301
302 /**
303 * @param bool $taskHealthIsRetrying
304 */
305 public function setTaskHealthIsRetrying($taskHealthIsRetrying)
306 {
307 $this->taskHealthIsRetrying = $taskHealthIsRetrying;
308 }
309
310 /**
311 * @return int
312 */
313 public function getQueueOffset()
314 {
315 return (int)$this->queueOffset;
316 }
317
318 /**
319 * @param bool $queueOffset
320 */
321 public function setQueueOffset($queueOffset)
322 {
323 $this->queueOffset = (int)$queueOffset;
324 }
325
326 /**
327 * @return int
328 */
329 public function getQueueCount()
330 {
331 return (int)$this->queueCount;
332 }
333
334 /**
335 * @param int $queueCount
336 */
337 public function setQueueCount($queueCount)
338 {
339 $this->queueCount = (int)$queueCount;
340 }
341
342 /**
343 * @return bool
344 */
345 public function getDatabaseOnlyBackup()
346 {
347 return (bool)$this->databaseOnlyBackup;
348 }
349
350 /**
351 * @param bool $databaseOnlyBackup
352 */
353 public function setDatabaseOnlyBackup($databaseOnlyBackup)
354 {
355 $this->databaseOnlyBackup = (bool)$databaseOnlyBackup;
356 }
357
358 /**
359 * @return string
360 */
361 public function getRequirementFailReason()
362 {
363 return $this->requirementFailReason;
364 }
365
366 /**
367 * @param string $requirementFailReason
368 */
369 public function setRequirementFailReason($requirementFailReason)
370 {
371 $this->requirementFailReason = $requirementFailReason;
372 }
373
374 /**
375 * @return int
376 */
377 public function getStartTime()
378 {
379 return $this->startTime;
380 }
381
382 /**
383 * @param int $startTime
384 */
385 public function setStartTime($startTime)
386 {
387 $this->startTime = $startTime;
388 }
389
390 /**
391 * @return int
392 */
393 public function getEndTime()
394 {
395 return $this->endTime;
396 }
397
398 /**
399 * @param int $endTime
400 */
401 public function setEndTime($endTime)
402 {
403 $this->endTime = $endTime;
404 }
405
406 /**
407 * This method expects the job to have finished successfully, otherwise it will return zero.
408 *
409 * @return int
410 */
411 public function getDuration()
412 {
413 if (is_int($this->startTime) && is_int($this->endTime)) {
414 return $this->endTime - $this->startTime;
415 }
416
417 return 0;
418 }
419
420 /**
421 * @param int $duration
422 */
423 public function setDuration($duration)
424 {
425 $this->duration = $duration;
426 }
427
428 /**
429 * @return bool
430 */
431 public function isCleaned()
432 {
433 return $this->cleaned;
434 }
435
436 /**
437 * @param bool $cleaned
438 */
439 public function setCleaned($cleaned = true)
440 {
441 $this->cleaned = $cleaned;
442 }
443
444 /** @param int $index */
445 public function setCurrentTaskIndex($index)
446 {
447 $this->currentTaskIndex = $index;
448 }
449
450 /** @return int */
451 public function getCurrentTaskIndex()
452 {
453 return $this->currentTaskIndex;
454 }
455
456 /** @param array $queue */
457 public function setTaskQueue($queue)
458 {
459 $this->taskQueue = $queue;
460 }
461
462 /** @return array */
463 public function getTaskQueue()
464 {
465 return $this->taskQueue;
466 }
467
468 /** @return string */
469 public function getCurrentTask()
470 {
471 if (empty($this->taskQueue[$this->currentTaskIndex])) {
472 $debugTaskQueue = print_r($this->taskQueue, true);
473 debug_log("getCurrenTask queue is empty $debugTaskQueue Current task index: $this->currentTaskIndex");
474 return '';
475 }
476
477 return $this->taskQueue[$this->currentTaskIndex];
478 }
479
480 /** @throws FinishedQueueException */
481 public function moveToNextTask()
482 {
483 if (count($this->taskQueue) === $this->currentTaskIndex + 1) {
484 throw new FinishedQueueException();
485 }
486
487 $this->currentTaskIndex++;
488 }
489
490 /** @return int */
491 public function getRetries()
492 {
493 return $this->retries;
494 }
495
496 /** @param int $retries */
497 public function setRetries($retries)
498 {
499 $this->retries = $retries;
500 }
501
502 /**
503 * @return array
504 */
505 public function getCurrentTaskData(): array
506 {
507 return $this->currentTaskData;
508 }
509
510 /**
511 * @param array $currentTaskData
512 */
513 public function setCurrentTaskData(array $currentTaskData)
514 {
515 $this->currentTaskData = $currentTaskData;
516 }
517
518 public function getTotalChunks(): int
519 {
520 return $this->totalChunks;
521 }
522
523 public function setTotalChunks(int $totalChunks)
524 {
525 $this->totalChunks = $totalChunks;
526 }
527
528 /**
529 * @return bool
530 */
531 public function getIsWpCliRequest(): bool
532 {
533 return $this->isWpCliRequest;
534 }
535
536 /**
537 * @param bool $isWpCliRequest
538 */
539 public function setIsWpCliRequest(bool $isWpCliRequest)
540 {
541 $this->isWpCliRequest = $isWpCliRequest;
542 }
543 }
544