1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* The Jetpack Connection error class file. |
4
|
|
|
* |
5
|
|
|
* @package automattic/jetpack-connection |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Automattic\Jetpack\Connection; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* The Jetpack Connection Errors that handles errors |
12
|
|
|
*/ |
13
|
|
|
class Errors { |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Return the code and details of all known errors. |
17
|
|
|
* |
18
|
|
|
* @return array |
19
|
|
|
*/ |
20
|
|
|
public function get_errors() { |
21
|
|
|
|
22
|
|
|
$errors = array( |
23
|
|
|
array( |
24
|
|
|
'code' => 'unknown_error', |
25
|
|
|
'title' => __( 'Unknown connection error', 'jetpack' ), |
26
|
|
|
'fix_tip' => __( 'Unknown connection error', 'jetpack' ), |
27
|
|
|
'fix_url' => '', |
28
|
|
|
'fix_callback' => null, |
29
|
|
|
), |
30
|
|
|
|
31
|
|
|
array( |
32
|
|
|
'code' => 'malformed_token', |
33
|
|
|
'title' => __( 'Malformed token', 'jetpack' ), |
34
|
|
|
'fix_tip' => __( 'The token used to authenticate requests between your site and WordPress.com is invalid. Try resetting the connection', 'jetpack' ), |
35
|
|
|
'fix_url' => '', // The URL of a call to action button to fix it. |
36
|
|
|
'fix_label' => 'Reconnect', // The label of a call to action button to fix it. |
37
|
|
|
'fix_callback' => array( $this, 'fix_disconnect' ), // a callback that will be invoked to try to fix the issue locally. |
38
|
|
|
), |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
return apply_filters( 'jetpack_connection_errors', $errors ); |
42
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Gets the details for one specific error code |
47
|
|
|
* |
48
|
|
|
* @param string $error_code the error code. |
49
|
|
|
* @return array $error the error details |
50
|
|
|
*/ |
51
|
|
|
public function get_error( $error_code ) { |
52
|
|
|
$errors = $this->get_errors(); |
53
|
|
|
return isset( $errors[ $error_code ] ) ? $errors[ $error_code ] : $errors['unknow_error']; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Keep track of a connection error that was encoutered |
58
|
|
|
* |
59
|
|
|
* @param Connection_Error $error the error object. |
60
|
|
|
* @return void |
61
|
|
|
*/ |
62
|
|
|
public function report_error( Connection_Error $error ) { |
63
|
|
|
$this->store_error( $error ); |
64
|
|
|
$this->inform_wpcom( $error ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Stores the error in the database so we know there is an issue and can inform the user |
69
|
|
|
* |
70
|
|
|
* @param Connection_Error $error the error object. |
71
|
|
|
* @return void |
72
|
|
|
*/ |
73
|
|
|
public function store_error( Connection_Error $error ) { |
74
|
|
|
// store the error on the database so we can display feedback to the user. |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Informs wpcom servers about the error |
79
|
|
|
* |
80
|
|
|
* @param Connection_Error $error the error object. |
81
|
|
|
* @return void |
82
|
|
|
*/ |
83
|
|
|
public function inform_wpcom( Connection_Error $error ) { |
84
|
|
|
// securely inform wpcom about the error (via sync?) so Calypso knows about it and it can trigger some self-healing routine. |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Gets the reported errors stored in the database |
89
|
|
|
* |
90
|
|
|
* @return array $errors |
91
|
|
|
*/ |
92
|
|
|
public function get_stored_errors() { |
93
|
|
|
// retireve errors from the database |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Delete the reported errors stored in the database |
98
|
|
|
* |
99
|
|
|
* @return array $errors |
100
|
|
|
*/ |
101
|
|
|
public function delete_stored_errors() { |
102
|
|
|
// delete errors from the database |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Tries to fix connection errors by disconnecting the site |
107
|
|
|
* |
108
|
|
|
* After disconnecting, clear the reported errors. |
109
|
|
|
* |
110
|
|
|
* @return void |
111
|
|
|
*/ |
112
|
|
|
public function fix_disconnect() { |
113
|
|
|
// calls the manager disconnect routine |
114
|
|
|
|
115
|
|
|
$this->delete_stored_errors(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
} |
119
|
|
|
|