@@ -48,7 +48,7 @@ public static function retry_connection() {
48
48
* @return bool
49
49
*/
50
50
private static function create_site () {
51
- if ( ! empty ( get_option ( ' vrts_project_id ' ) ) || ! empty ( get_option ( ' vrts_project_token ' ) ) ) {
51
+ if ( static :: is_connected ( ) ) {
52
52
return ;
53
53
}
54
54
$ time = current_time ( 'mysql ' );
@@ -63,9 +63,17 @@ private static function create_site() {
63
63
'requested_at ' => $ time ,
64
64
];
65
65
66
+ if ( ! empty ( get_option ( 'vrts_project_id ' ) ) && ! empty ( get_option ( 'vrts_project_token ' ) ) ) {
67
+ $ parameters ['project_id ' ] = get_option ( 'vrts_project_id ' );
68
+ $ parameters ['project_token ' ] = get_option ( 'vrts_project_token ' );
69
+ $ parameters ['project_secret ' ] = get_option ( 'vrts_project_secret ' );
70
+ $ parameters ['tests ' ] = Test::get_all_service_test_ids ();
71
+ }
72
+
66
73
$ service_request = self ::rest_service_request ( $ service_api_route , $ parameters , 'post ' );
67
74
68
- if ( 201 === $ service_request ['status_code ' ] ) {
75
+ delete_option ( 'vrts_disconnected ' );
76
+ if ( 201 === $ service_request ['status_code ' ] || 200 === $ service_request ['status_code ' ] ) {
69
77
$ data = $ service_request ['response ' ];
70
78
71
79
update_option ( 'vrts_project_id ' , $ data ['id ' ] );
@@ -77,6 +85,8 @@ private static function create_site() {
77
85
self ::add_homepage_test ();
78
86
79
87
return true ;
88
+ } else {
89
+ update_option ( 'vrts_disconnected ' , 1 );
80
90
}
81
91
return false ;
82
92
}
@@ -311,7 +321,10 @@ public static function fetch_updates() {
311
321
public static function disconnect_service () {
312
322
$ service_project_id = get_option ( 'vrts_project_id ' );
313
323
$ service_api_route = 'sites/ ' . $ service_project_id ;
314
- self ::rest_service_request ( $ service_api_route , [], 'delete ' );
324
+ $ response = self ::rest_service_request ( $ service_api_route , [], 'delete ' );
325
+ if ( 200 === $ response ['status_code ' ] ) {
326
+ update_option ( 'vrts_disconnected ' , 1 );
327
+ }
315
328
}
316
329
317
330
/**
@@ -333,7 +346,7 @@ public static function delete_option() {
333
346
* Check if external service was able to connect
334
347
*/
335
348
public static function is_connected () {
336
- return (bool ) get_option ( 'vrts_project_id ' ) && (bool ) get_option ( 'vrts_project_token ' );
349
+ return ! ( bool ) get_option ( ' vrts_disconnected ' ) && (bool ) get_option ( 'vrts_project_id ' ) && (bool ) get_option ( 'vrts_project_token ' );
337
350
}
338
351
339
352
/**
0 commit comments