PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.4.0
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.4.0
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 / Backup / Storage / Providers.php
wp-staging / Backup / Storage Last commit date
Providers.php 10 months ago
Providers.php
223 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
16 use function WPStaging\functions\debug_log;
17
18 class Providers
19 {
20 /** @var array
21 *
22 * @example [
23 * 'storageIdentifier' => 'storageId'
24 * ]
25 */
26 const STORAGE_IDS_BY_IDENTIFIERS = [
27 'googledrive' => 'googleDrive',
28 'amazons3' => 'amazonS3',
29 'dropbox' => 'dropbox',
30 'one-drive' => 'one-drive',
31 'sftp' => 'sftp',
32 'digitalocean-spaces' => 'digitalocean-spaces',
33 'wasabi-s3' => 'wasabi-s3',
34 'generic-s3' => 'generic-s3',
35 'pcloud' => 'pcloud',
36 ];
37
38 protected $storages = [];
39
40 public function __construct()
41 {
42 $this->storages = [
43 [
44 'id' => 'googleDrive',
45 'cli' => 'google-drive',
46 'name' => 'Google Drive',
47 'enabled' => true,
48 'authClass' => $this->filterAuthClassForPro(GoogleDriveAuth::class),
49 'settingsPath' => $this->getStorageAdminPage('googleDrive'),
50 ],
51 [
52 'id' => 'amazonS3',
53 'cli' => 'amazon-s3',
54 'name' => 'Amazon S3',
55 'enabled' => true,
56 'authClass' => $this->filterAuthClassForPro(AmazonS3Auth::class),
57 'settingsPath' => $this->getStorageAdminPage('amazonS3'),
58 ],
59 [
60 'id' => 'dropbox',
61 'cli' => 'dropbox',
62 'name' => 'Dropbox',
63 'enabled' => true,
64 'authClass' => $this->filterAuthClassForPro(DropboxAuth::class),
65 'settingsPath' => $this->getStorageAdminPage('dropbox'),
66 ],
67 [
68 'id' => 'one-drive',
69 'cli' => 'one-drive',
70 'name' => 'Microsoft OneDrive',
71 'enabled' => true,
72 'authClass' => $this->filterAuthClassForPro(OneDriveAuth::class),
73 'settingsPath' => $this->getStorageAdminPage('one-drive'),
74 ],
75 [
76 'id' => 'pcloud',
77 'cli' => 'pcloud',
78 'name' => 'pCloud',
79 'enabled' => true,
80 'authClass' => $this->filterAuthClassForPro(PCloudAuth::class),
81 'settingsPath' => $this->getStorageAdminPage('pcloud'),
82 ],
83 [
84 'id' => 'sftp',
85 'cli' => 'sftp',
86 'name' => 'FTP / SFTP',
87 'enabled' => true,
88 'authClass' => $this->filterAuthClassForPro(SftpAuth::class),
89 'settingsPath' => $this->getStorageAdminPage('sftp'),
90 ],
91 [
92 'id' => 'digitalocean-spaces',
93 'cli' => 'digitalocean-spaces',
94 'name' => 'DigitalOcean Spaces',
95 'enabled' => true,
96 'authClass' => $this->filterAuthClassForPro(DOSAuth::class),
97 'settingsPath' => $this->getStorageAdminPage('digitalocean-spaces'),
98 ],
99 [
100 'id' => 'wasabi-s3',
101 'cli' => 'wasabi-s3',
102 'name' => 'Wasabi S3',
103 'enabled' => true,
104 'authClass' => $this->filterAuthClassForPro(WasabiAuth::class),
105 'settingsPath' => $this->getStorageAdminPage('wasabi-s3'),
106 ],
107 [
108 'id' => 'generic-s3',
109 'cli' => 'generic-s3',
110 'name' => 'Generic S3',
111 'enabled' => true,
112 'authClass' => $this->filterAuthClassForPro(GenericS3Auth::class),
113 'settingsPath' => $this->getStorageAdminPage('generic-s3'),
114 ],
115 ];
116 }
117
118 /**
119 * @param null|bool $isEnabled. Default null
120 * Use null for all storages,
121 * Use true for enabled storages,
122 * Use false for disabled storages
123 *
124 * @return array
125 */
126 public function getStorageIds($isEnabled = null)
127 {
128 return array_map(function ($storage) {
129 return $storage['id'];
130 }, $this->getStorages($isEnabled));
131 }
132
133 /**
134 * @param null|bool $isEnabled. Default null
135 * Use null for all storages,
136 * Use true for enabled storages,
137 * Use false for disabled storages
138 *
139 * @return array
140 */
141 public function getStorages($isEnabled = null)
142 {
143 if ($isEnabled === null) {
144 return $this->storages;
145 }
146
147 return array_filter($this->storages, function ($storage) use ($isEnabled) {
148 return $storage['enabled'] === $isEnabled;
149 });
150 }
151
152 /**
153 * @param string $id
154 * @param string $property
155 * @param null|bool $isEnabled. Default null
156 * Use null for all storages,
157 * Use true for enabled storages,
158 * Use false for disabled storages
159 *
160 * @return mixed
161 */
162 public function getStorageProperty($id, $property, $isEnabled = null)
163 {
164 foreach ($this->getStorages($isEnabled) as $storage) {
165 if ($storage['id'] === $id) {
166 if (array_key_exists($property, $storage)) {
167 return $storage[$property];
168 }
169 }
170 }
171
172 return false;
173 }
174
175 /**
176 * @param string $class
177 * @return bool
178 */
179 public function isActivated($class)
180 {
181 if (empty($class)) {
182 return false;
183 }
184
185 /** @see WPStaging\Backup\Storage\AbstractStorage */
186 $storage = WPStaging::make($class);
187 return $storage->isAuthenticated();
188 }
189
190 /**
191 * @param string $identifier
192 *
193 * @return string|false
194 */
195 public function getStorageByIdentifier(string $identifier)
196 {
197 if (!isset(self::STORAGE_IDS_BY_IDENTIFIERS[$identifier])) {
198 debug_log("Failed to find storage id by identifier: {$identifier}");
199 return false;
200 }
201
202 return self::STORAGE_IDS_BY_IDENTIFIERS[$identifier];
203 }
204
205 /**
206 * @param string $id
207 * @return string
208 */
209 protected function filterAuthClassForPro($id)
210 {
211 if (empty($id) || !WPStaging::isPro()) {
212 return '';
213 }
214
215 return $id;
216 }
217
218 private function getStorageAdminPage($storageTab)
219 {
220 return admin_url('admin.php?page=wpstg-settings&tab=remote-storages&sub-tab=' . $storageTab);
221 }
222 }
223