FinishStagingSiteDeleteTask.php
72 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Staging\Tasks\StagingSiteDelete; |
| 4 | |
| 5 | use WPStaging\Framework\Queue\SeekableQueueInterface; |
| 6 | use WPStaging\Framework\Job\Dto\StepsDto; |
| 7 | use WPStaging\Framework\Job\Dto\TaskResponseDto; |
| 8 | use WPStaging\Framework\Utils\Cache\Cache; |
| 9 | use WPStaging\Staging\Dto\Job\StagingSiteDeleteDataDto; |
| 10 | use WPStaging\Staging\Sites; |
| 11 | use WPStaging\Staging\Tasks\StagingTask; |
| 12 | use WPStaging\Vendor\Psr\Log\LoggerInterface; |
| 13 | |
| 14 | class FinishStagingSiteDeleteTask extends StagingTask |
| 15 | { |
| 16 | /** @var StagingSiteDeleteDataDto */ |
| 17 | protected $jobDataDto; |
| 18 | |
| 19 | /** @var Sites */ |
| 20 | private $sites; |
| 21 | |
| 22 | /** |
| 23 | * @param LoggerInterface $logger |
| 24 | * @param Cache $cache |
| 25 | * @param StepsDto $stepsDto |
| 26 | * @param SeekableQueueInterface $taskQueue |
| 27 | * @param Sites $sites |
| 28 | */ |
| 29 | public function __construct(LoggerInterface $logger, Cache $cache, StepsDto $stepsDto, SeekableQueueInterface $taskQueue, Sites $sites) |
| 30 | { |
| 31 | parent::__construct($logger, $cache, $stepsDto, $taskQueue); |
| 32 | $this->sites = $sites; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @return string |
| 37 | */ |
| 38 | public static function getTaskName() |
| 39 | { |
| 40 | return 'staging_finish_delete'; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @return string |
| 45 | */ |
| 46 | public static function getTaskTitle() |
| 47 | { |
| 48 | return 'Finish Staging Site Delete'; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @return TaskResponseDto |
| 53 | */ |
| 54 | public function execute() |
| 55 | { |
| 56 | $this->getJobTransientCache()->completeJob(); |
| 57 | $stagingSite = $this->jobDataDto->getStagingSite(); |
| 58 | $stagingSites = $this->sites->tryGettingStagingSites(); |
| 59 | if (isset($stagingSites[$this->jobDataDto->getCloneId()])) { |
| 60 | unset($stagingSites[$this->jobDataDto->getCloneId()]); |
| 61 | $this->sites->updateStagingSites($stagingSites); |
| 62 | } |
| 63 | |
| 64 | $this->logger->info(sprintf( |
| 65 | 'Staging Site "%s" deleted.', |
| 66 | $stagingSite->getSiteName() |
| 67 | )); |
| 68 | |
| 69 | return $this->generateResponse(); |
| 70 | } |
| 71 | } |
| 72 |