Migration, Backup, Staging – WPvivid - Version 0.9.32

Version Description

  • Updated the plugin code for WPvivid Backup for MainWP extension.
  • Fixed some bugs in the plugin code.
  • Optimized the plugin code.
Download this release

Release Info

Developer wpvivid
Plugin Icon 128x128 Migration, Backup, Staging – WPvivid
Version 0.9.32
Comparing to
See all releases

Code changes from version 0.9.31 to 0.9.32

admin/class-wpvivid-admin.php CHANGED
@@ -348,6 +348,7 @@ class WPvivid_Admin {
348
  if ($restore_status === WPVIVID_RESTORE_COMPLETED)
349
  {
350
  $restore->clean_restore_data();
 
351
  $need_review=WPvivid_Setting::get_option('wpvivid_need_review');
352
  if($need_review=='not')
353
  {
@@ -374,6 +375,9 @@ class WPvivid_Admin {
374
  {
375
  $request_page='wpvivid_tab_general';
376
 
 
 
 
377
  if(isset($_REQUEST['tab-backup']))
378
  {
379
  $request_page='wpvivid_tab_general';
348
  if ($restore_status === WPVIVID_RESTORE_COMPLETED)
349
  {
350
  $restore->clean_restore_data();
351
+ do_action('wpvivid_rebuild_backup_list');
352
  $need_review=WPvivid_Setting::get_option('wpvivid_need_review');
353
  if($need_review=='not')
354
  {
375
  {
376
  $request_page='wpvivid_tab_general';
377
 
378
+ if(isset($_REQUEST['wpvivid-remote-page-mainwp'])){
379
+ $request_page='wpvivid_tab_remote_storage';
380
+ }
381
  if(isset($_REQUEST['tab-backup']))
382
  {
383
  $request_page='wpvivid_tab_general';
admin/partials/wpvivid-settings-page-display.php CHANGED
@@ -454,6 +454,7 @@ function wpvivid_export_import_settings()
454
  try {
455
  var jsonarray = jQuery.parseJSON(data);
456
  if (jsonarray.result === 'success') {
 
457
  location.reload();
458
  }
459
  else {
454
  try {
455
  var jsonarray = jQuery.parseJSON(data);
456
  if (jsonarray.result === 'success') {
457
+ alert('The plugin settings is imported successfully.');
458
  location.reload();
459
  }
460
  else {
includes/class-wpvivid-backup-uploader.php CHANGED
@@ -15,6 +15,7 @@ class Wpvivid_BackupUploader
15
 
16
  add_action('wp_ajax_wpvivid_rescan_local_folder',array($this,'rescan_local_folder_set_backup'));
17
  add_action('wp_ajax_wpvivid_get_backup_count',array($this,'get_backup_count'));
 
18
  }
19
 
20
  function get_file_id()
@@ -274,10 +275,99 @@ class Wpvivid_BackupUploader
274
  @closedir($handler);
275
  }
276
 
277
- function rescan_local_folder_set_backup()
278
- {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
  $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR;
280
 
 
 
281
  $backups=array();
282
  $count = 0;
283
  if(is_dir($path))
@@ -317,7 +407,6 @@ class Wpvivid_BackupUploader
317
  $ret['result']=WPVIVID_FAILED;
318
  $ret['error']='Failed to get local storage directory.';
319
  }
320
-
321
  if(!empty($backups))
322
  {
323
  foreach ($backups as $backup_id =>$backup)
@@ -365,10 +454,20 @@ class Wpvivid_BackupUploader
365
  $tour = true;
366
  $html = apply_filters('wpvivid_add_backup_list', $html, 'wpvivid_backup_list', $tour);
367
  $ret['html'] = $html;
 
 
 
 
 
 
368
  echo json_encode($ret);
369
  die();
370
  }
371
 
 
 
 
 
372
  static function rescan_local_folder()
373
  {
374
  $backupdir=WPvivid_Setting::get_backupdir();
15
 
16
  add_action('wp_ajax_wpvivid_rescan_local_folder',array($this,'rescan_local_folder_set_backup'));
17
  add_action('wp_ajax_wpvivid_get_backup_count',array($this,'get_backup_count'));
18
+ add_action('wpvivid_rebuild_backup_list', array($this, 'wpvivid_rebuild_backup_list'), 10);
19
  }
20
 
21
  function get_file_id()
275
  @closedir($handler);
276
  }
277
 
278
+ function wpvivid_check_remove_update_backup($path){
279
+ $backup_list = WPvivid_Setting::get_option('wpvivid_backup_list');
280
+ $remove_backup_array = array();
281
+ $update_backup_array = array();
282
+ $tmp_file_array = array();
283
+ $remote_backup_list=WPvivid_Backuplist::get_has_remote_backuplist();
284
+ foreach ($backup_list as $key => $value){
285
+ if(!in_array($key, $remote_backup_list)) {
286
+ $need_remove = true;
287
+ $need_update = false;
288
+ if (is_dir($path)) {
289
+ $handler = opendir($path);
290
+ while (($filename = readdir($handler)) !== false) {
291
+ if ($filename != "." && $filename != "..") {
292
+ if (!is_dir($path . $filename)) {
293
+ if ($this->check_wpvivid_file_info($filename, $backup_id, $need_update)) {
294
+ if ($key === $backup_id) {
295
+ $need_remove = false;
296
+ }
297
+ if ($need_update) {
298
+ if ($this->check_is_a_wpvivid_backup($path . $filename) === true) {
299
+ if (!in_array($filename, $tmp_file_array)) {
300
+ $add_file['file_name'] = $filename;
301
+ $add_file['size'] = filesize($path . $filename);
302
+ $tmp_file_array[] = $filename;
303
+ $update_backup_array[$backup_id]['files'][] = $add_file;
304
+ }
305
+ }
306
+ }
307
+ }
308
+ }
309
+ }
310
+ }
311
+ if ($handler) {
312
+ @closedir($handler);
313
+ }
314
+ }
315
+ if ($need_remove) {
316
+ $remove_backup_array[] = $key;
317
+ }
318
+ }
319
+ }
320
+ $this->wpvivid_remove_update_local_backup_list($remove_backup_array, $update_backup_array);
321
+ return true;
322
+ }
323
+
324
+ function check_wpvivid_file_info($file_name, &$backup_id, &$need_update=false){
325
+ if(preg_match('/wpvivid-.*_.*_.*\.zip$/',$file_name))
326
+ {
327
+ if(preg_match('/wpvivid-(.*?)_/',$file_name,$matches))
328
+ {
329
+ $id= $matches[0];
330
+ $id=substr($id,0,strlen($id)-1);
331
+ $backup_id=$id;
332
+
333
+ if(WPvivid_Backuplist::get_backup_by_id($id)===false)
334
+ {
335
+ $need_update = false;
336
+ return true;
337
+ }
338
+ else
339
+ {
340
+ $need_update = true;
341
+ return true;
342
+ }
343
+ }
344
+ else
345
+ {
346
+ return false;
347
+ }
348
+ }
349
+ else
350
+ {
351
+ return false;
352
+ }
353
+ }
354
+
355
+ function wpvivid_remove_update_local_backup_list($remove_backup_array, $update_backup_array){
356
+ $backup_list = WPvivid_Setting::get_option('wpvivid_backup_list');
357
+ foreach ($remove_backup_array as $remove_backup_id){
358
+ unset($backup_list[$remove_backup_id]);
359
+ }
360
+ foreach ($update_backup_array as $update_backup_id => $data){
361
+ $backup_list[$update_backup_id]['backup']['files'] = $data['files'];
362
+ }
363
+ WPvivid_Setting::update_option('wpvivid_backup_list', $backup_list);
364
+ }
365
+
366
+ function _rescan_local_folder_set_backup(){
367
  $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR;
368
 
369
+ $this->wpvivid_check_remove_update_backup($path);
370
+
371
  $backups=array();
372
  $count = 0;
373
  if(is_dir($path))
407
  $ret['result']=WPVIVID_FAILED;
408
  $ret['error']='Failed to get local storage directory.';
409
  }
 
410
  if(!empty($backups))
411
  {
412
  foreach ($backups as $backup_id =>$backup)
454
  $tour = true;
455
  $html = apply_filters('wpvivid_add_backup_list', $html, 'wpvivid_backup_list', $tour);
456
  $ret['html'] = $html;
457
+ return $ret;
458
+ }
459
+
460
+ function rescan_local_folder_set_backup()
461
+ {
462
+ $ret = $this->_rescan_local_folder_set_backup();
463
  echo json_encode($ret);
464
  die();
465
  }
466
 
467
+ public function wpvivid_rebuild_backup_list(){
468
+ $this->_rescan_local_folder_set_backup();
469
+ }
470
+
471
  static function rescan_local_folder()
472
  {
473
  $backupdir=WPvivid_Setting::get_backupdir();
includes/class-wpvivid-backup.php CHANGED
@@ -166,6 +166,7 @@ class WPvivid_Backup_Task
166
  else {
167
  $this->task['options']['backup_options']['ismerge']=1;
168
  }
 
169
 
170
  $this->task['options']['log_file_name']=$id.'_backup';
171
  $log=new WPvivid_Log();
@@ -295,10 +296,10 @@ class WPvivid_Backup_Task
295
  //$backup_data['root_path']=WP_CONTENT_DIR;
296
  $backup_data['root_flag']=WPVIVID_BACKUP_ROOT_WP_CONTENT;
297
  $backup_data['prefix']=$this->get_prefix().'_backup_plugin';
298
- if(isset($backup_data['compress']['subpackage_plugin_upload'])&&$backup_data['compress']['subpackage_plugin_upload'])
299
- {
300
- $backup_data['plugin_subpackage']=1;
301
- }
302
  $backup_data['files_root']=$this->transfer_path(WP_PLUGIN_DIR);
303
 
304
  $exclude_plugins[]='wpvivid-backuprestore';
@@ -374,6 +375,7 @@ class WPvivid_Backup_Task
374
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'plugins', '/').'#';
375
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'cache', '/').'#';
376
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'Dropbox_Backup', '/').'#';
 
377
  $upload_dir = wp_upload_dir();
378
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']), '/').'#';
379
  $exclude_regex[]='#^'.preg_quote($this->transfer_path(get_theme_root()), '/').'#';
@@ -783,12 +785,6 @@ class WPvivid_Backup_Task
783
  {
784
  $files[] = $path . DIRECTORY_SEPARATOR . $filename;
785
  }
786
- else
787
- {
788
- global $wpvivid_plugin;
789
- $wpvivid_plugin->wpvivid_log->WriteLog('file not readable:' . $path . DIRECTORY_SEPARATOR . $filename, 'notice');
790
- }
791
-
792
  } else {
793
  if(is_readable($path . DIRECTORY_SEPARATOR . $filename))
794
  {
@@ -796,11 +792,6 @@ class WPvivid_Backup_Task
796
  $files[] = $path . DIRECTORY_SEPARATOR . $filename;
797
  }
798
  }
799
- else
800
- {
801
- global $wpvivid_plugin;
802
- $wpvivid_plugin->wpvivid_log->WriteLog('file not readable:' . $path . DIRECTORY_SEPARATOR . $filename, 'notice');
803
- }
804
  }
805
  }
806
  }
@@ -1294,11 +1285,6 @@ class WPvivid_Backup_Task
1294
  {
1295
  $files[] = $path . DIRECTORY_SEPARATOR . $filename;
1296
  }
1297
- else
1298
- {
1299
- global $wpvivid_plugin;
1300
- $wpvivid_plugin->wpvivid_log->WriteLog('file not readable:' . $path . DIRECTORY_SEPARATOR . $filename, 'notice');
1301
- }
1302
  } else {
1303
  if(is_readable($path . DIRECTORY_SEPARATOR . $filename))
1304
  {
@@ -1307,11 +1293,6 @@ class WPvivid_Backup_Task
1307
  $files[] = $path . DIRECTORY_SEPARATOR . $filename;
1308
  }
1309
  }
1310
- else
1311
- {
1312
- global $wpvivid_plugin;
1313
- $wpvivid_plugin->wpvivid_log->WriteLog('file not readable:' . $path . DIRECTORY_SEPARATOR . $filename, 'notice');
1314
- }
1315
  }
1316
  }
1317
  }
@@ -2152,6 +2133,40 @@ class WPvivid_Backup_Item
2152
  }
2153
  return $ret;
2154
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2155
  }
2156
 
2157
  class WPvivid_Backup
@@ -2387,7 +2402,94 @@ class WPvivid_Backup
2387
 
2388
  public function clearcache()
2389
  {
2390
- WPvivid_tools::clearcache($this->task->get_prefix());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2391
  }
2392
 
2393
  public function clean_remote_backup($remotes,$files)
166
  else {
167
  $this->task['options']['backup_options']['ismerge']=1;
168
  }
169
+ $this->task['options']['backup_options']['ismerge']=apply_filters('wpvivid_set_backup_ismerge',$this->task['options']['backup_options']['ismerge'],$options);
170
 
171
  $this->task['options']['log_file_name']=$id.'_backup';
172
  $log=new WPvivid_Log();
296
  //$backup_data['root_path']=WP_CONTENT_DIR;
297
  $backup_data['root_flag']=WPVIVID_BACKUP_ROOT_WP_CONTENT;
298
  $backup_data['prefix']=$this->get_prefix().'_backup_plugin';
299
+ //if(isset($backup_data['compress']['subpackage_plugin_upload'])&&$backup_data['compress']['subpackage_plugin_upload'])
300
+ //{
301
+ // $backup_data['plugin_subpackage']=1;
302
+ //}
303
  $backup_data['files_root']=$this->transfer_path(WP_PLUGIN_DIR);
304
 
305
  $exclude_plugins[]='wpvivid-backuprestore';
375
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'plugins', '/').'#';
376
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'cache', '/').'#';
377
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'Dropbox_Backup', '/').'#';
378
+ $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'mysql.sql', '/').'#';//mysql
379
  $upload_dir = wp_upload_dir();
380
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']), '/').'#';
381
  $exclude_regex[]='#^'.preg_quote($this->transfer_path(get_theme_root()), '/').'#';
785
  {
786
  $files[] = $path . DIRECTORY_SEPARATOR . $filename;
787
  }
 
 
 
 
 
 
788
  } else {
789
  if(is_readable($path . DIRECTORY_SEPARATOR . $filename))
790
  {
792
  $files[] = $path . DIRECTORY_SEPARATOR . $filename;
793
  }
794
  }
 
 
 
 
 
795
  }
796
  }
797
  }
1285
  {
1286
  $files[] = $path . DIRECTORY_SEPARATOR . $filename;
1287
  }
 
 
 
 
 
1288
  } else {
1289
  if(is_readable($path . DIRECTORY_SEPARATOR . $filename))
1290
  {
1293
  $files[] = $path . DIRECTORY_SEPARATOR . $filename;
1294
  }
1295
  }
 
 
 
 
 
1296
  }
1297
  }
1298
  }
2133
  }
2134
  return $ret;
2135
  }
2136
+
2137
+ public function cleanup_local_backup()
2138
+ {
2139
+ $files=array();
2140
+ $download_dir=$this->config['local']['path'];
2141
+ $file=$this->get_files(false);
2142
+
2143
+ foreach ($file as $filename)
2144
+ {
2145
+ $files[] = $filename;
2146
+ }
2147
+
2148
+ foreach ($files as $file)
2149
+ {
2150
+ $download_path = WP_CONTENT_DIR .DIRECTORY_SEPARATOR . $download_dir . DIRECTORY_SEPARATOR . $file;
2151
+ if (file_exists($download_path))
2152
+ {
2153
+ @unlink($download_path);
2154
+ }
2155
+ }
2156
+ }
2157
+
2158
+ public function cleanup_remote_backup()
2159
+ {
2160
+ if(!empty($this->config['remote']))
2161
+ {
2162
+ $files=$this->get_files(false);
2163
+
2164
+ foreach($this->config['remote'] as $remote)
2165
+ {
2166
+ WPvivid_downloader::delete($remote,$files);
2167
+ }
2168
+ }
2169
+ }
2170
  }
2171
 
2172
  class WPvivid_Backup
2402
 
2403
  public function clearcache()
