JobBackupDataDto.php
1192 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Backup\Dto\Job; |
| 4 | |
| 5 | use WPStaging\Backup\Dto\Interfaces\RemoteUploadDtoInterface; |
| 6 | use WPStaging\Backup\Dto\Traits\IsExportingTrait; |
| 7 | use WPStaging\Backup\Dto\Traits\IsExcludingTrait; |
| 8 | use WPStaging\Backup\Dto\Traits\RemoteUploadTrait; |
| 9 | use WPStaging\Backup\Entity\BackupMetadata; |
| 10 | use WPStaging\Framework\Facades\Hooks; |
| 11 | use WPStaging\Framework\Job\Dto\JobDataDto; |
| 12 | |
| 13 | class JobBackupDataDto extends JobDataDto implements RemoteUploadDtoInterface |
| 14 | { |
| 15 | use IsExportingTrait; |
| 16 | use IsExcludingTrait; |
| 17 | use RemoteUploadTrait; |
| 18 | |
| 19 | /** @var string|null */ |
| 20 | private $name; |
| 21 | |
| 22 | /** @var array */ |
| 23 | private $excludedDirectories = []; |
| 24 | |
| 25 | /** @var int */ |
| 26 | private $totalDirectories; |
| 27 | |
| 28 | /** @var int The number of files in the backup index */ |
| 29 | private $totalFiles; |
| 30 | |
| 31 | /** @var array The number of files in backup parts */ |
| 32 | private $filesInParts = []; |
| 33 | |
| 34 | /** @var int The number of files the FilesystemScanner discovered */ |
| 35 | private $discoveredFiles = 0; |
| 36 | |
| 37 | /** @var array The number of files the FilesystemScanner discovered in themes,plugins,muplugins,uploads,others */ |
| 38 | private $discoveredFilesArray = []; |
| 39 | |
| 40 | /** @var int The number of discovered files couldn't be added to backup */ |
| 41 | private $invalidFiles = 0; |
| 42 | |
| 43 | /** @var string */ |
| 44 | private $databaseFile; |
| 45 | |
| 46 | /** |
| 47 | * @var int If a file couldn't be processed in a single request, |
| 48 | * this property holds how many bytes were written thus far |
| 49 | * so that the backup can start writing from this byte onwards. |
| 50 | */ |
| 51 | private $fileBeingBackupWrittenBytes; |
| 52 | |
| 53 | /** |
| 54 | * @var int If header of a file was written but it couldn't be processed in single requests, |
| 55 | */ |
| 56 | private $currentWrittenFileHeaderBytes = 0; |
| 57 | |
| 58 | /** |
| 59 | * @var int start offset of the current file being processed, |
| 60 | */ |
| 61 | private $currentFileStartOffset = 0; |
| 62 | |
| 63 | /** @var int */ |
| 64 | private $totalRowsBackup = 0; |
| 65 | |
| 66 | /** @var int */ |
| 67 | private $tableRowsOffset = 0; |
| 68 | |
| 69 | /** @var string Sql file $sqlWrittenBytes belongs to, since a multipart rotation restarts the byte count */ |
| 70 | private $sqlCheckpointFile = ''; |
| 71 | |
| 72 | /** @var int Length of the sql file when $tableRowsOffset was last set, rewound to on retry */ |
| 73 | private $sqlWrittenBytes = 0; |
| 74 | |
| 75 | /** @var int */ |
| 76 | private $totalRowsOfTableBeingBackup = 0; |
| 77 | |
| 78 | /** @var int reset to PHP_INT_MIN for each table */ |
| 79 | private $lastInsertId = PHP_INT_MIN; |
| 80 | |
| 81 | /** @var array */ |
| 82 | private $tablesToBackup = []; |
| 83 | |
| 84 | /** @var array */ |
| 85 | private $nonWpTables = []; |
| 86 | |
| 87 | /** @var int The size in bytes of the database in this backup */ |
| 88 | private $databaseFileSize = 0; |
| 89 | |
| 90 | /** @var int The size in bytes of the filesystem in this backup */ |
| 91 | private $filesystemSize = 0; |
| 92 | |
| 93 | /** @var int The number of requests that the Discovering Files task has executed so far */ |
| 94 | private $discoveringFilesRequests = 0; |
| 95 | |
| 96 | /** @var string The cron to repeat this backup, if scheduled. */ |
| 97 | private $scheduleRecurrence = ''; |
| 98 | |
| 99 | /** @var array The hour and minute to repeat this backup, if scheduled. */ |
| 100 | private $scheduleTime = []; |
| 101 | |
| 102 | /** @var int How many backups to keep, if scheduled. */ |
| 103 | private $scheduleRotation = 0; |
| 104 | |
| 105 | /** @var string The absolute path to this .wpstg file */ |
| 106 | private $backupFilePath = ''; |
| 107 | |
| 108 | /** @var string If set, this backup was created as part of this schedule ID. */ |
| 109 | private $scheduleId = ''; |
| 110 | |
| 111 | /** @var bool Should the backup be validated for each file once the backup is created. */ |
| 112 | private $isValidateBackupFiles = false; |
| 113 | |
| 114 | /** @var bool Should this scheduled backup be created right now. Matters only if this backup is repeated on schedule */ |
| 115 | private $isCreateScheduleBackupNow = false; |
| 116 | |
| 117 | /** @var bool Should the backup be created in background? */ |
| 118 | private $isCreateBackupInBackground = false; |
| 119 | |
| 120 | /** @var array Site selected to backup */ |
| 121 | private $sitesToBackup = []; |
| 122 | |
| 123 | /** |
| 124 | * is network subsite or network main site backup |
| 125 | * @var bool */ |
| 126 | private $isNetworkSiteBackup = false; |
| 127 | |
| 128 | /** |
| 129 | * @var array |
| 130 | * Store max index for each category |
| 131 | */ |
| 132 | private $fileBackupIndices = []; |
| 133 | |
| 134 | /** @var int */ |
| 135 | private $maxDbPartIndex = 0; |
| 136 | |
| 137 | /** |
| 138 | * Persisted cross-AJAX state for the multipart big-file segmenter. |
| 139 | * Tracks how many bytes of the source file have already been written across previous |
| 140 | * segments / parts so an interrupted backup can resume mid-file. |
| 141 | * @var int |
| 142 | */ |
| 143 | private $bigFileSourceBytesWritten = 0; |
| 144 | |
| 145 | /** |
| 146 | * Persisted cross-AJAX state for the multipart big-file segmenter. |
| 147 | * True when the next segment to write must carry REQUIRE_PREVIOUS_PART. |
| 148 | * @var bool |
| 149 | */ |
| 150 | private $bigFileIsContinuation = false; |
| 151 | |
| 152 | /** @var int */ |
| 153 | private $currentMultipartFileInfoIndex = 0; |
| 154 | |
| 155 | /** @var array */ |
| 156 | private $multipartFilesInfo = []; |
| 157 | |
| 158 | /** |
| 159 | * @var array<string, int> |
| 160 | * Store total size for each category |
| 161 | */ |
| 162 | private $categorySizes = []; |
| 163 | |
| 164 | /** @var string */ |
| 165 | private $backupType = ''; |
| 166 | |
| 167 | /** @var int */ |
| 168 | private $subsiteBlogId = 0; |
| 169 | |
| 170 | /** @var int */ |
| 171 | private $filePartIndex = 0; |
| 172 | |
| 173 | /** @var bool */ |
| 174 | private $isContaining2GBFile = false; |
| 175 | |
| 176 | /** @var bool */ |
| 177 | private $isGlitchInBackup = false; |
| 178 | |
| 179 | /** @var string */ |
| 180 | private $glitchReason = ''; |
| 181 | |
| 182 | /** @var int */ |
| 183 | private $fileAppendTimeLimit = 10; |
| 184 | |
| 185 | /** @var bool */ |
| 186 | private $isCompressed = false; |
| 187 | |
| 188 | /** |
| 189 | * @var int |
| 190 | */ |
| 191 | private $backupSizeUncompressed = 0; |
| 192 | |
| 193 | /** |
| 194 | * @var int |
| 195 | */ |
| 196 | private $backupSizeCompressed = 0; |
| 197 | |
| 198 | /** |
| 199 | * @var int |
| 200 | */ |
| 201 | private $totalFilesCompressed = 0; |
| 202 | |
| 203 | /** @var array */ |
| 204 | private $pushPrepareData = []; |
| 205 | |
| 206 | /** |
| 207 | * @return bool Whether this backup was created by a schedule, as opposed to manually. |
| 208 | */ |
| 209 | public function isScheduledBackup(): bool |
| 210 | { |
| 211 | return $this->getRepeatBackupOnSchedule() || !empty($this->getScheduleId()); |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * @return string|null |
| 216 | */ |
| 217 | public function getName() |
| 218 | { |
| 219 | return $this->name; |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Hydrated dynamically. |
| 224 | * |
| 225 | * @param string|null $name |
| 226 | */ |
| 227 | public function setName($name) |
| 228 | { |
| 229 | $this->name = $name; |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * @return array |
| 234 | */ |
| 235 | public function getPushPrepareData(): array |
| 236 | { |
| 237 | return $this->pushPrepareData; |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * @param array $pushPrepareData |
| 242 | * @return void |
| 243 | */ |
| 244 | public function setPushPrepareData(array $pushPrepareData) |
| 245 | { |
| 246 | $this->pushPrepareData = $pushPrepareData; |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * @return array|null |
| 251 | */ |
| 252 | public function getExcludedDirectories() |
| 253 | { |
| 254 | return (array)$this->excludedDirectories; |
| 255 | } |
| 256 | |
| 257 | public function setExcludedDirectories(array $excludedDirectories = []) |
| 258 | { |
| 259 | $this->excludedDirectories = $excludedDirectories; |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * @return int |
| 264 | */ |
| 265 | public function getTotalDirectories() |
| 266 | { |
| 267 | return $this->totalDirectories; |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * @param int $totalDirectories |
| 272 | */ |
| 273 | public function setTotalDirectories($totalDirectories) |
| 274 | { |
| 275 | $this->totalDirectories = $totalDirectories; |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * @return int |
| 280 | */ |
| 281 | public function getTotalFiles() |
| 282 | { |
| 283 | return $this->totalFiles; |
| 284 | } |
| 285 | |
| 286 | /** |
| 287 | * @param int $totalFiles |
| 288 | */ |
| 289 | public function setTotalFiles($totalFiles) |
| 290 | { |
| 291 | $this->totalFiles = $totalFiles; |
| 292 | } |
| 293 | |
| 294 | /** |
| 295 | * @return int |
| 296 | */ |
| 297 | public function getDiscoveredFiles() |
| 298 | { |
| 299 | return $this->discoveredFiles; |
| 300 | } |
| 301 | |
| 302 | /** |
| 303 | * @param int $discoveredFiles |
| 304 | */ |
| 305 | public function setDiscoveredFiles($discoveredFiles) |
| 306 | { |
| 307 | $this->discoveredFiles = $discoveredFiles; |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * @return int |
| 312 | */ |
| 313 | public function getInvalidFiles(): int |
| 314 | { |
| 315 | return $this->invalidFiles; |
| 316 | } |
| 317 | |
| 318 | /** |
| 319 | * @param int $invalidFiles |
| 320 | * @return void |
| 321 | */ |
| 322 | public function setInvalidFiles(int $invalidFiles) |
| 323 | { |
| 324 | $this->invalidFiles = $invalidFiles; |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * @return void |
| 329 | */ |
| 330 | public function incrementInvalidFiles() |
| 331 | { |
| 332 | $this->invalidFiles++; |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * @return string |
| 337 | */ |
| 338 | public function getDatabaseFile() |
| 339 | { |
| 340 | return $this->databaseFile; |
| 341 | } |
| 342 | |
| 343 | /** |
| 344 | * @param string $databaseFile |
| 345 | */ |
| 346 | public function setDatabaseFile($databaseFile) |
| 347 | { |
| 348 | $this->databaseFile = $databaseFile; |
| 349 | } |
| 350 | |
| 351 | /** |
| 352 | * @return int |
| 353 | */ |
| 354 | public function getTableRowsOffset() |
| 355 | { |
| 356 | return (int)$this->tableRowsOffset; |
| 357 | } |
| 358 | |
| 359 | /** |
| 360 | * @param int $tableRowsOffset |
| 361 | */ |
| 362 | public function setTableRowsOffset($tableRowsOffset) |
| 363 | { |
| 364 | $this->tableRowsOffset = (int)$tableRowsOffset; |
| 365 | } |
| 366 | |
| 367 | /** |
| 368 | * @return string |
| 369 | */ |
| 370 | public function getSqlCheckpointFile() |
| 371 | { |
| 372 | return (string)$this->sqlCheckpointFile; |
| 373 | } |
| 374 | |
| 375 | /** |
| 376 | * @param string $sqlCheckpointFile |
| 377 | */ |
| 378 | public function setSqlCheckpointFile($sqlCheckpointFile) |
| 379 | { |
| 380 | $this->sqlCheckpointFile = (string)$sqlCheckpointFile; |
| 381 | } |
| 382 | |
| 383 | /** |
| 384 | * @return int |
| 385 | */ |
| 386 | public function getSqlWrittenBytes() |
| 387 | { |
| 388 | return (int)$this->sqlWrittenBytes; |
| 389 | } |
| 390 | |
| 391 | /** |
| 392 | * @param int $sqlWrittenBytes |
| 393 | */ |
| 394 | public function setSqlWrittenBytes($sqlWrittenBytes) |
| 395 | { |
| 396 | $this->sqlWrittenBytes = (int)$sqlWrittenBytes; |
| 397 | } |
| 398 | |
| 399 | /** |
| 400 | * @return int |
| 401 | */ |
| 402 | public function getTotalRowsBackup() |
| 403 | { |
| 404 | return (int)$this->totalRowsBackup; |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * @param int $totalRowsBackup |
| 409 | */ |
| 410 | public function setTotalRowsBackup($totalRowsBackup) |
| 411 | { |
| 412 | $this->totalRowsBackup = (int)$totalRowsBackup; |
| 413 | } |
| 414 | |
| 415 | /** |
| 416 | * @return int |
| 417 | */ |
| 418 | public function getFileBeingBackupWrittenBytes() |
| 419 | { |
| 420 | return (int)$this->fileBeingBackupWrittenBytes; |
| 421 | } |
| 422 | |
| 423 | /** |
| 424 | * @param int $fileBeingBackupWrittenBytes |
| 425 | */ |
| 426 | public function setFileBeingBackupWrittenBytes($fileBeingBackupWrittenBytes) |
| 427 | { |
| 428 | $this->fileBeingBackupWrittenBytes = (int)$fileBeingBackupWrittenBytes; |
| 429 | } |
| 430 | |
| 431 | /** |
| 432 | * @return array |
| 433 | */ |
| 434 | public function getTablesToBackup() |
| 435 | { |
| 436 | return (array)$this->tablesToBackup; |
| 437 | } |
| 438 | |
| 439 | /** |
| 440 | * @param array $tablesToBackup |
| 441 | */ |
| 442 | public function setTablesToBackup($tablesToBackup) |
| 443 | { |
| 444 | $this->tablesToBackup = (array)$tablesToBackup; |
| 445 | } |
| 446 | |
| 447 | /** |
| 448 | * @return array |
| 449 | */ |
| 450 | public function getNonWpTables() |
| 451 | { |
| 452 | return (array)$this->nonWpTables; |
| 453 | } |
| 454 | |
| 455 | /** |
| 456 | * @param array $nonWpTables |
| 457 | */ |
| 458 | public function setNonWpTables($nonWpTables) |
| 459 | { |
| 460 | $this->nonWpTables = (array)$nonWpTables; |
| 461 | } |
| 462 | |
| 463 | /** |
| 464 | * @return int |
| 465 | */ |
| 466 | public function getTotalRowsOfTableBeingBackup() |
| 467 | { |
| 468 | return (int)$this->totalRowsOfTableBeingBackup; |
| 469 | } |
| 470 | |
| 471 | /** |
| 472 | * @param int $totalRowsOfTableBeingBackup |
| 473 | */ |
| 474 | public function setTotalRowsOfTableBeingBackup($totalRowsOfTableBeingBackup) |
| 475 | { |
| 476 | $this->totalRowsOfTableBeingBackup = (int)$totalRowsOfTableBeingBackup; |
| 477 | } |
| 478 | |
| 479 | /** |
| 480 | * @return int |
| 481 | */ |
| 482 | public function getDatabaseFileSize() |
| 483 | { |
| 484 | return $this->databaseFileSize; |
| 485 | } |
| 486 | |
| 487 | /** |
| 488 | * @param int $databaseFileSize |
| 489 | */ |
| 490 | public function setDatabaseFileSize($databaseFileSize) |
| 491 | { |
| 492 | $this->databaseFileSize = $databaseFileSize; |
| 493 | } |
| 494 | |
| 495 | /** |
| 496 | * @return int |
| 497 | */ |
| 498 | public function getFilesystemSize() |
| 499 | { |
| 500 | return $this->filesystemSize; |
| 501 | } |
| 502 | |
| 503 | /** |
| 504 | * @param int $filesystemSize |
| 505 | */ |
| 506 | public function setFilesystemSize($filesystemSize) |
| 507 | { |
| 508 | $this->filesystemSize = $filesystemSize; |
| 509 | } |
| 510 | |
| 511 | /** |
| 512 | * @return int |
| 513 | */ |
| 514 | public function getDiscoveringFilesRequests() |
| 515 | { |
| 516 | return $this->discoveringFilesRequests; |
| 517 | } |
| 518 | |
| 519 | /** |
| 520 | * @param int $discoveringFilesRequests |
| 521 | */ |
| 522 | public function setDiscoveringFilesRequests($discoveringFilesRequests) |
| 523 | { |
| 524 | $this->discoveringFilesRequests = $discoveringFilesRequests; |
| 525 | } |
| 526 | |
| 527 | /** |
| 528 | * @see Cron For WP STAGING cron recurrences. |
| 529 | * |
| 530 | * @return string A WP STAGING cron schedule |
| 531 | */ |
| 532 | public function getScheduleRecurrence() |
| 533 | { |
| 534 | return $this->scheduleRecurrence; |
| 535 | } |
| 536 | |
| 537 | /** |
| 538 | * @param string $scheduleRecurrence |
| 539 | */ |
| 540 | public function setScheduleRecurrence($scheduleRecurrence) |
| 541 | { |
| 542 | $this->scheduleRecurrence = $scheduleRecurrence; |
| 543 | } |
| 544 | |
| 545 | /** |
| 546 | * @return array H:i time format, expected to be accurate to the site's timezone, example: 00:00 |
| 547 | */ |
| 548 | public function getScheduleTime() |
| 549 | { |
| 550 | return $this->scheduleTime; |
| 551 | } |
| 552 | |
| 553 | /** |
| 554 | * @param array $scheduleTime Hour and Minute ['00', '00'] |
| 555 | */ |
| 556 | public function setScheduleTime(array $scheduleTime) |
| 557 | { |
| 558 | $this->scheduleTime = $scheduleTime; |
| 559 | } |
| 560 | |
| 561 | /** |
| 562 | * @return int How many backups to keep, example: 1 |
| 563 | */ |
| 564 | public function getScheduleRotation() |
| 565 | { |
| 566 | return $this->scheduleRotation; |
| 567 | } |
| 568 | |
| 569 | /** |
| 570 | * @param int $scheduleRotation |
| 571 | */ |
| 572 | public function setScheduleRotation($scheduleRotation) |
| 573 | { |
| 574 | $this->scheduleRotation = $scheduleRotation; |
| 575 | } |
| 576 | |
| 577 | /** |
| 578 | * @return string |
| 579 | */ |
| 580 | public function getBackupFilePath() |
| 581 | { |
| 582 | return $this->backupFilePath; |
| 583 | } |
| 584 | |
| 585 | /** |
| 586 | * @param string $backupFilePath |
| 587 | */ |
| 588 | public function setBackupFilePath($backupFilePath) |
| 589 | { |
| 590 | $this->backupFilePath = $backupFilePath; |
| 591 | } |
| 592 | |
| 593 | /** |
| 594 | * @return string|null |
| 595 | */ |
| 596 | public function getScheduleId() |
| 597 | { |
| 598 | return $this->scheduleId; |
| 599 | } |
| 600 | |
| 601 | /** |
| 602 | * @param string $scheduleId |
| 603 | */ |
| 604 | public function setScheduleId($scheduleId) |
| 605 | { |
| 606 | $this->scheduleId = $scheduleId; |
| 607 | } |
| 608 | |
| 609 | /** |
| 610 | * @return bool |
| 611 | */ |
| 612 | public function getIsCreateScheduleBackupNow() |
| 613 | { |
| 614 | return $this->isCreateScheduleBackupNow; |
| 615 | } |
| 616 | |
| 617 | /** |
| 618 | * @param bool $isCreateScheduleBackupNow |
| 619 | */ |
| 620 | public function setIsCreateScheduleBackupNow($isCreateScheduleBackupNow) |
| 621 | { |
| 622 | $this->isCreateScheduleBackupNow = (bool)$isCreateScheduleBackupNow; |
| 623 | } |
| 624 | |
| 625 | /** |
| 626 | * @return bool |
| 627 | */ |
| 628 | public function getIsCreateBackupInBackground(): bool |
| 629 | { |
| 630 | return (bool)$this->isCreateBackupInBackground; |
| 631 | } |
| 632 | |
| 633 | /** |
| 634 | * Cannot strict type it yet, otherwise it might throw error for older scheduled backup |
| 635 | * @param bool $isCreateBackupInBackground |
| 636 | */ |
| 637 | public function setIsCreateBackupInBackground($isCreateBackupInBackground) |
| 638 | { |
| 639 | $this->isCreateBackupInBackground = (bool)$isCreateBackupInBackground; |
| 640 | } |
| 641 | |
| 642 | /** |
| 643 | * @return array|null |
| 644 | */ |
| 645 | public function getSitesToBackup() |
| 646 | { |
| 647 | return (array)$this->sitesToBackup; |
| 648 | } |
| 649 | |
| 650 | public function setSitesToBackup(array $sitesToBackup = []) |
| 651 | { |
| 652 | $this->sitesToBackup = $sitesToBackup; |
| 653 | } |
| 654 | |
| 655 | /** |
| 656 | * @return array |
| 657 | */ |
| 658 | public function getDiscoveredFilesArray() |
| 659 | { |
| 660 | return $this->discoveredFilesArray; |
| 661 | } |
| 662 | |
| 663 | /** |
| 664 | * @param array $discoveredFiles |
| 665 | */ |
| 666 | public function setDiscoveredFilesArray($discoveredFiles = []) |
| 667 | { |
| 668 | $this->discoveredFilesArray = $discoveredFiles; |
| 669 | } |
| 670 | |
| 671 | /** |
| 672 | * @param string $category |
| 673 | * @return int |
| 674 | */ |
| 675 | public function getDiscoveredFilesByCategory($category) |
| 676 | { |
| 677 | if (!array_key_exists($category, $this->discoveredFilesArray)) { |
| 678 | return 0; |
| 679 | } |
| 680 | |
| 681 | return $this->discoveredFilesArray[$category]; |
| 682 | } |
| 683 | |
| 684 | /** |
| 685 | * @param string $category |
| 686 | * @param int $discoveredFiles |
| 687 | */ |
| 688 | public function setDiscoveredFilesByCategory($category, $discoveredFiles) |
| 689 | { |
| 690 | $this->discoveredFilesArray[$category] = $discoveredFiles; |
| 691 | } |
| 692 | |
| 693 | /** |
| 694 | * @return array |
| 695 | */ |
| 696 | public function getFilesInParts() |
| 697 | { |
| 698 | return $this->filesInParts; |
| 699 | } |
| 700 | |
| 701 | /** |
| 702 | * @param array $filesInParts |
| 703 | */ |
| 704 | public function setFilesInParts($filesInParts = []) |
| 705 | { |
| 706 | $this->filesInParts = $filesInParts; |
| 707 | } |
| 708 | |
| 709 | /** |
| 710 | * @param string $category |
| 711 | * @param int $categoryIndex |
| 712 | * @return int |
| 713 | */ |
| 714 | public function getFilesInPart($category, $categoryIndex) |
| 715 | { |
| 716 | if (!array_key_exists($category, $this->filesInParts)) { |
| 717 | return 0; |
| 718 | } |
| 719 | |
| 720 | if (!isset($this->filesInParts[$category][$categoryIndex])) { |
| 721 | return 0; |
| 722 | } |
| 723 | |
| 724 | return $this->filesInParts[$category][$categoryIndex]; |
| 725 | } |
| 726 | |
| 727 | /** |
| 728 | * @param string $category |
| 729 | * @param int $categoryIndex |
| 730 | * @param int $files |
| 731 | */ |
| 732 | public function setFilesInPart($category, $categoryIndex, $files) |
| 733 | { |
| 734 | if (!array_key_exists($category, $this->filesInParts)) { |
| 735 | $this->filesInParts[$category] = []; |
| 736 | } |
| 737 | |
| 738 | $this->filesInParts[$category][$categoryIndex] = $files; |
| 739 | } |
| 740 | |
| 741 | /** |
| 742 | * @param string $category |
| 743 | * @param int $categoryIndex |
| 744 | * @return void |
| 745 | */ |
| 746 | public function incrementFilesInPart(string $category, int $categoryIndex = 0) |
| 747 | { |
| 748 | if (!array_key_exists($category, $this->filesInParts)) { |
| 749 | $this->filesInParts[$category] = []; |
| 750 | } |
| 751 | |
| 752 | if (!array_key_exists($categoryIndex, $this->filesInParts[$category])) { |
| 753 | $this->filesInParts[$category][$categoryIndex] = 0; |
| 754 | } |
| 755 | |
| 756 | $this->filesInParts[$category][$categoryIndex]++; |
| 757 | } |
| 758 | |
| 759 | /** |
| 760 | * @return array |
| 761 | */ |
| 762 | public function getFileBackupIndices() |
| 763 | { |
| 764 | return $this->fileBackupIndices; |
| 765 | } |
| 766 | |
| 767 | /** |
| 768 | * @param array $fileBackupIndices |
| 769 | */ |
| 770 | public function setFileBackupIndices($fileBackupIndices = []) |
| 771 | { |
| 772 | $this->fileBackupIndices = $fileBackupIndices; |
| 773 | } |
| 774 | |
| 775 | /** |
| 776 | * @return int |
| 777 | */ |
| 778 | public function getMaxDbPartIndex() |
| 779 | { |
| 780 | return $this->maxDbPartIndex; |
| 781 | } |
| 782 | |
| 783 | /** |
| 784 | * @param int $maxDbPartIndex |
| 785 | */ |
| 786 | public function setMaxDbPartIndex($maxDbPartIndex) |
| 787 | { |
| 788 | $this->maxDbPartIndex = $maxDbPartIndex; |
| 789 | } |
| 790 | |
| 791 | public function getBigFileSourceBytesWritten(): int |
| 792 | { |
| 793 | return (int) $this->bigFileSourceBytesWritten; |
| 794 | } |
| 795 | |
| 796 | public function setBigFileSourceBytesWritten(int $bigFileSourceBytesWritten) |
| 797 | { |
| 798 | $this->bigFileSourceBytesWritten = $bigFileSourceBytesWritten; |
| 799 | } |
| 800 | |
| 801 | public function getBigFileIsContinuation(): bool |
| 802 | { |
| 803 | return (bool) $this->bigFileIsContinuation; |
| 804 | } |
| 805 | |
| 806 | public function setBigFileIsContinuation(bool $bigFileIsContinuation) |
| 807 | { |
| 808 | $this->bigFileIsContinuation = $bigFileIsContinuation; |
| 809 | } |
| 810 | |
| 811 | /** |
| 812 | * @return int |
| 813 | */ |
| 814 | public function getCurrentMultipartFileInfoIndex() |
| 815 | { |
| 816 | return $this->currentMultipartFileInfoIndex; |
| 817 | } |
| 818 | |
| 819 | /** |
| 820 | * @param int $currentMultipartFileInfoIndex |
| 821 | */ |
| 822 | public function setCurrentMultipartFileInfoIndex($currentMultipartFileInfoIndex) |
| 823 | { |
| 824 | $this->currentMultipartFileInfoIndex = $currentMultipartFileInfoIndex; |
| 825 | } |
| 826 | |
| 827 | /** |
| 828 | * @return array |
| 829 | */ |
| 830 | public function getMultipartFilesInfo() |
| 831 | { |
| 832 | return $this->multipartFilesInfo; |
| 833 | } |
| 834 | |
| 835 | /** |
| 836 | * @param array $multipartFilesInfo |
| 837 | */ |
| 838 | public function setMultipartFilesInfo($multipartFilesInfo) |
| 839 | { |
| 840 | $this->multipartFilesInfo = $multipartFilesInfo; |
| 841 | } |
| 842 | |
| 843 | /** |
| 844 | * @param array $multipartFileInfo |
| 845 | */ |
| 846 | public function addMultipartFileInfo($multipartFileInfo) |
| 847 | { |
| 848 | $this->multipartFilesInfo[] = $multipartFileInfo; |
| 849 | } |
| 850 | |
| 851 | /** |
| 852 | * @param array $multipartFileInfo |
| 853 | * @param int $index |
| 854 | */ |
| 855 | public function updateMultipartFileInfo($multipartFileInfo, $index) |
| 856 | { |
| 857 | $this->multipartFilesInfo[$index] = $multipartFileInfo; |
| 858 | } |
| 859 | |
| 860 | /** |
| 861 | * @param int $lastInsertId |
| 862 | */ |
| 863 | public function setLastInsertId($lastInsertId) |
| 864 | { |
| 865 | $this->lastInsertId = $lastInsertId; |
| 866 | } |
| 867 | |
| 868 | /** |
| 869 | * @return int |
| 870 | */ |
| 871 | public function getLastInsertId() |
| 872 | { |
| 873 | return $this->lastInsertId; |
| 874 | } |
| 875 | |
| 876 | /** |
| 877 | * @param array<string, int> $categorySizes |
| 878 | */ |
| 879 | public function setCategorySizes($categorySizes) |
| 880 | { |
| 881 | $this->categorySizes = $categorySizes; |
| 882 | } |
| 883 | |
| 884 | /** |
| 885 | * @return array<string, int> |
| 886 | */ |
| 887 | public function getCategorySizes() |
| 888 | { |
| 889 | return $this->categorySizes; |
| 890 | } |
| 891 | |
| 892 | /** |
| 893 | * @return int |
| 894 | */ |
| 895 | public function getFilePartIndex(): int |
| 896 | { |
| 897 | return $this->filePartIndex; |
| 898 | } |
| 899 | |
| 900 | /** |
| 901 | * @param int $index |
| 902 | * @return void |
| 903 | */ |
| 904 | public function setFilePartIndex(int $index = 0) |
| 905 | { |
| 906 | $this->filePartIndex = $index; |
| 907 | } |
| 908 | |
| 909 | /** |
| 910 | * @param bool $isNetworkSiteBackup |
| 911 | * @return void |
| 912 | */ |
| 913 | public function setIsNetworkSiteBackup(bool $isNetworkSiteBackup) |
| 914 | { |
| 915 | $this->isNetworkSiteBackup = $isNetworkSiteBackup; |
| 916 | } |
| 917 | |
| 918 | /** |
| 919 | * @return bool |
| 920 | */ |
| 921 | public function getIsNetworkSiteBackup(): bool |
| 922 | { |
| 923 | return (bool)$this->isNetworkSiteBackup; |
| 924 | } |
| 925 | |
| 926 | /** |
| 927 | * @param string $backupType |
| 928 | * @return void |
| 929 | */ |
| 930 | public function setBackupType(string $backupType) |
| 931 | { |
| 932 | $this->backupType = $backupType; |
| 933 | } |
| 934 | |
| 935 | /** |
| 936 | * @return string |
| 937 | */ |
| 938 | public function getBackupType(): string |
| 939 | { |
| 940 | return $this->backupType; |
| 941 | } |
| 942 | |
| 943 | /** |
| 944 | * @param int|null $subsiteBlogId |
| 945 | * @return void |
| 946 | */ |
| 947 | public function setSubsiteBlogId($subsiteBlogId) |
| 948 | { |
| 949 | $this->subsiteBlogId = $subsiteBlogId; |
| 950 | } |
| 951 | |
| 952 | /** |
| 953 | * @return int |
| 954 | */ |
| 955 | public function getSubsiteBlogId(): int |
| 956 | { |
| 957 | if (empty($this->subsiteBlogId)) { |
| 958 | $this->subsiteBlogId = get_current_blog_id(); |
| 959 | } |
| 960 | |
| 961 | return (int)$this->subsiteBlogId; |
| 962 | } |
| 963 | |
| 964 | /** |
| 965 | * @return bool |
| 966 | */ |
| 967 | public function getIsValidateBackupFiles(): bool |
| 968 | { |
| 969 | return (bool)$this->isValidateBackupFiles; |
| 970 | } |
| 971 | |
| 972 | /** |
| 973 | * Cannot strict type it yet, otherwise it might throw error for older scheduled backup |
| 974 | * @param bool $isValidateBackupFiles |
| 975 | */ |
| 976 | public function setIsValidateBackupFiles($isValidateBackupFiles) |
| 977 | { |
| 978 | $this->isValidateBackupFiles = (bool)$isValidateBackupFiles; |
| 979 | } |
| 980 | |
| 981 | /** |
| 982 | * @return bool |
| 983 | */ |
| 984 | public function getIsBackupFormatV1(): bool |
| 985 | { |
| 986 | return Hooks::applyFilters(BackupMetadata::FILTER_BACKUP_FORMAT_V1, false); |
| 987 | } |
| 988 | |
| 989 | /** |
| 990 | * @return bool |
| 991 | */ |
| 992 | public function getIsContaining2GBFile(): bool |
| 993 | { |
| 994 | return $this->isContaining2GBFile; |
| 995 | } |
| 996 | |
| 997 | /** |
| 998 | * @param bool $isContaining2GBFile |
| 999 | * @return void |
| 1000 | */ |
| 1001 | public function setIsContaining2GBFile(bool $isContaining2GBFile) |
| 1002 | { |
| 1003 | $this->isContaining2GBFile = $isContaining2GBFile; |
| 1004 | } |
| 1005 | |
| 1006 | public function getIsGlitchInBackup(): bool |
| 1007 | { |
| 1008 | return $this->isGlitchInBackup; |
| 1009 | } |
| 1010 | |
| 1011 | /** |
| 1012 | * @param bool $isGlitchInBackup |
| 1013 | * @return void |
| 1014 | */ |
| 1015 | public function setIsGlitchInBackup(bool $isGlitchInBackup) |
| 1016 | { |
| 1017 | $this->isGlitchInBackup = $isGlitchInBackup; |
| 1018 | } |
| 1019 | |
| 1020 | public function getGlitchReason(): string |
| 1021 | { |
| 1022 | return $this->glitchReason; |
| 1023 | } |
| 1024 | |
| 1025 | /** |
| 1026 | * @param string $glitchReason |
| 1027 | * @return void |
| 1028 | */ |
| 1029 | public function setGlitchReason(string $glitchReason) |
| 1030 | { |
| 1031 | $this->glitchReason = $glitchReason; |
| 1032 | } |
| 1033 | |
| 1034 | /** |
| 1035 | * @return int |
| 1036 | */ |
| 1037 | public function getCurrentWrittenFileHeaderBytes(): int |
| 1038 | { |
| 1039 | return (int)$this->currentWrittenFileHeaderBytes; |
| 1040 | } |
| 1041 | |
| 1042 | /** |
| 1043 | * @param int $currentWrittenFileHeaderBytes |
| 1044 | * @return void |
| 1045 | */ |
| 1046 | public function setCurrentWrittenFileHeaderBytes(int $currentWrittenFileHeaderBytes) |
| 1047 | { |
| 1048 | $this->currentWrittenFileHeaderBytes = (int)$currentWrittenFileHeaderBytes; |
| 1049 | } |
| 1050 | |
| 1051 | public function getCurrentFileStartOffset(): int |
| 1052 | { |
| 1053 | return $this->currentFileStartOffset; |
| 1054 | } |
| 1055 | |
| 1056 | /** |
| 1057 | * @param int $currentFileStartOffset |
| 1058 | * @return void |
| 1059 | */ |
| 1060 | public function setCurrentFileStartOffset(int $currentFileStartOffset) |
| 1061 | { |
| 1062 | $this->currentFileStartOffset = (int)$currentFileStartOffset; |
| 1063 | } |
| 1064 | |
| 1065 | /** |
| 1066 | * @param int $timeLimit |
| 1067 | * @return void |
| 1068 | */ |
| 1069 | public function setFileAppendTimeLimit(int $timeLimit) |
| 1070 | { |
| 1071 | $this->fileAppendTimeLimit = $timeLimit; |
| 1072 | } |
| 1073 | |
| 1074 | /** |
| 1075 | * @return int |
| 1076 | */ |
| 1077 | public function getFileAppendTimeLimit(): int |
| 1078 | { |
| 1079 | return $this->fileAppendTimeLimit; |
| 1080 | } |
| 1081 | |
| 1082 | /** |
| 1083 | * @return void |
| 1084 | */ |
| 1085 | public function incrementFileAppendTimeLimit() |
| 1086 | { |
| 1087 | $this->fileAppendTimeLimit += 5; |
| 1088 | } |
| 1089 | |
| 1090 | /** |
| 1091 | * @return void |
| 1092 | */ |
| 1093 | public function resetFileAppendTimeLimit() |
| 1094 | { |
| 1095 | $this->fileAppendTimeLimit = 10; |
| 1096 | } |
| 1097 | |
| 1098 | /** |
| 1099 | * @return bool |
| 1100 | */ |
| 1101 | public function getIsCompressed(): bool |
| 1102 | { |
| 1103 | return $this->isCompressed; |
| 1104 | } |
| 1105 | |
| 1106 | /** |
| 1107 | * @param bool $isCompressed |
| 1108 | * @return void |
| 1109 | */ |
| 1110 | public function setIsCompressed(bool $isCompressed) |
| 1111 | { |
| 1112 | $this->isCompressed = $isCompressed; |
| 1113 | } |
| 1114 | |
| 1115 | /** |
| 1116 | * @return int |
| 1117 | */ |
| 1118 | public function getBackupSizeUncompressed(): int |
| 1119 | { |
| 1120 | return $this->backupSizeUncompressed; |
| 1121 | } |
| 1122 | |
| 1123 | /** |
| 1124 | * @param int $backupSizeUncompressed |
| 1125 | * @return void |
| 1126 | */ |
| 1127 | public function setBackupSizeUncompressed(int $backupSizeUncompressed) |
| 1128 | { |
| 1129 | $this->backupSizeUncompressed = $backupSizeUncompressed; |
| 1130 | } |
| 1131 | |
| 1132 | /** |
| 1133 | * @param int $backupSizeUncompressed |
| 1134 | * @return void |
| 1135 | */ |
| 1136 | public function addBackupSizeUncompressed(int $backupSizeUncompressed) |
| 1137 | { |
| 1138 | $this->backupSizeUncompressed += $backupSizeUncompressed; |
| 1139 | } |
| 1140 | |
| 1141 | /** |
| 1142 | * @return int |
| 1143 | */ |
| 1144 | public function getBackupSizeCompressed(): int |
| 1145 | { |
| 1146 | return $this->backupSizeCompressed; |
| 1147 | } |
| 1148 | |
| 1149 | /** |
| 1150 | * @param int $backupSizeCompressed |
| 1151 | * @return void |
| 1152 | */ |
| 1153 | public function setBackupSizeCompressed(int $backupSizeCompressed) |
| 1154 | { |
| 1155 | $this->backupSizeCompressed = $backupSizeCompressed; |
| 1156 | } |
| 1157 | |
| 1158 | /** |
| 1159 | * @param int $backupSizeCompressed |
| 1160 | * @return void |
| 1161 | */ |
| 1162 | public function addBackupSizeCompressed(int $backupSizeCompressed) |
| 1163 | { |
| 1164 | $this->backupSizeCompressed += $backupSizeCompressed; |
| 1165 | } |
| 1166 | |
| 1167 | /** |
| 1168 | * @return int |
| 1169 | */ |
| 1170 | public function getTotalFilesCompressed(): int |
| 1171 | { |
| 1172 | return $this->totalFilesCompressed; |
| 1173 | } |
| 1174 | |
| 1175 | /** |
| 1176 | * @param int $totalFilesCompressed |
| 1177 | * @return void |
| 1178 | */ |
| 1179 | public function setTotalFilesCompressed(int $totalFilesCompressed) |
| 1180 | { |
| 1181 | $this->totalFilesCompressed = $totalFilesCompressed; |
| 1182 | } |
| 1183 | |
| 1184 | /** |
| 1185 | * @return void |
| 1186 | */ |
| 1187 | public function incrementTotalFilesCompressed() |
| 1188 | { |
| 1189 | $this->totalFilesCompressed++; |
| 1190 | } |
| 1191 | } |
| 1192 |