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