2404
  {
2405
+ $task_id=$this->task->get_prefix();
2406
+ $path = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir();
2407
+ $handler=opendir($path);
2408
+ while(($filename=readdir($handler))!==false)
2409
+ {
2410
+ if(is_dir($path.DIRECTORY_SEPARATOR.$filename) && preg_match('#temp-'.$task_id.'#',$filename))
2411
+ {
2412
+ $this->deldir($path.DIRECTORY_SEPARATOR.$filename,'',true);
2413
+ }
2414
+ if(is_dir($path.DIRECTORY_SEPARATOR.$filename) && preg_match('#temp-'.$task_id.'#',$filename))
2415
+ {
2416
+ $this->deldir($path.DIRECTORY_SEPARATOR.$filename,'',true);
2417
+ }
2418
+ if(preg_match('#pclzip-.*\.tmp#', $filename)){
2419
+ @unlink($path.DIRECTORY_SEPARATOR.$filename);
2420
+ }
2421
+ if(preg_match('#pclzip-.*\.gz#', $filename)){
2422
+ @unlink($path.DIRECTORY_SEPARATOR.$filename);
2423
+ }
2424
+ }
2425
+ @closedir($handler);
2426
+ }
2427
+
2428
+ public function deldir($path,$exclude=array(),$flag = false)
2429
+ {
2430
+ if(!is_dir($path))
2431
+ {
2432
+ return ;
2433
+ }
2434
+ $handler=opendir($path);
2435
+ if(empty($handler))
2436
+ return ;
2437
+ while(($filename=readdir($handler))!==false)
2438
+ {
2439
+ if($filename != "." && $filename != "..")
2440
+ {
2441
+ if(is_dir($path.DIRECTORY_SEPARATOR.$filename)){
2442
+ if(empty($exclude)||$this->regex_match($exclude['directory'],$path.DIRECTORY_SEPARATOR.$filename ,0)){
2443
+ $this->deldir( $path.DIRECTORY_SEPARATOR.$filename ,$exclude, $flag);
2444
+ @rmdir( $path.DIRECTORY_SEPARATOR.$filename );
2445
+ }
2446
+ }else{
2447
+ if(empty($exclude)||$this->regex_match($exclude['file'],$path.DIRECTORY_SEPARATOR.$filename ,0)){
2448
+ @unlink($path.DIRECTORY_SEPARATOR.$filename);
2449
+ }
2450
+ }
2451
+ }
2452
+ }
2453
+ if($handler)
2454
+ @closedir($handler);
2455
+ if($flag)
2456
+ @rmdir($path);
2457
+ }
2458
+
2459
+ public function regex_match($regex_array,$string,$mode)
2460
+ {
2461
+ if(empty($regex_array))
2462
+ {
2463
+ return true;
2464
+ }
2465
+
2466
+ if($mode==0)
2467
+ {
2468
+ foreach ($regex_array as $regex)
2469
+ {
2470
+ if(preg_match($regex,$string))
2471
+ {
2472
+ return false;
2473
+ }
2474
+ }
2475
+
2476
+ return true;
2477
+ }
2478
+
2479
+ if($mode==1)
2480
+ {
2481
+ foreach ($regex_array as $regex)
2482
+ {
2483
+ if(preg_match($regex,$string))
2484
+ {
2485
+ return true;
2486
+ }
2487
+ }
2488
+
2489
+ return false;
2490
+ }
2491
+
2492
+ return true;
2493
  }
2494
 
2495
  public function clean_remote_backup($remotes,$files)
includes/class-wpvivid-backuplist.php CHANGED
@@ -180,17 +180,21 @@ class WPvivid_Backuplist
180
  return $list;
181
  }
182
 
