Version Description
- Added an advanced section in settings page.
- Optimized the layout of settings page and display of some settings.
- Added an option of enabling optimization mode for web hosting/shared hosting in advanced settings.
- Added a memory_limit option in advanced settings.
- Added a chunk size option in advanced settings.
- Added an option to cancel a running migration.
- Provided the WPDB as the interface with the database for the sites missing PDO_MYSQL.
- Fixed a timeout error occurred in some cases during backup process.
- Optimized the plugin code.
Download this release
Release Info
Developer | wpvivid |
Plugin | Migration, Backup, Staging – WPvivid |
Version | 0.9.20 |
Comparing to | |
See all releases |
Code changes from version 0.9.19 to 0.9.20
- admin/js/wpvivid-admin.js +9 -9
- admin/partials/wpvivid-settings-page-display.php +129 -46
- includes/class-wpvivid-backup-database.php +12 -219
- includes/class-wpvivid-backup-uploader.php +2 -1
- includes/class-wpvivid-backup.php +629 -22
- includes/class-wpvivid-db-method.php +268 -0
- includes/class-wpvivid-migrate.php +52 -33
- includes/class-wpvivid-mysqldump-method.php +80 -3
- includes/class-wpvivid-mysqldump-wpdb.php +1 -1
- includes/class-wpvivid-mysqldump.php +49 -63
- includes/class-wpvivid-restore-database.php +92 -173
- includes/class-wpvivid-restore-db-method.php +85 -0
- includes/class-wpvivid-restore-db-pdo-mysql-method.php +200 -0
- includes/class-wpvivid-restore-db-wpdb-method.php +163 -0
- includes/class-wpvivid-restore-site.php +1 -2
- includes/class-wpvivid-schedule.php +104 -33
- includes/class-wpvivid-setting.php +4 -0
- includes/class-wpvivid-tools.php +19 -1
- includes/class-wpvivid-zipclass.php +285 -3
- includes/class-wpvivid.php +1317 -1186
- includes/customclass/class-wpvivid-amazons3-plus.php +4 -4
- includes/customclass/class-wpvivid-dropbox.php +3 -2
- includes/customclass/class-wpvivid-google-drive.php +10 -5
- includes/customclass/class-wpvivid-one-drive.php +24 -5
- includes/customclass/class-wpvivid-s3compat.php +4 -2
- includes/customclass/class-wpvivid-send-to-site.php +303 -251
- includes/customclass/class-wpvivid-sftpclass.php +2 -2
- readme.txt +36 -32
- wpvivid-backuprestore.php +7 -3
admin/js/wpvivid-admin.js
CHANGED
@@ -304,7 +304,6 @@ function wpvivid_check_runningtask(){
|
|
304 |
}
|
305 |
else if (value.status.str === 'running') {
|
306 |
running_backup_taskid = index;
|
307 |
-
//jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
|
308 |
wpvivid_control_backup_lock();
|
309 |
jQuery('#wpvivid_postbox_backup_percent').show();
|
310 |
jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
|
@@ -312,7 +311,6 @@ function wpvivid_check_runningtask(){
|
|
312 |
}
|
313 |
else if (value.status.str === 'wait_resume') {
|
314 |
running_backup_taskid = index;
|
315 |
-
//jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
|
316 |
wpvivid_control_backup_lock();
|
317 |
jQuery('#wpvivid_postbox_backup_percent').show();
|
318 |
jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
|
@@ -325,7 +323,6 @@ function wpvivid_check_runningtask(){
|
|
325 |
}
|
326 |
else if (value.status.str === 'no_responds') {
|
327 |
running_backup_taskid = index;
|
328 |
-
//jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
|
329 |
wpvivid_control_backup_lock();
|
330 |
jQuery('#wpvivid_postbox_backup_percent').show();
|
331 |
jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
|
@@ -333,7 +330,6 @@ function wpvivid_check_runningtask(){
|
|
333 |
}
|
334 |
else if (value.status.str === 'completed') {
|
335 |
jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
|
336 |
-
//jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
|
337 |
wpvivid_control_backup_unlock();
|
338 |
jQuery('#wpvivid_postbox_backup_percent').hide();
|
339 |
jQuery('#wpvivid_last_backup_msg').html(jsonarray.last_msg_html);
|
@@ -347,7 +343,6 @@ function wpvivid_check_runningtask(){
|
|
347 |
}
|
348 |
else if (value.status.str === 'error') {
|
349 |
jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
|
350 |
-
//jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
|
351 |
wpvivid_control_backup_unlock();
|
352 |
jQuery('#wpvivid_postbox_backup_percent').hide();
|
353 |
jQuery('#wpvivid_last_backup_msg').html(jsonarray.last_msg_html);
|
@@ -366,7 +361,6 @@ function wpvivid_check_runningtask(){
|
|
366 |
{
|
367 |
jQuery('#wpvivid_backup_cancel_btn').css({'pointer-events': 'auto', 'opacity': '1'});
|
368 |
jQuery('#wpvivid_backup_log_btn').css({'pointer-events': 'auto', 'opacity': '1'});
|
369 |
-
//jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
|
370 |
wpvivid_control_backup_unlock();
|
371 |
jQuery('#wpvivid_postbox_backup_percent').hide();
|
372 |
wpvivid_retrieve_backup_list();
|
@@ -648,12 +642,12 @@ function wpvivid_start_backup(){
|
|
648 |
m_downloading_id = '';
|
649 |
}
|
650 |
m_backup_task_id = jsonarray.task_id;
|
651 |
-
if (jsonarray.check.alert_db === false && jsonarray.check.alter_files === false && jsonarray.check.alter_fcgi === false) {
|
652 |
jQuery('#wpvivid_backuplist').html('');
|
653 |
jQuery('#wpvivid_backuplist').append(jsonarray.html);
|
654 |
wpvivid_backup_now(jsonarray.task_id);
|
655 |
}
|
656 |
-
else {
|
657 |
var descript = '';
|
658 |
if (jsonarray.check.alert_db === true || jsonarray.check.alter_files === true) {
|
659 |
descript = 'The database (the dumping SQL file) might be too large, backing up the database may run out of server memory and result in a backup failure.\n' +
|
@@ -673,7 +667,12 @@ function wpvivid_start_backup(){
|
|
673 |
jQuery('#wpvivid_postbox_backup_percent').hide();
|
674 |
}
|
675 |
}
|
676 |
-
|
|
|
|
|
|
|
|
|
|
|
677 |
}
|
678 |
}
|
679 |
catch (err) {
|
@@ -1170,6 +1169,7 @@ function wpvivid_interface_flow_control(){
|
|
1170 |
jQuery('#wpvivid_general_email_enable').click(function(){
|
1171 |
if(jQuery('#wpvivid_general_email_enable').prop('checked') === true){
|
1172 |
jQuery('#wpvivid_general_email_setting').show();
|
|
|
1173 |
}
|
1174 |
else{
|
1175 |
jQuery('#wpvivid_general_email_setting').hide();
|
304 |
}
|
305 |
else if (value.status.str === 'running') {
|
306 |
running_backup_taskid = index;
|
|
|
307 |
wpvivid_control_backup_lock();
|
308 |
jQuery('#wpvivid_postbox_backup_percent').show();
|
309 |
jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
|
311 |
}
|
312 |
else if (value.status.str === 'wait_resume') {
|
313 |
running_backup_taskid = index;
|
|
|
314 |
wpvivid_control_backup_lock();
|
315 |
jQuery('#wpvivid_postbox_backup_percent').show();
|
316 |
jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
|
323 |
}
|
324 |
else if (value.status.str === 'no_responds') {
|
325 |
running_backup_taskid = index;
|
|
|
326 |
wpvivid_control_backup_lock();
|
327 |
jQuery('#wpvivid_postbox_backup_percent').show();
|
328 |
jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
|
330 |
}
|
331 |
else if (value.status.str === 'completed') {
|
332 |
jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
|
|
|
333 |
wpvivid_control_backup_unlock();
|
334 |
jQuery('#wpvivid_postbox_backup_percent').hide();
|
335 |
jQuery('#wpvivid_last_backup_msg').html(jsonarray.last_msg_html);
|
343 |
}
|
344 |
else if (value.status.str === 'error') {
|
345 |
jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
|
|
|
346 |
wpvivid_control_backup_unlock();
|
347 |
jQuery('#wpvivid_postbox_backup_percent').hide();
|
348 |
jQuery('#wpvivid_last_backup_msg').html(jsonarray.last_msg_html);
|
361 |
{
|
362 |
jQuery('#wpvivid_backup_cancel_btn').css({'pointer-events': 'auto', 'opacity': '1'});
|
363 |
jQuery('#wpvivid_backup_log_btn').css({'pointer-events': 'auto', 'opacity': '1'});
|
|
|
364 |
wpvivid_control_backup_unlock();
|
365 |
jQuery('#wpvivid_postbox_backup_percent').hide();
|
366 |
wpvivid_retrieve_backup_list();
|
642 |
m_downloading_id = '';
|
643 |
}
|
644 |
m_backup_task_id = jsonarray.task_id;
|
645 |
+
/*if (jsonarray.check.alert_db === false && jsonarray.check.alter_files === false && jsonarray.check.alter_fcgi === false) {
|
646 |
jQuery('#wpvivid_backuplist').html('');
|
647 |
jQuery('#wpvivid_backuplist').append(jsonarray.html);
|
648 |
wpvivid_backup_now(jsonarray.task_id);
|
649 |
}
|
650 |
+
else {*/
|
651 |
var descript = '';
|
652 |
if (jsonarray.check.alert_db === true || jsonarray.check.alter_files === true) {
|
653 |
descript = 'The database (the dumping SQL file) might be too large, backing up the database may run out of server memory and result in a backup failure.\n' +
|
667 |
jQuery('#wpvivid_postbox_backup_percent').hide();
|
668 |
}
|
669 |
}
|
670 |
+
else{
|
671 |
+
jQuery('#wpvivid_backuplist').html('');
|
672 |
+
jQuery('#wpvivid_backuplist').append(jsonarray.html);
|
673 |
+
wpvivid_backup_now(jsonarray.task_id);
|
674 |
+
}
|
675 |
+
//}
|
676 |
}
|
677 |
}
|
678 |
catch (err) {
|
1169 |
jQuery('#wpvivid_general_email_enable').click(function(){
|
1170 |
if(jQuery('#wpvivid_general_email_enable').prop('checked') === true){
|
1171 |
jQuery('#wpvivid_general_email_setting').show();
|
1172 |
+
|
1173 |
}
|
1174 |
else{
|
1175 |
jQuery('#wpvivid_general_email_setting').hide();
|
admin/partials/wpvivid-settings-page-display.php
CHANGED
@@ -21,12 +21,6 @@ function wpvivid_general_settings()
|
|
21 |
$wpvivid_show_tab_menu = '';
|
22 |
}
|
23 |
}
|
24 |
-
if(!isset($general_setting['options']['wpvivid_common_setting']['max_resume_count'])){
|
25 |
-
$wpvivid_max_resume_count = WPVIVID_RESUME_RETRY_TIMES;
|
26 |
-
}
|
27 |
-
else{
|
28 |
-
$wpvivid_max_resume_count = intval($general_setting['options']['wpvivid_common_setting']['max_resume_count']);
|
29 |
-
}
|
30 |
if(!isset($general_setting['options']['wpvivid_common_setting']['domain_include'])){
|
31 |
$wpvivid_domain_include = 'checked';
|
32 |
}
|
@@ -38,9 +32,6 @@ function wpvivid_general_settings()
|
|
38 |
$wpvivid_domain_include = '';
|
39 |
}
|
40 |
}
|
41 |
-
if(!isset($general_setting['options']['wpvivid_common_setting']['memory_limit'])){
|
42 |
-
$general_setting['options']['wpvivid_common_setting']['memory_limit']=WPVIVID_MEMORY_LIMIT;
|
43 |
-
}
|
44 |
global $wpvivid_pulgin;
|
45 |
$out_of_date=$wpvivid_pulgin->_get_out_of_date_info();
|
46 |
?>
|
@@ -48,26 +39,6 @@ function wpvivid_general_settings()
|
|
48 |
<td class="row-title wpvivid-backup-settings-table-left tablelistcolumn"><label for="tablecell"><?php _e('General Settings', 'wpvivid'); ?></label></td>
|
49 |
<td class="tablelistcolumn">
|
50 |
<div class="postbox schedule-tab-block">
|
51 |
-
<div><strong><?php _e('Compress Files Every', 'wpvivid'); ?></strong></div>
|
52 |
-
<div class="schedule-tab-block setting-page-content">
|
53 |
-
<input type="text" placeholder="400" option="setting" name="max_file_size" id="wpvivid_max_zip" class="all-options" value="<?php esc_attr_e(str_replace('M', '', $general_setting['options']['wpvivid_compress_setting']['max_file_size']), 'wpvivid'); ?>" onkeyup="value=value.replace(/\D/g,'')" />MB
|
54 |
-
<div><p><?php _e( 'Some web hosting providers limit large zip files (e.g. 200MB), and therefore splitting your backup into many parts is an ideal way to avoid to hit the limitation if you are running a big website. Please try to adjust the value if you are encountering backup errors. If you use a value of 0 MB, any backup files won\'t be split.', 'wpvivid' ); ?></div></p>
|
55 |
-
</div>
|
56 |
-
<div><strong><?php _e('Exclude the files which are larger than', 'wpvivid'); ?></strong></div>
|
57 |
-
<div class="schedule-tab-block setting-page-content">
|
58 |
-
<input type="text" placeholder="400" option="setting" name="exclude_file_size" id="wpvivid_ignore_large" class="all-options" value="<?php esc_attr_e($general_setting['options']['wpvivid_compress_setting']['exclude_file_size'], 'wpvivid'); ?>" onkeyup="value=value.replace(/\D/g,'')" />MB
|
59 |
-
<div><p><?php _e( 'Using the option will ignore the file larger than the certain size in MB when backing up, \'0\' (zero) means unlimited.', 'wpvivid' ); ?></p></div>
|
60 |
-
</div>
|
61 |
-
<div><strong><?php _e('PHP script execution timeout', 'wpvivid'); ?></strong></div>
|
62 |
-
<div class="schedule-tab-block setting-page-content">
|
63 |
-
<input type="text" placeholder="600" option="setting" name="max_execution_time" id="wpvivid_option_timeout" class="all-options" value="<?php esc_attr_e($general_setting['options']['wpvivid_common_setting']['max_execution_time'], 'wpvivid'); ?>" onkeyup="value=value.replace(/\D/g,'')" />Seconds
|
64 |
-
<div><p><?php _e( 'The time-out is not your server PHP time-out. With the execution time exhausted, our plugin will shut the process of backup down. If the progress of backup encounters a time-out, that means you have a medium or large sized website, please try to scale the value bigger. ', 'wpvivid' ); ?></p></div>
|
65 |
-
</div>
|
66 |
-
<div><strong><?php _e('PHP memory limit', 'wpvivid'); ?></strong></div>
|
67 |
-
<div class="schedule-tab-block setting-page-content">
|
68 |
-
<input type="text" placeholder="256" option="setting" name="memory_limit" class="all-options" value="<?php esc_attr_e(str_replace('M', '', $general_setting['options']['wpvivid_common_setting']['memory_limit']), 'wpvivid'); ?>" onkeyup="value=value.replace(/\D/g,'')" />MB
|
69 |
-
<div><p><?php _e('Adjust this value to apply for a temporary PHP memory limit for WPvivid backup plugin to run a backup. We set this value to 256M by default. Increase the value if you encounter a memory exhausted error. Note: some web hosting providers may not support this.', 'wpvivid'); ?></p></div>
|
70 |
-
</div>
|
71 |
<div>
|
72 |
<select option="setting" name="max_backup_count" id="wpvivid_max_backup_count">
|
73 |
<?php
|
@@ -82,21 +53,6 @@ function wpvivid_general_settings()
|
|
82 |
?>
|
83 |
</select><strong><?php _e('backups retained', 'wpvivid'); ?></strong>
|
84 |
</div>
|
85 |
-
<div>
|
86 |
-
<strong>Retrying </strong>
|
87 |
-
<select option="setting" name="max_resume_count">
|
88 |
-
<?php
|
89 |
-
for($resume_count=3; $resume_count<10; $resume_count++){
|
90 |
-
if($resume_count === $wpvivid_max_resume_count){
|
91 |
-
_e('<option selected="selected" value="'.$resume_count.'">'.$resume_count.'</option>');
|
92 |
-
}
|
93 |
-
else{
|
94 |
-
_e('<option value="'.$resume_count.'">'.$resume_count.'</option>');
|
95 |
-
}
|
96 |
-
}
|
97 |
-
?>
|
98 |
-
</select><strong><?php _e(' times when encountering a time-out error', 'wpvivid'); ?></strong>
|
99 |
-
</div>
|
100 |
<div>
|
101 |
<label for="wpvivid_estimate_backup">
|
102 |
<input type="checkbox" option="setting" name="estimate_backup" id="wpvivid_estimate_backup" value="1" <?php esc_attr_e($wpvivid_setting_estimate_backup, 'wpvivid'); ?> />
|
@@ -319,11 +275,138 @@ function wpvivid_export_import_settings()
|
|
319 |
<?php
|
320 |
}
|
321 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
322 |
add_action('wpvivid_setting_add_cell','wpvivid_general_settings',10);
|
323 |
-
add_action('wpvivid_setting_add_cell','wpvivid_compressing',12);
|
324 |
add_action('wpvivid_setting_add_cell','wpvivid_email_report',13);
|
325 |
add_action('wpvivid_setting_add_cell','wpvivid_clean_junk',14);
|
326 |
-
add_action('wpvivid_setting_add_cell','
|
|
|
327 |
?>
|
328 |
<div>
|
329 |
<table class="widefat">
|
21 |
$wpvivid_show_tab_menu = '';
|
22 |
}
|
23 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
if(!isset($general_setting['options']['wpvivid_common_setting']['domain_include'])){
|
25 |
$wpvivid_domain_include = 'checked';
|
26 |
}
|
32 |
$wpvivid_domain_include = '';
|
33 |
}
|
34 |
}
|
|
|
|
|
|
|
35 |
global $wpvivid_pulgin;
|
36 |
$out_of_date=$wpvivid_pulgin->_get_out_of_date_info();
|
37 |
?>
|
39 |
<td class="row-title wpvivid-backup-settings-table-left tablelistcolumn"><label for="tablecell"><?php _e('General Settings', 'wpvivid'); ?></label></td>
|
40 |
<td class="tablelistcolumn">
|
41 |
<div class="postbox schedule-tab-block">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
<div>
|
43 |
<select option="setting" name="max_backup_count" id="wpvivid_max_backup_count">
|
44 |
<?php
|
53 |
?>
|
54 |
</select><strong><?php _e('backups retained', 'wpvivid'); ?></strong>
|
55 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
<div>
|
57 |
<label for="wpvivid_estimate_backup">
|
58 |
<input type="checkbox" option="setting" name="estimate_backup" id="wpvivid_estimate_backup" value="1" <?php esc_attr_e($wpvivid_setting_estimate_backup, 'wpvivid'); ?> />
|
275 |
<?php
|
276 |
}
|
277 |
|
278 |
+
function wpvivid_advanced_settings()
|
279 |
+
{
|
280 |
+
$general_setting=WPvivid_Setting::get_setting(true, "");
|
281 |
+
$wpvivid_setting_no_compress='';
|
282 |
+
$wpvivid_setting_compress='';
|
283 |
+
if($general_setting['options']['wpvivid_compress_setting']['no_compress']){
|
284 |
+
$wpvivid_setting_no_compress='checked';
|
285 |
+
}
|
286 |
+
else{
|
287 |
+
$wpvivid_setting_compress='checked';
|
288 |
+
}
|
289 |
+
|
290 |
+
if(!isset($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload'])){
|
291 |
+
$subpackage_plugin_upload = '';
|
292 |
+
}
|
293 |
+
else{
|
294 |
+
if($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']){
|
295 |
+
$subpackage_plugin_upload = 'checked';
|
296 |
+
}
|
297 |
+
else{
|
298 |
+
$subpackage_plugin_upload = '';
|
299 |
+
}
|
300 |
+
}
|
301 |
+
if(!isset($general_setting['options']['wpvivid_common_setting']['max_resume_count'])){
|
302 |
+
$wpvivid_max_resume_count = WPVIVID_RESUME_RETRY_TIMES;
|
303 |
+
}
|
304 |
+
else{
|
305 |
+
$wpvivid_max_resume_count = intval($general_setting['options']['wpvivid_common_setting']['max_resume_count']);
|
306 |
+
}
|
307 |
+
if(!isset($general_setting['options']['wpvivid_common_setting']['memory_limit'])){
|
308 |
+
$general_setting['options']['wpvivid_common_setting']['memory_limit']=WPVIVID_MEMORY_LIMIT;
|
309 |
+
}
|
310 |
+
if(!isset($general_setting['options']['wpvivid_common_setting']['restore_memory_limit'])){
|
311 |
+
$general_setting['options']['wpvivid_common_setting']['restore_memory_limit']=WPVIVID_RESTORE_MEMORY_LIMIT;
|
312 |
+
}
|
313 |
+
if(!isset($general_setting['options']['wpvivid_common_setting']['migrate_size'])){
|
314 |
+
$general_setting['options']['wpvivid_common_setting']['migrate_size']=WPVIVID_MIGRATE_SIZE;
|
315 |
+
}
|
316 |
+
?>
|
317 |
+
<tr>
|
318 |
+
<td class="row-title wpvivid-backup-settings-table-left tablelistcolumn"><label for="tablecell"><?php _e('Advanced', 'wpvivid'); ?></label></td>
|
319 |
+
<td class="tablelistcolumn">
|
320 |
+
<div class="postbox schedule-tab-block setting-page-content">
|
321 |
+
<div>
|
322 |
+
<p><strong><?php _e('Enable the option when backup failed.', 'wpvivid'); ?></strong><?php _e(' Special optimization for web hosting/shared hosting', 'wpvivid'); ?></p>
|
323 |
+
<div>
|
324 |
+
<label>
|
325 |
+
<input type="checkbox" option="setting" name="subpackage_plugin_upload" <?php esc_attr_e($subpackage_plugin_upload); ?> />
|
326 |
+
<span><strong><?php _e('Enable optimization mode for web hosting/shared hosting', 'wpvivid'); ?></strong></span>
|
327 |
+
</label>
|
328 |
+
<div>
|
329 |
+
<p><?php _e('Enabling this option can improve the backup success rate, but it will take more time for backup.', 'wpvivid'); ?></p>
|
330 |
+
</div>
|
331 |
+
</div>
|
332 |
+
</div>
|
333 |
+
</div>
|
334 |
+
<div class="postbox schedule-tab-block setting-page-content">
|
335 |
+
<fieldset>
|
336 |
+
<label>
|
337 |
+
<input type="radio" option="setting" name="no_compress" value="1" <?php esc_attr_e($wpvivid_setting_no_compress, 'wpvivid'); ?> />
|
338 |
+
<span title="<?php _e( 'It will cause a lower CPU Usage and is recommended in a web hosting/ shared hosting environment.', 'wpvivid' ); ?>"><?php _e( 'Only Archive without compressing', 'wpvivid' ); ?></span>
|
339 |
+
</label>
|
340 |
+
<label>
|
341 |
+
<input type="radio" option="setting" name="no_compress" value="0" <?php esc_attr_e($wpvivid_setting_compress, 'wpvivid'); ?> />
|
342 |
+
<span title="<?php _e( 'It will cause a higher CPU Usage and is recommended in a VPS/ dedicated hosting environment.', 'wpvivid' ); ?>"><?php _e( 'Compress and Archive', 'wpvivid' ); ?></span>
|
343 |
+
</label>
|
344 |
+
<label style="display: none;">
|
345 |
+
<input type="radio" option="setting" name="compress_type" value="zip" checked />
|
346 |
+
<input type="radio" option="setting" name="use_temp_file" value="1" checked />
|
347 |
+
<input type="radio" option="setting" name="use_temp_size" value="16" checked />
|
348 |
+
</label>
|
349 |
+
</fieldset>
|
350 |
+
|
351 |
+
<div style="padding-top: 10px;">
|
352 |
+
<div><strong><?php _e('Compress Files Every', 'wpvivid'); ?></strong></div>
|
353 |
+
<div class="schedule-tab-block setting-page-content">
|
354 |
+
<input type="text" placeholder="400" option="setting" name="max_file_size" id="wpvivid_max_zip" class="all-options" value="<?php esc_attr_e(str_replace('M', '', $general_setting['options']['wpvivid_compress_setting']['max_file_size']), 'wpvivid'); ?>" onkeyup="value=value.replace(/\D/g,'')" />MB
|
355 |
+
<div><p><?php _e( 'Some web hosting providers limit large zip files (e.g. 200MB), and therefore splitting your backup into many parts is an ideal way to avoid to hit the limitation if you are running a big website. Please try to adjust the value if you are encountering backup errors. If you use a value of 0 MB, any backup files won\'t be split.', 'wpvivid' ); ?></div></p>
|
356 |
+
</div>
|
357 |
+
<div><strong><?php _e('Exclude the files which are larger than', 'wpvivid'); ?></strong></div>
|
358 |
+
<div class="schedule-tab-block setting-page-content">
|
359 |
+
<input type="text" placeholder="400" option="setting" name="exclude_file_size" id="wpvivid_ignore_large" class="all-options" value="<?php esc_attr_e($general_setting['options']['wpvivid_compress_setting']['exclude_file_size'], 'wpvivid'); ?>" onkeyup="value=value.replace(/\D/g,'')" />MB
|
360 |
+
<div><p><?php _e( 'Using the option will ignore the file larger than the certain size in MB when backing up, \'0\' (zero) means unlimited.', 'wpvivid' ); ?></p></div>
|
361 |
+
</div>
|
362 |
+
<div><strong><?php _e('PHP script execution timeout', 'wpvivid'); ?></strong></div>
|
363 |
+
<div class="schedule-tab-block setting-page-content">
|
364 |
+
<input type="text" placeholder="600" option="setting" name="max_execution_time" id="wpvivid_option_timeout" class="all-options" value="<?php esc_attr_e($general_setting['options']['wpvivid_common_setting']['max_execution_time'], 'wpvivid'); ?>" onkeyup="value=value.replace(/\D/g,'')" />Seconds
|
365 |
+
<div><p><?php _e( 'The time-out is not your server PHP time-out. With the execution time exhausted, our plugin will shut the process of backup down. If the progress of backup encounters a time-out, that means you have a medium or large sized website, please try to scale the value bigger. ', 'wpvivid' ); ?></p></div>
|
366 |
+
</div>
|
367 |
+
<div><strong><?php _e('PHP Memory Limit for backup', 'wpvivid'); ?></strong></div>
|
368 |
+
<div class="schedule-tab-block setting-page-content">
|
369 |
+
<input type="text" placeholder="256" option="setting" name="memory_limit" class="all-options" value="<?php esc_attr_e(str_replace('M', '', $general_setting['options']['wpvivid_common_setting']['memory_limit']), 'wpvivid'); ?>" onkeyup="value=value.replace(/\D/g,'')" />MB
|
370 |
+
<div><p><?php _e('Adjust this value to apply for a temporary PHP memory limit for WPvivid backup plugin to run a backup. We set this value to 256M by default. Increase the value if you encounter a memory exhausted error. Note: some web hosting providers may not support this.', 'wpvivid'); ?></p></div>
|
371 |
+
</div>
|
372 |
+
<div><strong><?php _e('PHP Memory Limit for restoration', 'wpvivid'); ?></strong></div>
|
373 |
+
<div class="schedule-tab-block setting-page-content">
|
374 |
+
<input type="text" placeholder="256" option="setting" name="restore_memory_limit" class="all-options" value="<?php esc_attr_e(str_replace('M', '', $general_setting['options']['wpvivid_common_setting']['restore_memory_limit']), 'wpvivid'); ?>" onkeyup="value=value.replace(/\D/g,'')" />MB
|
375 |
+
<div><p><?php _e('Adjust this value to apply for a temporary PHP memory limit for WPvivid backup plugin in restore process. We set this value to 256M by default. Increase the value if you encounter a memory exhausted error. Note: some web hosting providers may not support this.', 'wpvivid'); ?></p></div>
|
376 |
+
</div>
|
377 |
+
<div><strong><?php _e('Chunk Size', 'wpvivid'); ?></strong></div>
|
378 |
+
<div class="schedule-tab-block setting-page-content">
|
379 |
+
<input type="text" placeholder="2" option="setting" name="migrate_size" class="all-options" value="<?php esc_attr_e($general_setting['options']['wpvivid_common_setting']['migrate_size']); ?>" onkeyup="value=value.replace(/\D/g,'')" />KB
|
380 |
+
<div><p><?php _e('e.g. if you choose a chunk size of 2MB, a 8MB file will use 4 chunks. Decreasing this value will break the ISP\'s transmission limit, for example:512KB', 'wpvivid'); ?></p></div>
|
381 |
+
</div>
|
382 |
+
<div>
|
383 |
+
<strong>Retrying </strong>
|
384 |
+
<select option="setting" name="max_resume_count">
|
385 |
+
<?php
|
386 |
+
for($resume_count=3; $resume_count<10; $resume_count++){
|
387 |
+
if($resume_count === $wpvivid_max_resume_count){
|
388 |
+
_e('<option selected="selected" value="'.$resume_count.'">'.$resume_count.'</option>');
|
389 |
+
}
|
390 |
+
else{
|
391 |
+
_e('<option value="'.$resume_count.'">'.$resume_count.'</option>');
|
392 |
+
}
|
393 |
+
}
|
394 |
+
?>
|
395 |
+
</select><strong><?php _e(' times when encountering a time-out error', 'wpvivid'); ?></strong>
|
396 |
+
</div>
|
397 |
+
</div>
|
398 |
+
</div>
|
399 |
+
</td>
|
400 |
+
</tr>
|
401 |
+
<?php
|
402 |
+
}
|
403 |
+
|
404 |
add_action('wpvivid_setting_add_cell','wpvivid_general_settings',10);
|
405 |
+
//add_action('wpvivid_setting_add_cell','wpvivid_compressing',12);
|
406 |
add_action('wpvivid_setting_add_cell','wpvivid_email_report',13);
|
407 |
add_action('wpvivid_setting_add_cell','wpvivid_clean_junk',14);
|
408 |
+
add_action('wpvivid_setting_add_cell','wpvivid_advanced_settings',15);
|
409 |
+
add_action('wpvivid_setting_add_cell','wpvivid_export_import_settings',16);
|
410 |
?>
|
411 |
<div>
|
412 |
<table class="widefat">
|
includes/class-wpvivid-backup-database.php
CHANGED
@@ -20,31 +20,6 @@ class WPvivid_Backup_Database
|
|
20 |
private $CharsetArray;
|
21 |
private $CollateArray;
|
22 |
private $task_id;
|
23 |
-
public $must_privilege = array(
|
24 |
-
'backup' => array(
|
25 |
-
'SELECT' => NECESSARY,
|
26 |
-
'INSERT' => NECESSARY,
|
27 |
-
'UPDATE' => NECESSARY,
|
28 |
-
'SHOW VIEW' => OPTION,
|
29 |
-
'LOCK TABLES' => OPTION,
|
30 |
-
'EVENT' => OPTION,
|
31 |
-
'TRIGGER' => OPTION,
|
32 |
-
'CREATE ROUTINE' => OPTION,
|
33 |
-
),
|
34 |
-
'restore' => array(
|
35 |
-
'SELECT' => NECESSARY,
|
36 |
-
'INSERT' => NECESSARY,
|
37 |
-
'UPDATE' => NECESSARY,
|
38 |
-
'DROP' => NECESSARY,
|
39 |
-
'CREATE' => NECESSARY,
|
40 |
-
'SHOW VIEW' => OPTION,
|
41 |
-
'EVENT' => OPTION,
|
42 |
-
'TRIGGER' => OPTION,
|
43 |
-
'CREATE ROUTINE' => OPTION,
|
44 |
-
'CREATE VIEW' => OPTION,
|
45 |
-
'LOCK TABLES' => OPTION,
|
46 |
-
)
|
47 |
-
);
|
48 |
|
49 |
public function __construct() {
|
50 |
$this->CharsetArray = array();
|
@@ -79,74 +54,30 @@ class WPvivid_Backup_Database
|
|
79 |
|
80 |
$backup_file =$data['sql_file_name'];
|
81 |
|
82 |
-
$privileges = array();
|
83 |
require_once 'class-wpvivid-mysqldump-method.php';
|
84 |
require_once 'class-wpvivid-mysqldump.php';
|
85 |
-
if(class_exists('PDO'))
|
86 |
-
{
|
87 |
-
$res = explode(':',DB_HOST);
|
88 |
-
$db_host = $res[0];
|
89 |
-
$db_port = empty($res[1])?'':$res[1];
|
90 |
-
if(!empty($db_port))
|
91 |
-
$db_host = $db_host.':'.$db_port;
|
92 |
-
try{
|
93 |
-
$pdo=new PDO('mysql:host=' . $db_host . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD );
|
94 |
-
}catch (Exception $e)
|
95 |
-
{
|
96 |
-
if(!empty($db_port)){
|
97 |
-
$db_host = $res[0];
|
98 |
-
$pdo=new PDO('mysql:host=' . $db_host . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD );
|
99 |
-
if(empty($pdo) || !$pdo){
|
100 |
-
return array('result' => WPVIVID_FAILED,'error' =>'The error establishing a database connection. Please check wp-config.php file and make sure the information is correct.');
|
101 |
-
}
|
102 |
-
}else{
|
103 |
-
return array('result' => WPVIVID_FAILED,'error' =>'The error establishing a database connection. Please check wp-config.php file and make sure the information is correct.');
|
104 |
-
}
|
105 |
-
}
|
106 |
-
|
107 |
-
$result = $pdo -> query('Select @@Version;');
|
108 |
-
|
109 |
-
if($result && $result->rowCount()>0)
|
110 |
-
{
|
111 |
-
$datas = $result -> fetchAll();
|
112 |
-
$version = $datas[0][0];
|
113 |
-
}
|
114 |
-
else{
|
115 |
-
return array('result'=>WPVIVID_FAILED,'error'=>'MySQL version is not obtained. Please check if MySQL is installed or not.');
|
116 |
-
}
|
117 |
-
|
118 |
-
if(version_compare('5.3.0',phpversion()) > 0){
|
119 |
-
return array('result'=>WPVIVID_FAILED,'error'=>'Your PHP version is too old. Please upgrade at least to PHP 5.3.0.');
|
120 |
-
}
|
121 |
-
if(version_compare('4.1.0',$version) > 0){
|
122 |
-
return array('result'=>WPVIVID_FAILED,'error'=>'Your MySQL version is too old. Please upgrade at least to MySQL 4.1.0.');
|
123 |
-
}
|
124 |
|
125 |
-
|
126 |
-
|
127 |
-
{
|
128 |
-
return $result;
|
129 |
-
}else{
|
130 |
-
$privileges = $result['data'];
|
131 |
-
}
|
132 |
|
133 |
-
|
134 |
-
|
|
|
|
|
135 |
|
136 |
-
|
137 |
-
|
138 |
-
return array('result'=>WPVIVID_FAILED,'error'=>'PDO extension not found. Please check if PDO extension is installed or not.');
|
139 |
}
|
140 |
|
|
|
|
|
141 |
$exclude = array('/^(?!'.$prefix.')/');
|
142 |
-
|
143 |
-
$dump = new WPvivid_Mysqldump(
|
144 |
-
$dump -> set_privilege($privileges);
|
145 |
|
146 |
if(file_exists($backup_file))
|
147 |
@unlink($backup_file);
|
148 |
|
149 |
-
$dump->log=$wpvivid_pulgin->wpvivid_log;
|
150 |
$dump->task_id=$task_id;
|
151 |
$dump->start($backup_file);
|
152 |
unset($pdo);
|
@@ -169,142 +100,4 @@ class WPvivid_Backup_Database
|
|
169 |
$files[] = $backup_file;
|
170 |
return array('result'=>WPVIVID_SUCCESS,'files'=>$files);
|
171 |
}
|
172 |
-
|
173 |
-
public function check_privilege($type,$pdo)
|
174 |
-
{
|
175 |
-
global $wpvivid_pulgin;
|
176 |
-
|
177 |
-
$temp_privileges = array();
|
178 |
-
foreach ($this -> must_privilege[$type] as $key => $value){
|
179 |
-
$temp_privileges[$key] = 0;
|
180 |
-
}
|
181 |
-
|
182 |
-
$res = explode(':',DB_HOST);
|
183 |
-
$db_host = $res[0];
|
184 |
-
$db_port = empty($res[1])?'':$res[1];
|
185 |
-
if(!empty($db_port))
|
186 |
-
$db_host = $db_host.':'.$db_port;
|
187 |
-
$result = $pdo -> query('show grants for `'.DB_USER.'`@`'.$db_host.'`;');
|
188 |
-
if(!$result && !empty($db_port))
|
189 |
-
{
|
190 |
-
$db_host = $res[0];
|
191 |
-
$result = $pdo -> query('show grants for `'.DB_USER.'`@`'.$db_host.'`;');
|
192 |
-
}
|
193 |
-
|
194 |
-
if($result && $result->rowCount()>0)
|
195 |
-
{
|
196 |
-
$datas = $result -> fetchAll();
|
197 |
-
foreach ($datas as $data)
|
198 |
-
{
|
199 |
-
$sql = $data[0];
|
200 |
-
if(stristr($sql,'USAGE'))
|
201 |
-
continue;
|
202 |
-
$result = array();
|
203 |
-
$pattern = "#^GRANT (.*?) TO '".DB_USER."'@'".$db_host."'#";
|
204 |
-
preg_match_all($pattern,$sql,$result);
|
205 |
-
$results = explode(' ON ',$result[1][0]);
|
206 |
-
|
207 |
-
$tables = explode('.',$results[1]);
|
208 |
-
$table_fix_name=trim($tables[0],'`');
|
209 |
-
$table_fix_name=str_replace('\\','',$table_fix_name);
|
210 |
-
$wpvivid_pulgin->wpvivid_log->WriteLog('check table:'.$table_fix_name.' DB_NAME:'.DB_NAME,'notice');
|
211 |
-
if(trim($tables[0],'`') == '*' || trim($tables[0],'`') == DB_NAME||$table_fix_name== DB_NAME)
|
212 |
-
{
|
213 |
-
$privileges = trim($results[0]);
|
214 |
-
$privileges = strtoupper($privileges);
|
215 |
-
if($privileges == 'ALL PRIVILEGES')
|
216 |
-
{
|
217 |
-
foreach ($temp_privileges as $key => $value)
|
218 |
-
{
|
219 |
-
$temp_privileges[$key] = 1;
|
220 |
-
}
|
221 |
-
}else {
|
222 |
-
$privileges = explode(',',$privileges);
|
223 |
-
foreach ($privileges as $privilege)
|
224 |
-
{
|
225 |
-
$privilege = trim($privilege);
|
226 |
-
if(array_key_exists($privilege,$temp_privileges))
|
227 |
-
{
|
228 |
-
$temp_privileges[$privilege] = 1;
|
229 |
-
}
|
230 |
-
}
|
231 |
-
}
|
232 |
-
}
|
233 |
-
}
|
234 |
-
|
235 |
-
}else{
|
236 |
-
foreach ($temp_privileges as $key => $value)
|
237 |
-
{
|
238 |
-
$temp_privileges[$key] = 1;
|
239 |
-
}
|
240 |
-
|
241 |
-
$wpvivid_pulgin->wpvivid_log->WriteLog('When performing database check, an anomaly is encountered.','notice');
|
242 |
-
}
|
243 |
-
$options = array();
|
244 |
-
foreach ($temp_privileges as $key => $value)
|
245 |
-
{
|
246 |
-
if($value == 0){
|
247 |
-
if($this -> must_privilege[$type][$key] === OPTION)
|
248 |
-
{
|
249 |
-
$options[] = $key;
|
250 |
-
}
|
251 |
-
}
|
252 |
-
}
|
253 |
-
if(!empty($options))
|
254 |
-
{
|
255 |
-
global $wpvivid_pulgin;
|
256 |
-
$wpvivid_pulgin->wpvivid_log->WriteLog('The lack of optional database privileges including '.implode(',',$options),'notice');
|
257 |
-
}
|
258 |
-
return array('result' => WPVIVID_SUCCESS,'data' => $temp_privileges);
|
259 |
-
}
|
260 |
-
|
261 |
-
public function check_big_db($pdo)
|
262 |
-
{
|
263 |
-
global $wpvivid_pulgin;
|
264 |
-
|
265 |
-
$sth = $pdo->query('SHOW TABLE STATUS');
|
266 |
-
|
267 |
-
$dbSize = 0;
|
268 |
-
$max_rows=0;
|
269 |
-
$rows = $sth->fetchAll();
|
270 |
-
|
271 |
-
foreach ($rows as $row)
|
272 |
-
{
|
273 |
-
$max_rows+=$row["Rows"];
|
274 |
-
$dbSize+=$row["Data_length"];
|
275 |
-
}
|
276 |
-
|
277 |
-
if($max_rows>7000000)
|
278 |
-
{
|
279 |
-
$message='Exporting a large database with more than '.$max_rows.' rows may cause an error when performing dump action.';
|
280 |
-
$wpvivid_pulgin->wpvivid_log->WriteLog($message, 'notice');
|
281 |
-
WPvivid_taskmanager::update_backup_sub_task_progress($this->task_id,'backup',WPVIVID_BACKUP_TYPE_DB,0,$message);
|
282 |
-
}
|
283 |
-
}
|
284 |
-
|
285 |
-
public function check_max_allowed_packet($pdo)
|
286 |
-
{
|
287 |
-
global $wpvivid_pulgin;
|
288 |
-
|
289 |
-
$max_allowed_packet = $pdo->query("SELECT @@session.max_allowed_packet;");
|
290 |
-
if($max_allowed_packet)
|
291 |
-
{
|
292 |
-
$max_allowed_packet = $max_allowed_packet -> fetchAll();
|
293 |
-
if(is_array($max_allowed_packet)&&isset($max_allowed_packet[0])&&isset($max_allowed_packet[0][0]))
|
294 |
-
{
|
295 |
-
if($max_allowed_packet[0][0]<1048576)
|
296 |
-
{
|
297 |
-
$wpvivid_pulgin->wpvivid_log->WriteLog('warning: max_allowed_packet less than 1M :'.size_format($max_allowed_packet[0][0],2),'notice');
|
298 |
-
}
|
299 |
-
else if($max_allowed_packet[0][0]<33554432)
|
300 |
-
{
|
301 |
-
$wpvivid_pulgin->wpvivid_log->WriteLog('max_allowed_packet less than 32M :'.size_format($max_allowed_packet[0][0],2),'notice');
|
302 |
-
}
|
303 |
-
}
|
304 |
-
}
|
305 |
-
else
|
306 |
-
{
|
307 |
-
$wpvivid_pulgin->wpvivid_log->WriteLog('get max_allowed_packet failed ','notice');
|
308 |
-
}
|
309 |
-
}
|
310 |
}
|
20 |
private $CharsetArray;
|
21 |
private $CollateArray;
|
22 |
private $task_id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
public function __construct() {
|
25 |
$this->CharsetArray = array();
|
54 |
|
55 |
$backup_file =$data['sql_file_name'];
|
56 |
|
|
|
57 |
require_once 'class-wpvivid-mysqldump-method.php';
|
58 |
require_once 'class-wpvivid-mysqldump.php';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
+
$db_method=new WPvivid_DB_Method();
|
61 |
+
$version =$db_method->get_mysql_version();
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
+
if(version_compare('4.1.0',$version) > 0)
|
64 |
+
{
|
65 |
+
return array('result'=>WPVIVID_FAILED,'error'=>'Your MySQL version is too old. Please upgrade at least to MySQL 4.1.0.');
|
66 |
+
}
|
67 |
|
68 |
+
if(version_compare('5.3.0',phpversion()) > 0){
|
69 |
+
return array('result'=>WPVIVID_FAILED,'error'=>'Your PHP version is too old. Please upgrade at least to PHP 5.3.0.');
|
|
|
70 |
}
|
71 |
|
72 |
+
$db_method->check_max_allowed_packet();
|
73 |
+
|
74 |
$exclude = array('/^(?!'.$prefix.')/');
|
75 |
+
//$dsn = 'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME;
|
76 |
+
$dump = new WPvivid_Mysqldump(DB_HOST,DB_NAME, DB_USER, DB_PASSWORD , array('exclude-tables'=>$exclude,'add-drop-table' => true,'extended-insert'=>false));
|
|
|
77 |
|
78 |
if(file_exists($backup_file))
|
79 |
@unlink($backup_file);
|
80 |
|
|
|
81 |
$dump->task_id=$task_id;
|
82 |
$dump->start($backup_file);
|
83 |
unset($pdo);
|
100 |
$files[] = $backup_file;
|
101 |
return array('result'=>WPVIVID_SUCCESS,'files'=>$files);
|
102 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
}
|
includes/class-wpvivid-backup-uploader.php
CHANGED
@@ -68,6 +68,8 @@ class Wpvivid_BackupUploader
|
|
68 |
{
|
69 |
$id= $matches[0];
|
70 |
$id=substr($id,0,strlen($id)-1);
|
|
|
|
|
71 |
if(WPvivid_Backuplist::get_backuplist_by_key($id)===false)
|
72 |
{
|
73 |
$backup_id=$id;
|
@@ -226,7 +228,6 @@ class Wpvivid_BackupUploader
|
|
226 |
{
|
227 |
continue;
|
228 |
} else {
|
229 |
-
|
230 |
if($this->check_file_is_a_wpvivid_backup($filename,$backup_id))
|
231 |
{
|
232 |
if($this->check_is_a_wpvivid_backup($path.$filename))
|
68 |
{
|
69 |
$id= $matches[0];
|
70 |
$id=substr($id,0,strlen($id)-1);
|
71 |
+
|
72 |
+
|
73 |
if(WPvivid_Backuplist::get_backuplist_by_key($id)===false)
|
74 |
{
|
75 |
$backup_id=$id;
|
228 |
{
|
229 |
continue;
|
230 |
} else {
|
|
|
231 |
if($this->check_file_is_a_wpvivid_backup($filename,$backup_id))
|
232 |
{
|
233 |
if($this->check_is_a_wpvivid_backup($path.$filename))
|
includes/class-wpvivid-backup.php
CHANGED
@@ -9,6 +9,8 @@ define('WPVIVID_BACKUP_TYPE_DB','backup_db');
|
|
9 |
define('WPVIVID_BACKUP_TYPE_THEMES','backup_themes');
|
10 |
define('WPVIVID_BACKUP_TYPE_PLUGIN','backup_plugin');
|
11 |
define('WPVIVID_BACKUP_TYPE_UPLOADS','backup_uploads');
|
|
|
|
|
12 |
define('WPVIVID_BACKUP_TYPE_CONTENT','backup_content');
|
13 |
define('WPVIVID_BACKUP_TYPE_CORE','backup_core');
|
14 |
define('WPVIVID_BACKUP_TYPE_OTHERS','backup_others');
|
@@ -143,7 +145,19 @@ class WPvivid_Backup_Task
|
|
143 |
$this->set_backup(WPVIVID_BACKUP_TYPE_DB);
|
144 |
$this->set_backup(WPVIVID_BACKUP_TYPE_THEMES);
|
145 |
$this->set_backup(WPVIVID_BACKUP_TYPE_PLUGIN);
|
146 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
$this->set_backup(WPVIVID_BACKUP_TYPE_CONTENT);
|
148 |
$this->set_backup(WPVIVID_BACKUP_TYPE_CORE);
|
149 |
}
|
@@ -151,7 +165,19 @@ class WPvivid_Backup_Task
|
|
151 |
{
|
152 |
$this->set_backup(WPVIVID_BACKUP_TYPE_THEMES);
|
153 |
$this->set_backup(WPVIVID_BACKUP_TYPE_PLUGIN);
|
154 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
$this->set_backup(WPVIVID_BACKUP_TYPE_CONTENT);
|
156 |
$this->set_backup(WPVIVID_BACKUP_TYPE_CORE);
|
157 |
}
|
@@ -256,6 +282,30 @@ class WPvivid_Backup_Task
|
|
256 |
$backup_data['exclude_regex']=$exclude_regex;
|
257 |
$backup_data['include_regex']=array();
|
258 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
else if($backup==WPVIVID_BACKUP_TYPE_CONTENT)
|
260 |
{
|
261 |
$backup_data['root_path']=get_home_path();
|
@@ -273,7 +323,6 @@ class WPvivid_Backup_Task
|
|
273 |
$exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']), '/').'#';$exclude_regex[]='#^'.preg_quote($this->transfer_path(get_theme_root()), '/').'#';
|
274 |
$backup_data['exclude_regex']=$exclude_regex;
|
275 |
$backup_data['include_regex']=array();
|
276 |
-
|
277 |
}
|
278 |
else if($backup==WPVIVID_BACKUP_TYPE_CORE)
|
279 |
{
|
@@ -285,8 +334,8 @@ class WPvivid_Backup_Task
|
|
285 |
$backup_data['json_info']['wp_core']=1;
|
286 |
$include_regex[]='#^'.preg_quote($this -> transfer_path(get_home_path().DIRECTORY_SEPARATOR.'wp-admin'), '/').'#';
|
287 |
$include_regex[]='#^'.preg_quote($this->transfer_path(get_home_path().DIRECTORY_SEPARATOR.'wp-includes'), '/').'#';
|
288 |
-
$exclude_regex[]='#^'.preg_quote($this->transfer_path(get_home_path().DIRECTORY_SEPARATOR), '/').'pclzip-.*\.tmp#';
|
289 |
-
$exclude_regex[]='#^'.preg_quote($this->transfer_path(get_home_path().DIRECTORY_SEPARATOR), '/').'pclzip-.*\.gz#';
|
290 |
$backup_data['exclude_regex']=$exclude_regex;
|
291 |
$backup_data['include_regex']=$include_regex;
|
292 |
}
|
@@ -294,7 +343,6 @@ class WPvivid_Backup_Task
|
|
294 |
{
|
295 |
$backup_data['root_path']=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->task['options']['backup_options']['dir'];
|
296 |
$backup_data['prefix']=$this->get_prefix().'_backup_all';
|
297 |
-
|
298 |
$backup_data['files']=array();
|
299 |
foreach ($this->task['options']['backup_options']['backup'] as $backup_finished_data)
|
300 |
{
|
@@ -308,14 +356,44 @@ class WPvivid_Backup_Task
|
|
308 |
}
|
309 |
if($backup_data!==false)
|
310 |
{
|
|
|
|
|
311 |
$this->task['options']['backup_options']['backup'][$backup_data['key']]=$backup_data;
|
312 |
}
|
313 |
}
|
314 |
}
|
315 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
316 |
public function get_need_backup_files($backup_data)
|
317 |
{
|
318 |
-
if(isset($backup_data['files'])
|
319 |
{
|
320 |
return $backup_data['files'];
|
321 |
}
|
@@ -347,10 +425,11 @@ class WPvivid_Backup_Task
|
|
347 |
|
348 |
public function get_need_backup()
|
349 |
{
|
|
|
350 |
$backup=false;
|
351 |
$i_finished_backup_count=0;
|
352 |
$i_count_of_backup=sizeof($this->task['options']['backup_options']['backup']);
|
353 |
-
foreach ($this->task['options']['backup_options']['backup'] as $backup_data)
|
354 |
{
|
355 |
if($backup_data['result']!==false)
|
356 |
{
|
@@ -365,10 +444,9 @@ class WPvivid_Backup_Task
|
|
365 |
{
|
366 |
if($backup===false)
|
367 |
{
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
}
|
372 |
$backup=$backup_data;
|
373 |
}
|
374 |
}
|
@@ -389,6 +467,7 @@ class WPvivid_Backup_Task
|
|
389 |
if(!array_key_exists(WPVIVID_BACKUP_TYPE_MERGE,$this->task['options']['backup_options']['backup']))
|
390 |
{
|
391 |
$this->set_backup(WPVIVID_BACKUP_TYPE_MERGE);
|
|
|
392 |
$backup=$this->task['options']['backup_options']['backup'][WPVIVID_BACKUP_TYPE_MERGE];
|
393 |
}
|
394 |
}
|
@@ -397,12 +476,57 @@ class WPvivid_Backup_Task
|
|
397 |
return $backup;
|
398 |
}
|
399 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
400 |
public function update_backup_result($backup_data,$result)
|
401 |
{
|
|
|
|
|
402 |
if(array_key_exists($backup_data['key'],$this->task['options']['backup_options']['backup']))
|
403 |
{
|
404 |
$this->task['options']['backup_options']['backup'][$backup_data['key']]['finished']=1;
|
|
|
|
|
|
|
405 |
$this->task['options']['backup_options']['backup'][$backup_data['key']]['result']=$result;
|
|
|
406 |
WPvivid_taskmanager::update_task_options($this->task['id'],'backup_options', $this->task['options']['backup_options']);
|
407 |
|
408 |
if($result['result']==WPVIVID_FAILED)
|
@@ -426,6 +550,49 @@ class WPvivid_Backup_Task
|
|
426 |
{
|
427 |
WPvivid_taskmanager::update_backup_main_task_progress($this->task['id'],'backup',100,1);
|
428 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
429 |
}
|
430 |
|
431 |
public function get_backup_result()
|
@@ -459,7 +626,7 @@ class WPvivid_Backup_Task
|
|
459 |
return $files;
|
460 |
}
|
461 |
|
462 |
-
public function getFileLoop(&$files,$path,$exclude_regex=array(),$include_regex=array(),$exclude_file_size
|
463 |
{
|
464 |
$count = 0;
|
465 |
if(is_dir($path))
|
@@ -473,7 +640,7 @@ class WPvivid_Backup_Task
|
|
473 |
{
|
474 |
if ($this->regex_match($exclude_regex, $path . DIRECTORY_SEPARATOR . $filename, 0)) {
|
475 |
if ($this->regex_match($include_regex, $path . DIRECTORY_SEPARATOR . $filename, 1)) {
|
476 |
-
$this->getFileLoop($files, $path . DIRECTORY_SEPARATOR . $filename, $exclude_regex, $include_regex, $include_dir);
|
477 |
}
|
478 |
}
|
479 |
} else {
|
@@ -547,6 +714,50 @@ class WPvivid_Backup_Task
|
|
547 |
}
|
548 |
|
549 |
$files=array_merge($files,$this->get_backup_file($backup_finished_data['key']));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
550 |
}
|
551 |
}
|
552 |
return $files;
|
@@ -768,6 +979,245 @@ class WPvivid_Backup_Task
|
|
768 |
|
769 |
return $list_tasks;
|
770 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
771 |
}
|
772 |
|
773 |
class WPvivid_Backup_Item
|
@@ -1130,7 +1580,6 @@ class WPvivid_Backup_Item
|
|
1130 |
{
|
1131 |
$zip=new WPvivid_ZipClass();
|
1132 |
$json=$zip->get_json_data($file_name);
|
1133 |
-
|
1134 |
$json=json_decode($json,1);
|
1135 |
if(is_null($json))
|
1136 |
{
|
@@ -1357,14 +1806,16 @@ class WPvivid_Backup
|
|
1357 |
{
|
1358 |
global $wpvivid_pulgin;
|
1359 |
$wpvivid_pulgin->set_time_limit($this->task->get_id());
|
1360 |
-
|
|
|
1361 |
$wpvivid_pulgin->wpvivid_log->WriteLog('Prepare to backup '.$next_backup['key'].' files.','notice');
|
1362 |
if(isset($next_backup['files'])) {
|
1363 |
$wpvivid_pulgin->wpvivid_log->WriteLog('File number: ' . sizeof($next_backup['files']), 'notice');
|
1364 |
}
|
1365 |
$result = $this->_backup($next_backup);
|
1366 |
$wpvivid_pulgin->wpvivid_log->WriteLog('Backing up '.$next_backup['key'].' completed.','notice');
|
1367 |
-
|
|
|
1368 |
$this->task->update_backup_result($next_backup,$result);
|
1369 |
$wpvivid_pulgin->check_cancel_backup($task_id);
|
1370 |
unset($next_backup);
|
@@ -1398,6 +1849,7 @@ class WPvivid_Backup
|
|
1398 |
return $result;
|
1399 |
}
|
1400 |
}
|
|
|
1401 |
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-zipclass.php';
|
1402 |
|
1403 |
$zip = new WPvivid_ZipClass();
|
@@ -1406,17 +1858,172 @@ class WPvivid_Backup
|
|
1406 |
return $zip->last_error;
|
1407 |
}
|
1408 |
|
1409 |
-
|
|
|
|
|
|
|
1410 |
|
1411 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1412 |
{
|
1413 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1414 |
{
|
1415 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1416 |
}
|
1417 |
}
|
1418 |
|
1419 |
return $result;
|
|
|
1420 |
}
|
1421 |
|
1422 |
public function cleanup()
|
@@ -1526,7 +2133,7 @@ class WPvivid_Backup
|
|
1526 |
if (is_dir($path . DIRECTORY_SEPARATOR . $filename)) {
|
1527 |
if ($this->regex_match($exclude_regex['directory'], $path . DIRECTORY_SEPARATOR . $filename, 0)) {
|
1528 |
if ($this->regex_match($include_regex, $path . DIRECTORY_SEPARATOR . $filename, 1)) {
|
1529 |
-
$this->getFileLoop($files, $path . DIRECTORY_SEPARATOR . $filename, $exclude_regex, $include_regex, $include_dir);
|
1530 |
}
|
1531 |
}
|
1532 |
} else {
|
9 |
define('WPVIVID_BACKUP_TYPE_THEMES','backup_themes');
|
10 |
define('WPVIVID_BACKUP_TYPE_PLUGIN','backup_plugin');
|
11 |
define('WPVIVID_BACKUP_TYPE_UPLOADS','backup_uploads');
|
12 |
+
define('WPVIVID_BACKUP_TYPE_UPLOADS_FILES','backup_uploads_files');
|
13 |
+
define('WPVIVID_BACKUP_TYPE_UPLOADS_FILES_OTHER','backup_uploads_files_other');
|
14 |
define('WPVIVID_BACKUP_TYPE_CONTENT','backup_content');
|
15 |
define('WPVIVID_BACKUP_TYPE_CORE','backup_core');
|
16 |
define('WPVIVID_BACKUP_TYPE_OTHERS','backup_others');
|
145 |
$this->set_backup(WPVIVID_BACKUP_TYPE_DB);
|
146 |
$this->set_backup(WPVIVID_BACKUP_TYPE_THEMES);
|
147 |
$this->set_backup(WPVIVID_BACKUP_TYPE_PLUGIN);
|
148 |
+
$general_setting=WPvivid_Setting::get_setting(true, "");
|
149 |
+
if(isset($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']) && !empty($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload'])){
|
150 |
+
if($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']){
|
151 |
+
$this->set_backup(WPVIVID_BACKUP_TYPE_UPLOADS_FILES);
|
152 |
+
$this->set_backup(WPVIVID_BACKUP_TYPE_UPLOADS_FILES_OTHER);
|
153 |
+
}
|
154 |
+
else{
|
155 |
+
$this->set_backup(WPVIVID_BACKUP_TYPE_UPLOADS);
|
156 |
+
}
|
157 |
+
}
|
158 |
+
else{
|
159 |
+
$this->set_backup(WPVIVID_BACKUP_TYPE_UPLOADS);
|
160 |
+
}
|
161 |
$this->set_backup(WPVIVID_BACKUP_TYPE_CONTENT);
|
162 |
$this->set_backup(WPVIVID_BACKUP_TYPE_CORE);
|
163 |
}
|
165 |
{
|
166 |
$this->set_backup(WPVIVID_BACKUP_TYPE_THEMES);
|
167 |
$this->set_backup(WPVIVID_BACKUP_TYPE_PLUGIN);
|
168 |
+
$general_setting=WPvivid_Setting::get_setting(true, "");
|
169 |
+
if(isset($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']) && !empty($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload'])){
|
170 |
+
if($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']){
|
171 |
+
$this->set_backup(WPVIVID_BACKUP_TYPE_UPLOADS_FILES);
|
172 |
+
$this->set_backup(WPVIVID_BACKUP_TYPE_UPLOADS_FILES_OTHER);
|
173 |
+
}
|
174 |
+
else{
|
175 |
+
$this->set_backup(WPVIVID_BACKUP_TYPE_UPLOADS);
|
176 |
+
}
|
177 |
+
}
|
178 |
+
else{
|
179 |
+
$this->set_backup(WPVIVID_BACKUP_TYPE_UPLOADS);
|
180 |
+
}
|
181 |
$this->set_backup(WPVIVID_BACKUP_TYPE_CONTENT);
|
182 |
$this->set_backup(WPVIVID_BACKUP_TYPE_CORE);
|
183 |
}
|
282 |
$backup_data['exclude_regex']=$exclude_regex;
|
283 |
$backup_data['include_regex']=array();
|
284 |
}
|
285 |
+
else if($backup==WPVIVID_BACKUP_TYPE_UPLOADS_FILES)
|
286 |
+
{
|
287 |
+
$backup_data['root_path']=WP_CONTENT_DIR;
|
288 |
+
$backup_data['prefix']=$this->get_prefix().'_backup_uploads';
|
289 |
+
$upload_dir = wp_upload_dir();
|
290 |
+
$backup_data['files_root']=$this -> transfer_path($upload_dir['basedir']);
|
291 |
+
$exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'backwpup', '/').'#'; // BackWPup backup directory
|
292 |
+
$exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'backup-guard', '/').'#'; // Wordpress Backup and Migrate Plugin backup directory
|
293 |
+
//$exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR, '/').'[0-9]{4}#';
|
294 |
+
$backup_data['exclude_regex']=$exclude_regex;
|
295 |
+
$backup_data['include_regex'][]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR, '/').'[0-9]{4}#';
|
296 |
+
}
|
297 |
+
else if($backup==WPVIVID_BACKUP_TYPE_UPLOADS_FILES_OTHER)
|
298 |
+
{
|
299 |
+
$backup_data['root_path']=WP_CONTENT_DIR;
|
300 |
+
$backup_data['prefix']=$this->get_prefix().'_backup_uploads_other';
|
301 |
+
$upload_dir = wp_upload_dir();
|
302 |
+
$backup_data['files_root']=$this -> transfer_path($upload_dir['basedir']);
|
303 |
+
$exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'backwpup', '/').'#'; // BackWPup backup directory
|
304 |
+
$exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'backup-guard', '/').'#'; // Wordpress Backup and Migrate Plugin backup directory
|
305 |
+
$exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR, '/').'[0-9]{4}#';
|
306 |
+
$backup_data['exclude_regex']=$exclude_regex;
|
307 |
+
$backup_data['include_regex']=array();
|
308 |
+
}
|
309 |
else if($backup==WPVIVID_BACKUP_TYPE_CONTENT)
|
310 |
{
|
311 |
$backup_data['root_path']=get_home_path();
|
323 |
$exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']), '/').'#';$exclude_regex[]='#^'.preg_quote($this->transfer_path(get_theme_root()), '/').'#';
|
324 |
$backup_data['exclude_regex']=$exclude_regex;
|
325 |
$backup_data['include_regex']=array();
|
|
|
326 |
}
|
327 |
else if($backup==WPVIVID_BACKUP_TYPE_CORE)
|
328 |
{
|
334 |
$backup_data['json_info']['wp_core']=1;
|
335 |
$include_regex[]='#^'.preg_quote($this -> transfer_path(get_home_path().DIRECTORY_SEPARATOR.'wp-admin'), '/').'#';
|
336 |
$include_regex[]='#^'.preg_quote($this->transfer_path(get_home_path().DIRECTORY_SEPARATOR.'wp-includes'), '/').'#';
|
337 |
+
$exclude_regex[]='#^'.preg_quote($this->transfer_path(get_home_path().DIRECTORY_SEPARATOR.'wp-admin'.DIRECTORY_SEPARATOR), '/').'pclzip-.*\.tmp#';
|
338 |
+
$exclude_regex[]='#^'.preg_quote($this->transfer_path(get_home_path().DIRECTORY_SEPARATOR.'wp-admin'.DIRECTORY_SEPARATOR), '/').'pclzip-.*\.gz#';
|
339 |
$backup_data['exclude_regex']=$exclude_regex;
|
340 |
$backup_data['include_regex']=$include_regex;
|
341 |
}
|
343 |
{
|
344 |
$backup_data['root_path']=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->task['options']['backup_options']['dir'];
|
345 |
$backup_data['prefix']=$this->get_prefix().'_backup_all';
|
|
|
346 |
$backup_data['files']=array();
|
347 |
foreach ($this->task['options']['backup_options']['backup'] as $backup_finished_data)
|
348 |
{
|
356 |
}
|
357 |
if($backup_data!==false)
|
358 |
{
|
359 |
+
add_filter('wpvivid_set_backup', array($this, 'wpvivid_set_backup'),10);
|
360 |
+
$backup_data=apply_filters('wpvivid_set_backup',$backup_data);
|
361 |
$this->task['options']['backup_options']['backup'][$backup_data['key']]=$backup_data;
|
362 |
}
|
363 |
}
|
364 |
}
|
365 |
|
366 |
+
public function wpvivid_set_backup($backup_data)
|
367 |
+
{
|
368 |
+
if($backup_data['key']==WPVIVID_BACKUP_TYPE_PLUGIN)
|
369 |
+
{
|
370 |
+
$general_setting=WPvivid_Setting::get_setting(true, "");
|
371 |
+
if(isset($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']) && !empty($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload'])){
|
372 |
+
if($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']){
|
373 |
+
$backup_data['resume_packages'] = 1;
|
374 |
+
}
|
375 |
+
}
|
376 |
+
}
|
377 |
+
else if($backup_data['key']==WPVIVID_BACKUP_TYPE_MERGE)
|
378 |
+
{
|
379 |
+
$backup_data['resume_packages'] = 1;
|
380 |
+
}
|
381 |
+
else if($backup_data['key']==WPVIVID_BACKUP_TYPE_UPLOADS_FILES)
|
382 |
+
{
|
383 |
+
$general_setting=WPvivid_Setting::get_setting(true, "");
|
384 |
+
if(isset($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']) && !empty($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload'])){
|
385 |
+
if($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']){
|
386 |
+
$backup_data['resume_packages'] = 1;
|
387 |
+
}
|
388 |
+
}
|
389 |
+
}
|
390 |
+
|
391 |
+
return $backup_data;
|
392 |
+
}
|
393 |
+
|
394 |
public function get_need_backup_files($backup_data)
|
395 |
{
|
396 |
+
if(isset($backup_data['files'])&&!empty($backup_data['files']))
|
397 |
{
|
398 |
return $backup_data['files'];
|
399 |
}
|
425 |
|
426 |
public function get_need_backup()
|
427 |
{
|
428 |
+
$this->task=WPvivid_taskmanager::get_task($this->task['id']);
|
429 |
$backup=false;
|
430 |
$i_finished_backup_count=0;
|
431 |
$i_count_of_backup=sizeof($this->task['options']['backup_options']['backup']);
|
432 |
+
foreach ($this->task['options']['backup_options']['backup'] as $key=>$backup_data)
|
433 |
{
|
434 |
if($backup_data['result']!==false)
|
435 |
{
|
444 |
{
|
445 |
if($backup===false)
|
446 |
{
|
447 |
+
add_filter('wpvivid_get_need_backup_files', array($this, 'wpvivid_get_need_backup_files'),10);
|
448 |
+
$backup_data=apply_filters('wpvivid_get_need_backup_files',$backup_data);
|
449 |
+
|
|
|
450 |
$backup=$backup_data;
|
451 |
}
|
452 |
}
|
467 |
if(!array_key_exists(WPVIVID_BACKUP_TYPE_MERGE,$this->task['options']['backup_options']['backup']))
|
468 |
{
|
469 |
$this->set_backup(WPVIVID_BACKUP_TYPE_MERGE);
|
470 |
+
WPvivid_Setting::update_task($this->task['id'],$this->task);
|
471 |
$backup=$this->task['options']['backup_options']['backup'][WPVIVID_BACKUP_TYPE_MERGE];
|
472 |
}
|
473 |
}
|
476 |
return $backup;
|
477 |
}
|
478 |
|
479 |
+
public function wpvivid_get_need_backup_files($backup_data)
|
480 |
+
{
|
481 |
+
if(!isset($backup_data['dump_db']))
|
482 |
+
{
|
483 |
+
if($backup_data['key']==WPVIVID_BACKUP_TYPE_PLUGIN)
|
484 |
+
{
|
485 |
+
$general_setting=WPvivid_Setting::get_setting(true, "");
|
486 |
+
if(isset($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']) && !empty($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload'])){
|
487 |
+
if($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']){
|
488 |
+
$backup_data['files']=$this->get_need_backup_folder($backup_data);
|
489 |
+
$this->task['options']['backup_options']['backup'][$backup_data['key']]=$backup_data;
|
490 |
+
WPvivid_Setting::update_task($this->task['id'],$this->task);
|
491 |
+
}
|
492 |
+
}
|
493 |
+
else{
|
494 |
+
$backup_data['files']=$this->get_need_backup_files($backup_data);
|
495 |
+
}
|
496 |
+
}
|
497 |
+
else if ($backup_data['key']==WPVIVID_BACKUP_TYPE_UPLOADS_FILES)
|
498 |
+
{
|
499 |
+
$general_setting=WPvivid_Setting::get_setting(true, "");
|
500 |
+
if(isset($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']) && !empty($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload'])){
|
501 |
+
if($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']){
|
502 |
+
$backup_data['files']=$this->get_need_uploads_backup_folder($backup_data);
|
503 |
+
$this->task['options']['backup_options']['backup'][$backup_data['key']]=$backup_data;
|
504 |
+
WPvivid_Setting::update_task($this->task['id'],$this->task);
|
505 |
+
}
|
506 |
+
}
|
507 |
+
else{
|
508 |
+
$backup_data['files']=$this->get_need_backup_files($backup_data);
|
509 |
+
}
|
510 |
+
}
|
511 |
+
else {
|
512 |
+
$backup_data['files']=$this->get_need_backup_files($backup_data);
|
513 |
+
}
|
514 |
+
}
|
515 |
+
return $backup_data;
|
516 |
+
}
|
517 |
+
|
518 |
public function update_backup_result($backup_data,$result)
|
519 |
{
|
520 |
+
$this->task=WPvivid_taskmanager::get_task($this->task['id']);
|
521 |
+
|
522 |
if(array_key_exists($backup_data['key'],$this->task['options']['backup_options']['backup']))
|
523 |
{
|
524 |
$this->task['options']['backup_options']['backup'][$backup_data['key']]['finished']=1;
|
525 |
+
|
526 |
+
add_filter('wpvivid_backup_update_result', array($this, 'wpvivid_backup_update_result'),10,2);
|
527 |
+
$result=apply_filters('wpvivid_backup_update_result',$result,$backup_data);
|
528 |
$this->task['options']['backup_options']['backup'][$backup_data['key']]['result']=$result;
|
529 |
+
|
530 |
WPvivid_taskmanager::update_task_options($this->task['id'],'backup_options', $this->task['options']['backup_options']);
|
531 |
|
532 |
if($result['result']==WPVIVID_FAILED)
|
550 |
{
|
551 |
WPvivid_taskmanager::update_backup_main_task_progress($this->task['id'],'backup',100,1);
|
552 |
}
|
553 |
+
WPvivid_Setting::update_task($this->task['id'],$this->task);
|
554 |
+
}
|
555 |
+
|
556 |
+
public function wpvivid_backup_update_result($result,$backup_data)
|
557 |
+
{
|
558 |
+
if($result['result']==WPVIVID_SUCCESS)
|
559 |
+
{
|
560 |
+
$exist_files_name=array();
|
561 |
+
foreach ($result['files'] as $temp_file_data)
|
562 |
+
{
|
563 |
+
$exist_files_name[$temp_file_data['file_name']]=$temp_file_data['file_name'];
|
564 |
+
}
|
565 |
+
if(WPVIVID_BACKUP_TYPE_PLUGIN==$backup_data['key'])
|
566 |
+
{
|
567 |
+
$packages_files_info = $this->get_packages_files_info(WPVIVID_BACKUP_TYPE_PLUGIN);
|
568 |
+
if ($packages_files_info !== false)
|
569 |
+
{
|
570 |
+
foreach ($packages_files_info as $file_data)
|
571 |
+
{
|
572 |
+
if(!array_key_exists($file_data['file_name'],$exist_files_name))
|
573 |
+
{
|
574 |
+
$result['files'][]=$file_data;
|
575 |
+
}
|
576 |
+
}
|
577 |
+
}
|
578 |
+
}
|
579 |
+
else if(WPVIVID_BACKUP_TYPE_UPLOADS_FILES==$backup_data['key'])
|
580 |
+
{
|
581 |
+
$packages_files_info = $this->get_packages_files_info(WPVIVID_BACKUP_TYPE_UPLOADS_FILES);
|
582 |
+
if ($packages_files_info !== false)
|
583 |
+
{
|
584 |
+
foreach ($packages_files_info as $file_data)
|
585 |
+
{
|
586 |
+
if(!array_key_exists($file_data['file_name'],$exist_files_name))
|
587 |
+
{
|
588 |
+
$result['files'][]=$file_data;
|
589 |
+
}
|
590 |
+
}
|
591 |
+
}
|
592 |
+
}
|
593 |
+
}
|
594 |
+
|
595 |
+
return $result;
|
596 |
}
|
597 |
|
598 |
public function get_backup_result()
|
626 |
return $files;
|
627 |
}
|
628 |
|
629 |
+
public function getFileLoop(&$files,$path,$exclude_regex=array(),$include_regex=array(),$exclude_file_size,$include_dir = true)
|
630 |
{
|
631 |
$count = 0;
|
632 |
if(is_dir($path))
|
640 |
{
|
641 |
if ($this->regex_match($exclude_regex, $path . DIRECTORY_SEPARATOR . $filename, 0)) {
|
642 |
if ($this->regex_match($include_regex, $path . DIRECTORY_SEPARATOR . $filename, 1)) {
|
643 |
+
$this->getFileLoop($files, $path . DIRECTORY_SEPARATOR . $filename, $exclude_regex, $include_regex, $exclude_file_size, $include_dir);
|
644 |
}
|
645 |
}
|
646 |
} else {
|
714 |
}
|
715 |
|
716 |
$files=array_merge($files,$this->get_backup_file($backup_finished_data['key']));
|
717 |
+
add_filter('wpvivid_get_need_cleanup_files', array($this, 'wpvivid_get_need_cleanup_files'),10,2);
|
718 |
+
$files=apply_filters('wpvivid_get_need_cleanup_files',$files,$backup_finished_data);
|
719 |
+
}
|
720 |
+
}
|
721 |
+
|
722 |
+
return $files;
|
723 |
+
}
|
724 |
+
|
725 |
+
public function wpvivid_get_need_cleanup_files($files,$backup_finished_data)
|
726 |
+
{
|
727 |
+
if(WPVIVID_BACKUP_TYPE_PLUGIN==$backup_finished_data['key'])
|
728 |
+
{
|
729 |
+
$general_setting=WPvivid_Setting::get_setting(true, "");
|
730 |
+
if(isset($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']) && !empty($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload'])){
|
731 |
+
if($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']){
|
732 |
+
$packages_files_info = $this->get_packages_files_info(WPVIVID_BACKUP_TYPE_PLUGIN);
|
733 |
+
if ($packages_files_info !== false) {
|
734 |
+
foreach ($packages_files_info as $file_data) {
|
735 |
+
$path = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $this->task['options']['backup_options']['dir'] . DIRECTORY_SEPARATOR . $file_data['file_name'];
|
736 |
+
global $wpvivid_pulgin;
|
737 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog('test:' . $path, 'notice');
|
738 |
+
if (!in_array($path, $files))
|
739 |
+
$files[] = $path;
|
740 |
+
}
|
741 |
+
}
|
742 |
+
}
|
743 |
+
}
|
744 |
+
}
|
745 |
+
else if(WPVIVID_BACKUP_TYPE_UPLOADS_FILES==$backup_finished_data['key'])
|
746 |
+
{
|
747 |
+
$general_setting=WPvivid_Setting::get_setting(true, "");
|
748 |
+
if(isset($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']) && !empty($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload'])){
|
749 |
+
if($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']){
|
750 |
+
$packages_files_info = $this->get_packages_files_info(WPVIVID_BACKUP_TYPE_UPLOADS_FILES);
|
751 |
+
if ($packages_files_info !== false) {
|
752 |
+
foreach ($packages_files_info as $file_data) {
|
753 |
+
$path = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $this->task['options']['backup_options']['dir'] . DIRECTORY_SEPARATOR . $file_data['file_name'];
|
754 |
+
global $wpvivid_pulgin;
|
755 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog('test:' . $path, 'notice');
|
756 |
+
if (!in_array($path, $files))
|
757 |
+
$files[] = $path;
|
758 |
+
}
|
759 |
+
}
|
760 |
+
}
|
761 |
}
|
762 |
}
|
763 |
return $files;
|
979 |
|
980 |
return $list_tasks;
|
981 |
}
|
982 |
+
|
983 |
+
public function get_packages_info($key)
|
984 |
+
{
|
985 |
+
if(isset($this->task['data']['backup']['sub_job'][$key]))
|
986 |
+
{
|
987 |
+
if(empty($this->task['data']['backup']['sub_job'][$key]['job_data']))
|
988 |
+
{
|
989 |
+
return false;
|
990 |
+
}
|
991 |
+
else
|
992 |
+
{
|
993 |
+
$packages=array();
|
994 |
+
foreach ($this->task['data']['backup']['sub_job'][$key]['job_data'] as $key=>$package)
|
995 |
+
{
|
996 |
+
if($key=='files')
|
997 |
+
{
|
998 |
+
continue;
|
999 |
+
}
|
1000 |
+
|
1001 |
+
$packages[]=$package;
|
1002 |
+
}
|
1003 |
+
if(empty($packages))
|
1004 |
+
{
|
1005 |
+
return false;
|
1006 |
+
}
|
1007 |
+
else
|
1008 |
+
{
|
1009 |
+
return $packages;
|
1010 |
+
}
|
1011 |
+
}
|
1012 |
+
}
|
1013 |
+
else
|
1014 |
+
{
|
1015 |
+
return false;
|
1016 |
+
}
|
1017 |
+
}
|
1018 |
+
|
1019 |
+
public function get_packages_files_info($key)
|
1020 |
+
{
|
1021 |
+
if(isset($this->task['data']['backup']['sub_job'][$key]))
|
1022 |
+
{
|
1023 |
+
if(empty($this->task['data']['backup']['sub_job'][$key]['job_data']))
|
1024 |
+
{
|
1025 |
+
return false;
|
1026 |
+
}
|
1027 |
+
else
|
1028 |
+
{
|
1029 |
+
if(isset($this->task['data']['backup']['sub_job'][$key]['job_data']['files']))
|
1030 |
+
{
|
1031 |
+
return $this->task['data']['backup']['sub_job'][$key]['job_data']['files'];
|
1032 |
+
}
|
1033 |
+
else
|
1034 |
+
{
|
1035 |
+
return false;
|
1036 |
+
}
|
1037 |
+
}
|
1038 |
+
}
|
1039 |
+
else
|
1040 |
+
{
|
1041 |
+
return false;
|
1042 |
+
}
|
1043 |
+
}
|
1044 |
+
|
1045 |
+
public function set_packages_info($key,$packages)
|
1046 |
+
{
|
1047 |
+
$this->task=WPvivid_taskmanager::get_task($this->task['id']);
|
1048 |
+
$job_data=array();
|
1049 |
+
foreach ($packages as $package)
|
1050 |
+
{
|
1051 |
+
$package['backup']=false;
|
1052 |
+
$job_data[basename($package['path'])]=$package;
|
1053 |
+
}
|
1054 |
+
$this->task['data']['backup']['sub_job'][$key]['job_data']=$job_data;
|
1055 |
+
WPvivid_Setting::update_task($this->task['id'],$this->task);
|
1056 |
+
return $job_data;
|
1057 |
+
}
|
1058 |
+
|
1059 |
+
public function update_packages_info($key,$package,$file_data=false)
|
1060 |
+
{
|
1061 |
+
$this->task=WPvivid_taskmanager::get_task($this->task['id']);
|
1062 |
+
$this->task['data']['backup']['sub_job'][$key]['job_data'][basename($package['path'])]=$package;
|
1063 |
+
if($file_data!==false)
|
1064 |
+
{
|
1065 |
+
$this->task['data']['backup']['sub_job'][$key]['job_data']['files'][]=$file_data;
|
1066 |
+
}
|
1067 |
+
WPvivid_Setting::update_task($this->task['id'],$this->task);
|
1068 |
+
}
|
1069 |
+
|
1070 |
+
public function update_sub_task_progress($key,$finished,$progress)
|
1071 |
+
{
|
1072 |
+
$this->task=WPvivid_taskmanager::get_task($this->task['id']);
|
1073 |
+
$this->task['status']['run_time']=time();
|
1074 |
+
$this->task['status']['str']='running';
|
1075 |
+
$this->task['data']['doing']='backup';
|
1076 |
+
$sub_job_name=$key;
|
1077 |
+
$this->task['data']['backup']['doing']=$key;
|
1078 |
+
$this->task['data']['backup']['sub_job'][$sub_job_name]['finished']=$finished;
|
1079 |
+
$this->task['data']['backup']['sub_job'][$sub_job_name]['progress']=$progress;
|
1080 |
+
if(!isset( $this->task['data']['backup']['sub_job'][$sub_job_name]['job_data']))
|
1081 |
+
{
|
1082 |
+
$this->task['data']['backup']['sub_job'][$sub_job_name]['job_data']=array();
|
1083 |
+
}
|
1084 |
+
WPvivid_Setting::update_task($this->task['id'],$this->task);
|
1085 |
+
}
|
1086 |
+
|
1087 |
+
public function get_need_backup_folder($backup_data)
|
1088 |
+
{
|
1089 |
+
if(isset($backup_data['files'])&&empty($backup_data['files']))
|
1090 |
+
{
|
1091 |
+
return $backup_data['files'];
|
1092 |
+
}
|
1093 |
+
else
|
1094 |
+
{
|
1095 |
+
return $this->get_folder_list($backup_data['files_root'],$backup_data['exclude_regex'],$backup_data['include_regex'],$this->task['options']['backup_options']['compress']['exclude_file_size']);
|
1096 |
+
}
|
1097 |
+
}
|
1098 |
+
|
1099 |
+
public function get_folder_list($root,$exclude_regex,$include_regex,$exclude_file_size)
|
1100 |
+
{
|
1101 |
+
$files=array();
|
1102 |
+
$this->getFolder($files,$root,$exclude_regex,$include_regex,$exclude_file_size);
|
1103 |
+
return $files;
|
1104 |
+
}
|
1105 |
+
|
1106 |
+
public function getFolder(&$files,$path,$exclude_regex=array(),$include_regex=array(),$exclude_file_size=array(),$include_dir = true)
|
1107 |
+
{
|
1108 |
+
$count = 0;
|
1109 |
+
if(is_dir($path))
|
1110 |
+
{
|
1111 |
+
$handler = opendir($path);
|
1112 |
+
while (($filename = readdir($handler)) !== false)
|
1113 |
+
{
|
1114 |
+
if ($filename != "." && $filename != "..")
|
1115 |
+
{
|
1116 |
+
$count++;
|
1117 |
+
|
1118 |
+
if (is_dir($path . DIRECTORY_SEPARATOR . $filename))
|
1119 |
+
{
|
1120 |
+
if ($this->regex_match($exclude_regex, $path . DIRECTORY_SEPARATOR . $filename, 0))
|
1121 |
+
{
|
1122 |
+
if ($this->regex_match($include_regex, $path . DIRECTORY_SEPARATOR . $filename, 1))
|
1123 |
+
{
|
1124 |
+
$files[] = $path . DIRECTORY_SEPARATOR . $filename;
|
1125 |
+
}
|
1126 |
+
}
|
1127 |
+
} else {
|
1128 |
+
if($this->regex_match($exclude_regex, $path . DIRECTORY_SEPARATOR . $filename, 0)){
|
1129 |
+
if ($exclude_file_size == 0)
|
1130 |
+
{
|
1131 |
+
$files[] = $path . DIRECTORY_SEPARATOR . $filename;
|
1132 |
+
} else {
|
1133 |
+
if (filesize($path . DIRECTORY_SEPARATOR . $filename) < $exclude_file_size * 1024 * 1024)
|
1134 |
+
{
|
1135 |
+
$files[] = $path . DIRECTORY_SEPARATOR . $filename;
|
1136 |
+
}
|
1137 |
+
}
|
1138 |
+
}
|
1139 |
+
}
|
1140 |
+
}
|
1141 |
+
}
|
1142 |
+
if($handler)
|
1143 |
+
@closedir($handler);
|
1144 |
+
}
|
1145 |
+
if($include_dir && $count == 0)
|
1146 |
+
{
|
1147 |
+
$files[] = $path;
|
1148 |
+
}
|
1149 |
+
}
|
1150 |
+
|
1151 |
+
public function get_need_uploads_backup_folder($backup_data)
|
1152 |
+
{
|
1153 |
+
if(isset($backup_data['files'])&&empty($backup_data['files']))
|
1154 |
+
{
|
1155 |
+
return $backup_data['files'];
|
1156 |
+
}
|
1157 |
+
else
|
1158 |
+
{
|
1159 |
+
return $this->get_uploads_folder_list($backup_data['files_root'],$backup_data['exclude_regex'],$backup_data['include_regex'],$this->task['options']['backup_options']['compress']['exclude_file_size']);
|
1160 |
+
}
|
1161 |
+
}
|
1162 |
+
|
1163 |
+
public function get_uploads_folder_list($root,$exclude_regex,$include_regex,$exclude_file_size)
|
1164 |
+
{
|
1165 |
+
$files=array();
|
1166 |
+
$this->getUploadsFolder($files,$root,$exclude_regex,$include_regex,$exclude_file_size);
|
1167 |
+
return $files;
|
1168 |
+
}
|
1169 |
+
|
1170 |
+
public function getUploadsFolder(&$files,$path,$exclude_regex=array(),$include_regex=array(),$exclude_file_size=array(),$include_dir = true,$subdir=false)
|
1171 |
+
{
|
1172 |
+
$count = 0;
|
1173 |
+
if(is_dir($path))
|
1174 |
+
{
|
1175 |
+
$handler = opendir($path);
|
1176 |
+
while (($filename = readdir($handler)) !== false)
|
1177 |
+
{
|
1178 |
+
if ($filename != "." && $filename != "..")
|
1179 |
+
{
|
1180 |
+
$count++;
|
1181 |
+
|
1182 |
+
if (is_dir($path . DIRECTORY_SEPARATOR . $filename))
|
1183 |
+
{
|
1184 |
+
if ($this->regex_match($exclude_regex, $path . DIRECTORY_SEPARATOR . $filename, 0))
|
1185 |
+
{
|
1186 |
+
if ($this->regex_match($include_regex, $path . DIRECTORY_SEPARATOR . $filename, 1))
|
1187 |
+
{
|
1188 |
+
if($subdir)
|
1189 |
+
$files[] = $path . DIRECTORY_SEPARATOR . $filename;
|
1190 |
+
else
|
1191 |
+
$this->getUploadsFolder($files,$path . DIRECTORY_SEPARATOR . $filename,$exclude_regex,$include_regex,$exclude_file_size,$include_dir,true);
|
1192 |
+
}
|
1193 |
+
}
|
1194 |
+
} else {
|
1195 |
+
if($this->regex_match($exclude_regex, $path . DIRECTORY_SEPARATOR . $filename, 0))
|
1196 |
+
{
|
1197 |
+
if ($exclude_file_size == 0)
|
1198 |
+
{
|
1199 |
+
//if($subdir)
|
1200 |
+
// $files[] = $path . DIRECTORY_SEPARATOR . $filename;
|
1201 |
+
} else {
|
1202 |
+
if (filesize($path . DIRECTORY_SEPARATOR . $filename) < $exclude_file_size * 1024 * 1024)
|
1203 |
+
{
|
1204 |
+
//if($subdir)
|
1205 |
+
// $files[] = $path . DIRECTORY_SEPARATOR . $filename;
|
1206 |
+
}
|
1207 |
+
}
|
1208 |
+
}
|
1209 |
+
}
|
1210 |
+
}
|
1211 |
+
}
|
1212 |
+
if($handler)
|
1213 |
+
@closedir($handler);
|
1214 |
+
}
|
1215 |
+
if($include_dir && $count == 0)
|
1216 |
+
{
|
1217 |
+
if($subdir)
|
1218 |
+
$files[] = $path;
|
1219 |
+
}
|
1220 |
+
}
|
1221 |
}
|
1222 |
|
1223 |
class WPvivid_Backup_Item
|
1580 |
{
|
1581 |
$zip=new WPvivid_ZipClass();
|
1582 |
$json=$zip->get_json_data($file_name);
|
|
|
1583 |
$json=json_decode($json,1);
|
1584 |
if(is_null($json))
|
1585 |
{
|
1806 |
{
|
1807 |
global $wpvivid_pulgin;
|
1808 |
$wpvivid_pulgin->set_time_limit($this->task->get_id());
|
1809 |
+
$this->task->update_sub_task_progress($next_backup['key'],0,'Start backing up '.$next_backup['key'].'.');
|
1810 |
+
//WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'backup', $next_backup['key'],0,'Start backing up '.$next_backup['key'].'.');
|
1811 |
$wpvivid_pulgin->wpvivid_log->WriteLog('Prepare to backup '.$next_backup['key'].' files.','notice');
|
1812 |
if(isset($next_backup['files'])) {
|
1813 |
$wpvivid_pulgin->wpvivid_log->WriteLog('File number: ' . sizeof($next_backup['files']), 'notice');
|
1814 |
}
|
1815 |
$result = $this->_backup($next_backup);
|
1816 |
$wpvivid_pulgin->wpvivid_log->WriteLog('Backing up '.$next_backup['key'].' completed.','notice');
|
1817 |
+
$this->task->update_sub_task_progress($next_backup['key'],1,'Backing up '.$next_backup['key'].' finished.');
|
1818 |
+
//WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'backup', $next_backup['key'],1,'Backing up '.$next_backup['key'].' finished.',$result);
|
1819 |
$this->task->update_backup_result($next_backup,$result);
|
1820 |
$wpvivid_pulgin->check_cancel_backup($task_id);
|
1821 |
unset($next_backup);
|
1849 |
return $result;
|
1850 |
}
|
1851 |
}
|
1852 |
+
|
1853 |
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-zipclass.php';
|
1854 |
|
1855 |
$zip = new WPvivid_ZipClass();
|
1858 |
return $zip->last_error;
|
1859 |
}
|
1860 |
|
1861 |
+
if(isset($data['resume_packages']))
|
1862 |
+
{
|
1863 |
+
global $wpvivid_pulgin;
|
1864 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog('Start compressing '.$data['key'],'notice');
|
1865 |
|
1866 |
+
if($data['key']==WPVIVID_BACKUP_TYPE_PLUGIN)
|
1867 |
+
{
|
1868 |
+
$ret =$zip->get_plugin_packages($data);
|
1869 |
+
}
|
1870 |
+
else if($data['key']==WPVIVID_BACKUP_TYPE_UPLOADS_FILES)
|
1871 |
+
{
|
1872 |
+
$ret =$zip->get_upload_packages($data);
|
1873 |
+
}
|
1874 |
+
else
|
1875 |
+
{
|
1876 |
+
$ret =$zip->get_packages($data);
|
1877 |
+
}
|
1878 |
+
|
1879 |
+
$packages=$this->task->get_packages_info($data['key']);
|
1880 |
+
if($packages===false)
|
1881 |
+
{
|
1882 |
+
$packages=$this->task->set_packages_info($data['key'],$ret['packages']);
|
1883 |
+
}
|
1884 |
+
|
1885 |
+
define(PCLZIP_TEMPORARY_DIR,$ret['temp_dir']);
|
1886 |
+
|
1887 |
+
$result['result']=WPVIVID_SUCCESS;
|
1888 |
+
$result['files']=array();
|
1889 |
+
|
1890 |
+
foreach ($packages as $package)
|
1891 |
+
{
|
1892 |
+
if(!empty($package['files'])&&$package['backup']==false)
|
1893 |
+
{
|
1894 |
+
$zip_ret=$zip->_zip($package['path'],$package['files'], $data,$package['json']);
|
1895 |
+
if($zip_ret['result']==WPVIVID_SUCCESS)
|
1896 |
+
{
|
1897 |
+
$result['files'][] = $zip_ret['file_data'];
|
1898 |
+
$package['backup']=true;
|
1899 |
+
$this->task->update_packages_info($data['key'],$package,$zip_ret['file_data']);
|
1900 |
+
}
|
1901 |
+
else
|
1902 |
+
{
|
1903 |
+
$result=$zip_ret;
|
1904 |
+
break;
|
1905 |
+
}
|
1906 |
+
}else {
|
1907 |
+
continue;
|
1908 |
+
}
|
1909 |
+
}
|
1910 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog('Compressing '.$data['key'].' completed','notice');
|
1911 |
+
return $result;
|
1912 |
+
}
|
1913 |
+
else
|
1914 |
+
{
|
1915 |
+
$result =$zip->compress($data);
|
1916 |
+
|
1917 |
+
if(isset($data['dump_db']))
|
1918 |
+
{
|
1919 |
+
foreach ($data['files'] as $sql_file)
|
1920 |
+
{
|
1921 |
+
@unlink($sql_file);
|
1922 |
+
}
|
1923 |
+
}
|
1924 |
+
}
|
1925 |
+
|
1926 |
+
return $result;
|
1927 |
+
|
1928 |
+
/*
|
1929 |
+
if(isset($data['has_child']))
|
1930 |
+
{
|
1931 |
+
global $wpvivid_pulgin;
|
1932 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog('Start compressing '.$data['key'],'notice');
|
1933 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog('has_child','notice');
|
1934 |
+
|
1935 |
+
$ret =$zip->get_packages($data);
|
1936 |
+
|
1937 |
+
$packages=$this->task->get_packages_info(WPVIVID_BACKUP_TYPE_MERGE);
|
1938 |
+
if($packages===false)
|
1939 |
+
{
|
1940 |
+
$packages=$this->task->set_packages_info(WPVIVID_BACKUP_TYPE_MERGE,$ret['packages']);
|
1941 |
+
}
|
1942 |
+
|
1943 |
+
define(PCLZIP_TEMPORARY_DIR,$ret['temp_dir']);
|
1944 |
+
|
1945 |
+
$result['result']=WPVIVID_SUCCESS;
|
1946 |
+
$result['files']=array();
|
1947 |
+
|
1948 |
+
foreach ($packages as $package)
|
1949 |
+
{
|
1950 |
+
if(!empty($package['files'])&&$package['backup']==false)
|
1951 |
+
{
|
1952 |
+
$zip_ret=$zip->_zip($package['path'],$package['files'], $data,$package['json']);
|
1953 |
+
if($zip_ret['result']==WPVIVID_SUCCESS)
|
1954 |
+
{
|
1955 |
+
$result['files'][] = $zip_ret['file_data'];
|
1956 |
+
$package['backup']=true;
|
1957 |
+
$this->task->update_packages_info(WPVIVID_BACKUP_TYPE_MERGE,$package);
|
1958 |
+
}
|
1959 |
+
else
|
1960 |
+
{
|
1961 |
+
$result=$zip_ret;
|
1962 |
+
break;
|
1963 |
+
}
|
1964 |
+
}else {
|
1965 |
+
continue;
|
1966 |
+
}
|
1967 |
+
}
|
1968 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog('Compressing '.$data['key'].' completed','notice');
|
1969 |
+
return $result;
|
1970 |
+
}
|
1971 |
+
else if(isset($data['wp_plugin']))
|
1972 |
{
|
1973 |
+
global $wpvivid_pulgin;
|
1974 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog('Start compressing '.$data['key'],'notice');
|
1975 |
+
|
1976 |
+
$ret =$zip->get_plugin_packages($data);
|
1977 |
+
|
1978 |
+
$packages=$this->task->get_packages_info(WPVIVID_BACKUP_TYPE_PLUGIN);
|
1979 |
+
if($packages===false)
|
1980 |
{
|
1981 |
+
$packages=$this->task->set_packages_info(WPVIVID_BACKUP_TYPE_PLUGIN,$ret['packages']);
|
1982 |
+
}
|
1983 |
+
|
1984 |
+
define(PCLZIP_TEMPORARY_DIR,$ret['temp_dir']);
|
1985 |
+
|
1986 |
+
$result['result']=WPVIVID_SUCCESS;
|
1987 |
+
$result['files']=array();
|
1988 |
+
|
1989 |
+
foreach ($packages as $package)
|
1990 |
+
{
|
1991 |
+
if(!empty($package['files'])&&$package['backup']==false)
|
1992 |
+
{
|
1993 |
+
$zip_ret=$zip->_zip($package['path'],$package['files'], $data,$package['json']);
|
1994 |
+
if($zip_ret['result']==WPVIVID_SUCCESS)
|
1995 |
+
{
|
1996 |
+
$result['files'][] = $zip_ret['file_data'];
|
1997 |
+
$package['backup']=true;
|
1998 |
+
$this->task->update_packages_info(WPVIVID_BACKUP_TYPE_PLUGIN,$package,$zip_ret['file_data']);
|
1999 |
+
}
|
2000 |
+
else
|
2001 |
+
{
|
2002 |
+
$result=$zip_ret;
|
2003 |
+
break;
|
2004 |
+
}
|
2005 |
+
}else {
|
2006 |
+
continue;
|
2007 |
+
}
|
2008 |
+
}
|
2009 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog('Compressing '.$data['key'].' completed','notice');
|
2010 |
+
return $result;
|
2011 |
+
}
|
2012 |
+
else
|
2013 |
+
{
|
2014 |
+
$result =$zip->compress($data);
|
2015 |
+
|
2016 |
+
if(isset($data['dump_db']))
|
2017 |
+
{
|
2018 |
+
foreach ($data['files'] as $sql_file)
|
2019 |
+
{
|
2020 |
+
@unlink($sql_file);
|
2021 |
+
}
|
2022 |
}
|
2023 |
}
|
2024 |
|
2025 |
return $result;
|
2026 |
+
*/
|
2027 |
}
|
2028 |
|
2029 |
public function cleanup()
|
2133 |
if (is_dir($path . DIRECTORY_SEPARATOR . $filename)) {
|
2134 |
if ($this->regex_match($exclude_regex['directory'], $path . DIRECTORY_SEPARATOR . $filename, 0)) {
|
2135 |
if ($this->regex_match($include_regex, $path . DIRECTORY_SEPARATOR . $filename, 1)) {
|
2136 |
+
$this->getFileLoop($files, $path . DIRECTORY_SEPARATOR . $filename, $exclude_regex, $include_regex, $exclude_file_size, $include_dir);
|
2137 |
}
|
2138 |
}
|
2139 |
} else {
|
includes/class-wpvivid-db-method.php
ADDED
@@ -0,0 +1,268 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Created by PhpStorm.
|
4 |
+
* User: alienware`x
|
5 |
+
* Date: 2019/6/10
|
6 |
+
* Time: 13:04
|
7 |
+
*/
|
8 |
+
|
9 |
+
class WPvivid_DB_Method
|
10 |
+
{
|
11 |
+
public $db_handle;
|
12 |
+
public $type;
|
13 |
+
|
14 |
+
public function connect_db()
|
15 |
+
{
|
16 |
+
if(class_exists('PDO'))
|
17 |
+
{
|
18 |
+
$extensions=get_loaded_extensions();
|
19 |
+
if(array_search('pdo_mysql',$extensions))
|
20 |
+
{
|
21 |
+
$this->db_handle=new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD );
|
22 |
+
$this->type='pdo_mysql';
|
23 |
+
return;
|
24 |
+
}
|
25 |
+
}
|
26 |
+
global $wpdb;
|
27 |
+
$this->db_handle=$wpdb;
|
28 |
+
$this->type='wpdb';
|
29 |
+
|
30 |
+
return array('result'=>WPVIVID_SUCCESS);
|
31 |
+
}
|
32 |
+
|
33 |
+
public function check_db($fcgi)
|
34 |
+
{
|
35 |
+
$ret=$this->connect_db();
|
36 |
+
|
37 |
+
if($ret['result']==WPVIVID_FAILED)
|
38 |
+
{
|
39 |
+
return $ret;
|
40 |
+
}
|
41 |
+
|
42 |
+
if($this->type=='pdo_mysql')
|
43 |
+
{
|
44 |
+
return $this->check_db_pdo($fcgi);
|
45 |
+
}
|
46 |
+
else if($this->type=='wpdb')
|
47 |
+
{
|
48 |
+
return $this->check_db_wpdb($fcgi);
|
49 |
+
}
|
50 |
+
|
51 |
+
return array('result' => WPVIVID_FAILED,'error' => 'db handle type not found.');
|
52 |
+
}
|
53 |
+
|
54 |
+
public function check_db_pdo($fcgi)
|
55 |
+
{
|
56 |
+
$ret['alert_db']=false;
|
57 |
+
$ret['result']=WPVIVID_SUCCESS;
|
58 |
+
$ret['big_tables']=array();
|
59 |
+
$db_info=array();
|
60 |
+
|
61 |
+
$sth = $this->db_handle->query('SHOW TABLE STATUS');
|
62 |
+
$dbSize = 0;
|
63 |
+
$sum_rows=0;
|
64 |
+
$rows = $sth->fetchAll();
|
65 |
+
foreach ($rows as $row)
|
66 |
+
{
|
67 |
+
global $wpdb;
|
68 |
+
if (is_multisite() && !defined('MULTISITE'))
|
69 |
+
{
|
70 |
+
$prefix = $wpdb->base_prefix;
|
71 |
+
} else {
|
72 |
+
$prefix = $wpdb->get_blog_prefix(0);
|
73 |
+
}
|
74 |
+
if(preg_match('/^(?!'.$prefix.')/', $row["Name"]) == 1){
|
75 |
+
continue;
|
76 |
+
}
|
77 |
+
|
78 |
+
$db_info[$row["Name"]]["Rows"]=$row["Rows"];
|
79 |
+
$db_info[$row["Name"]]["Data_length"]=size_format($row["Data_length"]+$row["Index_length"],2);
|
80 |
+
if($row["Rows"]>1000000)
|
81 |
+
{
|
82 |
+
$ret['big_tables'][$row["Name"]]['Rows']=$row["Rows"];
|
83 |
+
$ret['big_tables'][$row["Name"]]['Data_length']=size_format($row["Data_length"]+$row["Index_length"],2);
|
84 |
+
}
|
85 |
+
|
86 |
+
$sum_rows+=$row["Rows"];
|
87 |
+
$dbSize+=$row["Data_length"]+$row["Index_length"];
|
88 |
+
}
|
89 |
+
if($fcgi)
|
90 |
+
{
|
91 |
+
$alter_sum_rows=4000000;
|
92 |
+
}
|
93 |
+
else
|
94 |
+
{
|
95 |
+
$alter_sum_rows=4000000*3;
|
96 |
+
}
|
97 |
+
|
98 |
+
$memory_limit = ini_get('memory_limit');
|
99 |
+
$ret['memory_limit']=$memory_limit;
|
100 |
+
$memory_limit = trim($memory_limit);
|
101 |
+
$memory_limit_int = (int) $memory_limit;
|
102 |
+
$last = strtolower(substr($memory_limit, -1));
|
103 |
+
|
104 |
+
if($last == 'g')
|
105 |
+
$memory_limit_int = $memory_limit_int*1024*1024*1024;
|
106 |
+
if($last == 'm')
|
107 |
+
$memory_limit_int = $memory_limit_int*1024*1024;
|
108 |
+
if($last == 'k')
|
109 |
+
$memory_limit_int = $memory_limit_int*1024;
|
110 |
+
|
111 |
+
if($dbSize>($memory_limit_int*0.9))
|
112 |
+
{
|
113 |
+
$max_rows=0;
|
114 |
+
}
|
115 |
+
else
|
116 |
+
{
|
117 |
+
$max_rows=(($memory_limit_int*0.9)-$dbSize)/49;
|
118 |
+
}
|
119 |
+
|
120 |
+
$max_rows=max($max_rows,1048576);
|
121 |
+
|
122 |
+
if($sum_rows>$alter_sum_rows||$sum_rows>$max_rows)
|
123 |
+
{
|
124 |
+
//big db alert
|
125 |
+
$ret['alert_db']=true;
|
126 |
+
$ret['sum_rows']=$sum_rows;
|
127 |
+
$ret['db_size']=size_format($dbSize,2);
|
128 |
+
if($fcgi)
|
129 |
+
$ret['alter_fcgi']=true;
|
130 |
+
}
|
131 |
+
|
132 |
+
$ret['db_size']=size_format($dbSize,2);
|
133 |
+
return $ret;
|
134 |
+
}
|
135 |
+
|
136 |
+
public function check_db_wpdb($fcgi)
|
137 |
+
{
|
138 |
+
$ret['alert_db']=false;
|
139 |
+
$ret['result']=WPVIVID_SUCCESS;
|
140 |
+
$ret['big_tables']=array();
|
141 |
+
$db_info=array();
|
142 |
+
|
143 |
+
global $wpdb;
|
144 |
+
$result=$wpdb->get_results('SHOW TABLE STATUS',ARRAY_A);
|
145 |
+
|
146 |
+
//$sth = $this->db_handle->query('SHOW TABLE STATUS');
|
147 |
+
$dbSize = 0;
|
148 |
+
$sum_rows=0;
|
149 |
+
//$rows = $sth->fetchAll();
|
150 |
+
foreach ($result as $row)
|
151 |
+
{
|
152 |
+
global $wpdb;
|
153 |
+
if (is_multisite() && !defined('MULTISITE'))
|
154 |
+
{
|
155 |
+
$prefix = $wpdb->base_prefix;
|
156 |
+
} else {
|
157 |
+
$prefix = $wpdb->get_blog_prefix(0);
|
158 |
+
}
|
159 |
+
if(preg_match('/^(?!'.$prefix.')/', $row["Name"]) == 1){
|
160 |
+
continue;
|
161 |
+
}
|
162 |
+
|
163 |
+
$db_info[$row["Name"]]["Rows"]=$row["Rows"];
|
164 |
+
$db_info[$row["Name"]]["Data_length"]=size_format($row["Data_length"]+$row["Index_length"],2);
|
165 |
+
if($row["Rows"]>1000000)
|
166 |
+
{
|
167 |
+
$ret['big_tables'][$row["Name"]]['Rows']=$row["Rows"];
|
168 |
+
$ret['big_tables'][$row["Name"]]['Data_length']=size_format($row["Data_length"]+$row["Index_length"],2);
|
169 |
+
}
|
170 |
+
|
171 |
+
$sum_rows+=$row["Rows"];
|
172 |
+
$dbSize+=$row["Data_length"]+$row["Index_length"];
|
173 |
+
}
|
174 |
+
if($fcgi)
|
175 |
+
{
|
176 |
+
$alter_sum_rows=4000000;
|
177 |
+
}
|
178 |
+
else
|
179 |
+
{
|
180 |
+
$alter_sum_rows=4000000*3;
|
181 |
+
}
|
182 |
+
|
183 |
+
$memory_limit = ini_get('memory_limit');
|
184 |
+
$ret['memory_limit']=$memory_limit;
|
185 |
+
$memory_limit = trim($memory_limit);
|
186 |
+
$memory_limit_int = (int) $memory_limit;
|
187 |
+
$last = strtolower(substr($memory_limit, -1));
|
188 |
+
|
189 |
+
if($last == 'g')
|
190 |
+
$memory_limit_int = $memory_limit_int*1024*1024*1024;
|
191 |
+
if($last == 'm')
|
192 |
+
$memory_limit_int = $memory_limit_int*1024*1024;
|
193 |
+
if($last == 'k')
|
194 |
+
$memory_limit_int = $memory_limit_int*1024;
|
195 |
+
|
196 |
+
if($dbSize>($memory_limit_int*0.9))
|
197 |
+
{
|
198 |
+
$max_rows=0;
|
199 |
+
}
|
200 |
+
else
|
201 |
+
{
|
202 |
+
$max_rows=(($memory_limit_int*0.9)-$dbSize)/49;
|
203 |
+
}
|
204 |
+
|
205 |
+
$max_rows=max($max_rows,1048576);
|
206 |
+
|
207 |
+
if($sum_rows>$alter_sum_rows||$sum_rows>$max_rows)
|
208 |
+
{
|
209 |
+
//big db alert
|
210 |
+
$ret['alert_db']=true;
|
211 |
+
$ret['sum_rows']=$sum_rows;
|
212 |
+
$ret['db_size']=size_format($dbSize,2);
|
213 |
+
if($fcgi)
|
214 |
+
$ret['alter_fcgi']=true;
|
215 |
+
}
|
216 |
+
|
217 |
+
$ret['db_size']=size_format($dbSize,2);
|
218 |
+
return $ret;
|
219 |
+
}
|
220 |
+
|
221 |
+
public function get_sql_mode()
|
222 |
+
{
|
223 |
+
$ret=$this->connect_db();
|
224 |
+
|
225 |
+
if($ret['result']==WPVIVID_FAILED)
|
226 |
+
{
|
227 |
+
return $ret;
|
228 |
+
}
|
229 |
+
$ret['result']=WPVIVID_SUCCESS;
|
230 |
+
$ret['mysql_mode']='';
|
231 |
+
|
232 |
+
if($this->type=='pdo_mysql')
|
233 |
+
{
|
234 |
+
$rows = $this->db_handle->query('SELECT @@SESSION.sql_mode');
|
235 |
+
foreach ($rows as $row)
|
236 |
+
{
|
237 |
+
$ret['mysql_mode']=$row["@@SESSION.sql_mode"];
|
238 |
+
}
|
239 |
+
}
|
240 |
+
|
241 |
+
return $ret;
|
242 |
+
}
|
243 |
+
|
244 |
+
public function get_mysql_version()
|
245 |
+
{
|
246 |
+
global $wpdb;
|
247 |
+
|
248 |
+
$mysql_version = $wpdb->db_version();
|
249 |
+
|
250 |
+
return $mysql_version;
|
251 |
+
}
|
252 |
+
|
253 |
+
public function check_max_allowed_packet()
|
254 |
+
{
|
255 |
+
global $wpvivid_pulgin,$wpdb;
|
256 |
+
|
257 |
+
$max_allowed_packet = (int) $wpdb->get_var("SELECT @@session.max_allowed_packet");
|
258 |
+
|
259 |
+
if($max_allowed_packet<1048576)
|
260 |
+
{
|
261 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog('warning: max_allowed_packet less than 1M :'.size_format($max_allowed_packet,2),'notice');
|
262 |
+
}
|
263 |
+
else if($max_allowed_packet<33554432)
|
264 |
+
{
|
265 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog('max_allowed_packet less than 32M :'.size_format($max_allowed_packet,2),'notice');
|
266 |
+
}
|
267 |
+
}
|
268 |
+
}
|
includes/class-wpvivid-migrate.php
CHANGED
@@ -137,7 +137,7 @@ class WPvivid_Migrate
|
|
137 |
else
|
138 |
{
|
139 |
$ret['result']=WPVIVID_FAILED;
|
140 |
-
$ret['error']= '
|
141 |
}
|
142 |
}
|
143 |
else
|
@@ -335,7 +335,7 @@ class WPvivid_Migrate
|
|
335 |
}
|
336 |
else {
|
337 |
$ret['result']=WPVIVID_FAILED;
|
338 |
-
$ret['error']= '
|
339 |
$ret['response']=$response;
|
340 |
echo json_encode($ret);
|
341 |
die();
|
@@ -595,6 +595,9 @@ class WPvivid_Migrate
|
|
595 |
</div>
|
596 |
<div style="margin-left:10px; float: left; width:100%;"><p id="wpvivid_upload_current_doing"></p></div>
|
597 |
<div style="clear: both;"></div>
|
|
|
|
|
|
|
598 |
</div>
|
599 |
</div>
|
600 |
|
@@ -626,7 +629,7 @@ class WPvivid_Migrate
|
|
626 |
|
627 |
<div style="padding: 0 0 10px 0;">
|
628 |
<div id="wpvivid_transfer_btn" style="float: left;">
|
629 |
-
<input class="button-primary quicktransfer-btn" type="submit" value="<?php esc_attr_e( 'Transfer', 'wpvivid'); ?>" onclick="wpvivid_click_send_backup();" />
|
630 |
</div>
|
631 |
</div>
|
632 |
<div style="clear: both;"></div>
|
@@ -662,7 +665,9 @@ class WPvivid_Migrate
|
|
662 |
//wpvivid_edit_url_button
|
663 |
jQuery('#wpvivid_add_remote_site_url').show();
|
664 |
jQuery('#wpvivid_upload_backup_percent').hide();
|
665 |
-
|
|
|
|
|
666 |
function wpvivid_check_key(value){
|
667 |
var pos = value.indexOf('?');
|
668 |
var site_url = value.substring(0, pos);
|
@@ -781,7 +786,6 @@ class WPvivid_Migrate
|
|
781 |
};
|
782 |
migrate_task_need_update=true;
|
783 |
wpvivid_clear_notice('wpvivid_backup_notice');
|
784 |
-
//jQuery('#wpvivid_transfer_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
|
785 |
wpvivid_control_transfer_lock();
|
786 |
wpvivid_post_request(ajax_data, function (data)
|
787 |
{
|
@@ -793,6 +797,7 @@ class WPvivid_Migrate
|
|
793 |
wpvivid_delete_transfer_ready_task(jsonarray.error);
|
794 |
}
|
795 |
else{
|
|
|
796 |
wpvivid_migrate_now(jsonarray.task_id);
|
797 |
}
|
798 |
}
|
@@ -828,14 +833,12 @@ class WPvivid_Migrate
|
|
828 |
var jsonarray = jQuery.parseJSON(data);
|
829 |
if (jsonarray.result === 'success') {
|
830 |
wpvivid_add_notice('Backup', 'Error', error);
|
831 |
-
//jQuery('#wpvivid_transfer_btn').css({'pointer-events': 'auto', 'opacity': '1'});
|
832 |
wpvivid_control_transfer_unlock();
|
833 |
jQuery('#wpvivid_upload_backup_percent').hide();
|
834 |
}
|
835 |
}
|
836 |
catch(err){
|
837 |
wpvivid_add_notice('Backup', 'Error', err);
|
838 |
-
//jQuery('#wpvivid_transfer_btn').css({'pointer-events': 'auto', 'opacity': '1'});
|
839 |
wpvivid_control_transfer_unlock();
|
840 |
jQuery('#wpvivid_upload_backup_percent').hide();
|
841 |
}
|
@@ -848,7 +851,6 @@ class WPvivid_Migrate
|
|
848 |
|
849 |
function wpvivid_click_export_backup()
|
850 |
{
|
851 |
-
//alert("Export and Download Backup.");
|
852 |
var option_data = wpvivid_ajax_data_transfer('migrate');
|
853 |
var ajax_data = {
|
854 |
'action': 'wpvivid_export_download_backup',
|
@@ -887,6 +889,35 @@ class WPvivid_Migrate
|
|
887 |
}
|
888 |
}
|
889 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
890 |
var migrate_task_need_update=true;
|
891 |
var task_recheck_times=0;
|
892 |
function wpvivid_check_upload_runningtask()
|
@@ -918,30 +949,18 @@ class WPvivid_Migrate
|
|
918 |
if (jsonarray.transfer.result === 'success') {
|
919 |
jQuery.each(jsonarray.transfer.data, function (index, value) {
|
920 |
if (value.status.str === 'ready') {
|
921 |
-
/*jQuery('#wpvivid_transfer_btn').css({
|
922 |
-
'pointer-events': 'none',
|
923 |
-
'opacity': '0.4'
|
924 |
-
});*/
|
925 |
wpvivid_control_transfer_lock();
|
926 |
jQuery('#wpvivid_upload_backup_percent').show();
|
927 |
jQuery('#wpvivid_upload_backup_percent').html(value.progress_html);
|
928 |
migrate_task_need_update = true;
|
929 |
}
|
930 |
else if (value.status.str === 'running') {
|
931 |
-
/*jQuery('#wpvivid_transfer_btn').css({
|
932 |
-
'pointer-events': 'none',
|
933 |
-
'opacity': '0.4'
|
934 |
-
});*/
|
935 |
wpvivid_control_transfer_lock();
|
936 |
jQuery('#wpvivid_upload_backup_percent').show();
|
937 |
jQuery('#wpvivid_upload_backup_percent').html(value.progress_html);
|
938 |
migrate_task_need_update = true;
|
939 |
}
|
940 |
else if (value.status.str === 'wait_resume') {
|
941 |
-
/*jQuery('#wpvivid_transfer_btn').css({
|
942 |
-
'pointer-events': 'none',
|
943 |
-
'opacity': '0.4'
|
944 |
-
});*/
|
945 |
wpvivid_control_transfer_lock();
|
946 |
jQuery('#wpvivid_upload_backup_percent').show();
|
947 |
jQuery('#wpvivid_upload_backup_percent').html(value.progress_html);
|
@@ -953,30 +972,18 @@ class WPvivid_Migrate
|
|
953 |
}
|
954 |
}
|
955 |
else if (value.status.str === 'no_responds') {
|
956 |
-
/*jQuery('#wpvivid_transfer_btn').css({
|
957 |
-
'pointer-events': 'none',
|
958 |
-
'opacity': '0.4'
|
959 |
-
});*/
|
960 |
wpvivid_control_transfer_lock();
|
961 |
jQuery('#wpvivid_upload_backup_percent').show();
|
962 |
jQuery('#wpvivid_upload_backup_percent').html(value.progress_html);
|
963 |
migrate_task_need_update = true;
|
964 |
}
|
965 |
else if (value.status.str === 'completed') {
|
966 |
-
/*jQuery('#wpvivid_transfer_btn').css({
|
967 |
-
'pointer-events': 'auto',
|
968 |
-
'opacity': '1'
|
969 |
-
});*/
|
970 |
wpvivid_control_transfer_unlock();
|
971 |
jQuery('#wpvivid_upload_backup_percent').html(value.progress_html);
|
972 |
jQuery('#wpvivid_upload_backup_percent').hide();
|
973 |
migrate_task_need_update = true;
|
974 |
}
|
975 |
else if (value.status.str === 'error') {
|
976 |
-
/*jQuery('#wpvivid_transfer_btn').css({
|
977 |
-
'pointer-events': 'auto',
|
978 |
-
'opacity': '1'
|
979 |
-
});*/
|
980 |
wpvivid_control_transfer_unlock();
|
981 |
jQuery('#wpvivid_upload_backup_percent').html(value.progress_html);
|
982 |
jQuery('#wpvivid_upload_backup_percent').hide();
|
@@ -984,6 +991,15 @@ class WPvivid_Migrate
|
|
984 |
}
|
985 |
});
|
986 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
987 |
}
|
988 |
}
|
989 |
catch (err) {
|
@@ -1147,7 +1163,10 @@ class WPvivid_Migrate
|
|
1147 |
</div>
|
1148 |
<div style="clear:both;"></div>
|
1149 |
<div style="margin-left:10px; float: left; width:100%;"><p id="wpvivid_upload_current_doing">' . $list_tasks[$task['id']]['task_info']['descript'] . '</p></div>
|
1150 |
-
<div style="clear: both;"></div>
|
|
|
|
|
|
|
1151 |
}
|
1152 |
}
|
1153 |
WPvivid_taskmanager::delete_marked_task();
|
137 |
else
|
138 |
{
|
139 |
$ret['result']=WPVIVID_FAILED;
|
140 |
+
$ret['error']= 'failed to parse returned data. Unable to retrieve the correct authorization data via HTTP request.';
|
141 |
}
|
142 |
}
|
143 |
else
|
335 |
}
|
336 |
else {
|
337 |
$ret['result']=WPVIVID_FAILED;
|
338 |
+
$ret['error']= 'failed to parse returned data, unable to establish connection with the target site.';
|
339 |
$ret['response']=$response;
|
340 |
echo json_encode($ret);
|
341 |
die();
|
595 |
</div>
|
596 |
<div style="margin-left:10px; float: left; width:100%;"><p id="wpvivid_upload_current_doing"></p></div>
|
597 |
<div style="clear: both;"></div>
|
598 |
+
<div>
|
599 |
+
<div id="wpvivid_transfer_cancel" class="backup-log-btn"><input class="button-primary" id="wpvivid_transfer_cancel_btn" type="submit" value="<?php esc_attr_e( 'Cancel', 'wpvivid' ); ?>" /></div>
|
600 |
+
</div>
|
601 |
</div>
|
602 |
</div>
|
603 |
|
629 |
|
630 |
<div style="padding: 0 0 10px 0;">
|
631 |
<div id="wpvivid_transfer_btn" style="float: left;">
|
632 |
+
<input class="button-primary quicktransfer-btn" type="submit" value="<?php esc_attr_e( 'Clone then Transfer', 'wpvivid'); ?>" onclick="wpvivid_click_send_backup();" />
|
633 |
</div>
|
634 |
</div>
|
635 |
<div style="clear: both;"></div>
|
665 |
//wpvivid_edit_url_button
|
666 |
jQuery('#wpvivid_add_remote_site_url').show();
|
667 |
jQuery('#wpvivid_upload_backup_percent').hide();
|
668 |
+
|
669 |
+
var wpvivid_transfer_id = '';
|
670 |
+
|
671 |
function wpvivid_check_key(value){
|
672 |
var pos = value.indexOf('?');
|
673 |
var site_url = value.substring(0, pos);
|
786 |
};
|
787 |
migrate_task_need_update=true;
|
788 |
wpvivid_clear_notice('wpvivid_backup_notice');
|
|
|
789 |
wpvivid_control_transfer_lock();
|
790 |
wpvivid_post_request(ajax_data, function (data)
|
791 |
{
|
797 |
wpvivid_delete_transfer_ready_task(jsonarray.error);
|
798 |
}
|
799 |
else{
|
800 |
+
wpvivid_transfer_id = jsonarray.task_id;
|
801 |
wpvivid_migrate_now(jsonarray.task_id);
|
802 |
}
|
803 |
}
|
833 |
var jsonarray = jQuery.parseJSON(data);
|
834 |
if (jsonarray.result === 'success') {
|
835 |
wpvivid_add_notice('Backup', 'Error', error);
|
|
|
836 |
wpvivid_control_transfer_unlock();
|
837 |
jQuery('#wpvivid_upload_backup_percent').hide();
|
838 |
}
|
839 |
}
|
840 |
catch(err){
|
841 |
wpvivid_add_notice('Backup', 'Error', err);
|
|
|
842 |
wpvivid_control_transfer_unlock();
|
843 |
jQuery('#wpvivid_upload_backup_percent').hide();
|
844 |
}
|
851 |
|
852 |
function wpvivid_click_export_backup()
|
853 |
{
|
|
|
854 |
var option_data = wpvivid_ajax_data_transfer('migrate');
|
855 |
var ajax_data = {
|
856 |
'action': 'wpvivid_export_download_backup',
|
889 |
}
|
890 |
}
|
891 |
|
892 |
+
function wpvivid_transfer_cancel_flow()
|
893 |
+
{
|
894 |
+
jQuery('#wpvivid_transfer_cancel_btn').click(function(){
|
895 |
+
wpvivid_cancel_transfer();
|
896 |
+
});
|
897 |
+
}
|
898 |
+
|
899 |
+
function wpvivid_cancel_transfer()
|
900 |
+
{
|
901 |
+
var ajax_data= {
|
902 |
+
'action': 'wpvivid_backup_cancel',
|
903 |
+
'task_id': wpvivid_transfer_id
|
904 |
+
};
|
905 |
+
jQuery('#wpvivid_transfer_cancel_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
|
906 |
+
wpvivid_post_request(ajax_data, function(data){
|
907 |
+
try {
|
908 |
+
var jsonarray = jQuery.parseJSON(data);
|
909 |
+
jQuery('#wpvivid_upload_current_doing').html(jsonarray.msg);
|
910 |
+
}
|
911 |
+
catch(err){
|
912 |
+
alert(err);
|
913 |
+
}
|
914 |
+
}, function(XMLHttpRequest, textStatus, errorThrown) {
|
915 |
+
jQuery('#wpvivid_transfer_cancel_btn').css({'pointer-events': 'auto', 'opacity': '1'});
|
916 |
+
var error_message = wpvivid_output_ajaxerror('cancelling the backup', textStatus, errorThrown);
|
917 |
+
wpvivid_add_notice('Backup', 'Error', error_message);
|
918 |
+
});
|
919 |
+
}
|
920 |
+
|
921 |
var migrate_task_need_update=true;
|
922 |
var task_recheck_times=0;
|
923 |
function wpvivid_check_upload_runningtask()
|
949 |
if (jsonarray.transfer.result === 'success') {
|
950 |
jQuery.each(jsonarray.transfer.data, function (index, value) {
|
951 |
if (value.status.str === 'ready') {
|
|
|
|
|
|
|
|
|
952 |
wpvivid_control_transfer_lock();
|
953 |
jQuery('#wpvivid_upload_backup_percent').show();
|
954 |
jQuery('#wpvivid_upload_backup_percent').html(value.progress_html);
|
955 |
migrate_task_need_update = true;
|
956 |
}
|
957 |
else if (value.status.str === 'running') {
|
|
|
|
|
|
|
|
|
958 |
wpvivid_control_transfer_lock();
|
959 |
jQuery('#wpvivid_upload_backup_percent').show();
|
960 |
jQuery('#wpvivid_upload_backup_percent').html(value.progress_html);
|
961 |
migrate_task_need_update = true;
|
962 |
}
|
963 |
else if (value.status.str === 'wait_resume') {
|
|
|
|
|
|
|
|
|
964 |
wpvivid_control_transfer_lock();
|
965 |
jQuery('#wpvivid_upload_backup_percent').show();
|
966 |
jQuery('#wpvivid_upload_backup_percent').html(value.progress_html);
|
972 |
}
|
973 |
}
|
974 |
else if (value.status.str === 'no_responds') {
|
|
|
|
|
|
|
|
|
975 |
wpvivid_control_transfer_lock();
|
976 |
jQuery('#wpvivid_upload_backup_percent').show();
|
977 |
jQuery('#wpvivid_upload_backup_percent').html(value.progress_html);
|
978 |
migrate_task_need_update = true;
|
979 |
}
|
980 |
else if (value.status.str === 'completed') {
|
|
|
|
|
|
|
|
|
981 |
wpvivid_control_transfer_unlock();
|
982 |
jQuery('#wpvivid_upload_backup_percent').html(value.progress_html);
|
983 |
jQuery('#wpvivid_upload_backup_percent').hide();
|
984 |
migrate_task_need_update = true;
|
985 |
}
|
986 |
else if (value.status.str === 'error') {
|
|
|
|
|
|
|
|
|
987 |
wpvivid_control_transfer_unlock();
|
988 |
jQuery('#wpvivid_upload_backup_percent').html(value.progress_html);
|
989 |
jQuery('#wpvivid_upload_backup_percent').hide();
|
991 |
}
|
992 |
});
|
993 |
}
|
994 |
+
wpvivid_transfer_cancel_flow();
|
995 |
+
}
|
996 |
+
else{
|
997 |
+
if(wpvivid_transfer_id != '') {
|
998 |
+
jQuery('#wpvivid_transfer_cancel_btn').css({'pointer-events': 'auto', 'opacity': '1'});
|
999 |
+
wpvivid_control_transfer_unlock();
|
1000 |
+
jQuery('#wpvivid_upload_backup_percent').hide();
|
1001 |
+
wpvivid_transfer_id = '';
|
1002 |
+
}
|
1003 |
}
|
1004 |
}
|
1005 |
catch (err) {
|
1163 |
</div>
|
1164 |
<div style="clear:both;"></div>
|
1165 |
<div style="margin-left:10px; float: left; width:100%;"><p id="wpvivid_upload_current_doing">' . $list_tasks[$task['id']]['task_info']['descript'] . '</p></div>
|
1166 |
+
<div style="clear: both;"></div>
|
1167 |
+
<div>
|
1168 |
+
<div id="wpvivid_transfer_cancel" class="backup-log-btn"><input class="button-primary" id="wpvivid_transfer_cancel_btn" type="submit" value="'.esc_attr( 'Cancel', 'wpvivid' ).'" /></div>
|
1169 |
+
</div>';
|
1170 |
}
|
1171 |
}
|
1172 |
WPvivid_taskmanager::delete_marked_task();
|
includes/class-wpvivid-mysqldump-method.php
CHANGED
@@ -1,5 +1,8 @@
|
|
1 |
<?php
|
2 |
|
|
|
|
|
|
|
3 |
/**
|
4 |
* Enum with all available compression methods
|
5 |
*
|
@@ -405,6 +408,8 @@ class TypeAdapterSqlite extends TypeAdapterFactory
|
|
405 |
{
|
406 |
}
|
407 |
|
|
|
|
|
408 |
class TypeAdapterMysql extends TypeAdapterFactory
|
409 |
{
|
410 |
|
@@ -453,11 +458,17 @@ class TypeAdapterMysql extends TypeAdapterFactory
|
|
453 |
|
454 |
public function __construct ($dbHandler)
|
455 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
456 |
$this->dbHandler = $dbHandler;
|
457 |
$this->dsn='';
|
458 |
$this->user='';
|
459 |
$this->pass='';
|
460 |
-
$this->pdoSettings
|
461 |
$this->reconnect_count=0;
|
462 |
}
|
463 |
|
@@ -469,6 +480,37 @@ class TypeAdapterMysql extends TypeAdapterFactory
|
|
469 |
$this->pdoSettings=$pdoSetting;
|
470 |
}
|
471 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
472 |
public function databases()
|
473 |
{
|
474 |
$this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
|
@@ -524,7 +566,7 @@ class TypeAdapterMysql extends TypeAdapterFactory
|
|
524 |
throw new Exception("Error getting table code, unknown output");
|
525 |
}
|
526 |
|
527 |
-
$createTable = str_replace('\'0000-00-00 00:00:00\'','\'
|
528 |
|
529 |
if ( $dumpSettings['reset-auto-increment'] ) {
|
530 |
$match = "/AUTO_INCREMENT=[0-9]+/s";
|
@@ -946,8 +988,17 @@ class TypeAdapterMysql extends TypeAdapterFactory
|
|
946 |
$this->reconnect();
|
947 |
$this->reconnect_count++;
|
948 |
$ret= $this->dbHandler->query($string);
|
|
|
|
|
|
|
|
|
949 |
}
|
950 |
}
|
|
|
|
|
|
|
|
|
|
|
951 |
return $ret;
|
952 |
}
|
953 |
|
@@ -981,6 +1032,11 @@ class TypeAdapterMysql extends TypeAdapterFactory
|
|
981 |
$this->pdoSettings
|
982 |
);
|
983 |
}
|
|
|
|
|
|
|
|
|
|
|
984 |
}
|
985 |
|
986 |
class TypeAdapterWpdb extends TypeAdapterFactory
|
@@ -1028,6 +1084,13 @@ class TypeAdapterWpdb extends TypeAdapterFactory
|
|
1028 |
$this->dbHandler = $dbHandler;
|
1029 |
}
|
1030 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1031 |
public function databases()
|
1032 |
{
|
1033 |
$this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
|
@@ -1083,7 +1146,7 @@ class TypeAdapterWpdb extends TypeAdapterFactory
|
|
1083 |
throw new Exception("Error getting table code, unknown output");
|
1084 |
}
|
1085 |
|
1086 |
-
$createTable = str_replace('\'0000-00-00 00:00:00\'','\'
|
1087 |
|
1088 |
if ( $dumpSettings['reset-auto-increment'] ) {
|
1089 |
$match = "/AUTO_INCREMENT=[0-9]+/s";
|
@@ -1498,4 +1561,18 @@ class TypeAdapterWpdb extends TypeAdapterFactory
|
|
1498 |
{
|
1499 |
return $this->dbHandler->get_results($string, ARRAY_A);
|
1500 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1501 |
}
|
1 |
<?php
|
2 |
|
3 |
+
use PDO as PDO;
|
4 |
+
use PDOException as PDOException;
|
5 |
+
|
6 |
/**
|
7 |
* Enum with all available compression methods
|
8 |
*
|
408 |
{
|
409 |
}
|
410 |
|
411 |
+
|
412 |
+
|
413 |
class TypeAdapterMysql extends TypeAdapterFactory
|
414 |
{
|
415 |
|
458 |
|
459 |
public function __construct ($dbHandler)
|
460 |
{
|
461 |
+
$pdoSettingsDefault = array(
|
462 |
+
PDO::ATTR_PERSISTENT => true,
|
463 |
+
PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING,
|
464 |
+
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false
|
465 |
+
);
|
466 |
+
|
467 |
$this->dbHandler = $dbHandler;
|
468 |
$this->dsn='';
|
469 |
$this->user='';
|
470 |
$this->pass='';
|
471 |
+
$this->pdoSettings=$pdoSettingsDefault;
|
472 |
$this->reconnect_count=0;
|
473 |
}
|
474 |
|
480 |
$this->pdoSettings=$pdoSetting;
|
481 |
}
|
482 |
|
483 |
+
public function connect($host,$dbname,$user,$pass,$init_commands=array())
|
484 |
+
{
|
485 |
+
$this->dsn='mysql:host=' . $host . ';dbname=' . $dbname;
|
486 |
+
$this->user=$user;
|
487 |
+
$this->pass=$pass;
|
488 |
+
$this->dbHandler = @new PDO(
|
489 |
+
$this->dsn,
|
490 |
+
$this->user,
|
491 |
+
$this->pass,
|
492 |
+
$this->pdoSettings
|
493 |
+
);
|
494 |
+
// Execute init commands once connected
|
495 |
+
foreach($init_commands as $stmt)
|
496 |
+
{
|
497 |
+
$this->dbHandler->exec($stmt);
|
498 |
+
}
|
499 |
+
$this->dbHandler->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_NATURAL);
|
500 |
+
}
|
501 |
+
|
502 |
+
public function errorInfo()
|
503 |
+
{
|
504 |
+
$error=$this->dbHandler->errorInfo();
|
505 |
+
return $error;
|
506 |
+
}
|
507 |
+
|
508 |
+
public function quote($colValue)
|
509 |
+
{
|
510 |
+
return $this->dbHandler->quote($colValue);
|
511 |
+
}
|
512 |
+
|
513 |
+
|
514 |
public function databases()
|
515 |
{
|
516 |
$this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
|
566 |
throw new Exception("Error getting table code, unknown output");
|
567 |
}
|
568 |
|
569 |
+
$createTable = str_replace('\'0000-00-00 00:00:00\'','\'1999-01-01 00:00:00\'',$row['Create Table']);
|
570 |
|
571 |
if ( $dumpSettings['reset-auto-increment'] ) {
|
572 |
$match = "/AUTO_INCREMENT=[0-9]+/s";
|
988 |
$this->reconnect();
|
989 |
$this->reconnect_count++;
|
990 |
$ret= $this->dbHandler->query($string);
|
991 |
+
if($ret!==false)
|
992 |
+
{
|
993 |
+
$ret->setFetchMode(PDO::FETCH_ASSOC);
|
994 |
+
}
|
995 |
}
|
996 |
}
|
997 |
+
else
|
998 |
+
{
|
999 |
+
$ret->setFetchMode(PDO::FETCH_ASSOC);
|
1000 |
+
}
|
1001 |
+
|
1002 |
return $ret;
|
1003 |
}
|
1004 |
|
1032 |
$this->pdoSettings
|
1033 |
);
|
1034 |
}
|
1035 |
+
|
1036 |
+
public function closeCursor($resultSet)
|
1037 |
+
{
|
1038 |
+
$resultSet->closeCursor();
|
1039 |
+
}
|
1040 |
}
|
1041 |
|
1042 |
class TypeAdapterWpdb extends TypeAdapterFactory
|
1084 |
$this->dbHandler = $dbHandler;
|
1085 |
}
|
1086 |
|
1087 |
+
public function connect($host,$dbname,$user,$pass,$init_commands=array())
|
1088 |
+
{
|
1089 |
+
global $wpdb;
|
1090 |
+
|
1091 |
+
$this->dbHandler=$wpdb;
|
1092 |
+
}
|
1093 |
+
|
1094 |
public function databases()
|
1095 |
{
|
1096 |
$this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
|
1146 |
throw new Exception("Error getting table code, unknown output");
|
1147 |
}
|
1148 |
|
1149 |
+
$createTable = str_replace('\'0000-00-00 00:00:00\'','\'1999-01-01 00:00:00\'',$row['Create Table']);
|
1150 |
|
1151 |
if ( $dumpSettings['reset-auto-increment'] ) {
|
1152 |
$match = "/AUTO_INCREMENT=[0-9]+/s";
|
1561 |
{
|
1562 |
return $this->dbHandler->get_results($string, ARRAY_A);
|
1563 |
}
|
1564 |
+
|
1565 |
+
public function quote($value)
|
1566 |
+
{
|
1567 |
+
$search = array("\x00", "\x0a", "\x0d", "\x1a");
|
1568 |
+
$replace = array('\0', '\n', '\r', '\Z');
|
1569 |
+
$value=str_replace('\\', '\\\\', $value);
|
1570 |
+
$value=str_replace('\'', '\\\'', $value);
|
1571 |
+
$value= "'" . str_replace($search, $replace, $value) . "'";
|
1572 |
+
return $value;
|
1573 |
+
}
|
1574 |
+
|
1575 |
+
public function closeCursor($resultSet)
|
1576 |
+
{
|
1577 |
+
}
|
1578 |
}
|
includes/class-wpvivid-mysqldump-wpdb.php
CHANGED
@@ -546,7 +546,7 @@ class WPvivid_Mysqldump_wpdb
|
|
546 |
|
547 |
foreach($vals as $key => $value){
|
548 |
if($value === '\'0000-00-00 00:00:00\'')
|
549 |
-
$vals[$key] = '\'
|
550 |
}
|
551 |
|
552 |
if ($onlyOnce || !$this->dumpSettings['extended-insert'])
|
546 |
|
547 |
foreach($vals as $key => $value){
|
548 |
if($value === '\'0000-00-00 00:00:00\'')
|
549 |
+
$vals[$key] = '\'1991-01-01 00:00:00\'';
|
550 |
}
|
551 |
|
552 |
if ($onlyOnce || !$this->dumpSettings['extended-insert'])
|
includes/class-wpvivid-mysqldump.php
CHANGED
@@ -16,8 +16,7 @@
|
|
16 |
|
17 |
|
18 |
use Exception as Exception;
|
19 |
-
|
20 |
-
use PDOException as PDOException;
|
21 |
|
22 |
/**
|
23 |
* Mysqldump Class Doc Comment
|
@@ -56,11 +55,6 @@ class WPvivid_Mysqldump
|
|
56 |
*/
|
57 |
public $pass;
|
58 |
/**
|
59 |
-
* Connection string for PDO
|
60 |
-
* @var string
|
61 |
-
*/
|
62 |
-
public $dsn;
|
63 |
-
/**
|
64 |
* Destination filename, defaults to stdout
|
65 |
* @var string
|
66 |
*/
|
@@ -72,12 +66,11 @@ class WPvivid_Mysqldump
|
|
72 |
private $triggers = array();
|
73 |
private $procedures = array();
|
74 |
private $events = array();
|
75 |
-
private $dbHandler = null;
|
76 |
private $dbType;
|
77 |
private $compressManager;
|
78 |
private $typeAdapter;
|
79 |
private $dumpSettings = array();
|
80 |
-
private $pdoSettings = array();
|
81 |
private $version;
|
82 |
private $tableColumnTypes = array();
|
83 |
public $log=false;
|
@@ -97,26 +90,15 @@ class WPvivid_Mysqldump
|
|
97 |
* @var array
|
98 |
*/
|
99 |
private $dsnArray = array();
|
100 |
-
private $privileges = array();
|
101 |
|
102 |
public $last_query_string='';
|
103 |
|
104 |
-
/**
|
105 |
-
* Constructor of Mysqldump. Note that in the case of an SQLite database
|
106 |
-
* connection, the filename must be in the $db parameter.
|
107 |
-
*
|
108 |
-
* @param string $dsn PDO DSN connection string
|
109 |
-
* @param string $user SQL account username
|
110 |
-
* @param string $pass SQL account password
|
111 |
-
* @param array $dumpSettings SQL database settings
|
112 |
-
* @param array $pdoSettings PDO configured attributes
|
113 |
-
*/
|
114 |
public function __construct(
|
115 |
-
$
|
|
|
116 |
$user = '',
|
117 |
$pass = '',
|
118 |
-
$dumpSettings = array()
|
119 |
-
$pdoSettings = array()
|
120 |
) {
|
121 |
$dumpSettingsDefault = array(
|
122 |
'include-tables' => array(),
|
@@ -151,21 +133,17 @@ class WPvivid_Mysqldump
|
|
151 |
'disable-foreign-keys-check' => true
|
152 |
);
|
153 |
|
154 |
-
$
|
155 |
-
PDO::ATTR_PERSISTENT => true,
|
156 |
-
PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING,
|
157 |
-
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false
|
158 |
-
);
|
159 |
-
|
160 |
$this->user = $user;
|
161 |
$this->pass = $pass;
|
162 |
-
$this->
|
163 |
-
$this->
|
164 |
$this->dumpSettings = self::array_replace_recursive($dumpSettingsDefault, $dumpSettings);
|
165 |
|
166 |
$this->dumpSettings['init_commands'][] = "SET NAMES " . $this->dumpSettings['default-character-set'];
|
167 |
|
168 |
-
if (false === $this->dumpSettings['skip-tz-utc'])
|
|
|
169 |
$this->dumpSettings['init_commands'][] = "SET TIME_ZONE='+00:00'";
|
170 |
}
|
171 |
|
@@ -185,8 +163,20 @@ class WPvivid_Mysqldump
|
|
185 |
// Create a new compressManager to manage compressed output
|
186 |
$this->compressManager = CompressManagerFactory::create($this->dumpSettings['compress']);
|
187 |
}
|
188 |
-
|
189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
}
|
191 |
|
192 |
/**
|
@@ -195,7 +185,7 @@ class WPvivid_Mysqldump
|
|
195 |
*/
|
196 |
public function __destruct()
|
197 |
{
|
198 |
-
|
199 |
}
|
200 |
|
201 |
/**
|
@@ -277,6 +267,7 @@ class WPvivid_Mysqldump
|
|
277 |
private function connect()
|
278 |
{
|
279 |
// Connecting with PDO
|
|
|
280 |
try {
|
281 |
switch ($this->dbType) {
|
282 |
case 'sqlite':
|
@@ -306,18 +297,10 @@ class WPvivid_Mysqldump
|
|
306 |
"Connection to " . $this->dbType . " failed with message: " .
|
307 |
$e->getMessage()
|
308 |
);
|
309 |
-
}
|
310 |
-
|
311 |
-
if ( is_null($this->dbHandler) ) {
|
312 |
-
throw new Exception("Connection to ". $this->dbType . "failed");
|
313 |
-
}
|
314 |
|
315 |
-
$this->
|
316 |
-
$this->typeAdapter
|
317 |
-
if($this->dbType=='mysql'||$this->dbType=='pgsql'||$this->dbType=='dblib')
|
318 |
-
{
|
319 |
-
$this->typeAdapter->set_connect_info($this->dsn, $this->user, $this->pass, $this->pdoSettings);
|
320 |
-
}
|
321 |
}
|
322 |
|
323 |
/**
|
@@ -389,7 +372,8 @@ class WPvivid_Mysqldump
|
|
389 |
$name = implode(",", $this->dumpSettings['include-tables']);
|
390 |
throw new Exception("Table (" . $name . ") not found in database");
|
391 |
}
|
392 |
-
|
|
|
393 |
global $wpvivid_pulgin;
|
394 |
|
395 |
$this->exportTables();
|
@@ -416,6 +400,7 @@ class WPvivid_Mysqldump
|
|
416 |
}else{
|
417 |
$this->exportEvents();
|
418 |
}
|
|
|
419 |
|
420 |
// Restore saved parameters
|
421 |
$this->compressManager->write(
|
@@ -756,7 +741,7 @@ class WPvivid_Mysqldump
|
|
756 |
if($columns===false)
|
757 |
{
|
758 |
global $wpvivid_pulgin;
|
759 |
-
$error=$this->
|
760 |
if(isset($error[2])){
|
761 |
$error = 'Error: '.$error[2];
|
762 |
}
|
@@ -770,7 +755,7 @@ class WPvivid_Mysqldump
|
|
770 |
);
|
771 |
if($columns===false)
|
772 |
{
|
773 |
-
$error=$this->
|
774 |
if(isset($error[2])){
|
775 |
$error = 'Error: '.$error[2];
|
776 |
}
|
@@ -783,8 +768,6 @@ class WPvivid_Mysqldump
|
|
783 |
}
|
784 |
}
|
785 |
|
786 |
-
$columns->setFetchMode(PDO::FETCH_ASSOC);
|
787 |
-
|
788 |
foreach($columns as $key => $col) {
|
789 |
$types = $this->typeAdapter->parseColumnType($col);
|
790 |
$columnTypes[$col['Field']] = array(
|
@@ -975,7 +958,7 @@ class WPvivid_Mysqldump
|
|
975 |
} elseif ($columnTypes[$colName]['is_numeric']) {
|
976 |
$ret[] = $colValue;
|
977 |
} else {
|
978 |
-
$ret[] = $this->
|
979 |
}
|
980 |
}
|
981 |
return $ret;
|
@@ -1016,8 +999,6 @@ class WPvivid_Mysqldump
|
|
1016 |
}
|
1017 |
|
1018 |
$resultSet = $this->query($stmt);
|
1019 |
-
$resultSet->setFetchMode(PDO::FETCH_ASSOC);
|
1020 |
-
|
1021 |
$i=0;
|
1022 |
$i_check_cancel=0;
|
1023 |
$count=0;
|
@@ -1027,7 +1008,7 @@ class WPvivid_Mysqldump
|
|
1027 |
|
1028 |
foreach($vals as $key => $value){
|
1029 |
if($value === '\'0000-00-00 00:00:00\'')
|
1030 |
-
$vals[$key] = '\'
|
1031 |
}
|
1032 |
|
1033 |
if ($onlyOnce || !$this->dumpSettings['extended-insert'])
|
@@ -1073,7 +1054,9 @@ class WPvivid_Mysqldump
|
|
1073 |
}
|
1074 |
}
|
1075 |
}
|
1076 |
-
|
|
|
|
|
1077 |
|
1078 |
if (!$onlyOnce) {
|
1079 |
$this->compressManager->write(";" . PHP_EOL);
|
@@ -1106,13 +1089,16 @@ class WPvivid_Mysqldump
|
|
1106 |
$this->exec($this->typeAdapter->start_transaction());
|
1107 |
}
|
1108 |
|
1109 |
-
if ($this->dumpSettings['lock-tables'])
|
1110 |
-
|
1111 |
-
|
1112 |
-
|
1113 |
-
|
1114 |
-
|
1115 |
-
|
|
|
|
|
|
|
1116 |
}
|
1117 |
|
1118 |
if ($this->dumpSettings['add-locks']) {
|
16 |
|
17 |
|
18 |
use Exception as Exception;
|
19 |
+
|
|
|
20 |
|
21 |
/**
|
22 |
* Mysqldump Class Doc Comment
|
55 |
*/
|
56 |
public $pass;
|
57 |
/**
|
|
|
|
|
|
|
|
|
|
|
58 |
* Destination filename, defaults to stdout
|
59 |
* @var string
|
60 |
*/
|
66 |
private $triggers = array();
|
67 |
private $procedures = array();
|
68 |
private $events = array();
|
69 |
+
//private $dbHandler = null;
|
70 |
private $dbType;
|
71 |
private $compressManager;
|
72 |
private $typeAdapter;
|
73 |
private $dumpSettings = array();
|
|
|
74 |
private $version;
|
75 |
private $tableColumnTypes = array();
|
76 |
public $log=false;
|
90 |
* @var array
|
91 |
*/
|
92 |
private $dsnArray = array();
|
|
|
93 |
|
94 |
public $last_query_string='';
|
95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
public function __construct(
|
97 |
+
$host = '',
|
98 |
+
$dbname='',
|
99 |
$user = '',
|
100 |
$pass = '',
|
101 |
+
$dumpSettings = array()
|
|
|
102 |
) {
|
103 |
$dumpSettingsDefault = array(
|
104 |
'include-tables' => array(),
|
133 |
'disable-foreign-keys-check' => true
|
134 |
);
|
135 |
|
136 |
+
$this->dbType=$this->get_db_type();
|
|
|
|
|
|
|
|
|
|
|
137 |
$this->user = $user;
|
138 |
$this->pass = $pass;
|
139 |
+
$this->host=$host;
|
140 |
+
$this->dbName=$dbname;
|
141 |
$this->dumpSettings = self::array_replace_recursive($dumpSettingsDefault, $dumpSettings);
|
142 |
|
143 |
$this->dumpSettings['init_commands'][] = "SET NAMES " . $this->dumpSettings['default-character-set'];
|
144 |
|
145 |
+
if (false === $this->dumpSettings['skip-tz-utc'])
|
146 |
+
{
|
147 |
$this->dumpSettings['init_commands'][] = "SET TIME_ZONE='+00:00'";
|
148 |
}
|
149 |
|
163 |
// Create a new compressManager to manage compressed output
|
164 |
$this->compressManager = CompressManagerFactory::create($this->dumpSettings['compress']);
|
165 |
}
|
166 |
+
|
167 |
+
|
168 |
+
public function get_db_type()
|
169 |
+
{
|
170 |
+
if(class_exists('PDO'))
|
171 |
+
{
|
172 |
+
$extensions=get_loaded_extensions();
|
173 |
+
if(array_search('pdo_mysql',$extensions))
|
174 |
+
{
|
175 |
+
return 'mysql';
|
176 |
+
}
|
177 |
+
}
|
178 |
+
|
179 |
+
return 'wpdb';
|
180 |
}
|
181 |
|
182 |
/**
|
185 |
*/
|
186 |
public function __destruct()
|
187 |
{
|
188 |
+
//$this->dbHandler = null;
|
189 |
}
|
190 |
|
191 |
/**
|
267 |
private function connect()
|
268 |
{
|
269 |
// Connecting with PDO
|
270 |
+
/*
|
271 |
try {
|
272 |
switch ($this->dbType) {
|
273 |
case 'sqlite':
|
297 |
"Connection to " . $this->dbType . " failed with message: " .
|
298 |
$e->getMessage()
|
299 |
);
|
300 |
+
}*/
|
|
|
|
|
|
|
|
|
301 |
|
302 |
+
$this->typeAdapter = TypeAdapterFactory::create($this->dbType, null);
|
303 |
+
$this->typeAdapter->connect($this->host,$this->dbName,$this->user,$this->pass,$this->dumpSettings['init_commands']);
|
|
|
|
|
|
|
|
|
304 |
}
|
305 |
|
306 |
/**
|
372 |
$name = implode(",", $this->dumpSettings['include-tables']);
|
373 |
throw new Exception("Table (" . $name . ") not found in database");
|
374 |
}
|
375 |
+
$this->exportTables();
|
376 |
+
/*
|
377 |
global $wpvivid_pulgin;
|
378 |
|
379 |
$this->exportTables();
|
400 |
}else{
|
401 |
$this->exportEvents();
|
402 |
}
|
403 |
+
*/
|
404 |
|
405 |
// Restore saved parameters
|
406 |
$this->compressManager->write(
|
741 |
if($columns===false)
|
742 |
{
|
743 |
global $wpvivid_pulgin;
|
744 |
+
$error=$this->typeAdapter->errorInfo();
|
745 |
if(isset($error[2])){
|
746 |
$error = 'Error: '.$error[2];
|
747 |
}
|
755 |
);
|
756 |
if($columns===false)
|
757 |
{
|
758 |
+
$error=$this->typeAdapter->errorInfo();
|
759 |
if(isset($error[2])){
|
760 |
$error = 'Error: '.$error[2];
|
761 |
}
|
768 |
}
|
769 |
}
|
770 |
|
|
|
|
|
771 |
foreach($columns as $key => $col) {
|
772 |
$types = $this->typeAdapter->parseColumnType($col);
|
773 |
$columnTypes[$col['Field']] = array(
|
958 |
} elseif ($columnTypes[$colName]['is_numeric']) {
|
959 |
$ret[] = $colValue;
|
960 |
} else {
|
961 |
+
$ret[] = $this->typeAdapter->quote($colValue);
|
962 |
}
|
963 |
}
|
964 |
return $ret;
|
999 |
}
|
1000 |
|
1001 |
$resultSet = $this->query($stmt);
|
|
|
|
|
1002 |
$i=0;
|
1003 |
$i_check_cancel=0;
|
1004 |
$count=0;
|
1008 |
|
1009 |
foreach($vals as $key => $value){
|
1010 |
if($value === '\'0000-00-00 00:00:00\'')
|
1011 |
+
$vals[$key] = '\'1999-01-01 00:00:00\'';
|
1012 |
}
|
1013 |
|
1014 |
if ($onlyOnce || !$this->dumpSettings['extended-insert'])
|
1054 |
}
|
1055 |
}
|
1056 |
}
|
1057 |
+
|
1058 |
+
$this->typeAdapter->closeCursor($resultSet);
|
1059 |
+
//$resultSet->closeCursor();
|
1060 |
|
1061 |
if (!$onlyOnce) {
|
1062 |
$this->compressManager->write(";" . PHP_EOL);
|
1089 |
$this->exec($this->typeAdapter->start_transaction());
|
1090 |
}
|
1091 |
|
1092 |
+
if ($this->dumpSettings['lock-tables'])
|
1093 |
+
{
|
1094 |
+
$this->typeAdapter->lock_table($tableName);
|
1095 |
+
//if($this -> privileges['LOCK TABLES'] == 0)
|
1096 |
+
//{
|
1097 |
+
//global $wpvivid_pulgin;
|
1098 |
+
// $wpvivid_pulgin->wpvivid_log->WriteLog('The lack of LOCK TABLES privilege, the backup will skip lock_tables() to continue.','notice');
|
1099 |
+
//}else{
|
1100 |
+
// $this->typeAdapter->lock_table($tableName);
|
1101 |
+
//}
|
1102 |
}
|
1103 |
|
1104 |
if ($this->dumpSettings['add-locks']) {
|
includes/class-wpvivid-restore-database.php
CHANGED
@@ -10,8 +10,6 @@ require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-set
|
|
10 |
require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-rollback.php';
|
11 |
class WPvivid_RestoreDB
|
12 |
{
|
13 |
-
private $max_allow_packet;
|
14 |
-
|
15 |
private $support_engines;
|
16 |
private $support_charsets;
|
17 |
private $support_collates;
|
@@ -34,18 +32,21 @@ class WPvivid_RestoreDB
|
|
34 |
|
35 |
private $current_setting;
|
36 |
|
37 |
-
private $db;
|
38 |
-
|
39 |
-
private $skip_query;
|
40 |
|
41 |
private $replacing_table;
|
42 |
|
|
|
|
|
43 |
public function restore($path,$sql_file,$options)
|
44 |
{
|
45 |
add_filter('wpvivid_restore_db_skip_replace_tables', array($this, 'skip_tables'),10,2);
|
46 |
add_filter('wpvivid_restore_db_skip_replace_rows', array($this, 'skip_rows'),10,3);
|
47 |
|
48 |
-
|
|
|
|
|
49 |
|
50 |
global $wpvivid_pulgin;
|
51 |
|
@@ -65,112 +66,24 @@ class WPvivid_RestoreDB
|
|
65 |
}
|
66 |
|
67 |
$this->current_setting = WPvivid_Setting::export_setting_to_json();
|
68 |
-
$ret=$this->connect_db();
|
69 |
if($ret['result']==WPVIVID_FAILED)
|
70 |
{
|
71 |
return $ret;
|
72 |
}
|
73 |
|
74 |
-
$this->test_db();
|
75 |
-
$this->check_max_allow_packet();
|
76 |
|
77 |
-
$
|
78 |
-
$sql_mod = $res[0][0];
|
79 |
-
$temp_sql_mode = str_replace('NO_ENGINE_SUBSTITUTION','',$sql_mod);
|
80 |
-
$temp_sql_mode = 'NO_AUTO_VALUE_ON_ZERO,'.$temp_sql_mode;
|
81 |
-
$this->db->query('SET SESSION sql_mode = "'.$temp_sql_mode.'"');
|
82 |
$result=$this->execute_sql_file($path.$sql_file,$options);
|
83 |
-
unset($this->
|
84 |
return $result;
|
85 |
}else {
|
86 |
return array('result'=>'failed','error'=>'Database\'s .sql file not found. Please try again.');
|
87 |
}
|
88 |
}
|
89 |
|
90 |
-
private function connect_db()
|
91 |
-
{
|
92 |
-
$res = explode(':',DB_HOST);
|
93 |
-
$db_host = $res[0];
|
94 |
-
$db_port = empty($res[1])?'':$res[1];
|
95 |
-
if(!empty($db_port))
|
96 |
-
$db_host = $db_host.':'.$db_port;
|
97 |
-
try
|
98 |
-
{
|
99 |
-
$this->db = null;
|
100 |
-
$this->db=new PDO('mysql:host=' . $db_host . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD );
|
101 |
-
$this->db->exec('SET NAMES utf8');
|
102 |
-
if(empty($this->db) || !$this->db)
|
103 |
-
{
|
104 |
-
$ret['result']=WPVIVID_FAILED;
|
105 |
-
$ret['error']='The error establishing a database connection. Please check wp-config.php file and make sure the information is correct.';
|
106 |
-
}
|
107 |
-
else
|
108 |
-
{
|
109 |
-
$ret['result']=WPVIVID_SUCCESS;
|
110 |
-
}
|
111 |
-
}
|
112 |
-
catch (Exception $e)
|
113 |
-
{
|
114 |
-
if(!empty($db_port))
|
115 |
-
{
|
116 |
-
$db_host = $res[0];
|
117 |
-
$this->db=new PDO('mysql:host=' . $db_host . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD );
|
118 |
-
$this->db->exec('SET NAMES utf8');
|
119 |
-
}
|
120 |
-
if(empty($this->db) || !$this->db)
|
121 |
-
{
|
122 |
-
$ret['result']=WPVIVID_FAILED;
|
123 |
-
$ret['error']='The error establishing a database connection. Please check wp-config.php file and make sure the information is correct.';
|
124 |
-
}
|
125 |
-
else
|
126 |
-
{
|
127 |
-
$ret['result']=WPVIVID_SUCCESS;
|
128 |
-
}
|
129 |
-
}
|
130 |
-
return $ret;
|
131 |
-
}
|
132 |
-
|
133 |
-
private function test_db()
|
134 |
-
{
|
135 |
-
global $wpvivid_pulgin;
|
136 |
-
$test_table_new=uniqid('wpvivid_test_tables_');
|
137 |
-
$columns='(test_id int)';
|
138 |
-
$test_table = $this->db->exec("CREATE TABLE IF NOT EXISTS $test_table_new $columns");
|
139 |
-
|
140 |
-
if ($test_table!==false)
|
141 |
-
{
|
142 |
-
$wpvivid_pulgin->restore_data->write_log('The test to create table succeeds.','notice');
|
143 |
-
$test_table = $this->db->exec("INSERT INTO $test_table_new (`test_id`) VALUES ('123')");
|
144 |
-
if($test_table!==false)
|
145 |
-
{
|
146 |
-
$wpvivid_pulgin->restore_data->write_log('The test to insert into table succeeds.','notice');
|
147 |
-
$test_table = $this->db->exec("DROP TABLE IF EXISTS $test_table_new");
|
148 |
-
if($test_table!==false)
|
149 |
-
{
|
150 |
-
$wpvivid_pulgin->restore_data->write_log('The test to drop table succeeds.','notice');
|
151 |
-
return true;
|
152 |
-
}
|
153 |
-
else
|
154 |
-
{
|
155 |
-
$error=$this->db->errorInfo();
|
156 |
-
$wpvivid_pulgin->restore_data->write_log('Unable to drop table. The reason is '.$error[2],'warning');
|
157 |
-
return false;
|
158 |
-
}
|
159 |
-
}
|
160 |
-
else
|
161 |
-
{
|
162 |
-
$error=$this->db->errorInfo();
|
163 |
-
$wpvivid_pulgin->restore_data->write_log('Unable to insert into table. The reason is '.$error[2],'warning');
|
164 |
-
return false;
|
165 |
-
}
|
166 |
-
}
|
167 |
-
else {
|
168 |
-
$error=$this->db->errorInfo();
|
169 |
-
$wpvivid_pulgin->restore_data->write_log('Unable to create table. The reason is '.$error[2],'warning');
|
170 |
-
return false;
|
171 |
-
}
|
172 |
-
}
|
173 |
-
|
174 |
private function execute_sql_file($file,$option)
|
175 |
{
|
176 |
global $wpdb,$wpvivid_pulgin;
|
@@ -257,14 +170,16 @@ class WPvivid_RestoreDB
|
|
257 |
$query='';
|
258 |
|
259 |
$current_table='';
|
|
|
260 |
while(!feof($sql_handle))
|
261 |
{
|
262 |
$line = fgets($sql_handle);
|
263 |
$line_num ++;
|
264 |
$startWith = substr(trim($line), 0 ,2);
|
|
|
265 |
$endWith = substr(trim($line), -1 ,1);
|
266 |
$line = rtrim($line);
|
267 |
-
if (empty($line) || $startWith == '--' || $startWith == '/*' || $startWith == '//')
|
268 |
{
|
269 |
if ($endWith == ';' && preg_match('- # -',$line))
|
270 |
{
|
@@ -303,7 +218,7 @@ class WPvivid_RestoreDB
|
|
303 |
{
|
304 |
if (preg_match('#^\\s*CREATE TABLE#', $query))
|
305 |
{
|
306 |
-
$current_table=$this->create_table($query);
|
307 |
}else if(preg_match('#^\\s*LOCK TABLES#',$query))
|
308 |
{
|
309 |
$this->lock_table($query);
|
@@ -314,7 +229,7 @@ class WPvivid_RestoreDB
|
|
314 |
}
|
315 |
else if(preg_match('#^\\s*DROP TABLE #', $query))
|
316 |
{
|
317 |
-
if(!empty($this->old_site_url)&&$this->old_site_url!=$this->new_site_url)
|
318 |
{
|
319 |
if(isset($option['is_migrate']))
|
320 |
{
|
@@ -326,11 +241,20 @@ class WPvivid_RestoreDB
|
|
326 |
}
|
327 |
$this->drop_table($query);
|
328 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
329 |
else
|
330 |
{
|
331 |
-
if ($this->
|
332 |
{
|
333 |
-
$wpvivid_pulgin->restore_data->write_log('Restore ' . basename($file) . ' error at line ' . $line_num . ',' . PHP_EOL . 'errorinfo: [' . implode('][', $this->
|
334 |
$query = '';
|
335 |
continue;
|
336 |
}
|
@@ -339,7 +263,7 @@ class WPvivid_RestoreDB
|
|
339 |
}
|
340 |
}
|
341 |
|
342 |
-
if(!empty($this->old_site_url)&&$this->old_site_url!=$this->new_site_url)
|
343 |
{
|
344 |
if(isset($option['is_migrate']))
|
345 |
{
|
@@ -369,28 +293,38 @@ class WPvivid_RestoreDB
|
|
369 |
{
|
370 |
$table_name = $matches[1];
|
371 |
$new_table_name=$this->new_prefix.substr($table_name,strlen($this->old_prefix));
|
372 |
-
|
373 |
$query=str_replace($table_name,$new_table_name,$query);
|
374 |
}
|
375 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
376 |
|
377 |
$this->execute_sql($query);
|
378 |
}
|
379 |
|
380 |
-
private function create_table($query)
|
381 |
{
|
382 |
global $wpvivid_pulgin;
|
383 |
$table_name='';
|
384 |
if (preg_match('/^\s*CREATE TABLE +\`?([^\`]*)\`?/i', $query, $matches))
|
385 |
{
|
386 |
$table_name = $matches[1];
|
|
|
387 |
}
|
388 |
|
389 |
if(!empty($this->old_prefix)&&$this->old_prefix!=$this->new_prefix)
|
390 |
{
|
391 |
-
//$this->restore_data->write_log('create table','notice');
|
392 |
$new_table_name=$this->new_prefix.substr($table_name,strlen($this->old_prefix));
|
393 |
-
//$this->restore_data->write_log('create table replace table:'.$table_name.' to :'.$new_table_name,'notice');
|
394 |
$query=str_replace($table_name,$new_table_name,$query);
|
395 |
$wpvivid_pulgin->restore_data->write_log('Create table '.$new_table_name,'notice');
|
396 |
$table_name=$new_table_name;
|
@@ -492,7 +426,6 @@ class WPvivid_RestoreDB
|
|
492 |
{
|
493 |
$table_name = $matches[1];
|
494 |
$new_table_name=$this->new_prefix.substr($table_name,strlen($this->old_prefix));
|
495 |
-
//$this->restore_data->write_log('insert into replace table:'.$table_name.' to :'.$new_table_name,'notice');
|
496 |
$query=str_replace($table_name,$new_table_name,$query);
|
497 |
}
|
498 |
}
|
@@ -513,7 +446,7 @@ class WPvivid_RestoreDB
|
|
513 |
$query=str_replace($table_name,$new_table_name,$query);
|
514 |
}
|
515 |
}
|
516 |
-
|
517 |
$this->execute_sql($query);
|
518 |
}
|
519 |
|
@@ -552,6 +485,9 @@ class WPvivid_RestoreDB
|
|
552 |
}
|
553 |
}
|
554 |
|
|
|
|
|
|
|
555 |
$skip_table=false;
|
556 |
if(apply_filters('wpvivid_restore_db_skip_replace_tables',$skip_table,$table_name))
|
557 |
{
|
@@ -561,20 +497,19 @@ class WPvivid_RestoreDB
|
|
561 |
|
562 |
$query = 'SELECT COUNT(*) FROM `'.$table_name.'`';
|
563 |
|
564 |
-
$result=$this->
|
565 |
-
|
566 |
-
if($result && $result->rowCount()>0)
|
567 |
{
|
568 |
-
$count
|
569 |
-
$wpvivid_pulgin->restore_data->write_log('Count of rows in '.$table_name.': '.$count
|
570 |
-
if($count
|
571 |
{
|
572 |
return ;
|
573 |
}
|
574 |
|
575 |
$query='DESCRIBE `'.$table_name.'`';
|
576 |
-
$result=$this->
|
577 |
-
|
578 |
$columns=array();
|
579 |
foreach ($result as $data)
|
580 |
{
|
@@ -585,8 +520,6 @@ class WPvivid_RestoreDB
|
|
585 |
$column['PRI']=0;
|
586 |
$columns[]=$column;
|
587 |
}
|
588 |
-
|
589 |
-
$count=$count[0][0];
|
590 |
$page=5000;
|
591 |
|
592 |
$update_query='';
|
@@ -598,16 +531,14 @@ class WPvivid_RestoreDB
|
|
598 |
$end_row=$current_row+$page;
|
599 |
$query = 'SELECT * FROM `'.$table_name.'` LIMIT '.$current_row.', '.$end_row;
|
600 |
|
601 |
-
$result=$this->
|
602 |
-
|
603 |
-
if($result && $result->rowCount()>0)
|
604 |
{
|
605 |
-
$rows = $result
|
606 |
foreach ($rows as $row)
|
607 |
{
|
608 |
$update=array();
|
609 |
$where=array();
|
610 |
-
|
611 |
foreach ($columns as $column)
|
612 |
{
|
613 |
$old_data = $row[$column['Field']];
|
@@ -639,28 +570,41 @@ class WPvivid_RestoreDB
|
|
639 |
if(!empty($update)&&!empty($where))
|
640 |
{
|
641 |
$temp_query = 'UPDATE `'.$table_name.'` SET '.implode(', ', $update).' WHERE '.implode(' AND ', array_filter($where)).';';
|
642 |
-
|
|
|
|
|
|
|
643 |
{
|
644 |
-
$update_query
|
645 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
646 |
{
|
647 |
$wpvivid_pulgin->restore_data->write_log('update replace rows', 'notice');
|
648 |
$this->execute_sql($update_query);
|
649 |
|
650 |
$update_query='';
|
651 |
}
|
|
|
|
|
|
|
|
|
652 |
}
|
653 |
-
else
|
654 |
{
|
655 |
-
$
|
656 |
$this->execute_sql($update_query);
|
657 |
-
|
658 |
$update_query='';
|
659 |
}
|
660 |
-
|
661 |
-
{
|
662 |
-
$update_query.=$temp_query;
|
663 |
-
}
|
664 |
}
|
665 |
//return;
|
666 |
}
|
@@ -984,6 +928,9 @@ class WPvivid_RestoreDB
|
|
984 |
$skip_tables[]='dmsguestbook';
|
985 |
$skip_tables[]='relevanssi';
|
986 |
$skip_tables[]='wfFileMods';
|
|
|
|
|
|
|
987 |
if(in_array(substr($table_name, strlen($this->new_prefix)),$skip_tables))
|
988 |
{
|
989 |
$skip_table=true;
|
@@ -1014,6 +961,7 @@ class WPvivid_RestoreDB
|
|
1014 |
return $skip_rows;
|
1015 |
}
|
1016 |
|
|
|
1017 |
private function check_max_allow_packet()
|
1018 |
{
|
1019 |
//$max_allow_packet
|
@@ -1046,17 +994,20 @@ class WPvivid_RestoreDB
|
|
1046 |
$this->max_allow_packet=1048576;
|
1047 |
}
|
1048 |
}
|
1049 |
-
|
1050 |
public function check_max_allow_packet_ex()
|
1051 |
{
|
1052 |
$max_all_packet_warning=false;
|
1053 |
-
|
|
|
|
|
|
|
|
|
1054 |
if($ret['result']==WPVIVID_SUCCESS)
|
1055 |
{
|
1056 |
-
$max_allowed_packet = $this->
|
1057 |
if($max_allowed_packet)
|
1058 |
{
|
1059 |
-
$max_allowed_packet = $max_allowed_packet -> fetchAll();
|
1060 |
if(is_array($max_allowed_packet)&&isset($max_allowed_packet[0])&&isset($max_allowed_packet[0][0]))
|
1061 |
{
|
1062 |
if($max_allowed_packet[0][0]<16777216){
|
@@ -1070,39 +1021,7 @@ class WPvivid_RestoreDB
|
|
1070 |
|
1071 |
private function execute_sql($query)
|
1072 |
{
|
1073 |
-
|
1074 |
-
|
1075 |
-
if($this->skip_query>10)
|
1076 |
-
{
|
1077 |
-
if(strlen($query)>$this->max_allow_packet)
|
1078 |
-
{
|
1079 |
-
$wpvivid_pulgin->restore_data->write_log('skip query size:'.size_format(strlen($query)), 'Warning');
|
1080 |
-
return ;
|
1081 |
-
}
|
1082 |
-
}
|
1083 |
-
|
1084 |
-
if ($this->db->exec($query)===false)
|
1085 |
-
{
|
1086 |
-
$info=$this->db->errorInfo();
|
1087 |
-
$wpvivid_pulgin->restore_data->write_log('query: [' . implode('][', $info) . ']', 'Warning');
|
1088 |
-
|
1089 |
-
if($info[1] == 2006)
|
1090 |
-
{
|
1091 |
-
if(strlen($query)>$this->max_allow_packet)
|
1092 |
-
{
|
1093 |
-
$this->skip_query++;
|
1094 |
-
$wpvivid_pulgin->restore_data->write_log('max_allow_packet too small:'.size_format($this->max_allow_packet).' query size:'.size_format(strlen($query)), 'Warning');
|
1095 |
-
}
|
1096 |
-
$ret=$this->connect_db();
|
1097 |
-
if($ret['result']==WPVIVID_FAILED)
|
1098 |
-
{
|
1099 |
-
$wpvivid_pulgin->restore_data->write_log('reconnect failed', 'Warning');
|
1100 |
-
}
|
1101 |
-
else{
|
1102 |
-
$wpvivid_pulgin->restore_data->write_log('reconnect succeed', 'Warning');
|
1103 |
-
}
|
1104 |
-
}
|
1105 |
-
}
|
1106 |
}
|
1107 |
|
1108 |
}
|
10 |
require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-rollback.php';
|
11 |
class WPvivid_RestoreDB
|
12 |
{
|
|
|
|
|
13 |
private $support_engines;
|
14 |
private $support_charsets;
|
15 |
private $support_collates;
|
32 |
|
33 |
private $current_setting;
|
34 |
|
35 |
+
//private $db;
|
36 |
+
//private $skip_query;
|
|
|
37 |
|
38 |
private $replacing_table;
|
39 |
|
40 |
+
private $db_method;
|
41 |
+
|
42 |
public function restore($path,$sql_file,$options)
|
43 |
{
|
44 |
add_filter('wpvivid_restore_db_skip_replace_tables', array($this, 'skip_tables'),10,2);
|
45 |
add_filter('wpvivid_restore_db_skip_replace_rows', array($this, 'skip_rows'),10,3);
|
46 |
|
47 |
+
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-restore-db-method.php';
|
48 |
+
$this->db_method=new WPvivid_Restore_DB_Method();
|
49 |
+
$this->db_method->set_skip_query(0);
|
50 |
|
51 |
global $wpvivid_pulgin;
|
52 |
|
66 |
}
|
67 |
|
68 |
$this->current_setting = WPvivid_Setting::export_setting_to_json();
|
69 |
+
$ret=$this->db_method->connect_db();
|
70 |
if($ret['result']==WPVIVID_FAILED)
|
71 |
{
|
72 |
return $ret;
|
73 |
}
|
74 |
|
75 |
+
$this->db_method->test_db();
|
76 |
+
$this->db_method->check_max_allow_packet();
|
77 |
|
78 |
+
$this->db_method->init_sql_mode();
|
|
|
|
|
|
|
|
|
79 |
$result=$this->execute_sql_file($path.$sql_file,$options);
|
80 |
+
unset($this->db_method);
|
81 |
return $result;
|
82 |
}else {
|
83 |
return array('result'=>'failed','error'=>'Database\'s .sql file not found. Please try again.');
|
84 |
}
|
85 |
}
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
private function execute_sql_file($file,$option)
|
88 |
{
|
89 |
global $wpdb,$wpvivid_pulgin;
|
170 |
$query='';
|
171 |
|
172 |
$current_table='';
|
173 |
+
$current_old_table='';
|
174 |
while(!feof($sql_handle))
|
175 |
{
|
176 |
$line = fgets($sql_handle);
|
177 |
$line_num ++;
|
178 |
$startWith = substr(trim($line), 0 ,2);
|
179 |
+
$startWithEx = substr(trim($line), 0 ,3);
|
180 |
$endWith = substr(trim($line), -1 ,1);
|
181 |
$line = rtrim($line);
|
182 |
+
if (empty($line) || $startWith == '--' || ($startWith == '/*'&&$startWithEx!='/*!') || $startWith == '//')
|
183 |
{
|
184 |
if ($endWith == ';' && preg_match('- # -',$line))
|
185 |
{
|
218 |
{
|
219 |
if (preg_match('#^\\s*CREATE TABLE#', $query))
|
220 |
{
|
221 |
+
$current_table=$this->create_table($query,$current_old_table);
|
222 |
}else if(preg_match('#^\\s*LOCK TABLES#',$query))
|
223 |
{
|
224 |
$this->lock_table($query);
|
229 |
}
|
230 |
else if(preg_match('#^\\s*DROP TABLE #', $query))
|
231 |
{
|
232 |
+
if($this->old_prefix!=$this->new_prefix||(!empty($this->old_site_url)&&$this->old_site_url!=$this->new_site_url))
|
233 |
{
|
234 |
if(isset($option['is_migrate']))
|
235 |
{
|
241 |
}
|
242 |
$this->drop_table($query);
|
243 |
}
|
244 |
+
else if(preg_match('#\/*!#', $query))
|
245 |
+
{
|
246 |
+
if ($this->replace_table_execute_sql($query,$current_old_table)===false)
|
247 |
+
{
|
248 |
+
$wpvivid_pulgin->restore_data->write_log('Restore ' . basename($file) . ' error at line ' . $line_num . ',' . PHP_EOL . 'errorinfo: [' . implode('][', $this->db_method->errorInfo()) . ']', 'Warning');
|
249 |
+
$query = '';
|
250 |
+
continue;
|
251 |
+
}
|
252 |
+
}
|
253 |
else
|
254 |
{
|
255 |
+
if ($this->db_method->execute_sql($query)===false)
|
256 |
{
|
257 |
+
$wpvivid_pulgin->restore_data->write_log('Restore ' . basename($file) . ' error at line ' . $line_num . ',' . PHP_EOL . 'errorinfo: [' . implode('][', $this->db_method->errorInfo()) . ']', 'Warning');
|
258 |
$query = '';
|
259 |
continue;
|
260 |
}
|
263 |
}
|
264 |
}
|
265 |
|
266 |
+
if($this->old_prefix!=$this->new_prefix||(!empty($this->old_site_url)&&$this->old_site_url!=$this->new_site_url))
|
267 |
{
|
268 |
if(isset($option['is_migrate']))
|
269 |
{
|
293 |
{
|
294 |
$table_name = $matches[1];
|
295 |
$new_table_name=$this->new_prefix.substr($table_name,strlen($this->old_prefix));
|
296 |
+
$wpvivid_pulgin->restore_data->write_log('lock replace table:'.$table_name.' to :'.$new_table_name,'notice');
|
297 |
$query=str_replace($table_name,$new_table_name,$query);
|
298 |
}
|
299 |
}
|
300 |
+
$this->execute_sql($query);
|
301 |
+
}
|
302 |
+
|
303 |
+
private function replace_table_execute_sql($query,$table_name)
|
304 |
+
{
|
305 |
+
global $wpvivid_pulgin;
|
306 |
+
if(!empty($table_name))
|
307 |
+
{
|
308 |
+
$new_table_name=$this->new_prefix.substr($table_name,strlen($this->old_prefix));
|
309 |
+
$query=str_replace($table_name,$new_table_name,$query);
|
310 |
+
}
|
311 |
|
312 |
$this->execute_sql($query);
|
313 |
}
|
314 |
|
315 |
+
private function create_table($query,&$current_old_table)
|
316 |
{
|
317 |
global $wpvivid_pulgin;
|
318 |
$table_name='';
|
319 |
if (preg_match('/^\s*CREATE TABLE +\`?([^\`]*)\`?/i', $query, $matches))
|
320 |
{
|
321 |
$table_name = $matches[1];
|
322 |
+
$current_old_table=$table_name;
|
323 |
}
|
324 |
|
325 |
if(!empty($this->old_prefix)&&$this->old_prefix!=$this->new_prefix)
|
326 |
{
|
|
|
327 |
$new_table_name=$this->new_prefix.substr($table_name,strlen($this->old_prefix));
|
|
|
328 |
$query=str_replace($table_name,$new_table_name,$query);
|
329 |
$wpvivid_pulgin->restore_data->write_log('Create table '.$new_table_name,'notice');
|
330 |
$table_name=$new_table_name;
|
426 |
{
|
427 |
$table_name = $matches[1];
|
428 |
$new_table_name=$this->new_prefix.substr($table_name,strlen($this->old_prefix));
|
|
|
429 |
$query=str_replace($table_name,$new_table_name,$query);
|
430 |
}
|
431 |
}
|
446 |
$query=str_replace($table_name,$new_table_name,$query);
|
447 |
}
|
448 |
}
|
449 |
+
$wpvivid_pulgin->restore_data->write_log('Drop table if exist','notice');
|
450 |
$this->execute_sql($query);
|
451 |
}
|
452 |
|
485 |
}
|
486 |
}
|
487 |
|
488 |
+
if($this->old_site_url==$this->new_site_url)
|
489 |
+
return ;
|
490 |
+
|
491 |
$skip_table=false;
|
492 |
if(apply_filters('wpvivid_restore_db_skip_replace_tables',$skip_table,$table_name))
|
493 |
{
|
497 |
|
498 |
$query = 'SELECT COUNT(*) FROM `'.$table_name.'`';
|
499 |
|
500 |
+
$result=$this->db_method->query($query,ARRAY_N);
|
501 |
+
if($result && sizeof($result)>0)
|
|
|
502 |
{
|
503 |
+
$count=$result[0][0];
|
504 |
+
$wpvivid_pulgin->restore_data->write_log('Count of rows in '.$table_name.': '.$count, 'notice');
|
505 |
+
if($count==0)
|
506 |
{
|
507 |
return ;
|
508 |
}
|
509 |
|
510 |
$query='DESCRIBE `'.$table_name.'`';
|
511 |
+
$result=$this->db_method->query($query,ARRAY_A);
|
512 |
+
//$result=$result -> fetchAll(PDO::FETCH_ASSOC);
|
513 |
$columns=array();
|
514 |
foreach ($result as $data)
|
515 |
{
|
520 |
$column['PRI']=0;
|
521 |
$columns[]=$column;
|
522 |
}
|
|
|
|
|
523 |
$page=5000;
|
524 |
|
525 |
$update_query='';
|
531 |
$end_row=$current_row+$page;
|
532 |
$query = 'SELECT * FROM `'.$table_name.'` LIMIT '.$current_row.', '.$end_row;
|
533 |
|
534 |
+
$result=$this->db_method->query($query,ARRAY_A);
|
535 |
+
if($result && sizeof($result)>0)
|
|
|
536 |
{
|
537 |
+
$rows = $result;
|
538 |
foreach ($rows as $row)
|
539 |
{
|
540 |
$update=array();
|
541 |
$where=array();
|
|
|
542 |
foreach ($columns as $column)
|
543 |
{
|
544 |
$old_data = $row[$column['Field']];
|
570 |
if(!empty($update)&&!empty($where))
|
571 |
{
|
572 |
$temp_query = 'UPDATE `'.$table_name.'` SET '.implode(', ', $update).' WHERE '.implode(' AND ', array_filter($where)).';';
|
573 |
+
|
574 |
+
$type=$this->db_method->get_type();
|
575 |
+
|
576 |
+
if($type=='pdo_mysql')
|
577 |
{
|
578 |
+
if($update_query=='')
|
579 |
+
{
|
580 |
+
$update_query=$temp_query;
|
581 |
+
if(strlen($update_query)>$this->db_method->get_max_allow_packet())
|
582 |
+
{
|
583 |
+
$wpvivid_pulgin->restore_data->write_log('update replace rows', 'notice');
|
584 |
+
$this->execute_sql($update_query);
|
585 |
+
|
586 |
+
$update_query='';
|
587 |
+
}
|
588 |
+
}
|
589 |
+
else if(strlen($temp_query)+strlen($update_query)>$this->db_method->get_max_allow_packet())
|
590 |
{
|
591 |
$wpvivid_pulgin->restore_data->write_log('update replace rows', 'notice');
|
592 |
$this->execute_sql($update_query);
|
593 |
|
594 |
$update_query='';
|
595 |
}
|
596 |
+
else
|
597 |
+
{
|
598 |
+
$update_query.=$temp_query;
|
599 |
+
}
|
600 |
}
|
601 |
+
else
|
602 |
{
|
603 |
+
$update_query=$temp_query;
|
604 |
$this->execute_sql($update_query);
|
|
|
605 |
$update_query='';
|
606 |
}
|
607 |
+
|
|
|
|
|
|
|
608 |
}
|
609 |
//return;
|
610 |
}
|
928 |
$skip_tables[]='dmsguestbook';
|
929 |
$skip_tables[]='relevanssi';
|
930 |
$skip_tables[]='wfFileMods';
|
931 |
+
$skip_tables[]='learnpress_sessions';
|
932 |
+
$skip_tables[]='icl_string_pages';
|
933 |
+
$skip_tables[]='webarx_event_log';
|
934 |
if(in_array(substr($table_name, strlen($this->new_prefix)),$skip_tables))
|
935 |
{
|
936 |
$skip_table=true;
|
961 |
return $skip_rows;
|
962 |
}
|
963 |
|
964 |
+
/*
|
965 |
private function check_max_allow_packet()
|
966 |
{
|
967 |
//$max_allow_packet
|
994 |
$this->max_allow_packet=1048576;
|
995 |
}
|
996 |
}
|
997 |
+
*/
|
998 |
public function check_max_allow_packet_ex()
|
999 |
{
|
1000 |
$max_all_packet_warning=false;
|
1001 |
+
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-restore-db-method.php';
|
1002 |
+
$this->db_method=new WPvivid_Restore_DB_Method();
|
1003 |
+
$this->db_method->set_skip_query(0);
|
1004 |
+
|
1005 |
+
$ret=$this->db_method->connect_db();
|
1006 |
if($ret['result']==WPVIVID_SUCCESS)
|
1007 |
{
|
1008 |
+
$max_allowed_packet = $this->db_method->query("SELECT @@session.max_allowed_packet;",ARRAY_N);
|
1009 |
if($max_allowed_packet)
|
1010 |
{
|
|
|
1011 |
if(is_array($max_allowed_packet)&&isset($max_allowed_packet[0])&&isset($max_allowed_packet[0][0]))
|
1012 |
{
|
1013 |
if($max_allowed_packet[0][0]<16777216){
|
1021 |
|
1022 |
private function execute_sql($query)
|
1023 |
{
|
1024 |
+
$this->db_method->execute_sql($query);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1025 |
}
|
1026 |
|
1027 |
}
|
includes/class-wpvivid-restore-db-method.php
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Created by PhpStorm.
|
4 |
+
* User: alienware`x
|
5 |
+
* Date: 2019/6/11
|
6 |
+
* Time: 13:26
|
7 |
+
*/
|
8 |
+
|
9 |
+
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-restore-db-pdo-mysql-method.php';
|
10 |
+
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-restore-db-wpdb-method.php';
|
11 |
+
|
12 |
+
class WPvivid_Restore_DB_Method
|
13 |
+
{
|
14 |
+
private $db;
|
15 |
+
private $type;
|
16 |
+
|
17 |
+
public function __construct()
|
18 |
+
{
|
19 |
+
global $wpvivid_pulgin;
|
20 |
+
if(class_exists('PDO'))
|
21 |
+
{
|
22 |
+
$extensions=get_loaded_extensions();
|
23 |
+
if(array_search('pdo_mysql',$extensions))
|
24 |
+
{
|
25 |
+
$wpvivid_pulgin->restore_data->write_log('pdo_mysql', 'Warning');
|
26 |
+
$this->db =new WPvivid_Restore_DB_PDO_Mysql_Method();
|
27 |
+
$this->type='pdo_mysql';
|
28 |
+
return;
|
29 |
+
}
|
30 |
+
}
|
31 |
+
$wpvivid_pulgin->restore_data->write_log('wpdb', 'Warning');
|
32 |
+
$this->db =new WPvivid_Restore_DB_WPDB_Method();
|
33 |
+
$this->type='wpdb';
|
34 |
+
}
|
35 |
+
|
36 |
+
public function get_type()
|
37 |
+
{
|
38 |
+
return $this->type;
|
39 |
+
}
|
40 |
+
|
41 |
+
public function connect_db()
|
42 |
+
{
|
43 |
+
return $this->db->connect_db();
|
44 |
+
}
|
45 |
+
|
46 |
+
public function test_db()
|
47 |
+
{
|
48 |
+
return $this->db->test_db();
|
49 |
+
}
|
50 |
+
|
51 |
+
public function check_max_allow_packet()
|
52 |
+
{
|
53 |
+
$this->db->check_max_allow_packet();
|
54 |
+
}
|
55 |
+
|
56 |
+
public function get_max_allow_packet()
|
57 |
+
{
|
58 |
+
return $this->db->get_max_allow_packet();
|
59 |
+
}
|
60 |
+
|
61 |
+
public function init_sql_mode()
|
62 |
+
{
|
63 |
+
$this->db->init_sql_mode();
|
64 |
+
}
|
65 |
+
|
66 |
+
public function set_skip_query($count)
|
67 |
+
{
|
68 |
+
$this->db->set_skip_query($count);
|
69 |
+
}
|
70 |
+
|
71 |
+
public function execute_sql($query)
|
72 |
+
{
|
73 |
+
$this->db->execute_sql($query);
|
74 |
+
}
|
75 |
+
|
76 |
+
public function query($sql,$output=ARRAY_A)
|
77 |
+
{
|
78 |
+
return $this->db->query($sql,$output);
|
79 |
+
}
|
80 |
+
|
81 |
+
public function errorInfo()
|
82 |
+
{
|
83 |
+
return $this->db->errorInfo();
|
84 |
+
}
|
85 |
+
}
|
includes/class-wpvivid-restore-db-pdo-mysql-method.php
ADDED
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Created by PhpStorm.
|
4 |
+
* User: alienware`x
|
5 |
+
* Date: 2019/6/12
|
6 |
+
* Time: 15:46
|
7 |
+
*/
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
class WPvivid_Restore_DB_PDO_Mysql_Method
|
12 |
+
{
|
13 |
+
private $db;
|
14 |
+
private $max_allow_packet;
|
15 |
+
private $skip_query=0;
|
16 |
+
|
17 |
+
public function connect_db()
|
18 |
+
{
|
19 |
+
$db_host=DB_HOST;
|
20 |
+
try
|
21 |
+
{
|
22 |
+
$this->db = null;
|
23 |
+
$this->db=new PDO('mysql:host=' . $db_host . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD );
|
24 |
+
$this->db->exec('SET NAMES utf8');
|
25 |
+
if(empty($this->db) || !$this->db)
|
26 |
+
{
|
27 |
+
$ret['result']=WPVIVID_FAILED;
|
28 |
+
$ret['error']='The error establishing a database connection. Please check wp-config.php file and make sure the information is correct.';
|
29 |
+
}
|
30 |
+
else
|
31 |
+
{
|
32 |
+
$ret['result']=WPVIVID_SUCCESS;
|
33 |
+
}
|
34 |
+
}
|
35 |
+
catch (Exception $e)
|
36 |
+
{
|
37 |
+
if(empty($this->db) || !$this->db)
|
38 |
+
{
|
39 |
+
$ret['result']=WPVIVID_FAILED;
|
40 |
+
$ret['error']='The error establishing a database connection. Please check wp-config.php file and make sure the information is correct.';
|
41 |
+
}
|
42 |
+
else
|
43 |
+
{
|
44 |
+
$ret['result']=WPVIVID_FAILED;
|
45 |
+
$ret['error']=$e->getMessage();
|
46 |
+
}
|
47 |
+
}
|
48 |
+
return $ret;
|
49 |
+
}
|
50 |
+
|
51 |
+
public function test_db()
|
52 |
+
{
|
53 |
+
global $wpvivid_pulgin;
|
54 |
+
$test_table_new=uniqid('wpvivid_test_tables_');
|
55 |
+
$columns='(test_id int)';
|
56 |
+
$test_table = $this->db->exec("CREATE TABLE IF NOT EXISTS $test_table_new $columns");
|
57 |
+
|
58 |
+
if ($test_table!==false)
|
59 |
+
{
|
60 |
+
$wpvivid_pulgin->restore_data->write_log('The test to create table succeeds.','notice');
|
61 |
+
$test_table = $this->db->exec("INSERT INTO $test_table_new (`test_id`) VALUES ('123')");
|
62 |
+
if($test_table!==false)
|
63 |
+
{
|
64 |
+
$wpvivid_pulgin->restore_data->write_log('The test to insert into table succeeds.','notice');
|
65 |
+
$test_table = $this->db->exec("DROP TABLE IF EXISTS $test_table_new");
|
66 |
+
if($test_table!==false)
|
67 |
+
{
|
68 |
+
$wpvivid_pulgin->restore_data->write_log('The test to drop table succeeds.','notice');
|
69 |
+
return true;
|
70 |
+
}
|
71 |
+
else
|
72 |
+
{
|
73 |
+
$error=$this->db->errorInfo();
|
74 |
+
$wpvivid_pulgin->restore_data->write_log('Unable to drop table. The reason is '.$error[2],'warning');
|
75 |
+
return false;
|
76 |
+
}
|
77 |
+
}
|
78 |
+
else
|
79 |
+
{
|
80 |
+
$error=$this->db->errorInfo();
|
81 |
+
$wpvivid_pulgin->restore_data->write_log('Unable to insert into table. The reason is '.$error[2],'warning');
|
82 |
+
return false;
|
83 |
+
}
|
84 |
+
}
|
85 |
+
else {
|
86 |
+
$error=$this->db->errorInfo();
|
87 |
+
$wpvivid_pulgin->restore_data->write_log('Unable to create table. The reason is '.$error[2],'warning');
|
88 |
+
return false;
|
89 |
+
}
|
90 |
+
}
|
91 |
+
|
92 |
+
public function check_max_allow_packet()
|
93 |
+
{
|
94 |
+
global $wpvivid_pulgin;
|
95 |
+
|
96 |
+
$max_allowed_packet = $this->db->query("SELECT @@session.max_allowed_packet;");
|
97 |
+
if($max_allowed_packet)
|
98 |
+
{
|
99 |
+
$max_allowed_packet = $max_allowed_packet -> fetchAll();
|
100 |
+
|
101 |
+
if(is_array($max_allowed_packet)&&isset($max_allowed_packet[0])&&isset($max_allowed_packet[0][0]))
|
102 |
+
{
|
103 |
+
if($max_allowed_packet[0][0]<1048576)
|
104 |
+
{
|
105 |
+
$wpvivid_pulgin->restore_data->write_log('warning: max_allowed_packet less than 1M :'.size_format($max_allowed_packet[0][0],2),'notice');
|
106 |
+
}
|
107 |
+
else if($max_allowed_packet[0][0]<33554432)
|
108 |
+
{
|
109 |
+
$wpvivid_pulgin->restore_data->write_log('max_allowed_packet less than 32M :'.size_format($max_allowed_packet[0][0],2),'notice');
|
110 |
+
}
|
111 |
+
$this->max_allow_packet=$max_allowed_packet[0][0];
|
112 |
+
$wpvivid_pulgin->restore_data->write_log( $this->max_allow_packet,'notice');
|
113 |
+
}
|
114 |
+
else
|
115 |
+
{
|
116 |
+
$wpvivid_pulgin->restore_data->write_log('get max_allowed_packet failed','notice');
|
117 |
+
$this->max_allow_packet=1048576;
|
118 |
+
}
|
119 |
+
}
|
120 |
+
else
|
121 |
+
{
|
122 |
+
$wpvivid_pulgin->restore_data->write_log('get max_allowed_packet failed','notice');
|
123 |
+
$this->max_allow_packet=1048576;
|
124 |
+
}
|
125 |
+
}
|
126 |
+
|
127 |
+
public function get_max_allow_packet()
|
128 |
+
{
|
129 |
+
return $this->max_allow_packet;
|
130 |
+
}
|
131 |
+
|
132 |
+
public function init_sql_mode()
|
133 |
+
{
|
134 |
+
$res = $this->db->query('SELECT @@SESSION.sql_mode') -> fetchAll();
|
135 |
+
$sql_mod = $res[0][0];
|
136 |
+
$temp_sql_mode = str_replace('NO_ENGINE_SUBSTITUTION','',$sql_mod);
|
137 |
+
$temp_sql_mode = 'NO_AUTO_VALUE_ON_ZERO,'.$temp_sql_mode;
|
138 |
+
$this->db->query('SET SESSION sql_mode = "'.$temp_sql_mode.'"');
|
139 |
+
}
|
140 |
+
|
141 |
+
public function set_skip_query($count)
|
142 |
+
{
|
143 |
+
$this->skip_query=$count;
|
144 |
+
}
|
145 |
+
|
146 |
+
public function execute_sql($query)
|
147 |
+
{
|
148 |
+
global $wpvivid_pulgin;
|
149 |
+
|
150 |
+
if($this->skip_query>10)
|
151 |
+
{
|
152 |
+
if(strlen($query)>$this->max_allow_packet)
|
153 |
+
{
|
154 |
+
$wpvivid_pulgin->restore_data->write_log('skip query size:'.size_format(strlen($query)), 'Warning');
|
155 |
+
return ;
|
156 |
+
}
|
157 |
+
}
|
158 |
+
|
159 |
+
if ($this->db->exec($query)===false)
|
160 |
+
{
|
161 |
+
$info=$this->db->errorInfo();
|
162 |
+
$wpvivid_pulgin->restore_data->write_log($query.' query: [' . implode('][', $info) . ']', 'Warning');
|
163 |
+
|
164 |
+
if($info[1] == 2006)
|
165 |
+
{
|
166 |
+
if(strlen($query)>$this->max_allow_packet)
|
167 |
+
{
|
168 |
+
$this->skip_query++;
|
169 |
+
$wpvivid_pulgin->restore_data->write_log('max_allow_packet too small:'.size_format($this->max_allow_packet).' query size:'.size_format(strlen($query)), 'Warning');
|
170 |
+
}
|
171 |
+
$ret=$this->connect_db();
|
172 |
+
if($ret['result']==WPVIVID_FAILED)
|
173 |
+
{
|
174 |
+
$wpvivid_pulgin->restore_data->write_log('reconnect failed', 'Warning');
|
175 |
+
}
|
176 |
+
else{
|
177 |
+
$wpvivid_pulgin->restore_data->write_log('reconnect succeed', 'Warning');
|
178 |
+
}
|
179 |
+
}
|
180 |
+
}
|
181 |
+
}
|
182 |
+
|
183 |
+
public function query($sql,$output)
|
184 |
+
{
|
185 |
+
$ret=$this->db->query($sql);
|
186 |
+
if($ret===false)
|
187 |
+
{
|
188 |
+
return $ret;
|
189 |
+
}
|
190 |
+
else
|
191 |
+
{
|
192 |
+
return $ret -> fetchAll();
|
193 |
+
}
|
194 |
+
}
|
195 |
+
|
196 |
+
public function errorInfo()
|
197 |
+
{
|
198 |
+
return $this->db->errorInfo();
|
199 |
+
}
|
200 |
+
}
|
includes/class-wpvivid-restore-db-wpdb-method.php
ADDED
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Created by PhpStorm.
|
4 |
+
* User: alienware`x
|
5 |
+
* Date: 2019/6/12
|
6 |
+
* Time: 15:49
|
7 |
+
*/
|
8 |
+
|
9 |
+
class WPvivid_Restore_DB_WPDB_Method
|
10 |
+
{
|
11 |
+
private $max_allow_packet;
|
12 |
+
private $skip_query=0;
|
13 |
+
|
14 |
+
public function connect_db()
|
15 |
+
{
|
16 |
+
global $wpdb;
|
17 |
+
$wpdb->get_results('SET NAMES utf8', ARRAY_A);
|
18 |
+
$ret['result']=WPVIVID_SUCCESS;
|
19 |
+
return $ret;
|
20 |
+
}
|
21 |
+
|
22 |
+
public function test_db()
|
23 |
+
{
|
24 |
+
global $wpvivid_pulgin;
|
25 |
+
global $wpdb;
|
26 |
+
|
27 |
+
$test_table_new=uniqid('wpvivid_test_tables_');
|
28 |
+
$columns='(test_id int)';
|
29 |
+
$test_table = $wpdb->get_results("CREATE TABLE IF NOT EXISTS $test_table_new $columns",ARRAY_A);
|
30 |
+
|
31 |
+
if ($test_table!==false)
|
32 |
+
{
|
33 |
+
$wpvivid_pulgin->restore_data->write_log('The test to create table succeeds.','notice');
|
34 |
+
$test_table = $wpdb->get_results("INSERT INTO $test_table_new (`test_id`) VALUES ('123')",ARRAY_A);
|
35 |
+
if($test_table!==false)
|
36 |
+
{
|
37 |
+
$wpvivid_pulgin->restore_data->write_log('The test to insert into table succeeds.','notice');
|
38 |
+
$test_table = $wpdb->get_results("DROP TABLE IF EXISTS $test_table_new",ARRAY_A);
|
39 |
+
if($test_table!==false)
|
40 |
+
{
|
41 |
+
$wpvivid_pulgin->restore_data->write_log('The test to drop table succeeds.','notice');
|
42 |
+
return true;
|
43 |
+
}
|
44 |
+
else
|
45 |
+
{
|
46 |
+
$error=$wpdb->last_error;
|
47 |
+
$wpvivid_pulgin->restore_data->write_log('Unable to drop table. The reason is '.$error,'warning');
|
48 |
+
return false;
|
49 |
+
}
|
50 |
+
}
|
51 |
+
else
|
52 |
+
{
|
53 |
+
$error=$wpdb->last_error;
|
54 |
+
$wpvivid_pulgin->restore_data->write_log('Unable to insert into table. The reason is '.$error,'warning');
|
55 |
+
return false;
|
56 |
+
}
|
57 |
+
}
|
58 |
+
else {
|
59 |
+
$error=$wpdb->last_error;
|
60 |
+
$wpvivid_pulgin->restore_data->write_log('Unable to create table. The reason is '.$error,'warning');
|
61 |
+
return false;
|
62 |
+
}
|
63 |
+
}
|
64 |
+
|
65 |
+
public function check_max_allow_packet()
|
66 |
+
{
|
67 |
+
global $wpvivid_pulgin;
|
68 |
+
|
69 |
+
$wpvivid_pulgin->restore_data->write_log('get max_allowed_packet wpdb ','notice');
|
70 |
+
global $wpdb;
|
71 |
+
$max_allowed_packet =$wpdb->get_var("SELECT @@session.max_allowed_packet");
|
72 |
+
if($max_allowed_packet!==null)
|
73 |
+
{
|
74 |
+
if($max_allowed_packet<1048576)
|
75 |
+
{
|
76 |
+
$wpvivid_pulgin->restore_data->write_log('warning: max_allowed_packet less than 1M :'.size_format($max_allowed_packet,2),'notice');
|
77 |
+
}
|
78 |
+
else if($max_allowed_packet<33554432)
|
79 |
+
{
|
80 |
+
$wpvivid_pulgin->restore_data->write_log('max_allowed_packet less than 32M :'.size_format($max_allowed_packet,2),'notice');
|
81 |
+
}
|
82 |
+
$this->max_allow_packet=$max_allowed_packet;
|
83 |
+
}
|
84 |
+
else
|
85 |
+
{
|
86 |
+
$wpvivid_pulgin->restore_data->write_log('get max_allowed_packet failed ','notice');
|
87 |
+
$this->max_allow_packet=1048576;
|
88 |
+
}
|
89 |
+
}
|
90 |
+
|
91 |
+
public function get_max_allow_packet()
|
92 |
+
{
|
93 |
+
return $this->max_allow_packet;
|
94 |
+
}
|
95 |
+
|
96 |
+
public function init_sql_mode()
|
97 |
+
{
|
98 |
+
global $wpdb;
|
99 |
+
$res = $wpdb->get_var('SELECT @@SESSION.sql_mode');
|
100 |
+
if($res===null)
|
101 |
+
{
|
102 |
+
global $wpvivid_pulgin;
|
103 |
+
$wpvivid_pulgin->restore_data->write_log('get sql_mode failed','notice');
|
104 |
+
}
|
105 |
+
else
|
106 |
+
{
|
107 |
+
$sql_mod = $res;
|
108 |
+
$temp_sql_mode = str_replace('NO_ENGINE_SUBSTITUTION','',$sql_mod);
|
109 |
+
$temp_sql_mode = 'ALLOW_INVALID_DATES,NO_AUTO_VALUE_ON_ZERO,'.$temp_sql_mode;
|
110 |
+
$wpdb->get_results('SET SESSION sql_mode = "'.$temp_sql_mode.'"',ARRAY_A);
|
111 |
+
}
|
112 |
+
|
113 |
+
}
|
114 |
+
|
115 |
+
public function set_skip_query($count)
|
116 |
+
{
|
117 |
+
$this->skip_query=$count;
|
118 |
+
}
|
119 |
+
|
120 |
+
public function execute_sql($query)
|
121 |
+
{
|
122 |
+
global $wpvivid_pulgin;
|
123 |
+
|
124 |
+
global $wpdb;
|
125 |
+
//$wpvivid_pulgin->restore_data->write_log('query:'.$query, 'notice');
|
126 |
+
if ($wpdb->get_results($query)===false)
|
127 |
+
{
|
128 |
+
$error=$wpdb->last_error;
|
129 |
+
$wpvivid_pulgin->restore_data->write_log($error, 'Warning');
|
130 |
+
|
131 |
+
/*
|
132 |
+
if($info[1] == 2006)
|
133 |
+
{
|
134 |
+
if(strlen($query)>$this->max_allow_packet)
|
135 |
+
{
|
136 |
+
$this->skip_query++;
|
137 |
+
$wpvivid_pulgin->restore_data->write_log('max_allow_packet too small:'.size_format($this->max_allow_packet).' query size:'.size_format(strlen($query)), 'Warning');
|
138 |
+
}
|
139 |
+
$ret=$this->connect_db();
|
140 |
+
if($ret['result']==WPVIVID_FAILED)
|
141 |
+
{
|
142 |
+
$wpvivid_pulgin->restore_data->write_log('reconnect failed', 'Warning');
|
143 |
+
}
|
144 |
+
else{
|
145 |
+
$wpvivid_pulgin->restore_data->write_log('reconnect succeed', 'Warning');
|
146 |
+
}
|
147 |
+
}
|
148 |
+
*/
|
149 |
+
}
|
150 |
+
}
|
151 |
+
|
152 |
+
public function query($sql,$output)
|
153 |
+
{
|
154 |
+
global $wpdb;
|
155 |
+
return $wpdb->get_results($sql,$output);
|
156 |
+
}
|
157 |
+
|
158 |
+
public function errorInfo()
|
159 |
+
{
|
160 |
+
global $wpdb;
|
161 |
+
return $wpdb->last_error;;
|
162 |
+
}
|
163 |
+
}
|
includes/class-wpvivid-restore-site.php
CHANGED
@@ -68,10 +68,9 @@ class WPvivid_RestoreSite
|
|
68 |
$include_path=array();
|
69 |
}
|
70 |
|
71 |
-
$wpvivid_pulgin->restore_data->write_log('backup old file site','notice');
|
72 |
-
|
73 |
if(!isset($option['skip_backup_old_site']))
|
74 |
{
|
|
|
75 |
$this->pre_restore($root_path,$old_path,$include_path,$exclude_path);
|
76 |
}
|
77 |
|
68 |
$include_path=array();
|
69 |
}
|
70 |
|
|
|
|
|
71 |
if(!isset($option['skip_backup_old_site']))
|
72 |
{
|
73 |
+
$wpvivid_pulgin->restore_data->write_log('backup old file site','notice');
|
74 |
$this->pre_restore($root_path,$old_path,$include_path,$exclude_path);
|
75 |
}
|
76 |
|
includes/class-wpvivid-schedule.php
CHANGED
@@ -6,25 +6,23 @@ if (!defined('WPVIVID_PLUGIN_DIR')){
|
|
6 |
|
7 |
class WPvivid_Schedule
|
8 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
public function wpvivid_cron_schedules($schedules)
|
10 |
{
|
11 |
-
if(!isset($schedules["wpvivid_4hours"])){
|
12 |
-
$schedules["wpvivid_4hours"] = array(
|
13 |
-
'interval' => 3600*4,
|
14 |
-
'display' => __('4 Hours'));
|
15 |
-
}
|
16 |
-
if(!isset($schedules["wpvivid_6hours"])){
|
17 |
-
$schedules["wpvivid_6hours"] = array(
|
18 |
-
'interval' => 3600*6,
|
19 |
-
'display' => __('6 Hours'));
|
20 |
-
}
|
21 |
-
|
22 |
-
if(!isset($schedules["wpvivid_8hours"])){
|
23 |
-
$schedules["wpvivid_8hours"] = array(
|
24 |
-
'interval' => 3600*8,
|
25 |
-
'display' => __('8 Hours'));
|
26 |
-
}
|
27 |
-
|
28 |
if(!isset($schedules["wpvivid_12hours"])){
|
29 |
$schedules["wpvivid_12hours"] = array(
|
30 |
'interval' => 3600*12,
|
@@ -58,22 +56,39 @@ class WPvivid_Schedule
|
|
58 |
return $schedules;
|
59 |
}
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
public function output($html)
|
62 |
{
|
63 |
-
$html='
|
64 |
-
|
65 |
-
|
66 |
-
$
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
74 |
|
75 |
-
$html.=' <label><input type="radio" option="schedule" name="recurrence" value="wpvivid_monthly" />';
|
76 |
-
$html.='<span>Monthly</span></label><br>';
|
77 |
return $html;
|
78 |
}
|
79 |
|
@@ -93,7 +108,64 @@ class WPvivid_Schedule
|
|
93 |
$day=$time['start_time']['day'];
|
94 |
$current_day=$time['start_time']['current_day'];
|
95 |
|
96 |
-
if(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
{
|
98 |
if(strtotime('now')>strtotime($current_day))
|
99 |
{
|
@@ -152,7 +224,7 @@ class WPvivid_Schedule
|
|
152 |
}
|
153 |
|
154 |
return strtotime($temp);
|
155 |
-
}
|
156 |
|
157 |
return false;
|
158 |
}
|
@@ -245,7 +317,6 @@ class WPvivid_Schedule
|
|
245 |
$timestamp = wp_next_scheduled($schedule_data['event']);
|
246 |
wp_unschedule_event($timestamp,$schedule_data['event']);
|
247 |
}
|
248 |
-
|
249 |
if(wp_schedule_event($schedule_data['start_time'], $schedule_data['type'], $schedule_data['event'])===false)
|
250 |
{
|
251 |
$ret['result']='failed';
|
6 |
|
7 |
class WPvivid_Schedule
|
8 |
{
|
9 |
+
protected $schedule_type = array(
|
10 |
+
'wpvivid_12hours' => '12Hours',
|
11 |
+
'twicedaily' => '12Hours',
|
12 |
+
'wpvivid_daily' => 'Daily',
|
13 |
+
'daily' => 'Daily',
|
14 |
+
'onceday' => 'Daily',
|
15 |
+
'wpvivid_weekly' => 'Weekly',
|
16 |
+
'weekly' => 'Weekly',
|
17 |
+
'wpvivid_fortnightly' => 'Fortnightly',
|
18 |
+
'fortnightly' => 'Fortnightly',
|
19 |
+
'wpvivid_monthly' => 'Monthly',
|
20 |
+
'monthly' => 'Monthly',
|
21 |
+
'montly' => 'Monthly'
|
22 |
+
);
|
23 |
+
|
24 |
public function wpvivid_cron_schedules($schedules)
|
25 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
if(!isset($schedules["wpvivid_12hours"])){
|
27 |
$schedules["wpvivid_12hours"] = array(
|
28 |
'interval' => 3600*12,
|
56 |
return $schedules;
|
57 |
}
|
58 |
|
59 |
+
public function check_schedule_type($display){
|
60 |
+
$schedules = wp_get_schedules();
|
61 |
+
$check_res = false;
|
62 |
+
$ret = array();
|
63 |
+
foreach ($this->schedule_type as $key => $value){
|
64 |
+
if($value == $display){
|
65 |
+
if(isset($schedules[$key])){
|
66 |
+
$check_res = true;
|
67 |
+
$ret['type']=$key;
|
68 |
+
break;
|
69 |
+
}
|
70 |
+
}
|
71 |
+
}
|
72 |
+
$ret['result']=$check_res;
|
73 |
+
return $ret;
|
74 |
+
}
|
75 |
+
|
76 |
public function output($html)
|
77 |
{
|
78 |
+
$html='';
|
79 |
+
|
80 |
+
$display_array = array("12Hours", "Daily", "Weekly", "Fortnightly", "Monthly");
|
81 |
+
foreach($display_array as $display){
|
82 |
+
$schedule_check = $this->check_schedule_type($display);
|
83 |
+
if($schedule_check['result']){
|
84 |
+
$html.=' <label><input type="radio" option="schedule" name="recurrence" value="'.$schedule_check['type'].'" />';
|
85 |
+
$html.='<span>'.$display.'</span></label><br>';
|
86 |
+
}
|
87 |
+
else{
|
88 |
+
$html.='<p>Warning: Unable to set '.$display.' backup schedule</p>';
|
89 |
+
}
|
90 |
+
}
|
91 |
|
|
|
|
|
92 |
return $html;
|
93 |
}
|
94 |
|
108 |
$day=$time['start_time']['day'];
|
109 |
$current_day=$time['start_time']['current_day'];
|
110 |
|
111 |
+
if(strtotime('now')>strtotime($current_day)){
|
112 |
+
$daily_start_time = $current_day.' +1 day';
|
113 |
+
}
|
114 |
+
else{
|
115 |
+
$daily_start_time = $current_day;
|
116 |
+
}
|
117 |
+
|
118 |
+
$weekly_tmp = $week.' '.$current_day;
|
119 |
+
if(strtotime('now')>strtotime($weekly_tmp)) {
|
120 |
+
$weekly_start_time = $week.' '.$weekly_tmp.' next week';
|
121 |
+
}
|
122 |
+
else{
|
123 |
+
$weekly_start_time = $weekly_tmp;
|
124 |
+
}
|
125 |
+
|
126 |
+
$date_now = date("Y-m-",time());
|
127 |
+
$monthly_tmp = $date_now.$day.' '.$current_day;
|
128 |
+
if(strtotime('now')>strtotime($monthly_tmp)){
|
129 |
+
$date_now = date("Y-m-",strtotime('+1 month'));
|
130 |
+
$monthly_start_time = $date_now.$day.' '.$current_day;
|
131 |
+
}
|
132 |
+
else{
|
133 |
+
$monthly_start_time = $monthly_tmp;
|
134 |
+
}
|
135 |
+
|
136 |
+
$schedule_type_ex = array(
|
137 |
+
'wpvivid_12hours' => '12Hours',
|
138 |
+
'twicedaily' => '12Hours',
|
139 |
+
'wpvivid_daily' => 'Daily',
|
140 |
+
'daily' => 'Daily',
|
141 |
+
'onceday' => 'Daily',
|
142 |
+
'wpvivid_weekly' => 'Weekly',
|
143 |
+
'weekly' => 'Weekly',
|
144 |
+
'wpvivid_fortnightly' => 'Fortnightly',
|
145 |
+
'fortnightly' => 'Fortnightly',
|
146 |
+
'wpvivid_monthly' => 'Monthly',
|
147 |
+
'monthly' => 'Monthly',
|
148 |
+
'montly' => 'Monthly'
|
149 |
+
);
|
150 |
+
|
151 |
+
$display_array = array(
|
152 |
+
"12Hours" => $daily_start_time,
|
153 |
+
"Daily" => $daily_start_time,
|
154 |
+
"Weekly" => $weekly_start_time,
|
155 |
+
"Fortnightly" => $weekly_start_time,
|
156 |
+
"Monthly" => $monthly_start_time
|
157 |
+
);
|
158 |
+
foreach ($schedule_type_ex as $key => $value){
|
159 |
+
if($key == $time['type']){
|
160 |
+
foreach ($display_array as $display_key => $display_value){
|
161 |
+
if($value == $display_key){
|
162 |
+
return strtotime($display_value);
|
163 |
+
}
|
164 |
+
}
|
165 |
+
}
|
166 |
+
}
|
167 |
+
|
168 |
+
/*if($time['type']=='wpvivid_12hours' || $time['type']=='twicedaily')
|
169 |
{
|
170 |
if(strtotime('now')>strtotime($current_day))
|
171 |
{
|
224 |
}
|
225 |
|
226 |
return strtotime($temp);
|
227 |
+
}*/
|
228 |
|
229 |
return false;
|
230 |
}
|
317 |
$timestamp = wp_next_scheduled($schedule_data['event']);
|
318 |
wp_unschedule_event($timestamp,$schedule_data['event']);
|
319 |
}
|
|
|
320 |
if(wp_schedule_event($schedule_data['start_time'], $schedule_data['type'], $schedule_data['event'])===false)
|
321 |
{
|
322 |
$ret['result']='failed';
|
includes/class-wpvivid-setting.php
CHANGED
@@ -76,6 +76,7 @@ class WPvivid_Setting
|
|
76 |
$compress_option['use_temp_file']=WPVIVID_DEFAULT_USE_TEMP;
|
77 |
$compress_option['use_temp_size']=WPVIVID_DEFAULT_USE_TEMP_SIZE;
|
78 |
$compress_option['exclude_file_size']=WPVIVID_DEFAULT_EXCLUDE_FILE_SIZE;
|
|
|
79 |
self::update_option('wpvivid_compress_setting',$compress_option);
|
80 |
return $compress_option;
|
81 |
}
|
@@ -125,6 +126,9 @@ class WPvivid_Setting
|
|
125 |
$common_option['estimate_backup']=WPVIVID_DEFAULT_ESTIMATE_BACKUP;
|
126 |
$common_option['max_resume_count']=WPVIVID_RESUME_RETRY_TIMES;
|
127 |
$common_option['memory_limit']=WPVIVID_MEMORY_LIMIT;
|
|
|
|
|
|
|
128 |
self::update_option('wpvivid_common_setting',$common_option);
|
129 |
return $common_option;
|
130 |
}
|
76 |
$compress_option['use_temp_file']=WPVIVID_DEFAULT_USE_TEMP;
|
77 |
$compress_option['use_temp_size']=WPVIVID_DEFAULT_USE_TEMP_SIZE;
|
78 |
$compress_option['exclude_file_size']=WPVIVID_DEFAULT_EXCLUDE_FILE_SIZE;
|
79 |
+
$compress_option['subpackage_plugin_upload']=WPVIVID_DEFAULT_SUBPACKAGE_PLUGIN_UPLOAD;
|
80 |
self::update_option('wpvivid_compress_setting',$compress_option);
|
81 |
return $compress_option;
|
82 |
}
|
126 |
$common_option['estimate_backup']=WPVIVID_DEFAULT_ESTIMATE_BACKUP;
|
127 |
$common_option['max_resume_count']=WPVIVID_RESUME_RETRY_TIMES;
|
128 |
$common_option['memory_limit']=WPVIVID_MEMORY_LIMIT;
|
129 |
+
$common_option['restore_memory_limit']=WPVIVID_RESTORE_MEMORY_LIMIT;
|
130 |
+
$common_option['migrate_size']=WPVIVID_MIGRATE_SIZE;
|
131 |
+
$common_option['low_resource_enable']=WPVIVID_DEFAULT_LOW_RESOURCE_MODE;
|
132 |
self::update_option('wpvivid_common_setting',$common_option);
|
133 |
return $common_option;
|
134 |
}
|
includes/class-wpvivid-tools.php
CHANGED
@@ -50,6 +50,12 @@ class WPvivid_tools
|
|
50 |
{
|
51 |
WPvivid_tools::deldir($path.DIRECTORY_SEPARATOR.$filename,'',true);
|
52 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
}
|
54 |
@closedir($handler);
|
55 |
}
|
@@ -71,6 +77,12 @@ class WPvivid_tools
|
|
71 |
{
|
72 |
WPvivid_tools::deldir($path.DIRECTORY_SEPARATOR.$filename,'',true);
|
73 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
}
|
75 |
@closedir($handler);
|
76 |
}
|
@@ -161,9 +173,15 @@ class WPvivid_tools
|
|
161 |
file_put_contents($file,json_encode($json));
|
162 |
}
|
163 |
public static function file_get_array($file){
|
|
|
164 |
if(file_exists($file)){
|
165 |
-
|
|
|
|
|
|
|
|
|
166 |
}else{
|
|
|
167 |
return array();
|
168 |
}
|
169 |
}
|
50 |
{
|
51 |
WPvivid_tools::deldir($path.DIRECTORY_SEPARATOR.$filename,'',true);
|
52 |
}
|
53 |
+
if(preg_match('#pclzip-.*\.tmp#', $filename)){
|
54 |
+
@unlink($path.DIRECTORY_SEPARATOR.$filename);
|
55 |
+
}
|
56 |
+
if(preg_match('#pclzip-.*\.gz#', $filename)){
|
57 |
+
@unlink($path.DIRECTORY_SEPARATOR.$filename);
|
58 |
+
}
|
59 |
}
|
60 |
@closedir($handler);
|
61 |
}
|
77 |
{
|
78 |
WPvivid_tools::deldir($path.DIRECTORY_SEPARATOR.$filename,'',true);
|
79 |
}
|
80 |
+
if(preg_match('#pclzip-.*\.tmp#', $filename)){
|
81 |
+
@unlink($path.DIRECTORY_SEPARATOR.$filename);
|
82 |
+
}
|
83 |
+
if(preg_match('#pclzip-.*\.gz#', $filename)){
|
84 |
+
@unlink($path.DIRECTORY_SEPARATOR.$filename);
|
85 |
+
}
|
86 |
}
|
87 |
@closedir($handler);
|
88 |
}
|
173 |
file_put_contents($file,json_encode($json));
|
174 |
}
|
175 |
public static function file_get_array($file){
|
176 |
+
global $wpvivid_pulgin;
|
177 |
if(file_exists($file)){
|
178 |
+
$get_file_ret = json_decode(file_get_contents($file),true);
|
179 |
+
if(empty($get_file_ret)){
|
180 |
+
$wpvivid_pulgin->restore_data->write_log('Failed to decode restore data file.', 'notice');
|
181 |
+
}
|
182 |
+
return $get_file_ret;
|
183 |
}else{
|
184 |
+
$wpvivid_pulgin->restore_data->write_log('Failed to open restore data file, the file may not exist.', 'notice');
|
185 |
return array();
|
186 |
}
|
187 |
}
|
includes/class-wpvivid-zipclass.php
CHANGED
@@ -21,6 +21,172 @@ class WPvivid_ZipClass extends Wpvivid_Compress_Default
|
|
21 |
}
|
22 |
}
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
public function compress($data)
|
25 |
{
|
26 |
if(!function_exists('get_home_path'))
|
@@ -189,7 +355,7 @@ class WPvivid_ZipClass extends Wpvivid_Compress_Default
|
|
189 |
return $zips;
|
190 |
}
|
191 |
|
192 |
-
|
193 |
{
|
194 |
global $wpvivid_pulgin;
|
195 |
|
@@ -245,7 +411,7 @@ class WPvivid_ZipClass extends Wpvivid_Compress_Default
|
|
245 |
@unlink($temp_path);
|
246 |
}
|
247 |
|
248 |
-
$wpvivid_pulgin->wpvivid_log->WriteLog('Prepare to zip files.
|
249 |
|
250 |
if($no_compress)
|
251 |
{
|
@@ -327,7 +493,6 @@ class WPvivid_ZipClass extends Wpvivid_Compress_Default
|
|
327 |
{
|
328 |
$archive = new PclZip($path);
|
329 |
$list = $archive->listContent();
|
330 |
-
|
331 |
foreach ($list as $item)
|
332 |
{
|
333 |
//index
|
@@ -366,6 +531,123 @@ class WPvivid_ZipClass extends Wpvivid_Compress_Default
|
|
366 |
|
367 |
return $files;
|
368 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
369 |
}
|
370 |
|
371 |
$wpvivid_old_time=0;
|
21 |
}
|
22 |
}
|
23 |
|
24 |
+
public function get_packages($data)
|
25 |
+
{
|
26 |
+
if(!function_exists('get_home_path'))
|
27 |
+
require_once(ABSPATH . 'wp-admin/includes/file.php');
|
28 |
+
$files = $this -> filesplit($data['compress']['max_file_size'],$data['files']);
|
29 |
+
|
30 |
+
$temp_dir = $data['path'].'temp-'.$data['prefix'].DIRECTORY_SEPARATOR;
|
31 |
+
if(!file_exists($temp_dir))
|
32 |
+
@mkdir($temp_dir);
|
33 |
+
$packages = array();
|
34 |
+
if(sizeof($files) > 1)
|
35 |
+
{
|
36 |
+
for($i =0;$i <sizeof($files);$i ++)
|
37 |
+
{
|
38 |
+
$package = array();
|
39 |
+
$path = $data['path'].$data['prefix'].'.part'.sprintf('%03d',($i +1)).'.zip';
|
40 |
+
|
41 |
+
$remove_path_size = strlen( $this -> transfer_path(get_home_path()));
|
42 |
+
|
43 |
+
if(isset($data['json_info']))
|
44 |
+
{
|
45 |
+
$package['json']=$data['json_info'];
|
46 |
+
}
|
47 |
+
|
48 |
+
$package['json']['root'] = substr($data['root_path'], $remove_path_size);
|
49 |
+
$package['json']['file']=basename($path);
|
50 |
+
$package['path'] = $path;
|
51 |
+
$package['files'] = $files[$i];
|
52 |
+
$packages[] = $package;
|
53 |
+
}
|
54 |
+
}else {
|
55 |
+
$package = array();
|
56 |
+
$path = $data['path'].$data['prefix'].'.zip';
|
57 |
+
|
58 |
+
$remove_path_size = strlen( $this -> transfer_path(get_home_path()));
|
59 |
+
|
60 |
+
if(isset($data['json_info']))
|
61 |
+
{
|
62 |
+
$package['json']=$data['json_info'];
|
63 |
+
}
|
64 |
+
|
65 |
+
$package['json']['root'] = substr($data['root_path'], $remove_path_size);
|
66 |
+
$package['json']['file']=basename($path);
|
67 |
+
$package['path'] = $path;
|
68 |
+
$package['files'] = $files[0];
|
69 |
+
$packages[] = $package;
|
70 |
+
}
|
71 |
+
|
72 |
+
$ret['packages']=$packages;
|
73 |
+
$ret['temp_dir']=$temp_dir;
|
74 |
+
return $ret;
|
75 |
+
}
|
76 |
+
|
77 |
+
public function get_plugin_packages($data)
|
78 |
+
{
|
79 |
+
if(!function_exists('get_home_path'))
|
80 |
+
require_once(ABSPATH . 'wp-admin/includes/file.php');
|
81 |
+
$files = $this -> filesplit_plugin(3000,$data['files']);
|
82 |
+
|
83 |
+
$temp_dir = $data['path'].'temp-'.$data['prefix'].DIRECTORY_SEPARATOR;
|
84 |
+
if(!file_exists($temp_dir))
|
85 |
+
@mkdir($temp_dir);
|
86 |
+
$packages = array();
|
87 |
+
|
88 |
+
if(sizeof($files) > 1)
|
89 |
+
{
|
90 |
+
for($i =0;$i <sizeof($files);$i ++)
|
91 |
+
{
|
92 |
+
$package = array();
|
93 |
+
$path = $data['path'].$data['prefix'].'.part'.sprintf('%03d',($i +1)).'.zip';
|
94 |
+
|
95 |
+
$remove_path_size = strlen( $this -> transfer_path(get_home_path()));
|
96 |
+
|
97 |
+
if(isset($data['json_info']))
|
98 |
+
{
|
99 |
+
$package['json']=$data['json_info'];
|
100 |
+
}
|
101 |
+
|
102 |
+
$package['json']['root'] = substr($data['root_path'], $remove_path_size);
|
103 |
+
$package['json']['file']=basename($path);
|
104 |
+
$package['path'] = $path;
|
105 |
+
$package['files'] = $files[$i];
|
106 |
+
$packages[] = $package;
|
107 |
+
}
|
108 |
+
}else {
|
109 |
+
$package = array();
|
110 |
+
$path = $data['path'].$data['prefix'].'.zip';
|
111 |
+
|
112 |
+
$remove_path_size = strlen( $this -> transfer_path(get_home_path()));
|
113 |
+
|
114 |
+
if(isset($data['json_info']))
|
115 |
+
{
|
116 |
+
$package['json']=$data['json_info'];
|
117 |
+
}
|
118 |
+
|
119 |
+
$package['json']['root'] = substr($data['root_path'], $remove_path_size);
|
120 |
+
$package['json']['file']=basename($path);
|
121 |
+
$package['path'] = $path;
|
122 |
+
$package['files'] = $files[0];
|
123 |
+
$packages[] = $package;
|
124 |
+
}
|
125 |
+
|
126 |
+
$ret['packages']=$packages;
|
127 |
+
$ret['temp_dir']=$temp_dir;
|
128 |
+
return $ret;
|
129 |
+
}
|
130 |
+
|
131 |
+
public function get_upload_packages($data)
|
132 |
+
{
|
133 |
+
if(!function_exists('get_home_path'))
|
134 |
+
require_once(ABSPATH . 'wp-admin/includes/file.php');
|
135 |
+
|
136 |
+
$max_size= $data['compress']['max_file_size'];
|
137 |
+
$max_size = str_replace('M', '', $max_size);
|
138 |
+
$size = intval($max_size) * 1024 * 1024;
|
139 |
+
|
140 |
+
$files = $this -> filesplit_plugin($size,$data['files'],0);
|
141 |
+
|
142 |
+
$temp_dir = $data['path'].'temp-'.$data['prefix'].DIRECTORY_SEPARATOR;
|
143 |
+
if(!file_exists($temp_dir))
|
144 |
+
@mkdir($temp_dir);
|
145 |
+
$packages = array();
|
146 |
+
|
147 |
+
if(sizeof($files) > 1)
|
148 |
+
{
|
149 |
+
for($i =0;$i <sizeof($files);$i ++)
|
150 |
+
{
|
151 |
+
$package = array();
|
152 |
+
$path = $data['path'].$data['prefix'].'.part'.sprintf('%03d',($i +1)).'.zip';
|
153 |
+
|
154 |
+
$remove_path_size = strlen( $this -> transfer_path(get_home_path()));
|
155 |
+
|
156 |
+
if(isset($data['json_info']))
|
157 |
+
{
|
158 |
+
$package['json']=$data['json_info'];
|
159 |
+
}
|
160 |
+
|
161 |
+
$package['json']['root'] = substr($data['root_path'], $remove_path_size);
|
162 |
+
$package['json']['file']=basename($path);
|
163 |
+
$package['path'] = $path;
|
164 |
+
$package['files'] = $files[$i];
|
165 |
+
$packages[] = $package;
|
166 |
+
}
|
167 |
+
}else {
|
168 |
+
$package = array();
|
169 |
+
$path = $data['path'].$data['prefix'].'.zip';
|
170 |
+
|
171 |
+
$remove_path_size = strlen( $this -> transfer_path(get_home_path()));
|
172 |
+
|
173 |
+
if(isset($data['json_info']))
|
174 |
+
{
|
175 |
+
$package['json']=$data['json_info'];
|
176 |
+
}
|
177 |
+
|
178 |
+
$package['json']['root'] = substr($data['root_path'], $remove_path_size);
|
179 |
+
$package['json']['file']=basename($path);
|
180 |
+
$package['path'] = $path;
|
181 |
+
$package['files'] = $files[0];
|
182 |
+
$packages[] = $package;
|
183 |
+
}
|
184 |
+
|
185 |
+
$ret['packages']=$packages;
|
186 |
+
$ret['temp_dir']=$temp_dir;
|
187 |
+
return $ret;
|
188 |
+
}
|
189 |
+
|
190 |
public function compress($data)
|
191 |
{
|
192 |
if(!function_exists('get_home_path'))
|
355 |
return $zips;
|
356 |
}
|
357 |
|
358 |
+
public function _zip($name,$files,$options,$json_info=false)
|
359 |
{
|
360 |
global $wpvivid_pulgin;
|
361 |
|
411 |
@unlink($temp_path);
|
412 |
}
|
413 |
|
414 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog('Prepare to zip files. file: '.basename($name),'notice');
|
415 |
|
416 |
if($no_compress)
|
417 |
{
|
493 |
{
|
494 |
$archive = new PclZip($path);
|
495 |
$list = $archive->listContent();
|
|
|
496 |
foreach ($list as $item)
|
497 |
{
|
498 |
//index
|
531 |
|
532 |
return $files;
|
533 |
}
|
534 |
+
|
535 |
+
public function filesplit_plugin($max_file_size,$files,$is_num=true)
|
536 |
+
{
|
537 |
+
$packages=array();
|
538 |
+
if($max_file_size == 0 || empty($max_file_size))
|
539 |
+
{
|
540 |
+
$packages[] = $files;
|
541 |
+
}else{
|
542 |
+
$folder_num_sum = 0;
|
543 |
+
$package = array();
|
544 |
+
|
545 |
+
foreach ($files as $file)
|
546 |
+
{
|
547 |
+
$folder_num=0;
|
548 |
+
if(is_dir($file))
|
549 |
+
{
|
550 |
+
if($is_num)
|
551 |
+
{
|
552 |
+
$folder_num=$this->get_folder_file_count($file);
|
553 |
+
}
|
554 |
+
else
|
555 |
+
{
|
556 |
+
$folder_num=$this->get_folder_file_size($file);
|
557 |
+
}
|
558 |
+
}
|
559 |
+
else
|
560 |
+
{
|
561 |
+
$folder_num_sum+=filesize($file);
|
562 |
+
}
|
563 |
+
|
564 |
+
if($folder_num > $max_file_size)
|
565 |
+
{
|
566 |
+
$temp_package[] = $file;
|
567 |
+
$packages[] = $temp_package;
|
568 |
+
$temp_package = array();
|
569 |
+
continue;
|
570 |
+
}
|
571 |
+
else
|
572 |
+
{
|
573 |
+
$folder_num_sum+=$folder_num;
|
574 |
+
}
|
575 |
+
|
576 |
+
if($folder_num_sum > $max_file_size)
|
577 |
+
{
|
578 |
+
$package[] = $file;
|
579 |
+
$packages[] = $package;
|
580 |
+
$package = array();
|
581 |
+
$folder_num_sum=0;
|
582 |
+
}
|
583 |
+
else{
|
584 |
+
$package[] = $file;
|
585 |
+
}
|
586 |
+
|
587 |
+
}
|
588 |
+
if(!empty($package))
|
589 |
+
$packages[] = $package;
|
590 |
+
}
|
591 |
+
return $packages;
|
592 |
+
}
|
593 |
+
|
594 |
+
public function get_folder_file_count($file)
|
595 |
+
{
|
596 |
+
$count=0;
|
597 |
+
$this->get_folder_file_count_loop($file,$count);
|
598 |
+
|
599 |
+
return $count;
|
600 |
+
}
|
601 |
+
|
602 |
+
function get_folder_file_count_loop($path,&$count)
|
603 |
+
{
|
604 |
+
$handler = opendir($path);
|
605 |
+
|
606 |
+
while (($filename = readdir($handler)) !== false)
|
607 |
+
{
|
608 |
+
if ($filename != "." && $filename != "..")
|
609 |
+
{
|
610 |
+
$count++;
|
611 |
+
|
612 |
+
if(is_dir($path . DIRECTORY_SEPARATOR . $filename))
|
613 |
+
{
|
614 |
+
$this->get_folder_file_count_loop($path . DIRECTORY_SEPARATOR . $filename,$count);
|
615 |
+
}
|
616 |
+
}
|
617 |
+
}
|
618 |
+
if($handler)
|
619 |
+
@closedir($handler);
|
620 |
+
}
|
621 |
+
|
622 |
+
function get_folder_file_size($file)
|
623 |
+
{
|
624 |
+
$count=0;
|
625 |
+
$this->get_folder_file_size_loop($file,$count);
|
626 |
+
|
627 |
+
return $count;
|
628 |
+
}
|
629 |
+
|
630 |
+
function get_folder_file_size_loop($path,&$count)
|
631 |
+
{
|
632 |
+
$handler = opendir($path);
|
633 |
+
|
634 |
+
while (($filename = readdir($handler)) !== false)
|
635 |
+
{
|
636 |
+
if ($filename != "." && $filename != "..")
|
637 |
+
{
|
638 |
+
if(is_dir($path . DIRECTORY_SEPARATOR . $filename))
|
639 |
+
{
|
640 |
+
$this->get_folder_file_size_loop($path . DIRECTORY_SEPARATOR . $filename,$count);
|
641 |
+
}
|
642 |
+
else
|
643 |
+
{
|
644 |
+
$count+=filesize($path . DIRECTORY_SEPARATOR . $filename);
|
645 |
+
}
|
646 |
+
}
|
647 |
+
}
|
648 |
+
if($handler)
|
649 |
+
@closedir($handler);
|
650 |
+
}
|
651 |
}
|
652 |
|
653 |
$wpvivid_old_time=0;
|
includes/class-wpvivid.php
CHANGED
@@ -113,7 +113,7 @@ class WPvivid {
|
|
113 |
add_action('wpvivid_handle_upload_succeed',array($this,'wpvivid_deal_upload_succeed'),9);
|
114 |
|
115 |
add_action('wpvivid_handle_backup_failed',array($this,'wpvivid_mark_task'),20);
|
116 |
-
|
117 |
//Initialisation schedule hook
|
118 |
$this->init_cron();
|
119 |
//Initialisation log object
|
@@ -129,7 +129,7 @@ class WPvivid {
|
|
129 |
add_action(WPVIVID_CLEAN_BACKUP_RECORD_EVENT,array($this,'clean_backup_record_event'));
|
130 |
//add_clean_event
|
131 |
add_action(WPVIVID_TASK_MONITOR_EVENT,array( $this,'task_monitor'));
|
132 |
-
add_filter('cron_schedules',array( $schedule,'wpvivid_cron_schedules'));
|
133 |
add_filter('wpvivid_schedule_time', array($schedule, 'output'));
|
134 |
}
|
135 |
|
@@ -159,12 +159,21 @@ class WPvivid {
|
|
159 |
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-crypt.php';
|
160 |
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-migrate.php';
|
161 |
|
|
|
162 |
|
163 |
$this->remote_collection=new WPvivid_Remote_collection();
|
164 |
$this->migrate=new WPvivid_Migrate();
|
165 |
$this->backup_uploader=new Wpvivid_BackupUploader();
|
166 |
}
|
167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
private function set_locale()
|
169 |
{
|
170 |
$plugin_i18n = new WPvivid_i18n();
|
@@ -482,10 +491,16 @@ class WPvivid {
|
|
482 |
public function delete_ready_task()
|
483 |
{
|
484 |
$this->ajax_check_security();
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
489 |
echo json_encode($ret);
|
490 |
die();
|
491 |
}
|
@@ -497,26 +512,31 @@ class WPvivid {
|
|
497 |
public function backup_now()
|
498 |
{
|
499 |
$this->ajax_check_security();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
500 |
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
$task_id=sanitize_key($_POST['task_id']);
|
509 |
|
510 |
-
|
511 |
-
|
512 |
-
{
|
513 |
-
$
|
514 |
-
$
|
515 |
-
echo json_encode(
|
516 |
die();
|
517 |
}
|
518 |
-
|
519 |
-
$this->backup($task_id);
|
520 |
die();
|
521 |
}
|
522 |
/**
|
@@ -527,52 +547,53 @@ class WPvivid {
|
|
527 |
public function view_backup_log()
|
528 |
{
|
529 |
$this->ajax_check_security();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
530 |
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
$json['result']='failed';
|
538 |
-
$json['error']=__('Retrieving the backup information failed while showing log. Please try again later.', 'wpvivid');
|
539 |
-
echo json_encode($json);
|
540 |
-
die();
|
541 |
-
}
|
542 |
|
543 |
-
|
544 |
-
{
|
545 |
-
$json['result']='failed';
|
546 |
-
$json['error']=__('The log not found.', 'wpvivid');
|
547 |
-
echo json_encode($json);
|
548 |
-
die();
|
549 |
-
}
|
550 |
|
551 |
-
|
|
|
|
|
|
|
|
|
|
|
552 |
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
die();
|
559 |
-
}
|
560 |
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
|
|
|
|
|
|
565 |
}
|
566 |
-
fclose($file);
|
567 |
-
|
568 |
-
$json['result']='success';
|
569 |
-
$json['data']=$buffer;
|
570 |
-
echo json_encode($json);
|
571 |
}
|
572 |
-
|
573 |
-
$
|
574 |
-
$
|
575 |
-
echo json_encode(
|
|
|
576 |
}
|
577 |
die();
|
578 |
}
|
@@ -584,44 +605,48 @@ class WPvivid {
|
|
584 |
public function read_last_backup_log()
|
585 |
{
|
586 |
$this->ajax_check_security();
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
}
|
604 |
|
605 |
-
|
606 |
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
611 |
echo json_encode($json);
|
612 |
-
die();
|
613 |
}
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
}
|
620 |
-
fclose($file);
|
621 |
-
|
622 |
-
$json['result']='success';
|
623 |
-
$json['data']=$buffer;
|
624 |
-
echo json_encode($json);
|
625 |
die();
|
626 |
}
|
627 |
/**
|
@@ -632,54 +657,55 @@ class WPvivid {
|
|
632 |
public function view_backup_task_log()
|
633 |
{
|
634 |
$this->ajax_check_security();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
635 |
|
636 |
-
|
637 |
-
{
|
638 |
-
$backup_task_id = sanitize_key($_POST['id']);
|
639 |
-
$option=WPvivid_taskmanager::get_task_options($backup_task_id,'log_file_name');
|
640 |
-
if(!$option)
|
641 |
-
{
|
642 |
-
$json['result']='failed';
|
643 |
-
$json['error']=__('Retrieving the backup information failed while showing log. Please try again later.', 'wpvivid');
|
644 |
-
echo json_encode($json);
|
645 |
-
die();
|
646 |
-
}
|
647 |
|
648 |
-
|
|
|
|
|
|
|
|
|
|
|
649 |
|
650 |
-
|
651 |
-
{
|
652 |
-
$json['result']='failed';
|
653 |
-
$json['error']=__('The log not found.', 'wpvivid');
|
654 |
-
echo json_encode($json);
|
655 |
-
die();
|
656 |
-
}
|
657 |
|
658 |
-
|
|
|
|
|
|
|
|
|
|
|
659 |
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
die();
|
666 |
-
}
|
667 |
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
|
|
|
|
|
|
672 |
}
|
673 |
-
fclose($file);
|
674 |
-
|
675 |
-
$json['result']='success';
|
676 |
-
$json['data']=$buffer;
|
677 |
-
echo json_encode($json);
|
678 |
}
|
679 |
-
|
680 |
-
$
|
681 |
-
$
|
682 |
-
echo json_encode(
|
|
|
683 |
}
|
684 |
die();
|
685 |
}
|
@@ -691,27 +717,31 @@ class WPvivid {
|
|
691 |
public function backup_cancel()
|
692 |
{
|
693 |
$this->ajax_check_security();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
694 |
|
695 |
-
|
696 |
-
{
|
697 |
-
$task_id=sanitize_key($_POST['task_id']);
|
698 |
-
if(WPvivid_taskmanager::get_task($task_id)!==false)
|
699 |
-
{
|
700 |
-
$file_name=WPvivid_taskmanager::get_task_options($task_id,'file_prefix');
|
701 |
-
$backup_options=WPvivid_taskmanager::get_task_options($task_id,'backup_options');
|
702 |
-
$file=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_options['dir'].DIRECTORY_SEPARATOR.$file_name.'_cancel';
|
703 |
-
touch($file);
|
704 |
-
}
|
705 |
-
|
706 |
-
$timestamp = wp_next_scheduled(WPVIVID_TASK_MONITOR_EVENT,array($task_id));
|
707 |
|
708 |
-
|
709 |
-
|
710 |
-
|
|
|
|
|
|
|
711 |
}
|
712 |
-
|
713 |
-
|
714 |
-
|
|
|
|
|
|
|
715 |
}
|
716 |
die();
|
717 |
}
|
@@ -797,6 +827,14 @@ class WPvivid {
|
|
797 |
die();
|
798 |
}
|
799 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
800 |
$doing=WPvivid_taskmanager::get_backup_main_task_progress($task_id);
|
801 |
if($doing=='backup')
|
802 |
{
|
@@ -995,7 +1033,7 @@ class WPvivid {
|
|
995 |
|
996 |
if(WPvivid_taskmanager::get_task_options($task_id,'remote_options')!=false)
|
997 |
{
|
998 |
-
$this->upload($task_id);
|
999 |
}
|
1000 |
}
|
1001 |
catch (Exception $e)
|
@@ -1084,15 +1122,15 @@ class WPvivid {
|
|
1084 |
* start upload files to remote.
|
1085 |
*
|
1086 |
* @var string $task_id
|
1087 |
-
*
|
1088 |
* @since 0.9.10
|
1089 |
*/
|
1090 |
-
public function upload($task_id)
|
1091 |
{
|
1092 |
$this->end_shutdown_function=false;
|
1093 |
register_shutdown_function(array($this,'deal_shutdown_error'),$task_id);
|
1094 |
@ignore_user_abort(true);
|
1095 |
-
WPvivid_taskmanager::update_backup_task_status($task_id,
|
1096 |
$this->current_task=WPvivid_taskmanager::get_task($task_id);
|
1097 |
//start a watch task event
|
1098 |
$this->add_monitor_event($task_id);
|
@@ -1266,7 +1304,7 @@ class WPvivid {
|
|
1266 |
do_action('wpvivid_handle_backup_failed', $task);
|
1267 |
} else {
|
1268 |
$this->check_cancel_backup($task_id);
|
1269 |
-
$message = 'Task timed out
|
1270 |
if ($this->add_resume_event($task_id))
|
1271 |
{
|
1272 |
WPvivid_taskmanager::update_backup_task_status($task_id, false, 'wait_resume', false, $status['resume_count']);
|
@@ -1342,7 +1380,7 @@ class WPvivid {
|
|
1342 |
*
|
1343 |
* @since 0.9.1
|
1344 |
*/
|
1345 |
-
public function task_monitor($task_id
|
1346 |
{
|
1347 |
if(WPvivid_taskmanager::get_task($task_id)!==false)
|
1348 |
{
|
@@ -1412,16 +1450,24 @@ class WPvivid {
|
|
1412 |
$this->add_monitor_event($task_id);
|
1413 |
}
|
1414 |
else{
|
1415 |
-
|
1416 |
-
|
1417 |
-
|
1418 |
-
|
1419 |
-
|
1420 |
-
|
1421 |
-
|
1422 |
-
|
1423 |
-
|
1424 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1425 |
}
|
1426 |
}
|
1427 |
}
|
@@ -1442,11 +1488,6 @@ class WPvivid {
|
|
1442 |
*/
|
1443 |
public function check_backup($task_id,$backup_files)
|
1444 |
{
|
1445 |
-
$ret['alert_db']=false;
|
1446 |
-
$ret['alter_files']=false;
|
1447 |
-
$ret['alter_big_file']=false;
|
1448 |
-
$ret['alter_fcgi']=false;
|
1449 |
-
|
1450 |
$options=WPvivid_Setting::get_option('wpvivid_common_setting');
|
1451 |
if(isset($options['estimate_backup']))
|
1452 |
{
|
@@ -1460,7 +1501,6 @@ class WPvivid {
|
|
1460 |
}
|
1461 |
}
|
1462 |
|
1463 |
-
$db_size=false;
|
1464 |
$file_size=false;
|
1465 |
$check_file=false;
|
1466 |
$check_db=false;
|
@@ -1491,100 +1531,23 @@ class WPvivid {
|
|
1491 |
}
|
1492 |
if($check_db)
|
1493 |
{
|
1494 |
-
$
|
1495 |
-
$
|
1496 |
-
|
1497 |
-
$res = explode(':',DB_HOST);
|
1498 |
-
$db_host = $res[0];
|
1499 |
-
$db_port = empty($res[1])?'':$res[1];
|
1500 |
-
if(!empty($db_port))
|
1501 |
-
$db_host = $db_host.':'.$db_port;
|
1502 |
-
try{
|
1503 |
-
$pdo=new PDO('mysql:host=' . $db_host . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD );
|
1504 |
-
}catch (Exception $e)
|
1505 |
-
{
|
1506 |
-
if(!empty($db_port)){
|
1507 |
-
$db_host = $res[0];
|
1508 |
-
$pdo=new PDO('mysql:host=' . $db_host . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD );
|
1509 |
-
}else{
|
1510 |
-
return array('result' => WPVIVID_FAILED,'error' => 'The error establishing a database connection. Please check wp-config.php file and make sure the information is correct.');
|
1511 |
-
}
|
1512 |
-
}
|
1513 |
-
|
1514 |
-
$sth = $pdo->query('SHOW TABLE STATUS');
|
1515 |
-
$dbSize = 0;
|
1516 |
-
$sum_rows=0;
|
1517 |
-
$rows = $sth->fetchAll();
|
1518 |
-
foreach ($rows as $row)
|
1519 |
-
{
|
1520 |
-
global $wpdb;
|
1521 |
-
if (is_multisite() && !defined('MULTISITE'))
|
1522 |
-
{
|
1523 |
-
$prefix = $wpdb->base_prefix;
|
1524 |
-
} else {
|
1525 |
-
$prefix = $wpdb->get_blog_prefix(0);
|
1526 |
-
}
|
1527 |
-
if(preg_match('/^(?!'.$prefix.')/', $row["Name"]) == 1){
|
1528 |
-
continue;
|
1529 |
-
}
|
1530 |
-
|
1531 |
-
$db_info[$row["Name"]]["Rows"]=$row["Rows"];
|
1532 |
-
$db_info[$row["Name"]]["Data_length"]=$this->formatBytes($row["Data_length"]+$row["Index_length"]);
|
1533 |
-
if($row["Rows"]>1000000)
|
1534 |
-
{
|
1535 |
-
$ret['big_tables'][$row["Name"]]['Rows']=$row["Rows"];
|
1536 |
-
$ret['big_tables'][$row["Name"]]['Data_length']=$this->formatBytes($row["Data_length"]+$row["Index_length"]);
|
1537 |
-
}
|
1538 |
-
|
1539 |
-
$sum_rows+=$row["Rows"];
|
1540 |
-
$dbSize+=$row["Data_length"]+$row["Index_length"];
|
1541 |
-
}
|
1542 |
-
if($alter_fcgi)
|
1543 |
-
{
|
1544 |
-
|
1545 |
-
$alter_sum_rows=4000000;
|
1546 |
-
}
|
1547 |
-
else
|
1548 |
-
{
|
1549 |
-
$alter_sum_rows=4000000*3;
|
1550 |
-
}
|
1551 |
-
|
1552 |
-
$memory_limit = ini_get('memory_limit');
|
1553 |
-
$ret['memory_limit']=$memory_limit;
|
1554 |
-
$memory_limit = trim($memory_limit);
|
1555 |
-
$memory_limit_int = (int) $memory_limit;
|
1556 |
-
$last = strtolower(substr($memory_limit, -1));
|
1557 |
-
|
1558 |
-
if($last == 'g')
|
1559 |
-
$memory_limit_int = $memory_limit_int*1024*1024*1024;
|
1560 |
-
if($last == 'm')
|
1561 |
-
$memory_limit_int = $memory_limit_int*1024*1024;
|
1562 |
-
if($last == 'k')
|
1563 |
-
$memory_limit_int = $memory_limit_int*1024;
|
1564 |
-
|
1565 |
-
if($dbSize>($memory_limit_int*0.9))
|
1566 |
-
{
|
1567 |
-
$max_rows=0;
|
1568 |
-
}
|
1569 |
-
else
|
1570 |
{
|
1571 |
-
$
|
1572 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1573 |
|
1574 |
-
|
1575 |
-
|
1576 |
-
|
1577 |
-
{
|
1578 |
-
//big db alert
|
1579 |
-
$ret['alert_db']=true;
|
1580 |
-
$ret['sum_rows']=$sum_rows;
|
1581 |
-
$ret['db_size']=$this->formatBytes($dbSize);
|
1582 |
-
if($alter_fcgi)
|
1583 |
-
$ret['alter_fcgi']=true;
|
1584 |
-
}
|
1585 |
|
1586 |
-
$db_size=$this->formatBytes($dbSize);
|
1587 |
-
}
|
1588 |
if($check_file)
|
1589 |
{
|
1590 |
include_once WPVIVID_PLUGIN_DIR .'/includes/class-wpvivid-backup.php';
|
@@ -1619,12 +1582,11 @@ class WPvivid {
|
|
1619 |
$file_size['sum']=$this->formatBytes($sum_size);
|
1620 |
}
|
1621 |
|
1622 |
-
$ret['db_size']=$db_size;
|
1623 |
$ret['file_size']=$file_size;
|
1624 |
if($task_id!==false)
|
1625 |
{
|
1626 |
$task=new WPvivid_Backup_Task($task_id);
|
1627 |
-
$task->set_file_and_db_info($db_size,$file_size);
|
1628 |
}
|
1629 |
return $ret;
|
1630 |
}
|
@@ -1862,14 +1824,19 @@ class WPvivid {
|
|
1862 |
public function init_download_page()
|
1863 |
{
|
1864 |
$this->ajax_check_security();
|
1865 |
-
|
1866 |
-
|
1867 |
-
|
1868 |
-
|
1869 |
-
|
1870 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1871 |
}
|
1872 |
-
|
1873 |
die();
|
1874 |
}
|
1875 |
/**
|
@@ -1911,43 +1878,44 @@ class WPvivid {
|
|
1911 |
public function prepare_download_backup()
|
1912 |
{
|
1913 |
$this->ajax_check_security();
|
1914 |
-
|
1915 |
-
|
1916 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1917 |
die();
|
1918 |
}
|
1919 |
-
|
1920 |
-
|
1921 |
-
|
1922 |
-
|
1923 |
-
|
1924 |
-
if
|
1925 |
-
session_write_close();
|
1926 |
-
try
|
1927 |
-
{
|
1928 |
-
$downloader=new WPvivid_downloader();
|
1929 |
-
$downloader->ready_download($download_info);
|
1930 |
-
}
|
1931 |
-
catch (Exception $e)
|
1932 |
-
{
|
1933 |
-
$message = 'A exception ('.get_class($e).') occurred '.$e->getMessage().' (Code: '.$e->getCode().', line '.$e->getLine().' in '.$e->getFile().')';
|
1934 |
-
error_log($message);
|
1935 |
-
}
|
1936 |
-
catch (Error $e)
|
1937 |
-
{
|
1938 |
-
$message = 'A error ('.get_class($e).') has occurred: '.$e->getMessage().' (Code: '.$e->getCode().', line '.$e->getLine().' in '.$e->getFile().')';
|
1939 |
-
error_log($message);
|
1940 |
-
}
|
1941 |
-
|
1942 |
-
$ret['result']='success';
|
1943 |
-
$json=json_encode($ret);
|
1944 |
-
echo $json;
|
1945 |
-
die();
|
1946 |
-
}
|
1947 |
-
|
1948 |
-
public function init_download($backup_id)
|
1949 |
-
{
|
1950 |
-
if(empty($backup_id))
|
1951 |
{
|
1952 |
$ret['result']=WPVIVID_SUCCESS;
|
1953 |
$ret['data']=array();
|
@@ -2284,65 +2252,60 @@ class WPvivid {
|
|
2284 |
public function delete_download()
|
2285 |
{
|
2286 |
$this->ajax_check_security();
|
2287 |
-
|
2288 |
-
|
2289 |
-
|
2290 |
-
die();
|
2291 |
-
}
|
2292 |
-
$download_info=array();
|
2293 |
-
$download_info['backup_id']=sanitize_key($_POST['backup_id']);
|
2294 |
-
//$download_info['file_name']=sanitize_file_name($_POST['file_name']);
|
2295 |
-
$download_info['file_name']=$_POST['file_name'];
|
2296 |
-
|
2297 |
-
$files=array();
|
2298 |
-
$backup=WPvivid_Backuplist::get_backuplist_by_key($download_info['backup_id']);
|
2299 |
-
if(!$backup)
|
2300 |
-
{
|
2301 |
-
$json['result']='failed';
|
2302 |
-
$json['error']=__('Retrieving the backup(s) information failed while deleting the selected backup(s). Please try again later.', 'wpvivid');
|
2303 |
-
json_encode($json);
|
2304 |
-
die();
|
2305 |
-
}
|
2306 |
-
if($backup['backup']['ismerge']==1)
|
2307 |
-
{
|
2308 |
-
$backup_files=$backup['backup']['data']['meta']['files'];
|
2309 |
-
foreach ($backup_files as $file)
|
2310 |
-
{
|
2311 |
-
if($file['file_name']==$download_info['file_name'])
|
2312 |
-
{
|
2313 |
-
$files[]=$file;
|
2314 |
-
break;
|
2315 |
-
}
|
2316 |
}
|
2317 |
-
|
2318 |
-
|
2319 |
-
|
2320 |
-
|
2321 |
-
|
2322 |
-
|
2323 |
-
|
2324 |
-
|
2325 |
-
|
2326 |
-
|
2327 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2328 |
break;
|
2329 |
}
|
2330 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2331 |
}
|
2332 |
-
}
|
2333 |
|
2334 |
-
|
2335 |
|
2336 |
-
|
2337 |
-
|
2338 |
-
|
2339 |
-
|
2340 |
-
|
2341 |
-
unlink($download_path);
|
2342 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2343 |
}
|
2344 |
-
$ret=$this->init_download($_POST['backup_id']);
|
2345 |
-
echo json_encode($ret);
|
2346 |
die();
|
2347 |
}
|
2348 |
/**
|
@@ -2353,88 +2316,77 @@ class WPvivid {
|
|
2353 |
public function download_backup()
|
2354 |
{
|
2355 |
$this->ajax_check_security();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2356 |
|
2357 |
-
|
2358 |
-
|
2359 |
-
|
2360 |
-
|
2361 |
-
|
2362 |
-
}
|
2363 |
-
else
|
2364 |
-
{
|
2365 |
-
die();
|
2366 |
-
}
|
2367 |
-
|
2368 |
-
if(!empty($_REQUEST['file_name'])&&is_string($_REQUEST['file_name']))
|
2369 |
-
{
|
2370 |
-
//$file_name=sanitize_file_name($_REQUEST['file_name']);
|
2371 |
-
$file_name=$_REQUEST['file_name'];
|
2372 |
-
}
|
2373 |
-
else
|
2374 |
-
{
|
2375 |
-
die();
|
2376 |
-
}
|
2377 |
-
|
2378 |
-
$cache=WPvivid_taskmanager::get_download_cache($backup_id);
|
2379 |
-
if($cache===false)
|
2380 |
-
{
|
2381 |
-
$this->init_download($backup_id);
|
2382 |
-
$cache=WPvivid_taskmanager::get_download_cache($backup_id);
|
2383 |
-
}
|
2384 |
-
$path=false;
|
2385 |
-
if(array_key_exists($file_name,$cache['files']))
|
2386 |
-
{
|
2387 |
-
if($cache['files'][$file_name]['status']=='completed')
|
2388 |
-
{
|
2389 |
-
$path=$cache['files'][$file_name]['download_path'];
|
2390 |
}
|
2391 |
-
}
|
2392 |
-
if($path!==false)
|
2393 |
-
{
|
2394 |
-
if (file_exists($path))
|
2395 |
-
{
|
2396 |
-
if (session_id())
|
2397 |
-
session_write_close();
|
2398 |
|
2399 |
-
|
2400 |
-
|
2401 |
-
|
2402 |
-
|
2403 |
-
|
2404 |
-
|
2405 |
-
|
2406 |
-
|
2407 |
-
|
2408 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2409 |
|
2410 |
-
|
2411 |
-
|
2412 |
-
|
2413 |
-
|
2414 |
-
|
2415 |
-
|
2416 |
-
|
2417 |
-
|
2418 |
-
|
2419 |
-
|
2420 |
-
|
2421 |
-
|
2422 |
-
|
2423 |
-
|
2424 |
-
|
2425 |
-
|
2426 |
-
|
2427 |
-
|
2428 |
-
|
2429 |
-
sleep(1);
|
2430 |
}
|
2431 |
-
fclose($file);
|
2432 |
-
exit;
|
2433 |
}
|
2434 |
}
|
2435 |
}
|
2436 |
}
|
2437 |
-
|
|
|
|
|
|
|
|
|
|
|
2438 |
$admin_url = admin_url();
|
2439 |
echo __('file not found. please <a href="'.$admin_url.'admin.php?page=WPvivid">retry</a>.');
|
2440 |
die();
|
@@ -2447,14 +2399,19 @@ class WPvivid {
|
|
2447 |
public function get_backup_list()
|
2448 |
{
|
2449 |
$this->ajax_check_security('manage_options');
|
2450 |
-
|
2451 |
-
|
2452 |
-
|
2453 |
-
|
2454 |
-
|
2455 |
-
|
2456 |
-
|
2457 |
-
|
|
|
|
|
|
|
|
|
|
|
2458 |
die();
|
2459 |
}
|
2460 |
/**
|
@@ -2465,26 +2422,28 @@ class WPvivid {
|
|
2465 |
public function delete_backup()
|
2466 |
{
|
2467 |
$this->ajax_check_security();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2468 |
|
2469 |
-
|
2470 |
-
|
2471 |
-
|
2472 |
-
|
2473 |
-
$
|
2474 |
-
}
|
2475 |
-
else
|
2476 |
-
{
|
2477 |
-
$force_del=0;
|
2478 |
}
|
2479 |
-
$backup_id=sanitize_key($_POST['backup_id']);
|
2480 |
-
|
2481 |
-
$ret=$this->delete_backup_by_id($backup_id, $force_del);
|
2482 |
-
$html = '';
|
2483 |
-
$html = apply_filters('wpvivid_add_backup_list', $html);
|
2484 |
-
$ret['html'] = $html;
|
2485 |
-
echo json_encode($ret);
|
2486 |
}
|
2487 |
-
|
|
|
|
|
|
|
|
|
|
|
2488 |
die();
|
2489 |
}
|
2490 |
/**
|
@@ -2495,22 +2454,26 @@ class WPvivid {
|
|
2495 |
public function delete_backup_array()
|
2496 |
{
|
2497 |
$this->ajax_check_security();
|
2498 |
-
|
2499 |
-
|
2500 |
-
|
2501 |
-
|
2502 |
-
|
2503 |
-
|
2504 |
-
|
2505 |
-
|
2506 |
-
$
|
|
|
|
|
|
|
2507 |
}
|
2508 |
-
$html = '';
|
2509 |
-
$html = apply_filters('wpvivid_add_backup_list', $html);
|
2510 |
-
$ret['html'] = $html;
|
2511 |
-
echo json_encode($ret);
|
2512 |
}
|
2513 |
-
|
|
|
|
|
|
|
|
|
|
|
2514 |
die();
|
2515 |
}
|
2516 |
|
@@ -2600,15 +2563,20 @@ class WPvivid {
|
|
2600 |
public function delete_task()
|
2601 |
{
|
2602 |
$this->ajax_check_security('manage_options');
|
|
|
|
|
|
|
|
|
2603 |
|
2604 |
-
|
2605 |
-
|
2606 |
-
|
2607 |
-
|
2608 |
-
|
2609 |
-
|
|
|
|
|
2610 |
}
|
2611 |
-
|
2612 |
die();
|
2613 |
}
|
2614 |
/**
|
@@ -2618,41 +2586,46 @@ class WPvivid {
|
|
2618 |
*/
|
2619 |
public function add_remote()
|
2620 |
{
|
2621 |
-
|
2622 |
-
|
2623 |
-
|
2624 |
-
|
2625 |
-
|
2626 |
-
|
2627 |
-
|
2628 |
-
|
2629 |
-
|
2630 |
-
|
2631 |
-
}
|
2632 |
|
2633 |
-
|
2634 |
-
|
2635 |
-
|
2636 |
-
|
2637 |
-
|
2638 |
|
2639 |
-
|
2640 |
-
|
2641 |
-
|
2642 |
-
|
2643 |
-
|
2644 |
-
|
2645 |
-
|
2646 |
-
|
2647 |
-
|
2648 |
-
|
2649 |
-
|
2650 |
-
|
2651 |
-
|
2652 |
-
|
2653 |
-
|
2654 |
-
|
2655 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
2656 |
}
|
2657 |
echo json_encode($ret);
|
2658 |
die();
|
@@ -2664,40 +2637,43 @@ class WPvivid {
|
|
2664 |
*/
|
2665 |
public function delete_remote()
|
2666 |
{
|
2667 |
-
|
2668 |
-
|
2669 |
-
|
2670 |
-
|
2671 |
-
|
2672 |
-
|
2673 |
-
|
2674 |
-
|
2675 |
-
|
2676 |
-
|
2677 |
-
|
2678 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2679 |
}
|
2680 |
-
$ret['result']='success';
|
2681 |
-
$html = '';
|
2682 |
-
$html = apply_filters('wpvivid_add_remote_storage_list', $html);
|
2683 |
-
$ret['html'] = $html;
|
2684 |
-
$pic = '';
|
2685 |
-
$pic = apply_filters('wpvivid_schedule_add_remote_pic', $pic);
|
2686 |
-
$ret['pic'] = $pic;
|
2687 |
-
$dir = '';
|
2688 |
-
$dir = apply_filters('wpvivid_get_remote_directory', $dir);
|
2689 |
-
$ret['dir'] = $dir;
|
2690 |
-
$schedule_local_remote='';
|
2691 |
-
$schedule_local_remote= apply_filters('wpvivid_schedule_local_remote',$schedule_local_remote);
|
2692 |
-
$ret['local_remote'] = $schedule_local_remote;
|
2693 |
-
$remote_storage = '';
|
2694 |
-
$remote_storage = apply_filters('wpvivid_remote_storage',$remote_storage);
|
2695 |
-
$ret['remote_storage'] = $remote_storage;
|
2696 |
}
|
2697 |
-
|
2698 |
-
|
2699 |
-
$
|
2700 |
-
|
|
|
2701 |
}
|
2702 |
echo json_encode($ret);
|
2703 |
die();
|
@@ -2710,27 +2686,32 @@ class WPvivid {
|
|
2710 |
*/
|
2711 |
public function retrieve_remote()
|
2712 |
{
|
2713 |
-
|
2714 |
-
|
2715 |
-
|
2716 |
-
|
2717 |
-
|
2718 |
-
|
2719 |
-
|
2720 |
-
|
2721 |
-
|
2722 |
-
|
2723 |
-
|
2724 |
-
|
2725 |
-
|
2726 |
-
|
2727 |
-
|
|
|
|
|
2728 |
}
|
2729 |
-
$ret = $value;
|
2730 |
-
$ret['result']=WPVIVID_SUCCESS;
|
2731 |
-
break;
|
2732 |
}
|
2733 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2734 |
echo json_encode($ret);
|
2735 |
die();
|
2736 |
}
|
@@ -2742,26 +2723,60 @@ class WPvivid {
|
|
2742 |
public function edit_remote()
|
2743 |
{
|
2744 |
$this->ajax_check_security();
|
2745 |
-
|
2746 |
-
|
2747 |
-
|
2748 |
-
|
2749 |
-
|
2750 |
-
|
2751 |
-
|
2752 |
-
|
2753 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2754 |
die();
|
2755 |
}
|
2756 |
-
$
|
2757 |
-
|
2758 |
-
|
2759 |
-
|
2760 |
-
|
2761 |
-
|
2762 |
-
|
2763 |
-
|
2764 |
-
|
|
|
|
|
|
|
|
|
2765 |
$html = '';
|
2766 |
$html = apply_filters('wpvivid_add_remote_storage_list', $html);
|
2767 |
$ret['html'] = $html;
|
@@ -2771,43 +2786,19 @@ class WPvivid {
|
|
2771 |
$dir = '';
|
2772 |
$dir = apply_filters('wpvivid_get_remote_directory', $dir);
|
2773 |
$ret['dir'] = $dir;
|
2774 |
-
$schedule_local_remote='';
|
2775 |
-
$schedule_local_remote= apply_filters('wpvivid_schedule_local_remote'
|
2776 |
$ret['local_remote'] = $schedule_local_remote;
|
2777 |
$remote_storage = '';
|
2778 |
-
$remote_storage = apply_filters('wpvivid_remote_storage'
|
2779 |
$ret['remote_storage'] = $remote_storage;
|
2780 |
}
|
2781 |
-
|
2782 |
-
|
2783 |
-
|
2784 |
-
|
2785 |
-
|
2786 |
-
|
2787 |
-
*
|
2788 |
-
* @since 0.9.1
|
2789 |
-
*/
|
2790 |
-
public function list_remote()
|
2791 |
-
{
|
2792 |
-
$this->ajax_check_security('manage_options');
|
2793 |
-
|
2794 |
-
$ret['result']='success';
|
2795 |
-
$html = '';
|
2796 |
-
$html = apply_filters('wpvivid_add_remote_storage_list', $html);
|
2797 |
-
$ret['html'] = $html;
|
2798 |
-
$pic = '';
|
2799 |
-
$pic = apply_filters('wpvivid_schedule_add_remote_pic', $pic);
|
2800 |
-
$ret['pic'] = $pic;
|
2801 |
-
$dir = '';
|
2802 |
-
$dir = apply_filters('wpvivid_get_remote_directory', $dir);
|
2803 |
-
$ret['dir'] = $dir;
|
2804 |
-
$schedule_local_remote='';
|
2805 |
-
$schedule_local_remote= apply_filters('wpvivid_schedule_local_remote',$schedule_local_remote);
|
2806 |
-
$ret['local_remote'] = $schedule_local_remote;
|
2807 |
-
$remote_storage = '';
|
2808 |
-
$remote_storage = apply_filters('wpvivid_remote_storage',$remote_storage);
|
2809 |
-
$ret['remote_storage'] = $remote_storage;
|
2810 |
-
|
2811 |
echo json_encode($ret);
|
2812 |
die();
|
2813 |
}
|
@@ -2819,22 +2810,27 @@ class WPvivid {
|
|
2819 |
public function test_remote_connection()
|
2820 |
{
|
2821 |
$this->ajax_check_security();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2822 |
|
2823 |
-
|
2824 |
-
|
2825 |
-
|
2826 |
}
|
2827 |
-
$
|
2828 |
-
|
2829 |
-
|
2830 |
-
|
2831 |
-
{
|
2832 |
die();
|
2833 |
}
|
2834 |
-
|
2835 |
-
$remote_options['type']=$_POST['type'];
|
2836 |
-
$remote=$this->remote_collection->get_remote($remote_options);
|
2837 |
-
$ret=$remote->test_connect();
|
2838 |
echo json_encode($ret);
|
2839 |
die();
|
2840 |
}
|
@@ -2846,13 +2842,20 @@ class WPvivid {
|
|
2846 |
public function get_schedule()
|
2847 |
{
|
2848 |
$this->ajax_check_security('manage_options');
|
2849 |
-
|
2850 |
-
|
2851 |
-
|
2852 |
-
|
2853 |
-
|
2854 |
-
|
2855 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2856 |
die();
|
2857 |
}
|
2858 |
|
@@ -2892,89 +2895,98 @@ class WPvivid {
|
|
2892 |
public function init_restore_page()
|
2893 |
{
|
2894 |
$this->ajax_check_security();
|
|
|
|
|
|
|
|
|
2895 |
|
2896 |
-
|
2897 |
-
|
2898 |
-
die();
|
2899 |
-
}
|
2900 |
|
2901 |
-
|
2902 |
-
$ret_scan_last_restore=$this->scan_last_restore();
|
2903 |
-
|
2904 |
-
$backup_id =sanitize_key($_POST['backup_id']);
|
2905 |
-
//$json = $_POST['restore_options'];
|
2906 |
-
//$json = stripslashes($json);
|
2907 |
-
//$restore_options = json_decode($json, 1);
|
2908 |
-
//if(is_null($restore_options))
|
2909 |
-
//{
|
2910 |
-
// die();
|
2911 |
-
//}
|
2912 |
-
$backup = WPvivid_Backuplist::get_backuplist_by_key($backup_id);
|
2913 |
|
2914 |
-
|
2915 |
|
2916 |
-
|
2917 |
|
2918 |
-
|
2919 |
-
{
|
2920 |
-
$ret['is_migrate']=1;
|
2921 |
-
}
|
2922 |
-
else
|
2923 |
-
{
|
2924 |
-
$ret['is_migrate']=0;
|
2925 |
-
}
|
2926 |
|
2927 |
-
|
2928 |
-
|
|
|
|
|
|
|
2929 |
|
2930 |
-
|
|
|
2931 |
|
2932 |
-
|
2933 |
-
$ret['max_allow_packet_warning']=$restore_db_data ->check_max_allow_packet_ex();
|
2934 |
|
2935 |
-
|
2936 |
-
|
2937 |
-
if($unit == 'K'){
|
2938 |
-
$memory_limit_tmp = intval($memory_limit) * 1024;
|
2939 |
-
}
|
2940 |
-
else if($unit == 'M'){
|
2941 |
-
$memory_limit_tmp = intval($memory_limit) * 1024 * 1024;
|
2942 |
-
}
|
2943 |
-
else if($unit == 'G'){
|
2944 |
-
$memory_limit_tmp = intval($memory_limit) * 1024 * 1024 * 1024;
|
2945 |
-
}
|
2946 |
-
if($memory_limit_tmp<256 * 1024 * 1024){
|
2947 |
-
$ret['memory_limit_warning']='memory_limit = '.$memory_limit.' is too small. The recommended value is 256M or higher. Too small value could result in a failure of website restore.';
|
2948 |
-
}
|
2949 |
-
else{
|
2950 |
-
$ret['memory_limit_warning']=false;
|
2951 |
-
}
|
2952 |
|
2953 |
-
|
2954 |
-
$
|
2955 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2956 |
|
2957 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2958 |
die();
|
2959 |
}
|
2960 |
|
2961 |
public function delete_last_restore_data()
|
2962 |
{
|
2963 |
$this->ajax_check_security();
|
2964 |
-
|
2965 |
-
|
2966 |
-
|
2967 |
-
|
2968 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2969 |
die();
|
2970 |
}
|
2971 |
|
2972 |
public function delete_old_files()
|
2973 |
{
|
2974 |
-
|
2975 |
-
|
2976 |
-
|
2977 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2978 |
die();
|
2979 |
}
|
2980 |
/**
|
@@ -2985,30 +2997,33 @@ class WPvivid {
|
|
2985 |
public function prepare_restore()
|
2986 |
{
|
2987 |
$this->ajax_check_security();
|
|
|
|
|
|
|
|
|
2988 |
|
2989 |
-
|
2990 |
-
{
|
2991 |
-
die();
|
2992 |
-
}
|
2993 |
|
2994 |
-
|
2995 |
|
2996 |
-
|
2997 |
|
2998 |
-
|
2999 |
|
3000 |
-
|
|
|
|
|
|
|
|
|
3001 |
|
3002 |
-
|
3003 |
-
|
3004 |
-
|
3005 |
-
|
3006 |
-
|
3007 |
-
|
3008 |
-
|
3009 |
}
|
3010 |
-
|
3011 |
-
echo json_encode($ret);
|
3012 |
die();
|
3013 |
}
|
3014 |
/**
|
@@ -3019,70 +3034,78 @@ class WPvivid {
|
|
3019 |
public function download_restore_file()
|
3020 |
{
|
3021 |
$this->ajax_check_security();
|
|
|
|
|
|
|
|
|
|
|
3022 |
|
3023 |
-
|
3024 |
-
||!isset($_POST['file_name'])||empty($_POST['file_name'])||!is_string($_POST['file_name']))
|
3025 |
-
{
|
3026 |
-
die();
|
3027 |
-
}
|
3028 |
|
3029 |
-
|
|
|
|
|
3030 |
|
3031 |
-
|
3032 |
-
|
3033 |
-
|
|
|
|
|
|
|
|
|
|
|
3034 |
|
3035 |
-
|
3036 |
-
$file['size']=$_POST['size'];
|
3037 |
-
$file['md5']=$_POST['md5'];
|
3038 |
-
$backup=WPvivid_Backuplist::get_backuplist_by_key($backup_id);
|
3039 |
-
if(!$backup)
|
3040 |
-
{
|
3041 |
-
echo json_encode(array('result' => WPVIVID_FAILED ,'error'=>'backup not found'));
|
3042 |
-
die();
|
3043 |
-
}
|
3044 |
|
3045 |
-
|
|
|
3046 |
|
3047 |
-
|
3048 |
-
|
|
|
|
|
3049 |
|
3050 |
-
|
3051 |
-
|
3052 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
3053 |
die();
|
3054 |
}
|
3055 |
-
|
3056 |
-
$downloader=new WPvivid_downloader();
|
3057 |
-
$ret=$downloader->download($file,$local_path,$remote_option);
|
3058 |
-
|
3059 |
-
echo json_encode($ret);
|
3060 |
die();
|
3061 |
}
|
3062 |
|
3063 |
public function download_restore_progress()
|
3064 |
{
|
3065 |
-
|
3066 |
-
|
3067 |
-
|
3068 |
-
|
3069 |
|
3070 |
-
|
3071 |
|
3072 |
-
|
3073 |
-
|
3074 |
-
|
3075 |
-
|
3076 |
-
|
3077 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
3078 |
}
|
3079 |
-
|
3080 |
-
|
3081 |
-
$
|
3082 |
-
|
3083 |
-
|
3084 |
-
$ret['error']=$task['error'];
|
3085 |
-
echo json_encode($ret);
|
3086 |
}
|
3087 |
die();
|
3088 |
}
|
@@ -3189,6 +3212,14 @@ class WPvivid {
|
|
3189 |
{
|
3190 |
$this->_enable_maintenance_mode();
|
3191 |
$restore=new WPvivid_Restore();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3192 |
$ret=$restore->restore();
|
3193 |
$this->_disable_maintenance_mode();
|
3194 |
}
|
@@ -3363,24 +3394,29 @@ class WPvivid {
|
|
3363 |
*/
|
3364 |
public function get_restore_progress()
|
3365 |
{
|
3366 |
-
|
|
|
3367 |
|
3368 |
-
|
3369 |
-
|
3370 |
-
|
3371 |
-
|
3372 |
-
|
3373 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3374 |
}
|
3375 |
-
$ret['log']=$this->restore_data->get_log_content();
|
3376 |
-
echo json_encode($ret);
|
3377 |
-
die();
|
3378 |
}
|
3379 |
-
|
3380 |
-
|
3381 |
-
$
|
3382 |
-
|
3383 |
-
echo json_encode($ret);
|
3384 |
die();
|
3385 |
}
|
3386 |
}
|
@@ -3391,21 +3427,26 @@ class WPvivid {
|
|
3391 |
*/
|
3392 |
public function get_rollback_progress()
|
3393 |
{
|
3394 |
-
|
|
|
3395 |
|
3396 |
-
|
3397 |
-
|
3398 |
-
|
3399 |
-
|
3400 |
-
|
3401 |
-
|
3402 |
-
|
|
|
|
|
|
|
|
|
|
|
3403 |
}
|
3404 |
-
|
3405 |
-
|
3406 |
-
$
|
3407 |
-
|
3408 |
-
echo json_encode($ret);
|
3409 |
die();
|
3410 |
}
|
3411 |
}
|
@@ -3489,12 +3530,18 @@ class WPvivid {
|
|
3489 |
public function get_last_backup()
|
3490 |
{
|
3491 |
$this->ajax_check_security('manage_options');
|
3492 |
-
|
3493 |
-
|
3494 |
-
|
3495 |
-
|
3496 |
-
|
3497 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
3498 |
die();
|
3499 |
}
|
3500 |
|
@@ -3623,9 +3670,42 @@ class WPvivid {
|
|
3623 |
if(!empty($backup_error_array)){
|
3624 |
$error_notice_html = array();
|
3625 |
foreach ($backup_error_array as $key => $value){
|
3626 |
-
$notice_msg = 'Backup error: '.$value['error_msg'].', task id: '.$value['task_id'];
|
3627 |
$error_notice_html['bu_error']['task_id']=$value['task_id'];
|
3628 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3629 |
}
|
3630 |
WPvivid_Setting::delete_option('wpvivid_backup_error_array');
|
3631 |
$html = '';
|
@@ -3682,37 +3762,38 @@ class WPvivid {
|
|
3682 |
public function get_dir()
|
3683 |
{
|
3684 |
$this->ajax_check_security('manage_options');
|
|
|
|
|
3685 |
|
3686 |
-
|
|
|
|
|
3687 |
|
3688 |
-
|
3689 |
-
|
3690 |
-
|
3691 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3692 |
|
3693 |
-
if(!is_dir(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir['path']))
|
3694 |
-
{
|
3695 |
-
@mkdir(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir['path'],0777,true);
|
3696 |
-
@fopen(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir['path'].'/index.html', 'x');
|
3697 |
-
$tempfile=@fopen(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir['path'].'/.htaccess', 'x');
|
3698 |
-
if($tempfile)
|
3699 |
-
{
|
3700 |
-
$text="deny from all";
|
3701 |
-
fwrite($tempfile,$text );
|
3702 |
-
fclose($tempfile);
|
3703 |
-
}
|
3704 |
-
else
|
3705 |
-
{
|
3706 |
-
$ret['result']='failed';
|
3707 |
-
$ret['error']=__('Getting backup directory failed. Please try again later.', 'wpvivid');
|
3708 |
}
|
3709 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3710 |
}
|
3711 |
-
|
3712 |
-
$ret['result']='success';
|
3713 |
-
$ret['path']=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir['path'];
|
3714 |
-
echo json_encode($ret);
|
3715 |
-
|
3716 |
die();
|
3717 |
}
|
3718 |
/**
|
@@ -3723,53 +3804,47 @@ class WPvivid {
|
|
3723 |
public function set_security_lock()
|
3724 |
{
|
3725 |
$this->ajax_check_security('manage_options');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3726 |
|
3727 |
-
|
3728 |
-
|
3729 |
-
|
3730 |
-
|
3731 |
-
|
3732 |
-
|
3733 |
-
|
3734 |
-
|
3735 |
-
|
3736 |
-
|
3737 |
-
|
3738 |
-
|
3739 |
-
|
3740 |
-
|
3741 |
-
|
3742 |
-
if(array_key_exists($backup_id,$list))
|
3743 |
-
{
|
3744 |
-
if(isset($list[$backup_id]['lock']))
|
3745 |
-
{
|
3746 |
-
if($list[$backup_id]['lock'] == 1)
|
3747 |
-
{
|
3748 |
-
$backup_lock='/admin/partials/images/locked.png';
|
3749 |
-
$lock_status='lock';
|
3750 |
-
$ret['html'] = '<img src="' . esc_url(WPVIVID_PLUGIN_URL . $backup_lock) . '" name="' . esc_attr($lock_status, 'wpvivid') . '" onclick="wpvivid_set_backup_lock(\'' . __($backup_id, 'wpvivid') . '\', \'' . __($lock_status, 'wpvivid') . '\');" style="vertical-align:middle; cursor:pointer;"/>';
|
3751 |
-
}
|
3752 |
-
else
|
3753 |
-
{
|
3754 |
$backup_lock = '/admin/partials/images/unlocked.png';
|
3755 |
$lock_status = 'unlock';
|
3756 |
$ret['html'] = '<img src="' . esc_url(WPVIVID_PLUGIN_URL . $backup_lock) . '" name="' . esc_attr($lock_status, 'wpvivid') . '" onclick="wpvivid_set_backup_lock(\'' . __($backup_id, 'wpvivid') . '\', \'' . __($lock_status, 'wpvivid') . '\');" style="vertical-align:middle; cursor:pointer;"/>';
|
3757 |
}
|
3758 |
-
}
|
3759 |
-
else
|
3760 |
-
{
|
3761 |
$backup_lock = '/admin/partials/images/unlocked.png';
|
3762 |
$lock_status = 'unlock';
|
3763 |
$ret['html'] = '<img src="' . esc_url(WPVIVID_PLUGIN_URL . $backup_lock) . '" name="' . esc_attr($lock_status, 'wpvivid') . '" onclick="wpvivid_set_backup_lock(\'' . __($backup_id, 'wpvivid') . '\', \'' . __($lock_status, 'wpvivid') . '\');" style="vertical-align:middle; cursor:pointer;"/>';
|
3764 |
}
|
|
|
3765 |
}
|
3766 |
-
|
3767 |
-
|
3768 |
-
|
3769 |
-
|
3770 |
-
|
3771 |
-
|
3772 |
-
echo json_encode($ret);
|
3773 |
}
|
3774 |
die();
|
3775 |
}
|
@@ -3781,10 +3856,17 @@ class WPvivid {
|
|
3781 |
public function junk_files_info()
|
3782 |
{
|
3783 |
$this->ajax_check_security();
|
3784 |
-
|
3785 |
-
|
3786 |
-
|
3787 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3788 |
die();
|
3789 |
}
|
3790 |
|
@@ -3830,17 +3912,24 @@ class WPvivid {
|
|
3830 |
public function get_out_of_date_info()
|
3831 |
{
|
3832 |
$this->ajax_check_security();
|
|
|
|
|
|
|
|
|
|
|
3833 |
|
3834 |
-
|
3835 |
-
|
3836 |
-
|
3837 |
-
$ret['remote_options']=WPvivid_Setting::get_remote_options();
|
3838 |
-
|
3839 |
-
$info=WPvivid_Backuplist::get_out_of_date_backuplist_info(WPvivid_Setting::get_max_backup_count());
|
3840 |
-
$ret['info']=$info;
|
3841 |
-
$ret['info']['size']=$this->formatBytes($info['size']);
|
3842 |
|
3843 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3844 |
die();
|
3845 |
}
|
3846 |
|
@@ -3861,17 +3950,23 @@ class WPvivid {
|
|
3861 |
public function clean_out_of_date_backup()
|
3862 |
{
|
3863 |
$this->ajax_check_security();
|
3864 |
-
|
3865 |
-
|
3866 |
-
|
3867 |
-
|
3868 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3869 |
}
|
3870 |
-
$ret['result']='success';
|
3871 |
-
$html = '';
|
3872 |
-
$html = apply_filters('wpvivid_add_backup_list', $html);
|
3873 |
-
$ret['html'] = $html;
|
3874 |
-
echo json_encode($ret);
|
3875 |
die();
|
3876 |
}
|
3877 |
|
@@ -4102,89 +4197,107 @@ class WPvivid {
|
|
4102 |
public function get_setting()
|
4103 |
{
|
4104 |
$this->ajax_check_security('manage_options');
|
4105 |
-
|
4106 |
-
|
4107 |
-
|
4108 |
-
|
4109 |
-
|
4110 |
-
|
4111 |
-
|
4112 |
-
|
4113 |
-
|
4114 |
-
|
|
|
|
|
4115 |
echo json_encode($ret);
|
4116 |
}
|
4117 |
}
|
4118 |
-
else
|
4119 |
-
{
|
4120 |
-
$options_name=array();
|
4121 |
-
$ret=WPvivid_Setting::get_setting($all,$options_name);
|
4122 |
-
echo json_encode($ret);
|
4123 |
-
}
|
4124 |
}
|
4125 |
-
|
|
|
|
|
|
|
|
|
|
|
4126 |
die();
|
4127 |
}
|
4128 |
|
4129 |
public function update_setting()
|
4130 |
{
|
4131 |
$this->ajax_check_security('manage_options');
|
4132 |
-
|
4133 |
-
|
4134 |
-
|
4135 |
-
|
4136 |
-
|
4137 |
-
|
4138 |
-
|
4139 |
-
|
4140 |
-
|
|
|
4141 |
}
|
4142 |
-
$ret=WPvivid_Setting::update_setting($options);
|
4143 |
-
echo json_encode($ret);
|
4144 |
}
|
4145 |
-
|
|
|
|
|
|
|
|
|
|
|
4146 |
die();
|
4147 |
}
|
4148 |
|
4149 |
function set_default_remote_storage()
|
4150 |
{
|
4151 |
$this->ajax_check_security('manage_options');
|
4152 |
-
|
4153 |
-
|
4154 |
-
|
4155 |
-
|
4156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4157 |
echo json_encode($ret);
|
|
|
|
|
|
|
|
|
|
|
4158 |
die();
|
4159 |
}
|
4160 |
-
$remote_storage = $_POST['remote_storage'];
|
4161 |
-
WPvivid_Setting::update_user_history('remote_selected',$remote_storage);
|
4162 |
-
$ret['result'] = 'success';
|
4163 |
-
$html = '';
|
4164 |
-
$html = apply_filters('wpvivid_add_remote_storage_list', $html);
|
4165 |
-
$ret['html'] = $html;
|
4166 |
-
$pic = '';
|
4167 |
-
$pic = apply_filters('wpvivid_schedule_add_remote_pic', $pic);
|
4168 |
-
$ret['pic'] = $pic;
|
4169 |
-
$dir = '';
|
4170 |
-
$dir = apply_filters('wpvivid_get_remote_directory', $dir);
|
4171 |
-
$ret['dir'] = $dir;
|
4172 |
-
$schedule_local_remote='';
|
4173 |
-
$schedule_local_remote= apply_filters('wpvivid_schedule_local_remote',$schedule_local_remote);
|
4174 |
-
$ret['local_remote'] = $schedule_local_remote;
|
4175 |
-
$remote_storage = '';
|
4176 |
-
$remote_storage = apply_filters('wpvivid_remote_storage',$remote_storage);
|
4177 |
-
$ret['remote_storage'] = $remote_storage;
|
4178 |
-
echo json_encode($ret);
|
4179 |
die();
|
4180 |
}
|
4181 |
|
4182 |
function get_default_remote_storage(){
|
4183 |
$this->ajax_check_security('manage_options');
|
4184 |
-
|
4185 |
-
|
4186 |
-
|
4187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4188 |
die();
|
4189 |
}
|
4190 |
|
@@ -4197,36 +4310,38 @@ class WPvivid {
|
|
4197 |
public function get_general_setting()
|
4198 |
{
|
4199 |
$this->ajax_check_security('manage_options');
|
4200 |
-
|
4201 |
-
|
4202 |
-
|
4203 |
-
|
4204 |
-
|
4205 |
-
|
4206 |
-
|
4207 |
-
|
4208 |
-
|
4209 |
-
|
4210 |
-
|
4211 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4212 |
$schedule['next_start'] = date("l, F d, Y H:i", $schedule['next_start']);
|
4213 |
-
$ret['result']='success';
|
4214 |
-
$ret['data']['schedule']
|
4215 |
-
$ret['user_history']=WPvivid_Setting::get_user_history('remote_selected');
|
4216 |
echo json_encode($ret);
|
4217 |
}
|
4218 |
}
|
4219 |
-
|
4220 |
-
|
4221 |
-
|
4222 |
-
|
4223 |
-
|
4224 |
-
|
4225 |
-
$ret['result']='success';
|
4226 |
-
$ret['data']['schedule']=$schedule;
|
4227 |
-
$ret['user_history']=WPvivid_Setting::get_user_history('remote_selected');
|
4228 |
-
echo json_encode($ret);
|
4229 |
-
}
|
4230 |
}
|
4231 |
die();
|
4232 |
}
|
@@ -4250,6 +4365,7 @@ class WPvivid {
|
|
4250 |
$setting_data['wpvivid_compress_setting']['use_temp_file'] = $setting['use_temp_file'];
|
4251 |
$setting_data['wpvivid_compress_setting']['use_temp_size'] = $setting['use_temp_size'];
|
4252 |
$setting_data['wpvivid_compress_setting']['exclude_file_size'] = $setting['exclude_file_size'];
|
|
|
4253 |
|
4254 |
$setting_data['wpvivid_local_setting']['path'] = $setting['path'];
|
4255 |
$setting_data['wpvivid_local_setting']['save_local'] = $options['options']['wpvivid_local_setting']['save_local'];
|
@@ -4263,6 +4379,9 @@ class WPvivid {
|
|
4263 |
$setting_data['wpvivid_common_setting']['estimate_backup'] = $setting['estimate_backup'];
|
4264 |
$setting_data['wpvivid_common_setting']['max_resume_count'] = $setting['max_resume_count'];
|
4265 |
$setting_data['wpvivid_common_setting']['memory_limit'] = $setting['memory_limit'].'M';
|
|
|
|
|
|
|
4266 |
return $setting_data;
|
4267 |
}
|
4268 |
|
@@ -4360,7 +4479,7 @@ class WPvivid {
|
|
4360 |
|
4361 |
if(empty($data['max_file_size']) && $data['max_file_size'] != '0')
|
4362 |
{
|
4363 |
-
$ret['error']=__('The maximum zip file size is
|
4364 |
return $ret;
|
4365 |
}
|
4366 |
|
@@ -4446,50 +4565,48 @@ class WPvivid {
|
|
4446 |
public function export_setting()
|
4447 |
{
|
4448 |
$this->ajax_check_security('manage_options');
|
|
|
|
|
|
|
|
|
|
|
4449 |
|
4450 |
-
|
4451 |
-
|
4452 |
-
|
4453 |
-
|
4454 |
-
|
4455 |
|
4456 |
-
|
4457 |
-
|
4458 |
-
|
4459 |
-
|
4460 |
-
|
4461 |
-
{
|
4462 |
-
$setting=false;
|
4463 |
-
}
|
4464 |
|
4465 |
-
|
4466 |
-
|
4467 |
-
|
4468 |
-
|
4469 |
-
|
4470 |
-
{
|
4471 |
-
$history=false;
|
4472 |
-
}
|
4473 |
|
4474 |
-
|
4475 |
-
|
4476 |
-
|
4477 |
-
|
4478 |
-
|
4479 |
-
|
|
|
|
|
|
|
4480 |
|
4481 |
-
|
4482 |
-
if (!headers_sent())
|
4483 |
-
{
|
4484 |
-
header('Content-Disposition: attachment; filename=wpvivid_setting.json');
|
4485 |
-
//header('Content-type: application/json');
|
4486 |
-
header('Content-Type: application/force-download');
|
4487 |
-
header('Content-Description: File Transfer');
|
4488 |
-
header('Cache-Control: must-revalidate');
|
4489 |
-
header('Content-Transfer-Encoding: binary' );
|
4490 |
}
|
4491 |
-
|
4492 |
-
|
|
|
|
|
|
|
|
|
4493 |
}
|
4494 |
exit;
|
4495 |
}
|
@@ -4497,126 +4614,130 @@ class WPvivid {
|
|
4497 |
public function import_setting()
|
4498 |
{
|
4499 |
$this->ajax_check_security('manage_options');
|
4500 |
-
|
4501 |
-
|
4502 |
-
|
4503 |
-
|
4504 |
-
|
4505 |
-
|
4506 |
-
|
4507 |
-
|
4508 |
-
|
4509 |
-
|
4510 |
-
|
4511 |
-
|
4512 |
-
|
4513 |
-
|
4514 |
-
|
4515 |
-
|
4516 |
-
|
4517 |
-
|
4518 |
-
$ret['result']='failed';
|
4519 |
-
$ret['error']=__('The selected file is not the setting file for WPvivid. Please upload the right file.', 'wpvivid');
|
4520 |
-
echo json_encode($ret);
|
4521 |
}
|
4522 |
}
|
4523 |
-
|
|
|
|
|
|
|
|
|
|
|
4524 |
die();
|
4525 |
}
|
4526 |
|
4527 |
public function test_send_mail()
|
4528 |
{
|
4529 |
$this->ajax_check_security();
|
4530 |
-
|
4531 |
-
|
4532 |
-
|
4533 |
-
|
4534 |
-
|
4535 |
-
|
4536 |
-
|
4537 |
-
|
4538 |
-
|
4539 |
-
|
4540 |
-
|
4541 |
-
|
4542 |
-
|
4543 |
-
|
4544 |
-
|
4545 |
-
|
4546 |
-
|
4547 |
-
$ret
|
4548 |
-
}
|
4549 |
-
else
|
4550 |
-
{
|
4551 |
-
$ret['result']='success';
|
4552 |
}
|
4553 |
-
echo json_encode($ret);
|
4554 |
}
|
4555 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
4556 |
die();
|
4557 |
}
|
4558 |
|
4559 |
public function create_debug_package()
|
4560 |
{
|
4561 |
$this->ajax_check_security();
|
|
|
|
|
4562 |
|
4563 |
-
|
|
|
4564 |
|
4565 |
-
|
4566 |
-
|
4567 |
|
4568 |
-
|
4569 |
-
|
|
|
|
|
4570 |
|
4571 |
-
|
4572 |
-
|
4573 |
-
|
4574 |
-
|
4575 |
-
|
|
|
4576 |
|
4577 |
-
|
4578 |
-
|
4579 |
-
if(
|
4580 |
-
|
4581 |
-
|
|
|
|
|
|
|
|
|
|
|
4582 |
exit;
|
4583 |
}
|
4584 |
-
|
4585 |
-
|
4586 |
-
$server_info=json_encode($this->get_website_info());
|
4587 |
-
$server_file_path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_path.DIRECTORY_SEPARATOR.'wpvivid_server_info.json';
|
4588 |
-
if(file_exists($server_file_path))
|
4589 |
-
{
|
4590 |
-
@unlink( $server_file_path);
|
4591 |
-
}
|
4592 |
-
$server_file = fopen($server_file_path, 'x');
|
4593 |
-
fclose($server_file);
|
4594 |
-
file_put_contents($server_file_path,$server_info);
|
4595 |
-
if(!$archive->add($server_file_path,PCLZIP_OPT_REMOVE_ALL_PATH))
|
4596 |
-
{
|
4597 |
-
echo __($archive->errorInfo(true).' <a href="'.admin_url().'admin.php?page=WPvivid">retry</a>.');
|
4598 |
-
exit;
|
4599 |
-
}
|
4600 |
-
@unlink( $server_file_path);
|
4601 |
|
4602 |
-
|
4603 |
-
|
4604 |
|
4605 |
-
|
4606 |
-
|
4607 |
-
|
4608 |
-
|
4609 |
-
|
4610 |
-
|
4611 |
-
|
4612 |
-
|
4613 |
-
|
4614 |
-
}
|
4615 |
|
4616 |
|
4617 |
-
|
4618 |
-
|
4619 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4620 |
exit;
|
4621 |
}
|
4622 |
|
@@ -4628,12 +4749,20 @@ class WPvivid {
|
|
4628 |
public function get_log_list()
|
4629 |
{
|
4630 |
$this->ajax_check_security();
|
4631 |
-
|
4632 |
-
|
4633 |
-
|
4634 |
-
|
4635 |
-
|
4636 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4637 |
die();
|
4638 |
}
|
4639 |
|
@@ -4765,43 +4894,45 @@ class WPvivid {
|
|
4765 |
public function view_log()
|
4766 |
{
|
4767 |
$this->ajax_check_security();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4768 |
|
4769 |
-
|
4770 |
-
{
|
4771 |
-
$path=sanitize_text_field($_POST['path']);
|
4772 |
-
if(!file_exists($path))
|
4773 |
-
{
|
4774 |
-
$json['result']='failed';
|
4775 |
-
$json['error']=__('The log not found.', 'wpvivid');
|
4776 |
-
echo json_encode($json);
|
4777 |
-
die();
|
4778 |
-
}
|
4779 |
|
4780 |
-
|
|
|
|
|
|
|
|
|
|
|
4781 |
|
4782 |
-
|
4783 |
-
|
4784 |
-
|
4785 |
-
|
4786 |
-
|
4787 |
-
die();
|
4788 |
-
}
|
4789 |
|
4790 |
-
|
4791 |
-
|
4792 |
-
|
4793 |
-
|
|
|
|
|
|
|
4794 |
}
|
4795 |
-
fclose($file);
|
4796 |
-
|
4797 |
-
$json['result']='success';
|
4798 |
-
$json['data']=$buffer;
|
4799 |
-
echo json_encode($json);
|
4800 |
}
|
4801 |
-
|
4802 |
-
$
|
4803 |
-
$
|
4804 |
-
echo json_encode(
|
|
|
4805 |
}
|
4806 |
die();
|
4807 |
}
|
@@ -4924,33 +5055,16 @@ class WPvivid {
|
|
4924 |
|
4925 |
if( $ret['data']['pdo_mysql']=='support')
|
4926 |
{
|
4927 |
-
$
|
4928 |
-
$
|
4929 |
-
|
4930 |
-
if(!empty($db_port))
|
4931 |
-
$db_host = $db_host.':'.$db_port;
|
4932 |
-
|
4933 |
-
try{
|
4934 |
-
$conn=new PDO('mysql:host=' . $db_host . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD );
|
4935 |
-
$sth = $conn->query('SELECT @@SESSION.sql_mode');
|
4936 |
-
$rows = $sth->fetchAll();
|
4937 |
-
foreach ($rows as $row)
|
4938 |
-
{
|
4939 |
-
$ret['mysql_mode']=$row["@@SESSION.sql_mode"];
|
4940 |
-
}
|
4941 |
-
}catch (Exception $e)
|
4942 |
{
|
4943 |
-
|
4944 |
-
|
4945 |
-
|
4946 |
-
|
4947 |
-
|
4948 |
-
|
4949 |
-
{
|
4950 |
-
$ret['mysql_mode']=$row["@@SESSION.sql_mode"];
|
4951 |
-
}
|
4952 |
-
}
|
4953 |
-
$ret['data']['mysql_mode']= 'The error establishing a database connection. Please check wp-config.php file and make sure the information is correct.';
|
4954 |
}
|
4955 |
}
|
4956 |
else {
|
@@ -5346,57 +5460,74 @@ class WPvivid {
|
|
5346 |
public function need_review()
|
5347 |
{
|
5348 |
$this->ajax_check_security();
|
5349 |
-
|
5350 |
-
|
5351 |
-
|
5352 |
-
|
5353 |
-
|
5354 |
-
|
5355 |
-
|
5356 |
-
|
5357 |
-
|
5358 |
-
$
|
5359 |
-
|
5360 |
-
|
5361 |
-
|
5362 |
-
|
5363 |
-
|
5364 |
-
|
5365 |
-
|
5366 |
-
|
5367 |
-
$review_option = 'not';
|
5368 |
-
echo '';
|
5369 |
}
|
5370 |
-
|
|
|
|
|
|
|
|
|
|
|
5371 |
}
|
5372 |
die();
|
5373 |
}
|
5374 |
|
5375 |
public function wpvivid_send_debug_info(){
|
5376 |
$this->ajax_check_security();
|
5377 |
-
|
5378 |
-
|
5379 |
-
$ret['result']='failed';
|
5380 |
-
$ret['error']=__('User\'s email address is required.', 'wpvivid');
|
5381 |
-
}
|
5382 |
-
else {
|
5383 |
-
$pattern = '/^[a-z0-9]+([._-][a-z0-9]+)*@([0-9a-z]+\.[a-z]{2,14}(\.[a-z]{2})?)$/i';
|
5384 |
-
if (!preg_match($pattern, $_POST['user_mail'])) {
|
5385 |
$ret['result'] = 'failed';
|
5386 |
-
$ret['error'] = __('
|
5387 |
} else {
|
5388 |
-
$
|
5389 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
5390 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5391 |
}
|
5392 |
-
echo json_encode($ret);
|
5393 |
die();
|
5394 |
}
|
5395 |
|
5396 |
public function get_ini_memory_limit(){
|
5397 |
$this->ajax_check_security();
|
5398 |
-
|
5399 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5400 |
die();
|
5401 |
}
|
5402 |
}
|
113 |
add_action('wpvivid_handle_upload_succeed',array($this,'wpvivid_deal_upload_succeed'),9);
|
114 |
|
115 |
add_action('wpvivid_handle_backup_failed',array($this,'wpvivid_mark_task'),20);
|
116 |
+
add_action('init', array($this, 'init_pclzip_tmp_folder'));
|
117 |
//Initialisation schedule hook
|
118 |
$this->init_cron();
|
119 |
//Initialisation log object
|
129 |
add_action(WPVIVID_CLEAN_BACKUP_RECORD_EVENT,array($this,'clean_backup_record_event'));
|
130 |
//add_clean_event
|
131 |
add_action(WPVIVID_TASK_MONITOR_EVENT,array( $this,'task_monitor'));
|
132 |
+
add_filter('cron_schedules',array( $schedule,'wpvivid_cron_schedules'),99);
|
133 |
add_filter('wpvivid_schedule_time', array($schedule, 'output'));
|
134 |
}
|
135 |
|
159 |
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-crypt.php';
|
160 |
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-migrate.php';
|
161 |
|
162 |
+
include_once WPVIVID_PLUGIN_DIR.'/includes/class-wpvivid-db-method.php';
|
163 |
|
164 |
$this->remote_collection=new WPvivid_Remote_collection();
|
165 |
$this->migrate=new WPvivid_Migrate();
|
166 |
$this->backup_uploader=new Wpvivid_BackupUploader();
|
167 |
}
|
168 |
|
169 |
+
public function init_pclzip_tmp_folder()
|
170 |
+
{
|
171 |
+
if (!defined('PCLZIP_TEMPORARY_DIR')) {
|
172 |
+
$backupdir=WPvivid_Setting::get_backupdir();
|
173 |
+
define( 'PCLZIP_TEMPORARY_DIR', WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backupdir.DIRECTORY_SEPARATOR );
|
174 |
+
}
|
175 |
+
}
|
176 |
+
|
177 |
private function set_locale()
|
178 |
{
|
179 |
$plugin_i18n = new WPvivid_i18n();
|
491 |
public function delete_ready_task()
|
492 |
{
|
493 |
$this->ajax_check_security();
|
494 |
+
try {
|
495 |
+
WPvivid_taskmanager::delete_ready_task();
|
496 |
+
$ret['result'] = 'success';
|
497 |
+
}
|
498 |
+
catch (Exception $error) {
|
499 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
500 |
+
error_log($message);
|
501 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
502 |
+
die();
|
503 |
+
}
|
504 |
echo json_encode($ret);
|
505 |
die();
|
506 |
}
|
512 |
public function backup_now()
|
513 |
{
|
514 |
$this->ajax_check_security();
|
515 |
+
try {
|
516 |
+
if (!isset($_POST['task_id']) || empty($_POST['task_id']) || !is_string($_POST['task_id'])) {
|
517 |
+
$ret['result'] = 'failed';
|
518 |
+
$ret['error'] = __('Error occurred while parsing the request data. Please try to run backup again.', 'wpvivid');
|
519 |
+
echo json_encode($ret);
|
520 |
+
die();
|
521 |
+
}
|
522 |
+
$task_id = sanitize_key($_POST['task_id']);
|
523 |
|
524 |
+
//Start backup site
|
525 |
+
if (WPvivid_taskmanager::is_tasks_backup_running()) {
|
526 |
+
$ret['result'] = 'failed';
|
527 |
+
$ret['error'] = __('A task is already running. Please wait until the running task is complete, and try again.', 'wpvivid');
|
528 |
+
echo json_encode($ret);
|
529 |
+
die();
|
530 |
+
}
|
|
|
531 |
|
532 |
+
$this->backup($task_id);
|
533 |
+
}
|
534 |
+
catch (Exception $error) {
|
535 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
536 |
+
error_log($message);
|
537 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
538 |
die();
|
539 |
}
|
|
|
|
|
540 |
die();
|
541 |
}
|
542 |
/**
|
547 |
public function view_backup_log()
|
548 |
{
|
549 |
$this->ajax_check_security();
|
550 |
+
try {
|
551 |
+
if (isset($_POST['id']) && !empty($_POST['id']) && is_string($_POST['id'])) {
|
552 |
+
$backup_id = sanitize_key($_POST['id']);
|
553 |
+
$backup = WPvivid_Backuplist::get_backuplist_by_key($backup_id);
|
554 |
+
if (!$backup) {
|
555 |
+
$json['result'] = 'failed';
|
556 |
+
$json['error'] = __('Retrieving the backup information failed while showing log. Please try again later.', 'wpvivid');
|
557 |
+
echo json_encode($json);
|
558 |
+
die();
|
559 |
+
}
|
560 |
|
561 |
+
if (!file_exists($backup['log'])) {
|
562 |
+
$json['result'] = 'failed';
|
563 |
+
$json['error'] = __('The log not found.', 'wpvivid');
|
564 |
+
echo json_encode($json);
|
565 |
+
die();
|
566 |
+
}
|
|
|
|
|
|
|
|
|
|
|
567 |
|
568 |
+
$file = fopen($backup['log'], 'r');
|
|
|
|
|
|
|
|
|
|
|
|
|
569 |
|
570 |
+
if (!$file) {
|
571 |
+
$json['result'] = 'failed';
|
572 |
+
$json['error'] = __('Unable to open the log file.', 'wpvivid');
|
573 |
+
echo json_encode($json);
|
574 |
+
die();
|
575 |
+
}
|
576 |
|
577 |
+
$buffer = '';
|
578 |
+
while (!feof($file)) {
|
579 |
+
$buffer .= fread($file, 1024);
|
580 |
+
}
|
581 |
+
fclose($file);
|
|
|
|
|
582 |
|
583 |
+
$json['result'] = 'success';
|
584 |
+
$json['data'] = $buffer;
|
585 |
+
echo json_encode($json);
|
586 |
+
} else {
|
587 |
+
$json['result'] = 'failed';
|
588 |
+
$json['error'] = __('Reading the log failed. Please try again.', 'wpvivid');
|
589 |
+
echo json_encode($json);
|
590 |
}
|
|
|
|
|
|
|
|
|
|
|
591 |
}
|
592 |
+
catch (Exception $error) {
|
593 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
594 |
+
error_log($message);
|
595 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
596 |
+
die();
|
597 |
}
|
598 |
die();
|
599 |
}
|
605 |
public function read_last_backup_log()
|
606 |
{
|
607 |
$this->ajax_check_security();
|
608 |
+
try {
|
609 |
+
if (!isset($_POST['log_file_name']) || empty($_POST['log_file_name']) || !is_string($_POST['log_file_name'])) {
|
610 |
+
$json['result'] = 'failed';
|
611 |
+
$json['error'] = __('Reading the log failed. Please try again.', 'wpvivid');
|
612 |
+
echo json_encode($json);
|
613 |
+
die();
|
614 |
+
}
|
615 |
+
$option = sanitize_text_field($_POST['log_file_name']);
|
616 |
+
$log_file_name = $this->wpvivid_log->GetSaveLogFolder() . $option . '_log.txt';
|
617 |
|
618 |
+
if (!file_exists($log_file_name)) {
|
619 |
+
$json['result'] = 'failed';
|
620 |
+
$json['error'] = __('The log not found.', 'wpvivid');
|
621 |
+
echo json_encode($json);
|
622 |
+
die();
|
623 |
+
}
|
|
|
624 |
|
625 |
+
$file = fopen($log_file_name, 'r');
|
626 |
|
627 |
+
if (!$file) {
|
628 |
+
$json['result'] = 'failed';
|
629 |
+
$json['error'] = __('Unable to open the log file.', 'wpvivid');
|
630 |
+
echo json_encode($json);
|
631 |
+
die();
|
632 |
+
}
|
633 |
+
|
634 |
+
$buffer = '';
|
635 |
+
while (!feof($file)) {
|
636 |
+
$buffer .= fread($file, 1024);
|
637 |
+
}
|
638 |
+
fclose($file);
|
639 |
+
|
640 |
+
$json['result'] = 'success';
|
641 |
+
$json['data'] = $buffer;
|
642 |
echo json_encode($json);
|
|
|
643 |
}
|
644 |
+
catch (Exception $error) {
|
645 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
646 |
+
error_log($message);
|
647 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
648 |
+
die();
|
649 |
}
|
|
|
|
|
|
|
|
|
|
|
650 |
die();
|
651 |
}
|
652 |
/**
|
657 |
public function view_backup_task_log()
|
658 |
{
|
659 |
$this->ajax_check_security();
|
660 |
+
try {
|
661 |
+
if (isset($_POST['id']) && !empty($_POST['id']) && is_string($_POST['id'])) {
|
662 |
+
$backup_task_id = sanitize_key($_POST['id']);
|
663 |
+
$option = WPvivid_taskmanager::get_task_options($backup_task_id, 'log_file_name');
|
664 |
+
if (!$option) {
|
665 |
+
$json['result'] = 'failed';
|
666 |
+
$json['error'] = __('Retrieving the backup information failed while showing log. Please try again later.', 'wpvivid');
|
667 |
+
echo json_encode($json);
|
668 |
+
die();
|
669 |
+
}
|
670 |
|
671 |
+
$log_file_name = $this->wpvivid_log->GetSaveLogFolder() . $option . '_log.txt';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
672 |
|
673 |
+
if (!file_exists($log_file_name)) {
|
674 |
+
$json['result'] = 'failed';
|
675 |
+
$json['error'] = __('The log not found.', 'wpvivid');
|
676 |
+
echo json_encode($json);
|
677 |
+
die();
|
678 |
+
}
|
679 |
|
680 |
+
$file = fopen($log_file_name, 'r');
|
|
|
|
|
|
|
|
|
|
|
|
|
681 |
|
682 |
+
if (!$file) {
|
683 |
+
$json['result'] = 'failed';
|
684 |
+
$json['error'] = __('Unable to open the log file.', 'wpvivid');
|
685 |
+
echo json_encode($json);
|
686 |
+
die();
|
687 |
+
}
|
688 |
|
689 |
+
$buffer = '';
|
690 |
+
while (!feof($file)) {
|
691 |
+
$buffer .= fread($file, 1024);
|
692 |
+
}
|
693 |
+
fclose($file);
|
|
|
|
|
694 |
|
695 |
+
$json['result'] = 'success';
|
696 |
+
$json['data'] = $buffer;
|
697 |
+
echo json_encode($json);
|
698 |
+
} else {
|
699 |
+
$json['result'] = 'failed';
|
700 |
+
$json['error'] = __('Reading the log failed. Please try again.', 'wpvivid');
|
701 |
+
echo json_encode($json);
|
702 |
}
|
|
|
|
|
|
|
|
|
|
|
703 |
}
|
704 |
+
catch (Exception $error) {
|
705 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
706 |
+
error_log($message);
|
707 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
708 |
+
die();
|
709 |
}
|
710 |
die();
|
711 |
}
|
717 |
public function backup_cancel()
|
718 |
{
|
719 |
$this->ajax_check_security();
|
720 |
+
try {
|
721 |
+
if (isset($_POST['task_id']) && !empty($_POST['task_id']) && is_string($_POST['task_id'])) {
|
722 |
+
$task_id = sanitize_key($_POST['task_id']);
|
723 |
+
if (WPvivid_taskmanager::get_task($task_id) !== false) {
|
724 |
+
$file_name = WPvivid_taskmanager::get_task_options($task_id, 'file_prefix');
|
725 |
+
$backup_options = WPvivid_taskmanager::get_task_options($task_id, 'backup_options');
|
726 |
+
$file = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $backup_options['dir'] . DIRECTORY_SEPARATOR . $file_name . '_cancel';
|
727 |
+
touch($file);
|
728 |
+
}
|
729 |
|
730 |
+
$timestamp = wp_next_scheduled(WPVIVID_TASK_MONITOR_EVENT, array($task_id));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
731 |
|
732 |
+
if ($timestamp === false) {
|
733 |
+
$this->add_monitor_event($task_id, 10);
|
734 |
+
}
|
735 |
+
$json['result'] = 'success';
|
736 |
+
$json['msg'] = __('The backup will be canceled after backing up the current chunk ends.', 'wpvivid');
|
737 |
+
echo json_encode($json);
|
738 |
}
|
739 |
+
}
|
740 |
+
catch (Exception $error) {
|
741 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
742 |
+
error_log($message);
|
743 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
744 |
+
die();
|
745 |
}
|
746 |
die();
|
747 |
}
|
827 |
die();
|
828 |
}
|
829 |
|
830 |
+
if (WPvivid_taskmanager::is_tasks_backup_running())
|
831 |
+
{
|
832 |
+
$ret['result'] = 'failed';
|
833 |
+
$ret['error'] = __('A task is already running. Please wait until the running task is complete, and try again.', 'wpvivid');
|
834 |
+
echo json_encode($ret);
|
835 |
+
die();
|
836 |
+
}
|
837 |
+
|
838 |
$doing=WPvivid_taskmanager::get_backup_main_task_progress($task_id);
|
839 |
if($doing=='backup')
|
840 |
{
|
1033 |
|
1034 |
if(WPvivid_taskmanager::get_task_options($task_id,'remote_options')!=false)
|
1035 |
{
|
1036 |
+
$this->upload($task_id,false);
|
1037 |
}
|
1038 |
}
|
1039 |
catch (Exception $e)
|
1122 |
* start upload files to remote.
|
1123 |
*
|
1124 |
* @var string $task_id
|
1125 |
+
* @var bool $restart
|
1126 |
* @since 0.9.10
|
1127 |
*/
|
1128 |
+
public function upload($task_id,$restart=true)
|
1129 |
{
|
1130 |
$this->end_shutdown_function=false;
|
1131 |
register_shutdown_function(array($this,'deal_shutdown_error'),$task_id);
|
1132 |
@ignore_user_abort(true);
|
1133 |
+
WPvivid_taskmanager::update_backup_task_status($task_id,$restart,'running');
|
1134 |
$this->current_task=WPvivid_taskmanager::get_task($task_id);
|
1135 |
//start a watch task event
|
1136 |
$this->add_monitor_event($task_id);
|
1304 |
do_action('wpvivid_handle_backup_failed', $task);
|
1305 |
} else {
|
1306 |
$this->check_cancel_backup($task_id);
|
1307 |
+
$message = 'Task timed out (WebHosting).';
|
1308 |
if ($this->add_resume_event($task_id))
|
1309 |
{
|
1310 |
WPvivid_taskmanager::update_backup_task_status($task_id, false, 'wait_resume', false, $status['resume_count']);
|
1380 |
*
|
1381 |
* @since 0.9.1
|
1382 |
*/
|
1383 |
+
public function task_monitor($task_id)
|
1384 |
{
|
1385 |
if(WPvivid_taskmanager::get_task($task_id)!==false)
|
1386 |
{
|
1450 |
$this->add_monitor_event($task_id);
|
1451 |
}
|
1452 |
else{
|
1453 |
+
$this->add_monitor_event($task_id);
|
1454 |
+
}
|
1455 |
+
}
|
1456 |
+
}
|
1457 |
+
else if($status['str']=='wait_resume')
|
1458 |
+
{
|
1459 |
+
$timestamp = wp_next_scheduled(WPVIVID_RESUME_SCHEDULE_EVENT,array($task_id));
|
1460 |
+
if($timestamp===false)
|
1461 |
+
{
|
1462 |
+
if($this->wpvivid_log)
|
1463 |
+
$this->wpvivid_log->WriteLog('Missing resume task,so we create new one.','error');
|
1464 |
+
$message = 'Task timed out (WebHosting).';
|
1465 |
+
if ($this->add_resume_event($task_id))
|
1466 |
+
{
|
1467 |
+
WPvivid_taskmanager::update_backup_task_status($task_id, false, 'wait_resume', false, $status['resume_count']);
|
1468 |
+
} else {
|
1469 |
+
$task = WPvivid_taskmanager::update_backup_task_status($task_id, false, 'error', false, $status['resume_count'], $message);
|
1470 |
+
do_action('wpvivid_handle_backup_failed', $task);
|
1471 |
}
|
1472 |
}
|
1473 |
}
|
1488 |
*/
|
1489 |
public function check_backup($task_id,$backup_files)
|
1490 |
{
|
|
|
|
|
|
|
|
|
|
|
1491 |
$options=WPvivid_Setting::get_option('wpvivid_common_setting');
|
1492 |
if(isset($options['estimate_backup']))
|
1493 |
{
|
1501 |
}
|
1502 |
}
|
1503 |
|
|
|
1504 |
$file_size=false;
|
1505 |
$check_file=false;
|
1506 |
$check_db=false;
|
1531 |
}
|
1532 |
if($check_db)
|
1533 |
{
|
1534 |
+
$db_method=new WPvivid_DB_Method();
|
1535 |
+
$ret=$db_method->check_db($alter_fcgi);
|
1536 |
+
if($ret['result']==WPVIVID_FAILED)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1537 |
{
|
1538 |
+
return $ret;
|
1539 |
}
|
1540 |
+
}
|
1541 |
+
else
|
1542 |
+
{
|
1543 |
+
$ret['alert_db']=false;
|
1544 |
+
$ret['db_size']=false;
|
1545 |
+
}
|
1546 |
|
1547 |
+
$ret['alter_files']=false;
|
1548 |
+
$ret['alter_big_file']=false;
|
1549 |
+
$ret['alter_fcgi']=false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1550 |
|
|
|
|
|
1551 |
if($check_file)
|
1552 |
{
|
1553 |
include_once WPVIVID_PLUGIN_DIR .'/includes/class-wpvivid-backup.php';
|
1582 |
$file_size['sum']=$this->formatBytes($sum_size);
|
1583 |
}
|
1584 |
|
|
|
1585 |
$ret['file_size']=$file_size;
|
1586 |
if($task_id!==false)
|
1587 |
{
|
1588 |
$task=new WPvivid_Backup_Task($task_id);
|
1589 |
+
$task->set_file_and_db_info($ret['db_size'],$file_size);
|
1590 |
}
|
1591 |
return $ret;
|
1592 |
}
|
1824 |
public function init_download_page()
|
1825 |
{
|
1826 |
$this->ajax_check_security();
|
1827 |
+
try {
|
1828 |
+
if (isset($_POST['backup_id']) && !empty($_POST['backup_id']) && is_string($_POST['backup_id'])) {
|
1829 |
+
$backup_id = sanitize_key($_POST['backup_id']);
|
1830 |
+
$ret = $this->init_download($backup_id);
|
1831 |
+
echo json_encode($ret);
|
1832 |
+
}
|
1833 |
+
}
|
1834 |
+
catch (Exception $error) {
|
1835 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
1836 |
+
error_log($message);
|
1837 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
1838 |
+
die();
|
1839 |
}
|
|
|
1840 |
die();
|
1841 |
}
|
1842 |
/**
|
1878 |
public function prepare_download_backup()
|
1879 |
{
|
1880 |
$this->ajax_check_security();
|
1881 |
+
try {
|
1882 |
+
if (!isset($_POST['backup_id']) || empty($_POST['backup_id']) || !is_string($_POST['backup_id']) || !isset($_POST['file_name']) || empty($_POST['file_name']) || !is_string($_POST['file_name'])) {
|
1883 |
+
die();
|
1884 |
+
}
|
1885 |
+
$download_info = array();
|
1886 |
+
$download_info['backup_id'] = sanitize_key($_POST['backup_id']);
|
1887 |
+
//$download_info['file_name']=sanitize_file_name($_POST['file_name']);
|
1888 |
+
$download_info['file_name'] = $_POST['file_name'];
|
1889 |
+
set_time_limit(600);
|
1890 |
+
if (session_id())
|
1891 |
+
session_write_close();
|
1892 |
+
try {
|
1893 |
+
$downloader = new WPvivid_downloader();
|
1894 |
+
$downloader->ready_download($download_info);
|
1895 |
+
} catch (Exception $e) {
|
1896 |
+
$message = 'A exception (' . get_class($e) . ') occurred ' . $e->getMessage() . ' (Code: ' . $e->getCode() . ', line ' . $e->getLine() . ' in ' . $e->getFile() . ')';
|
1897 |
+
error_log($message);
|
1898 |
+
} catch (Error $e) {
|
1899 |
+
$message = 'A error (' . get_class($e) . ') has occurred: ' . $e->getMessage() . ' (Code: ' . $e->getCode() . ', line ' . $e->getLine() . ' in ' . $e->getFile() . ')';
|
1900 |
+
error_log($message);
|
1901 |
+
}
|
1902 |
+
|
1903 |
+
$ret['result'] = 'success';
|
1904 |
+
$json = json_encode($ret);
|
1905 |
+
echo $json;
|
1906 |
+
}
|
1907 |
+
catch (Exception $error) {
|
1908 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
1909 |
+
error_log($message);
|
1910 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
1911 |
die();
|
1912 |
}
|
1913 |
+
die();
|
1914 |
+
}
|
1915 |
+
|
1916 |
+
public function init_download($backup_id)
|
1917 |
+
{
|
1918 |
+
if(empty($backup_id))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1919 |
{
|
1920 |
$ret['result']=WPVIVID_SUCCESS;
|
1921 |
$ret['data']=array();
|
2252 |
public function delete_download()
|
2253 |
{
|
2254 |
$this->ajax_check_security();
|
2255 |
+
try {
|
2256 |
+
if (!isset($_POST['backup_id']) || empty($_POST['backup_id']) || !is_string($_POST['backup_id']) || !isset($_POST['file_name']) || empty($_POST['file_name']) || !is_string($_POST['file_name'])) {
|
2257 |
+
die();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2258 |
}
|
2259 |
+
$download_info = array();
|
2260 |
+
$download_info['backup_id'] = sanitize_key($_POST['backup_id']);
|
2261 |
+
//$download_info['file_name']=sanitize_file_name($_POST['file_name']);
|
2262 |
+
$download_info['file_name'] = $_POST['file_name'];
|
2263 |
+
|
2264 |
+
$files = array();
|
2265 |
+
$backup = WPvivid_Backuplist::get_backuplist_by_key($download_info['backup_id']);
|
2266 |
+
if (!$backup) {
|
2267 |
+
$json['result'] = 'failed';
|
2268 |
+
$json['error'] = __('Retrieving the backup(s) information failed while deleting the selected backup(s). Please try again later.', 'wpvivid');
|
2269 |
+
json_encode($json);
|
2270 |
+
die();
|
2271 |
+
}
|
2272 |
+
if ($backup['backup']['ismerge'] == 1) {
|
2273 |
+
$backup_files = $backup['backup']['data']['meta']['files'];
|
2274 |
+
foreach ($backup_files as $file) {
|
2275 |
+
if ($file['file_name'] == $download_info['file_name']) {
|
2276 |
+
$files[] = $file;
|
2277 |
break;
|
2278 |
}
|
2279 |
}
|
2280 |
+
} else {
|
2281 |
+
foreach ($backup['backup']['data']['type'] as $type) {
|
2282 |
+
$backup_files = $type['files'];
|
2283 |
+
foreach ($backup_files as $file) {
|
2284 |
+
if ($file['file_name'] == $download_info['file_name']) {
|
2285 |
+
$files[] = $file;
|
2286 |
+
break;
|
2287 |
+
}
|
2288 |
+
}
|
2289 |
+
}
|
2290 |
}
|
|
|
2291 |
|
2292 |
+
$download_dir = $backup['local']['path'];
|
2293 |
|
2294 |
+
foreach ($files as $file) {
|
2295 |
+
$download_path = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $download_dir . DIRECTORY_SEPARATOR . $file['file_name'];
|
2296 |
+
if (file_exists($download_path)) {
|
2297 |
+
unlink($download_path);
|
2298 |
+
}
|
|
|
2299 |
}
|
2300 |
+
$ret = $this->init_download($_POST['backup_id']);
|
2301 |
+
echo json_encode($ret);
|
2302 |
+
}
|
2303 |
+
catch (Exception $error) {
|
2304 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
2305 |
+
error_log($message);
|
2306 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
2307 |
+
die();
|
2308 |
}
|
|
|
|
|
2309 |
die();
|
2310 |
}
|
2311 |
/**
|
2316 |
public function download_backup()
|
2317 |
{
|
2318 |
$this->ajax_check_security();
|
2319 |
+
try {
|
2320 |
+
if (isset($_REQUEST['backup_id']) && isset($_REQUEST['file_name'])) {
|
2321 |
+
if (!empty($_REQUEST['backup_id']) && is_string($_REQUEST['backup_id'])) {
|
2322 |
+
$backup_id = sanitize_key($_REQUEST['backup_id']);
|
2323 |
+
} else {
|
2324 |
+
die();
|
2325 |
+
}
|
2326 |
|
2327 |
+
if (!empty($_REQUEST['file_name']) && is_string($_REQUEST['file_name'])) {
|
2328 |
+
//$file_name=sanitize_file_name($_REQUEST['file_name']);
|
2329 |
+
$file_name = $_REQUEST['file_name'];
|
2330 |
+
} else {
|
2331 |
+
die();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2332 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2333 |
|
2334 |
+
$cache = WPvivid_taskmanager::get_download_cache($backup_id);
|
2335 |
+
if ($cache === false) {
|
2336 |
+
$this->init_download($backup_id);
|
2337 |
+
$cache = WPvivid_taskmanager::get_download_cache($backup_id);
|
2338 |
+
}
|
2339 |
+
$path = false;
|
2340 |
+
if (array_key_exists($file_name, $cache['files'])) {
|
2341 |
+
if ($cache['files'][$file_name]['status'] == 'completed') {
|
2342 |
+
$path = $cache['files'][$file_name]['download_path'];
|
2343 |
}
|
2344 |
+
}
|
2345 |
+
if ($path !== false) {
|
2346 |
+
if (file_exists($path)) {
|
2347 |
+
if (session_id())
|
2348 |
+
session_write_close();
|
2349 |
+
|
2350 |
+
$size = filesize($path);
|
2351 |
+
if (!headers_sent()) {
|
2352 |
+
header('Content-Description: File Transfer');
|
2353 |
+
header('Content-Type: application/zip');
|
2354 |
+
header('Content-Disposition: attachment; filename="' . basename($path) . '"');
|
2355 |
+
header('Cache-Control: must-revalidate');
|
2356 |
+
header('Content-Length: ' . $size);
|
2357 |
+
header('Content-Transfer-Encoding: binary');
|
2358 |
+
}
|
2359 |
|
2360 |
+
if ($size < 1024 * 1024 * 60) {
|
2361 |
+
ob_end_clean();
|
2362 |
+
readfile($path);
|
2363 |
+
exit;
|
2364 |
+
} else {
|
2365 |
+
ob_end_clean();
|
2366 |
+
$download_rate = 1024 * 10;
|
2367 |
+
$file = fopen($path, "r");
|
2368 |
+
while (!feof($file)) {
|
2369 |
+
set_time_limit(20);
|
2370 |
+
// send the current file part to the browser
|
2371 |
+
print fread($file, round($download_rate * 1024));
|
2372 |
+
// flush the content to the browser
|
2373 |
+
flush();
|
2374 |
+
// sleep one second
|
2375 |
+
sleep(1);
|
2376 |
+
}
|
2377 |
+
fclose($file);
|
2378 |
+
exit;
|
|
|
2379 |
}
|
|
|
|
|
2380 |
}
|
2381 |
}
|
2382 |
}
|
2383 |
}
|
2384 |
+
catch (Exception $error) {
|
2385 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
2386 |
+
error_log($message);
|
2387 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
2388 |
+
die();
|
2389 |
+
}
|
2390 |
$admin_url = admin_url();
|
2391 |
echo __('file not found. please <a href="'.$admin_url.'admin.php?page=WPvivid">retry</a>.');
|
2392 |
die();
|
2399 |
public function get_backup_list()
|
2400 |
{
|
2401 |
$this->ajax_check_security('manage_options');
|
2402 |
+
try {
|
2403 |
+
$json['result'] = 'success';
|
2404 |
+
$html = '';
|
2405 |
+
$html = apply_filters('wpvivid_add_backup_list', $html);
|
2406 |
+
$json['html'] = $html;
|
2407 |
+
echo json_encode($json);
|
2408 |
+
}
|
2409 |
+
catch (Exception $error) {
|
2410 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
2411 |
+
error_log($message);
|
2412 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
2413 |
+
die();
|
2414 |
+
}
|
2415 |
die();
|
2416 |
}
|
2417 |
/**
|
2422 |
public function delete_backup()
|
2423 |
{
|
2424 |
$this->ajax_check_security();
|
2425 |
+
try {
|
2426 |
+
if (isset($_POST['backup_id']) && !empty($_POST['backup_id']) && is_string($_POST['backup_id']) && isset($_POST['force'])) {
|
2427 |
+
if ($_POST['force'] == 0 || $_POST['force'] == 1) {
|
2428 |
+
$force_del = $_POST['force'];
|
2429 |
+
} else {
|
2430 |
+
$force_del = 0;
|
2431 |
+
}
|
2432 |
+
$backup_id = sanitize_key($_POST['backup_id']);
|
2433 |
|
2434 |
+
$ret = $this->delete_backup_by_id($backup_id, $force_del);
|
2435 |
+
$html = '';
|
2436 |
+
$html = apply_filters('wpvivid_add_backup_list', $html);
|
2437 |
+
$ret['html'] = $html;
|
2438 |
+
echo json_encode($ret);
|
|
|
|
|
|
|
|
|
2439 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2440 |
}
|
2441 |
+
catch (Exception $error) {
|
2442 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
2443 |
+
error_log($message);
|
2444 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
2445 |
+
die();
|
2446 |
+
}
|
2447 |
die();
|
2448 |
}
|
2449 |
/**
|
2454 |
public function delete_backup_array()
|
2455 |
{
|
2456 |
$this->ajax_check_security();
|
2457 |
+
try {
|
2458 |
+
if (isset($_POST['backup_id']) && !empty($_POST['backup_id']) && is_array($_POST['backup_id'])) {
|
2459 |
+
$backup_ids = $_POST['backup_id'];
|
2460 |
+
$ret = array();
|
2461 |
+
foreach ($backup_ids as $backup_id) {
|
2462 |
+
$backup_id = sanitize_key($backup_id);
|
2463 |
+
$ret = $this->delete_backup_by_id($backup_id);
|
2464 |
+
}
|
2465 |
+
$html = '';
|
2466 |
+
$html = apply_filters('wpvivid_add_backup_list', $html);
|
2467 |
+
$ret['html'] = $html;
|
2468 |
+
echo json_encode($ret);
|
2469 |
}
|
|
|
|
|
|
|
|
|
2470 |
}
|
2471 |
+
catch (Exception $error) {
|
2472 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
2473 |
+
error_log($message);
|
2474 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
2475 |
+
die();
|
2476 |
+
}
|
2477 |
die();
|
2478 |
}
|
2479 |
|
2563 |
public function delete_task()
|
2564 |
{
|
2565 |
$this->ajax_check_security('manage_options');
|
2566 |
+
try {
|
2567 |
+
if (isset($_POST['task_id']) && !empty($_POST['task_id']) && is_string($_POST['task_id'])) {
|
2568 |
+
$task_id = sanitize_key($_POST['task_id']);
|
2569 |
+
WPvivid_taskmanager::delete_task($task_id);
|
2570 |
|
2571 |
+
echo $json['result'] = 'success';
|
2572 |
+
}
|
2573 |
+
}
|
2574 |
+
catch (Exception $error) {
|
2575 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
2576 |
+
error_log($message);
|
2577 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
2578 |
+
die();
|
2579 |
}
|
|
|
2580 |
die();
|
2581 |
}
|
2582 |
/**
|
2586 |
*/
|
2587 |
public function add_remote()
|
2588 |
{
|
2589 |
+
try {
|
2590 |
+
if (empty($_POST) || !isset($_POST['remote']) || !is_string($_POST['remote']) || !isset($_POST['type']) || !is_string($_POST['type'])) {
|
2591 |
+
die();
|
2592 |
+
}
|
2593 |
+
$json = $_POST['remote'];
|
2594 |
+
$json = stripslashes($json);
|
2595 |
+
$remote_options = json_decode($json, true);
|
2596 |
+
if (is_null($remote_options)) {
|
2597 |
+
die();
|
2598 |
+
}
|
|
|
2599 |
|
2600 |
+
$remote_options['type'] = $_POST['type'];
|
2601 |
+
if ($remote_options['type'] == 'amazons3') {
|
2602 |
+
$remote_options['s3Path'] = rtrim($remote_options['s3Path'], "/");
|
2603 |
+
}
|
2604 |
+
$ret = $this->remote_collection->add_remote($remote_options);
|
2605 |
|
2606 |
+
if ($ret['result'] == 'success') {
|
2607 |
+
$html = '';
|
2608 |
+
$html = apply_filters('wpvivid_add_remote_storage_list', $html);
|
2609 |
+
$ret['html'] = $html;
|
2610 |
+
$pic = '';
|
2611 |
+
$pic = apply_filters('wpvivid_schedule_add_remote_pic', $pic);
|
2612 |
+
$ret['pic'] = $pic;
|
2613 |
+
$dir = '';
|
2614 |
+
$dir = apply_filters('wpvivid_get_remote_directory', $dir);
|
2615 |
+
$ret['dir'] = $dir;
|
2616 |
+
$schedule_local_remote = '';
|
2617 |
+
$schedule_local_remote = apply_filters('wpvivid_schedule_local_remote', $schedule_local_remote);
|
2618 |
+
$ret['local_remote'] = $schedule_local_remote;
|
2619 |
+
$remote_storage = '';
|
2620 |
+
$remote_storage = apply_filters('wpvivid_remote_storage', $remote_storage);
|
2621 |
+
$ret['remote_storage'] = $remote_storage;
|
2622 |
+
}
|
2623 |
+
}
|
2624 |
+
catch (Exception $error) {
|
2625 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
2626 |
+
error_log($message);
|
2627 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
2628 |
+
die();
|
2629 |
}
|
2630 |
echo json_encode($ret);
|
2631 |
die();
|
2637 |
*/
|
2638 |
public function delete_remote()
|
2639 |
{
|
2640 |
+
try {
|
2641 |
+
$this->ajax_check_security('manage_options');
|
2642 |
+
if (empty($_POST) || !isset($_POST['remote_id']) || !is_string($_POST['remote_id'])) {
|
2643 |
+
die();
|
2644 |
+
}
|
2645 |
+
$id = sanitize_key($_POST['remote_id']);
|
2646 |
+
if (WPvivid_Setting::delete_remote_option($id)) {
|
2647 |
+
$remote_selected = WPvivid_Setting::get_user_history('remote_selected');
|
2648 |
+
if (in_array($id, $remote_selected)) {
|
2649 |
+
WPvivid_Setting::update_user_history('remote_selected', array());
|
2650 |
+
}
|
2651 |
+
$ret['result'] = 'success';
|
2652 |
+
$html = '';
|
2653 |
+
$html = apply_filters('wpvivid_add_remote_storage_list', $html);
|
2654 |
+
$ret['html'] = $html;
|
2655 |
+
$pic = '';
|
2656 |
+
$pic = apply_filters('wpvivid_schedule_add_remote_pic', $pic);
|
2657 |
+
$ret['pic'] = $pic;
|
2658 |
+
$dir = '';
|
2659 |
+
$dir = apply_filters('wpvivid_get_remote_directory', $dir);
|
2660 |
+
$ret['dir'] = $dir;
|
2661 |
+
$schedule_local_remote = '';
|
2662 |
+
$schedule_local_remote = apply_filters('wpvivid_schedule_local_remote', $schedule_local_remote);
|
2663 |
+
$ret['local_remote'] = $schedule_local_remote;
|
2664 |
+
$remote_storage = '';
|
2665 |
+
$remote_storage = apply_filters('wpvivid_remote_storage', $remote_storage);
|
2666 |
+
$ret['remote_storage'] = $remote_storage;
|
2667 |
+
} else {
|
2668 |
+
$ret['result'] = 'failed';
|
2669 |
+
$ret['error'] = __('Retrieving the backup(s) information failed while deleting the selected backup(s). Please try again later.', 'wpvivid');
|
2670 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2671 |
}
|
2672 |
+
catch (Exception $error) {
|
2673 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
2674 |
+
error_log($message);
|
2675 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
2676 |
+
die();
|
2677 |
}
|
2678 |
echo json_encode($ret);
|
2679 |
die();
|
2686 |
*/
|
2687 |
public function retrieve_remote()
|
2688 |
{
|
2689 |
+
try {
|
2690 |
+
$this->ajax_check_security();
|
2691 |
+
if (empty($_POST) || !isset($_POST['remote_id']) || !is_string($_POST['remote_id'])) {
|
2692 |
+
die();
|
2693 |
+
}
|
2694 |
+
$id = sanitize_key($_POST['remote_id']);
|
2695 |
+
$remoteslist = WPvivid_Setting::get_all_remote_options();
|
2696 |
+
$ret['result'] = WPVIVID_FAILED;
|
2697 |
+
$ret['error'] = __('Failed to get the remote storage information. Please try again later.', 'wpvivid');
|
2698 |
+
foreach ($remoteslist as $key => $value) {
|
2699 |
+
if ($key == $id) {
|
2700 |
+
if ($key === 'remote_selected') {
|
2701 |
+
continue;
|
2702 |
+
}
|
2703 |
+
$ret = $value;
|
2704 |
+
$ret['result'] = WPVIVID_SUCCESS;
|
2705 |
+
break;
|
2706 |
}
|
|
|
|
|
|
|
2707 |
}
|
2708 |
}
|
2709 |
+
catch (Exception $error) {
|
2710 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
2711 |
+
error_log($message);
|
2712 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
2713 |
+
die();
|
2714 |
+
}
|
2715 |
echo json_encode($ret);
|
2716 |
die();
|
2717 |
}
|
2723 |
public function edit_remote()
|
2724 |
{
|
2725 |
$this->ajax_check_security();
|
2726 |
+
try {
|
2727 |
+
if (empty($_POST) || !isset($_POST['remote']) || !is_string($_POST['remote']) || !isset($_POST['id']) || !is_string($_POST['id']) || !isset($_POST['type']) || !is_string($_POST['type'])) {
|
2728 |
+
die();
|
2729 |
+
}
|
2730 |
+
$json = $_POST['remote'];
|
2731 |
+
$json = stripslashes($json);
|
2732 |
+
$remote_options = json_decode($json, true);
|
2733 |
+
if (is_null($remote_options)) {
|
2734 |
+
die();
|
2735 |
+
}
|
2736 |
+
$remote_options['type'] = $_POST['type'];
|
2737 |
+
if ($remote_options['type'] == 'amazons3') {
|
2738 |
+
$remote_options['s3Path'] = rtrim($remote_options['s3Path'], "/");
|
2739 |
+
}
|
2740 |
+
$ret = $this->remote_collection->update_remote($_POST['id'], $remote_options);
|
2741 |
+
|
2742 |
+
if ($ret['result'] == 'success') {
|
2743 |
+
$ret['result'] = WPVIVID_SUCCESS;
|
2744 |
+
$html = '';
|
2745 |
+
$html = apply_filters('wpvivid_add_remote_storage_list', $html);
|
2746 |
+
$ret['html'] = $html;
|
2747 |
+
$pic = '';
|
2748 |
+
$pic = apply_filters('wpvivid_schedule_add_remote_pic', $pic);
|
2749 |
+
$ret['pic'] = $pic;
|
2750 |
+
$dir = '';
|
2751 |
+
$dir = apply_filters('wpvivid_get_remote_directory', $dir);
|
2752 |
+
$ret['dir'] = $dir;
|
2753 |
+
$schedule_local_remote = '';
|
2754 |
+
$schedule_local_remote = apply_filters('wpvivid_schedule_local_remote', $schedule_local_remote);
|
2755 |
+
$ret['local_remote'] = $schedule_local_remote;
|
2756 |
+
$remote_storage = '';
|
2757 |
+
$remote_storage = apply_filters('wpvivid_remote_storage', $remote_storage);
|
2758 |
+
$ret['remote_storage'] = $remote_storage;
|
2759 |
+
}
|
2760 |
+
}
|
2761 |
+
catch (Exception $error) {
|
2762 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
2763 |
+
error_log($message);
|
2764 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
2765 |
die();
|
2766 |
}
|
2767 |
+
echo json_encode($ret);
|
2768 |
+
die();
|
2769 |
+
}
|
2770 |
+
/**
|
2771 |
+
* List exist remote
|
2772 |
+
*
|
2773 |
+
* @since 0.9.1
|
2774 |
+
*/
|
2775 |
+
public function list_remote()
|
2776 |
+
{
|
2777 |
+
$this->ajax_check_security('manage_options');
|
2778 |
+
try {
|
2779 |
+
$ret['result'] = 'success';
|
2780 |
$html = '';
|
2781 |
$html = apply_filters('wpvivid_add_remote_storage_list', $html);
|
2782 |
$ret['html'] = $html;
|
2786 |
$dir = '';
|
2787 |
$dir = apply_filters('wpvivid_get_remote_directory', $dir);
|
2788 |
$ret['dir'] = $dir;
|
2789 |
+
$schedule_local_remote = '';
|
2790 |
+
$schedule_local_remote = apply_filters('wpvivid_schedule_local_remote', $schedule_local_remote);
|
2791 |
$ret['local_remote'] = $schedule_local_remote;
|
2792 |
$remote_storage = '';
|
2793 |
+
$remote_storage = apply_filters('wpvivid_remote_storage', $remote_storage);
|
2794 |
$ret['remote_storage'] = $remote_storage;
|
2795 |
}
|
2796 |
+
catch (Exception $error) {
|
2797 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
2798 |
+
error_log($message);
|
2799 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
2800 |
+
die();
|
2801 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2802 |
echo json_encode($ret);
|
2803 |
die();
|
2804 |
}
|
2810 |
public function test_remote_connection()
|
2811 |
{
|
2812 |
$this->ajax_check_security();
|
2813 |
+
try {
|
2814 |
+
if (empty($_POST) || !isset($_POST['remote']) || !is_string($_POST['remote']) || !isset($_POST['type']) || !is_string($_POST['type'])) {
|
2815 |
+
die();
|
2816 |
+
}
|
2817 |
+
$json = $_POST['remote'];
|
2818 |
+
$json = stripslashes($json);
|
2819 |
+
$remote_options = json_decode($json, true);
|
2820 |
+
if (is_null($remote_options)) {
|
2821 |
+
die();
|
2822 |
+
}
|
2823 |
|
2824 |
+
$remote_options['type'] = $_POST['type'];
|
2825 |
+
$remote = $this->remote_collection->get_remote($remote_options);
|
2826 |
+
$ret = $remote->test_connect();
|
2827 |
}
|
2828 |
+
catch (Exception $error) {
|
2829 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
2830 |
+
error_log($message);
|
2831 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
|
|
2832 |
die();
|
2833 |
}
|
|
|
|
|
|
|
|
|
2834 |
echo json_encode($ret);
|
2835 |
die();
|
2836 |
}
|
2842 |
public function get_schedule()
|
2843 |
{
|
2844 |
$this->ajax_check_security('manage_options');
|
2845 |
+
try {
|
2846 |
+
$schedule = WPvivid_Schedule::get_schedule();
|
2847 |
+
$schedule['next_start'] = date("l, F d, Y H:i", $schedule['next_start']);
|
2848 |
+
$ret['result'] = 'success';
|
2849 |
+
$ret['data'] = $schedule;
|
2850 |
+
$ret['user_history'] = WPvivid_Setting::get_user_history('remote_selected');
|
2851 |
+
echo json_encode($ret);
|
2852 |
+
}
|
2853 |
+
catch (Exception $error) {
|
2854 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
2855 |
+
error_log($message);
|
2856 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
2857 |
+
die();
|
2858 |
+
}
|
2859 |
die();
|
2860 |
}
|
2861 |
|
2895 |
public function init_restore_page()
|
2896 |
{
|
2897 |
$this->ajax_check_security();
|
2898 |
+
try {
|
2899 |
+
if (!isset($_POST['backup_id']) || empty($_POST['backup_id']) || !is_string($_POST['backup_id'])) {
|
2900 |
+
die();
|
2901 |
+
}
|
2902 |
|
2903 |
+
$this->restore_data = new WPvivid_restore_data();
|
2904 |
+
$ret_scan_last_restore = $this->scan_last_restore();
|
|
|
|
|
2905 |
|
2906 |
+
$backup_id = sanitize_key($_POST['backup_id']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2907 |
|
2908 |
+
$backup = WPvivid_Backuplist::get_backuplist_by_key($backup_id);
|
2909 |
|
2910 |
+
$backup_item = new WPvivid_Backup_Item($backup);
|
2911 |
|
2912 |
+
$ret = $backup_item->check_backup_files();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2913 |
|
2914 |
+
if ($backup_item->get_backup_type() == 'Upload' || $backup_item->get_backup_type() == 'Migration') {
|
2915 |
+
$ret['is_migrate'] = 1;
|
2916 |
+
} else {
|
2917 |
+
$ret['is_migrate'] = 0;
|
2918 |
+
}
|
2919 |
|
2920 |
+
$ret['skip_backup_old_site'] = 1;
|
2921 |
+
$ret['skip_backup_old_database'] = 1;
|
2922 |
|
2923 |
+
$ret = array_merge($ret, $ret_scan_last_restore);
|
|
|
2924 |
|
2925 |
+
$restore_db_data = new WPvivid_RestoreDB();
|
2926 |
+
$ret['max_allow_packet_warning'] = $restore_db_data->check_max_allow_packet_ex();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2927 |
|
2928 |
+
$memory_limit = ini_get('memory_limit');
|
2929 |
+
$unit = substr($memory_limit, -1);
|
2930 |
+
if ($unit == 'K') {
|
2931 |
+
$memory_limit_tmp = intval($memory_limit) * 1024;
|
2932 |
+
} else if ($unit == 'M') {
|
2933 |
+
$memory_limit_tmp = intval($memory_limit) * 1024 * 1024;
|
2934 |
+
} else if ($unit == 'G') {
|
2935 |
+
$memory_limit_tmp = intval($memory_limit) * 1024 * 1024 * 1024;
|
2936 |
+
}
|
2937 |
+
if ($memory_limit_tmp < 256 * 1024 * 1024) {
|
2938 |
+
$ret['memory_limit_warning'] = 'memory_limit = ' . $memory_limit . ' is too small. The recommended value is 256M or higher. Too small value could result in a failure of website restore.';
|
2939 |
+
} else {
|
2940 |
+
$ret['memory_limit_warning'] = false;
|
2941 |
+
}
|
2942 |
|
2943 |
+
if ($ret['result'] == WPVIVID_FAILED) {
|
2944 |
+
$this->wpvivid_handle_restore_error($ret['error'], 'Init restore page');
|
2945 |
+
}
|
2946 |
+
|
2947 |
+
echo json_encode($ret);
|
2948 |
+
}
|
2949 |
+
catch (Exception $error) {
|
2950 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
2951 |
+
error_log($message);
|
2952 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
2953 |
+
die();
|
2954 |
+
}
|
2955 |
die();
|
2956 |
}
|
2957 |
|
2958 |
public function delete_last_restore_data()
|
2959 |
{
|
2960 |
$this->ajax_check_security();
|
2961 |
+
try {
|
2962 |
+
$this->restore_data = new WPvivid_restore_data();
|
2963 |
+
$this->restore_data->clean_restore_data();
|
2964 |
+
$ret['result'] = 'success';
|
2965 |
+
echo json_encode($ret);
|
2966 |
+
}
|
2967 |
+
catch (Exception $error) {
|
2968 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
2969 |
+
error_log($message);
|
2970 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
2971 |
+
die();
|
2972 |
+
}
|
2973 |
die();
|
2974 |
}
|
2975 |
|
2976 |
public function delete_old_files()
|
2977 |
{
|
2978 |
+
try {
|
2979 |
+
$this->restore_data = new WPvivid_restore_data();
|
2980 |
+
$this->restore_data->delete_old_files();
|
2981 |
+
$ret['result'] = 'success';
|
2982 |
+
echo json_encode($ret);
|
2983 |
+
}
|
2984 |
+
catch (Exception $error) {
|
2985 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
2986 |
+
error_log($message);
|
2987 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
2988 |
+
die();
|
2989 |
+
}
|
2990 |
die();
|
2991 |
}
|
2992 |
/**
|
2997 |
public function prepare_restore()
|
2998 |
{
|
2999 |
$this->ajax_check_security();
|
3000 |
+
try {
|
3001 |
+
if (!isset($_POST['backup_id']) || empty($_POST['backup_id']) || !is_string($_POST['backup_id'])) {
|
3002 |
+
die();
|
3003 |
+
}
|
3004 |
|
3005 |
+
$backup_id = sanitize_key($_POST['backup_id']);
|
|
|
|
|
|
|
3006 |
|
3007 |
+
$backup = WPvivid_Backuplist::get_backuplist_by_key($backup_id);
|
3008 |
|
3009 |
+
$backup_item = new WPvivid_Backup_Item($backup);
|
3010 |
|
3011 |
+
$ret = $backup_item->check_backup_files();
|
3012 |
|
3013 |
+
if ($backup_item->get_backup_type() == 'Upload') {
|
3014 |
+
$ret['is_migrate'] = 1;
|
3015 |
+
} else {
|
3016 |
+
$ret['is_migrate'] = 0;
|
3017 |
+
}
|
3018 |
|
3019 |
+
echo json_encode($ret);
|
3020 |
+
}
|
3021 |
+
catch (Exception $error) {
|
3022 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
3023 |
+
error_log($message);
|
3024 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
3025 |
+
die();
|
3026 |
}
|
|
|
|
|
3027 |
die();
|
3028 |
}
|
3029 |
/**
|
3034 |
public function download_restore_file()
|
3035 |
{
|
3036 |
$this->ajax_check_security();
|
3037 |
+
try {
|
3038 |
+
if (!isset($_POST['backup_id']) || empty($_POST['backup_id']) || !is_string($_POST['backup_id'])
|
3039 |
+
|| !isset($_POST['file_name']) || empty($_POST['file_name']) || !is_string($_POST['file_name'])) {
|
3040 |
+
die();
|
3041 |
+
}
|
3042 |
|
3043 |
+
set_time_limit(600);
|
|
|
|
|
|
|
|
|
3044 |
|
3045 |
+
$backup_id = sanitize_key($_POST['backup_id']);
|
3046 |
+
//$file_name=sanitize_file_name($_POST['file_name']);
|
3047 |
+
$file_name = $_POST['file_name'];
|
3048 |
|
3049 |
+
$file['file_name'] = $file_name;
|
3050 |
+
$file['size'] = $_POST['size'];
|
3051 |
+
$file['md5'] = $_POST['md5'];
|
3052 |
+
$backup = WPvivid_Backuplist::get_backuplist_by_key($backup_id);
|
3053 |
+
if (!$backup) {
|
3054 |
+
echo json_encode(array('result' => WPVIVID_FAILED, 'error' => 'backup not found'));
|
3055 |
+
die();
|
3056 |
+
}
|
3057 |
|
3058 |
+
$backup_item = new WPvivid_Backup_Item($backup);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3059 |
|
3060 |
+
$local_path = $backup_item->get_local_path();
|
3061 |
+
$remote_option = $backup_item->get_remote();
|
3062 |
|
3063 |
+
if ($remote_option === false) {
|
3064 |
+
echo json_encode(array('result' => WPVIVID_FAILED, 'error' => 'Retrieving the cloud storage information failed while downloading backups. Please try again later.'));
|
3065 |
+
die();
|
3066 |
+
}
|
3067 |
|
3068 |
+
$downloader = new WPvivid_downloader();
|
3069 |
+
$ret = $downloader->download($file, $local_path, $remote_option);
|
3070 |
+
|
3071 |
+
echo json_encode($ret);
|
3072 |
+
}
|
3073 |
+
catch (Exception $error) {
|
3074 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
3075 |
+
error_log($message);
|
3076 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
3077 |
die();
|
3078 |
}
|
|
|
|
|
|
|
|
|
|
|
3079 |
die();
|
3080 |
}
|
3081 |
|
3082 |
public function download_restore_progress()
|
3083 |
{
|
3084 |
+
try {
|
3085 |
+
if (!isset($_POST['file_name'])) {
|
3086 |
+
die();
|
3087 |
+
}
|
3088 |
|
3089 |
+
$task = WPvivid_taskmanager::get_download_task_v2($_POST['file_name']);
|
3090 |
|
3091 |
+
if ($task === false) {
|
3092 |
+
$ret['result'] = WPVIVID_FAILED;
|
3093 |
+
$ret['error'] = 'not found download file';
|
3094 |
+
$this->wpvivid_handle_restore_error($ret['error'], 'Downloading backup file');
|
3095 |
+
echo json_encode($ret);
|
3096 |
+
} else {
|
3097 |
+
$ret['result'] = WPVIVID_SUCCESS;
|
3098 |
+
$ret['status'] = $task['status'];
|
3099 |
+
$ret['log'] = $task['progress_text'];
|
3100 |
+
$ret['error'] = $task['error'];
|
3101 |
+
echo json_encode($ret);
|
3102 |
+
}
|
3103 |
}
|
3104 |
+
catch (Exception $error) {
|
3105 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
3106 |
+
error_log($message);
|
3107 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
3108 |
+
die();
|
|
|
|
|
3109 |
}
|
3110 |
die();
|
3111 |
}
|
3212 |
{
|
3213 |
$this->_enable_maintenance_mode();
|
3214 |
$restore=new WPvivid_Restore();
|
3215 |
+
$common_setting = WPvivid_Setting::get_option('wpvivid_common_setting');
|
3216 |
+
if(isset($common_setting['restore_memory_limit']) && !empty($common_setting['restore_memory_limit'])){
|
3217 |
+
$memory_limit = $common_setting['restore_memory_limit'];
|
3218 |
+
}
|
3219 |
+
else{
|
3220 |
+
$memory_limit = WPVIVID_RESTORE_MEMORY_LIMIT;
|
3221 |
+
}
|
3222 |
+
@ini_set('memory_limit', $memory_limit);
|
3223 |
$ret=$restore->restore();
|
3224 |
$this->_disable_maintenance_mode();
|
3225 |
}
|
3394 |
*/
|
3395 |
public function get_restore_progress()
|
3396 |
{
|
3397 |
+
try {
|
3398 |
+
$this->restore_data = new WPvivid_restore_data();
|
3399 |
|
3400 |
+
if ($this->restore_data->has_restore()) {
|
3401 |
+
$ret['result'] = 'success';
|
3402 |
+
$ret['status'] = $this->restore_data->get_restore_status();
|
3403 |
+
if ($ret['status'] == WPVIVID_RESTORE_ERROR) {
|
3404 |
+
$this->restore_data->save_error_log_to_debug();
|
3405 |
+
}
|
3406 |
+
$ret['log'] = $this->restore_data->get_log_content();
|
3407 |
+
echo json_encode($ret);
|
3408 |
+
die();
|
3409 |
+
} else {
|
3410 |
+
$ret['result'] = 'failed';
|
3411 |
+
$ret['error'] = __('The restore file not found. Please verify the file exists.', 'wpvivid');
|
3412 |
+
echo json_encode($ret);
|
3413 |
+
die();
|
3414 |
}
|
|
|
|
|
|
|
3415 |
}
|
3416 |
+
catch (Exception $error) {
|
3417 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
3418 |
+
error_log($message);
|
3419 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
|
|
3420 |
die();
|
3421 |
}
|
3422 |
}
|
3427 |
*/
|
3428 |
public function get_rollback_progress()
|
3429 |
{
|
3430 |
+
try {
|
3431 |
+
$this->restore_data = new WPvivid_restore_data();
|
3432 |
|
3433 |
+
if ($this->restore_data->has_rollback()) {
|
3434 |
+
$ret['result'] = 'success';
|
3435 |
+
$ret['status'] = $this->restore_data->get_rollback_status();
|
3436 |
+
$ret['log'] = $this->restore_data->get_rollback_log_content();
|
3437 |
+
echo json_encode($ret);
|
3438 |
+
die();
|
3439 |
+
} else {
|
3440 |
+
$ret['result'] = 'failed';
|
3441 |
+
$ret['error'] = 'The restore file not found. Please verify the file exists.';
|
3442 |
+
echo json_encode($ret);
|
3443 |
+
die();
|
3444 |
+
}
|
3445 |
}
|
3446 |
+
catch (Exception $error) {
|
3447 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
3448 |
+
error_log($message);
|
3449 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
|
|
3450 |
die();
|
3451 |
}
|
3452 |
}
|
3530 |
public function get_last_backup()
|
3531 |
{
|
3532 |
$this->ajax_check_security('manage_options');
|
3533 |
+
try {
|
3534 |
+
$html = '';
|
3535 |
+
$html = apply_filters('wpvivid_get_last_backup_message', $html);
|
3536 |
+
$ret['data'] = $html;
|
3537 |
+
echo json_encode($ret);
|
3538 |
+
}
|
3539 |
+
catch (Exception $error) {
|
3540 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
3541 |
+
error_log($message);
|
3542 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
3543 |
+
die();
|
3544 |
+
}
|
3545 |
die();
|
3546 |
}
|
3547 |
|
3670 |
if(!empty($backup_error_array)){
|
3671 |
$error_notice_html = array();
|
3672 |
foreach ($backup_error_array as $key => $value){
|
|
|
3673 |
$error_notice_html['bu_error']['task_id']=$value['task_id'];
|
3674 |
+
$general_setting=WPvivid_Setting::get_setting(true, "");
|
3675 |
+
$need_notice = false;
|
3676 |
+
if(!isset($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload'])){
|
3677 |
+
$need_notice = true;
|
3678 |
+
}
|
3679 |
+
else{
|
3680 |
+
if($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']){
|
3681 |
+
$need_notice = false;
|
3682 |
+
}
|
3683 |
+
else{
|
3684 |
+
$need_notice = true;
|
3685 |
+
}
|
3686 |
+
}
|
3687 |
+
if($need_notice) {
|
3688 |
+
if($value['error_msg'] == 'Too many resumption attempts.' || $value['error_msg'] == 'Task timed out.' || $value['error_msg'] = 'Task timed out (WebHosting).') {
|
3689 |
+
$notice_msg1 = 'Backup failed, it seems due to insufficient server resource or hitting server limit. Please navigate to Settings > Advanced > ';
|
3690 |
+
$notice_msg2 = 'optimization mode for web hosting/shared hosting';
|
3691 |
+
$notice_msg3 = ' to enable it and try again';
|
3692 |
+
$error_notice_html['bu_error']['error_msg']=__('<div class="notice notice-error inline"><p>'.$notice_msg1.'<strong>'.$notice_msg2.'</strong>'.$notice_msg3.'</p></div>');
|
3693 |
+
}
|
3694 |
+
else{
|
3695 |
+
$notice_msg = 'Backup error: '.$value['error_msg'].', task id: '.$value['task_id'];
|
3696 |
+
$error_notice_html['bu_error']['error_msg']=__('<div class="notice notice-error inline"><p>'.$notice_msg.', Please switch to <a href="#" onclick="wpvivid_click_switch_page(\'wrap\', \'wpvivid_tab_debug\', true);">Website Info</a> page to send us the debug information. </p></div>');
|
3697 |
+
}
|
3698 |
+
}
|
3699 |
+
else{
|
3700 |
+
if($value['error_msg'] == 'Too many resumption attempts.' || $value['error_msg'] == 'Task timed out.' || $value['error_msg'] = 'Task timed out (WebHosting).') {
|
3701 |
+
$notice_msg = 'Backup failed, it seems due to insufficient server resource or hitting server limit.';
|
3702 |
+
$error_notice_html['bu_error']['error_msg'] = __('<div class="notice notice-error inline"><p>' . $notice_msg . ', Please switch to <a href="#" onclick="wpvivid_click_switch_page(\'wrap\', \'wpvivid_tab_debug\', true);">Website Info</a> page to send us the debug information. </p></div>');
|
3703 |
+
}
|
3704 |
+
else {
|
3705 |
+
$notice_msg = 'Backup error: ' . $value['error_msg'] . ', task id: ' . $value['task_id'];
|
3706 |
+
$error_notice_html['bu_error']['error_msg'] = __('<div class="notice notice-error inline"><p>' . $notice_msg . ', Please switch to <a href="#" onclick="wpvivid_click_switch_page(\'wrap\', \'wpvivid_tab_debug\', true);">Website Info</a> page to send us the debug information. </p></div>');
|
3707 |
+
}
|
3708 |
+
}
|
3709 |
}
|
3710 |
WPvivid_Setting::delete_option('wpvivid_backup_error_array');
|
3711 |
$html = '';
|
3762 |
public function get_dir()
|
3763 |
{
|
3764 |
$this->ajax_check_security('manage_options');
|
3765 |
+
try {
|
3766 |
+
$dir = WPvivid_Setting::get_option('wpvivid_local_setting');
|
3767 |
|
3768 |
+
if (!isset($dir['path'])) {
|
3769 |
+
$dir = WPvivid_Setting::set_default_local_option();
|
3770 |
+
}
|
3771 |
|
3772 |
+
if (!is_dir(WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $dir['path'])) {
|
3773 |
+
@mkdir(WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $dir['path'], 0777, true);
|
3774 |
+
@fopen(WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $dir['path'] . '/index.html', 'x');
|
3775 |
+
$tempfile = @fopen(WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $dir['path'] . '/.htaccess', 'x');
|
3776 |
+
if ($tempfile) {
|
3777 |
+
$text = "deny from all";
|
3778 |
+
fwrite($tempfile, $text);
|
3779 |
+
fclose($tempfile);
|
3780 |
+
} else {
|
3781 |
+
$ret['result'] = 'failed';
|
3782 |
+
$ret['error'] = __('Getting backup directory failed. Please try again later.', 'wpvivid');
|
3783 |
+
}
|
3784 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3785 |
}
|
3786 |
|
3787 |
+
$ret['result'] = 'success';
|
3788 |
+
$ret['path'] = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $dir['path'];
|
3789 |
+
echo json_encode($ret);
|
3790 |
+
}
|
3791 |
+
catch (Exception $error) {
|
3792 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
3793 |
+
error_log($message);
|
3794 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
3795 |
+
die();
|
3796 |
}
|
|
|
|
|
|
|
|
|
|
|
3797 |
die();
|
3798 |
}
|
3799 |
/**
|
3804 |
public function set_security_lock()
|
3805 |
{
|
3806 |
$this->ajax_check_security('manage_options');
|
3807 |
+
try {
|
3808 |
+
if (isset($_POST['backup_id']) && !empty($_POST['backup_id']) && is_string($_POST['backup_id']) && isset($_POST['lock'])) {
|
3809 |
+
$backup_id = sanitize_key($_POST['backup_id']);
|
3810 |
+
if ($_POST['lock'] == 0 || $_POST['lock'] == 1) {
|
3811 |
+
$lock = $_POST['lock'];
|
3812 |
+
} else {
|
3813 |
+
$lock = 0;
|
3814 |
+
}
|
3815 |
|
3816 |
+
WPvivid_Backuplist::set_security_lock($backup_id, $lock);
|
3817 |
+
$ret['result'] = 'success';
|
3818 |
+
$list = WPvivid_Setting::get_option('wpvivid_backup_list');
|
3819 |
+
if (array_key_exists($backup_id, $list)) {
|
3820 |
+
if (isset($list[$backup_id]['lock'])) {
|
3821 |
+
if ($list[$backup_id]['lock'] == 1) {
|
3822 |
+
$backup_lock = '/admin/partials/images/locked.png';
|
3823 |
+
$lock_status = 'lock';
|
3824 |
+
$ret['html'] = '<img src="' . esc_url(WPVIVID_PLUGIN_URL . $backup_lock) . '" name="' . esc_attr($lock_status, 'wpvivid') . '" onclick="wpvivid_set_backup_lock(\'' . __($backup_id, 'wpvivid') . '\', \'' . __($lock_status, 'wpvivid') . '\');" style="vertical-align:middle; cursor:pointer;"/>';
|
3825 |
+
} else {
|
3826 |
+
$backup_lock = '/admin/partials/images/unlocked.png';
|
3827 |
+
$lock_status = 'unlock';
|
3828 |
+
$ret['html'] = '<img src="' . esc_url(WPVIVID_PLUGIN_URL . $backup_lock) . '" name="' . esc_attr($lock_status, 'wpvivid') . '" onclick="wpvivid_set_backup_lock(\'' . __($backup_id, 'wpvivid') . '\', \'' . __($lock_status, 'wpvivid') . '\');" style="vertical-align:middle; cursor:pointer;"/>';
|
3829 |
+
}
|
3830 |
+
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3831 |
$backup_lock = '/admin/partials/images/unlocked.png';
|
3832 |
$lock_status = 'unlock';
|
3833 |
$ret['html'] = '<img src="' . esc_url(WPVIVID_PLUGIN_URL . $backup_lock) . '" name="' . esc_attr($lock_status, 'wpvivid') . '" onclick="wpvivid_set_backup_lock(\'' . __($backup_id, 'wpvivid') . '\', \'' . __($lock_status, 'wpvivid') . '\');" style="vertical-align:middle; cursor:pointer;"/>';
|
3834 |
}
|
3835 |
+
} else {
|
|
|
|
|
3836 |
$backup_lock = '/admin/partials/images/unlocked.png';
|
3837 |
$lock_status = 'unlock';
|
3838 |
$ret['html'] = '<img src="' . esc_url(WPVIVID_PLUGIN_URL . $backup_lock) . '" name="' . esc_attr($lock_status, 'wpvivid') . '" onclick="wpvivid_set_backup_lock(\'' . __($backup_id, 'wpvivid') . '\', \'' . __($lock_status, 'wpvivid') . '\');" style="vertical-align:middle; cursor:pointer;"/>';
|
3839 |
}
|
3840 |
+
echo json_encode($ret);
|
3841 |
}
|
3842 |
+
}
|
3843 |
+
catch (Exception $error) {
|
3844 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
3845 |
+
error_log($message);
|
3846 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
3847 |
+
die();
|
|
|
3848 |
}
|
3849 |
die();
|
3850 |
}
|
3856 |
public function junk_files_info()
|
3857 |
{
|
3858 |
$this->ajax_check_security();
|
3859 |
+
try {
|
3860 |
+
$ret['result'] = 'success';
|
3861 |
+
$ret['data'] = $this->_junk_files_info();
|
3862 |
+
echo json_encode($ret);
|
3863 |
+
}
|
3864 |
+
catch (Exception $error) {
|
3865 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
3866 |
+
error_log($message);
|
3867 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
3868 |
+
die();
|
3869 |
+
}
|
3870 |
die();
|
3871 |
}
|
3872 |
|
3912 |
public function get_out_of_date_info()
|
3913 |
{
|
3914 |
$this->ajax_check_security();
|
3915 |
+
try {
|
3916 |
+
$dir = WPvivid_Setting::get_backupdir();
|
3917 |
+
$dir = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $dir;
|
3918 |
+
$ret['web_server'] = $dir;
|
3919 |
+
$ret['remote_options'] = WPvivid_Setting::get_remote_options();
|
3920 |
|
3921 |
+
$info = WPvivid_Backuplist::get_out_of_date_backuplist_info(WPvivid_Setting::get_max_backup_count());
|
3922 |
+
$ret['info'] = $info;
|
3923 |
+
$ret['info']['size'] = $this->formatBytes($info['size']);
|
|
|
|
|
|
|
|
|
|
|
3924 |
|
3925 |
+
echo json_encode($ret);
|
3926 |
+
}
|
3927 |
+
catch (Exception $error) {
|
3928 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
3929 |
+
error_log($message);
|
3930 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
3931 |
+
die();
|
3932 |
+
}
|
3933 |
die();
|
3934 |
}
|
3935 |
|
3950 |
public function clean_out_of_date_backup()
|
3951 |
{
|
3952 |
$this->ajax_check_security();
|
3953 |
+
try {
|
3954 |
+
$backup_ids = WPvivid_Backuplist::get_out_of_date_backuplist(WPvivid_Setting::get_max_backup_count());
|
3955 |
+
foreach ($backup_ids as $backup_id) {
|
3956 |
+
$this->delete_backup_by_id($backup_id);
|
3957 |
+
}
|
3958 |
+
$ret['result'] = 'success';
|
3959 |
+
$html = '';
|
3960 |
+
$html = apply_filters('wpvivid_add_backup_list', $html);
|
3961 |
+
$ret['html'] = $html;
|
3962 |
+
echo json_encode($ret);
|
3963 |
+
}
|
3964 |
+
catch (Exception $error) {
|
3965 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
3966 |
+
error_log($message);
|
3967 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
3968 |
+
die();
|
3969 |
}
|
|
|
|
|
|
|
|
|
|
|
3970 |
die();
|
3971 |
}
|
3972 |
|
4197 |
public function get_setting()
|
4198 |
{
|
4199 |
$this->ajax_check_security('manage_options');
|
4200 |
+
try {
|
4201 |
+
if (isset($_POST['all']) && is_bool($_POST['all'])) {
|
4202 |
+
$all = $_POST['all'];
|
4203 |
+
if (!$all) {
|
4204 |
+
if (isset($_POST['options_name']) && is_array($_POST['options_name'])) {
|
4205 |
+
$options_name = $_POST['options_name'];
|
4206 |
+
$ret = WPvivid_Setting::get_setting($all, $options_name);
|
4207 |
+
echo json_encode($ret);
|
4208 |
+
}
|
4209 |
+
} else {
|
4210 |
+
$options_name = array();
|
4211 |
+
$ret = WPvivid_Setting::get_setting($all, $options_name);
|
4212 |
echo json_encode($ret);
|
4213 |
}
|
4214 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
4215 |
}
|
4216 |
+
catch (Exception $error) {
|
4217 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
4218 |
+
error_log($message);
|
4219 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
4220 |
+
die();
|
4221 |
+
}
|
4222 |
die();
|
4223 |
}
|
4224 |
|
4225 |
public function update_setting()
|
4226 |
{
|
4227 |
$this->ajax_check_security('manage_options');
|
4228 |
+
try {
|
4229 |
+
if (isset($_POST['options']) && !empty($_POST['options']) && is_string($_POST['options'])) {
|
4230 |
+
$json = $_POST['options'];
|
4231 |
+
$json = stripslashes($json);
|
4232 |
+
$options = json_decode($json, true);
|
4233 |
+
if (is_null($options)) {
|
4234 |
+
die();
|
4235 |
+
}
|
4236 |
+
$ret = WPvivid_Setting::update_setting($options);
|
4237 |
+
echo json_encode($ret);
|
4238 |
}
|
|
|
|
|
4239 |
}
|
4240 |
+
catch (Exception $error) {
|
4241 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
4242 |
+
error_log($message);
|
4243 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
4244 |
+
die();
|
4245 |
+
}
|
4246 |
die();
|
4247 |
}
|
4248 |
|
4249 |
function set_default_remote_storage()
|
4250 |
{
|
4251 |
$this->ajax_check_security('manage_options');
|
4252 |
+
try {
|
4253 |
+
if (!isset($_POST['remote_storage']) || empty($_POST['remote_storage']) || !is_array($_POST['remote_storage'])) {
|
4254 |
+
$ret['result'] = WPVIVID_FAILED;
|
4255 |
+
$ret['error'] = __('Choose one storage from the list to be the default storage.', 'wpvivid');
|
4256 |
+
echo json_encode($ret);
|
4257 |
+
die();
|
4258 |
+
}
|
4259 |
+
$remote_storage = $_POST['remote_storage'];
|
4260 |
+
WPvivid_Setting::update_user_history('remote_selected', $remote_storage);
|
4261 |
+
$ret['result'] = 'success';
|
4262 |
+
$html = '';
|
4263 |
+
$html = apply_filters('wpvivid_add_remote_storage_list', $html);
|
4264 |
+
$ret['html'] = $html;
|
4265 |
+
$pic = '';
|
4266 |
+
$pic = apply_filters('wpvivid_schedule_add_remote_pic', $pic);
|
4267 |
+
$ret['pic'] = $pic;
|
4268 |
+
$dir = '';
|
4269 |
+
$dir = apply_filters('wpvivid_get_remote_directory', $dir);
|
4270 |
+
$ret['dir'] = $dir;
|
4271 |
+
$schedule_local_remote = '';
|
4272 |
+
$schedule_local_remote = apply_filters('wpvivid_schedule_local_remote', $schedule_local_remote);
|
4273 |
+
$ret['local_remote'] = $schedule_local_remote;
|
4274 |
+
$remote_storage = '';
|
4275 |
+
$remote_storage = apply_filters('wpvivid_remote_storage', $remote_storage);
|
4276 |
+
$ret['remote_storage'] = $remote_storage;
|
4277 |
echo json_encode($ret);
|
4278 |
+
}
|
4279 |
+
catch (Exception $error) {
|
4280 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
4281 |
+
error_log($message);
|
4282 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
4283 |
die();
|
4284 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4285 |
die();
|
4286 |
}
|
4287 |
|
4288 |
function get_default_remote_storage(){
|
4289 |
$this->ajax_check_security('manage_options');
|
4290 |
+
try {
|
4291 |
+
$ret['result'] = 'success';
|
4292 |
+
$ret['remote_storage'] = WPvivid_Setting::get_user_history('remote_selected');
|
4293 |
+
echo json_encode($ret);
|
4294 |
+
}
|
4295 |
+
catch (Exception $error) {
|
4296 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
4297 |
+
error_log($message);
|
4298 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
4299 |
+
die();
|
4300 |
+
}
|
4301 |
die();
|
4302 |
}
|
4303 |
|
4310 |
public function get_general_setting()
|
4311 |
{
|
4312 |
$this->ajax_check_security('manage_options');
|
4313 |
+
try {
|
4314 |
+
if (isset($_POST['all']) && is_bool($_POST['all'])) {
|
4315 |
+
$all = $_POST['all'];
|
4316 |
+
if (!$all) {
|
4317 |
+
if (isset($_POST['options_name']) && is_array($_POST['options_name'])) {
|
4318 |
+
$options_name = $_POST['options_name'];
|
4319 |
+
$ret['data']['setting'] = WPvivid_Setting::get_setting($all, $options_name);
|
4320 |
+
|
4321 |
+
$schedule = WPvivid_Schedule::get_schedule();
|
4322 |
+
$schedule['next_start'] = date("l, F d, Y H:i", $schedule['next_start']);
|
4323 |
+
$ret['result'] = 'success';
|
4324 |
+
$ret['data']['schedule'] = $schedule;
|
4325 |
+
$ret['user_history'] = WPvivid_Setting::get_user_history('remote_selected');
|
4326 |
+
echo json_encode($ret);
|
4327 |
+
}
|
4328 |
+
} else {
|
4329 |
+
$options_name = array();
|
4330 |
+
$ret['data']['setting'] = WPvivid_Setting::get_setting($all, $options_name);
|
4331 |
+
$schedule = WPvivid_Schedule::get_schedule();
|
4332 |
$schedule['next_start'] = date("l, F d, Y H:i", $schedule['next_start']);
|
4333 |
+
$ret['result'] = 'success';
|
4334 |
+
$ret['data']['schedule'] = $schedule;
|
4335 |
+
$ret['user_history'] = WPvivid_Setting::get_user_history('remote_selected');
|
4336 |
echo json_encode($ret);
|
4337 |
}
|
4338 |
}
|
4339 |
+
}
|
4340 |
+
catch (Exception $error) {
|
4341 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
4342 |
+
error_log($message);
|
4343 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
4344 |
+
die();
|
|
|
|
|
|
|
|
|
|
|
4345 |
}
|
4346 |
die();
|
4347 |
}
|
4365 |
$setting_data['wpvivid_compress_setting']['use_temp_file'] = $setting['use_temp_file'];
|
4366 |
$setting_data['wpvivid_compress_setting']['use_temp_size'] = $setting['use_temp_size'];
|
4367 |
$setting_data['wpvivid_compress_setting']['exclude_file_size'] = $setting['exclude_file_size'];
|
4368 |
+
$setting_data['wpvivid_compress_setting']['subpackage_plugin_upload'] = $setting['subpackage_plugin_upload'];
|
4369 |
|
4370 |
$setting_data['wpvivid_local_setting']['path'] = $setting['path'];
|
4371 |
$setting_data['wpvivid_local_setting']['save_local'] = $options['options']['wpvivid_local_setting']['save_local'];
|
4379 |
$setting_data['wpvivid_common_setting']['estimate_backup'] = $setting['estimate_backup'];
|
4380 |
$setting_data['wpvivid_common_setting']['max_resume_count'] = $setting['max_resume_count'];
|
4381 |
$setting_data['wpvivid_common_setting']['memory_limit'] = $setting['memory_limit'].'M';
|
4382 |
+
$setting_data['wpvivid_common_setting']['restore_memory_limit'] = $setting['restore_memory_limit'].'M';
|
4383 |
+
$setting_data['wpvivid_common_setting']['migrate_size'] = $setting['migrate_size'];
|
4384 |
+
|
4385 |
return $setting_data;
|
4386 |
}
|
4387 |
|
4479 |
|
4480 |
if(empty($data['max_file_size']) && $data['max_file_size'] != '0')
|
4481 |
{
|
4482 |
+
$ret['error']=__('The maximum zip file size is required.', 'wpvivid');
|
4483 |
return $ret;
|
4484 |
}
|
4485 |
|
4565 |
public function export_setting()
|
4566 |
{
|
4567 |
$this->ajax_check_security('manage_options');
|
4568 |
+
try {
|
4569 |
+
if (isset($_REQUEST['setting']) && !empty($_REQUEST['setting']) && isset($_REQUEST['history']) && !empty($_REQUEST['history'])) {
|
4570 |
+
$setting = sanitize_text_field($_REQUEST['setting']);
|
4571 |
+
$history = sanitize_text_field($_REQUEST['history']);
|
4572 |
+
$review = sanitize_text_field($_REQUEST['review']);
|
4573 |
|
4574 |
+
if ($setting == '1') {
|
4575 |
+
$setting = true;
|
4576 |
+
} else {
|
4577 |
+
$setting = false;
|
4578 |
+
}
|
4579 |
|
4580 |
+
if ($history == '1') {
|
4581 |
+
$history = true;
|
4582 |
+
} else {
|
4583 |
+
$history = false;
|
4584 |
+
}
|
|
|
|
|
|
|
4585 |
|
4586 |
+
if ($review == '1') {
|
4587 |
+
$review = true;
|
4588 |
+
} else {
|
4589 |
+
$review = false;
|
4590 |
+
}
|
|
|
|
|
|
|
4591 |
|
4592 |
+
$json = WPvivid_Setting::export_setting_to_json($setting, $history, $review);
|
4593 |
+
if (!headers_sent()) {
|
4594 |
+
header('Content-Disposition: attachment; filename=wpvivid_setting.json');
|
4595 |
+
//header('Content-type: application/json');
|
4596 |
+
header('Content-Type: application/force-download');
|
4597 |
+
header('Content-Description: File Transfer');
|
4598 |
+
header('Cache-Control: must-revalidate');
|
4599 |
+
header('Content-Transfer-Encoding: binary');
|
4600 |
+
}
|
4601 |
|
4602 |
+
echo json_encode($json);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4603 |
}
|
4604 |
+
}
|
4605 |
+
catch (Exception $error) {
|
4606 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
4607 |
+
error_log($message);
|
4608 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
4609 |
+
die();
|
4610 |
}
|
4611 |
exit;
|
4612 |
}
|
4614 |
public function import_setting()
|
4615 |
{
|
4616 |
$this->ajax_check_security('manage_options');
|
4617 |
+
try {
|
4618 |
+
if (isset($_POST['data']) && !empty($_POST['data']) && is_string($_POST['data'])) {
|
4619 |
+
$data = $_POST['data'];
|
4620 |
+
$data = stripslashes($data);
|
4621 |
+
$json = json_decode($data, true);
|
4622 |
+
if (is_null($json)) {
|
4623 |
+
die();
|
4624 |
+
}
|
4625 |
+
if (json_last_error() === JSON_ERROR_NONE && is_array($json) && array_key_exists('plugin', $json) && $json['plugin'] == 'WPvivid') {
|
4626 |
+
WPvivid_Setting::import_json_to_setting($json);
|
4627 |
+
WPvivid_Schedule::reset_schedule();
|
4628 |
+
$ret['result'] = 'success';
|
4629 |
+
echo json_encode($ret);
|
4630 |
+
} else {
|
4631 |
+
$ret['result'] = 'failed';
|
4632 |
+
$ret['error'] = __('The selected file is not the setting file for WPvivid. Please upload the right file.', 'wpvivid');
|
4633 |
+
echo json_encode($ret);
|
4634 |
+
}
|
|
|
|
|
|
|
4635 |
}
|
4636 |
}
|
4637 |
+
catch (Exception $error) {
|
4638 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
4639 |
+
error_log($message);
|
4640 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
4641 |
+
die();
|
4642 |
+
}
|
4643 |
die();
|
4644 |
}
|
4645 |
|
4646 |
public function test_send_mail()
|
4647 |
{
|
4648 |
$this->ajax_check_security();
|
4649 |
+
try {
|
4650 |
+
if (isset($_POST['send_to']) && !empty($_POST['send_to']) && is_string($_POST['send_to'])) {
|
4651 |
+
$send_to = sanitize_email($_POST['send_to']);
|
4652 |
+
if (empty($send_to)) {
|
4653 |
+
$ret['result'] = 'failed';
|
4654 |
+
$ret['error'] = __('Invalid email address', 'wpvivid');
|
4655 |
+
echo json_encode($ret);
|
4656 |
+
} else {
|
4657 |
+
$subject = 'WPvivid Test Mail';
|
4658 |
+
$body = 'This is a test mail from WPvivid backup plugin';
|
4659 |
+
$headers = array('Content-Type: text/html; charset=UTF-8');
|
4660 |
+
if (wp_mail($send_to, $subject, $body, $headers) === false) {
|
4661 |
+
$ret['result'] = 'failed';
|
4662 |
+
$ret['error'] = __('Unable to send email. Please check the configuration of email server.', 'wpvivid');
|
4663 |
+
} else {
|
4664 |
+
$ret['result'] = 'success';
|
4665 |
+
}
|
4666 |
+
echo json_encode($ret);
|
|
|
|
|
|
|
|
|
4667 |
}
|
|
|
4668 |
}
|
4669 |
}
|
4670 |
+
catch (Exception $error) {
|
4671 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
4672 |
+
error_log($message);
|
4673 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
4674 |
+
die();
|
4675 |
+
}
|
4676 |
die();
|
4677 |
}
|
4678 |
|
4679 |
public function create_debug_package()
|
4680 |
{
|
4681 |
$this->ajax_check_security();
|
4682 |
+
try {
|
4683 |
+
$files = WPvivid_error_log::get_error_log();
|
4684 |
|
4685 |
+
if (!class_exists('PclZip'))
|
4686 |
+
include_once(ABSPATH . '/wp-admin/includes/class-pclzip.php');
|
4687 |
|
4688 |
+
$backup_path = WPvivid_Setting::get_backupdir();
|
4689 |
+
$path = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $backup_path . DIRECTORY_SEPARATOR . 'wpvivid_debug.zip';
|
4690 |
|
4691 |
+
if (file_exists($path)) {
|
4692 |
+
@unlink($path);
|
4693 |
+
}
|
4694 |
+
$archive = new PclZip($path);
|
4695 |
|
4696 |
+
if (!empty($files)) {
|
4697 |
+
if (!$archive->add($files, PCLZIP_OPT_REMOVE_ALL_PATH)) {
|
4698 |
+
echo __($archive->errorInfo(true) . ' <a href="' . admin_url() . 'admin.php?page=WPvivid">retry</a>.');
|
4699 |
+
exit;
|
4700 |
+
}
|
4701 |
+
}
|
4702 |
|
4703 |
+
$server_info = json_encode($this->get_website_info());
|
4704 |
+
$server_file_path = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $backup_path . DIRECTORY_SEPARATOR . 'wpvivid_server_info.json';
|
4705 |
+
if (file_exists($server_file_path)) {
|
4706 |
+
@unlink($server_file_path);
|
4707 |
+
}
|
4708 |
+
$server_file = fopen($server_file_path, 'x');
|
4709 |
+
fclose($server_file);
|
4710 |
+
file_put_contents($server_file_path, $server_info);
|
4711 |
+
if (!$archive->add($server_file_path, PCLZIP_OPT_REMOVE_ALL_PATH)) {
|
4712 |
+
echo __($archive->errorInfo(true) . ' <a href="' . admin_url() . 'admin.php?page=WPvivid">retry</a>.');
|
4713 |
exit;
|
4714 |
}
|
4715 |
+
@unlink($server_file_path);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4716 |
|
4717 |
+
if (session_id())
|
4718 |
+
session_write_close();
|
4719 |
|
4720 |
+
$size = filesize($path);
|
4721 |
+
if (!headers_sent()) {
|
4722 |
+
header('Content-Description: File Transfer');
|
4723 |
+
header('Content-Type: application/zip');
|
4724 |
+
header('Content-Disposition: attachment; filename="' . basename($path) . '"');
|
4725 |
+
header('Cache-Control: must-revalidate');
|
4726 |
+
header('Content-Length: ' . $size);
|
4727 |
+
header('Content-Transfer-Encoding: binary');
|
4728 |
+
}
|
|
|
4729 |
|
4730 |
|
4731 |
+
ob_end_clean();
|
4732 |
+
readfile($path);
|
4733 |
+
@unlink($path);
|
4734 |
+
}
|
4735 |
+
catch (Exception $error) {
|
4736 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
4737 |
+
error_log($message);
|
4738 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
4739 |
+
die();
|
4740 |
+
}
|
4741 |
exit;
|
4742 |
}
|
4743 |
|
4749 |
public function get_log_list()
|
4750 |
{
|
4751 |
$this->ajax_check_security();
|
4752 |
+
try {
|
4753 |
+
$ret['result'] = 'success';
|
4754 |
+
$html = '';
|
4755 |
+
$html = apply_filters('wpvivid_get_log_list', $html);
|
4756 |
+
$ret['html'] = $html['html'];
|
4757 |
+
$ret['log_count'] = $html['log_count'];
|
4758 |
+
echo json_encode($ret);
|
4759 |
+
}
|
4760 |
+
catch (Exception $error) {
|
4761 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
4762 |
+
error_log($message);
|
4763 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
4764 |
+
die();
|
4765 |
+
}
|
4766 |
die();
|
4767 |
}
|
4768 |
|
4894 |
public function view_log()
|
4895 |
{
|
4896 |
$this->ajax_check_security();
|
4897 |
+
try {
|
4898 |
+
if (isset($_POST['path']) && !empty($_POST['path']) && is_string($_POST['path'])) {
|
4899 |
+
$path = sanitize_text_field($_POST['path']);
|
4900 |
+
if (!file_exists($path)) {
|
4901 |
+
$json['result'] = 'failed';
|
4902 |
+
$json['error'] = __('The log not found.', 'wpvivid');
|
4903 |
+
echo json_encode($json);
|
4904 |
+
die();
|
4905 |
+
}
|
4906 |
|
4907 |
+
$file = fopen($path, 'r');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4908 |
|
4909 |
+
if (!$file) {
|
4910 |
+
$json['result'] = 'failed';
|
4911 |
+
$json['error'] = __('Unable to open the log file.', 'wpvivid');
|
4912 |
+
echo json_encode($json);
|
4913 |
+
die();
|
4914 |
+
}
|
4915 |
|
4916 |
+
$buffer = '';
|
4917 |
+
while (!feof($file)) {
|
4918 |
+
$buffer .= fread($file, 1024);
|
4919 |
+
}
|
4920 |
+
fclose($file);
|
|
|
|
|
4921 |
|
4922 |
+
$json['result'] = 'success';
|
4923 |
+
$json['data'] = $buffer;
|
4924 |
+
echo json_encode($json);
|
4925 |
+
} else {
|
4926 |
+
$json['result'] = 'failed';
|
4927 |
+
$json['error'] = __('Reading the log failed. Please try again.', 'wpvivid');
|
4928 |
+
echo json_encode($json);
|
4929 |
}
|
|
|
|
|
|
|
|
|
|
|
4930 |
}
|
4931 |
+
catch (Exception $error) {
|
4932 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
4933 |
+
error_log($message);
|
4934 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
4935 |
+
die();
|
4936 |
}
|
4937 |
die();
|
4938 |
}
|
5055 |
|
5056 |
if( $ret['data']['pdo_mysql']=='support')
|
5057 |
{
|
5058 |
+
$db_method=new WPvivid_DB_Method();
|
5059 |
+
$ret_sql_mode=$db_method->get_sql_mode();
|
5060 |
+
if($ret_sql_mode['result']==WPVIVID_FAILED)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5061 |
{
|
5062 |
+
$ret['data']['mysql_mode']='';
|
5063 |
+
}
|
5064 |
+
else
|
5065 |
+
{
|
5066 |
+
$ret['data']['mysql_mode']=$ret_sql_mode['mysql_mode'];
|
5067 |
+
$ret['mysql_mode']=$ret_sql_mode['mysql_mode'];
|
|
|
|
|
|
|
|
|
|
|
5068 |
}
|
5069 |
}
|
5070 |
else {
|
5460 |
public function need_review()
|
5461 |
{
|
5462 |
$this->ajax_check_security();
|
5463 |
+
try {
|
5464 |
+
if (isset($_POST['review']) && !empty($_POST['review']) && is_string($_POST['review'])) {
|
5465 |
+
$review = $_POST['review'];
|
5466 |
+
if ($review == 'rate-now') {
|
5467 |
+
$review_option = 'do_not_ask';
|
5468 |
+
echo 'https://wordpress.org/support/plugin/wpvivid-backuprestore/reviews/?filter=5';
|
5469 |
+
} elseif ($review == 'never-ask') {
|
5470 |
+
$review_option = 'do_not_ask';
|
5471 |
+
echo '';
|
5472 |
+
} elseif ($review == 'ask-later') {
|
5473 |
+
$review_option = 'not';
|
5474 |
+
WPvivid_Setting::update_option('cron_backup_count', 0);
|
5475 |
+
echo '';
|
5476 |
+
} else {
|
5477 |
+
$review_option = 'not';
|
5478 |
+
echo '';
|
5479 |
+
}
|
5480 |
+
WPvivid_Setting::update_option('wpvivid_need_review', $review_option);
|
|
|
|
|
5481 |
}
|
5482 |
+
}
|
5483 |
+
catch (Exception $error) {
|
5484 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
5485 |
+
error_log($message);
|
5486 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
5487 |
+
die();
|
5488 |
}
|
5489 |
die();
|
5490 |
}
|
5491 |
|
5492 |
public function wpvivid_send_debug_info(){
|
5493 |
$this->ajax_check_security();
|
5494 |
+
try {
|
5495 |
+
if (!isset($_POST['user_mail']) || empty($_POST['user_mail'])) {
|
|
|
|
|
|
|
|
|
|
|
|
|
5496 |
$ret['result'] = 'failed';
|
5497 |
+
$ret['error'] = __('User\'s email address is required.', 'wpvivid');
|
5498 |
} else {
|
5499 |
+
$pattern = '/^[a-z0-9]+([._-][a-z0-9]+)*@([0-9a-z]+\.[a-z]{2,14}(\.[a-z]{2})?)$/i';
|
5500 |
+
if (!preg_match($pattern, $_POST['user_mail'])) {
|
5501 |
+
$ret['result'] = 'failed';
|
5502 |
+
$ret['error'] = __('Please enter a valid email address.', 'wpvivid');
|
5503 |
+
} else {
|
5504 |
+
$this->ajax_check_security();
|
5505 |
+
$ret = WPvivid_mail_report::wpvivid_send_debug_info($_POST['user_mail']);
|
5506 |
+
}
|
5507 |
}
|
5508 |
+
echo json_encode($ret);
|
5509 |
+
}
|
5510 |
+
catch (Exception $error) {
|
5511 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
5512 |
+
error_log($message);
|
5513 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
5514 |
+
die();
|
5515 |
}
|
|
|
5516 |
die();
|
5517 |
}
|
5518 |
|
5519 |
public function get_ini_memory_limit(){
|
5520 |
$this->ajax_check_security();
|
5521 |
+
try {
|
5522 |
+
$memory_limit = @ini_get('memory_limit');
|
5523 |
+
echo $memory_limit;
|
5524 |
+
}
|
5525 |
+
catch (Exception $error) {
|
5526 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
5527 |
+
error_log($message);
|
5528 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
5529 |
+
die();
|
5530 |
+
}
|
5531 |
die();
|
5532 |
}
|
5533 |
}
|
includes/customclass/class-wpvivid-amazons3-plus.php
CHANGED
@@ -2,10 +2,10 @@
|
|
2 |
if (!defined('WPVIVID_PLUGIN_DIR')){
|
3 |
die;
|
4 |
}
|
5 |
-
|
6 |
-
define('WPVIVID_REMOTE_AMAZONS3','amazons3');
|
7 |
-
|
8 |
-
define('WPVIVID_AMAZONS3_DEFAULT_FOLDER','/wpvivid_backup');
|
9 |
|
10 |
require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-remote.php';
|
11 |
require_once 'class-wpvivid-base-s3.php';
|
2 |
if (!defined('WPVIVID_PLUGIN_DIR')){
|
3 |
die;
|
4 |
}
|
5 |
+
if(!defined('WPVIVID_REMOTE_AMAZONS3'))
|
6 |
+
define('WPVIVID_REMOTE_AMAZONS3','amazons3');
|
7 |
+
if(!defined('WPVIVID_AMAZONS3_DEFAULT_FOLDER'))
|
8 |
+
define('WPVIVID_AMAZONS3_DEFAULT_FOLDER','/wpvivid_backup');
|
9 |
|
10 |
require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-remote.php';
|
11 |
require_once 'class-wpvivid-base-s3.php';
|
includes/customclass/class-wpvivid-dropbox.php
CHANGED
@@ -6,7 +6,8 @@ if (!defined('WPVIVID_PLUGIN_DIR')){
|
|
6 |
if(!defined('WPVIVID_REMOTE_DROPBOX')){
|
7 |
define('WPVIVID_REMOTE_DROPBOX','dropbox');
|
8 |
}
|
9 |
-
|
|
|
10 |
require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-base-dropbox.php';
|
11 |
require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-remote.php';
|
12 |
class WPvivid_Dropbox extends WPvivid_Remote {
|
@@ -295,7 +296,7 @@ class WPvivid_Dropbox extends WPvivid_Remote {
|
|
295 |
$remote_options['token'] = $_POST['code'];
|
296 |
$remote_options['name'] = $_GET['name'];
|
297 |
$remote_options['path'] = WPVIVID_DROPBOX_DEFAULT_FOLDER;
|
298 |
-
$remote_options['default'] = $_GET['
|
299 |
$ret = $wpvivid_pulgin->remote_collection->add_remote($remote_options);
|
300 |
if ($ret['result'] == 'success') {
|
301 |
header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_dropbox_drive&result=success');
|
6 |
if(!defined('WPVIVID_REMOTE_DROPBOX')){
|
7 |
define('WPVIVID_REMOTE_DROPBOX','dropbox');
|
8 |
}
|
9 |
+
if(!defined('WPVIVID_DROPBOX_DEFAULT_FOLDER'))
|
10 |
+
define('WPVIVID_DROPBOX_DEFAULT_FOLDER','/');
|
11 |
require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-base-dropbox.php';
|
12 |
require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-remote.php';
|
13 |
class WPvivid_Dropbox extends WPvivid_Remote {
|
296 |
$remote_options['token'] = $_POST['code'];
|
297 |
$remote_options['name'] = $_GET['name'];
|
298 |
$remote_options['path'] = WPVIVID_DROPBOX_DEFAULT_FOLDER;
|
299 |
+
$remote_options['default'] = $_GET['bdefault'];
|
300 |
$ret = $wpvivid_pulgin->remote_collection->add_remote($remote_options);
|
301 |
if ($ret['result'] == 'success') {
|
302 |
header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_dropbox_drive&result=success');
|
includes/customclass/class-wpvivid-google-drive.php
CHANGED
@@ -6,11 +6,16 @@ if (!defined('WPVIVID_PLUGIN_DIR')){
|
|
6 |
|
7 |
require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-remote.php';
|
8 |
|
9 |
-
|
10 |
-
define('
|
11 |
-
|
12 |
-
define('
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
14 |
class Wpvivid_Google_drive extends WPvivid_Remote
|
15 |
{
|
16 |
public $options;
|
6 |
|
7 |
require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-remote.php';
|
8 |
|
9 |
+
if(!defined('WPVIVID_REMOTE_GOOGLEDRIVE'))
|
10 |
+
define('WPVIVID_REMOTE_GOOGLEDRIVE','googledrive');
|
11 |
+
if(!defined('WPVIVID_GOOGLEDRIVE_DEFAULT_FOLDER'))
|
12 |
+
define('WPVIVID_GOOGLEDRIVE_DEFAULT_FOLDER','wpvivid_backup');
|
13 |
+
if(!defined('WPVIVID_GOOGLEDRIVE_SECRETS'))
|
14 |
+
define('WPVIVID_GOOGLEDRIVE_SECRETS',WPVIVID_PLUGIN_DIR.'/includes/customclass/client_secrets.json');
|
15 |
+
if(!defined('WPVIVID_GOOGLEDRIVE_UPLOAD_SIZE'))
|
16 |
+
define('WPVIVID_GOOGLEDRIVE_UPLOAD_SIZE',1024*1024*2);
|
17 |
+
if(!defined('WPVIVID_GOOGLE_NEED_PHP_VERSION'))
|
18 |
+
define('WPVIVID_GOOGLE_NEED_PHP_VERSION','5.5');
|
19 |
class Wpvivid_Google_drive extends WPvivid_Remote
|
20 |
{
|
21 |
public $options;
|
includes/customclass/class-wpvivid-one-drive.php
CHANGED
@@ -12,11 +12,30 @@ if (!defined('WPVIVID_PLUGIN_DIR')){
|
|
12 |
|
13 |
require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-remote.php';
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
define('
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
class WPvivid_one_drive extends WPvivid_Remote
|
22 |
{
|
12 |
|
13 |
require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-remote.php';
|
14 |
|
15 |
+
if(!defined('WPVIVID_REMOTE_ONEDRIVE'))
|
16 |
+
{
|
17 |
+
define('WPVIVID_REMOTE_ONEDRIVE','onedrive');
|
18 |
+
}
|
19 |
+
|
20 |
+
if(!defined('WPVIVID_ONEDRIVE_DEFAULT_FOLDER'))
|
21 |
+
{
|
22 |
+
define('WPVIVID_ONEDRIVE_DEFAULT_FOLDER','wpvivid_backup');
|
23 |
+
}
|
24 |
+
|
25 |
+
if(!defined('WPVIVID_ONEDRIVE_UPLOAD_SIZE'))
|
26 |
+
{
|
27 |
+
define('WPVIVID_ONEDRIVE_UPLOAD_SIZE',1024*1024*2);
|
28 |
+
}
|
29 |
+
|
30 |
+
if(!defined('WPVIVID_ONEDRIVE_DOWNLOAD_SIZE'))
|
31 |
+
{
|
32 |
+
define('WPVIVID_ONEDRIVE_DOWNLOAD_SIZE',1024*1024*2);
|
33 |
+
}
|
34 |
+
|
35 |
+
if(!defined('WPVIVID_ONEDRIVE_RETRY_TIMES'))
|
36 |
+
{
|
37 |
+
define('WPVIVID_ONEDRIVE_RETRY_TIMES','3');
|
38 |
+
}
|
39 |
|
40 |
class WPvivid_one_drive extends WPvivid_Remote
|
41 |
{
|
includes/customclass/class-wpvivid-s3compat.php
CHANGED
@@ -5,8 +5,10 @@ if (!defined('WPVIVID_PLUGIN_DIR')){
|
|
5 |
if(!defined('WPVIVID_REMOTE_S3COMPAT')){
|
6 |
define('WPVIVID_REMOTE_S3COMPAT','s3compat');
|
7 |
}
|
8 |
-
|
9 |
-
define('
|
|
|
|
|
10 |
require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-remote.php';
|
11 |
use Aws\S3\S3Client;
|
12 |
use Aws\S3\Exception\S3Exception;
|
5 |
if(!defined('WPVIVID_REMOTE_S3COMPAT')){
|
6 |
define('WPVIVID_REMOTE_S3COMPAT','s3compat');
|
7 |
}
|
8 |
+
if(!defined('WPVIVID_S3COMPAT_DEFAULT_FOLDER'))
|
9 |
+
define('WPVIVID_S3COMPAT_DEFAULT_FOLDER','/wpvivid_backup');
|
10 |
+
if(!defined('WPVIVID_S3COMPAT_NEED_PHP_VERSION'))
|
11 |
+
define('WPVIVID_S3COMPAT_NEED_PHP_VERSION','5.3.9');
|
12 |
require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-remote.php';
|
13 |
use Aws\S3\S3Client;
|
14 |
use Aws\S3\Exception\S3Exception;
|
includes/customclass/class-wpvivid-send-to-site.php
CHANGED
@@ -5,10 +5,12 @@ if (!defined('WPVIVID_PLUGIN_DIR'))
|
|
5 |
die;
|
6 |
}
|
7 |
|
8 |
-
|
|
|
9 |
require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-remote.php';
|
10 |
|
11 |
-
|
|
|
12 |
|
13 |
class WPvivid_Send_to_site extends WPvivid_Remote
|
14 |
{
|
@@ -128,8 +130,9 @@ class WPvivid_Send_to_site extends WPvivid_Remote
|
|
128 |
return $result;
|
129 |
}
|
130 |
}
|
131 |
-
$this->upload_finish($task_id);
|
132 |
-
return
|
|
|
133 |
}
|
134 |
|
135 |
public function _upload($task_id, $file,$callback)
|
@@ -179,7 +182,14 @@ class WPvivid_Send_to_site extends WPvivid_Remote
|
|
179 |
$retry_count=0;
|
180 |
while (!feof($handle))
|
181 |
{
|
182 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
if($ret['result']==WPVIVID_SUCCESS)
|
184 |
{
|
185 |
$status = WPvivid_taskmanager::get_backup_task_status($task_id);
|
@@ -282,7 +292,7 @@ class WPvivid_Send_to_site extends WPvivid_Remote
|
|
282 |
else
|
283 |
{
|
284 |
$ret['result']=WPVIVID_FAILED;
|
285 |
-
$ret['error']= '
|
286 |
}
|
287 |
}
|
288 |
else
|
@@ -335,7 +345,7 @@ class WPvivid_Send_to_site extends WPvivid_Remote
|
|
335 |
|
336 |
$response=wp_remote_post($this->options['url'],$args);
|
337 |
|
338 |
-
$wpvivid_pulgin->wpvivid_log->WriteLog('finished
|
339 |
|
340 |
if ( is_wp_error( $response ) )
|
341 |
{
|
@@ -346,16 +356,35 @@ class WPvivid_Send_to_site extends WPvivid_Remote
|
|
346 |
{
|
347 |
if($response['response']['code']==200)
|
348 |
{
|
349 |
-
$offset=$offset+$upload_size;
|
350 |
-
$ret['result']=WPVIVID_SUCCESS;
|
351 |
$res=json_decode($response['body'],1);
|
352 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
353 |
}
|
354 |
else
|
355 |
{
|
356 |
$ret['result']=WPVIVID_FAILED;
|
357 |
$ret['http_code']=$response['response']['code'];
|
358 |
-
$ret['error']=
|
359 |
}
|
360 |
}
|
361 |
return $ret;
|
@@ -379,7 +408,6 @@ class WPvivid_Send_to_site extends WPvivid_Remote
|
|
379 |
$args['body']=array('wpvivid_content'=>$data,'wpvivid_action'=>'send_to_site_finish');
|
380 |
$args['timeout']=30;
|
381 |
$response=wp_remote_post($this->options['url'],$args);
|
382 |
-
|
383 |
if ( is_wp_error( $response ) )
|
384 |
{
|
385 |
$ret['result']=WPVIVID_FAILED;
|
@@ -389,7 +417,24 @@ class WPvivid_Send_to_site extends WPvivid_Remote
|
|
389 |
{
|
390 |
if($response['response']['code']==200)
|
391 |
{
|
392 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
393 |
}
|
394 |
else
|
395 |
{
|
@@ -404,72 +449,66 @@ class WPvivid_Send_to_site extends WPvivid_Remote
|
|
404 |
public function send_to_site_connect()
|
405 |
{
|
406 |
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-crypt.php';
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
die();
|
418 |
-
}
|
419 |
-
|
420 |
-
$crypt=new WPvivid_crypt(base64_decode($option['private_key']));
|
421 |
-
$body=base64_decode($_POST['wpvivid_content']);
|
422 |
-
$data=$crypt->decrypt_message($body);
|
423 |
-
if (!is_string($data))
|
424 |
-
{
|
425 |
-
$ret['result']=WPVIVID_FAILED;
|
426 |
-
$ret['error']='The key is invalid.';
|
427 |
-
echo json_encode($ret);
|
428 |
-
die();
|
429 |
-
}
|
430 |
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
$
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
|
|
439 |
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
$ret['result']=WPVIVID_FAILED;
|
445 |
-
$ret['error']='The uploading backup already exists in Backups list.';
|
446 |
echo json_encode($ret);
|
|
|
447 |
}
|
448 |
-
else
|
449 |
-
{
|
450 |
-
global $wpvivid_pulgin;
|
451 |
-
$wpvivid_pulgin->wpvivid_log=new WPvivid_Log();
|
452 |
-
if(!file_exists($wpvivid_pulgin->wpvivid_log->GetSaveLogFolder().$params['backup_id'].'_backup_log.txt'))
|
453 |
-
{
|
454 |
-
$wpvivid_pulgin->wpvivid_log->CreateLogFile($params['backup_id'].'_backup','no_folder','transfer');
|
455 |
-
$wpvivid_pulgin->wpvivid_log->WriteLogHander();
|
456 |
-
}
|
457 |
-
else
|
458 |
-
{
|
459 |
-
$wpvivid_pulgin->wpvivid_log->OpenLogFile($params['backup_id'].'_backup','no_folder');
|
460 |
-
}
|
461 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
462 |
|
463 |
-
|
464 |
-
|
|
|
|
|
|
|
|
|
|
|
465 |
echo json_encode($ret);
|
466 |
}
|
467 |
}
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
|
|
473 |
}
|
474 |
die();
|
475 |
}
|
@@ -477,156 +516,173 @@ class WPvivid_Send_to_site extends WPvivid_Remote
|
|
477 |
public function send_to_site()
|
478 |
{
|
479 |
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-crypt.php';
|
480 |
-
|
|
|
|
|
|
|
481 |
{
|
482 |
-
|
483 |
-
$wpvivid_pulgin->wpvivid_log=new WPvivid_Log();
|
484 |
-
|
485 |
-
$default=array();
|
486 |
-
$option=get_option('wpvivid_api_token',$default);
|
487 |
-
if(empty($option))
|
488 |
{
|
489 |
-
|
490 |
-
|
491 |
-
if($option['expires'] !=0 && $option['expires']<time())
|
492 |
-
{
|
493 |
-
die();
|
494 |
-
}
|
495 |
-
$crypt=new WPvivid_crypt(base64_decode($option['private_key']));
|
496 |
-
$body=base64_decode($_POST['wpvivid_content']);
|
497 |
-
$data=$crypt->decrypt_message($body);
|
498 |
-
if (!is_string($data))
|
499 |
-
{
|
500 |
-
$ret['result']=WPVIVID_FAILED;
|
501 |
-
$ret['error']='The key is invalid.';
|
502 |
-
echo json_encode($ret);
|
503 |
-
die();
|
504 |
-
}
|
505 |
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
514 |
|
515 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
516 |
|
517 |
-
|
|
|
|
|
518 |
|
519 |
-
|
520 |
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
{
|
532 |
-
if(fseek($handle, $offset)===-1)
|
533 |
{
|
534 |
-
|
|
|
|
|
|
|
535 |
}
|
536 |
-
}
|
537 |
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
|
547 |
-
|
548 |
|
549 |
|
550 |
-
|
551 |
-
{
|
552 |
-
if (md5_file($file_path) == $params['md5'])
|
553 |
{
|
554 |
-
$
|
555 |
-
|
|
|
|
|
556 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
557 |
$ret['result']=WPVIVID_SUCCESS;
|
558 |
-
$ret['op']='
|
559 |
-
|
560 |
-
$wpvivid_pulgin->wpvivid_log->WriteLog('file md5 not match','notice');
|
561 |
-
$ret['result']=WPVIVID_FAILED;
|
562 |
-
$ret['error']='File md5 is not matched.';
|
563 |
}
|
564 |
-
}
|
565 |
-
else
|
566 |
-
{
|
567 |
-
$wpvivid_pulgin->wpvivid_log->WriteLog('continue size:'.filesize($file_path).' size1:'.$params['file_size'],'notice');
|
568 |
-
$ret['result']=WPVIVID_SUCCESS;
|
569 |
-
$ret['op']='continue';
|
570 |
-
//
|
571 |
-
}
|
572 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
573 |
echo json_encode($ret);
|
|
|
574 |
}
|
|
|
575 |
die();
|
576 |
}
|
577 |
|
578 |
public function send_to_site_finish()
|
579 |
{
|
580 |
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-crypt.php';
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
die();
|
592 |
-
}
|
593 |
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
}
|
604 |
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
}
|
613 |
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
618 |
|
619 |
-
|
620 |
-
|
621 |
-
$params['backup']['type']='Migration';
|
622 |
-
$list = WPvivid_Setting::get_option('wpvivid_backup_list');
|
623 |
-
$list[$params['backup_id']]=$params['backup'];
|
624 |
-
$list[$params['backup_id']]['log']=$wpvivid_pulgin->wpvivid_log->log_file;
|
625 |
-
WPvivid_Setting::update_option('wpvivid_backup_list',$list);
|
626 |
}
|
627 |
-
|
628 |
-
|
|
|
|
|
629 |
echo json_encode($ret);
|
|
|
630 |
}
|
631 |
die();
|
632 |
}
|
@@ -658,7 +714,6 @@ class WPvivid_Send_to_site extends WPvivid_Remote
|
|
658 |
$args['body']=array('wpvivid_content'=>$data,'wpvivid_action'=>'send_to_site_file_status');
|
659 |
$args['timeout']=30;
|
660 |
$response=wp_remote_post($this->options['url'],$args);
|
661 |
-
|
662 |
if ( is_wp_error( $response ) )
|
663 |
{
|
664 |
$ret['result']=WPVIVID_FAILED;
|
@@ -687,7 +742,7 @@ class WPvivid_Send_to_site extends WPvivid_Remote
|
|
687 |
else
|
688 |
{
|
689 |
$ret['result']=WPVIVID_FAILED;
|
690 |
-
$ret['error']= '
|
691 |
}
|
692 |
}
|
693 |
else
|
@@ -702,78 +757,75 @@ class WPvivid_Send_to_site extends WPvivid_Remote
|
|
702 |
public function send_to_site_file_status()
|
703 |
{
|
704 |
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-crypt.php';
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
die();
|
716 |
-
}
|
717 |
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
}
|
728 |
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
}
|
737 |
|
738 |
-
|
739 |
-
|
740 |
|
741 |
-
|
742 |
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
die();
|
755 |
-
}
|
756 |
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
|
|
|
|
765 |
} else {
|
766 |
-
$ret['result']=
|
767 |
-
$ret['
|
|
|
768 |
}
|
|
|
769 |
}
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
$ret['file_status']['offset']=filesize($file_path);
|
775 |
-
}
|
776 |
echo json_encode($ret);
|
|
|
777 |
}
|
778 |
die();
|
779 |
}
|
5 |
die;
|
6 |
}
|
7 |
|
8 |
+
if(!defined('WPVIVID_REMOTE_SEND_TO_SITE'))
|
9 |
+
define('WPVIVID_REMOTE_SEND_TO_SITE','send_to_site');
|
10 |
require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-remote.php';
|
11 |
|
12 |
+
if(!defined('WPVIVID_SEND_TO_SITE_UPLOAD_SIZE'))
|
13 |
+
define('WPVIVID_SEND_TO_SITE_UPLOAD_SIZE', 2);
|
14 |
|
15 |
class WPvivid_Send_to_site extends WPvivid_Remote
|
16 |
{
|
130 |
return $result;
|
131 |
}
|
132 |
}
|
133 |
+
$result=$this->upload_finish($task_id);
|
134 |
+
return $result;
|
135 |
+
//return array('result' =>WPVIVID_SUCCESS);
|
136 |
}
|
137 |
|
138 |
public function _upload($task_id, $file,$callback)
|
182 |
$retry_count=0;
|
183 |
while (!feof($handle))
|
184 |
{
|
185 |
+
$general_setting=WPvivid_Setting::get_setting(true, "");
|
186 |
+
if(!isset($general_setting['options']['wpvivid_common_setting']['migrate_size']) || empty($general_setting['options']['wpvivid_common_setting']['migrate_size'])){
|
187 |
+
$general_setting['options']['wpvivid_common_setting']['migrate_size']=WPVIVID_SEND_TO_SITE_UPLOAD_SIZE;
|
188 |
+
}
|
189 |
+
$upload_size = $general_setting['options']['wpvivid_common_setting']['migrate_size'];
|
190 |
+
$upload_size = intval($upload_size) * 1024;
|
191 |
+
|
192 |
+
$ret=$this->send_chunk($task_id,$handle,basename($file),$offset,$upload_size,$file_size,$md5);
|
193 |
if($ret['result']==WPVIVID_SUCCESS)
|
194 |
{
|
195 |
$status = WPvivid_taskmanager::get_backup_task_status($task_id);
|
292 |
else
|
293 |
{
|
294 |
$ret['result']=WPVIVID_FAILED;
|
295 |
+
$ret['error']= 'Failed to parse returned data, unable to establish connection with the target site.';
|
296 |
}
|
297 |
}
|
298 |
else
|
345 |
|
346 |
$response=wp_remote_post($this->options['url'],$args);
|
347 |
|
348 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog('finished send chunk','notice');
|
349 |
|
350 |
if ( is_wp_error( $response ) )
|
351 |
{
|
356 |
{
|
357 |
if($response['response']['code']==200)
|
358 |
{
|
|
|
|
|
359 |
$res=json_decode($response['body'],1);
|
360 |
+
if($res!=null)
|
361 |
+
{
|
362 |
+
if($res['result']==WPVIVID_SUCCESS)
|
363 |
+
{
|
364 |
+
$offset=$offset+$upload_size;
|
365 |
+
$ret['result']=WPVIVID_SUCCESS;
|
366 |
+
$ret['op']=$res['op'];
|
367 |
+
}
|
368 |
+
else
|
369 |
+
{
|
370 |
+
$ret['result']=WPVIVID_FAILED;
|
371 |
+
$ret['error']= $res['error'];
|
372 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog( $ret['error'],'notice');
|
373 |
+
}
|
374 |
+
|
375 |
+
}
|
376 |
+
else
|
377 |
+
{
|
378 |
+
$ret['result']=WPVIVID_FAILED;
|
379 |
+
$ret['error']= 'Failed to parse returned data, chunk transfer failed.';
|
380 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog('error send chunk failed','notice');
|
381 |
+
}
|
382 |
}
|
383 |
else
|
384 |
{
|
385 |
$ret['result']=WPVIVID_FAILED;
|
386 |
$ret['http_code']=$response['response']['code'];
|
387 |
+
$ret['error']= 'http error, error code:'.$response['response']['code'];
|
388 |
}
|
389 |
}
|
390 |
return $ret;
|
408 |
$args['body']=array('wpvivid_content'=>$data,'wpvivid_action'=>'send_to_site_finish');
|
409 |
$args['timeout']=30;
|
410 |
$response=wp_remote_post($this->options['url'],$args);
|
|
|
411 |
if ( is_wp_error( $response ) )
|
412 |
{
|
413 |
$ret['result']=WPVIVID_FAILED;
|
417 |
{
|
418 |
if($response['response']['code']==200)
|
419 |
{
|
420 |
+
$res=json_decode($response['body'],1);
|
421 |
+
if($res!=null)
|
422 |
+
{
|
423 |
+
if($res['result']==WPVIVID_SUCCESS)
|
424 |
+
{
|
425 |
+
$ret['result']=WPVIVID_SUCCESS;
|
426 |
+
}
|
427 |
+
else
|
428 |
+
{
|
429 |
+
$ret['result']=WPVIVID_FAILED;
|
430 |
+
$ret['error']= $res['error'];
|
431 |
+
}
|
432 |
+
}
|
433 |
+
else
|
434 |
+
{
|
435 |
+
$ret['result']=WPVIVID_FAILED;
|
436 |
+
$ret['error']= 'Failed to parse returned data, uploading backup chunks failed.';
|
437 |
+
}
|
438 |
}
|
439 |
else
|
440 |
{
|
449 |
public function send_to_site_connect()
|
450 |
{
|
451 |
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-crypt.php';
|
452 |
+
try {
|
453 |
+
if (isset($_POST['wpvivid_content'])) {
|
454 |
+
$default = array();
|
455 |
+
$option = get_option('wpvivid_api_token', $default);
|
456 |
+
if (empty($option)) {
|
457 |
+
die();
|
458 |
+
}
|
459 |
+
if ($option['expires'] != 0 && $option['expires'] < time()) {
|
460 |
+
die();
|
461 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
462 |
|
463 |
+
$crypt = new WPvivid_crypt(base64_decode($option['private_key']));
|
464 |
+
$body = base64_decode($_POST['wpvivid_content']);
|
465 |
+
$data = $crypt->decrypt_message($body);
|
466 |
+
if (!is_string($data)) {
|
467 |
+
$ret['result'] = WPVIVID_FAILED;
|
468 |
+
$ret['error'] = 'The key is invalid.';
|
469 |
+
echo json_encode($ret);
|
470 |
+
die();
|
471 |
+
}
|
472 |
|
473 |
+
$params = json_decode($data, 1);
|
474 |
+
if (is_null($params)) {
|
475 |
+
$ret['result'] = WPVIVID_FAILED;
|
476 |
+
$ret['error'] = 'The key is invalid.';
|
|
|
|
|
477 |
echo json_encode($ret);
|
478 |
+
die();
|
479 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
480 |
|
481 |
+
if (isset($params['backup_id'])) {
|
482 |
+
if (WPvivid_Backuplist::get_backuplist_by_key($params['backup_id']) !== false) {
|
483 |
+
$ret['result'] = WPVIVID_FAILED;
|
484 |
+
$ret['error'] = 'The uploading backup already exists in Backups list.';
|
485 |
+
echo json_encode($ret);
|
486 |
+
} else {
|
487 |
+
global $wpvivid_pulgin;
|
488 |
+
$wpvivid_pulgin->wpvivid_log = new WPvivid_Log();
|
489 |
+
if (!file_exists($wpvivid_pulgin->wpvivid_log->GetSaveLogFolder() . $params['backup_id'] . '_backup_log.txt')) {
|
490 |
+
$wpvivid_pulgin->wpvivid_log->CreateLogFile($params['backup_id'] . '_backup', 'no_folder', 'transfer');
|
491 |
+
$wpvivid_pulgin->wpvivid_log->WriteLogHander();
|
492 |
+
} else {
|
493 |
+
$wpvivid_pulgin->wpvivid_log->OpenLogFile($params['backup_id'] . '_backup', 'no_folder');
|
494 |
+
}
|
495 |
|
496 |
+
|
497 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog('Connect site success', 'notice');
|
498 |
+
$ret['result'] = WPVIVID_SUCCESS;
|
499 |
+
echo json_encode($ret);
|
500 |
+
}
|
501 |
+
} else {
|
502 |
+
$ret['result'] = WPVIVID_SUCCESS;
|
503 |
echo json_encode($ret);
|
504 |
}
|
505 |
}
|
506 |
+
}
|
507 |
+
catch (Exception $e) {
|
508 |
+
$ret['result']=WPVIVID_FAILED;
|
509 |
+
$ret['error']=$e->getMessage();
|
510 |
+
echo json_encode($ret);
|
511 |
+
die();
|
512 |
}
|
513 |
die();
|
514 |
}
|
516 |
public function send_to_site()
|
517 |
{
|
518 |
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-crypt.php';
|
519 |
+
$test_log=new WPvivid_Log();
|
520 |
+
$test_log->CreateLogFile('test_backup','no_folder','transfer');
|
521 |
+
$test_log->WriteLog('test upload.','notice');
|
522 |
+
try
|
523 |
{
|
524 |
+
if(isset($_POST['wpvivid_content']))
|
|
|
|
|
|
|
|
|
|
|
525 |
{
|
526 |
+
global $wpvivid_pulgin;
|
527 |
+
$wpvivid_pulgin->wpvivid_log=new WPvivid_Log();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
528 |
|
529 |
+
$default=array();
|
530 |
+
$option=get_option('wpvivid_api_token',$default);
|
531 |
+
if(empty($option))
|
532 |
+
{
|
533 |
+
die();
|
534 |
+
}
|
535 |
+
if($option['expires'] !=0 && $option['expires']<time())
|
536 |
+
{
|
537 |
+
die();
|
538 |
+
}
|
539 |
+
$crypt=new WPvivid_crypt(base64_decode($option['private_key']));
|
540 |
+
$body=base64_decode($_POST['wpvivid_content']);
|
541 |
+
$data=$crypt->decrypt_message($body);
|
542 |
+
if (!is_string($data))
|
543 |
+
{
|
544 |
+
$ret['result']=WPVIVID_FAILED;
|
545 |
+
$ret['error']='The key is invalid.';
|
546 |
+
echo json_encode($ret);
|
547 |
+
die();
|
548 |
+
}
|
549 |
|
550 |
+
$params=json_decode($data,1);
|
551 |
+
if(is_null($params))
|
552 |
+
{
|
553 |
+
$ret['result']=WPVIVID_FAILED;
|
554 |
+
$ret['error']='The key is invalid.';
|
555 |
+
echo json_encode($ret);
|
556 |
+
die();
|
557 |
+
}
|
558 |
|
559 |
+
$wpvivid_pulgin->wpvivid_log->OpenLogFile($params['backup_id'].'_backup','no_folder','backup');
|
560 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog('start upload.','notice');
|
561 |
+
$dir=WPvivid_Setting::get_backupdir();
|
562 |
|
563 |
+
$file_path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.str_replace('wpvivid','wpvivid_temp',$params['name']);
|
564 |
|
565 |
+
if(!file_exists($file_path))
|
566 |
+
{
|
567 |
+
$handle=fopen($file_path,'w');
|
568 |
+
fclose($handle);
|
569 |
+
}
|
570 |
|
571 |
+
$handle=fopen($file_path,'rb+');
|
572 |
+
$offset=$params['offset'];
|
573 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog('Write file:'.$file_path.' offset:'.size_format($offset),'notice');
|
574 |
+
if($offset)
|
|
|
|
|
575 |
{
|
576 |
+
if(fseek($handle, $offset)===-1)
|
577 |
+
{
|
578 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog('Seek file offset failed:'.size_format($offset),'notice');
|
579 |
+
}
|
580 |
}
|
|
|
581 |
|
582 |
+
if (fwrite($handle,base64_decode($params['data'])) === FALSE)
|
583 |
+
{
|
584 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog('Write file :'.$file_path.' failed size:'.filesize($file_path),'notice');
|
585 |
+
}
|
586 |
+
else
|
587 |
+
{
|
588 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog('Write file:'.$file_path.' success size:'.filesize($file_path),'notice');
|
589 |
+
}
|
590 |
|
591 |
+
fclose($handle);
|
592 |
|
593 |
|
594 |
+
if(filesize($file_path)>=$params['file_size'])
|
|
|
|
|
595 |
{
|
596 |
+
if (md5_file($file_path) == $params['md5'])
|
597 |
+
{
|
598 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog('rename temp file:'.$file_path.' to new name:'.WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.$params['name'],'notice');
|
599 |
+
rename($file_path,WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.$params['name']);
|
600 |
|
601 |
+
$ret['result']=WPVIVID_SUCCESS;
|
602 |
+
$ret['op']='finished';
|
603 |
+
} else {
|
604 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog('file md5 not match','notice');
|
605 |
+
$ret['result']=WPVIVID_FAILED;
|
606 |
+
$ret['error']='File md5 is not matched.';
|
607 |
+
}
|
608 |
+
}
|
609 |
+
else
|
610 |
+
{
|
611 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog('continue size:'.filesize($file_path).' size1:'.$params['file_size'],'notice');
|
612 |
$ret['result']=WPVIVID_SUCCESS;
|
613 |
+
$ret['op']='continue';
|
614 |
+
//
|
|
|
|
|
|
|
615 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
616 |
|
617 |
+
echo json_encode($ret);
|
618 |
+
}
|
619 |
+
}
|
620 |
+
catch (Exception $e)
|
621 |
+
{
|
622 |
+
$ret['result']=WPVIVID_FAILED;
|
623 |
+
$ret['error']=$e->getMessage();
|
624 |
+
//$wpvivid_pulgin->wpvivid_log->WriteLog($e->getMessage(),'error');
|
625 |
echo json_encode($ret);
|
626 |
+
die();
|
627 |
}
|
628 |
+
|
629 |
die();
|
630 |
}
|
631 |
|
632 |
public function send_to_site_finish()
|
633 |
{
|
634 |
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-crypt.php';
|
635 |
+
try {
|
636 |
+
if (isset($_POST['wpvivid_content'])) {
|
637 |
+
$default = array();
|
638 |
+
$option = get_option('wpvivid_api_token', $default);
|
639 |
+
if (empty($option)) {
|
640 |
+
die();
|
641 |
+
}
|
642 |
+
if ($option['expires'] != 0 && $option['expires'] < time()) {
|
643 |
+
die();
|
644 |
+
}
|
|
|
|
|
645 |
|
646 |
+
$crypt = new WPvivid_crypt(base64_decode($option['private_key']));
|
647 |
+
$body = base64_decode($_POST['wpvivid_content']);
|
648 |
+
$data = $crypt->decrypt_message($body);
|
649 |
+
if (!is_string($data)) {
|
650 |
+
$ret['result'] = WPVIVID_FAILED;
|
651 |
+
$ret['error'] = 'The key is invalid.';
|
652 |
+
echo json_encode($ret);
|
653 |
+
die();
|
654 |
+
}
|
|
|
655 |
|
656 |
+
$params = json_decode($data, 1);
|
657 |
+
if (is_null($params)) {
|
658 |
+
$ret['result'] = WPVIVID_FAILED;
|
659 |
+
$ret['error'] = 'The key is invalid.';
|
660 |
+
echo json_encode($ret);
|
661 |
+
die();
|
662 |
+
}
|
|
|
663 |
|
664 |
+
global $wpvivid_pulgin;
|
665 |
+
$wpvivid_pulgin->wpvivid_log = new WPvivid_Log();
|
666 |
+
$wpvivid_pulgin->wpvivid_log->OpenLogFile($params['backup_id'] . '_backup', 'no_folder', 'backup');
|
667 |
+
$wpvivid_pulgin->wpvivid_log->WriteLog('upload finished', 'notice');
|
668 |
+
|
669 |
+
if (isset($params['backup']) && isset($params['backup_id'])) {
|
670 |
+
$params['backup']['type'] = 'Migration';
|
671 |
+
$list = WPvivid_Setting::get_option('wpvivid_backup_list');
|
672 |
+
$list[$params['backup_id']] = $params['backup'];
|
673 |
+
$list[$params['backup_id']]['log'] = $wpvivid_pulgin->wpvivid_log->log_file;
|
674 |
+
WPvivid_Setting::update_option('wpvivid_backup_list', $list);
|
675 |
+
}
|
676 |
|
677 |
+
$ret['result'] = WPVIVID_SUCCESS;
|
678 |
+
echo json_encode($ret);
|
|
|
|
|
|
|
|
|
|
|
679 |
}
|
680 |
+
}
|
681 |
+
catch (Exception $e) {
|
682 |
+
$ret['result']=WPVIVID_FAILED;
|
683 |
+
$ret['error']=$e->getMessage();
|
684 |
echo json_encode($ret);
|
685 |
+
die();
|
686 |
}
|
687 |
die();
|
688 |
}
|
714 |
$args['body']=array('wpvivid_content'=>$data,'wpvivid_action'=>'send_to_site_file_status');
|
715 |
$args['timeout']=30;
|
716 |
$response=wp_remote_post($this->options['url'],$args);
|
|
|
717 |
if ( is_wp_error( $response ) )
|
718 |
{
|
719 |
$ret['result']=WPVIVID_FAILED;
|
742 |
else
|
743 |
{
|
744 |
$ret['result']=WPVIVID_FAILED;
|
745 |
+
$ret['error']= 'Failed to parse returned data, unable to retrieve file status of target site.';
|
746 |
}
|
747 |
}
|
748 |
else
|
757 |
public function send_to_site_file_status()
|
758 |
{
|
759 |
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-crypt.php';
|
760 |
+
try {
|
761 |
+
if (isset($_POST['wpvivid_content'])) {
|
762 |
+
$default = array();
|
763 |
+
$option = get_option('wpvivid_api_token', $default);
|
764 |
+
if (empty($option)) {
|
765 |
+
die();
|
766 |
+
}
|
767 |
+
if ($option['expires'] != 0 && $option['expires'] < time()) {
|
768 |
+
die();
|
769 |
+
}
|
|
|
|
|
770 |
|
771 |
+
$crypt = new WPvivid_crypt(base64_decode($option['private_key']));
|
772 |
+
$body = base64_decode($_POST['wpvivid_content']);
|
773 |
+
$data = $crypt->decrypt_message($body);
|
774 |
+
if (!is_string($data)) {
|
775 |
+
$ret['result'] = WPVIVID_FAILED;
|
776 |
+
$ret['error'] = 'The key is invalid.';
|
777 |
+
echo json_encode($ret);
|
778 |
+
die();
|
779 |
+
}
|
|
|
780 |
|
781 |
+
$params = json_decode($data, 1);
|
782 |
+
if (is_null($params)) {
|
783 |
+
$ret['result'] = WPVIVID_FAILED;
|
784 |
+
$ret['error'] = 'The key is invalid.';
|
785 |
+
echo json_encode($ret);
|
786 |
+
die();
|
787 |
+
}
|
|
|
788 |
|
789 |
+
$dir = WPvivid_Setting::get_backupdir();
|
790 |
+
$file_path = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . str_replace('wpvivid', 'wpvivid_temp', $params['name']);
|
791 |
|
792 |
+
$rename = true;
|
793 |
|
794 |
+
if (!file_exists($file_path)) {
|
795 |
+
$file_path = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $params['name'];
|
796 |
+
$rename = false;
|
797 |
+
}
|
798 |
+
$offset = filesize($file_path);
|
799 |
+
if (!$offset) {
|
800 |
+
$ret['result'] = WPVIVID_SUCCESS;
|
801 |
+
$ret['file_status']['status'] = 'start';
|
802 |
+
echo json_encode($ret);
|
803 |
+
die();
|
804 |
+
}
|
|
|
|
|
805 |
|
806 |
+
if (filesize($file_path) >= $params['file_size']) {
|
807 |
+
if (md5_file($file_path) == $params['md5']) {
|
808 |
+
if ($rename)
|
809 |
+
rename($file_path, WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $params['name']);
|
810 |
+
$ret['result'] = WPVIVID_SUCCESS;
|
811 |
+
$ret['file_status']['status'] = 'finished';
|
812 |
+
} else {
|
813 |
+
$ret['result'] = WPVIVID_FAILED;
|
814 |
+
$ret['error'] = 'File md5 is not matched.';
|
815 |
+
}
|
816 |
} else {
|
817 |
+
$ret['result'] = WPVIVID_SUCCESS;
|
818 |
+
$ret['file_status']['status'] = 'continue';
|
819 |
+
$ret['file_status']['offset'] = filesize($file_path);
|
820 |
}
|
821 |
+
echo json_encode($ret);
|
822 |
}
|
823 |
+
}
|
824 |
+
catch (Exception $e) {
|
825 |
+
$ret['result']=WPVIVID_FAILED;
|
826 |
+
$ret['error']=$e->getMessage();
|
|
|
|
|
827 |
echo json_encode($ret);
|
828 |
+
die();
|
829 |
}
|
830 |
die();
|
831 |
}
|
includes/customclass/class-wpvivid-sftpclass.php
CHANGED
@@ -3,8 +3,8 @@
|
|
3 |
if (!defined('WPVIVID_PLUGIN_DIR')){
|
4 |
die;
|
5 |
}
|
6 |
-
|
7 |
-
define('WPVIVID_REMOTE_SFTP','sftp');
|
8 |
require_once WPVIVID_PLUGIN_DIR .'/includes/customclass/class-wpvivid-remote.php';
|
9 |
|
10 |
class WPvivid_SFTPClass extends WPvivid_Remote{
|
3 |
if (!defined('WPVIVID_PLUGIN_DIR')){
|
4 |
die;
|
5 |
}
|
6 |
+
if(!defined('WPVIVID_REMOTE_SFTP'))
|
7 |
+
define('WPVIVID_REMOTE_SFTP','sftp');
|
8 |
require_once WPVIVID_PLUGIN_DIR .'/includes/customclass/class-wpvivid-remote.php';
|
9 |
|
10 |
class WPvivid_SFTPClass extends WPvivid_Remote{
|
readme.txt
CHANGED
@@ -1,31 +1,31 @@
|
|
1 |
-
===
|
2 |
Contributors: wpvivid
|
3 |
-
Tags:
|
4 |
Requires at least: 4.5
|
5 |
Tested up to: 5.2
|
6 |
Requires PHP: 5.3
|
7 |
-
Stable tag: 0.9.
|
8 |
License: GPLv3 or later
|
9 |
License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
|
10 |
|
11 |
-
|
12 |
|
13 |
== Description ==
|
14 |
WPvivid Backup Plugin is the only free all-in-one backup, restore and migration WordPress plugin.
|
15 |
|
16 |
-
|
17 |
|
18 |
== Core Features ==
|
19 |
|
20 |
-
= 1. Easy Site
|
21 |
-
|
22 |
|
23 |
-
You can also
|
24 |
|
25 |
-
You are free to choose what to
|
26 |
= 2. Upload Backups (New Feature) =
|
27 |
-
Upload a backup to restore or
|
28 |
-
You can
|
29 |
= 3. Automatic Backup =
|
30 |
Setup and forget, the plugin will do the rest automatically backing up your website.
|
31 |
= 4. One-Click Restore =
|
@@ -35,21 +35,21 @@ Restore your WordPress site from a backup with a single click.
|
|
35 |
|
36 |
Dropbox, Google Drive, Microsoft OneDrive, Amazon S3, DigitalOcean Spaces, SFTP, FTP and more are coming soon.
|
37 |
|
38 |
-
== Site
|
39 |
1. Install the WPvivid Backup plugin on both the destination site and the sending site.
|
40 |
2. Generate a site key on the destination site with one click.
|
41 |
3. Paste the key in the sending site and save it.
|
42 |
-
4.
|
43 |
|
44 |
== Features Spotlight ==
|
45 |
-
* One-Click Site
|
46 |
-
* Upload Backups to Restore or
|
47 |
* Schedule Automated Backups
|
48 |
* One-Click Restore
|
49 |
* Manual Backup
|
50 |
* Filter Large Files
|
51 |
* Large Database Support
|
52 |
-
* Optimized for
|
53 |
* Set Backup Retention
|
54 |
* Backup Splitting
|
55 |
* No Limit of Backup Size
|
@@ -94,11 +94,11 @@ We offer free support in 3 channels:
|
|
94 |
WPvivid Backup plugin is created and operated with full respect and protection of users personal information, and is in full compliance with General Data Protection Regulation(GDPR). Check out the following content to know the details:
|
95 |
= What personal data can WPvivid Backup plugin access and how is the data processed? =
|
96 |
The plugin currently only has a free version and is available to download from WordPress plugin repository. Thus, all the data related to the updates of the versions as well as the support forum for the plugin on WordPress.org is held by WordPress.org.
|
97 |
-
In addition, the implementations of all
|
98 |
The only personal data currently we can access are the contact data when you contact us by email, which may include your name, email address and other contact details. The data will only be used for the purposes of handling and resolving your enquiry.
|
99 |
= How does WPvivid Backup plugin help users create a GDPR compliant backup? =
|
100 |
In order to help users create a GDPR compliant backup, the plugin comes with multiple features including selection for backup content, backup and restore logs, and email report. Moreover, as the plugin itself does not collect any personal data, you do not need to sign a Data Processing Agreement (DPA) with us.
|
101 |
-
However, if you
|
102 |
Check out the [privacy policy](https://wpvivid.com/privacy-policy) involving the use of Google Drive, Dropbox and Microsoft OneDrive.
|
103 |
|
104 |
== License ==
|
@@ -110,14 +110,14 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
110 |
2. Backup list
|
111 |
3. Dashboard
|
112 |
4. Configure remote storage
|
113 |
-
5.
|
114 |
-
6. Upload a backup to restore or
|
115 |
|
116 |
== Frequently Asked Questions ==
|
117 |
= What does WPvivid Backup plugin do? =
|
118 |
-
As its name says, it is an all in one free WP backup plugin that enables you to easily
|
119 |
-
= Does the plugin also
|
120 |
-
Yes, we have added website
|
121 |
Yes, it's a completely free feature.
|
122 |
= How many cloud options does it support? Are they free to access? =
|
123 |
Out of the box we support Dropbox, Google Drive, Amazon S3, Microsoft OneDrive, DigitalOcean Spaces, we also support FTP, SFTP methods which you can use on any other remote storage provider supporting these methods. We are working hard to add more soon.
|
@@ -133,19 +133,23 @@ Yes, absolutely. Whenever you need it, help can be found from the plugin [suppor
|
|
133 |
If your website is running on WordPress then yes it will.
|
134 |
|
135 |
The plugin has been extensively tested on the shared and dedicated hosting plans from the leading website hosting providers like Godaddy, Siteground, and many others.
|
136 |
-
=
|
137 |
-
|
138 |
-
= What does the error "Error: Backup error: Allowed memory size of xxxxxxxxxx bytes exhausted (tried to allocate xxxxxxxxxx bytes), task id: wpvivid-xxxxxxxxxxxxx." mean? =
|
139 |
-
This error often occurs while creating a backup for a website with an oversized database. In this case, the size of database is larger than the value of memory limit in php.ini file. As a result, there will be no sufficient memory to compress the database.
|
140 |
-
To avoid that, please try using the solutions below to modify memory limit in php.ini file, and make sure the value is larger than the database size:
|
141 |
-
1. Increase PHP memory limit.
|
142 |
-
Please try to contact your web hosting provider for changing PHP memory limit, or modify it by yourself as the administrator role if your website is hosting on VPS or dedicated server.
|
143 |
-
2. Upgrade your web hosting plan.
|
144 |
|
145 |
== Contact us ==
|
146 |
Feel free to let us know how we can help using the [support forum](https://wordpress.org/support/plugin/wpvivid-backuprestore) for the plugin on WordPress.org or our [contact form](https://wpvivid.com/contact-us). You can also reach us with a direct message on [Twitter](https://twitter.com/WPvividcom).
|
147 |
|
148 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
= 0.9.19 =
|
150 |
- Added a php memory limit option to settings, you can use it to temporarily increase php memory limit when encountering a memory exhausted error in backup process.
|
151 |
- Fixed: Backup does not exist error that occurred in some cases when downloading the backup to local.
|
@@ -159,7 +163,7 @@ Feel free to let us know how we can help using the [support forum](https://wordp
|
|
159 |
- Added an option to hide settings in admin menu.
|
160 |
- Changed the plugin icon showing in admin menu.
|
161 |
- Included more info in the error log when sending to support.
|
162 |
-
- Improved compatibility with
|
163 |
- Optimized the cache directory in backup process.
|
164 |
- Fixed errors occurred in some cases during the authentication process with Google Drive, Dropbox, Microsoft OneDrive.
|
165 |
- Optimized plugin code.
|
1 |
+
=== Move A Cloned Site to A New Host - WPvivid Backup Plugin ===
|
2 |
Contributors: wpvivid
|
3 |
+
Tags: move, clone, migrate, copy, backup, restore, auto backup, cloud backup
|
4 |
Requires at least: 4.5
|
5 |
Tested up to: 5.2
|
6 |
Requires PHP: 5.3
|
7 |
+
Stable tag: 0.9.20
|
8 |
License: GPLv3 or later
|
9 |
License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
|
10 |
|
11 |
+
Clone or copy WP sites then move or migrate them to new host (new domain), schedule backups, transfer backups to leading remote storage. All in one.
|
12 |
|
13 |
== Description ==
|
14 |
WPvivid Backup Plugin is the only free all-in-one backup, restore and migration WordPress plugin.
|
15 |
|
16 |
+
Clone or copy WordPress sites then move or migrate them to a new host (new domain). Off-site backup schedules, transfer backups to leading remote storage. All in one.
|
17 |
|
18 |
== Core Features ==
|
19 |
|
20 |
+
= 1. Easy Site Move or Migration (New Feature) =
|
21 |
+
Move your WordPress site to a new domain with a single click. The plugin supports site move from dev environment to a new server, from dev environment to a new domain or from a live server to another.
|
22 |
|
23 |
+
You can also move a site to a subdirectory, from a.com to b.com, from a.com to a.com/directory and from a.com to b.com/directory.
|
24 |
|
25 |
+
You are free to choose what to move: the entire site, files or just the database only.
|
26 |
= 2. Upload Backups (New Feature) =
|
27 |
+
Upload a backup to restore or clone.
|
28 |
+
You can clone or restore backups created with 0.9.14 or a higher version.
|
29 |
= 3. Automatic Backup =
|
30 |
Setup and forget, the plugin will do the rest automatically backing up your website.
|
31 |
= 4. One-Click Restore =
|
35 |
|
36 |
Dropbox, Google Drive, Microsoft OneDrive, Amazon S3, DigitalOcean Spaces, SFTP, FTP and more are coming soon.
|
37 |
|
38 |
+
== Site Clone Process ==
|
39 |
1. Install the WPvivid Backup plugin on both the destination site and the sending site.
|
40 |
2. Generate a site key on the destination site with one click.
|
41 |
3. Paste the key in the sending site and save it.
|
42 |
+
4. Clone the site with one-click.
|
43 |
|
44 |
== Features Spotlight ==
|
45 |
+
* One-Click Site Move or Migration
|
46 |
+
* Upload Backups to Restore or Clone
|
47 |
* Schedule Automated Backups
|
48 |
* One-Click Restore
|
49 |
* Manual Backup
|
50 |
* Filter Large Files
|
51 |
* Large Database Support
|
52 |
+
* Optimized for Web Hosting/Shared Web Hosting
|
53 |
* Set Backup Retention
|
54 |
* Backup Splitting
|
55 |
* No Limit of Backup Size
|
94 |
WPvivid Backup plugin is created and operated with full respect and protection of users personal information, and is in full compliance with General Data Protection Regulation(GDPR). Check out the following content to know the details:
|
95 |
= What personal data can WPvivid Backup plugin access and how is the data processed? =
|
96 |
The plugin currently only has a free version and is available to download from WordPress plugin repository. Thus, all the data related to the updates of the versions as well as the support forum for the plugin on WordPress.org is held by WordPress.org.
|
97 |
+
In addition, the implementations of all migrations, backups and restores of your site happen completely on your website server, there are no data come across any of our servers in the whole process.
|
98 |
The only personal data currently we can access are the contact data when you contact us by email, which may include your name, email address and other contact details. The data will only be used for the purposes of handling and resolving your enquiry.
|
99 |
= How does WPvivid Backup plugin help users create a GDPR compliant backup? =
|
100 |
In order to help users create a GDPR compliant backup, the plugin comes with multiple features including selection for backup content, backup and restore logs, and email report. Moreover, as the plugin itself does not collect any personal data, you do not need to sign a Data Processing Agreement (DPA) with us.
|
101 |
+
However, if you transfer your backups to cloud storage with Move A Cloned Site to A New Host - WPvivid Backup Plugin, the personal data is moved to that storage provider. You'll need to sign a Data Processing Agreement with that provider.
|
102 |
Check out the [privacy policy](https://wpvivid.com/privacy-policy) involving the use of Google Drive, Dropbox and Microsoft OneDrive.
|
103 |
|
104 |
== License ==
|
110 |
2. Backup list
|
111 |
3. Dashboard
|
112 |
4. Configure remote storage
|
113 |
+
5. Move a WordPress site to a new domain
|
114 |
+
6. Upload a backup to restore or move
|
115 |
|
116 |
== Frequently Asked Questions ==
|
117 |
= What does WPvivid Backup plugin do? =
|
118 |
+
As its name says, it is an all in one free WP backup plugin that enables you to easily move a WordPress site to a new domain, to perform manual and scheduled backups of your WordPress site, to back up to cloud storage and restore backups directly from your sites admin dashboard.
|
119 |
+
= Does the plugin also migrate my site? Is it a free feature? =
|
120 |
+
Yes, we have added website migration feature since version 0.9.14.
|
121 |
Yes, it's a completely free feature.
|
122 |
= How many cloud options does it support? Are they free to access? =
|
123 |
Out of the box we support Dropbox, Google Drive, Amazon S3, Microsoft OneDrive, DigitalOcean Spaces, we also support FTP, SFTP methods which you can use on any other remote storage provider supporting these methods. We are working hard to add more soon.
|
133 |
If your website is running on WordPress then yes it will.
|
134 |
|
135 |
The plugin has been extensively tested on the shared and dedicated hosting plans from the leading website hosting providers like Godaddy, Siteground, and many others.
|
136 |
+
= Do you have any get-started guides/docs? =
|
137 |
+
Yes, we do. Here are the guides for [copying your site to a new host](https://wpvivid.com/get-started-transfer-site.html), [creating a manual backup](https://wpvivid.com/get-started-create-a-manual-backup.html), [restoring your site from a backup](https://wpvivid.com/get-started-restore-site.html), [the plugin settings](https://wpvivid.com/get-started-settings.html).
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
|
139 |
== Contact us ==
|
140 |
Feel free to let us know how we can help using the [support forum](https://wordpress.org/support/plugin/wpvivid-backuprestore) for the plugin on WordPress.org or our [contact form](https://wpvivid.com/contact-us). You can also reach us with a direct message on [Twitter](https://twitter.com/WPvividcom).
|
141 |
|
142 |
== Changelog ==
|
143 |
+
= 0.9.20 =
|
144 |
+
- Added an advanced section in settings page.
|
145 |
+
- Optimized the layout of settings page and display of some settings.
|
146 |
+
- Added an option of enabling optimization mode for web hosting/shared hosting in advanced settings.
|
147 |
+
- Added a memory_limit option in advanced settings.
|
148 |
+
- Added a chunk size option in advanced settings.
|
149 |
+
- Added an option to cancel a running migration.
|
150 |
+
- Provided the WPDB as the interface with the database for the sites missing PDO_MYSQL.
|
151 |
+
- Fixed a timeout error occurred in some cases during backup process.
|
152 |
+
- Optimized the plugin code.
|
153 |
= 0.9.19 =
|
154 |
- Added a php memory limit option to settings, you can use it to temporarily increase php memory limit when encountering a memory exhausted error in backup process.
|
155 |
- Fixed: Backup does not exist error that occurred in some cases when downloading the backup to local.
|
163 |
- Added an option to hide settings in admin menu.
|
164 |
- Changed the plugin icon showing in admin menu.
|
165 |
- Included more info in the error log when sending to support.
|
166 |
+
- Improved compatibility with some hosting like GoDaddy.
|
167 |
- Optimized the cache directory in backup process.
|
168 |
- Fixed errors occurred in some cases during the authentication process with Google Drive, Dropbox, Microsoft OneDrive.
|
169 |
- Optimized plugin code.
|
wpvivid-backuprestore.php
CHANGED
@@ -7,7 +7,7 @@
|
|
7 |
* @wordpress-plugin
|
8 |
* Plugin Name: WPvivid Backup Plugin
|
9 |
* Description: Transfer site to a new domain. Off-site backup schedule, transfer backups to leading remote storage (dropbox, onedrive, google drive etc). All in one.
|
10 |
-
* Version: 0.9.
|
11 |
* Author: WPvivid Team
|
12 |
* Author URI: https://wpvivid.com
|
13 |
* License: GPL-3.0+
|
@@ -21,7 +21,7 @@ if ( ! defined( 'WPINC' ) ) {
|
|
21 |
die;
|
22 |
}
|
23 |
|
24 |
-
define( 'WPVIVID_PLUGIN_VERSION', '0.9.
|
25 |
//
|
26 |
define('WPVIVID_RESTORE_INIT','init');
|
27 |
define('WPVIVID_RESTORE_READY','ready');
|
@@ -39,6 +39,8 @@ define('WPVIVID_PLUGIN_DIR',dirname(__FILE__));
|
|
39 |
//We set a long enough default execution time (10 min) to ensure that the backup process can be completed.
|
40 |
define('WPVIVID_MAX_EXECUTION_TIME',900);
|
41 |
define('WPVIVID_MEMORY_LIMIT','256M');
|
|
|
|
|
42 |
//If the server uses fastcgi then default execution time should be set to 2 min for more efficient.
|
43 |
define('WPVIVID_MAX_EXECUTION_TIME_FCGI',180);
|
44 |
//Default number of reserved backups
|
@@ -69,6 +71,8 @@ define('WPVIVID_DEFAULT_DOMAIN_INCLUDE', true);
|
|
69 |
define('WPVIVID_DEFAULT_ESTIMATE_BACKUP', true);
|
70 |
//Specify the folder and database to be backed up
|
71 |
|
|
|
|
|
72 |
//define schedule hooks
|
73 |
define('WPVIVID_MAIN_SCHEDULE_EVENT','wpvivid_main_schedule_event');
|
74 |
define('WPVIVID_RESUME_SCHEDULE_EVENT','wpvivid_resume_schedule_event');
|
@@ -76,7 +80,7 @@ define('WPVIVID_CLEAN_BACKING_UP_DATA_EVENT','wpvivid_clean_backing_up_data_even
|
|
76 |
define('WPVIVID_TASK_MONITOR_EVENT','wpvivid_task_monitor_event');
|
77 |
define('WPVIVID_CLEAN_BACKUP_RECORD_EVENT','wpvivid_clean_backup_record_event');
|
78 |
//backup resume retry times
|
79 |
-
define('WPVIVID_RESUME_RETRY_TIMES',
|
80 |
define('WPVIVID_RESUME_INTERVAL',60);
|
81 |
|
82 |
define('WPVIVID_REMOTE_CONNECT_RETRY_TIMES','3');
|
7 |
* @wordpress-plugin
|
8 |
* Plugin Name: WPvivid Backup Plugin
|
9 |
* Description: Transfer site to a new domain. Off-site backup schedule, transfer backups to leading remote storage (dropbox, onedrive, google drive etc). All in one.
|
10 |
+
* Version: 0.9.20
|
11 |
* Author: WPvivid Team
|
12 |
* Author URI: https://wpvivid.com
|
13 |
* License: GPL-3.0+
|
21 |
die;
|
22 |
}
|
23 |
|
24 |
+
define( 'WPVIVID_PLUGIN_VERSION', '0.9.20' );
|
25 |
//
|
26 |
define('WPVIVID_RESTORE_INIT','init');
|
27 |
define('WPVIVID_RESTORE_READY','ready');
|
39 |
//We set a long enough default execution time (10 min) to ensure that the backup process can be completed.
|
40 |
define('WPVIVID_MAX_EXECUTION_TIME',900);
|
41 |
define('WPVIVID_MEMORY_LIMIT','256M');
|
42 |
+
define('WPVIVID_RESTORE_MEMORY_LIMIT','256M');
|
43 |
+
define('WPVIVID_MIGRATE_SIZE', '2048');
|
44 |
//If the server uses fastcgi then default execution time should be set to 2 min for more efficient.
|
45 |
define('WPVIVID_MAX_EXECUTION_TIME_FCGI',180);
|
46 |
//Default number of reserved backups
|
71 |
define('WPVIVID_DEFAULT_ESTIMATE_BACKUP', true);
|
72 |
//Specify the folder and database to be backed up
|
73 |
|
74 |
+
define('WPVIVID_DEFAULT_SUBPACKAGE_PLUGIN_UPLOAD', false);
|
75 |
+
|
76 |
//define schedule hooks
|
77 |
define('WPVIVID_MAIN_SCHEDULE_EVENT','wpvivid_main_schedule_event');
|
78 |
define('WPVIVID_RESUME_SCHEDULE_EVENT','wpvivid_resume_schedule_event');
|
80 |
define('WPVIVID_TASK_MONITOR_EVENT','wpvivid_task_monitor_event');
|
81 |
define('WPVIVID_CLEAN_BACKUP_RECORD_EVENT','wpvivid_clean_backup_record_event');
|
82 |
//backup resume retry times
|
83 |
+
define('WPVIVID_RESUME_RETRY_TIMES',6);
|
84 |
define('WPVIVID_RESUME_INTERVAL',60);
|
85 |
|
86 |
define('WPVIVID_REMOTE_CONNECT_RETRY_TIMES','3');
|