PluginProbe
UpdraftPlus: WP Backup & Migration Plugin / 1.3.8
UpdraftPlus: WP Backup & Migration Plugin v1.3.8
1.26.7 1.26.6 1.26.5 1.26.4 1.26.3 1.9.19 1.9.25 1.9.26 1.9.30 1.9.31 1.9.32 1.9.4 1.9.40 1.9.41 1.9.42 1.9.43 1.9.44 1.9.45 1.9.46 1.9.5 1.9.50 1.9.51 1.9.60 1.9.62 1.9.63 All 371 releases
updraftplus / includes / updraft-restorer.php

updraft-restorer.php in UpdraftPlus: WP Backup & Migration Plugin 1.3.8, at includes/updraft-restorer.php

91 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 class Updraft_Restorer extends WP_Upgrader {
3
4 function backup_strings() {
5 $this->strings['no_package'] = __('Backup file not available.');
6 $this->strings['unpack_package'] = __('Unpacking backup...');
7 $this->strings['moving_old'] = __('Moving old directory out of the way...');
8 $this->strings['moving_backup'] = __('Moving unpackaged backup in place...');
9 $this->strings['cleaning_up'] = __('Cleaning up detritus...');
10 $this->strings['old_move_failed'] = __('Could not move old dir out of the way.');
11 $this->strings['new_move_failed'] = __('Could not move new dir into place. Check your wp-content/upgrade folder.');
12 $this->strings['delete_failed'] = __('Failed to delete working directory after restoring.');
13 }
14
15 function restore_backup($backup_file, $type) {
16
17 if ($type != 'plugins' && $type != 'themes' && $type != 'others' && $type != 'uploads') continue;
18
19 global $wp_filesystem;
20 $this->init();
21 $this->backup_strings();
22
23 $res = $this->fs_connect(array(ABSPATH, WP_CONTENT_DIR) );
24 if(!$res) exit;
25
26 $wp_dir = trailingslashit($wp_filesystem->abspath());
27
28 $download = $this->download_package( $backup_file );
29 if ( is_wp_error($download) )
30 return $download;
31
32 $delete = (UpdraftPlus_Options::get_updraft_option('updraft_delete_local')) ? true : false;
33
34 $working_dir = $this->unpack_package($download , $delete);
35 if (is_wp_error($working_dir)) return $working_dir;
36
37 if ($type == "others" ) {
38
39 // In this special case, the backup contents are not in a folder, so it is not simply a case of moving the folder around, but rather looping over all that we find
40
41 $upgrade_files = $wp_filesystem->dirlist($working_dir);
42 if ( !empty($upgrade_files) ) {
43 foreach ( $upgrade_files as $filestruc ) {
44 $file = $filestruc['name'];
45 # Sanity check (should not be possible as these were excluded at backup time)
46 if ($file != "plugins" && $file != "themes" && $file != "uploads" && $file != "upgrade") {
47 # First, move the existing one, if necessary (may not be present)
48 if ($wp_filesystem->exists($wp_dir . "wp-content/$file")) {
49 if ( !$wp_filesystem->move($wp_dir . "wp-content/$file", $wp_dir . "wp-content/$file-old", true) ) {
50 return new WP_Error('old_move_failed', $this->strings['old_move_failed']);
51 }
52 }
53 # Now, move in the new one
54 if ( !$wp_filesystem->move($working_dir . "/$file", $wp_dir . "wp-content/$file", true) ) {
55 return new WP_Error('new_move_failed', $this->strings['new_move_failed']);
56 }
57 }
58 }
59 }
60
61 } else {
62
63 show_message($this->strings['moving_old']);
64 if ( !$wp_filesystem->move($wp_dir . "wp-content/$type", $wp_dir . "wp-content/$type-old", true) ) {
65 return new WP_Error('old_move_failed', $this->strings['old_move_failed']);
66 }
67
68 show_message($this->strings['moving_backup']);
69 if ( !$wp_filesystem->move($working_dir . "/$type", $wp_dir . "wp-content/$type", true) ) {
70 return new WP_Error('new_move_failed', $this->strings['new_move_failed']);
71 }
72
73 }
74
75 show_message($this->strings['cleaning_up']);
76 if ( !$wp_filesystem->delete($working_dir) ) {
77 return new WP_Error('delete_failed', $this->strings['delete_failed']);
78 }
79
80
81 switch($type) {
82 case 'uploads':
83 @$wp_filesystem->chmod($wp_dir . "wp-content/$type", 0777, true);
84 break;
85 default:
86 @$wp_filesystem->chmod($wp_dir . "wp-content/$type", FS_CHMOD_DIR);
87 }
88 }
89
90 }
91 ?>