183
- public static function get_oldest_backup_id($list){
184
- $oldest_id='not set';
 
185
  $oldest=0;
186
  foreach ($list as $k=>$backup)
187
  {
188
- if(!array_key_exists('lock',$backup)) {
189
- if ($oldest == 0) {
 
 
190
  $oldest = $backup['create_time'];
191
  $oldest_id = $k;
192
  } else {
193
- if ($oldest > $backup['create_time']) {
 
194
  $oldest_id = $k;
195
  }
196
  }
@@ -205,15 +209,20 @@ class WPvivid_Backuplist
205
  $size=sizeof($list);
206
  if($size>=$max_count)
207
  {
208
- $ret['result']='need_delete';
209
  $oldest_id=self::get_oldest_backup_id($list);
210
- $ret['oldest_id']=$oldest_id;
 
 
 
 
 
 
 
211
  }
212
  else
213
  {
214
- $ret['result']='ok';
215
  }
216
- return $ret;
217
  }
218
 
219
  public static function get_out_of_date_backuplist($max_count)
@@ -229,7 +238,7 @@ class WPvivid_Backuplist
229
  {
230
  $oldest_id=self::get_oldest_backup_id($list);
231
 
232
- if($oldest_id!='not set')
233
  {
234
  $out_of_date_list[]=$oldest_id;
235
  unset($list[$oldest_id]);
@@ -262,7 +271,7 @@ class WPvivid_Backuplist
262
  {
263
  $oldest_id=self::get_oldest_backup_id($list);
264
 
265
- if($oldest_id!='not set')
266
  {
267
  $out_of_date_list['size']+=self::get_size($oldest_id);
268
  $out_of_date_list['count']++;
180
  return $list;
181
  }
182
 
183
+ public static function get_oldest_backup_id($list)
184
+ {
185
+ $oldest_id='';
186
  $oldest=0;
187
  foreach ($list as $k=>$backup)
188
  {
189
+ if(!array_key_exists('lock',$backup))
190
+ {
191
+ if ($oldest == 0)
192
+ {
193
  $oldest = $backup['create_time'];
194
  $oldest_id = $k;
195
  } else {
196
+ if ($oldest > $backup['create_time'])
197
+ {
198
  $oldest_id = $k;
199
  }
200
  }
209
  $size=sizeof($list);
210
  if($size>=$max_count)
211
  {
 
212
  $oldest_id=self::get_oldest_backup_id($list);
213
+ if(empty($oldest_id))
214
+ {
215
+ return false;
216
+ }
217
+ else
218
+ {
219
+ return $oldest_id;
220
+ }
221
  }
222
  else
223
  {
224
+ return false;
225
  }
 
226
  }
227
 
228
  public static function get_out_of_date_backuplist($max_count)
238
  {
239
  $oldest_id=self::get_oldest_backup_id($list);
240
 
241
+ if(!empty($oldest_id))
242
  {
243
  $out_of_date_list[]=$oldest_id;
244
  unset($list[$oldest_id]);
271
  {
272
  $oldest_id=self::get_oldest_backup_id($list);
273
 
274
+ if(!empty($oldest_id))
275
  {
276
  $out_of_date_list['size']+=self::get_size($oldest_id);
277
  $out_of_date_list['count']++;
includes/class-wpvivid-backuptoremote.php CHANGED
@@ -3,7 +3,7 @@
3
  if (!defined('WPVIVID_PLUGIN_DIR')){
4
  die;
5
  }
6
- require_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-tools.php';
7
  require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-ftpclass.php';
8
  require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-sftpclass.php';
9
  require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-amazons3-plus.php';
3
  if (!defined('WPVIVID_PLUGIN_DIR')){
4
  die;
5
  }
6
+
7
  require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-ftpclass.php';
8
  require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-sftpclass.php';
9
  require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-amazons3-plus.php';
includes/class-wpvivid-downloader.php CHANGED
@@ -3,8 +3,6 @@
3
  if (!defined('WPVIVID_PLUGIN_DIR')){
4
  die;
5
  }
6
- //include_once plugin_dir_path( __FILE__ ) .'class-wpvivid-tools.php';
7
- //include_once plugin_dir_path( __FILE__ ) .'phpseclib/Net/SCP.php';
8
 
9
  class WPvivid_downloader
10
  {
@@ -72,7 +70,7 @@ class WPvivid_downloader
72
  {
73
  if(filesize($local_file)>$file_info['size'])
74
  {
75
- unlink($local_file);
76
  }
77
  $need_download_files[$file_info['file_name']]=$file_info;
78
  }
3
  if (!defined('WPVIVID_PLUGIN_DIR')){
4
  die;
5
  }
 
 
6
 
7
  class WPvivid_downloader
8
  {
70
  {
71
  if(filesize($local_file)>$file_info['size'])
72
  {
73
+ @unlink($local_file);
74
  }
75
  $need_download_files[$file_info['file_name']]=$file_info;
76
  }
includes/class-wpvivid-exporter.php CHANGED
@@ -1085,6 +1085,20 @@ class WPvivid_Exporter_task
1085
  }
1086
  }
1087
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1088
  $sum_attachment_ids=array_merge($sum_attachment_ids,$attachment_ids);
1089
 
1090
  foreach ($attachment_ids as $attachment_id)
1085
  }
1086
  }
1087
 
1088
+ //_thumbnail_id
1089
+ $_thumbnail_id=get_post_meta($id,'_thumbnail_id',true);
1090
+ if($_thumbnail_id!=false)
1091
+ {
1092
+ if(!in_array($_thumbnail_id,$attachment_added_ids))
1093
+ {
1094
+ if(!is_null(get_post($_thumbnail_id)))
1095
+ {
1096
+ $attachment_ids[] = $_thumbnail_id;
1097
+ $attachment_added_ids[]=$_thumbnail_id;
1098
+ }
1099
+ }
1100
+ }
1101
+
1102
  $sum_attachment_ids=array_merge($sum_attachment_ids,$attachment_ids);
1103
 
1104
  foreach ($attachment_ids as $attachment_id)
includes/class-wpvivid-interface-mainwp.php ADDED
@@ -0,0 +1,509 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class WPvivid_Interface_MainWP
4
+ {
5
+ public function __construct(){
6
+ $this->load_wpvivid_mainwp_backup_filter();
7
+ $this->load_wpvivid_mainwp_side_bar_filter();
8
+ $this->load_wpvivid_mainwp_backup_list_filter();
9
+ $this->load_wpvivid_mainwp_schedule_filter();
10
+ $this->load_wpvivid_mainwp_setting_filter();
11
+ $this->load_wpvivid_mainwp_remote_filter();
12
+ }
13
+
14
+ public function load_wpvivid_mainwp_backup_filter(){
15
+ add_filter('wpvivid_get_status_mainwp', array($this, 'wpvivid_get_status_mainwp'));
16
+ add_filter('wpvivid_get_backup_list_mainwp', array($this, 'wpvivid_get_backup_list_mainwp'));
17
+ add_filter('wpvivid_get_backup_schedule_mainwp', array($this, 'wpvivid_get_backup_schedule_mainwp'));
18
+ add_filter('wpvivid_get_default_remote_mainwp', array($this, 'wpvivid_get_default_remote_mainwp'));
19
+ add_filter('wpvivid_prepare_backup_mainwp', array($this, 'wpvivid_prepare_backup_mainwp'));
20
+ add_filter('wpvivid_backup_now_mainwp', array($this, 'wpvivid_backup_now_mainwp'));
21
+ add_filter('wpvivid_view_backup_task_log_mainwp', array($this, 'wpvivid_view_backup_task_log_mainwp'));
22
+ add_filter('wpvivid_backup_cancel_mainwp', array($this, 'wpvivid_backup_cancel_mainwp'));
23
+ }
24
+
25
+ public function load_wpvivid_mainwp_side_bar_filter(){
26
+ add_filter('wpvivid_read_last_backup_log_mainwp', array($this, 'wpvivid_read_last_backup_log_mainwp'));
27
+ }
28
+
29
+ public function load_wpvivid_mainwp_backup_list_filter(){
30
+ add_filter('wpvivid_set_security_lock_mainwp', array($this, 'wpvivid_set_security_lock_mainwp'));
31
+ add_filter('wpvivid_view_log_mainwp', array($this, 'wpvivid_view_log_mainwp'));
32
+ add_filter('wpvivid_init_download_page_mainwp', array($this, 'wpvivid_init_download_page_mainwp'));
33
+ add_filter('wpvivid_prepare_download_backup_mainwp', array($this, 'wpvivid_prepare_download_backup_mainwp'));
34
+ add_filter('wpvivid_get_download_task_mainwp', array($this, 'wpvivid_get_download_task_mainwp'));
35
+ add_filter('wpvivid_download_backup_mainwp', array($this, 'wpvivid_download_backup_mainwp'));
36
+ add_filter('wpvivid_delete_backup_mainwp', array($this, 'wpvivid_delete_backup_mainwp'));
37
+ add_filter('wpvivid_delete_backup_array_mainwp', array($this, 'wpvivid_delete_backup_array_mainwp'));
38
+ }
39
+
40
+ public function load_wpvivid_mainwp_schedule_filter(){
41
+ add_filter('wpvivid_set_schedule_mainwp', array($this, 'wpvivid_set_schedule_mainwp'));
42
+ }
43
+
44
+ public function load_wpvivid_mainwp_setting_filter(){
45
+ add_filter('wpvivid_set_general_setting_mainwp', array($this, 'wpvivid_set_general_setting_mainwp'));
46
+ }
47
+
48
+ public function load_wpvivid_mainwp_remote_filter(){
49
+ add_filter('wpvivid_set_remote_mainwp', array($this, 'wpvivid_set_remote_mainwp'));
50
+ }
51
+
52
+ public function wpvivid_get_status_mainwp($data){
53
+ $ret['result']='success';
54
+ $list_tasks=array();
55
+ $tasks=WPvivid_Setting::get_tasks();
56
+ foreach ($tasks as $task)
57
+ {
58
+ $backup = new WPvivid_Backup_Task($task['id']);
59
+ $list_tasks[$task['id']]=$backup->get_backup_task_info($task['id']);
60
+ if($list_tasks[$task['id']]['task_info']['need_update_last_task']===true){
61
+ $task_msg = WPvivid_taskmanager::get_task($task['id']);
62
+ WPvivid_Setting::update_option('wpvivid_last_msg',$task_msg);
63
+ }
64
+ }
65
+ $ret['wpvivid']['task']=$list_tasks;
66
+ $backuplist=WPvivid_Backuplist::get_backuplist();
67
+ $schedule=WPvivid_Schedule::get_schedule();
68
+ $ret['wpvivid']['backup_list']=$backuplist;
69
+ $ret['wpvivid']['schedule']=$schedule;
70
+ $ret['wpvivid']['schedule']['last_message']=WPvivid_Setting::get_last_backup_message('wpvivid_last_msg');
71
+ WPvivid_taskmanager::delete_marked_task();
72
+ return $ret;
73
+ }
74
+
75
+ public function wpvivid_get_backup_list_mainwp($data){
76
+ $backuplist=WPvivid_Backuplist::get_backuplist();
77
+ $ret['result']='success';
78
+ $ret['wpvivid']['backup_list']=$backuplist;
79
+ return $ret;
80
+ }
81
+
82
+ public function wpvivid_get_backup_schedule_mainwp($data){
83
+ $schedule=WPvivid_Schedule::get_schedule();
84
+ $ret['result']='success';
85
+ $ret['wpvivid']['schedule']=$schedule;
86
+ $ret['wpvivid']['schedule']['last_message']=WPvivid_Setting::get_last_backup_message('wpvivid_last_msg');
87
+ return $ret;
88
+ }
89
+
90
+ public function wpvivid_get_default_remote_mainwp($data){
91
+ global $wpvivid_plugin;
92
+ $ret['result']='success';
93
+ $ret['remote_storage_type']=$wpvivid_plugin->function_realize->_get_default_remote_storage();
94
+ return $ret;
95
+ }
96
+
97
+ public function wpvivid_prepare_backup_mainwp($data){
98
+ $backup_options = $data['backup'];
99
+ global $wpvivid_plugin;
100
+ if(isset($backup_options)&&!empty($backup_options)){
101
+ if (is_null($backup_options)) {
102
+ $ret['error']='Invalid parameter param:'.$backup_options;
103
+ return $ret;
104
+ }
105
+ $backup_options = apply_filters('wpvivid_custom_backup_options', $backup_options);
106
+
107
+ if(!isset($backup_options['type']))
108
+ {
109
+ $backup_options['type']='Manual';
110
+ $backup_options['action']='backup';
111
+ }
112
+ $ret = $wpvivid_plugin->check_backup_option($backup_options, $backup_options['type']);
113
+ if($ret['result']!='success') {
114
+ return $ret;
115
+ }
116
+ $ret=$wpvivid_plugin->pre_backup($backup_options);
117
+ if($ret['result']=='success') {
118
+ //Check the website data to be backed up
119
+ $ret['check']=$wpvivid_plugin->check_backup($ret['task_id'],$backup_options);
120
+ if(isset($ret['check']['result']) && $ret['check']['result'] == 'failed') {
121
+ $ret['error']=$ret['check']['error'];
122
+ return $ret;
123
+ }
124
+ }
125
+ }
126
+ else{
127
+ $ret['error']='Error occurred while parsing the request data. Please try to run backup again.';
128
+ return $ret;
129
+ }
130
+ return $ret;
131
+ }
132
+
133
+ public function wpvivid_backup_now_mainwp($data){
134
+ $task_id = $data['task_id'];
135
+ global $wpvivid_plugin;
136
+ if (!isset($task_id)||empty($task_id)||!is_string($task_id))
137
+ {
138
+ $ret['error']=__('Error occurred while parsing the request data. Please try to run backup again.', 'wpvivid');
139
+ return $ret;
140
+ }
141
+ $task_id=sanitize_key($task_id);
142
+ $ret['result']='success';
143
+ $txt = '<mainwp>' . base64_encode( serialize( $ret ) ) . '</mainwp>';
144
+ // Close browser connection so that it can resume AJAX polling
145
+ header( 'Content-Length: ' . ( ( ! empty( $txt ) ) ? strlen( $txt ) : '0' ) );
146
+ header( 'Connection: close' );
147
+ header( 'Content-Encoding: none' );
148
+ if ( session_id() ) {
149
+ session_write_close();
150
+ }
151
+ echo $txt;
152
+ // These two added - 19-Feb-15 - started being required on local dev machine, for unknown reason (probably some plugin that started an output buffer).
153
+ if ( ob_get_level() ) {
154
+ ob_end_flush();
155
+ }
156
+ flush();
157
+
158
+ //Start backup site
159
+ $wpvivid_plugin->backup($task_id);
160
+ $ret['result']='success';
161
+ }
162
+
163
+ public function wpvivid_view_backup_task_log_mainwp($data){
164
+ $backup_task_id = $data['id'];
165
+ global $wpvivid_plugin;
166
+ if (!isset($backup_task_id)||empty($backup_task_id)||!is_string($backup_task_id)){
167
+ $ret['error']='Reading the log failed. Please try again.';
168
+ return $ret;
169
+ }
170
+ $backup_task_id = sanitize_key($backup_task_id);
171
+ $ret=$wpvivid_plugin->function_realize->_get_log_file('tasklog', $backup_task_id);
172
+ if($ret['result'] == 'success') {
173
+ $file = fopen($ret['log_file'], 'r');
174
+ if (!$file) {
175
+ $ret['result'] = 'failed';
176
+ $ret['error'] = __('Unable to open the log file.', 'wpvivid');
177
+ return $ret;
178
+ }
179
+ $buffer = '';
180
+ while (!feof($file)) {
181
+ $buffer .= fread($file, 1024);
182
+ }
183
+ fclose($file);
184
+ $ret['result'] = 'success';
185
+ $ret['data'] = $buffer;
186
+ }
187
+ else{
188
+ $ret['error']='Unknown error';
189
+ }
190
+ return $ret;
191
+ }
192
+
193
+ public function wpvivid_backup_cancel_mainwp($data){
194
+ global $wpvivid_plugin;
195
+ $ret=$wpvivid_plugin->function_realize->_backup_cancel();
196
+ return $ret;
197
+ }
198
+
199
+ public function wpvivid_read_last_backup_log_mainwp($data){
200
+ $log_file_name = $data['log_file_name'];
201
+ global $wpvivid_plugin;
202
+ if(!isset($log_file_name)||empty($log_file_name)||!is_string($log_file_name))
203
+ {
204
+ $ret['result']='failed';
205
+ $ret['error']=__('Reading the log failed. Please try again.', 'wpvivid');
206
+ return $ret;
207
+ }
208
+ $log_file_name=sanitize_text_field($log_file_name);
209
+ $ret=$wpvivid_plugin->function_realize->_get_log_file('lastlog', $log_file_name);
210
+ if($ret['result'] == 'success') {
211
+ $file = fopen($ret['log_file'], 'r');
212
+ if (!$file) {
213
+ $ret['result'] = 'failed';
214
+ $ret['error'] = __('Unable to open the log file.', 'wpvivid');
215
+ return $ret;
216
+ }
217
+ $buffer = '';
218
+ while (!feof($file)) {
219
+ $buffer .= fread($file, 1024);
220
+ }
221
+ fclose($file);
222
+ $ret['result'] = 'success';
223
+ $ret['data'] = $buffer;
224
+ }
225
+ else{
226
+ $ret['error']='Unknown error';
227
+ }
228
+ return $ret;
229
+ }
230
+
231
+ public function wpvivid_set_security_lock_mainwp($data){
232
+ $backup_id = $data['backup_id'];
233
+ $lock = $data['lock'];
234
+ if(!isset($backup_id)||empty($backup_id)||!is_string($backup_id)){
235
+ $ret['error']='Backup id not found';
236
+ return $ret;
237
+ }
238
+ if(!isset($lock)){
239
+ $ret['error']='Invalid parameter param: lock';
240
+ return $ret;
241
+ }
242
+ $backup_id=sanitize_key($backup_id);
243
+ if($lock==0||$lock==1) {
244
+ }
245
+ else {
246
+ $lock=0;
247
+ }
248
+ WPvivid_Backuplist::set_security_lock($backup_id,$lock);
249
+ $backuplist=WPvivid_Backuplist::get_backuplist();
250
+ $ret['wpvivid']['backup_list']=$backuplist;
251
+ return $ret;
252
+ }
253
+
254
+ public function wpvivid_view_log_mainwp($data){
255
+ $backup_id = $data['id'];
256
+ global $wpvivid_plugin;
257
+ if (!isset($backup_id)||empty($backup_id)||!is_string($backup_id)){
258
+ $ret['error']='Backup id not found';
259
+ return $ret;
260
+ }
261
+ $backup_id=sanitize_key($backup_id);
262
+ $ret=$wpvivid_plugin->function_realize->_get_log_file('backuplist', $backup_id);
263
+ if($ret['result'] == 'success') {
264
+ $file = fopen($ret['log_file'], 'r');
265
+ if (!$file) {
266
+ $ret['result'] = 'failed';
267
+ $ret['error'] = __('Unable to open the log file.', 'wpvivid');
268
+ return $ret;
269
+ }
270
+ $buffer = '';
271
+ while (!feof($file)) {
272
+ $buffer .= fread($file, 1024);
273
+ }
274
+ fclose($file);
275
+ $ret['data'] = $buffer;
276
+ }
277
+ else{
278
+ $ret['error']='Unknown error';
279
+ }
280
+ return $ret;
281
+ }
282
+
283
+ public function wpvivid_init_download_page_mainwp($data){
284
+ $backup_id = $data['backup_id'];
285
+ global $wpvivid_plugin;
286
+ if(!isset($backup_id)||empty($backup_id)||!is_string($backup_id)) {
287
+ $ret['error']='Invalid parameter param:'.$backup_id;
288
+ return $ret;
289
+ }
290
+ else {
291
+ $backup_id=sanitize_key($backup_id);
292
+ return $wpvivid_plugin->init_download($backup_id);
293
+ }
294
+ }
295
+
296
+ public function wpvivid_prepare_download_backup_mainwp($data){
297
+ $backup_id = $data['backup_id'];
298
+ $file_name = $data['file_name'];
299
+ if(!isset($backup_id)||empty($backup_id)||!is_string($backup_id))
300
+ {
301
+ $ret['error']='Invalid parameter param:'.$backup_id;
302
+ return $ret;
303
+ }
304
+ if(!isset($file_name)||empty($file_name)||!is_string($file_name))
305
+ {
306
+ $ret['error']='Invalid parameter param:'.$file_name;
307
+ return $ret;
308
+ }
309
+ $download_info=array();
310
+ $download_info['backup_id']=sanitize_key($backup_id);
311
+ $download_info['file_name'] = $file_name;
312
+
313
+ @set_time_limit(600);
314
+ if (session_id())
315
+ session_write_close();
316
+ try
317
+ {
318
+ $downloader=new WPvivid_downloader();
319
+ $downloader->ready_download($download_info);
320
+ }
321
+ catch (Exception $e)
322
+ {
323
+ $message = 'A exception ('.get_class($e).') occurred '.$e->getMessage().' (Code: '.$e->getCode().', line '.$e->getLine().' in '.$e->getFile().')';
324
+ error_log($message);
325
+ return array('error'=>$message);
326
+ }
327
+ catch (Error $e)
328
+ {
329
+ $message = 'A error ('.get_class($e).') has occurred: '.$e->getMessage().' (Code: '.$e->getCode().', line '.$e->getLine().' in '.$e->getFile().')';
330
+ error_log($message);
331
+ return array('error'=>$message);
332
+ }
333
+
334
+ $ret['result']='success';
335
+ return $ret;
336
+ }
337
+
338
+ public function wpvivid_get_download_task_mainwp($data){
339
+ $backup_id = $data['backup_id'];
340
+ if(!isset($backup_id)||empty($backup_id)||!is_string($backup_id)) {
341
+ $ret['error']='Invalid parameter param:'.$backup_id;
342
+ return $ret;
343
+ }
344
+ else {
345
+ $backup = WPvivid_Backuplist::get_backup_by_id($backup_id);
346
+ if ($backup === false) {
347
+ $ret['result'] = WPVIVID_FAILED;
348
+ $ret['error'] = 'backup id not found';
349
+ return $ret;
350
+ }
351
+ $backup_item = new WPvivid_Backup_Item($backup);
352
+ $ret = $backup_item->update_download_page($backup_id);
353
+ return $ret;
354
+ }
355
+ }
356
+
357
+ public function wpvivid_download_backup_mainwp($data){
358
+ $backup_id = $data['backup_id'];
359
+ $file_name = $data['file_name'];
360
+ global $wpvivid_plugin;
361
+ if(!isset($backup_id)||empty($backup_id)||!is_string($backup_id)) {
362
+ $ret['error']='Invalid parameter param: backup_id';
363
+ return $ret;
364
+ }
365
+ if(!isset($file_name)||empty($file_name)||!is_string($file_name)) {
366
+ $ret['error']='Invalid parameter param: file_name';
367
+ return $ret;
368
+ }
369
+ $backup_id=sanitize_key($backup_id);
370
+ $cache=WPvivid_taskmanager::get_download_cache($backup_id);
371
+ if($cache===false) {
372
+ $wpvivid_plugin->init_download($backup_id);
373
+ $cache=WPvivid_taskmanager::get_download_cache($backup_id);
374
+ }
375
+ $path=false;
376
+ if(array_key_exists($file_name,$cache['files'])) {
377
+ if($cache['files'][$file_name]['status']=='completed') {
378
+ $path=$cache['files'][$file_name]['download_path'];
379
+ $download_url = $cache['files'][$file_name]['download_url'];
380
+ }
381
+ }
382
+ if($path!==false) {
383
+ if (file_exists($path)) {
384
+ $ret['download_url'] = $download_url;
385
+ $ret['size'] = filesize($path);
386
+ }
387
+ }
388
+ return $ret;
389
+ }
390
+
391
+ public function wpvivid_delete_backup_mainwp($data){
392
+ $backup_id = $data['backup_id'];
393
+ $force_del = $data['force'];
394
+ global $wpvivid_plugin;
395
+ if(!isset($backup_id)||empty($backup_id)||!is_string($backup_id)) {
396
+ $ret['error']='Invalid parameter param: backup_id.';
397
+ return $ret;
398
+ }
399
+ if(!isset($force_del)){
400
+ $ret['error']='Invalid parameter param: force.';
401
+ return $ret;
402
+ }
403
+ if($force_del==0||$force_del==1) {
404
+ }
405
+ else {
406
+ $force_del=0;
407
+ }
408
+ $backup_id=sanitize_key($backup_id);
409
+ $ret=$wpvivid_plugin->delete_backup_by_id($backup_id, $force_del);
410
+ $backuplist=WPvivid_Backuplist::get_backuplist();
411
+ $ret['wpvivid']['backup_list']=$backuplist;
412
+ return $ret;
413
+ }
414
+
415
+ public function wpvivid_delete_backup_array_mainwp($data){
416
+ $backup_id_array = $data['backup_id'];
417
+ global $wpvivid_plugin;
418
+ if(!isset($backup_id_array)||empty($backup_id_array)||!is_array($backup_id_array)) {
419
+ $ret['error']='Invalid parameter param: backup_id';
420
+ return $ret;
421
+ }
422
+ $ret=array();
423
+ foreach($backup_id_array as $backup_id)
424
+ {
425
+ $backup_id=sanitize_key($backup_id);
426
+ $ret=$wpvivid_plugin->delete_backup_by_id($backup_id);
427
+ }
428
+ $backuplist=WPvivid_Backuplist::get_backuplist();
429
+ $ret['wpvivid']['backup_list']=$backuplist;
430
+ return $ret;
431
+ }
432
+
433
+ public function wpvivid_set_schedule_mainwp($data){
434
+ $schedule = $data['schedule'];
435
+ $ret=array();
436
+ try {
437
+ if(isset($schedule)&&!empty($schedule)) {
438
+ $json = $schedule;
439
+ $json = stripslashes($json);
440
+ $schedule = json_decode($json, true);
441
+ if (is_null($schedule)) {
442
+ $ret['error']='bad parameter';
443
+ return $ret;
444
+ }
445
+ $ret=WPvivid_Schedule::set_schedule_ex($schedule);
446
+ if($ret['result']!='success') {
447
+ return $ret;
448
+ }
449
+ }
450
+ $ret['result']='success';
451
+ }
452
+ catch (Exception $error) {
453
+ $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
454
+ error_log($message);
455
+ return array('error'=>$message);
456
+ }
457
+ return $ret;
458
+ }
459
+
460
+ public function wpvivid_set_general_setting_mainwp($data){
461
+ $setting = $data['setting'];
462
+ $ret=array();
463
+ try {
464
+ if(isset($setting)&&!empty($setting)) {
465
+ $json_setting = $setting;
466
+ $json_setting = stripslashes($json_setting);
467
+ $setting = json_decode($json_setting, true);
468
+ if (is_null($setting)) {
469
+ $ret['error']='bad parameter';
470
+ return $ret;
471
+ }
472
+ WPvivid_Setting::update_setting($setting);
473
+ }
474
+
475
+ $ret['result']='success';
476
+ }
477
+ catch (Exception $error) {
478
+ $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
479
+ error_log($message);
480
+ return array('error'=>$message);
481
+ }
482
+ return $ret;
483
+ }
484
+
485
+ public function wpvivid_set_remote_mainwp($data){
486
+ $remote = $data['remote'];
487
+ global $wpvivid_plugin;
488
+ $ret=array();
489
+ try {
490
+ if(isset($remote)&&!empty($remote)) {
491
+ $json = $remote;
492
+ $json = stripslashes($json);
493
+ $remote = json_decode($json, true);
494
+ if (is_null($remote)) {
495
+ $ret['error']='bad parameter';
496
+ return $ret;
497
+ }
498
+ $wpvivid_plugin->function_realize->_set_remote($remote);
499
+ }
500
+ $ret['result']='success';
501
+ }
502
+ catch (Exception $error) {
503
+ $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
504
+ error_log($message);
505
+ return array('error'=>$message);
506
+ }
507
+ return $ret;
508
+ }
509
+ }
includes/class-wpvivid-public-interface.php CHANGED
@@ -9,99 +9,11 @@ class WPvivid_Public_Interface
9
 
10
  public function mainwp_data($data){
11
  $action = sanitize_text_field($data['mwp_action']);
12
- switch ($action)
13
- {
14
- case 'create_schedule_addon':
15
- $ret = apply_filters('wpvivid_create_schedule_addon_mainwp', $data['schedule']);
16
- break;
17
- case 'get_schedules_addon':
18
- $ret = apply_filters('wpvivid_get_schedules_addon_mainwp', array());
19
- break;
20
- case 'delete_schedules_addon':
21
- $ret = apply_filters('wpvivid_delete_schedule_addon_mainwp', $data['schedule_id']);
22
- break;
23
- case 'save_schedule_status_addon':
24
- $ret = apply_filters('wpvivid_save_schedule_status_addon_mainwp', $data['schedule_data']);
25
- break;
26
- case 'update_schedule_addon':
27
- $ret = apply_filters('wpvivid_update_schedule_addon_mainwp', $data['schedule']);
28
- break;
29
- case 'set_schedule_addon':
30
- $ret = apply_filters('wpvivid_sync_schedule_addon_mainwp', $data['schedule']);
31
- break;
32
- case 'get_database_tables':
33
- $ret = apply_filters('wpvivid_get_database_tables_mainwp', array());
34
- break;
35
- case 'get_themes_plugins':
36
- $ret = apply_filters('wpvivid_get_themes_plugins_mainwp', array());
37
- break;
38
- case 'get_uploads_tree_data':
39
- $ret = apply_filters('wpvivid_get_uploads_tree_data_mainwp', $data['tree_node']);
40
- break;
41
- case 'get_content_tree_data':
42
- $ret = apply_filters('wpvivid_get_content_tree_data_mainwp', $data['tree_node']);
43
- break;
44
- case 'get_additional_folder_tree_data':
45
- $ret = apply_filters('wpvivid_get_additional_folder_tree_data_mainwp', $data['tree_node']);
46
- break;
47
- case 'achieve_local_backup_addon':
48
- $ret = apply_filters('wpvivid_achieve_local_backup_addon_mainwp', $data);
49
- break;
50
- case 'achieve_remote_backup_addon':
51
- $ret = apply_filters('wpvivid_achieve_remote_backup_addon_mainwp', $data);
52
- break;
53
- case 'connect_additional_database_addon':
54
- $ret = apply_filters('wpvivid_connect_additional_database_addon_mainwp', $data);
55
- break;
56
- case 'add_additional_database_addon':
57
- $ret = apply_filters('wpvivid_add_additional_database_addon_mainwp', $data);
58
- break;
59
- case 'remove_additional_database_addon':
60
- $ret = apply_filters('wpvivid_remove_additional_database_addon_mainwp', $data);
61
- break;
62
- case 'prepare_backup_addon':
63
- $ret = apply_filters('wpvivid_prepare_backup_addon_mainwp', $data);
64
- break;
65
- case 'backup_now_addon':
66
- $ret = apply_filters('wpvivid_backup_now_addon_mainwp', $data['task_id']);
67
- break;
68
- case 'list_tasks_addon':
69
- $ret = apply_filters('wpvivid_list_tasks_addon_mainwp', array());
70
- break;
71
- case 'init_download_page_addon':
72
- $ret = apply_filters('wpvivid_init_download_page_addon_mainwp', $data['backup_id']);
73
- break;
74
- case 'get_download_progress_addon':
75
- $ret = apply_filters('wpvivid_get_download_progress_addon_mainwp', $data['backup_id']);
76
- break;
77
- case 'rescan_local_folder_addon':
78
- $ret = apply_filters('wpvivid_rescan_local_folder_addon_mainwp', array());
79
- break;
80
- case 'set_security_lock_addon':
81
- $ret = apply_filters('wpvivid_set_security_lock_addon_mainwp', $data);
82
- break;
83
- case 'set_remote_security_lock_addon':
84
- $ret = apply_filters('wpvivid_set_remote_security_lock_addon_mainwp', $data);
85
- break;
86
- case 'delete_local_backup_addon':
87
- $ret = apply_filters('wpvivid_delete_local_backup_addon_mainwp', $data);
88
- break;
89
- case 'delete_local_backup_array_addon':
90
- $ret = apply_filters('wpvivid_delete_local_backup_array_addon_mainwp', $data);
91
- break;
92
- case 'delete_remote_backup_addon':
93
- $ret = apply_filters('wpvivid_delete_remote_backup_addon_mainwp', $data);
94
- break;
95
- case 'delete_remote_backup_array_addon':
96
- $ret = apply_filters('wpvivid_delete_remote_backup_array_addon_mainwp', $data);
97
- break;
98
- case 'view_log_addon':
99
- $ret = apply_filters('wpvivid_view_log_addon_mainwp', $data);
100
- break;
101
- default:
102
- $ret['result'] = 'failed';
103
- $ret['error'] = 'Unknown action';
104
- break;
105
  }
106
  return $ret;
107
  }
@@ -365,12 +277,6 @@ class WPvivid_Public_Interface
365
 
366
  public function backup_cancel($task_id = ''){
367
  global $wpvivid_plugin;
368
- /*if (!isset($task_id)||empty($task_id)||!is_string($task_id)){
369
- $ret['error']='Backup id not found';
370
- return $ret;
371
- }
372
- $task_id=sanitize_key($task_id);
373
- $ret=$wpvivid_plugin->function_realize->_backup_cancel($task_id);*/
374
  $ret=$wpvivid_plugin->function_realize->_backup_cancel();
375
  return $ret;
376
  }
9
 
10
  public function mainwp_data($data){
11
  $action = sanitize_text_field($data['mwp_action']);
12
+ if (has_filter($action)) {
13
+ $ret = apply_filters($action, $data);
14
+ } else {
15
+ $ret['result'] = WPVIVID_FAILED;
16
+ $ret['error'] = 'Unknown function';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  }
18
  return $ret;
19
  }
277
 
278
  public function backup_cancel($task_id = ''){
279
  global $wpvivid_plugin;
 
 
 
 
 
 
280
  $ret=$wpvivid_plugin->function_realize->_backup_cancel();
281
  return $ret;
282
  }
includes/class-wpvivid-restore-data.php CHANGED
@@ -6,24 +6,16 @@ if (!defined('WPVIVID_PLUGIN_DIR')){
6
  class WPvivid_restore_data
7
  {
8
  public $restore_data_file;
9
- private $rollback_file;
10
- private $rollback_data_file;
11
  public $restore_log_file;
12
  public $restore_log=false;
13
  public $restore_cache=false;
14
- private $rollback_log_file;
15
- private $rollback_log=false;
16
- private $rollback_cache=false;
17
 
18
 
19
  public function __construct()
20
  {
21
  $dir=WPvivid_Setting::get_backupdir();
22
  $this->restore_data_file= WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.'wpvivid_restoredata';
23
- $this->rollback_data_file= WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.WPVIVID_DEFAULT_ROLLBACK_DIR.DIRECTORY_SEPARATOR.'wpvivid_rollbackdata';
24
- $this->rollback_file= WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.WPVIVID_DEFAULT_ROLLBACK_DIR.DIRECTORY_SEPARATOR.'wpvivid_rollback';
25
  $this->restore_log_file= WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.'wpvivid_restore_log.txt';
26
- $this->rollback_log_file= WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.WPVIVID_DEFAULT_ROLLBACK_DIR.DIRECTORY_SEPARATOR.'wpvivid_rollback_log.txt';
27
  }
28
 
29
  public function has_restore()
@@ -38,40 +30,10 @@ class WPvivid_restore_data
38
  }
39
  }
40
 
41
- public function has_rollback()
42
- {
43
- if(file_exists($this->rollback_data_file))
44
- {
45
- return true;
46
- }
47
- else
48
- {
49
- return false;
50
- }
51
- }
52
-
53
- public function has_old_files()
54
- {
55
- if(file_exists(dirname($this -> rollback_file)))
56
- {
57
- return true;
58
- }
59
- else
60
- {
61
- return false;
62
- }
63
- }
64
-
65
- public function delete_old_files()
66
- {
67
- WPvivid_tools::deldir(dirname($this -> rollback_file),'',true);
68
- }
69
-
70
  public function delete_temp_files()
71
  {
72
  $backup=$this->get_backup_data();
73
  $backup_item=new WPvivid_Backup_Item($backup);
74
-
75
  foreach($this->restore_cache['restore_tasks'] as $index => $task)
76
  {
77
  if(isset($task['option'])&&isset($task['option']['has_child']))
@@ -99,11 +61,13 @@ class WPvivid_restore_data
99
  foreach ($temp_files as $delete_file)
100
  {
101
  $path= $backup_item->get_local_path().$delete_file['file_name'];
102
- $this->write_log('clean file:'.$path,'notice');
103
- @unlink($path);
 
 
 
104
  }
105
  }
106
- break;
107
  }
108
  }
109
  }
@@ -158,12 +122,6 @@ class WPvivid_restore_data
158
 
159
  WPvivid_tools::file_put_array($data,$this->restore_data_file);
160
  $this->restore_cache=$data;
161
- $rollback_data = require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-rollback-template.php';
162
- $rollback_data['task_id'] = $backup_id;
163
- WPvivid_tools::deldir(dirname($this -> rollback_file));
164
- if(!file_exists(dirname($this -> rollback_file)))
165
- mkdir(dirname($this -> rollback_file));
166
- WPvivid_tools::file_put_array($rollback_data,$this->rollback_file);
167
  }
168
 
169
  public function get_restore_option()
@@ -175,15 +133,6 @@ class WPvivid_restore_data
175
  return $this->restore_cache['restore_options'];
176
  }
177
 
178
- public function init_rollback_data()
179
- {
180
- $this->rollback_log=new WPvivid_Log();
181
- $this->rollback_log->CreateLogFile($this->rollback_log_file,'has_folder','rollback');
182
- $rollback_data=WPvivid_tools::file_get_array($this->rollback_file);
183
- WPvivid_tools::file_put_array($rollback_data,$this->rollback_data_file);
184
- $this->rollback_cache=$rollback_data;
185
- }
186
-
187
  public function get_restore_status()
188
  {
189
  if($this->restore_cache===false)
@@ -200,22 +149,6 @@ class WPvivid_restore_data
200
  }
201
  }
202
 
203
- public function get_rollback_status()
204
- {
205
- if($this->rollback_cache===false)
206
- {
207
- $this->rollback_cache=WPvivid_tools::file_get_array($this->rollback_data_file);
208
- }
209
- if(empty($this->rollback_cache))
210
- {
211
- return WPVIVID_RESTORE_ERROR;
212
- }
213
- else
214
- {
215
- return $this->rollback_cache['status'];
216
- }
217
- }
218
-
219
  public function get_restore_error()
220
  {
221
  if($this->restore_cache===false)
@@ -233,32 +166,11 @@ class WPvivid_restore_data
233
 
234
  }
235
 
236
- public function get_rollback_error()
237
- {
238
- if($this->rollback_cache===false)
239
- {
240
- $this->rollback_cache=WPvivid_tools::file_get_array($this->rollback_data_file);
241
- }
242
- if(empty( $this->rollback_cache))
243
- {
244
- return array('task_name'=>'file','error'=>'Rollback data file not found, it may be deleted. Please verify the file exists.');
245
- }
246
- else
247
- {
248
- return array('task_name'=> $this->rollback_cache['error_task'],'error'=> $this->rollback_cache['error']);
249
- }
250
- }
251
-
252
  public function clean_restore_data()
253
  {
254
  @unlink($this->restore_data_file);
255
  }
256
 
257
- public function clean_rollback_data()
258
- {
259
- @unlink($this->rollback_data_file);
260
- }
261
-
262
  public function write_log($message,$type)
263
  {
264
  if($this->restore_log===false)
@@ -295,17 +207,6 @@ class WPvivid_restore_data
295
  WPvivid_error_log::create_restore_error_log($this->restore_log->log_file);
296
  }
297
 
298
- public function write_rollback_log($message,$type)
299
- {
300
- if($this->rollback_log===false)
301
- {
302
- $this->rollback_log=new WPvivid_Log();
303
- $this->rollback_log->OpenLogFile($this->rollback_log_file,'has_folder');
304
- }
305
-
306
- $this->rollback_log->WriteLog($message,$type);
307
- }
308
-
309
  public function get_log_content()
310
  {
311
  $file =fopen($this->restore_log_file,'r');
@@ -325,25 +226,6 @@ class WPvivid_restore_data
325
  return $buffer;
326
  }
327
 
328
- public function get_rollback_log_content()
329
- {
330
- $file =fopen($this->rollback_log_file,'r');
331
-
332
- if(!$file)
333
- {
334
- return '';
335
- }
336
-
337
- $buffer='';
338
- while(!feof($file))
339
- {
340
- $buffer .= fread($file,1024);
341
- }
342
- fclose($file);
343
-
344
- return $buffer;
345
- }
346
-
347
  public function get_log_handle()
348
  {
349
  if($this->restore_log===false)
@@ -414,39 +296,6 @@ class WPvivid_restore_data
414
  return $next_task;
415
  }
416
 
417
- public function get_next_rollback_task()
418
- {
419
- $next_task=false;
420
- if($this->rollback_cache===false)
421
- {
422
- $this->rollback_cache=WPvivid_tools::file_get_array($this->rollback_data_file);
423
- }
424
-
425
- foreach($this->rollback_cache['data'] as $task_type => $task)
426
- {
427
- if($task['status'] === WPVIVID_RESTORE_READY)
428
- {
429
- $next_task=$task;
430
- $this->rollback_cache['status'] = WPVIVID_RESTORE_RUNNING;
431
- $this->rollback_cache['data'][$task_type]['status'] = WPVIVID_RESTORE_RUNNING;
432
- $this->rollback_cache['data'][$task_type]['time']['start'] = time();
433
- WPvivid_tools::file_put_array($this->rollback_cache,$this->rollback_data_file);
434
- break;
435
- }
436
- else if($task['status'] === WPVIVID_RESTORE_RUNNING)
437
- {
438
- $next_task=WPVIVID_RESTORE_RUNNING;
439
- break;
440
- }
441
- else if($task['status'] === WPVIVID_RESTORE_COMPLETED)
442
- {
443
- continue;
444
- }
445
- }
446
-
447
- return $next_task;
448
- }
449
-
450
  public function update_error($error,$error_task='',$table=array())
451
  {
452
  if($this->restore_cache===false)
@@ -471,30 +320,6 @@ class WPvivid_restore_data
471
  WPvivid_tools::file_put_array($this->restore_cache,$this->restore_data_file);
472
  }
473
 
474
- public function update_rollback_error($error,$error_task='',$table=array())
475
- {
476
- if($this->rollback_cache===false)
477
- {
478
- $this->rollback_cache=WPvivid_tools::file_get_array($this->rollback_data_file);
479
- }
480
- $this->rollback_cache['status'] = WPVIVID_RESTORE_ERROR;
481
- $this->rollback_cache['error'] = $error;
482
- if($error_task!='')
483
- {
484
- $this->rollback_cache['data'][$error_task]['time']['end'] = time();
485
- $this->rollback_cache['data'][$error_task]['status'] = WPVIVID_RESTORE_ERROR;
486
- $this->rollback_cache['data'][$error_task]['return'] = $error;
487
- $this->rollback_cache['error_task'] = $error_task;
488
- if(!empty($table))
489
- {
490
- $this->rollback_cache['data'][$error_task]['table']['succeed'] = empty($table['succeed'])?0:$table['succeed'];
491
- $this->rollback_cache['data'][$error_task]['table']['failed'] = empty($table['failed'])?0:$table['failed'];
492
- $this->rollback_cache['data'][$error_task]['table']['unfinished'] = empty($table['unfinished'])?0:$table['unfinished'];
493
- }
494
- }
495
- WPvivid_tools::file_put_array($this->rollback_cache,$this->rollback_data_file);
496
- }
497
-
498
  public function update_status($status)
499
  {
500
  if($this->restore_cache===false)
@@ -506,17 +331,6 @@ class WPvivid_restore_data
506
  WPvivid_tools::file_put_array($this->restore_cache,$this->restore_data_file);
507
  }
508
 
509
- public function update_rollback_status($status)
510
- {
511
- if($this->rollback_cache===false)
512
- {
513
- $this->rollback_cache=WPvivid_tools::file_get_array($this->rollback_data_file);
514
- }
515
-
516
- $this->rollback_cache['status'] = $status;
517
- WPvivid_tools::file_put_array($this->rollback_cache,$this->rollback_data_file);
518
- }
519
-
520
  public function update_sub_task($task_index,$result)
521
  {
522
  if($this->restore_cache===false)
@@ -547,36 +361,6 @@ class WPvivid_restore_data
547
  WPvivid_tools::file_put_array($this->restore_cache,$this->restore_data_file);
548
  }
549
 
550
- public function update_rollback_sub_task_completed($task_type,$return,$table=array())
551
- {
552
- if($this->rollback_cache===false)
553
- {
554
- $this->rollback_cache=WPvivid_tools::file_get_array($this->rollback_data_file);
555
- }
556
-
557
- $this->rollback_cache['data'][$task_type]['time']['end'] = time();
558
- $this->rollback_cache['data'][$task_type]['status'] = WPVIVID_RESTORE_COMPLETED;
559
- $this->rollback_cache['data'][$task_type]['return'] = $return;
560
- $this->rollback_cache['status'] = WPVIVID_RESTORE_RUNNING;
561
- if(!empty($table)){
562
- $this->rollback_cache['data'][$task_type]['table']['succeed'] = empty($table['succeed'])?0:$table['succeed'];
563
- $this->rollback_cache['data'][$task_type]['table']['failed'] = empty($table['failed'])?0:$table['failed'];
564
- $this->rollback_cache['data'][$task_type]['table']['unfinished'] = empty($table['unfinished'])?0:$table['unfinished'];
565
- }
566
- WPvivid_tools::file_put_array($this->rollback_cache,$this->rollback_cache);
567
- }
568
-
569
- public function set_rollback_data($type_name,$task_id,$data)
570
- {
571
- $rollback_data=WPvivid_tools::file_get_array($this->rollback_file);
572
-
573
- $rollback_data['data'][$type_name]['status'] = WPVIVID_RESTORE_READY;
574
- $rollback_data['data'][$type_name]['task_id'] = $task_id;
575
- $rollback_data['data'][$type_name]['type_name'] = $type_name;
576
- $rollback_data['data'][$type_name]['data'] = $data;
577
- WPvivid_tools::file_put_array($rollback_data,$this->rollback_file);
578
- }
579
-
580
  public function get_need_unzip_file($restore_task)
581
  {
582
  $files=array();
6
  class WPvivid_restore_data
7
  {
8
  public $restore_data_file;
 
 
9
  public $restore_log_file;
10
  public $restore_log=false;
11
  public $restore_cache=false;
 
 
 
12
 
13
 
14
  public function __construct()
15
  {
16
  $dir=WPvivid_Setting::get_backupdir();
17
  $this->restore_data_file= WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.'wpvivid_restoredata';
 
 
18
  $this->restore_log_file= WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.'wpvivid_restore_log.txt';
 
19
  }
20
 
21
  public function has_restore()
30
  }
31
  }
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  public function delete_temp_files()
34
  {
35
  $backup=$this->get_backup_data();
36
  $backup_item=new WPvivid_Backup_Item($backup);
 
37
  foreach($this->restore_cache['restore_tasks'] as $index => $task)
38
  {
39
  if(isset($task['option'])&&isset($task['option']['has_child']))
61
  foreach ($temp_files as $delete_file)
62
  {
63
  $path= $backup_item->get_local_path().$delete_file['file_name'];
64
+ if(file_exists($path))
65
+ {
66
+ $this->write_log('clean file:'.$path,'notice');
67
+ @unlink($path);
68
+ }
69
  }
70
  }
 
71
  }
72
  }
73
  }
122
 
123
  WPvivid_tools::file_put_array($data,$this->restore_data_file);
124
  $this->restore_cache=$data;
 
 
 
 
 
 
125
  }
126
 
127
  public function get_restore_option()
133
  return $this->restore_cache['restore_options'];
134
  }
