class-wpml-tm-icl20-migration-factory.php
3.6 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
/**
* @author OnTheGo Systems
*/
class WPML_TM_ICL20_Migration_Factory {
/**
* @var WPML_TM_ICL20_Migration_Notices
*/
private $notices;
/**
* @var WPML_TM_ICL20_Migration_Progress
*/
private $progress;
/**
* @var WPML_TM_ICL20_Migration_Status
*/
private $status;
/**
* @var WPML_TP_Services
*/
private $tp_services;
/**
* @var WP_Http
*/
private $wp_http;
/**
* @return WPML_TM_ICL20_Migration_AJAX
*/
public function create_ajax() {
return new WPML_TM_ICL20_Migration_AJAX( $this->create_progress() );
}
/**
* @return WPML_TM_ICL20_Migration_Locks
*/
public function create_locks() {
return new WPML_TM_ICL20_Migration_Locks( $this->create_progress() );
}
/**
* @return WPML_TM_ICL20_Migration_Progress
*/
public function create_progress() {
if ( null === $this->progress ) {
$this->progress = new WPML_TM_ICL20_Migration_Progress();
}
return $this->progress;
}
/**
* @return WPML_TM_ICL20_Migrate
*/
public function create_migration() {
return new WPML_TM_ICL20_Migrate(
$this->create_progress(),
$this->create_status(),
$this->get_remote_migration(),
$this->get_local_migration(),
$this->get_tp_services()
);
}
/**
* @return WPML_TM_ICL20_Migration_Status
*/
public function create_status() {
if ( null === $this->status ) {
$current_service = $this->get_tp_services()->get_current_service();
$this->status = new WPML_TM_ICL20_Migration_Status( $current_service );
}
return $this->status;
}
/**
* @return WPML_TM_ICL20_Migrate_Remote
*/
private function get_remote_migration() {
$http = $this->get_wp_http();
$token = new WPML_TM_ICL20_Token( $http, ICL_API_ENDPOINT );
$project = new WPML_TM_ICL20_Project( $http, OTG_TRANSLATION_PROXY_URL );
$ack = new WPML_TM_ICL20_Acknowledge( $http, ICL_API_ENDPOINT );
$container = new WPML_TM_ICL20_Migration_Container( $token, $project, $ack );
return new WPML_TM_ICL20_Migrate_Remote( $this->create_progress(), $container );
}
/**
* @return WPML_TM_ICL20_Migrate_Local
*/
private function get_local_migration() {
return new WPML_TM_ICL20_Migrate_Local(
$this->get_tp_services(),
$this->create_status(),
$this->create_progress(),
$this->get_sitepress()
);
}
/**
* @return WPML_TP_Services
*/
private function get_tp_services() {
if ( null === $this->tp_services ) {
$this->tp_services = new WPML_TP_Services();
}
return $this->tp_services;
}
/**
* @return WP_Http
*/
private function get_wp_http() {
if ( null === $this->wp_http ) {
$this->wp_http = new WP_Http();
}
return $this->wp_http;
}
/**
* @return SitePress
*/
private function get_sitepress() {
global $sitepress;
return $sitepress;
}
/**
* @return WPML_TM_ICL20_Migration_Notices
*/
public function create_notices() {
if ( null === $this->notices ) {
$this->notices = new WPML_TM_ICL20_Migration_Notices( $this->create_progress(), wpml_get_admin_notices() );
}
return $this->notices;
}
/**
* @return WPML_TM_ICL20_Migration_Support
*/
public function create_ui_support() {
$template_paths = array(
WPML_TM_PATH . '/templates/support/icl20/migration/',
);
$template_loader = new WPML_Twig_Template_Loader( $template_paths );
$template_service = $template_loader->get_template();
return new WPML_TM_ICL20_Migration_Support( $template_service, $this->create_progress(), $this->can_rollback() );
}
/**
* @return bool
*/
public function can_rollback() {
return defined( 'WP_DEBUG' )
&& defined( 'WPML_TP_ICL_20_ENABLE_ROLLBACK' )
&& WP_DEBUG
&& WPML_TP_ICL_20_ENABLE_ROLLBACK;
}
}