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