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
1 year ago
Job.php
2 years ago
JobExecutable.php
2 years ago
Logs.php
3 years ago
PreserveDataFirstStep.php
3 years ago
PreserveDataSecondStep.php
2 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
Cancel.php
93 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Backend\Modules\Jobs; |
| 4 | |
| 5 | use WPStaging\Core\WPStaging; |
| 6 | use WPStaging\Framework\Analytics\AnalyticsEventDto; |
| 7 | |
| 8 | /** |
| 9 | * Class Cancel Processing |
| 10 | * @package WPStaging\Backend\Modules\Jobs |
| 11 | */ |
| 12 | class Cancel extends Job |
| 13 | { |
| 14 | |
| 15 | /** |
| 16 | * Start Module |
| 17 | * @return bool |
| 18 | */ |
| 19 | public function start() |
| 20 | { |
| 21 | $cloneData = $this->createCloneData(); |
| 22 | |
| 23 | if (!empty($this->options->jobIdentifier)) { |
| 24 | AnalyticsEventDto::enqueueCancelEvent($this->options->jobIdentifier); |
| 25 | } |
| 26 | |
| 27 | if (empty($cloneData)) { |
| 28 | return true; |
| 29 | } |
| 30 | |
| 31 | $deleteJob = WPStaging::make(Delete::class); |
| 32 | $deleteJob->setIsExternalDb(!$this->isStagingDatabaseSameAsProductionDatabase()); |
| 33 | |
| 34 | return $deleteJob->start($cloneData); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * @return array |
| 39 | */ |
| 40 | protected function createCloneData() |
| 41 | { |
| 42 | $clone = []; |
| 43 | |
| 44 | if (!$this->check()) { |
| 45 | return $clone; |
| 46 | } |
| 47 | |
| 48 | $clone["name"] = $this->options->clone; |
| 49 | $clone["number"] = $this->options->cloneNumber; |
| 50 | $clone["path"] = ABSPATH . $this->options->cloneDirectoryName; |
| 51 | $clone["prefix"] = $this->options->prefix; |
| 52 | $clone["databaseServer"] = $this->options->databaseServer; |
| 53 | $clone["databaseUser"] = $this->options->databaseUser; |
| 54 | $clone["databasePassword"] = $this->options->databasePassword; |
| 55 | $clone["databasePrefix"] = $this->options->databasePrefix; |
| 56 | $clone["databaseDatabase"] = $this->options->databaseDatabase; |
| 57 | $clone["databaseSsl"] = $this->options->databaseSsl; |
| 58 | |
| 59 | return $clone; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @return bool |
| 64 | */ |
| 65 | public function check() |
| 66 | { |
| 67 | return ( |
| 68 | isset($this->options) && |
| 69 | isset($this->options->clone) && |
| 70 | isset($this->options->cloneNumber) && |
| 71 | isset($this->options->cloneDirectoryName) && |
| 72 | isset($_POST["clone"]) && |
| 73 | $_POST["clone"] === $this->options->clone |
| 74 | ); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Get json response |
| 79 | * return json |
| 80 | */ |
| 81 | private function returnFinish($message = '') |
| 82 | { |
| 83 | |
| 84 | wp_die(json_encode([ |
| 85 | 'job' => 'delete', |
| 86 | 'status' => true, |
| 87 | 'message' => $message, |
| 88 | 'error' => false, |
| 89 | 'delete' => 'finished' |
| 90 | ])); |
| 91 | } |
| 92 | } |
| 93 |