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 / Backup / Task / FileBackupTask.php
wp-staging / Backup / Task Last commit date
Tasks 1 day ago BackupTask.php 1 day ago FileBackupTask.php 1 day ago FileRestoreTask.php 1 day ago RestoreTask.php 1 day ago
FileBackupTask.php
95 lines
1 <?php
2
3
4
5
6
7
8
9
10 namespace WPStaging\Backup\Task;
11
12 use WPStaging\Backup\Service\FileBackupService;
13 use WPStaging\Backup\Service\FileBackupServiceProvider;
14 use WPStaging\Backup\Task\BackupTask;
15 use WPStaging\Framework\Job\Dto\StepsDto;
16 use WPStaging\Framework\Job\Dto\TaskResponseDto;
17 use WPStaging\Framework\Queue\SeekableQueueInterface;
18 use WPStaging\Framework\Utils\Cache\Cache;
19 use WPStaging\Vendor\Psr\Log\LoggerInterface;
20
21 abstract class FileBackupTask extends BackupTask
22 {
23
24
25
26 const TRANSIENT_GRACEFUL_SHUTDOWN = 'wpstg_file_backup_task';
27
28
29 protected $fileBackupService;
30
31 public function __construct(FileBackupServiceProvider $fileBackupServiceProvider, LoggerInterface $logger, Cache $cache, StepsDto $stepsDto, SeekableQueueInterface $taskQueue)
32 {
33 parent::__construct($logger, $cache, $stepsDto, $taskQueue);
34 $this->fileBackupService = $fileBackupServiceProvider->getService(); // @phpstan-ignore-line
35 }
36
37 public static function getTaskName(): string
38 {
39 return 'backup_file_task';
40 }
41
42 public static function getTaskTitle(): string
43 {
44 return 'Adding Files to Backup';
45 }
46
47 public function execute(): TaskResponseDto
48 {
49 $this->prepareFileBackupTask();
50 set_transient(self::TRANSIENT_GRACEFUL_SHUTDOWN, '1', 60);
51 $this->fileBackupService->setupArchiver($this->getFileIdentifier(), $this->isOtherWpRootFilesTask());
52 $this->fileBackupService->execute();
53
54 delete_transient(self::TRANSIENT_GRACEFUL_SHUTDOWN);
55 return $this->generateResponse(false);
56 }
57
58
59 abstract protected function getFileIdentifier(): string;
60
61
62
63
64 private function prepareFileBackupTask()
65 {
66 $this->fileBackupService->inject($this, $this->taskQueue, $this->logger, $this->jobDataDto, $this->stepsDto);
67 if ($this->stepsDto->getTotal() > 0) {
68 $this->checkIfLastRequestGracefulShutdown();
69 return;
70 }
71
72 $this->stepsDto->setTotal($this->jobDataDto->getDiscoveredFilesByCategory($this->getFileIdentifier()));
73 }
74
75
76
77
78 protected function isOtherWpRootFilesTask(): bool
79 {
80 return false;
81 }
82
83 protected function checkIfLastRequestGracefulShutdown()
84 {
85 $transient = get_transient(self::TRANSIENT_GRACEFUL_SHUTDOWN);
86
87 if (empty($transient)) {
88 return;
89 }
90
91 $this->logger->debug('Resuming file backup task after a non-graceful shutdown.');
92 $this->fileBackupService->setIsGracefulShutdown(false);
93 }
94 }
95