Cleaners
3 months ago
Exceptions
5 years ago
Cancel.php
6 months ago
CancelUpdate.php
6 months ago
Cloning.php
1 week ago
CloningProcess.php
1 year ago
Data.php
6 months ago
Database.php
3 months ago
Delete.php
4 months ago
Directories.php
4 months ago
Files.php
2 months ago
Finish.php
2 months ago
Job.php
1 week ago
JobExecutable.php
6 months ago
Logs.php
3 years ago
PreserveDataFirstStep.php
1 month ago
PreserveDataSecondStep.php
1 month ago
ProcessLock.php
1 year ago
Scan.php
4 months ago
SearchReplace.php
5 months ago
TotalStepsAreNumberOfTables.php
5 years ago
Updating.php
1 week ago
ProcessLock.php
86 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Backend\Modules\Jobs; |
| 4 | |
| 5 | /** |
| 6 | * Class Cloning |
| 7 | * @package WPStaging\Backend\Modules\Jobs |
| 8 | */ |
| 9 | class ProcessLock extends JobExecutable |
| 10 | { |
| 11 | |
| 12 | /** |
| 13 | * Check if any process is already running |
| 14 | * @return boolean |
| 15 | */ |
| 16 | public function isRunning() |
| 17 | { |
| 18 | // Another process is running |
| 19 | if (parent::isRunning()) { |
| 20 | $this->log("Another process is running"); |
| 21 | |
| 22 | $message = __('Hold on, another WP STAGING process is already running...', 'wp-staging'); |
| 23 | |
| 24 | require_once WPSTG_VIEWS_DIR . "clone/ajax/process-lock.php"; |
| 25 | |
| 26 | wp_die(); |
| 27 | } |
| 28 | |
| 29 | // No other process running |
| 30 | |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Check if any process is already running, if running return a json encoded response for Swal Modal, |
| 36 | * Otherwise return false |
| 37 | * |
| 38 | * @return false|array |
| 39 | */ |
| 40 | public function ajaxIsRunning() |
| 41 | { |
| 42 | if (parent::isRunning()) { |
| 43 | return [ |
| 44 | 'success' => false, |
| 45 | 'type' => 'processLock', |
| 46 | // TODO: Create a Swal Response Class and Js library to handle that response or, Implement own Swal alternative |
| 47 | 'swalOptions' => [ |
| 48 | 'title' => __('Error!', 'wp-staging'), |
| 49 | 'html' => __('Hold on, another WP STAGING process is already running...', 'wp-staging'), |
| 50 | 'confirmButtonText' => __('Stop other process', 'wp-staging'), |
| 51 | 'showCancelButton' => true, |
| 52 | ], |
| 53 | ]; |
| 54 | } |
| 55 | |
| 56 | return false; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * remove process lock value |
| 61 | */ |
| 62 | public function restart() |
| 63 | { |
| 64 | unset($this->options->isRunning); |
| 65 | $this->cloneOptionCache->delete(); |
| 66 | $this->filesIndexCache->delete(); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * abstract |
| 71 | * @return void |
| 72 | */ |
| 73 | protected function calculateTotalSteps() |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * abstract |
| 79 | * @return bool |
| 80 | */ |
| 81 | protected function execute() |
| 82 | { |
| 83 | return false; |
| 84 | } |
| 85 | } |
| 86 |