PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.11.0
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.11.0
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 3 days ago
Upgrade.php
422 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->revertNextGenStagingEngine();
98
99 $this->setVersion();
100 }
101
102
103
104
105
106
107
108
109
110
111 private function revertNextGenStagingEngine()
112 {
113 if ($this->upgradeFlags->has('next_gen_engine_disabled')) {
114 return;
115 }
116
117 $stagingEngine = WPStaging::make(StagingEngine::class);
118 if ($stagingEngine->getStoredEngine() === StagingEngine::ENGINE_NEXT_GEN) {
119 $stagingEngine->saveEngine(StagingEngine::ENGINE_LEGACY);
120
121 $hasStagingSites = !empty(get_option(Sites::STAGING_SITES_OPTION, []))
122 || !empty(get_option(Sites::OLD_STAGING_SITES_OPTION, []));
123 if ($hasStagingSites) {
124 WPStaging::make(NextGenEngineNotice::class)->enable();
125 }
126 }
127
128 $this->upgradeFlags->mark('next_gen_engine_disabled');
129 }
130
131
132
133
134
135 private function upgrade3_8_1() // phpcs:ignore
136 {
137
138 if (version_compare($this->previousVersion, '3.8.1', '>')) {
139 return;
140 }
141
142 if (!class_exists('WPStaging\Backup\BackupScheduler')) {
143 return;
144 }
145
146 $optionBackupScheduleReportEmail = get_option(Notifications::OPTION_BACKUP_SCHEDULE_REPORT_EMAIL);
147 if (empty($optionBackupScheduleReportEmail) || !filter_var($optionBackupScheduleReportEmail, FILTER_VALIDATE_EMAIL)) {
148 $wpstgSettings = (array)get_option('wpstg_settings');
149
150 if (!empty($wpstgSettings['schedulesReportEmail'])) {
151 $optionBackupScheduleReportEmail = $wpstgSettings['schedulesReportEmail'];
152 } else {
153 $userObject = wp_get_current_user();
154 if (is_object($userObject) && !empty($userObject->user_email)) {
155 $optionBackupScheduleReportEmail = $userObject->user_email;
156 }
157 }
158
159 update_option(Notifications::OPTION_BACKUP_SCHEDULE_REPORT_EMAIL, $optionBackupScheduleReportEmail);
160 }
161
162
163 if (get_option(BackupScheduler::OPTION_BACKUP_SCHEDULE_ERROR_REPORT) === false && !empty($optionBackupScheduleReportEmail)) {
164 update_option(BackupScheduler::OPTION_BACKUP_SCHEDULE_ERROR_REPORT, 'true');
165 }
166 }
167
168
169
170
171
172
173
174
175
176
177 private function migrateRemoteStorageOptionNames()
178 {
179 if ($this->upgradeFlags->has('remote_storage_option_names_migrated')) {
180 return;
181 }
182
183 (new Providers())->migrateRemoteStorageOptions();
184 $this->upgradeFlags->mark('remote_storage_option_names_migrated');
185 }
186
187
188
189
190
191 private function upgrade3_0_7() // phpcs:ignore
192 {
193
194 if (version_compare($this->previousVersion, '3.0.6', '>')) {
195 return;
196 }
197
198 $queueUtil = WPStaging::make(Queue::class);
199 $queueUtil->maybeAddResponseColumnToTable();
200 }
201
202
203
204
205
206 private function upgrade2_8_7() // phpcs:ignore
207 {
208 $this->stagingSitesHelper->addMissingCloneNameUpgradeStructure();
209 $this->stagingSitesHelper->upgradeStagingSitesOption();
210 }
211
212
213
214
215
216 private function upgrade2_5_9() // phpcs:ignore
217 {
218
219 if (version_compare($this->previousVersion, '2.5.9', '<')) {
220
221 $sites = $this->stagingSitesHelper->tryGettingStagingSites();
222
223 $new = [];
224
225
226 foreach ($sites as $oldKey => $site) {
227 $key = preg_replace("#\W+#", '-', strtolower($oldKey));
228 $new[$key] = $sites[$oldKey];
229 }
230
231 if (!empty($new)) {
232 $this->stagingSitesHelper->updateStagingSites($new);
233 }
234 }
235 }
236
237
238
239
240 private function upgrade2_4_4() // phpcs:ignore
241 {
242
243 if (version_compare($this->previousVersion, '2.4.4', '<')) {
244
245 $htaccess = new Htaccess();
246 $htaccess->create(trailingslashit(WPStaging::getContentDir()) . '.htaccess');
247 $htaccess->create(trailingslashit(WPStaging::getContentDir()) . 'logs/.htaccess');
248
249
250 if (extension_loaded('litespeed')) {
251 $htaccess->createLitespeed(ABSPATH . '.htaccess');
252 }
253
254
255 $webconfig = new IISWebConfig();
256 $webconfig->create(trailingslashit(WPStaging::getContentDir()) . 'web.config');
257 $webconfig->create(trailingslashit(WPStaging::getContentDir()) . 'logs/web.config');
258 }
259 }
260
261
262
263
264
265 public function upgrade2_2_0() // phpcs:ignore
266 {
267
268 if (version_compare($this->previousVersion, '2.2.0', '<')) {
269 $this->upgradeElements();
270 }
271 }
272
273
274
275
276
277 private function upgradeElements()
278 {
279
280 $sites = $this->stagingSitesHelper->tryGettingStagingSites();
281
282 if ($sites === false || count($sites) === 0) {
283 return;
284 }
285
286
287 foreach ($sites as $key => $value) {
288 if (empty($sites[$key]['directoryName'])) {
289 continue;
290 }
291
292 !empty($sites[$key]['prefix']) ?
293 $sites[$key]['prefix'] = $value['prefix'] :
294 $sites[$key]['prefix'] = $this->getStagingPrefix($sites[$key]['directoryName']);
295 }
296
297 if (count($sites) > 0) {
298 $this->stagingSitesHelper->updateStagingSites($sites);
299 }
300 }
301
302
303
304
305
306
307 private function getStagingPrefix($directory)
308 {
309
310 $path = ABSPATH . $directory . "/wp-config.php";
311
312 if (($content = @file_get_contents($path)) === false) {
313 $prefix = "";
314 } else {
315
316 preg_match("/table_prefix\s*=\s*'(\w*)';/", $content, $matches);
317
318 if (!empty($matches[1])) {
319 $prefix = $matches[1];
320 } else {
321 $prefix = "";
322 }
323 }
324
325
326 if ($this->db->prefix != $prefix) {
327 return $prefix;
328 } else {
329 return "";
330 }
331 }
332
333
334
335
336
337 public function upgrade2_0_3() // phpcs:ignore
338 {
339
340 if (version_compare($this->previousVersion, '2.0.2', '<')) {
341 $this->initialInstall();
342 $this->upgradeNotices();
343 }
344 }
345
346
347
348
349
350
351 private function upgrade2_1_2() // phpcs:ignore
352 {
353 if ($this->previousVersion === false || version_compare($this->previousVersion, '2.1.2', '<')) {
354
355 $clones = $this->stagingSitesHelper->tryGettingStagingSites();
356
357 foreach ($clones as $key => $value) {
358 unset($clones[$key]);
359 $clones[preg_replace("#\W+#", '-', strtolower($key))] = $value;
360 }
361
362 if (!empty($clones)) {
363 $this->stagingSitesHelper->updateStagingSites($clones);
364 }
365 }
366 }
367
368
369
370
371
372 private function initialInstall()
373 {
374
375 add_option('wpstg_installDate', date('Y-m-d h:i:s'));
376 add_option(self::OPTION_INSTALL_DATE, date('Y-m-d h:i:s'));
377 $this->settings->optimizer = "1";
378 update_option('wpstg_settings', $this->settings);
379 }
380
381
382
383
384
385 private function setVersion()
386 {
387
388 if (version_compare($this->previousVersion, WPStaging::getVersion(), '<')) {
389
390 update_option('wpstg_version', preg_replace('/[^0-9.].*/', '', WPStaging::getVersion()));
391
392 update_option('wpstg_version_upgraded_from', preg_replace('/[^0-9.].*/', '', $this->previousVersion));
393
394 update_option(self::OPTION_UPGRADE_DATE, date('Y-m-d H:i'));
395
396 return true;
397 }
398
399 return false;
400 }
401
402
403
404
405
406
407 private function upgradeNotices()
408 {
409 $poll = get_option("wpstg_start_poll", false);
410 $beta = get_option("wpstg_hide_beta", false);
411 $rating = get_option("wpstg_RatingDiv", false);
412
413 if ($beta && $beta === "yes") {
414 update_option('wpstg_beta', 'no');
415 }
416
417 if ($rating && $rating === 'yes') {
418 update_option('wpstg_rating', 'no');
419 }
420 }
421 }
422