135
 
 
 
 
 
 
 
 
 
 
136
  public function get_restore_status()
137
  {
138
  if($this->restore_cache===false)
149
  }
150
  }
151
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  public function get_restore_error()
153
  {
154
  if($this->restore_cache===false)
166
 
167
  }
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  public function clean_restore_data()
170
  {
171
  @unlink($this->restore_data_file);
172
  }
173
 
 
 
 
 
 
174
  public function write_log($message,$type)
175
  {
176
  if($this->restore_log===false)
207
  WPvivid_error_log::create_restore_error_log($this->restore_log->log_file);
208
  }
209
 
 
 
 
 
 
 
 
 
 
 
 
210
  public function get_log_content()
211
  {
212
  $file =fopen($this->restore_log_file,'r');
226
  return $buffer;
227
  }
228
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229
  public function get_log_handle()
230
  {
231
  if($this->restore_log===false)
296
  return $next_task;
297
  }
298
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299
  public function update_error($error,$error_task='',$table=array())
300
  {
301
  if($this->restore_cache===false)
320
  WPvivid_tools::file_put_array($this->restore_cache,$this->restore_data_file);
321
  }
322
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
323
  public function update_status($status)
324
  {
325
  if($this->restore_cache===false)
331
  WPvivid_tools::file_put_array($this->restore_cache,$this->restore_data_file);
332
  }
