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 / Staging / Service / StagingEngine.php
wp-staging / Staging / Service Last commit date
Database 3 days ago AbstractStagingSetup.php 1 week ago DirectoryScanner.php 1 week ago FileCopier.php 1 week ago LegacyOptionsCache.php 1 week ago StagingEngine.php 3 days ago StagingSetup.php 1 week ago TableScanner.php 1 week ago
StagingEngine.php
115 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 const NEXT_GEN_ENABLED = true;
28
29
30 const ENGINES = [
31 self::ENGINE_LEGACY,
32 self::ENGINE_NEXT_GEN,
33 ];
34
35 public function isNextGenEnabled(): bool
36 {
37 return self::NEXT_GEN_ENABLED;
38 }
39
40
41
42
43
44 public function getEngine(): string
45 {
46 $engine = $this->getStoredEngine();
47 if ($engine === self::ENGINE_NEXT_GEN && !$this->isNextGenEnabled()) {
48 return self::ENGINE_LEGACY;
49 }
50
51 return $engine;
52 }
53
54
55
56
57
58 public function getStoredEngine(): string
59 {
60 $stored = get_option(self::OPTION_NAME, null);
61 if ($stored === null) {
62 $stored = get_option(self::LEGACY_OPTION_NAME, self::ENGINE_LEGACY);
63 }
64
65 return $this->resolveEngine($stored);
66 }
67
68 public function saveEngine(string $engine): bool
69 {
70 if (!$this->isValidEngine($engine)) {
71 return false;
72 }
73
74 if (get_option(self::OPTION_NAME, null) === $engine) {
75 return true;
76 }
77
78 return update_option(self::OPTION_NAME, $engine, false);
79 }
80
81 public function isValidEngine($engine): bool
82 {
83 return is_string($engine) && in_array($engine, self::ENGINES, true);
84 }
85
86
87
88
89 private function resolveEngine($stored): string
90 {
91 if ($this->isValidEngine($stored)) {
92 return $stored;
93 }
94
95 if (!is_array($stored)) {
96 return self::ENGINE_LEGACY;
97 }
98
99 $legacyActions = ['create', 'update', 'reset', 'push'];
100 foreach ($legacyActions as $action) {
101 if (isset($stored[$action]) && $stored[$action] === self::ENGINE_NEXT_GEN) {
102 return self::ENGINE_NEXT_GEN;
103 }
104 }
105
106 foreach ($legacyActions as $action) {
107 if (isset($stored[$action]) && $this->isValidEngine($stored[$action])) {
108 return $stored[$action];
109 }
110 }
111
112 return self::ENGINE_LEGACY;
113 }
114 }
115