Job
1 day ago
Service
11 months ago
Task
11 months ago
DirectoryNodeDto.php
1 year ago
ListableStagingSite.php
1 year ago
StagingSiteDto.php
2 months ago
StagingSiteDto.php
739 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Staging\Dto; |
| 4 | |
| 5 | use WPStaging\Framework\Traits\ArrayableTrait; |
| 6 | use WPStaging\Framework\Traits\HydrateTrait; |
| 7 | |
| 8 | /** |
| 9 | * Class StagingSiteDto |
| 10 | * |
| 11 | * This is OOP representation of all staging site options stored in database. |
| 12 | * |
| 13 | * @package WPStaging\Staging\Dto |
| 14 | */ |
| 15 | class StagingSiteDto implements \JsonSerializable |
| 16 | { |
| 17 | use HydrateTrait; |
| 18 | use ArrayableTrait; |
| 19 | |
| 20 | /** |
| 21 | * @var string |
| 22 | */ |
| 23 | const STATUS_FINISHED = 'finished'; |
| 24 | |
| 25 | const STATUS_UNFINISHED_BROKEN = 'unfinished or broken (?)'; |
| 26 | |
| 27 | /** @var string */ |
| 28 | protected $cloneId = ''; |
| 29 | |
| 30 | /** @var string */ |
| 31 | protected $cloneName = ''; |
| 32 | |
| 33 | /** @var string */ |
| 34 | protected $directoryName = ''; |
| 35 | |
| 36 | /** @var string */ |
| 37 | protected $path = ''; |
| 38 | |
| 39 | /** @var string */ |
| 40 | protected $url = ''; |
| 41 | |
| 42 | /** @var int */ |
| 43 | protected $number = 0; |
| 44 | |
| 45 | /** @var string */ |
| 46 | protected $version = ''; |
| 47 | |
| 48 | /** @var string */ |
| 49 | protected $status = ''; |
| 50 | |
| 51 | /** @var string */ |
| 52 | protected $prefix = ''; |
| 53 | |
| 54 | /** @var int */ |
| 55 | protected $datetime = 0; |
| 56 | |
| 57 | /** @var string */ |
| 58 | protected $databaseUser = ''; |
| 59 | |
| 60 | /** @var string */ |
| 61 | protected $databasePassword = ''; |
| 62 | |
| 63 | /** @var string */ |
| 64 | protected $databaseDatabase = ''; |
| 65 | |
| 66 | /** @var string */ |
| 67 | protected $databaseServer = ''; |
| 68 | |
| 69 | /** @var string */ |
| 70 | protected $databasePrefix = ''; |
| 71 | |
| 72 | /** @var bool */ |
| 73 | protected $databaseSsl = false; |
| 74 | |
| 75 | /** @var bool */ |
| 76 | protected $isEmailsAllowed = true; |
| 77 | |
| 78 | /** @var bool */ |
| 79 | protected $uploadsSymlinked = false; |
| 80 | |
| 81 | /** @var array */ |
| 82 | protected $includedTables = []; |
| 83 | |
| 84 | /** @var array */ |
| 85 | protected $excludeSizeRules = []; |
| 86 | |
| 87 | /** @var array */ |
| 88 | protected $excludeGlobRules = []; |
| 89 | |
| 90 | /** @var array */ |
| 91 | protected $excludedDirectories = []; |
| 92 | |
| 93 | /** @var array */ |
| 94 | protected $extraDirectories = []; |
| 95 | |
| 96 | /** @var bool */ |
| 97 | protected $networkClone = false; |
| 98 | |
| 99 | /** |
| 100 | * The blog ID from which this staging site was created (for multisite subsite cloning) |
| 101 | * 0 or 1 = main site, 2+ = subsite |
| 102 | * @var int |
| 103 | */ |
| 104 | protected $sourceBlogId = 0; |
| 105 | |
| 106 | /** @var bool */ |
| 107 | protected $isCronEnabled = true; |
| 108 | |
| 109 | /** @var bool */ |
| 110 | protected $isWooSchedulerEnabled = true; |
| 111 | |
| 112 | /** @var bool */ |
| 113 | protected $isEmailsReminderEnabled = false; |
| 114 | |
| 115 | /** @var int */ |
| 116 | protected $ownerId = 0; |
| 117 | |
| 118 | /** @var bool */ |
| 119 | protected $useNewAdminAccount = false; |
| 120 | |
| 121 | /** @var string */ |
| 122 | protected $adminEmail = ''; |
| 123 | |
| 124 | /** @var string */ |
| 125 | protected $adminPassword = ''; |
| 126 | |
| 127 | /** @var array */ |
| 128 | protected $excludedDirs = []; |
| 129 | |
| 130 | /** @var array|false */ |
| 131 | protected $tablePushSelection = false; |
| 132 | |
| 133 | /** @var bool */ |
| 134 | protected $isAutoUpdatePlugins = false; |
| 135 | |
| 136 | public function jsonSerialize(): mixed |
| 137 | { |
| 138 | return $this->toArray(); |
| 139 | } |
| 140 | |
| 141 | public function toListableItem(): ListableStagingSite |
| 142 | { |
| 143 | $listable = new ListableStagingSite(); |
| 144 | $listable->cloneId = $this->cloneId; |
| 145 | $listable->cloneName = $this->cloneName; |
| 146 | $listable->siteName = $this->getSiteName(); |
| 147 | $listable->path = $this->path; |
| 148 | $listable->url = $this->url; |
| 149 | $listable->isNetworkClone = $this->networkClone; |
| 150 | $listable->directoryName = $this->directoryName; |
| 151 | $listable->status = $this->status; |
| 152 | $listable->databaseName = $this->getDatabaseName(); |
| 153 | $listable->databasePrefix = $this->getUsedPrefix(); |
| 154 | $listable->modifiedAt = empty($this->datetime) ? 0 : get_date_from_gmt(date("Y-m-d H:i:s", $this->datetime), "D, d M Y H:i:s T"); |
| 155 | $listable->createdBy = $this->getOwnerName(); |
| 156 | |
| 157 | return $listable; |
| 158 | } |
| 159 | |
| 160 | public function getCloneId(): string |
| 161 | { |
| 162 | return $this->cloneId; |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * @param string|null $cloneId |
| 167 | * @return void |
| 168 | */ |
| 169 | public function setCloneId($cloneId) |
| 170 | { |
| 171 | $this->cloneId = (string)$cloneId; |
| 172 | } |
| 173 | |
| 174 | public function getCloneName(): string |
| 175 | { |
| 176 | return $this->cloneName; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * @param string $cloneName |
| 181 | * @return void |
| 182 | */ |
| 183 | public function setCloneName(string $cloneName) |
| 184 | { |
| 185 | $this->cloneName = $cloneName; |
| 186 | } |
| 187 | |
| 188 | public function getDirectoryName(): string |
| 189 | { |
| 190 | return $this->directoryName; |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * @param string $directoryName |
| 195 | * @return void |
| 196 | */ |
| 197 | public function setDirectoryName(string $directoryName) |
| 198 | { |
| 199 | $this->directoryName = $directoryName; |
| 200 | } |
| 201 | |
| 202 | public function getPath(): string |
| 203 | { |
| 204 | return $this->path; |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * @param string $path |
| 209 | * @return void |
| 210 | */ |
| 211 | public function setPath(string $path) |
| 212 | { |
| 213 | $this->path = $path; |
| 214 | } |
| 215 | |
| 216 | public function getUrl(): string |
| 217 | { |
| 218 | return $this->url; |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * @param string $url |
| 223 | * @return void |
| 224 | */ |
| 225 | public function setUrl(string $url) |
| 226 | { |
| 227 | $this->url = $url; |
| 228 | } |
| 229 | |
| 230 | public function getNumber(): int |
| 231 | { |
| 232 | return $this->number; |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * @param int $number |
| 237 | * @return void |
| 238 | */ |
| 239 | public function setNumber(int $number) |
| 240 | { |
| 241 | $this->number = $number; |
| 242 | } |
| 243 | |
| 244 | public function getVersion(): string |
| 245 | { |
| 246 | return $this->version; |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * @param string $version |
| 251 | * @return void |
| 252 | */ |
| 253 | public function setVersion(string $version) |
| 254 | { |
| 255 | $this->version = $version; |
| 256 | } |
| 257 | |
| 258 | public function getStatus(): string |
| 259 | { |
| 260 | return $this->status; |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * @param string $status |
| 265 | * @return void |
| 266 | */ |
| 267 | public function setStatus(string $status) |
| 268 | { |
| 269 | $this->status = $status; |
| 270 | } |
| 271 | |
| 272 | public function getPrefix(): string |
| 273 | { |
| 274 | return $this->prefix; |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * @param string $prefix |
| 279 | * @return void |
| 280 | */ |
| 281 | public function setPrefix(string $prefix) |
| 282 | { |
| 283 | $this->prefix = $prefix; |
| 284 | } |
| 285 | |
| 286 | public function getDatetime(): int |
| 287 | { |
| 288 | return $this->datetime; |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * @param int $datetime |
| 293 | * @return void |
| 294 | */ |
| 295 | public function setDatetime(int $datetime) |
| 296 | { |
| 297 | $this->datetime = $datetime; |
| 298 | } |
| 299 | |
| 300 | public function getDatabaseUser(): string |
| 301 | { |
| 302 | return $this->databaseUser; |
| 303 | } |
| 304 | |
| 305 | /** |
| 306 | * @param string $databaseUser |
| 307 | * @return void |
| 308 | */ |
| 309 | public function setDatabaseUser(string $databaseUser) |
| 310 | { |
| 311 | $this->databaseUser = $databaseUser; |
| 312 | } |
| 313 | |
| 314 | public function getDatabasePassword(): string |
| 315 | { |
| 316 | return $this->databasePassword; |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * @param string $databasePassword |
| 321 | * @return void |
| 322 | */ |
| 323 | public function setDatabasePassword(string $databasePassword) |
| 324 | { |
| 325 | $this->databasePassword = $databasePassword; |
| 326 | } |
| 327 | |
| 328 | public function getDatabaseDatabase(): string |
| 329 | { |
| 330 | return $this->databaseDatabase; |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * @param string $databaseDatabase |
| 335 | * @return void |
| 336 | */ |
| 337 | public function setDatabaseDatabase(string $databaseDatabase) |
| 338 | { |
| 339 | $this->databaseDatabase = $databaseDatabase; |
| 340 | } |
| 341 | |
| 342 | public function getDatabaseServer(): string |
| 343 | { |
| 344 | return $this->databaseServer; |
| 345 | } |
| 346 | |
| 347 | /** |
| 348 | * @param string $databaseServer |
| 349 | * @return void |
| 350 | */ |
| 351 | public function setDatabaseServer(string $databaseServer) |
| 352 | { |
| 353 | $this->databaseServer = $databaseServer; |
| 354 | } |
| 355 | |
| 356 | public function getDatabasePrefix(): string |
| 357 | { |
| 358 | if (empty($this->databasePrefix)) { |
| 359 | return $this->prefix; |
| 360 | } |
| 361 | |
| 362 | return $this->databasePrefix; |
| 363 | } |
| 364 | |
| 365 | /** |
| 366 | * @param string $databasePrefix |
| 367 | * @return void |
| 368 | */ |
| 369 | public function setDatabasePrefix(string $databasePrefix) |
| 370 | { |
| 371 | $this->databasePrefix = $databasePrefix; |
| 372 | } |
| 373 | |
| 374 | public function getDatabaseSsl(): bool |
| 375 | { |
| 376 | return $this->databaseSsl; |
| 377 | } |
| 378 | |
| 379 | /** |
| 380 | * @param bool $databaseSsl |
| 381 | * @return void |
| 382 | */ |
| 383 | public function setDatabaseSsl(bool $databaseSsl) |
| 384 | { |
| 385 | $this->databaseSsl = $databaseSsl; |
| 386 | } |
| 387 | |
| 388 | public function getIsEmailsAllowed(): bool |
| 389 | { |
| 390 | return $this->isEmailsAllowed; |
| 391 | } |
| 392 | |
| 393 | /** |
| 394 | * @param bool $isEmailsAllowed |
| 395 | * @return void |
| 396 | */ |
| 397 | public function setIsEmailsAllowed(bool $isEmailsAllowed) |
| 398 | { |
| 399 | $this->isEmailsAllowed = $isEmailsAllowed; |
| 400 | } |
| 401 | |
| 402 | public function getUploadsSymlinked(): bool |
| 403 | { |
| 404 | return $this->uploadsSymlinked; |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * @param bool $uploadsSymlinked |
| 409 | * @return void |
| 410 | */ |
| 411 | public function setUploadsSymlinked(bool $uploadsSymlinked) |
| 412 | { |
| 413 | $this->uploadsSymlinked = $uploadsSymlinked; |
| 414 | } |
| 415 | |
| 416 | public function getIncludedTables(): array |
| 417 | { |
| 418 | return $this->includedTables; |
| 419 | } |
| 420 | |
| 421 | /** |
| 422 | * @param array $includedTables |
| 423 | * @return void |
| 424 | */ |
| 425 | public function setIncludedTables(array $includedTables) |
| 426 | { |
| 427 | $this->includedTables = $includedTables; |
| 428 | } |
| 429 | |
| 430 | public function getExcludeSizeRules(): array |
| 431 | { |
| 432 | return $this->excludeSizeRules; |
| 433 | } |
| 434 | |
| 435 | /** |
| 436 | * @param array $excludeSizeRules |
| 437 | * @return void |
| 438 | */ |
| 439 | public function setExcludeSizeRules(array $excludeSizeRules) |
| 440 | { |
| 441 | $this->excludeSizeRules = $excludeSizeRules; |
| 442 | } |
| 443 | |
| 444 | public function getExcludeGlobRules(): array |
| 445 | { |
| 446 | return $this->excludeGlobRules; |
| 447 | } |
| 448 | |
| 449 | /** |
| 450 | * @param array $excludeGlobRules |
| 451 | * @return void |
| 452 | */ |
| 453 | public function setExcludeGlobRules(array $excludeGlobRules) |
| 454 | { |
| 455 | $this->excludeGlobRules = $excludeGlobRules; |
| 456 | } |
| 457 | |
| 458 | public function getExcludedDirectories(): array |
| 459 | { |
| 460 | return $this->excludedDirectories; |
| 461 | } |
| 462 | |
| 463 | /** |
| 464 | * @param array $excludedDirectories |
| 465 | * @return void |
| 466 | */ |
| 467 | public function setExcludedDirectories(array $excludedDirectories) |
| 468 | { |
| 469 | $this->excludedDirectories = $excludedDirectories; |
| 470 | } |
| 471 | |
| 472 | public function getExtraDirectories(): array |
| 473 | { |
| 474 | return $this->extraDirectories; |
| 475 | } |
| 476 | |
| 477 | /** |
| 478 | * @param array $extraDirectories |
| 479 | * @return void |
| 480 | */ |
| 481 | public function setExtraDirectories(array $extraDirectories) |
| 482 | { |
| 483 | $this->extraDirectories = $extraDirectories; |
| 484 | } |
| 485 | |
| 486 | public function getNetworkClone(): bool |
| 487 | { |
| 488 | return $this->networkClone; |
| 489 | } |
| 490 | |
| 491 | /** |
| 492 | * @param bool $networkClone |
| 493 | * @return void |
| 494 | */ |
| 495 | public function setNetworkClone(bool $networkClone) |
| 496 | { |
| 497 | $this->networkClone = $networkClone; |
| 498 | } |
| 499 | |
| 500 | public function getSourceBlogId(): int |
| 501 | { |
| 502 | return $this->sourceBlogId; |
| 503 | } |
| 504 | |
| 505 | /** |
| 506 | * @param int $sourceBlogId |
| 507 | * @return void |
| 508 | */ |
| 509 | public function setSourceBlogId(int $sourceBlogId) |
| 510 | { |
| 511 | $this->sourceBlogId = $sourceBlogId; |
| 512 | } |
| 513 | |
| 514 | public function getIsCronEnabled(): bool |
| 515 | { |
| 516 | return $this->isCronEnabled; |
| 517 | } |
| 518 | |
| 519 | /** |
| 520 | * @param bool $isCronEnabled |
| 521 | * @return void |
| 522 | */ |
| 523 | public function setIsCronEnabled(bool $isCronEnabled) |
| 524 | { |
| 525 | $this->isCronEnabled = $isCronEnabled; |
| 526 | } |
| 527 | |
| 528 | public function getIsWooSchedulerEnabled(): bool |
| 529 | { |
| 530 | return $this->isWooSchedulerEnabled; |
| 531 | } |
| 532 | |
| 533 | /** |
| 534 | * @param bool $isWooSchedulerEnabled |
| 535 | * @return void |
| 536 | */ |
| 537 | public function setIsWooSchedulerEnabled(bool $isWooSchedulerEnabled) |
| 538 | { |
| 539 | $this->isWooSchedulerEnabled = $isWooSchedulerEnabled; |
| 540 | } |
| 541 | |
| 542 | public function getIsEmailsReminderEnabled(): bool |
| 543 | { |
| 544 | return $this->isEmailsReminderEnabled; |
| 545 | } |
| 546 | |
| 547 | /** |
| 548 | * @param bool $isEmailsReminderEnabled |
| 549 | * @return void |
| 550 | */ |
| 551 | public function setIsEmailsReminderEnabled(bool $isEmailsReminderEnabled) |
| 552 | { |
| 553 | $this->isEmailsReminderEnabled = $isEmailsReminderEnabled; |
| 554 | } |
| 555 | |
| 556 | public function getOwnerId(): int |
| 557 | { |
| 558 | return $this->ownerId; |
| 559 | } |
| 560 | |
| 561 | /** |
| 562 | * @param int $ownerId |
| 563 | * @return void |
| 564 | */ |
| 565 | public function setOwnerId(int $ownerId) |
| 566 | { |
| 567 | $this->ownerId = $ownerId; |
| 568 | } |
| 569 | |
| 570 | public function getUseNewAdminAccount(): bool |
| 571 | { |
| 572 | return $this->useNewAdminAccount; |
| 573 | } |
| 574 | |
| 575 | /** |
| 576 | * @param bool $useNewAdminAccount |
| 577 | * @return void |
| 578 | */ |
| 579 | public function setUseNewAdminAccount(bool $useNewAdminAccount) |
| 580 | { |
| 581 | $this->useNewAdminAccount = $useNewAdminAccount; |
| 582 | } |
| 583 | |
| 584 | public function getAdminEmail(): string |
| 585 | { |
| 586 | return $this->adminEmail; |
| 587 | } |
| 588 | |
| 589 | /** |
| 590 | * @param string $adminEmail |
| 591 | * @return void |
| 592 | */ |
| 593 | public function setAdminEmail(string $adminEmail) |
| 594 | { |
| 595 | $this->adminEmail = $adminEmail; |
| 596 | } |
| 597 | |
| 598 | public function getAdminPassword(): string |
| 599 | { |
| 600 | return $this->adminPassword; |
| 601 | } |
| 602 | |
| 603 | /** |
| 604 | * @param string $adminPassword |
| 605 | * @return void |
| 606 | */ |
| 607 | public function setAdminPassword(string $adminPassword) |
| 608 | { |
| 609 | $this->adminPassword = $adminPassword; |
| 610 | } |
| 611 | |
| 612 | public function getExcludedDirs(): array |
| 613 | { |
| 614 | return $this->excludedDirs; |
| 615 | } |
| 616 | |
| 617 | /** |
| 618 | * @param array $excludedDirs |
| 619 | * @return void |
| 620 | */ |
| 621 | public function setExcludedDirs(array $excludedDirs) |
| 622 | { |
| 623 | $this->excludedDirs = $excludedDirs; |
| 624 | } |
| 625 | |
| 626 | /** |
| 627 | * @return array|false |
| 628 | */ |
| 629 | public function getTablePushSelection() |
| 630 | { |
| 631 | return $this->tablePushSelection; |
| 632 | } |
| 633 | |
| 634 | /** |
| 635 | * @param array|false $tablePushSelection |
| 636 | * @return void |
| 637 | */ |
| 638 | public function setTablePushSelection($tablePushSelection) |
| 639 | { |
| 640 | $this->tablePushSelection = $tablePushSelection; |
| 641 | } |
| 642 | |
| 643 | public function getSiteName(): string |
| 644 | { |
| 645 | return empty($this->cloneName) ? $this->directoryName : $this->cloneName; |
| 646 | } |
| 647 | |
| 648 | public function getIsCustomDatabaseConnection(): bool |
| 649 | { |
| 650 | return !empty($this->databaseDatabase) && !empty($this->databaseUser); |
| 651 | } |
| 652 | |
| 653 | public function getIsExternalDatabase(): bool |
| 654 | { |
| 655 | return $this->getIsCustomDatabaseConnection() |
| 656 | && ($this->getDatabaseName() !== DB_NAME |
| 657 | || $this->getDatabaseServer() !== DB_HOST); |
| 658 | } |
| 659 | |
| 660 | public function getOwnerName(): string |
| 661 | { |
| 662 | if (empty($this->ownerId)) { |
| 663 | return 'N/A'; |
| 664 | } |
| 665 | |
| 666 | $owner = get_userdata($this->ownerId); |
| 667 | if (empty($owner)) { |
| 668 | return 'N/A'; |
| 669 | } |
| 670 | |
| 671 | return isset($owner->user_login) ? $owner->user_login : 'N/A'; |
| 672 | } |
| 673 | |
| 674 | /** |
| 675 | * Current Production Site Database Name if no external database is used, |
| 676 | * otherwise external database name. |
| 677 | * |
| 678 | * @return string |
| 679 | */ |
| 680 | public function getDatabaseName(): string |
| 681 | { |
| 682 | return empty($this->databaseDatabase) ? DB_NAME : $this->databaseDatabase; |
| 683 | } |
| 684 | |
| 685 | /** |
| 686 | * If current production database, return value from $this->prefix, |
| 687 | * otherwise return value from $this->databasePrefix. |
| 688 | * |
| 689 | * @return string |
| 690 | */ |
| 691 | public function getUsedPrefix(): string |
| 692 | { |
| 693 | return $this->getIsExternalDatabase() ? $this->getDatabasePrefix() : $this->getPrefix(); |
| 694 | } |
| 695 | |
| 696 | /** |
| 697 | * @param bool $isAutoUpdatePlugins |
| 698 | * @return void |
| 699 | */ |
| 700 | public function setIsAutoUpdatePlugins(bool $isAutoUpdatePlugins) |
| 701 | { |
| 702 | $this->isAutoUpdatePlugins = $isAutoUpdatePlugins; |
| 703 | } |
| 704 | |
| 705 | /** |
| 706 | * @return bool |
| 707 | */ |
| 708 | public function getIsAutoUpdatePlugins(): bool |
| 709 | { |
| 710 | return $this->isAutoUpdatePlugins; |
| 711 | } |
| 712 | |
| 713 | public function getIsUploadsSymlink(): bool |
| 714 | { |
| 715 | $uploadsDirectory = $this->getPath() . '/wp-content/uploads'; |
| 716 | |
| 717 | return is_link($uploadsDirectory); |
| 718 | } |
| 719 | |
| 720 | /** |
| 721 | * Set whether uploads should be symlinked (used during staging creation) |
| 722 | * @param bool $isUploadsSymlink |
| 723 | * @return void |
| 724 | */ |
| 725 | public function setIsUploadsSymlink(bool $isUploadsSymlink) |
| 726 | { |
| 727 | $this->uploadsSymlinked = $isUploadsSymlink; |
| 728 | } |
| 729 | |
| 730 | /** |
| 731 | * Check if this staging site was created from a multisite subsite |
| 732 | * @return bool |
| 733 | */ |
| 734 | public function isFromSubsite(): bool |
| 735 | { |
| 736 | return $this->sourceBlogId > 1; |
| 737 | } |
| 738 | } |
| 739 |