333
 
 
 
 
 
 
 
 
 
 
 
 
334
  public function update_sub_task($task_index,$result)
335
  {
336
  if($this->restore_cache===false)
361
  WPvivid_tools::file_put_array($this->restore_cache,$this->restore_data_file);
362
  }
363
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
364
  public function get_need_unzip_file($restore_task)
365
  {
366
  $files=array();
includes/class-wpvivid-restore-database.php CHANGED
@@ -7,7 +7,6 @@ require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-zip
7
  require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-backup-database.php';
8
  require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-backup-site.php';
9
  require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-setting.php';
10
- require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-rollback.php';
11
  class WPvivid_RestoreDB
12
  {
13
  private $support_engines;
@@ -803,8 +802,7 @@ class WPvivid_RestoreDB
803
  for ($current_row = $start_row; $current_row <= $count; $current_row += $page)
804
  {
805
  $wpvivid_plugin->restore_data->write_log('Replace the row in '.$current_row. ' line.', 'notice');
806
- $end_row=$current_row+$page;
807
- $query = 'SELECT * FROM `'.$table_name.'` LIMIT '.$current_row.', '.$end_row;
808
 
809
  $result=$this->db_method->query($query,ARRAY_A);
810
  if($result && sizeof($result)>0)
@@ -1182,7 +1180,7 @@ class WPvivid_RestoreDB
1182
  //$old_string=str_replace($remove_http_link,$new_remove_http_link,$old_string);
1183
  }
1184
 
1185
- $new_mix_link=$this->get_mix_link($this->new_site_url);
1186
  if($new_mix_link!==false)
1187
  {
1188
  $from[]=$new_mix_link;
7
  require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-backup-database.php';
8
  require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-backup-site.php';
9
  require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-setting.php';
 
10
  class WPvivid_RestoreDB
11
  {
12
  private $support_engines;
802
  for ($current_row = $start_row; $current_row <= $count; $current_row += $page)
803
  {
804
  $wpvivid_plugin->restore_data->write_log('Replace the row in '.$current_row. ' line.', 'notice');
805
+ $query = 'SELECT * FROM `'.$table_name.'` LIMIT '.$current_row.', '.$page;
 
806
 
807
  $result=$this->db_method->query($query,ARRAY_A);
808
  if($result && sizeof($result)>0)
1180
  //$old_string=str_replace($remove_http_link,$new_remove_http_link,$old_string);
1181
  }
1182
 
1183
+ $new_mix_link=$this->get_mix_link($this->old_site_url);
1184
  if($new_mix_link!==false)
1185
  {
1186
  $from[]=$new_mix_link;
includes/class-wpvivid-restore-site.php CHANGED
@@ -5,7 +5,6 @@ if (!defined('WPVIVID_PLUGIN_DIR')){
5
  }
6
  include_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-zipclass.php';
7
  include_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-backup.php';
8
- include_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-rollback.php';
9
  class WPvivid_RestoreSite
10
  {
11
 
5
  }
6
  include_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-zipclass.php';
7
  include_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-backup.php';
 
8
  class WPvivid_RestoreSite
9
  {
10
 
includes/class-wpvivid-rollback-template.php DELETED
@@ -1,12 +0,0 @@
1
- <?php
2
-
3
- if (!defined('WPVIVID_PLUGIN_DIR')){
4
- die;
5
- }
6
- return array(
7
- 'task_id' => '',
8
- 'data' => array(),
9
- 'state' => WPVIVID_RESTORE_INIT,
10
- 'error' => '',
11
- 'error_task' => ''
12
- );
 
 
 
 
 
 
 
 
 
 
 
 
includes/class-wpvivid-rollback.php DELETED
@@ -1,281 +0,0 @@
1
- <?php
2
-
3
- if (!defined('WPVIVID_PLUGIN_DIR')){
4
- die;
5
- }
6
- include_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-restore-site.php';
7
- include_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-restore-database.php';
8
- include_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-tools.php';
9
- class WPvivid_RollBack
10
- {
11
- private $restore_data;
12
-
13
- public function rollback()
14
- {
15
- @set_time_limit(1800);
16
-
17
- $old_path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_DEFAULT_ROLLBACK_DIR;
18
-
19
- if(!file_exists($old_path))
20
- {
21
- return array('result'=>WPVIVID_RESTORE_COMPLETED);
22
- }
23
-
24
- $old_db_path=$old_path.DIRECTORY_SEPARATOR.'wpvivid_old_database'.DIRECTORY_SEPARATOR.'old_database.sql';
25
-
26
- if(file_exists($old_db_path))
27
- {
28
- $rollback_db=new WPvivid_RestoreDB();
29
- $options['skip_backup_old_site']=1;
30
- $options['skip_backup_old_database']=1;
31
- $rollback_db->restore($old_path.DIRECTORY_SEPARATOR.'wpvivid_old_database'.DIRECTORY_SEPARATOR,'old_database.sql',$options);
32
- }
33
-
34
- $old_site_path=$old_path.DIRECTORY_SEPARATOR.'wpvivid_old_site';
35
-
36
- if(file_exists($old_site_path))
37
- {
38
- $this->rollback_old_site($old_site_path);
39
- }
40
-
41
- return array('result'=>WPVIVID_RESTORE_COMPLETED);
42
-
43
- $this->restore_data=new WPvivid_restore_data();
44
-
45
- $next_task=$this->restore_data->get_next_rollback_task();
46
- if($next_task===false)
47
- {
48
- $this->restore_data->write_rollback_log('Rollback task completed.','notice');
49
- $this->restore_data->update_rollback_status(WPVIVID_RESTORE_COMPLETED);
50
- return array('result'=>WPVIVID_RESTORE_COMPLETED);
51
- }
52
- else if($next_task===WPVIVID_RESTORE_RUNNING)
53
- {
54
- $this->restore_data->write_rollback_log('A rollback task is already running.','error');
55
- return array('result'=>WPVIVID_RESTORE_RUNNING);
56
- }
57
- else
58
- {
59
- @set_time_limit(600);
60
- $this->restore_data->write_rollback_log('Start rollbacking '.$next_task['type_name'],'notice');
61
- $result = $this -> single_rollback($next_task);
62
- $table=array();
63
- if(!empty($result['table']))
64
- $table = $result['table'];
65
- if($result['result'] != WPVIVID_SUCCESS)
66
- {
67
- $this->restore_data->write_rollback_log($result['error'],'error');
68
- $this->restore_data->update_rollback_error($result,$next_task['type_name'],$table);
69
- return array('result'=>WPVIVID_RESTORE_ERROR,'error'=>array('task_name'=>$next_task['type_name'],'error'=>$result['error']));
70
- }
71
- else
72
- {
73
- $this->restore_data->write_rollback_log($next_task['type_name'].' rollback finished.','notice');
74
- $this->restore_data->update_rollback_sub_task_completed($next_task['type_name'],$result,$table);
75
- $this->restore_data->update_rollback_status(WPVIVID_RESTORE_WAIT);
76
- return array('result'=> WPVIVID_RESTORE_COMPLETED);
77
- }
78
- }
79
- }
80
-
81
- public function single_rollback($data)
82
- {
83
- if($data['type_name'] == WPVIVID_BACKUP_TYPE_DB || $data['type_name'] == WPVIVID_BACKUP_TYPE_OPTIONS)
84
- {
85
- $result = $this -> rollback_db($data);
86
- }else{
87
- $result = $this -> rollback_copy($data);
88
- }
89
- return $result;
90
- }
91
-
92
- private function rollback_old_site($old_site_path)
93
- {
94
- $replace_path=$old_site_path;
95
- $this->move_restore_file($old_site_path, get_home_path(),$replace_path);
96
- }
97
-
98
- private function move_restore_file($source_path,$destination,$replace_path)
99
- {
100
- $result = array('result'=>WPVIVID_SUCCESS);
101
-
102
- $handler=opendir($source_path);
103
- while(($filename=readdir($handler))!==false)
104
- {
105
- if($filename != "." && $filename != "..")
106
- {
107
- if(is_dir($source_path.DIRECTORY_SEPARATOR.$filename))
108
- {
109
- $this->move_restore_file($source_path.DIRECTORY_SEPARATOR.$filename,$destination,$replace_path);
110
- }else {
111
- $path=str_replace($replace_path,$destination,$source_path.DIRECTORY_SEPARATOR);
112
- if(file_exists($path))
113
- {
114
- @mkdir($path);
115
- }
116
- @copy($source_path.DIRECTORY_SEPARATOR.$filename,$path.DIRECTORY_SEPARATOR.$filename);
117
- }
118
- }
119
- }
120
- if($handler)
121
- @closedir($handler);
122
- return $result;
123
- }
124
- /*private function rollback_db($data){
125
- $this->restore_data->write_rollback_log('Start rollbacking database.','notice');
126
- $File = $data['data']['file'];
127
- if(!file_exists($File)){
128
- return array('result'=>WPVIVID_FAILED,'error'=>'The .sql file not found. Please try again later.');
129
- }
130
-
131
- $res = explode(':',DB_HOST);
132
- $db_host = $res[0];
133
- $db_port = empty($res[1])?'':$res[1];
134
- if(!empty($db_port))
135
- $db_host = $db_host.':'.$db_port;
136
- try{
137
- $pdo=new PDO('mysql:host=' . $db_host . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD );
138
- }catch (Exception $e)
139
- {
140
- if(!empty($db_port)){
141
- $db_host = $res[0];
142
- $pdo=new PDO('mysql:host=' . $db_host . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD );
143
- }
144
- if(empty($pdo) || !$pdo){
145
- 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.');
146
- }
147
- }
148
-
149
- $pdo -> query('SET NAMES utf8');
150
- $result = $this->rollback_db_file($pdo,$File);
151
- unset($pdo);
152
- return $result;
153
- }
154
- private function rollback_db_file($pdo,$File){
155
- global $wpdb;
156
- $prefix = $wpdb->base_prefix;
157
- $query = '';
158
- $tables = array();
159
- $errortables = array();
160
- $sqlhandle = fopen($File,'r');
161
-
162
- $backup_database = new WPvivid_Backup_Database();
163
- $privileges = $backup_database -> check_privilege('restore',$pdo);
164
- if($privileges['result'] == WPVIVID_FAILED){
165
- return $privileges;
166
- }else{
167
- $privileges = $privileges['data'];
168
- }
169
- $options = array();
170
- foreach ($privileges as $key => $value){
171
- if($value == 0){
172
- $options[] = $key;
173
- }
174
- }
175
-
176
- if(!empty($options))
177
- $this->restore_data->write_rollback_log('The lack of optional database privileges including '.implode(',',$options),'Notice');
178
-
179
- $success_num = 0;
180
- $error_num = 0;
181
- $line_num = 0;
182
- $error_info = array();
183
-
184
- $res = $pdo -> query('SELECT @@SESSION.sql_mode') -> fetchAll();
185
- $sql_mod = $res[0][0];
186
- $temp_sql_mode = str_replace('NO_ENGINE_SUBSTITUTION','',$sql_mod);
187
- $temp_sql_mode = 'NO_AUTO_VALUE_ON_ZERO,'.$temp_sql_mode;
188
- $pdo -> query('SET SESSION sql_mode = "'.$temp_sql_mode.'"');
189
-
190
- $data = $pdo -> query('select * from information_schema.tables WHERE table_schema = "'.DB_NAME.'"') -> fetchAll();
191
- foreach ($data as $item){
192
- if(preg_match('#'.$prefix.'#i',$item['TABLE_NAME'])){
193
- $tables[] = $item['TABLE_NAME'];
194
- }
195
- }
196
-
197
- if($tables){
198
- foreach ($tables as $table){
199
- if(!$pdo -> query('DROP TABLE '.$table))
200
- return array('result'=>WPVIVID_FAILED,'error' =>$pdo ->errorInfo());
201
- }
202
- }else{
203
- return array('result'=>WPVIVID_FAILED,'error'=>$pdo->errorInfo());
204
- }
205
-
206
- while(!feof($sqlhandle)) {
207
- $line = fgets($sqlhandle);
208
- $line_num ++;
209
- $startWith = substr(trim($line), 0 ,2);
210
- $endWith = substr(trim($line), -1 ,1);
211
-
212
- if (empty($line) || $startWith == '--' || $startWith == '/*' || $startWith == '//') {
213
- continue;
214
- }
215
-
216
- $query = $query . $line;
217
- if ($endWith == ';') {
218
- if(preg_match('#^\\s*LOCK TABLES#',$query) && $privileges['LOCK TABLES'] == 0){
219
- $this->restore_data->write_rollback_log('The lack of LOCK TABLES privilege, the backup will skip LOCK TABLES to continue.Notice at Line:'.$line_num,'notice');
220
- }else{
221
- if(!$result = $pdo -> query($query)){
222
- $error_num ++;
223
- $data = array('line'=>$line_num,'sql'=>$query,'error'=>$pdo->errorInfo());
224
- $this->restore_data->write_rollback_log('Restore '.basename($File).' error at line '.$line_num.','.PHP_EOL.'errorinfo: ['.implode('][',$pdo->errorInfo()).']','Warning');
225
- $error_info[] = $data;
226
- $query= '';
227
- continue;
228
- }
229
- $success_num ++;
230
- }
231
- $query= '';
232
- }
233
- }
234
- fclose($sqlhandle);
235
- $pdo -> query('SET SESSION sql_mode = "'.$sql_mod.'"');
236
-
237
- if($error_num > 0)
238
- {
239
- $this->restore_data->write_rollback_log('Database rollback error, '.$success_num.' succeeded, '.$error_num.' failed.','Warning');
240
- }else{
241
- $this->restore_data->write_rollback_log('Database rollback succeeded.','Notice');
242
- }
243
- return array('result'=>WPVIVID_SUCCESS,'meta'=>$error_info,'table'=>array('succeed'=>$success_num,'failed'=>$error_num));
244
- }
245
-
246
- private function rollback_copy($data){
247
- $src_path = $data['data']['src'];
248
- $dst_path = $data['data']['dst'];
249
- $replace_path = $data['data']['replace'];
250
- return $this -> _rollback_copy_loop($src_path,$dst_path,$replace_path);
251
- }
252
- private function _rollback_copy_loop($path,$temp_path,$replace_path){
253
- $result = array('result'=>WPVIVID_SUCCESS);
254
- if(empty($path)) {
255
- return array('result'=>'failed','error'=>'Failed to retrieve website\'s folder path. Please reinstall the plugin and try again.');
256
- }
257
- $handler=opendir($path);
258
- while(($filename=readdir($handler))!==false)
259
- {
260
- if($filename != "." && $filename != "..")
261
- {
262
- if(is_dir($path.DIRECTORY_SEPARATOR.$filename))
263
- {
264
- @mkdir(str_replace($replace_path,$temp_path,$path.DIRECTORY_SEPARATOR.$filename));
265
- $result = $this->_rollback_copy_loop($path.DIRECTORY_SEPARATOR.$filename,$temp_path,$replace_path);
266
- if($result['result'] != WPVIVID_SUCCESS)
267
- break;
268
- }else{
269
- if(!copy($path.DIRECTORY_SEPARATOR.$filename,str_replace($replace_path,$temp_path,$path.DIRECTORY_SEPARATOR.$filename))){
270
- $result = array('result'=>'failed','error'=>'Copying '.$path.DIRECTORY_SEPARATOR.$filename.' into '.$temp_path.DIRECTORY_SEPARATOR.$filename.' failed. Make sure the file isn\'t occupied, or the folder is writable.');
271
- break;
272
- }
273
- }
274
- }
275
- }
276
- if($handler)
277
- @closedir($handler);
278
- return $result;
279
- }
280
- */
281
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class-wpvivid-setting.php CHANGED
@@ -598,19 +598,43 @@ class WPvivid_Setting
598
 
599
  public static function get_sync_data()
600
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
601
  $data['setting']['wpvivid_compress_setting']=self::get_option('wpvivid_compress_setting');
602
  $data['setting']['wpvivid_local_setting']=self::get_option('wpvivid_local_setting');
603
  $data['setting']['wpvivid_common_setting']=self::get_option('wpvivid_common_setting');
604
  $data['setting']['wpvivid_email_setting']=self::get_option('wpvivid_email_setting');
605
  $data['setting']['cron_backup_count']=self::get_option('cron_backup_count');
606
 
 
 
 
607
  $data['schedule']=self::get_option('wpvivid_schedule_setting');
608
  $data['schedule_addon']=apply_filters('wpvivid_archieve_schedule_add_settings', array());
609
 
610
  $data['remote']['upload']=self::get_option('wpvivid_upload_setting');
611
  $data['remote']['history']=self::get_option('wpvivid_user_history');
612
 
613
- $data['backup_custom_setting']=apply_filters('wpvivid_get_backup_custom_setting', array());
 
 
614
  return $data;
615
  }
616
  }
598
 
599
  public static function get_sync_data()
600
  {
601
+ $wpvivid_info=apply_filters('wpvivid_get_wpvivid_info_addon_mainwp', false);
602
+ if(!$wpvivid_info){
603
+ $data['need_update']=false;
604
+ $data['current_version']='';
605
+ }
606
+ else{
607
+ $data['need_update']=$wpvivid_info['need_update'];
608
+ $data['current_version']=$wpvivid_info['current_version'];
609
+ }
610
+ $check_ret=apply_filters('wpvivid_check_is_pro_mainwp', false);
611
+ if(!$check_ret){
612
+ $data['is_pro']=false;
613
+ $data['latest_version']='';
614
+ }
615
+ else{
616
+ $data['is_pro']=$check_ret['check_pro'];
617
+ $data['latest_version']=$check_ret['latest_version'];
618
+ }
619
+ $data['time_zone']=apply_filters('wpvivid_get_time_zone_addon_mainwp', false);
620
  $data['setting']['wpvivid_compress_setting']=self::get_option('wpvivid_compress_setting');
621
  $data['setting']['wpvivid_local_setting']=self::get_option('wpvivid_local_setting');
622
  $data['setting']['wpvivid_common_setting']=self::get_option('wpvivid_common_setting');
623
  $data['setting']['wpvivid_email_setting']=self::get_option('wpvivid_email_setting');
624
  $data['setting']['cron_backup_count']=self::get_option('cron_backup_count');
625
 
626
+ $data['setting_addon'] = $data['setting'];
627
+ $data['setting_addon']['wpvivid_staging_options']=apply_filters('wpvivid_get_staging_setting_mainwp', array());
628
+
629
  $data['schedule']=self::get_option('wpvivid_schedule_setting');
630
  $data['schedule_addon']=apply_filters('wpvivid_archieve_schedule_add_settings', array());
631
 
632
  $data['remote']['upload']=self::get_option('wpvivid_upload_setting');
633
  $data['remote']['history']=self::get_option('wpvivid_user_history');
634
 
635
+ $data['backup_custom_setting']=apply_filters('wpvivid_get_backup_custom_setting_mainwp', array());
636
+
637
+ $data['report_addon'] = apply_filters('wpvivid_archieve_report_addon_mainwp', array());
638
  return $data;
639
  }
640
  }
includes/class-wpvivid-tools.php CHANGED
@@ -6,57 +6,6 @@ if (!defined('WPVIVID_PLUGIN_DIR')){
6
 
7
  class WPvivid_tools
8
  {
9
- public static function maintenance_on(){
10
- $myfile = fopen(ABSPATH.".maintenance", "w");
11
- $txt = '<?php $upgrading = time(); ?>';
12
- fwrite($myfile, $txt);
13
- fclose($myfile);
14
- }
15
- public static function maintenance_off(){
16
- @unlink(ABSPATH.".maintenance");
17
- }
18
-
19
- public static function recurse_copy($src,$dst) {
20
- $dir = opendir($src);
21
- @mkdir($dst);
22
- while(false !== ( $file = readdir($dir)) ) {
23
- if (( $file != '.' ) && ( $file != '..' )) {
24
- if ( is_dir($src . '/' . $file) ) {
25
- self::recurse_copy($src . '/' . $file,$dst . '/' . $file);
26
- }
27
- else {
28
- copy($src . '/' . $file,$dst . '/' . $file);
29
- }
30
- }
31
- }
32
- closedir($dir);
33
- return array('result'=>WPVIVID_SUCCESS);
34
- }
35
-
36
- public static function clearcache($task_id)
37
- {
38
- $path = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir();
39
- $handler=opendir($path);
40
- while(($filename=readdir($handler))!==false)
41
- {
42
- if(is_dir($path.DIRECTORY_SEPARATOR.$filename) && preg_match('#temp-'.$task_id.'#',$filename))
43
- {
44
- WPvivid_tools::deldir($path.DIRECTORY_SEPARATOR.$filename,'',true);
45
- }
46
- if(is_dir($path.DIRECTORY_SEPARATOR.$filename) && preg_match('#temp-'.$task_id.'#',$filename))
47
- {
48
- WPvivid_tools::deldir($path.DIRECTORY_SEPARATOR.$filename,'',true);
49
- }
50
- if(preg_match('#pclzip-.*\.tmp#', $filename)){
51
- @unlink($path.DIRECTORY_SEPARATOR.$filename);
52
- }
53
- if(preg_match('#pclzip-.*\.gz#', $filename)){
54
- @unlink($path.DIRECTORY_SEPARATOR.$filename);
55
- }
56
- }
57
- @closedir($handler);
58
- }
59
-
60
  public static function clean_junk_cache(){
61
  $home_url_prefix=get_home_url();
62
  $parse = parse_url($home_url_prefix);
@@ -151,21 +100,6 @@ class WPvivid_tools
151
  return true;
152
  }
153
 
154
- public static function delValueByKey($key , &$arr){
155
- $flag = true;
156
- if(!array_key_exists($key, $arr)){
157
- return false;
158
- }
159
- $keys = array_keys($arr);
160
- $index = array_search($key, $keys);
161
- if($index !== FALSE){
162
- array_splice($arr, $index, 1);
163
- }else{
164
- $flag = false;
165
- }
166
- return $flag;
167
- }
168
-
169
  public static function file_put_array($json,$file){
170
  file_put_contents($file,json_encode($json));
171
  }
@@ -182,13 +116,4 @@ class WPvivid_tools
182
  return array();
183
  }
184
  }
185
-
186
- public static function get_rollbackdata_file()
187
- {
188
- return WP_CONTENT_DIR.DIRECTORY_SEPARATOR.'wpvivid_rollbackdata.txt';
189
- }
190
- public static function get_restoredata_file()
191
- {
192
- return WP_CONTENT_DIR.DIRECTORY_SEPARATOR.'wpvivid_restoredata.txt';
193
- }
194
  }
6
 
7
  class WPvivid_tools
8
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  public static function clean_junk_cache(){
10
  $home_url_prefix=get_home_url();
11
  $parse = parse_url($home_url_prefix);
100
  return true;
101
  }
102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  public static function file_put_array($json,$file){
104
  file_put_contents($file,json_encode($json));
105
  }
116
  return array();
117
  }
118
  }
 
 
 
 
 
 
 
 
 
119
  }
