class-wizard-systemtest.php
7.05 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
/**
*
*/
class BackWPup_Pro_Wizard_SystemTest extends BackWPup_Pro_Wizards {
/**
*
*/
public function __construct() {
$this->info[ 'ID' ] = 'SYSTEMTEST';
$this->info[ 'name' ] = __( 'System Test', 'backwpup' );
$this->info[ 'description' ] = __( 'Wizard to test if BackWPup can work properly', 'backwpup' );
$this->info[ 'URI' ] = __( 'http://backwpup.com', 'backwpup' );
$this->info[ 'author' ] = 'Inpsyde GmbH';
$this->info[ 'authorURI' ] = __( 'http://inpsyde.com', 'backwpup' );
$this->info[ 'version' ] = BackWPup::get_plugin_data( 'Version' );
$this->info[ 'cap' ] = 'backwpup';
}
/**
* The name of the last button (execute button)
*
* @param $wizard_settings
* @return string
*/
public function get_last_button_name( array $wizard_settings ) {
return __( 'Run tests', 'backwpup' );
}
/**
* with steps has the wizard to to
*
* @param array $wizard_settings
*
* @return array
*/
public function get_steps( array $wizard_settings ) {
$steps = array();
$steps[0] = array( 'id' => 'ENV', 'name' => __( 'Environment', 'backwpup' ), 'description' => __( 'System Environment', 'backwpup' ) );
return $steps;
}
/**
* called on page
*
* @param array $wizard_settings
*/
public function page( array $wizard_settings ) {
if ( $wizard_settings[ 'wizard' ][ 'step' ] === 'ENV' ) {
echo '<p>' . esc_html__( 'Test if BackWPup can work without problems.', 'backwpup' ) . '</p>';
}
}
/**
* called on page inline_js
*
* @param array $wizard_settings
*/
public function inline_js( array $wizard_settings ) {
}
/**
* called on page load to save form data
*
* @param array $wizard_settings
*
* @return array
*/
public function save( array $wizard_settings ) {
return $wizard_settings;
}
/**
* called if last button clicked
*
* @param array $wizard_settings
*/
public function execute( array $wizard_settings ) {
global $wpdb;
/* @var wpdb $wpdb */
$error = 0;
$warning = 0;
//WP Version check
if ( version_compare( BackWPup::get_plugin_data( 'wp_version' ), '3.4', '<' ) ) {
echo '<p class="error">' . esc_html( sprintf( __( 'You must run WordPress version 3.4 or higher to use this plugin. You are using version %s now.','backwpup' ), BackWPup::get_plugin_data( 'wp_version' ) ) ).'</p>';
$error++;
}
// PHP Version check
if ( version_compare( PHP_VERSION, '5.2.6', '<' ) ) {
echo '<p class="error">' . esc_html( sprintf( __( 'You must run PHP version 5.2.6 or higher to use this plugin. You are using version %s now.','backwpup' ), PHP_VERSION ) ) .'</p>';
$error++;
}
elseif ( version_compare( PHP_VERSION, '5.2.6', '>=' ) && version_compare( PHP_VERSION, '5.3.2', '<' ) ) {
echo '<p class="warning">' . esc_html( sprintf( __( 'We recommend to run a PHP version above 5.3.2 to get the full plugin functionality. You are using version %s now.','backwpup' ), PHP_VERSION ) ) .'</p>';
$warning++;
}
//mysql Version check
if ( ! class_exists( 'mysqli' ) && version_compare( $wpdb->db_version( ), '5.0.7', '<' ) ) {
echo '<p class="error">' . esc_html( sprintf( __( 'You must have the MySQLi extension installed and a MySQL server version of 5.0.7 or higher to use this plugin. You are using version %s now.','backwpup' ), $wpdb->get_var( "SELECT VERSION() AS version" ) ) ) .'</p>';
$error++;
}
//curl check
if ( ! function_exists( 'curl_init' ) ) {
echo '<p class="error">' . esc_html( __( 'PHP cURL extension must be installed to use the full plugin functionality.','backwpup' ) ) .'</p>';
$error++;
}
$extension_rec = _x(
'We recommend to install the %1$s extension to generate %2$s archives.',
'%1 = extension name, %2 = file suffix',
'backwpup'
);
//ZIP Archive
if ( ! class_exists( 'ZipArchive' ) ) {
echo '<p class="warning">' . sprintf( $extension_rec, 'PHP ZIP', '.zip' ) .'</p>';
$warning++;
}
//GZ
if ( ! function_exists( 'gzopen' ) ) {
echo '<p class="warning">' . sprintf( $extension_rec, 'PHP GZ', '.tar.gz' ) .'</p>';
$warning++;
}
//bzip2
if ( ! function_exists( 'bzopen' ) ) {
echo '<p class="warning">' . sprintf( $extension_rec, 'PHP bzip2', '.tar.bz2' ) .'</p>';
$warning++;
}
//safe mode
if ( (bool)ini_get( 'safe_mode' ) ) {
echo '<p class="error">'
. str_replace( '\"','"', sprintf(
_x( 'Please disable the deprecated <a href="%s">PHP safe mode</a>.', 'Link to PHP manual', 'backwpup' ),
'http://php.net/manual/en/features.safe-mode.php'
) )
.'</p>';
$error++;
}
//FTP
if ( !function_exists( 'ftp_login' ) ) {
echo '<p class="warning">' . esc_html__( 'We recommend to install the PHP FTP extension to use the FTP backup destination.','backwpup' ) .'</p>';
$warning++;
}
//temp dir
$temp_folder_message = BackWPup_File::check_folder( BackWPup::get_plugin_data( 'TEMP' ), TRUE );
if ( !empty( $temp_folder_message ) ) {
echo '<p class="error">' . esc_html( $temp_folder_message ) .'</p>';
$error++;
}
//log dir
$log_folder = get_site_option( 'backwpup_cfg_logfolder' );
$log_folder = BackWPup_File::get_absolute_path( $log_folder );
$log_folder_message = BackWPup_File::check_folder( $log_folder );
if ( !empty( $log_folder_message ) ) {
echo '<p class="error">' . esc_html( $log_folder_message ) .'</p>';
$error++;
}
$raw_response = BackWPup_Job::get_jobrun_url( 'test' );
if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) || 204 != wp_remote_retrieve_response_code( $raw_response ) ) {
if ( is_wp_error( $raw_response ) ) {
echo '<p class="warning">' . esc_html( sprintf( __( 'The HTTP response test result is an error: "%s".','backwpup' ), $raw_response->get_error_message() ) ) .'</p>';
$warning++;
}
if ( 200 != wp_remote_retrieve_response_code( $raw_response ) && 204 != wp_remote_retrieve_response_code( $raw_response ) ) {
echo '<p class="warning">' . esc_html( sprintf( __( 'The HTTP response test result is a wrong HTTP status: %s. It should be status 200.','backwpup' ), wp_remote_retrieve_response_code( $raw_response ) ) ) .'</p>';
$warning++;
}
}
//cron test
$next_run = wp_next_scheduled( 'wp_update_plugins' );
if ( ! $next_run )
$next_run = wp_next_scheduled( 'wp_version_check' );
if ( ! $next_run )
$next_run = wp_next_scheduled( 'wp_update_themes' );
if ( ! $next_run )
$next_run = wp_next_scheduled( 'wp_scheduled_delete' );
if ( $next_run && $next_run < ( time() - 3600 * 12 ) ) {
echo '<p class="error">' . esc_html__( 'WP-Cron seems to be broken. But it is needed to run scheduled jobs.','backwpup' ) .'</p>';
$error++;
}
if ( empty( $error ) && empty( $warning ) ) {
echo '<div id="message" class="updated below-h2"><p>'. esc_html__( 'All tests passed without errors.', 'backwpup') .'</p></div>';
}
if ( empty( $error ) && ! empty( $warning ) ) {
esc_html_e( 'There is no error, but some warnings. BackWPup will work, but with limitations.', 'backwpup');
}
if ( ! empty( $error ) ) {
esc_html_e( 'There are errors. Please correct them, or BackWPup cannot work.', 'backwpup');
}
}
}