StagingSite
1 day ago
StagingSiteCreate
1 day ago
StagingSiteDelete
1 day ago
StagingSiteReset
1 day ago
StagingSiteUpdate
1 day ago
DataAdjustmentTask.php
1 day ago
DatabaseAdjustmentTask.php
1 day ago
FileAdjustmentTask.php
1 day ago
FileCopierTask.php
1 day ago
StagingTask.php
1 day ago
FileCopierTask.php
104 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Staging\Tasks; |
| 4 | |
| 5 | use WPStaging\Framework\Job\Dto\StepsDto; |
| 6 | use WPStaging\Framework\Job\Dto\TaskResponseDto; |
| 7 | use WPStaging\Framework\Job\Interfaces\FilesystemScannerDtoInterface; |
| 8 | use WPStaging\Framework\Queue\SeekableQueueInterface; |
| 9 | use WPStaging\Framework\Utils\Cache\Cache; |
| 10 | use WPStaging\Staging\Dto\Task\FileCopierTaskDto; |
| 11 | use WPStaging\Staging\Interfaces\StagingOperationDtoInterface; |
| 12 | use WPStaging\Staging\Service\FileCopier; |
| 13 | use WPStaging\Vendor\Psr\Log\LoggerInterface; |
| 14 | |
| 15 | abstract class FileCopierTask extends StagingTask |
| 16 | { |
| 17 | |
| 18 | protected $fileCopier; |
| 19 | |
| 20 | |
| 21 | protected $jobDataDto; // @phpstan-ignore-line |
| 22 | |
| 23 | |
| 24 | protected $currentTaskDto; |
| 25 | |
| 26 | public function __construct(FileCopier $fileCopier, LoggerInterface $logger, Cache $cache, StepsDto $stepsDto, SeekableQueueInterface $taskQueue) |
| 27 | { |
| 28 | parent::__construct($logger, $cache, $stepsDto, $taskQueue); |
| 29 | $this->fileCopier = $fileCopier; |
| 30 | } |
| 31 | |
| 32 | public static function getTaskName(): string |
| 33 | { |
| 34 | return 'staging_file_copier_task'; |
| 35 | } |
| 36 | |
| 37 | public static function getTaskTitle(): string |
| 38 | { |
| 39 | return 'Copying Files to Staging Site'; |
| 40 | } |
| 41 | |
| 42 | public function execute(): TaskResponseDto |
| 43 | { |
| 44 | |
| 45 | if ($this->getIsExcluded()) { |
| 46 | return $this->generateResponse(true); |
| 47 | } |
| 48 | |
| 49 | $this->prepareFileCopyingTask(); |
| 50 | |
| 51 | if ($this->stepsDto->getTotal() === 0) { |
| 52 | return $this->generateResponse(true); |
| 53 | } |
| 54 | |
| 55 | $this->fileCopier->setup($this->jobDataDto->getStagingSitePath(), $this->getLoggerFriendlyName(), $this->getIsWpContent()); |
| 56 | $this->fileCopier->execute(); |
| 57 | |
| 58 | $this->currentTaskDto->setBigFileDto($this->fileCopier->getBigFileDto()); |
| 59 | $this->setCurrentTaskDto($this->currentTaskDto); |
| 60 | |
| 61 | return $this->generateResponse(false); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | abstract protected function getFileIdentifier(): string; |
| 66 | |
| 67 | protected function getLoggerFriendlyName(): string |
| 68 | { |
| 69 | return $this->getFileIdentifier(); |
| 70 | } |
| 71 | |
| 72 | |
| 73 | protected function getIsWpContent(): bool |
| 74 | { |
| 75 | return false; |
| 76 | } |
| 77 | |
| 78 | |
| 79 | protected function getIsExcluded(): bool |
| 80 | { |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | |
| 85 | protected function getCurrentTaskType(): string |
| 86 | { |
| 87 | return FileCopierTaskDto::class; |
| 88 | } |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | private function prepareFileCopyingTask() |
| 94 | { |
| 95 | $this->fileCopier->inject($this->taskQueue, $this->logger, $this->stepsDto); |
| 96 | $this->fileCopier->setupBigFileBeingCopied($this->currentTaskDto->getBigFileDto()); |
| 97 | if ($this->stepsDto->getTotal() > 0) { |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | $this->stepsDto->setTotal($this->jobDataDto->getDiscoveredFilesByIdentifier($this->getFileIdentifier())); |
| 102 | } |
| 103 | } |
| 104 |