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 / Backup / Storage / Providers.php
wp-staging / Backup / Storage Last commit date
Traits 1 day ago Providers.php 1 day ago
Providers.php
340 lines
1 <?php
2
3 namespace WPStaging\Backup\Storage;
4
5 use WPStaging\Core\WPStaging;
6 use WPStaging\Pro\Backup\Storage\Amazon\S3 as AmazonS3Auth;
7 use WPStaging\Pro\Backup\Storage\DigitalOceanSpaces\Auth as DOSAuth;
8 use WPStaging\Pro\Backup\Storage\GenericS3\Auth as GenericS3Auth;
9 use WPStaging\Pro\Backup\Storage\GoogleDrive\Auth as GoogleDriveAuth;
10 use WPStaging\Pro\Backup\Storage\Dropbox\Auth as DropboxAuth;
11 use WPStaging\Pro\Backup\Storage\OneDrive\Auth as OneDriveAuth;
12 use WPStaging\Pro\Backup\Storage\SFTP\Auth as SftpAuth;
13 use WPStaging\Pro\Backup\Storage\Wasabi\Auth as WasabiAuth;
14 use WPStaging\Pro\Backup\Storage\PCloud\Auth as PCloudAuth;
15 use WPStaging\Backup\Storage\Traits\StorageIdNormalizerTrait;
16
17
18
19
20
21
22
23
24
25 class Providers
26 {
27 use StorageIdNormalizerTrait;
28
29
30 const IDENTIFIER_GOOGLE_DRIVE = 'google-drive';
31
32
33 const IDENTIFIER_AMAZON_S3 = 'amazon-s3';
34
35
36 const IDENTIFIER_DROPBOX = 'dropbox';
37
38
39 const IDENTIFIER_ONE_DRIVE = 'one-drive';
40
41
42 const IDENTIFIER_PCLOUD = 'pcloud';
43
44
45 const IDENTIFIER_SFTP = 'sftp';
46
47
48 const IDENTIFIER_DIGITALOCEAN_SPACES = 'digitalocean-spaces';
49
50
51 const IDENTIFIER_WASABI_S3 = 'wasabi-s3';
52
53
54 const IDENTIFIER_GENERIC_S3 = 'generic-s3';
55
56
57
58
59
60 const LEGACY_ID_MAP = [
61 'googleDrive' => self::IDENTIFIER_GOOGLE_DRIVE,
62 'amazonS3' => self::IDENTIFIER_AMAZON_S3,
63 'googledrive' => self::IDENTIFIER_GOOGLE_DRIVE,
64 'amazons3' => self::IDENTIFIER_AMAZON_S3,
65 ];
66
67
68
69
70
71 const REVERSE_LEGACY_ID_MAP = [
72 self::IDENTIFIER_GOOGLE_DRIVE => 'googledrive',
73 self::IDENTIFIER_AMAZON_S3 => 'amazons3',
74 ];
75
76
77 const LEGACY_OPTION_MAP = [
78 self::IDENTIFIER_GOOGLE_DRIVE => 'wpstg_googledrive',
79 self::IDENTIFIER_AMAZON_S3 => 'wpstg_amazons3',
80 ];
81
82
83 const LEGACY_PROPERTY_MAP = [
84 self::IDENTIFIER_GOOGLE_DRIVE => 'googleDrive',
85 self::IDENTIFIER_AMAZON_S3 => 'amazonS3',
86 self::IDENTIFIER_DIGITALOCEAN_SPACES => 'digitalOceanSpaces',
87 self::IDENTIFIER_WASABI_S3 => 'wasabiS3',
88 self::IDENTIFIER_GENERIC_S3 => 'genericS3',
89 self::IDENTIFIER_ONE_DRIVE => 'oneDrive',
90 self::IDENTIFIER_PCLOUD => 'pCloud',
91 ];
92
93
94 const STORAGE_LABELS = [
95 self::IDENTIFIER_GOOGLE_DRIVE => 'Google Drive',
96 self::IDENTIFIER_AMAZON_S3 => 'Amazon S3',
97 self::IDENTIFIER_SFTP => 'sFTP/FTP',
98 self::IDENTIFIER_DIGITALOCEAN_SPACES => 'Digital Ocean Spaces',
99 self::IDENTIFIER_WASABI_S3 => 'Wasabi S3',
100 self::IDENTIFIER_GENERIC_S3 => 'Generic S3',
101 self::IDENTIFIER_DROPBOX => 'Dropbox',
102 self::IDENTIFIER_ONE_DRIVE => 'Microsoft OneDrive',
103 self::IDENTIFIER_PCLOUD => 'pCloud',
104 ];
105
106 protected $storages = [];
107
108
109
110
111
112
113
114
115 public function __construct()
116 {
117 $this->storages = [
118 [
119 'id' => self::IDENTIFIER_GOOGLE_DRIVE,
120 'cli' => self::IDENTIFIER_GOOGLE_DRIVE,
121 'name' => 'Google Drive',
122 'enabled' => true,
123 'authClass' => $this->filterAuthClassForPro(GoogleDriveAuth::class),
124 'settingsPath' => $this->getStorageAdminPage(self::IDENTIFIER_GOOGLE_DRIVE),
125 ],
126 [
127 'id' => self::IDENTIFIER_AMAZON_S3,
128 'cli' => self::IDENTIFIER_AMAZON_S3,
129 'name' => 'Amazon S3',
130 'enabled' => true,
131 'authClass' => $this->filterAuthClassForPro(AmazonS3Auth::class),
132 'settingsPath' => $this->getStorageAdminPage(self::IDENTIFIER_AMAZON_S3),
133 ],
134 [
135 'id' => self::IDENTIFIER_DROPBOX,
136 'cli' => self::IDENTIFIER_DROPBOX,
137 'name' => 'Dropbox',
138 'enabled' => true,
139 'authClass' => $this->filterAuthClassForPro(DropboxAuth::class),
140 'settingsPath' => $this->getStorageAdminPage(self::IDENTIFIER_DROPBOX),
141 ],
142 [
143 'id' => self::IDENTIFIER_ONE_DRIVE,
144 'cli' => self::IDENTIFIER_ONE_DRIVE,
145 'name' => 'Microsoft OneDrive',
146 'enabled' => true,
147 'authClass' => $this->filterAuthClassForPro(OneDriveAuth::class),
148 'settingsPath' => $this->getStorageAdminPage(self::IDENTIFIER_ONE_DRIVE),
149 ],
150 [
151 'id' => self::IDENTIFIER_PCLOUD,
152 'cli' => self::IDENTIFIER_PCLOUD,
153 'name' => 'pCloud',
154 'enabled' => true,
155 'authClass' => $this->filterAuthClassForPro(PCloudAuth::class),
156 'settingsPath' => $this->getStorageAdminPage(self::IDENTIFIER_PCLOUD),
157 ],
158 [
159 'id' => self::IDENTIFIER_SFTP,
160 'cli' => self::IDENTIFIER_SFTP,
161 'name' => 'FTP / SFTP',
162 'enabled' => true,
163 'authClass' => $this->filterAuthClassForPro(SftpAuth::class),
164 'settingsPath' => $this->getStorageAdminPage(self::IDENTIFIER_SFTP),
165 ],
166 [
167 'id' => self::IDENTIFIER_DIGITALOCEAN_SPACES,
168 'cli' => self::IDENTIFIER_DIGITALOCEAN_SPACES,
169 'name' => 'DigitalOcean Spaces',
170 'enabled' => true,
171 'authClass' => $this->filterAuthClassForPro(DOSAuth::class),
172 'settingsPath' => $this->getStorageAdminPage(self::IDENTIFIER_DIGITALOCEAN_SPACES),
173 ],
174 [
175 'id' => self::IDENTIFIER_WASABI_S3,
176 'cli' => self::IDENTIFIER_WASABI_S3,
177 'name' => 'Wasabi S3',
178 'enabled' => true,
179 'authClass' => $this->filterAuthClassForPro(WasabiAuth::class),
180 'settingsPath' => $this->getStorageAdminPage(self::IDENTIFIER_WASABI_S3),
181 ],
182 [
183 'id' => self::IDENTIFIER_GENERIC_S3,
184 'cli' => self::IDENTIFIER_GENERIC_S3,
185 'name' => 'Generic S3',
186 'enabled' => true,
187 'authClass' => $this->filterAuthClassForPro(GenericS3Auth::class),
188 'settingsPath' => $this->getStorageAdminPage(self::IDENTIFIER_GENERIC_S3),
189 ],
190 ];
191 }
192
193
194
195
196
197
198
199
200
201 public function getStorageIds($isEnabled = null)
202 {
203 return array_map(function ($storage) {
204 return $storage['id'];
205 }, $this->getStorages($isEnabled));
206 }
207
208
209
210
211
212
213
214
215
216 public function getStorages($isEnabled = null)
217 {
218 if ($isEnabled === null) {
219 return $this->storages;
220 }
221
222 return array_filter($this->storages, function ($storage) use ($isEnabled) {
223 return $storage['enabled'] === $isEnabled;
224 });
225 }
226
227
228
229
230
231
232
233
234
235
236
237 public function getStorageProperty($id, $property, $isEnabled = null)
238 {
239 foreach ($this->getStorages($isEnabled) as $storage) {
240 if ($storage['id'] === $id) {
241 if (array_key_exists($property, $storage)) {
242 return $storage[$property];
243 }
244 }
245 }
246
247 return false;
248 }
249
250
251
252
253
254 public function isActivated($class)
255 {
256 if (empty($class)) {
257 return false;
258 }
259
260
261 $storage = WPStaging::make($class);
262 return $storage->isAuthenticated();
263 }
264
265
266
267
268
269 protected function filterAuthClassForPro($id)
270 {
271 if (empty($id) || !WPStaging::isPro()) {
272 return '';
273 }
274
275 return $id;
276 }
277
278 private function getStorageAdminPage($storageTab)
279 {
280 return admin_url('admin.php?page=wpstg-settings&tab=remote-storages&sub-tab=' . $storageTab);
281 }
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303 public function migrateRemoteStorageOptions()
304 {
305 $migrated = [];
306 foreach (self::LEGACY_ID_MAP as $legacyId => $newId) {
307 if (isset($migrated[$newId])) {
308 continue;
309 }
310
311 $newOptionName = 'wpstg_' . $newId;
312
313
314
315 $newValue = get_option($newOptionName);
316 if ($newValue !== false) {
317 $migrated[$newId] = true;
318 continue;
319 }
320
321 $legacyOptionNames = array_unique([
322 'wpstg_' . $legacyId,
323 'wpstg_' . strtolower($legacyId),
324 ]);
325
326 foreach ($legacyOptionNames as $legacyOptionName) {
327 $legacyValue = get_option($legacyOptionName, []);
328 if (empty($legacyValue)) {
329 continue;
330 }
331
332 update_option($newOptionName, $legacyValue, false);
333 break;
334 }
335
336 $migrated[$newId] = true;
337 }
338 }
339 }
340