PluginProbe
WP Synchro – The Ultimate WordPress Migration Tool / trunk
WP Synchro – The Ultimate WordPress Migration Tool vtrunk
1.16.1 1.16.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.10.0 1.11.0 1.11.1 1.11.2 1.11.3 1.11.4 1.11.5 1.12.0 1.13.0 1.14.0 1.15.0 1.2.0 1.3.0 1.3.1 1.3.2 All 45 releases
wpsynchro / src / API / Migrate.php

Migrate.php in WP Synchro – The Ultimate WordPress Migration Tool trunk, at src/API/Migrate.php

61 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPSynchro\API;
4
5 use WPSynchro\Migration\MigrationController;
6
7 /**
8 * Class for handling service "migrate"
9 * Call should already be verified by permissions callback
10 *
11 */
12 class Migrate extends WPSynchroService
13 {
14 public function service()
15 {
16 // Extract parameters
17 $body = $this->getRequestBody();
18 $parameters = json_decode($body);
19
20 if (isset($parameters->migration_id)) {
21 $migration_id = $parameters->migration_id;
22 } else {
23 $migration_id = '';
24 }
25 if (isset($parameters->job_id)) {
26 $job_id = $parameters->job_id;
27 } else {
28 $job_id = '';
29 }
30 if (isset($parameters->migration_restart)) {
31 $migration_restart = filter_var($parameters->migration_restart, FILTER_VALIDATE_BOOLEAN);
32 } else {
33 $migration_restart = false;
34 }
35
36 $migrate = MigrationController::getInstance();
37 $migrate->setup($migration_id, $job_id);
38
39 // If we should restart a failed migration and try to continue
40 if ($migration_restart) {
41 $migrate->attemptMigrationResume();
42 }
43
44 $sync_response = $migrate->runMigration();
45
46 if (isset($sync_response->errors) && count($sync_response->errors) > 0) {
47 // Set that we should not continue migration from frontend JS
48 $sync_response->should_continue = false;
49 } else {
50 // Set to frontend to continue migration
51 $sync_response->should_continue = true;
52 }
53
54 if (isset($sync_response->is_completed) && $sync_response->is_completed === true) {
55 $sync_response->should_continue = false;
56 }
57
58 echo json_encode($sync_response);
59 }
60 }
61