PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.11.0
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.11.0
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 / Staging / Service / StagingEngine.php
wp-staging / Staging / Service Last commit date
Database 1 day ago AbstractStagingSetup.php 1 day ago DirectoryScanner.php 1 day ago FileCopier.php 1 day ago LegacyOptionsCache.php 1 day ago StagingEngine.php 1 day ago StagingSetup.php 1 day ago TableScanner.php 1 day ago
StagingEngine.php
117 lines
1 <?php
2
3 namespace WPStaging\Staging\Service;
4
5
6
7
8 class StagingEngine
9 {
10
11 const OPTION_NAME = 'wpstg_staging_engine_preference';
12
13
14 const LEGACY_OPTION_NAME = 'wpstg_staging_engine_preferences';
15
16
17 const ENGINE_LEGACY = 'legacy';
18
19
20 const ENGINE_NEXT_GEN = 'next_gen';
21
22
23
24
25
26
27
28
29 const NEXT_GEN_ENABLED = false;
30
31
32 const ENGINES = [
33 self::ENGINE_LEGACY,
34 self::ENGINE_NEXT_GEN,
35 ];
36
37 public function isNextGenEnabled(): bool
38 {
39 return self::NEXT_GEN_ENABLED;
40 }
41
42
43
44
45
46 public function getEngine(): string
47 {
48 $engine = $this->getStoredEngine();
49 if ($engine === self::ENGINE_NEXT_GEN && !$this->isNextGenEnabled()) {
50 return self::ENGINE_LEGACY;
51 }
52
53 return $engine;
54 }
55
56
57
58
59
60 public function getStoredEngine(): string
61 {
62 $stored = get_option(self::OPTION_NAME, null);
63 if ($stored === null) {
64 $stored = get_option(self::LEGACY_OPTION_NAME, self::ENGINE_LEGACY);
65 }
66
67 return $this->resolveEngine($stored);
68 }
69
70 public function saveEngine(string $engine): bool
71 {
72 if (!$this->isValidEngine($engine)) {
73 return false;
74 }
75
76 if (get_option(self::OPTION_NAME, null) === $engine) {
77 return true;
78 }
79
80 return update_option(self::OPTION_NAME, $engine, false);
81 }
82
83 public function isValidEngine($engine): bool
84 {
85 return is_string($engine) && in_array($engine, self::ENGINES, true);
86 }
87
88
89
90
91 private function resolveEngine($stored): string
92 {
93 if ($this->isValidEngine($stored)) {
94 return $stored;
95 }
96
97 if (!is_array($stored)) {
98 return self::ENGINE_LEGACY;
99 }
100
101 $legacyActions = ['create', 'update', 'reset', 'push'];
102 foreach ($legacyActions as $action) {
103 if (isset($stored[$action]) && $stored[$action] === self::ENGINE_NEXT_GEN) {
104 return self::ENGINE_NEXT_GEN;
105 }
106 }
107
108 foreach ($legacyActions as $action) {
109 if (isset($stored[$action]) && $this->isValidEngine($stored[$action])) {
110 return $stored[$action];
111 }
112 }
113
114 return self::ENGINE_LEGACY;
115 }
116 }
117