RestoreFileHandlers
2 years ago
Tasks
2 years ago
AbstractTask.php
2 years ago
BackupTask.php
2 years ago
FileBackupTask.php
2 years ago
FileRestoreTask.php
2 years ago
RestoreTask.php
2 years ago
FileBackupTask.php
73 lines
| 1 | <?php |
| 2 | |
| 3 | // TODO PHP7.1; constant visibility |
| 4 | |
| 5 | namespace WPStaging\Backup\Task; |
| 6 | |
| 7 | use WPStaging\Backup\Dto\StepsDto; |
| 8 | use WPStaging\Backup\Dto\TaskResponseDto; |
| 9 | use WPStaging\Backup\Service\FileBackupService; |
| 10 | use WPStaging\Backup\Service\FileBackupServiceProvider; |
| 11 | use WPStaging\Backup\Task\BackupTask; |
| 12 | use WPStaging\Framework\Queue\SeekableQueueInterface; |
| 13 | use WPStaging\Framework\Utils\Cache\Cache; |
| 14 | use WPStaging\Vendor\Psr\Log\LoggerInterface; |
| 15 | |
| 16 | abstract class FileBackupTask extends BackupTask |
| 17 | { |
| 18 | /** @var string */ |
| 19 | const OTHER_WP_ROOT_IDENTIFIER = 'rootfiles'; |
| 20 | |
| 21 | /** @var FileBackupService */ |
| 22 | protected $fileBackupService; |
| 23 | |
| 24 | public function __construct(FileBackupServiceProvider $fileBackupServiceProvider, LoggerInterface $logger, Cache $cache, StepsDto $stepsDto, SeekableQueueInterface $taskQueue) |
| 25 | { |
| 26 | parent::__construct($logger, $cache, $stepsDto, $taskQueue); |
| 27 | $this->fileBackupService = $fileBackupServiceProvider->getService(); // @phpstan-ignore-line |
| 28 | } |
| 29 | |
| 30 | public static function getTaskName(): string |
| 31 | { |
| 32 | return 'backup_file_task'; |
| 33 | } |
| 34 | |
| 35 | public static function getTaskTitle(): string |
| 36 | { |
| 37 | return 'Adding Files to Backup'; |
| 38 | } |
| 39 | |
| 40 | public function execute(): TaskResponseDto |
| 41 | { |
| 42 | $this->prepareFileBackupTask(); |
| 43 | $this->fileBackupService->setupArchiver($this->getFileIdentifier(), $this->isOtherWpRootFilesTask()); |
| 44 | $this->fileBackupService->execute(); |
| 45 | |
| 46 | return $this->generateResponse(false); |
| 47 | } |
| 48 | |
| 49 | /** @return string */ |
| 50 | abstract protected function getFileIdentifier(): string; |
| 51 | |
| 52 | /** |
| 53 | * @return void |
| 54 | */ |
| 55 | private function prepareFileBackupTask() |
| 56 | { |
| 57 | $this->fileBackupService->inject($this->taskQueue, $this->logger, $this->jobDataDto, $this->stepsDto); |
| 58 | if ($this->stepsDto->getTotal() > 0) { |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | $this->stepsDto->setTotal($this->jobDataDto->getDiscoveredFilesByCategory($this->getFileIdentifier())); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * @return bool |
| 67 | */ |
| 68 | protected function isOtherWpRootFilesTask(): bool |
| 69 | { |
| 70 | return false; |
| 71 | } |
| 72 | } |
| 73 |