class-wpml-tm-icl20-migrate-remote.php
3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
class WPML_TM_ICL20_Migrate_Remote {
private $container;
private $progress;
/**
* WPML_TM_ICL20 constructor.
*
* @param WPML_TM_ICL20_Migration_Progress $progress
* @param WPML_TM_ICL20_Migration_Container $container
*/
public function __construct(
WPML_TM_ICL20_Migration_Progress $progress,
WPML_TM_ICL20_Migration_Container $container
) {
$this->progress = $progress;
$this->container = $container;
}
/**
* @param string $ts_accesskey
* @param int $ts_id
*
* @return bool
*
* Note: `ts_id` (aka `website_id`) = `website_id`
*
* @link https://onthegosystems.myjetbrains.com/youtrack/issue/icldev-2322
*/
public function acknowledge_icl( $ts_id, $ts_accesskey ) {
$result = false;
try {
$result = $this->container->get_acknowledge()->acknowledge_icl( $ts_id, $ts_accesskey );
} catch ( WPML_TM_ICL20MigrationException $ex ) {
$this->progress->log_failed_attempt( __METHOD__ . ' - ' . $ex->getCode() . ': ' . $ex->getMessage() );
}
if ( $result ) {
$this->progress->set_completed_step( WPML_TM_ICL20_Migration_Progress::STEP_ICL_ACK, true );
return $result;
}
$this->progress->set_completed_step( WPML_TM_ICL20_Migration_Progress::STEP_ICL_ACK, false );
return false;
}
/**
* @param string $ts_accesskey
* @param int $ts_id
*
* @return string|null
*
* Note: `ts_id` (aka `website_id`) = `website_id`
*
* @link https://onthegosystems.myjetbrains.com/youtrack/issue/icldev-2285
*/
public function get_token( $ts_id, $ts_accesskey ) {
$token = null;
try {
$token = $this->container->get_token()->get_token( $ts_id, $ts_accesskey );
} catch ( WPML_TM_ICL20MigrationException $ex ) {
$this->progress->log_failed_attempt( __METHOD__ . ' - ' . $ex->getCode() . ': ' . $ex->getMessage() );
}
if ( null !== $token ) {
$this->progress->set_completed_step( WPML_TM_ICL20_Migration_Progress::STEP_TOKEN, $token );
return $token;
}
$this->progress->set_completed_step( 'token', false );
return null;
}
/**
* @param int $project_id
* @param string $access_key
* @param string $new_token
*
* @return bool|null
* @link https://onthegosystems.myjetbrains.com/youtrack/issue/tsapi-887
*
*/
public function migrate_project( $project_id, $access_key, $new_token ) {
$migrate = null;
try {
$migrate = $this->container->get_project()->migrate( $project_id, $access_key, $new_token );
} catch ( WPML_TM_ICL20MigrationException $ex ) {
$this->progress->log_failed_attempt( __METHOD__ . ' - ' . $ex->getCode() . ': ' . $ex->getMessage() );
}
if ( $migrate ) {
$this->progress->set_completed_step( WPML_TM_ICL20_Migration_Progress::STEP_MIGRATE_REMOTE_PROJECT, true );
return $migrate;
}
$this->progress->set_completed_step( WPML_TM_ICL20_Migration_Progress::STEP_MIGRATE_REMOTE_PROJECT, false );
return false;
}
/**
* @param int $project_id
* @param string $access_key
*
* @return bool
* @link https://onthegosystems.myjetbrains.com/youtrack/issue/tsapi-887
*
*/
public function migrate_project_rollback( $project_id, $access_key ) {
$result = false;
try {
$result = $this->container->get_project()->rollback_migration( $project_id, $access_key );
} catch ( WPML_TM_ICL20MigrationException $ex ) {
$this->progress->log_failed_attempt( __METHOD__ . ' - ' . $ex->getCode() . ': ' . $ex->getMessage() );
}
return $result;
}
}