Cleaners
5 years ago
Exceptions
5 years ago
Cancel.php
2 years ago
CancelUpdate.php
2 years ago
Cloning.php
2 years ago
CloningProcess.php
2 years ago
Data.php
2 years ago
Database.php
2 years ago
Delete.php
2 years ago
Directories.php
2 years ago
Files.php
2 years ago
Finish.php
2 years ago
Job.php
2 years ago
JobExecutable.php
2 years ago
Logs.php
3 years ago
PreserveDataFirstStep.php
3 years ago
PreserveDataSecondStep.php
3 years ago
ProcessLock.php
2 years ago
Scan.php
2 years ago
SearchReplace.php
2 years ago
TotalStepsAreNumberOfTables.php
5 years ago
Updating.php
2 years ago
CancelUpdate.php
103 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Backend\Modules\Jobs; |
| 4 | |
| 5 | use WPStaging\Framework\Analytics\AnalyticsEventDto; |
| 6 | |
| 7 | /** |
| 8 | * Class Cancel Update Processing |
| 9 | * @package WPStaging\Backend\Modules\Jobs |
| 10 | */ |
| 11 | class CancelUpdate extends Job |
| 12 | { |
| 13 | |
| 14 | /** |
| 15 | * Start Module |
| 16 | * @return bool |
| 17 | */ |
| 18 | public function start() |
| 19 | { |
| 20 | $cloneData = $this->createCloneData(); |
| 21 | |
| 22 | if (!empty($this->options->jobIdentifier)) { |
| 23 | AnalyticsEventDto::enqueueCancelEvent($this->options->jobIdentifier); |
| 24 | } |
| 25 | |
| 26 | if (empty($cloneData)) { |
| 27 | return true; |
| 28 | } |
| 29 | |
| 30 | // Delete Cache Files |
| 31 | $this->deleteCacheFiles(); |
| 32 | |
| 33 | $this->returnFinish(); |
| 34 | |
| 35 | return true; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @return array |
| 40 | */ |
| 41 | protected function createCloneData() |
| 42 | { |
| 43 | $clone = []; |
| 44 | |
| 45 | if (!$this->check()) { |
| 46 | return $clone; |
| 47 | } |
| 48 | |
| 49 | $clone["name"] = $this->options->clone; |
| 50 | $clone["number"] = $this->options->cloneNumber; |
| 51 | $clone["path"] = ABSPATH . $this->options->cloneDirectoryName; |
| 52 | $clone["prefix"] = ABSPATH . $this->options->prefix; |
| 53 | |
| 54 | return $clone; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * @return bool |
| 59 | */ |
| 60 | public function check() |
| 61 | { |
| 62 | return ( |
| 63 | isset($this->options) && |
| 64 | isset($this->options->clone) && |
| 65 | isset($this->options->cloneNumber) && |
| 66 | isset($this->options->cloneDirectoryName) && |
| 67 | isset($_POST["clone"]) && |
| 68 | $_POST["clone"] === $this->options->clone |
| 69 | ); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Get json response |
| 74 | * return json |
| 75 | */ |
| 76 | private function returnFinish($message = '') |
| 77 | { |
| 78 | |
| 79 | wp_die(json_encode([ |
| 80 | 'job' => 'delete', |
| 81 | 'status' => true, |
| 82 | 'message' => $message, |
| 83 | 'error' => false, |
| 84 | 'delete' => 'finished' |
| 85 | ])); |
| 86 | } |
| 87 | |
| 88 | |
| 89 | /** |
| 90 | * Delete Cache Files |
| 91 | */ |
| 92 | protected function deleteCacheFiles() |
| 93 | { |
| 94 | $this->log("Cancel Updating: Deleting clone job's cache files..."); |
| 95 | |
| 96 | // Clean cache files |
| 97 | $this->cloneOptionCache->delete(); |
| 98 | $this->filesIndexCache->delete(); |
| 99 | |
| 100 | $this->log("Updating process canceled"); |
| 101 | } |
| 102 | } |
| 103 |