includes/class-wpvivid-zipclass.php CHANGED
@@ -831,11 +831,6 @@ class WPvivid_ZipClass extends Wpvivid_Compress_Default
831
  $files[] = $path . DIRECTORY_SEPARATOR . $filename;
832
  }
833
  }
834
- else
835
- {
836
- global $wpvivid_plugin;
837
- $wpvivid_plugin->wpvivid_log->WriteLog('file not readable:' . $path . DIRECTORY_SEPARATOR . $filename, 'notice');
838
- }
839
  }
840
  }
841
  }
831
  $files[] = $path . DIRECTORY_SEPARATOR . $filename;
832
  }
833
  }
 
 
 
 
 
834
  }
835
  }
836
  }
includes/class-wpvivid.php CHANGED
@@ -127,6 +127,8 @@ class WPvivid {
127
  add_filter('wpvivid_set_mail_subject', array($this, 'set_mail_subject'), 10, 2);
128
  add_filter('wpvivid_set_mail_body', array($this, 'set_mail_body'), 10, 2);
129
 
 
 
130
  //Initialisation schedule hook
131
  $this->init_cron();
132
  //Initialisation log object
@@ -185,11 +187,15 @@ class WPvivid {
185
  include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-exporter.php';
186
  include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-importer.php';
187
 
188
- include_once WPVIVID_PLUGIN_DIR.'/includes/class-wpvivid-tab-page-container.php' ;
 
 
 
189
 
190
  $this->function_realize=new WPvivid_Function_Realize();
191
  $this->migrate=new WPvivid_Migrate();
192
  $this->backup_uploader=new Wpvivid_BackupUploader();
 
193
  $send_to_site=new WPvivid_Send_to_site();
194
  $export_import = new WPvivid_Export_Import();
195
  }
@@ -291,8 +297,6 @@ class WPvivid {
291
  add_action('wp_ajax_wpvivid_prepare_download_backup',array( $this,'prepare_download_backup'));
292
  //Download backup from site
293
  add_action('wp_ajax_wpvivid_download_backup',array( $this,'download_backup'));
294
- //Delete downloaded file
295
- add_action('wp_ajax_wpvivid_delete_download',array( $this,'delete_download'));
296
  //Delete backup record
297
  add_action('wp_ajax_wpvivid_delete_backup',array( $this,'delete_backup'));
298
  //Delete backup records
@@ -338,21 +342,15 @@ class WPvivid {
338
  //
339
  add_action('wp_ajax_wpvivid_delete_last_restore_data',array( $this,'delete_last_restore_data'));
340
  //
341
- add_action('wp_ajax_wpvivid_delete_old_files',array( $this,'delete_old_files'));
342
  //start restore
343
  add_action('wp_ajax_wpvivid_restore',array( $this,'restore'));
344
- //start rollback
345
- add_action('wp_ajax_wpvivid_rollback',array( $this,'rollback'));
346
  add_action('wp_ajax_wpvivid_get_restore_progress',array( $this,'get_restore_progress'));
347
- add_action('wp_ajax_wpvivid_get_rollback_progress',array( $this,'get_rollback_progress'));
348
  add_action('wp_ajax_wpvivid_get_download_restore_progress',array( $this,'download_restore_progress'));
349
  //When restoring the database use wp_ajax_nopriv_
350
  add_action('wp_ajax_nopriv_wpvivid_init_restore_page',array( $this,'init_restore_page'));
351
  add_action('wp_ajax_nopriv_wpvivid_delete_last_restore_data',array( $this,'delete_last_restore_data'));
352
  add_action('wp_ajax_nopriv_wpvivid_restore',array( $this,'restore'));
353
- add_action('wp_ajax_nopriv_wpvivid_rollback',array( $this,'rollback'));
354
  add_action('wp_ajax_nopriv_wpvivid_get_restore_progress',array( $this,'get_restore_progress'));
355
- add_action('wp_ajax_nopriv_wpvivid_get_rollback_progress',array( $this,'get_rollback_progress'));
356
  add_action('wp_ajax_wpvivid_list_tasks',array( $this,'list_tasks'));
357
  //View last backup record log
358
  add_action('wp_ajax_wpvivid_read_last_backup_log',array( $this,'read_last_backup_log'));
@@ -975,26 +973,9 @@ class WPvivid {
975
 
976
  if(!empty($backup))
977
  {
978
-
979
  $backup_item=new WPvivid_Backup_Item($backup);
980
- $files=$backup_item->get_files();
981
- foreach ($files as $file)
982
- {
983
- if (file_exists($file))
984
- {
985
- @unlink($file);
986
- }
987
- }
988
-
989
- if(!empty($backup['remote']))
990
- {
991
- $files=$backup_item->get_files(false);
992
-
993
- foreach($backup['remote'] as $remote)
994
- {
995
- WPvivid_downloader::delete($remote,$files);
996
- }
997
- }
998
  }
999
  }
1000
  /**
@@ -1006,23 +987,38 @@ class WPvivid {
1006
  */
1007
  public function clean_oldest_backup()
1008
  {
1009
- $backup_ids=WPvivid_Backuplist::get_out_of_date_backuplist(WPvivid_Setting::get_max_backup_count());
1010
- foreach($backup_ids as $backup_id)
 
1011
  {
1012
- $this->delete_backup_by_id($backup_id);
1013
- }
1014
- $count=WPvivid_Setting::get_max_backup_count();
1015
- $ret=WPvivid_Backuplist::check_backuplist_limit($count);
1016
- if($ret['result']=='need_delete')
1017
- {
1018
- $oldest_id=$ret['oldest_id'];
1019
- if($oldest_id!='not set')
1020
  {
1021
  $this->add_clean_backup_record_event($oldest_id);
1022
  WPvivid_Backuplist::delete_backup($oldest_id);
1023
  }
1024
  }
1025
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1026
  /**
1027
  * Initialization backup task.
1028
  *
@@ -1090,6 +1086,7 @@ class WPvivid {
1090
  {
1091
  $backup=new WPvivid_Backup();
1092
 
 
1093
  $backup_ret=$backup->backup($task_id);
1094
  $backup->clearcache();
1095
 
@@ -1551,8 +1548,8 @@ class WPvivid {
1551
  $limit=WPVIVID_MAX_EXECUTION_TIME;
1552
  }
1553
  $time_spend=time()-$status['timeout'];
1554
-
1555
- if($time_spend>=$limit)
1556
  {
1557
  //time out
1558
  if(isset($options['max_resume_count']))
@@ -1597,7 +1594,7 @@ class WPvivid {
1597
  WPvivid_taskmanager::update_backup_task_status($task_id,false,'no_responds',false,$status['resume_count']);
1598
  $this->add_monitor_event($task_id);
1599
  }
1600
- else{
1601
  $this->add_monitor_event($task_id);
1602
  }
1603
  }
@@ -1669,8 +1666,8 @@ class WPvivid {
1669
  $limit=WPVIVID_MAX_EXECUTION_TIME;
1670
  }
1671
  $time_spend=time()-$status['timeout'];
1672
-
1673
- if($time_spend>=$limit)
1674
  {
1675
  //time out
1676
  if(isset($options['max_resume_count']))
@@ -2090,7 +2087,8 @@ class WPvivid {
2090
  }
2091
  else
2092
  {
2093
- ob_flush();
 
2094
  flush();
2095
  }
2096
  }
@@ -2228,7 +2226,6 @@ class WPvivid {
2228
  return $ret;
2229
  }
2230
  $ret['result']=WPVIVID_SUCCESS;
2231
- $type_list=array();
2232
  $backup=WPvivid_Backuplist::get_backup_by_id($backup_id);
2233
 
2234
  if($backup===false)
@@ -2248,70 +2245,6 @@ class WPvivid {
2248
  return $ret;
2249
  }
2250
 
2251
- /**
2252
- * delete download file
2253
- *
2254
- * @since 0.9.1
2255
- */
2256
- public function delete_download()
2257
- {
2258
- $this->ajax_check_security();
2259
- try {
2260
- 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'])) {
2261
- die();
2262
- }
2263
- $download_info = array();
2264
- $download_info['backup_id'] = sanitize_key($_POST['backup_id']);
2265
- //$download_info['file_name']=sanitize_file_name($_POST['file_name']);
2266
- $download_info['file_name'] = $_POST['file_name'];
2267
-
2268
- $files = array();
2269
- $backup = WPvivid_Backuplist::get_backup_by_id($download_info['backup_id']);
2270
- if (!$backup) {
2271
- $json['result'] = 'failed';
2272
- $json['error'] = __('Retrieving the backup(s) information failed while deleting the selected backup(s). Please try again later.', 'wpvivid');
2273
- json_encode($json);
2274
- die();
2275
- }
2276
- if ($backup['backup']['ismerge'] == 1) {
2277
- $backup_files = $backup['backup']['data']['meta']['files'];
2278
- foreach ($backup_files as $file) {
2279
- if ($file['file_name'] == $download_info['file_name']) {
2280
- $files[] = $file;
2281
- break;
2282
- }
2283
- }
2284
- } else {
2285
- foreach ($backup['backup']['data']['type'] as $type) {
2286
- $backup_files = $type['files'];
2287
- foreach ($backup_files as $file) {
2288
- if ($file['file_name'] == $download_info['file_name']) {
2289
- $files[] = $file;
2290
- break;
2291
- }
2292
- }
2293
- }
2294
- }
2295
-
2296
- $download_dir = $backup['local']['path'];
2297
-
2298
- foreach ($files as $file) {
2299
- $download_path = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $download_dir . DIRECTORY_SEPARATOR . $file['file_name'];
2300
- if (file_exists($download_path)) {
2301
- unlink($download_path);
2302
- }
2303
- }
2304
- $ret = $this->init_download($_POST['backup_id']);
2305
- echo json_encode($ret);
2306
- }
2307
- catch (Exception $error) {
2308
- $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
2309
- error_log($message);
2310
- echo json_encode(array('result'=>'failed','error'=>$message));
2311
- die();
2312
- }
2313
- die();
2314
- }
2315
  /**
2316
  * download backup file
2317
  *
@@ -2497,7 +2430,6 @@ class WPvivid {
2497
  }
2498
 
2499
  $backup_item=new WPvivid_Backup_Item($backup);
2500
-
2501
  if($backup_item->is_lock())
2502
  {
2503
  if($force==0)
@@ -2507,37 +2439,13 @@ class WPvivid {
2507
  return $ret;
2508
  }
2509
  }
2510
-
2511
- $files=$backup_item->get_files();
2512
-
2513
- foreach ($files as $file)
2514
- {
2515
- if (file_exists($file))
2516
- {
2517
- @unlink($file);
2518
- }
2519
- }
2520
-
2521
- $ret = WPvivid_Backuplist::get_backuplist_by_id($backup_id);
2522
-
2523
- if(!empty($backup['remote']))
2524
- {
2525
- WPvivid_Backuplist::delete_backup($backup_id);
2526
- $files=$backup_item->get_files(false);
2527
- foreach($backup['remote'] as $remote)
2528
- {
2529
- WPvivid_downloader::delete($remote,$files);
2530
- }
2531
- }
2532
- else
2533
- {
2534
- WPvivid_Backuplist::delete_backup($backup_id);
2535
- }
2536
 
2537
  $html = '';
2538
  $html = apply_filters('wpvivid_add_backup_list', $html);
2539
  $ret['html'] = $html;
2540
-
2541
  $ret['result']='success';
2542
  return $ret;
2543
  }
@@ -2557,24 +2465,8 @@ class WPvivid {
2557
  continue;
2558
  }
2559
 
2560
- $files=array();
2561
- $download_dir=$backup['local']['path'];
2562
-
2563
  $backup_item = new WPvivid_Backup_Item($backup);
2564
- $file=$backup_item->get_files(false);
2565
- foreach ($file as $filename) {
2566
- $files[] = $filename;
2567
- }
2568
-
2569
- foreach ($files as $file)
2570
- {
2571
- $download_path = WP_CONTENT_DIR .DIRECTORY_SEPARATOR . $download_dir . DIRECTORY_SEPARATOR . $file;
2572
- if (file_exists($download_path))
2573
- {
2574
- unlink($download_path);
2575
- }
2576
-
2577
- }
2578
  }
2579
  }
2580
 
@@ -2924,14 +2816,7 @@ class WPvivid {
2924
  $ret['has_exist_restore']=0;
2925
  }
2926
 
2927
- if($this->restore_data->has_old_files())
2928
- {
2929
- $ret['has_old_files']=1;
2930
- }
2931
- else
2932
- {
2933
- $ret['has_old_files']=0;
2934
- }
2935
  }
2936
  catch (Exception $error)
2937
  {
@@ -3110,22 +2995,6 @@ class WPvivid {
3110
  die();
3111
  }
3112
 
3113
- public function delete_old_files()
3114
- {
3115
- try {
3116
- $this->restore_data = new WPvivid_restore_data();
3117
- $this->restore_data->delete_old_files();
3118
- $ret['result'] = 'success';
3119
- echo json_encode($ret);
3120
- }
3121
- catch (Exception $error) {
3122
- $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
3123
- error_log($message);
3124
- echo json_encode(array('result'=>'failed','error'=>$message));
3125
- die();
3126
- }
3127
- die();
3128
- }
3129
  /**
3130
  * Prepare backup files for restore
3131
  *
@@ -3471,100 +3340,6 @@ class WPvivid {
3471
  die();
3472
  }
3473
  }
3474
- /**
3475
- * Start rollback
3476
- *
3477
- * @since 0.9.1
3478
- */
3479
- public function rollback()
3480
- {
3481
- $this->_enable_maintenance_mode();
3482
- try
3483
- {
3484
- $rollback=new WPvivid_RollBack();
3485
- $rollback->rollback();
3486
- }
3487
- catch (Exception $error)
3488
- {
3489
- $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
3490
- error_log($message);
3491
- $this->_disable_maintenance_mode();
3492
- echo json_encode(array('result'=>'failed','error'=>$message));
3493
- die();
3494
- }
3495
- catch (Error $error)
3496
- {
3497
- $message = 'An error has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
3498
- error_log($message);
3499
- $this->_disable_maintenance_mode();
3500
- echo json_encode(array('result'=>'failed','error'=>$message));
3501
- die();
3502
- }
3503
- $this->_disable_maintenance_mode();
3504
- echo json_encode(array('result'=>'finished'));
3505
- die();
3506
-
3507
-
3508
- $this->restore_data=new WPvivid_restore_data();
3509
- if($this->restore_data->has_rollback())
3510
- {
3511
- $status=$this->restore_data->get_rollback_status();
3512
-
3513
- if($status === WPVIVID_RESTORE_ERROR)
3514
- {
3515
- $ret['result']='failed';
3516
- $ret['error']=$this->restore_data->get_rollback_error();
3517
- echo json_encode($ret);
3518
- die();
3519
- }
3520
- else if($status === WPVIVID_RESTORE_COMPLETED)
3521
- {
3522
- $this->restore_data->write_rollback_log('disable maintenance mode','notice');
3523
- $this->_disable_maintenance_mode();
3524
- echo json_encode(array('result'=>'finished'));
3525
- die();
3526
- }
3527
- }
3528
- else
3529
- {
3530
- $this->restore_data->init_rollback_data();
3531
- $this->restore_data->write_rollback_log('init restore data','notice');
3532
- $this->_enable_maintenance_mode();
3533
- $this->restore_data->write_rollback_log('enable maintenance mode','notice');
3534
- }
3535
-
3536
- try
3537
- {
3538
- $rollback=new WPvivid_RollBack();
3539
- $this->_disable_maintenance_mode();
3540
- $ret=$rollback->rollback();
3541
- }
3542
- catch (Exception $error)
3543
- {
3544
- $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
3545
- error_log($message);
3546
-
3547
- $this->restore_data->update_rollback_error($message);
3548
- $this->restore_data->write_rollback_log($message,'error');
3549
- $this->_disable_maintenance_mode();
3550
- echo json_encode(array('result'=>'failed','error'=>$message));
3551
- die();
3552
- }
3553
- catch (Error $error)
3554
- {
3555
- $message = 'An error has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
3556
- error_log($message);
3557
-
3558
- $this->restore_data->update_rollback_error($message);
3559
- $this->restore_data->write_rollback_log($message,'error');
3560
- $this->_disable_maintenance_mode();
3561
- echo json_encode(array('result'=>'failed','error'=>$message));
3562
- die();
3563
- }
3564
-
3565
- echo json_encode($ret);
3566
- die();
3567
- }
3568
  /**
3569
  * Get restore progress
3570
  *
@@ -3598,36 +3373,6 @@ class WPvivid {
3598
  die();
3599
  }
3600
  }
3601
- /**
3602
- * Get rollback progress
3603
- *
3604
- * @since 0.9.1
3605
- */
3606
- public function get_rollback_progress()
3607
- {
3608
- try {
3609
- $this->restore_data = new WPvivid_restore_data();
3610
-
3611
- if ($this->restore_data->has_rollback()) {
3612
- $ret['result'] = 'success';
3613
- $ret['status'] = $this->restore_data->get_rollback_status();
3614
- $ret['log'] = $this->restore_data->get_rollback_log_content();
3615
- echo json_encode($ret);
3616
- die();
3617
- } else {
3618
- $ret['result'] = 'failed';
3619
- $ret['error'] = 'The restore file not found. Please verify the file exists.';
3620
- echo json_encode($ret);
3621
- die();
3622
- }
3623
- }
3624
- catch (Exception $error) {
3625
- $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
3626
- error_log($message);
3627
- echo json_encode(array('result'=>'failed','error'=>$message));
3628
- die();
3629
- }
3630
- }
3631
 
3632
  public function init_filesystem()
3633
  {
@@ -4030,15 +3775,6 @@ class WPvivid {
4030
  $ret['junk_path'] = $dir;
4031
  $ret['sum_size'] = '0';
4032
  }
4033
- catch (Error $e)
4034
- {
4035
- $ret['log_path'] = $log_dir = $this->wpvivid_log->GetSaveLogFolder();
4036
- $dir = WPvivid_Setting::get_backupdir();
4037
- $ret['old_files_path'] = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . WPVIVID_DEFAULT_ROLLBACK_DIR;
4038
- $dir = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $dir;
4039
- $ret['junk_path'] = $dir;
4040
- $ret['sum_size'] = '0';
4041
- }
4042
  return $ret;
4043
  }
4044
 
@@ -4083,8 +3819,10 @@ class WPvivid {
4083
  public function clean_out_of_date_backup()
4084
  {
4085
  $this->ajax_check_security();
4086
- try {
4087
- $backup_ids = WPvivid_Backuplist::get_out_of_date_backuplist(WPvivid_Setting::get_max_backup_count());
 
 
4088
  foreach ($backup_ids as $backup_id)
4089
  {
4090
  $this->delete_backup_by_id($backup_id);
@@ -4101,7 +3839,6 @@ class WPvivid {
4101
  $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
4102
  error_log($message);
4103
  echo json_encode(array('result'=>'failed','error'=>$message));
4104
- die();
4105
  }
4106
  die();
4107
  }
@@ -4199,12 +3936,6 @@ class WPvivid {
4199
  $this -> get_dir_files($delete_files,$delete_folder,$dir,$except_regex,$files,$folder,0,false);
4200
  }
4201
 
4202
- if($options['old_files']=='1')
4203
- {
4204
- $this->restore_data=new WPvivid_restore_data();
4205
- $this->restore_data->delete_old_files();
4206
- }
4207
-
4208
  foreach ($delete_files as $file)
4209
  {
4210
  if(file_exists($file))
@@ -5773,4 +5504,10 @@ class WPvivid {
5773
  $body=WPvivid_mail_report::create_body($task);
5774
  return $body;
5775
  }
 
 
 
 
 
 
5776
  }
127
  add_filter('wpvivid_set_mail_subject', array($this, 'set_mail_subject'), 10, 2);
128
  add_filter('wpvivid_set_mail_body', array($this, 'set_mail_body'), 10, 2);
129
 
130
+ add_filter('wpvivid_get_oldest_backup_ids', array($this, 'get_oldest_backup_ids'), 10, 2);
131
+ //
132
  //Initialisation schedule hook
133
  $this->init_cron();
134
  //Initialisation log object
187
  include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-exporter.php';
188
  include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-importer.php';
189
 
190
+ include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-tab-page-container.php' ;
191
+ include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-tools.php';
192
+
193
+ include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-interface-mainwp.php';
194
 
195
  $this->function_realize=new WPvivid_Function_Realize();
196
  $this->migrate=new WPvivid_Migrate();
197
  $this->backup_uploader=new Wpvivid_BackupUploader();
198
+ $this->interface_mainwp = new WPvivid_Interface_MainWP();
199
  $send_to_site=new WPvivid_Send_to_site();
200
  $export_import = new WPvivid_Export_Import();
201
  }
297
  add_action('wp_ajax_wpvivid_prepare_download_backup',array( $this,'prepare_download_backup'));
298
  //Download backup from site
299
  add_action('wp_ajax_wpvivid_download_backup',array( $this,'download_backup'));
 
 
300
  //Delete backup record
301
  add_action('wp_ajax_wpvivid_delete_backup',array( $this,'delete_backup'));
302
  //Delete backup records
342
  //
343
  add_action('wp_ajax_wpvivid_delete_last_restore_data',array( $this,'delete_last_restore_data'));
344
  //
 
345
  //start restore
346
  add_action('wp_ajax_wpvivid_restore',array( $this,'restore'));
 
 
347
  add_action('wp_ajax_wpvivid_get_restore_progress',array( $this,'get_restore_progress'));
 
348
  add_action('wp_ajax_wpvivid_get_download_restore_progress',array( $this,'download_restore_progress'));
349
  //When restoring the database use wp_ajax_nopriv_
350
  add_action('wp_ajax_nopriv_wpvivid_init_restore_page',array( $this,'init_restore_page'));
351
  add_action('wp_ajax_nopriv_wpvivid_delete_last_restore_data',array( $this,'delete_last_restore_data'));
352
  add_action('wp_ajax_nopriv_wpvivid_restore',array( $this,'restore'));
 
353
  add_action('wp_ajax_nopriv_wpvivid_get_restore_progress',array( $this,'get_restore_progress'));
 
354
  add_action('wp_ajax_wpvivid_list_tasks',array( $this,'list_tasks'));
355
  //View last backup record log
356
  add_action('wp_ajax_wpvivid_read_last_backup_log',array( $this,'read_last_backup_log'));
973
 
974
  if(!empty($backup))
975
  {
 
976
  $backup_item=new WPvivid_Backup_Item($backup);
977
+ $backup_item->cleanup_local_backup();
978
+ $backup_item->cleanup_remote_backup();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
979
  }
980
  }
981
  /**
987
  */
988
  public function clean_oldest_backup()
989
  {
990
+ $oldest_ids=array();
991
+ $oldest_ids=apply_filters('wpvivid_get_oldest_backup_ids',$oldest_ids,false);
992
+ if($oldest_ids!==false)
993
  {
994
+ foreach ($oldest_ids as $oldest_id)
 
 
 
 
 
 
 
995
  {
996
  $this->add_clean_backup_record_event($oldest_id);
997
  WPvivid_Backuplist::delete_backup($oldest_id);
998
  }
999
  }
1000
  }
1001
+
1002
+ public function get_oldest_backup_ids($oldest_ids,$multiple)
1003
+ {
1004
+ if($multiple)
1005
+ {
1006
+ $count=WPvivid_Setting::get_max_backup_count();
1007
+
1008
+ $oldest_ids = WPvivid_Backuplist::get_out_of_date_backuplist($count);
1009
+
1010
+ return $oldest_ids;
1011
+ }
1012
+ else
1013
+ {
1014
+ $count=WPvivid_Setting::get_max_backup_count();
1015
+ $oldest_id=WPvivid_Backuplist::check_backuplist_limit($count);
1016
+ $oldest_ids=array();
1017
+ $oldest_ids[]=$oldest_id;
1018
+ return $oldest_ids;
1019
+ }
1020
+ }
1021
+
1022
  /**
1023
  * Initialization backup task.
1024
  *
1086
  {
1087
  $backup=new WPvivid_Backup();
1088
 
1089
+ $backup->clearcache();
1090
  $backup_ret=$backup->backup($task_id);
1091
  $backup->clearcache();
1092
 
1548
  $limit=WPVIVID_MAX_EXECUTION_TIME;
1549
  }
1550
  $time_spend=time()-$status['timeout'];
1551
+ $last_active_time=time()-$status['run_time'];
1552
+ if($time_spend>=$limit&&$last_active_time>min(180,$limit))
1553
  {
1554
  //time out
1555
  if(isset($options['max_resume_count']))
1594
  WPvivid_taskmanager::update_backup_task_status($task_id,false,'no_responds',false,$status['resume_count']);
1595
  $this->add_monitor_event($task_id);
1596
  }
1597
+ else {
1598
  $this->add_monitor_event($task_id);
1599
  }
1600
  }
1666
  $limit=WPVIVID_MAX_EXECUTION_TIME;
1667
  }
1668
  $time_spend=time()-$status['timeout'];
1669
+ $last_active_time=time()-$status['run_time'];
1670
+ if($time_spend>=$limit&&$last_active_time>min(180,$limit))
1671
  {
1672
  //time out
1673
  if(isset($options['max_resume_count']))
2087
  }
2088
  else
2089
  {
2090
+ if(ob_get_level()>0)
2091
+ ob_flush();
2092
  flush();
2093
  }
2094
  }
2226
  return $ret;
2227
  }
2228
  $ret['result']=WPVIVID_SUCCESS;
 
2229
  $backup=WPvivid_Backuplist::get_backup_by_id($backup_id);
2230
 
2231
  if($backup===false)
2245
  return $ret;
2246
  }
2247
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2248
  /**
2249
  * download backup file
2250
  *
2430
  }
2431
 
2432
  $backup_item=new WPvivid_Backup_Item($backup);
 
2433
  if($backup_item->is_lock())
2434
  {
2435
  if($force==0)
2439
  return $ret;
2440
  }
2441
  }
2442
+ WPvivid_Backuplist::delete_backup($backup_id);
2443
+ $backup_item->cleanup_local_backup();
2444
+ $backup_item->cleanup_remote_backup();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2445
 
2446
  $html = '';
2447
  $html = apply_filters('wpvivid_add_backup_list', $html);
2448
  $ret['html'] = $html;
 
2449
  $ret['result']='success';
2450
  return $ret;
2451
  }
2465
  continue;
2466
  }
2467
 
 
 
 
2468
  $backup_item = new WPvivid_Backup_Item($backup);
2469
+ $backup_item->cleanup_local_backup();
 
 
 
 
 
 
 
 
 
 
 
 
 
2470
  }
2471
  }
2472
 
2816
  $ret['has_exist_restore']=0;
2817
  }
2818
 
2819
+ $ret['has_old_files']=0;
 
 
 
 
 
 
 
2820
  }
2821
  catch (Exception $error)
2822
  {
2995
  die();
2996
  }
2997
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2998
  /**
2999
  * Prepare backup files for restore
3000
  *
3340
  die();
3341
  }
3342
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3343
  /**
3344
  * Get restore progress
3345
  *
3373
  die();
3374
  }
3375
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3376
 
3377
  public function init_filesystem()
3378
  {
3775
  $ret['junk_path'] = $dir;
3776
  $ret['sum_size'] = '0';
3777
  }
 
 
 
 
 
 
 
 
 
3778
  return $ret;
3779
  }
3780
 
3819
  public function clean_out_of_date_backup()
3820
  {
3821
  $this->ajax_check_security();
3822
+ try
3823
+ {
3824
+ $backup_ids=array();
3825
+ $backup_ids=apply_filters('wpvivid_get_oldest_backup_ids',$backup_ids,true);
3826
  foreach ($backup_ids as $backup_id)
3827
  {
3828
  $this->delete_backup_by_id($backup_id);
3839
  $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
3840
  error_log($message);
3841
  echo json_encode(array('result'=>'failed','error'=>$message));
 
3842
  }
3843
  die();
3844
  }
3936
  $this -> get_dir_files($delete_files,$delete_folder,$dir,$except_regex,$files,$folder,0,false);
3937
  }
3938
 
 
 
 
 
 
 
3939
  foreach ($delete_files as $file)
3940
  {
3941
  if(file_exists($file))
5504
  $body=WPvivid_mail_report::create_body($task);
5505
  return $body;
5506
  }
5507
+
5508
+ public function wpvivid_handle_mainwp_action($data){
5509
+ $public_interface = new WPvivid_Public_Interface();
5510
+ $ret = $public_interface->mainwp_data($data);
5511
+ return $ret;
5512
+ }
5513
  }
includes/customclass/class-wpvivid-amazons3-plus.php CHANGED
@@ -466,6 +466,7 @@ class WPvivid_AMAZONS3Class extends WPvivid_Remote{
466
  $this -> last_time = time();
467
  $this -> last_size = 0;
468
  $wpvivid_plugin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
 
469
  if(!file_exists($file))
470
  return array('result' =>WPVIVID_FAILED,'error' =>$file.' not found. The file might has been moved, renamed or deleted. Please reload the list and verify the file exists.');
471
  $result = $this -> _put($task_id,$amazons3,$file,$callback);
@@ -474,6 +475,8 @@ class WPvivid_AMAZONS3Class extends WPvivid_Remote{
474
  return $result;
475
  }
476
  $wpvivid_plugin->wpvivid_log->WriteLog('Finished uploading '.basename($file),'notice');
 
 
477
  }
478
  return array('result' =>WPVIVID_SUCCESS);
479
  }
@@ -529,7 +532,7 @@ class WPvivid_AMAZONS3Class extends WPvivid_Remote{
529
  if(!$chunk_id){
530
  $chunks = array();
531
  $upload_job['job_data'][basename($file)]['upload_chunks'] = $chunks;
532
- WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_DROPBOX,WPVIVID_UPLOAD_UNDO,'Start multipartupload of '.basename($file).'.',$upload_job['job_data']);
533
  return array('result' => WPVIVID_FAILED,'error' => 'upload '.$file.' failed.');
534
  }
535
  $chunks[] = $chunk_id;
466
  $this -> last_time = time();
467
  $this -> last_size = 0;
468
  $wpvivid_plugin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
469
+ $wpvivid_plugin->set_time_limit($task_id);
470
  if(!file_exists($file))
471
  return array('result' =>WPVIVID_FAILED,'error' =>$file.' not found. The file might has been moved, renamed or deleted. Please reload the list and verify the file exists.');
472
  $result = $this -> _put($task_id,$amazons3,$file,$callback);
475
  return $result;
476
  }
477
  $wpvivid_plugin->wpvivid_log->WriteLog('Finished uploading '.basename($file),'notice');
478
+ $upload_job['job_data'][basename($file)]['uploaded']=1;
479
+ WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_AMAZONS3,WPVIVID_UPLOAD_SUCCESS,'Uploading '.basename($file).' completed.',$upload_job['job_data']);
480
  }
481
  return array('result' =>WPVIVID_SUCCESS);
482
  }
532
  if(!$chunk_id){
533
  $chunks = array();
534
  $upload_job['job_data'][basename($file)]['upload_chunks'] = $chunks;
535
+ WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_AMAZONS3,WPVIVID_UPLOAD_UNDO,'Start multipartupload of '.basename($file).'.',$upload_job['job_data']);
536
  return array('result' => WPVIVID_FAILED,'error' => 'upload '.$file.' failed.');
537
  }
538
  $chunks[] = $chunk_id;
includes/customclass/class-wpvivid-dropbox.php CHANGED
@@ -106,6 +106,7 @@ class WPvivid_Dropbox extends WPvivid_Remote {
106
  $this -> last_time = time();
107
  $this -> last_size = 0;
108
  $wpvivid_plugin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
 
109
  if(!file_exists($file))
110
  return array('result' =>WPVIVID_FAILED,'error' =>$file.' not found. The file might has been moved, renamed or deleted. Please reload the list and verify the file exists.');
111
  $result = $this -> _put($task_id,$dropbox,$file,$callback);
@@ -114,6 +115,8 @@ class WPvivid_Dropbox extends WPvivid_Remote {
114
  return $result;
115
  }
116
  $wpvivid_plugin->wpvivid_log->WriteLog('Finished uploading '.basename($file),'notice');
 
 
117
  }
118
  return array('result' =>WPVIVID_SUCCESS);
119
  }
106
  $this -> last_time = time();
107
  $this -> last_size = 0;
108
  $wpvivid_plugin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
109
+ $wpvivid_plugin->set_time_limit($task_id);
110
  if(!file_exists($file))
111
  return array('result' =>WPVIVID_FAILED,'error' =>$file.' not found. The file might has been moved, renamed or deleted. Please reload the list and verify the file exists.');
112
  $result = $this -> _put($task_id,$dropbox,$file,$callback);
115
  return $result;
116
  }
117
  $wpvivid_plugin->wpvivid_log->WriteLog('Finished uploading '.basename($file),'notice');
118
+ $upload_job['job_data'][basename($file)]['uploaded'] = 1;
119
+ WPvivid_taskmanager::update_backup_sub_task_progress($task_id, 'upload', WPVIVID_REMOTE_DROPBOX, WPVIVID_UPLOAD_SUCCESS, 'Uploading ' . basename($file) . ' completed.', $upload_job['job_data']);
120
  }
121
  return array('result' =>WPVIVID_SUCCESS);
122
  }
includes/customclass/class-wpvivid-google-drive.php CHANGED
@@ -589,14 +589,46 @@ class Wpvivid_Google_drive extends WPvivid_Remote
589
  if(!file_exists($file))
590
  return array('result' =>WPVIVID_FAILED,'error' =>$file.' not found. The file might has been moved, renamed or deleted. Please reload the list and verify the file exists.');
591
  $wpvivid_plugin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
 
592
  $result=$this->_upload($task_id, $file,$client,$service,$folder_id, $callback);
593
  if($result['result'] !==WPVIVID_SUCCESS){
594
  return $result;
595
  }
 
 
596
  }
597
  return array('result' =>WPVIVID_SUCCESS);
598
  }
599
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
600
  public function _upload($task_id, $file,$client,$service,$folder_id, $callback = '')
601
  {
602
  global $wpvivid_plugin;
589
  if(!file_exists($file))
590
  return array('result' =>WPVIVID_FAILED,'error' =>$file.' not found. The file might has been moved, renamed or deleted. Please reload the list and verify the file exists.');
591
  $wpvivid_plugin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
592
+ $wpvivid_plugin->set_time_limit($task_id);
593
  $result=$this->_upload($task_id, $file,$client,$service,$folder_id, $callback);
594
  if($result['result'] !==WPVIVID_SUCCESS){
595
  return $result;
596
  }
597
+
598
+ $this->check_token($client);
599
  }
600
  return array('result' =>WPVIVID_SUCCESS);
601
  }
602
 
603
+ public function check_token($client)
604
+ {
605
+ if ($client->isAccessTokenExpired())
606
+ {
607
+ // Refresh the token if possible, else fetch a new one.
608
+ if ($client->getRefreshToken())
609
+ {
610
+ $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
611
+ $token=$client->getAccessToken();
612
+ $remote_options=WPvivid_Setting::get_remote_option($this->options['id']);
613
+ $this->options['token']=json_decode(json_encode($token),1);
614
+ if($remote_options!==false)
615
+ {
616
+ $remote_options['token']=$this->options['token'];
617
+ WPvivid_Setting::update_remote_option($this->options['id'],$remote_options);
618
+ }
619
+ return array('result' => WPVIVID_SUCCESS);
620
+ }
621
+ else
622
+ {
623
+ return array('result' => WPVIVID_SUCCESS);
624
+ }
625
+ }
626
+ else
627
+ {
628
+ return array('result' => WPVIVID_SUCCESS);
629
+ }
630
+ }
631
+
632
  public function _upload($task_id, $file,$client,$service,$folder_id, $callback = '')
633
  {
634
  global $wpvivid_plugin;
includes/customclass/class-wpvivid-one-drive.php CHANGED
@@ -1,10 +1,4 @@
1
  <?php
2
- /**
3
- * Created by PhpStorm.
4
- * User: alienware`x
5
- * Date: 2019/2/14
6
- * Time: 16:06
7
- */
8
 
9
  if (!defined('WPVIVID_PLUGIN_DIR')){
10
  die;
@@ -551,11 +545,22 @@ class WPvivid_one_drive extends WPvivid_Remote
551
  if(!file_exists($file))
552
  return array('result' =>WPVIVID_FAILED,'error' =>$file.' not found. The file might has been moved, renamed or deleted. Please reload the list and verify the file exists.');
553
  $wpvivid_plugin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
 
554
  $result=$this->_upload($task_id, $file,$callback);
555
  if($result['result'] !==WPVIVID_SUCCESS)
556
  {
557
  return $result;
558
  }
 
 
 
 
 
 
 
 
 
 
559
  }
560
  return array('result' =>WPVIVID_SUCCESS);
561
  }
1
  <?php
 
 
 
 
 
 
2
 
3
  if (!defined('WPVIVID_PLUGIN_DIR')){
4
  die;
545
  if(!file_exists($file))
546
  return array('result' =>WPVIVID_FAILED,'error' =>$file.' not found. The file might has been moved, renamed or deleted. Please reload the list and verify the file exists.');
547
  $wpvivid_plugin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
548
+ $wpvivid_plugin->set_time_limit($task_id);
549
  $result=$this->_upload($task_id, $file,$callback);
550
  if($result['result'] !==WPVIVID_SUCCESS)
551
  {
552
  return $result;
553
  }
554
+
555
+ if($this->need_refresh())
556
+ {
557
+ $wpvivid_plugin->wpvivid_log->WriteLog('The token expired and will go to the server to refresh the token.','notice');
558
+ $ret=$this->refresh_token();
559
+ if($ret['result']===WPVIVID_FAILED)
560
+ {
561
+ return $ret;
562
+ }
563
+ }
564
  }
565
  return array('result' =>WPVIVID_SUCCESS);
566
  }
includes/customclass/class-wpvivid-s3compat.php CHANGED
@@ -132,7 +132,7 @@ class Wpvivid_S3Compat extends WPvivid_Remote{
132
  return $s3compat;
133
  }
134
 
135
- $upload_job=WPvivid_taskmanager::get_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_AMAZONS3);
136
  if(empty($upload_job))
137
  {
138
  $job_data=array();
@@ -142,8 +142,8 @@ class Wpvivid_S3Compat extends WPvivid_Remote{
142
  $file_data['uploaded']=0;
143
  $job_data[basename($file)]=$file_data;
144
  }
145
- WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_AMAZONS3,WPVIVID_UPLOAD_UNDO,'Start uploading',$job_data);
146
- $upload_job=WPvivid_taskmanager::get_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_AMAZONS3);
147
  }
