Backup
2 years ago
FileList
2 years ago
Restore
2 years ago
Backup.php
2 years ago
BackupSpeedIndex.php
2 years ago
Cancel.php
3 years ago
Delete.php
3 years ago
Edit.php
2 years ago
FileInfo.php
3 years ago
FileList.php
2 years ago
Listing.php
2 years ago
Parts.php
3 years ago
PrepareJob.php
2 years ago
Restore.php
2 years ago
ScheduleList.php
2 years ago
Status.php
3 years ago
Upload.php
2 years ago
Cancel.php
54 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Backup\Ajax; |
| 4 | |
| 5 | use WPStaging\Core\WPStaging; |
| 6 | use WPStaging\Framework\Analytics\AnalyticsEventDto; |
| 7 | use WPStaging\Framework\Component\AbstractTemplateComponent; |
| 8 | use WPStaging\Framework\TemplateEngine\TemplateEngine; |
| 9 | use WPStaging\Backup\BackupProcessLock; |
| 10 | use WPStaging\Backup\Dto\JobDataDto; |
| 11 | use WPStaging\Backup\Exceptions\ProcessLockedException; |
| 12 | use WPStaging\Backup\Job\Jobs\JobCancel; |
| 13 | |
| 14 | class Cancel extends AbstractTemplateComponent |
| 15 | { |
| 16 | protected $processLock; |
| 17 | |
| 18 | public function __construct(TemplateEngine $templateEngine, BackupProcessLock $processLock) |
| 19 | { |
| 20 | $this->processLock = $processLock; |
| 21 | |
| 22 | parent::__construct($templateEngine); |
| 23 | } |
| 24 | |
| 25 | public function render() |
| 26 | { |
| 27 | if (!$this->canRenderAjax()) { |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | try { |
| 32 | $this->processLock->checkProcessLocked(); |
| 33 | } catch (ProcessLockedException $e) { |
| 34 | wp_send_json_error($e->getMessage(), $e->getCode()); |
| 35 | } |
| 36 | |
| 37 | /** @var JobCancel $job */ |
| 38 | $job = WPStaging::getInstance()->get(JobCancel::class); |
| 39 | |
| 40 | if (isset($_POST['isInit']) && sanitize_text_field($_POST['isInit']) === 'yes') { |
| 41 | $jobDataDto = WPStaging::getInstance()->getContainer()->make(JobDataDto::class); |
| 42 | $jobDataDto->setInit(true); |
| 43 | $jobDataDto->setId(substr(md5(mt_rand() . time()), 0, 12)); |
| 44 | $job->setJobDataDto($jobDataDto); |
| 45 | |
| 46 | $jobId = isset($_POST['jobIdBeingCancelled']) ? html_entity_decode(sanitize_text_field($_POST['jobIdBeingCancelled'])) : ''; |
| 47 | |
| 48 | AnalyticsEventDto::enqueueCancelEvent($jobId); |
| 49 | } |
| 50 | |
| 51 | wp_send_json($job->prepareAndExecute()); |
| 52 | } |
| 53 | } |
| 54 |