PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.11.0
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.11.0
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 / Staging / Tasks / FileCopierTask.php
wp-staging / Staging / Tasks Last commit date
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