148
 
149
  foreach ($files as $file)
@@ -156,6 +156,7 @@ class Wpvivid_S3Compat extends WPvivid_Remote{
156
  $this->last_time = time();
157
  $this->last_size = 0;
158
  $wpvivid_plugin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
 
159
  if(!file_exists($file)){
160
  $wpvivid_plugin->wpvivid_log->WriteLog('Uploading '.basename($file).' failed.','notice');
161
  return array('result' =>WPVIVID_FAILED,'error' =>$file.' not found. The file might has been moved, renamed or deleted. Please reload the list and verify the file exists.');
@@ -166,13 +167,14 @@ class Wpvivid_S3Compat extends WPvivid_Remote{
166
  $wpvivid_plugin->wpvivid_log->WriteLog('Uploading '.basename($file).' failed.','notice');
167
  return $result;
168
  }
 
169
  $wpvivid_plugin->wpvivid_log->WriteLog('Finished uploading '.basename($file),'notice');
 
170
  }
171
  return array('result' => WPVIVID_SUCCESS);
172
  }
173
  public function _put($task_id,$s3compat,$file,$callback){
174
  $path = $this->options['path'].'/'.basename($file);
175
- $upload_job=WPvivid_taskmanager::get_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_DROPBOX);
176
  $this->current_file_size = filesize($file);
