PluginProbe ʕ •ᴥ•ʔ
Backup Migration / 1.4.6
Backup Migration v1.4.6
2.1.6 2.1.5.2 trunk 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.6.1 1.4.7 1.4.8 1.4.9 1.4.9.1 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.5.1
backup-backup / includes / cli-handler.php
backup-backup / includes Last commit date
banner 1 year ago check 1 year ago cli 1 year ago cron 1 year ago dashboard 1 year ago database 1 year ago extracter 1 year ago htaccess 1 year ago progress 1 year ago scanner 1 year ago staging 1 year ago uploader 1 year ago zipper 1 year ago .htaccess 1 year ago activation.php 1 year ago ajax.php 1 year ago analyst.php 1 year ago backup-process.php 1 year ago cli-handler.php 1 year ago compatibility.php 1 year ago config.php 1 year ago constants.php 1 year ago initializer.php 1 year ago logger.php 1 year ago
cli-handler.php
259 lines
1 <?php
2
3 // Namespace
4 namespace BMI\Plugin;
5
6 // Use classes
7 use BMI\Plugin\BMI_Logger as Logger;
8 use BMI\Plugin\Backup_Migration_Plugin as BMP;
9 use BMI\Plugin\Extracter\BMI_Extracter as Extracter;
10 use BMI\Plugin\Progress\BMI_MigrationProgress as MigrationProgress;
11 use BMI\Plugin AS BMI;
12
13 // Allow only PHP CLI to use this script
14 if (php_sapi_name() !== 'cli') {
15 echo 'This script it dedicated for PHP CLI';
16 exit;
17 }
18
19 function isFunctionEnabled($func) {
20 $disabled = explode(',', ini_get('disable_functions'));
21 $isDisabled = in_array($func, $disabled);
22 if (!$isDisabled && function_exists($func)) return true;
23 else return false;
24 }
25
26 // Find WordPress Path
27 function bmi_find_wordpress_base_path() {
28
29 $dir = dirname(__FILE__);
30 $previous = null;
31
32 do {
33
34 if (file_exists($dir . '/wp-load.php') && file_exists($dir . '/wp-config.php')) return $dir;
35 if ($previous == $dir) break;
36 $previous = $dir;
37
38 } while ($dir = dirname($dir));
39
40 return null;
41
42 }
43
44 // Tell WP to not use Themes and set Base Path
45 define('BASE_PATH', bmi_find_wordpress_base_path() . '/');
46 define('BMI_USING_CLI_FUNCTIONALITY', true);
47 if (isset($argv[1])) define('BMI_CLI_FUNCTION', $argv[1]);
48 else {
49
50 echo "\n\n========= BACKUP MIGRATION PLUGIN =========\n\n";
51 echo "Please specify CLI function: bmi_restore [<backup_name>.zip], bmi_backup or bmi_quick_migration <backup URL>\n\n";
52 echo "Examples: \n";
53 echo " – php -f cli-handler.php bmi_backup\n";
54 echo " – php -f cli-handler.php bmi_backup BMI_12-12-12_nameOfMySite_nameOfBackup.zip\n";
55 echo " – php -f cli-handler.php bmi_restore BMI_12-12-12_nameOfMySite_nameOfBackup.zip\n";
56 echo " – php -f cli-handler.php bmi_quick_migration \"http://localhost/site/linkToMyBackup.zip\"\n";
57 echo "\n========= BACKUP MIGRATION PLUGIN =========\n\n";
58 exit();
59
60 }
61
62 if (isset($argv[2])) define('BMI_CLI_ARGUMENT', $argv[2]);
63 if (isset($argv[3])) define('BMI_CLI_ARGUMENT_2', $argv[3]);
64
65 // Pseudo Server variables
66 $_SERVER['REQUEST_METHOD'] = 'CLI';
67
68 // Increase max execution time
69 if (isFunctionEnabled('headers_sent')) {
70 if (!headers_sent()) {
71 if (isFunctionEnabled('set_time_limit')) @set_time_limit(259200);
72 if (isFunctionEnabled('ini_set')) {
73 @ini_set('max_input_time', '259200');
74 @ini_set('max_execution_time', '259200');
75 }
76 }
77 }
78
79 // Response
80 ob_start();
81 echo '100101011101' . "\n";
82
83 @header('Connection: close');
84 @header('Content-Length: ' . ob_get_length());
85
86 ob_end_clean();
87 flush();
88
89 if (isFunctionEnabled('fastcgi_finish_request') && isFunctionEnabled('is_callable') && is_callable('fastcgi_finish_request')) {
90 fastcgi_finish_request();
91 }
92
93 // Let the server know it's server-side script
94 if (isFunctionEnabled('ignore_user_abort')) {
95 @ignore_user_abort(true);
96 }
97
98 if (isFunctionEnabled('session_write_close')) {
99 @session_write_close();
100 }
101
102 function fixSlashes($str, $slash = false) {
103 // Old version
104 // $str = str_replace('\\\\', DIRECTORY_SEPARATOR, $str);
105 // $str = str_replace('\\', DIRECTORY_SEPARATOR, $str);
106 // $str = str_replace('\/', DIRECTORY_SEPARATOR, $str);
107 // $str = str_replace('/', DIRECTORY_SEPARATOR, $str);
108
109 // if ($str[strlen($str) - 1] == DIRECTORY_SEPARATOR) {
110 // $str = substr($str, 0, -1);
111 // }
112
113 // Since 1.3.2
114 $protocol = '';
115 if ($slash == false) $slash = DIRECTORY_SEPARATOR;
116 if (substr($str, 0, 7) == 'http://') $protocol = 'http://';
117 else if (substr($str, 0, 8) == 'https://') $protocol = 'https://';
118
119 $str = substr($str, strlen($protocol));
120 $str = preg_replace('/[\\\\\/]+/', $slash, $str);
121 $str = rtrim($str, '/\\' );
122
123 return $protocol . $str;
124 }
125
126 function bmiLoadWordPressAndBackupPlugin() {
127
128 // Define how WP should load
129 define('WP_USE_THEMES', false);
130 define('SHORTINIT', true);
131
132 // Set path to our plugin's main file
133 $bmiPluginPathToLoad = fixSlashes(dirname(__DIR__) . '/backup-backup.php');
134 $bmiPluginPathToLoadPro = fixSlashes(dirname(dirname(__DIR__)) . '/backup-backup-pro/backup-backup-pro.php');
135
136 // Use WP Globals and load WordPress
137 global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header;
138 require_once bmi_find_wordpress_base_path() . DIRECTORY_SEPARATOR . 'wp-load.php';
139 global $wp_version;
140
141 // Load directory WordPress constants
142 require_once ABSPATH . WPINC . '/formatting.php';
143 require_once ABSPATH . WPINC . '/meta.php';
144 wp_plugin_directory_constants();
145
146 // Allow to register activation hook and realpath
147 $GLOBALS['wp_plugin_paths'] = array();
148 $GLOBALS['shortcode_tags'] = array();
149
150 // Load all dependencies of WordPress for Backup plugin
151 $dependencies = [
152 ABSPATH . WPINC . '/l10n.php',
153 ABSPATH . WPINC . '/plugin.php',
154 ABSPATH . WPINC . '/link-template.php',
155 ABSPATH . WPINC . '/class-wp-textdomain-registry.php',
156 ABSPATH . WPINC . '/class-wp-locale.php',
157 ABSPATH . WPINC . '/class-wp-locale-switcher.php',
158 ABSPATH . WPINC . '/session.php',
159 ABSPATH . WPINC . '/pluggable.php',
160 ABSPATH . WPINC . '/class-wp-ajax-response.php',
161 ABSPATH . WPINC . '/capabilities.php',
162 ABSPATH . WPINC . '/class-wp-roles.php',
163 ABSPATH . WPINC . '/class-wp-role.php',
164 ABSPATH . WPINC . '/class-wp-user.php',
165 ABSPATH . WPINC . '/class-wp-query.php',
166 ABSPATH . WPINC . '/query.php',
167 ABSPATH . WPINC . '/general-template.php',
168 ABSPATH . WPINC . '/http.php',
169 ABSPATH . WPINC . '/class-http.php',
170 ABSPATH . WPINC . '/class-wp-http.php',
171 ABSPATH . WPINC . '/class-wp-http-streams.php',
172 ABSPATH . WPINC . '/class-wp-http-curl.php',
173 ABSPATH . WPINC . '/class-wp-http-proxy.php',
174 ABSPATH . WPINC . '/class-wp-http-cookie.php',
175 ABSPATH . WPINC . '/class-wp-http-encoding.php',
176 ABSPATH . WPINC . '/class-wp-http-response.php',
177 ABSPATH . WPINC . '/class-wp-http-requests-response.php',
178 ABSPATH . WPINC . '/class-wp-http-requests-hooks.php',
179 ABSPATH . WPINC . '/widgets.php',
180 ABSPATH . WPINC . '/class-wp-widget.php',
181 ABSPATH . WPINC . '/class-wp-widget-factory.php',
182 ABSPATH . WPINC . '/class-wp-user-request.php',
183 ABSPATH . WPINC . '/user.php',
184 ABSPATH . WPINC . '/class-wp-user-query.php',
185 ABSPATH . WPINC . '/class-wp-session-tokens.php',
186 ABSPATH . WPINC . '/class-wp-user-meta-session-tokens.php',
187 ABSPATH . WPINC . '/rest-api.php',
188 ABSPATH . WPINC . '/kses.php',
189 ABSPATH . WPINC . '/theme.php',
190 ABSPATH . WPINC . '/rewrite.php',
191 ABSPATH . WPINC . '/class-wp-block-editor-context.php',
192 ABSPATH . WPINC . '/class-wp-block-type.php',
193 ABSPATH . WPINC . '/class-wp-block-pattern-categories-registry.php',
194 ABSPATH . WPINC . '/class-wp-block-patterns-registry.php',
195 ABSPATH . WPINC . '/class-wp-block-styles-registry.php',
196 ABSPATH . WPINC . '/class-wp-block-type-registry.php',
197 ABSPATH . WPINC . '/class-wp-block.php',
198 ABSPATH . WPINC . '/class-wp-block-list.php',
199 ABSPATH . WPINC . '/class-wp-block-parser-block.php',
200 ABSPATH . WPINC . '/class-wp-block-parser-frame.php',
201 ABSPATH . WPINC . '/class-wp-block-parser.php',
202 ABSPATH . WPINC . '/blocks.php',
203 ABSPATH . WPINC . '/blocks/index.php',
204 ];
205
206 for ($i = 0; $i < sizeof($dependencies); ++$i) {
207 $dependency = $dependencies[$i];
208 if (strpos($dependency, 'class-http.php') && version_compare($wp_version, '5.9.0', '>=')) {
209 continue;
210 }
211 if (strpos($dependency, 'session.php') && version_compare($wp_version, '4.7.0', '>=')) {
212 continue;
213 }
214 if (file_exists($dependency)) require_once $dependency;
215 }
216
217 // Load Cookie Constants
218 wp_cookie_constants();
219
220 // Load SSL Constants for DB export
221 wp_ssl_constants();
222
223 // Register Translation
224 if (class_exists('WP_Textdomain_Registry')) {
225 $GLOBALS['wp_textdomain_registry'] = new \WP_Textdomain_Registry();
226 }
227
228 if (file_exists($bmiPluginPathToLoadPro) && is_readable($bmiPluginPathToLoadPro)) {
229 wp_register_plugin_realpath($bmiPluginPathToLoadPro);
230 include_once $bmiPluginPathToLoadPro;
231
232 require_once BMI_PRO_ROOT_DIR . '/classes/core' . ((BMI_PRO_DEBUG) ? '.to-enc' : '') . '.php';
233 $bmi_pro_instance = new BMI_Pro_Core();
234 $bmi_pro_instance->initialize();
235 }
236
237 // Register our backup plugin and load its contents
238 wp_register_plugin_realpath($bmiPluginPathToLoad);
239 include_once $bmiPluginPathToLoad;
240
241 // Enable our plugin WITHOUT calling plugins_loaded hook – it's important
242 require_once BMI_ROOT_DIR . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'constants.php';
243
244 // Initialize backup-migration
245 if (!class_exists('Backup_Migration_Plugin')) {
246
247 // Require initializator
248 require_once BMI_ROOT_DIR . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'initializer.php';
249
250 // Initialize entire plugin
251 $bmi_instance = new BMI\Backup_Migration_Plugin();
252 $bmi_instance->initialize();
253
254 }
255
256 }
257
258 bmiLoadWordPressAndBackupPlugin();
259