PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 3.3.1
WP STAGING – WordPress Backup, Restore, Migration & Clone v3.3.1
4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Backend / Modules / Jobs / Updating.php
wp-staging / Backend / Modules / Jobs Last commit date
Cleaners 5 years ago Exceptions 5 years ago Cancel.php 2 years ago CancelUpdate.php 2 years ago Cloning.php 2 years ago CloningProcess.php 2 years ago Data.php 2 years ago Database.php 2 years ago Delete.php 2 years ago Directories.php 2 years ago Files.php 2 years ago Finish.php 2 years ago Job.php 2 years ago JobExecutable.php 2 years ago Logs.php 3 years ago PreserveDataFirstStep.php 3 years ago PreserveDataSecondStep.php 3 years ago ProcessLock.php 2 years ago Scan.php 2 years ago SearchReplace.php 2 years ago TotalStepsAreNumberOfTables.php 5 years ago Updating.php 2 years ago
Updating.php
255 lines
1 <?php
2
3 namespace WPStaging\Backend\Modules\Jobs;
4
5 use Exception;
6 use stdClass;
7 use WPStaging\Core\WPStaging;
8 use WPStaging\Framework\Database\SelectedTables;
9 use WPStaging\Framework\Filesystem\PathIdentifier;
10 use WPStaging\Framework\Filesystem\Scanning\ScanConst;
11 use WPStaging\Framework\Utils\Urls;
12 use WPStaging\Framework\Utils\Sanitize;
13 use WPStaging\Framework\Utils\WpDefaultDirectories;
14
15 /**
16 * Class Cloning
17 * @package WPStaging\Backend\Modules\Jobs
18 */
19 class Updating extends Job
20 {
21 /**
22 * External Database Used
23 * @var bool
24 */
25 public $isExternalDb;
26
27 /**
28 * @var string
29 */
30 private $mainJob;
31
32 /**
33 * @var WpDefaultDirectories
34 */
35 private $dirUtils;
36
37 /**
38 * @var Sanitize
39 */
40 private $sanitize;
41
42 /**
43 * @var Urls
44 */
45 private $urls;
46
47 /**
48 * Initialize is called in \Job
49 */
50 public function initialize()
51 {
52 $this->mainJob = Job::UPDATE;
53 $this->dirUtils = new WpDefaultDirectories();
54 $this->sanitize = WPStaging::make(Sanitize::class);
55 $this->urls = WPStaging::make(Urls::class);
56 }
57
58 /**
59 * @param $mainJob
60 */
61 public function setMainJob($mainJob)
62 {
63 $this->mainJob = $mainJob;
64 }
65
66 /**
67 * @return string
68 */
69 public function getMainJob()
70 {
71 return $this->mainJob;
72 }
73
74 /**
75 * Save Chosen Cloning Settings
76 * @return bool
77 * @throws Exception
78 */
79 public function save()
80 {
81 if (!isset($_POST) || !isset($_POST["cloneID"])) {
82 return false;
83 }
84
85 // Delete files to copy listing
86 $this->filesIndexCache->delete();
87
88 // Generate Options
89 $this->options->clone = preg_replace("#\W+#", '-', strtolower($this->sanitize->sanitizeString($_POST["cloneID"])));
90 $this->options->cloneNumber = 1;
91 $this->options->includedDirectories = [];
92 $this->options->excludedDirectories = [];
93 $this->options->extraDirectories = [];
94 $this->options->excludeGlobRules = [];
95 $this->options->excludeSizeRules = [];
96 $this->options->excludedFiles = [
97 '.htaccess',
98 '.DS_Store',
99 '*.git',
100 '*.svn',
101 '*.tmp',
102 'desktop.ini',
103 '.gitignore',
104 '*.log',
105 'object-cache.php',
106 'web.config', // Important: Windows IIS configuration file. Do not copy this to the staging site is staging site is placed into subfolder
107 '.wp-staging-cloneable', // File which make staging site to be cloneable
108 ];
109
110 $this->options->excludedFilesFullPath = [
111 PathIdentifier::IDENTIFIER_WP_CONTENT . 'db.php',
112 PathIdentifier::IDENTIFIER_WP_CONTENT . 'object-cache.php',
113 PathIdentifier::IDENTIFIER_WP_CONTENT . 'advanced-cache.php'
114 ];
115
116 // Define mainJob to differentiate between cloning, updating and pushing
117 $this->options->mainJob = $this->mainJob;
118
119 // Only exclude wp-config.php during UPDATE not RESET
120 if ($this->excludeWpConfigDuringUpdate()) {
121 $this->options->excludedFilesFullPath[] = 'wp-config.php';
122 }
123
124 // Job
125 $this->options->job = new stdClass();
126
127 // Check if clone data already exists and use that one
128 if (isset($this->options->existingClones[$this->options->clone])) {
129 $this->options->cloneName = $this->options->existingClones[$this->options->clone]['cloneName'];
130 $this->options->cloneDirectoryName = $this->options->existingClones[$this->options->clone]['directoryName'];
131 $this->options->cloneNumber = $this->options->existingClones[$this->options->clone]['number'];
132 $this->options->databaseUser = $this->options->existingClones[$this->options->clone]['databaseUser'];
133 $this->options->databasePassword = $this->options->existingClones[$this->options->clone]['databasePassword'];
134 $this->options->databaseDatabase = $this->options->existingClones[$this->options->clone]['databaseDatabase'];
135 $this->options->databaseServer = $this->options->existingClones[$this->options->clone]['databaseServer'];
136 $this->options->databasePrefix = $this->options->existingClones[$this->options->clone]['databasePrefix'];
137 $this->options->databaseSsl = isset($this->options->existingClones[$this->options->clone]['databaseSsl']) ? $this->options->existingClones[$this->options->clone]['databaseSsl'] : false;
138 $this->options->destinationHostname = $this->options->existingClones[$this->options->clone]['url'];
139 $this->options->uploadsSymlinked = isset($this->options->existingClones[strtolower($this->options->clone)]['uploadsSymlinked']) ? $this->options->existingClones[strtolower($this->options->clone)]['uploadsSymlinked'] : false;
140 $this->options->prefix = $this->options->existingClones[$this->options->clone]['prefix'];
141 $this->options->emailsAllowed = $this->options->existingClones[$this->options->clone]['emailsAllowed'];
142 $this->options->networkClone = isset($this->options->existingClones[strtolower($this->options->clone)]['networkClone']) ? $this->options->existingClones[$this->options->clone]['networkClone'] : false;
143 $this->options->networkClone = filter_var($this->options->networkClone, FILTER_VALIDATE_BOOLEAN);
144 $this->options->homeHostname = $this->urls->getHomeUrlWithoutScheme();
145 } else {
146 $job = 'update';
147 if ($this->mainJob === Job::RESET) {
148 $job = 'reset';
149 }
150
151 wp_die(sprintf("Fatal Error: Can not %s clone because there is no clone data.", esc_html($job)));
152 }
153
154 $this->isExternalDb = !(empty($this->options->databaseUser) && empty($this->options->databasePassword));
155
156 /**
157 * @see /WPStaging/Framework/CloningProcess/ExcludedPlugins.php to exclude plugins
158 * Only add other directories here
159 */
160 $excludedDirectories = [
161 PathIdentifier::IDENTIFIER_WP_CONTENT . 'cache',
162 ];
163
164 // Add upload folder to list of excluded directories for push if symlink option is enabled
165 if ($this->options->uploadsSymlinked) {
166 $excludedDirectories[] = PathIdentifier::IDENTIFIER_UPLOADS;
167 }
168
169 $this->options->excludedDirectories = $excludedDirectories;
170
171 $this->setTablesForUpdateJob();
172 $this->setDirectoriesForUpdateJob();
173
174 // Make sure it is always enabled for free version
175 $this->options->emailsAllowed = true;
176 if (defined('WPSTGPRO_VERSION')) {
177 $this->options->emailsAllowed = isset($_POST['emailsAllowed']) && $this->sanitize->sanitizeBool($_POST['emailsAllowed']);
178 }
179
180 $this->options->cloneDir = $this->options->existingClones[$this->options->clone]['path'];
181 $this->options->destinationDir = $this->getDestinationDir();
182 $this->options->cloneHostname = $this->options->destinationHostname;
183
184 // Process lock state
185 $this->options->isRunning = true;
186
187 return $this->saveOptions();
188 }
189
190 /**
191 * Get Destination Directory including staging subdirectory
192 * @return string
193 */
194 private function getDestinationDir()
195 {
196 if (empty($this->options->cloneDir)) {
197 return trailingslashit(WPStaging::getWPpath() . $this->options->cloneDirectoryName);
198 }
199
200 return trailingslashit($this->options->cloneDir);
201 }
202
203 private function setDirectoriesForUpdateJob()
204 {
205 // Exclude Glob Rules
206 $this->options->excludeGlobRules = [];
207 if (!empty($_POST["excludeGlobRules"])) {
208 $this->options->excludeGlobRules = $this->sanitize->sanitizeExcludeRules($_POST["excludeGlobRules"]);
209 }
210
211 $this->options->excludeSizeRules = [];
212 if (!empty($_POST["excludeSizeRules"])) {
213 $this->options->excludeSizeRules = $this->sanitize->sanitizeExcludeRules($_POST["excludeSizeRules"]);
214 }
215
216 // Excluded Directories
217 $excludedDirectoriesRequest = isset($_POST["excludedDirectories"]) ? $this->sanitize->sanitizeString($_POST["excludedDirectories"]) : '';
218 $excludedDirectoriesRequest = $this->dirUtils->getExcludedDirectories($excludedDirectoriesRequest);
219 $this->options->excludedDirectories = array_merge($this->options->excludedDirectories, $excludedDirectoriesRequest);
220 // Extra Directories
221 if (isset($_POST["extraDirectories"])) {
222 $this->options->extraDirectories = explode(ScanConst::DIRECTORIES_SEPARATOR, $this->sanitize->sanitizeString($_POST["extraDirectories"]));
223 }
224
225 // delete uploads folder before copying if uploads is not symlinked
226 $this->options->deleteUploadsFolder = !$this->options->uploadsSymlinked && isset($_POST['cleanUploadsDir']) && $this->sanitize->sanitizeBool($_POST['cleanUploadsDir']);
227 // should not backup uploads during update process
228 $this->options->backupUploadsFolder = false;
229 // clean plugins and themes dir before updating
230 $this->options->deletePluginsAndThemes = isset($_POST['cleanPluginsThemes']) && $this->sanitize->sanitizeBool($_POST['cleanPluginsThemes']);
231 // set default statuses for backup of uploads dir and cleaning of uploads, themes and plugins dirs
232 $this->options->statusBackupUploadsDir = 'skipped';
233 $this->options->statusContentCleaner = 'pending';
234 }
235
236 private function setTablesForUpdateJob()
237 {
238 // Included Tables / Prefixed Table - Excluded Tables
239 $includedTables = isset($_POST['includedTables']) ? $this->sanitize->sanitizeString($_POST['includedTables']) : '';
240 $excludedTables = isset($_POST['excludedTables']) ? $this->sanitize->sanitizeString($_POST['excludedTables']) : '';
241 $selectedTablesWithoutPrefix = isset($_POST['selectedTablesWithoutPrefix']) ? $this->sanitize->sanitizeString($_POST['selectedTablesWithoutPrefix']) : '';
242 $selectedTables = new SelectedTables($includedTables, $excludedTables, $selectedTablesWithoutPrefix);
243 $selectedTables->setAllTablesExcluded(empty($_POST['allTablesExcluded']) ? false : $this->sanitize->sanitizeBool($_POST['allTablesExcluded']));
244 $this->options->tables = $selectedTables->getSelectedTables($this->options->networkClone);
245 }
246
247 /**
248 * Start the cloning job
249 * not used but is abstract
250 */
251 public function start()
252 {
253 }
254 }
255