177
  $this->current_file_name = basename($file);
178
 
132
  return $s3compat;
133
  }
134
 
135
+ $upload_job=WPvivid_taskmanager::get_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_S3COMPAT);
136
  if(empty($upload_job))
137
  {
138
  $job_data=array();
142
  $file_data['uploaded']=0;
143
  $job_data[basename($file)]=$file_data;
144
  }
145
+ WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_S3COMPAT,WPVIVID_UPLOAD_UNDO,'Start uploading',$job_data);
146
+ $upload_job=WPvivid_taskmanager::get_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_S3COMPAT);
147
  }
148
 
149
  foreach ($files as $file)
156
  $this->last_time = time();
157
  $this->last_size = 0;
158
  $wpvivid_plugin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
159
+ $wpvivid_plugin->set_time_limit($task_id);
160
  if(!file_exists($file)){
161
  $wpvivid_plugin->wpvivid_log->WriteLog('Uploading '.basename($file).' failed.','notice');
162
  return array('result' =>WPVIVID_FAILED,'error' =>$file.' not found. The file might has been moved, renamed or deleted. Please reload the list and verify the file exists.');
167
  $wpvivid_plugin->wpvivid_log->WriteLog('Uploading '.basename($file).' failed.','notice');
168
  return $result;
169
  }
170
+ $upload_job['job_data'][basename($file)]['uploaded']=1;
171
  $wpvivid_plugin->wpvivid_log->WriteLog('Finished uploading '.basename($file),'notice');
172
+ WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_S3COMPAT,WPVIVID_UPLOAD_SUCCESS,'Uploading '.basename($file).' completed.',$upload_job['job_data']);
173
  }
174
  return array('result' => WPVIVID_SUCCESS);
175
  }
176
  public function _put($task_id,$s3compat,$file,$callback){
177
  $path = $this->options['path'].'/'.basename($file);
 
178
  $this->current_file_size = filesize($file);
179
  $this->current_file_name = basename($file);
180
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: move, clone, migrate, copy, backup, restore, auto backup, cloud backup
4
  Requires at least: 4.5
5
  Tested up to: 5.3.2
6
  Requires PHP: 5.3
7
- Stable tag: 0.9.31
8
  License: GPLv3 or later
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
10
 
@@ -169,6 +169,10 @@ Thank you for translating WPvivid Backup Plugin to your languages!
169
  * [Shohei OKADA](https://ja.gravatar.com/silversword0630)(Japanese)
170
 
171
  == Changelog ==
 
 
 
 
172
  = 0.9.31 =
173
  - Successfully tested with WordPress 5.3.2.
174
  - Fixed: Backup could fail when the split file size was set to 0 MB in the shared hosting optimization mode.
4
  Requires at least: 4.5
5
  Tested up to: 5.3.2
6
  Requires PHP: 5.3
7
+ Stable tag: 0.9.32
8
  License: GPLv3 or later
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
10
 
169
  * [Shohei OKADA](https://ja.gravatar.com/silversword0630)(Japanese)
170
 
171
  == Changelog ==
172
+ = 0.9.32 =
173
+ - Updated the plugin code for WPvivid Backup for MainWP extension.
174
+ - Fixed some bugs in the plugin code.
175
+ - Optimized the plugin code.
176
  = 0.9.31 =
177
  - Successfully tested with WordPress 5.3.2.
178
  - Fixed: Backup could fail when the split file size was set to 0 MB in the shared hosting optimization mode.
wpvivid-backuprestore.php CHANGED
@@ -7,7 +7,7 @@
7
  * @wordpress-plugin
8
  * Plugin Name: WPvivid Backup Plugin
9
  * Description: 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.
10
- * Version: 0.9.31
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.31' );
25
  //
26
  define('WPVIVID_RESTORE_INIT','init');
27
  define('WPVIVID_RESTORE_READY','ready');
@@ -30,7 +30,6 @@ define('WPVIVID_RESTORE_RUNNING','running');
30
  define('WPVIVID_RESTORE_ERROR','error');
31
  define('WPVIVID_RESTORE_WAIT','wait');
32
  define('WPVIVID_RESTORE_TIMEOUT',180);
33
- define('WPVIVID_ROLLBACK_TIMEOUT',180);
34
 
35
  define('WPVIVID_PLUGIN_SLUG','WPvivid');
36
  define('WPVIVID_PLUGIN_NAME',plugin_basename(__FILE__));
7
  * @wordpress-plugin
8
  * Plugin Name: WPvivid Backup Plugin
9
  * Description: 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.
10
+ * Version: 0.9.32
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.32' );
25
  //
26
  define('WPVIVID_RESTORE_INIT','init');
27
  define('WPVIVID_RESTORE_READY','ready');
30
  define('WPVIVID_RESTORE_ERROR','error');
31
  define('WPVIVID_RESTORE_WAIT','wait');
32
  define('WPVIVID_RESTORE_TIMEOUT',180);
 
33
 
34
  define('WPVIVID_PLUGIN_SLUG','WPvivid');
35
  define('WPVIVID_PLUGIN_NAME',plugin_basename(__FILE__));