PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.11.2
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.11.2
4.11.2 4.11.1 4.11.0 4.10.0 4.9.5 4.9.4 4.9.3 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 / Upgrade / Upgrade.php
wp-staging / Backend / Upgrade Last commit date
Upgrade.php 4 days ago
Upgrade.php
441 lines
1 <?php
2
3
4
5
6
7
8
9 namespace WPStaging\Backend\Upgrade;
10
11 use WPStaging\Core\Utils\IISWebConfig;
12 use WPStaging\Core\Utils\Htaccess;
13 use WPStaging\Core\WPStaging;
14 use WPStaging\Framework\BackgroundProcessing\Queue;
15 use WPStaging\Notifications\Notifications;
16 use WPStaging\Staging\Sites;
17 use WPStaging\Staging\Service\StagingEngine;
18 use WPStaging\Backup\BackupScheduler;
19 use WPStaging\Backup\Storage\Providers;
20 use WPStaging\Framework\Notices\NextGenEngineNotice;
21 use WPStaging\Framework\Upgrade\UpgradeFlags;
22
23
24 if (!defined("WPINC")) {
25 die;
26 }
27
28 class Upgrade
29 {
30
31
32
33 const OPTION_UPGRADE_DATE = 'wpstg_free_upgrade_date';
34
35
36
37
38 const OPTION_INSTALL_DATE = 'wpstg_free_install_date';
39
40
41
42
43
44 private $previousVersion;
45
46
47
48
49
50 private $settings;
51
52
53
54
55
56 private $db;
57
58
59
60
61 private $stagingSitesHelper;
62
63
64
65
66 private $upgradeFlags;
67
68 public function __construct()
69 {
70
71 $this->previousVersion = preg_replace('/[^0-9.].*/', '', get_option('wpstg_version'));
72
73 $this->settings = (object) get_option("wpstg_settings", []);
74
75
76 $this->db = WPStaging::getInstance()->get("wpdb");
77
78
79 $this->stagingSitesHelper = WPStaging::make(Sites::class);
80 $this->upgradeFlags = WPStaging::make(UpgradeFlags::class);
81 }
82
83
84
85
86 public function doUpgrade()
87 {
88 $this->upgrade2_0_3();
89 $this->upgrade2_1_2();
90 $this->upgrade2_2_0();
91 $this->upgrade2_4_4();
92 $this->upgrade2_5_9();
93 $this->upgrade2_8_7();
94 $this->upgrade3_0_7();
95 $this->upgrade3_8_1();
96 $this->migrateRemoteStorageOptionNames();
97 $this->maybeWarnAboutAffectedNextGenStagingSites();
98 $this->normalizeSettingsShape();
99
100 $this->setVersion();
101 }
102
103
104
105
106
107
108
109
110
111
112
113 private function maybeWarnAboutAffectedNextGenStagingSites()
114 {
115 if ($this->upgradeFlags->has('next_gen_engine_disabled')) {
116 return;
117 }
118
119 $stagingEngine = WPStaging::make(StagingEngine::class);
120 if ($stagingEngine->getStoredEngine() === StagingEngine::ENGINE_NEXT_GEN) {
121 if (!$stagingEngine->isNextGenEnabled()) {
122 $stagingEngine->saveEngine(StagingEngine::ENGINE_LEGACY);
123 }
124
125 $hasStagingSites = !empty(get_option(Sites::STAGING_SITES_OPTION, []))
126 || !empty(get_option(Sites::OLD_STAGING_SITES_OPTION, []));
127 if ($hasStagingSites) {
128 WPStaging::make(NextGenEngineNotice::class)->enable();
129 }
130 }
131
132 $this->upgradeFlags->mark('next_gen_engine_disabled');
133 }
134
135
136
137
138
139 private function upgrade3_8_1() // phpcs:ignore
140 {
141
142 if (version_compare($this->previousVersion, '3.8.1', '>')) {
143 return;
144 }
145
146 if (!class_exists('WPStaging\Backup\BackupScheduler')) {
147 return;
148 }
149
150 $optionBackupScheduleReportEmail = get_option(Notifications::OPTION_BACKUP_SCHEDULE_REPORT_EMAIL);
151 if (empty($optionBackupScheduleReportEmail) || !filter_var($optionBackupScheduleReportEmail, FILTER_VALIDATE_EMAIL)) {
152 $wpstgSettings = (array)get_option('wpstg_settings');
153
154 if (!empty($wpstgSettings['schedulesReportEmail'])) {
155 $optionBackupScheduleReportEmail = $wpstgSettings['schedulesReportEmail'];
156 } else {
157 $userObject = wp_get_current_user();
158 if (is_object($userObject) && !empty($userObject->user_email)) {
159 $optionBackupScheduleReportEmail = $userObject->user_email;
160 }
161 }
162
163 update_option(Notifications::OPTION_BACKUP_SCHEDULE_REPORT_EMAIL, $optionBackupScheduleReportEmail);
164 }
165
166
167 if (get_option(BackupScheduler::OPTION_BACKUP_SCHEDULE_ERROR_REPORT) === false && !empty($optionBackupScheduleReportEmail)) {
168 update_option(BackupScheduler::OPTION_BACKUP_SCHEDULE_ERROR_REPORT, 'true');
169 }
170 }
171
172
173
174
175
176
177
178
179
180
181 private function migrateRemoteStorageOptionNames()
182 {
183 if ($this->upgradeFlags->has('remote_storage_option_names_migrated')) {
184 return;
185 }
186
187 (new Providers())->migrateRemoteStorageOptions();
188 $this->upgradeFlags->mark('remote_storage_option_names_migrated');
189 }
190
191
192
193
194
195 private function upgrade3_0_7() // phpcs:ignore
196 {
197
198 if (version_compare($this->previousVersion, '3.0.6', '>')) {
199 return;
200 }
201
202 $queueUtil = WPStaging::make(Queue::class);
203 $queueUtil->maybeAddResponseColumnToTable();
204 }
205
206
207
208
209
210 private function upgrade2_8_7() // phpcs:ignore
211 {
212 $this->stagingSitesHelper->addMissingCloneNameUpgradeStructure();
213 $this->stagingSitesHelper->upgradeStagingSitesOption();
214 }
215
216
217
218
219
220 private function upgrade2_5_9() // phpcs:ignore
221 {
222
223 if (version_compare($this->previousVersion, '2.5.9', '<')) {
224
225 $sites = $this->stagingSitesHelper->tryGettingStagingSites();
226
227 $new = [];
228
229
230 foreach ($sites as $oldKey => $site) {
231 $key = preg_replace("#\W+#", '-', strtolower($oldKey));
232 $new[$key] = $sites[$oldKey];
233 }
234
235 if (!empty($new)) {
236 $this->stagingSitesHelper->updateStagingSites($new);
237 }
238 }
239 }
240
241
242
243
244 private function upgrade2_4_4() // phpcs:ignore
245 {
246
247 if (version_compare($this->previousVersion, '2.4.4', '<')) {
248
249 $htaccess = new Htaccess();
250 $htaccess->create(trailingslashit(WPStaging::getContentDir()) . '.htaccess');
251 $htaccess->create(trailingslashit(WPStaging::getContentDir()) . 'logs/.htaccess');
252
253
254 if (extension_loaded('litespeed')) {
255 $htaccess->createLitespeed(ABSPATH . '.htaccess');
256 }
257
258
259 $webconfig = new IISWebConfig();
260 $webconfig->create(trailingslashit(WPStaging::getContentDir()) . 'web.config');
261 $webconfig->create(trailingslashit(WPStaging::getContentDir()) . 'logs/web.config');
262 }
263 }
264
265
266
267
268
269 public function upgrade2_2_0() // phpcs:ignore
270 {
271
272 if (version_compare($this->previousVersion, '2.2.0', '<')) {
273 $this->upgradeElements();
274 }
275 }
276
277
278
279
280
281 private function upgradeElements()
282 {
283
284 $sites = $this->stagingSitesHelper->tryGettingStagingSites();
285
286 if ($sites === false || count($sites) === 0) {
287 return;
288 }
289
290
291 foreach ($sites as $key => $value) {
292 if (empty($sites[$key]['directoryName'])) {
293 continue;
294 }
295
296 !empty($sites[$key]['prefix']) ?
297 $sites[$key]['prefix'] = $value['prefix'] :
298 $sites[$key]['prefix'] = $this->getStagingPrefix($sites[$key]['directoryName']);
299 }
300
301 if (count($sites) > 0) {
302 $this->stagingSitesHelper->updateStagingSites($sites);
303 }
304 }
305
306
307
308
309
310
311 private function getStagingPrefix($directory)
312 {
313
314 $path = ABSPATH . $directory . "/wp-config.php";
315
316 if (($content = @file_get_contents($path)) === false) {
317 $prefix = "";
318 } else {
319
320 preg_match("/table_prefix\s*=\s*'(\w*)';/", $content, $matches);
321
322 if (!empty($matches[1])) {
323 $prefix = $matches[1];
324 } else {
325 $prefix = "";
326 }
327 }
328
329
330 if ($this->db->prefix != $prefix) {
331 return $prefix;
332 } else {
333 return "";
334 }
335 }
336
337
338
339
340
341 public function upgrade2_0_3() // phpcs:ignore
342 {
343
344 if (version_compare($this->previousVersion, '2.0.2', '<')) {
345 $this->initialInstall();
346 $this->upgradeNotices();
347 }
348 }
349
350
351
352
353
354
355 private function upgrade2_1_2() // phpcs:ignore
356 {
357 if ($this->previousVersion === false || version_compare($this->previousVersion, '2.1.2', '<')) {
358
359 $clones = $this->stagingSitesHelper->tryGettingStagingSites();
360
361 foreach ($clones as $key => $value) {
362 unset($clones[$key]);
363 $clones[preg_replace("#\W+#", '-', strtolower($key))] = $value;
364 }
365
366 if (!empty($clones)) {
367 $this->stagingSitesHelper->updateStagingSites($clones);
368 }
369 }
370 }
371
372
373
374
375
376 private function initialInstall()
377 {
378
379 add_option('wpstg_installDate', date('Y-m-d h:i:s'));
380 add_option(self::OPTION_INSTALL_DATE, date('Y-m-d h:i:s'));
381 $this->settings->optimizer = "1";
382 update_option('wpstg_settings', (array)$this->settings);
383 }
384
385
386
387
388
389
390 private function normalizeSettingsShape()
391 {
392 $settings = get_option('wpstg_settings');
393 if (!is_object($settings)) {
394 return;
395 }
396
397 update_option('wpstg_settings', (array)$settings);
398 }
399
400
401
402
403
404 private function setVersion()
405 {
406
407 if (version_compare($this->previousVersion, WPStaging::getVersion(), '<')) {
408
409 update_option('wpstg_version', preg_replace('/[^0-9.].*/', '', WPStaging::getVersion()));
410
411 update_option('wpstg_version_upgraded_from', preg_replace('/[^0-9.].*/', '', $this->previousVersion));
412
413 update_option(self::OPTION_UPGRADE_DATE, date('Y-m-d H:i'));
414
415 return true;
416 }
417
418 return false;
419 }
420
421
422
423
424
425
426 private function upgradeNotices()
427 {
428 $poll = get_option("wpstg_start_poll", false);
429 $beta = get_option("wpstg_hide_beta", false);
430 $rating = get_option("wpstg_RatingDiv", false);
431
432 if ($beta && $beta === "yes") {
433 update_option('wpstg_beta', 'no');
434 }
435
436 if ($rating && $rating === 'yes') {
437 update_option('wpstg_rating', 'no');
438 }
439 }
440 }
441