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 / Traits / WithStagingRequirementLogs.php
wp-staging / Staging / Traits Last commit date
StagingDatabaseDtoTrait.php 1 day ago StagingNetworkDtoTrait.php 1 day ago StagingOperationDtoTrait.php 1 day ago StagingSiteGetterTrait.php 1 day ago WithAdvanceStagingOptions.php 1 day ago WithDataAdjustmentTasks.php 11 months ago WithStagingDatabase.php 1 day ago WithStagingEnginePreference.php 1 day ago WithStagingRequirementLogs.php 1 day ago WithStagingSiteDto.php 1 day ago
WithStagingRequirementLogs.php
278 lines
1 <?php
2
3 namespace WPStaging\Staging\Traits;
4
5 use WPStaging\Core\Utils\Logger;
6 use WPStaging\Core\WPStaging;
7 use WPStaging\Pro\License\LicenseCapabilities;
8 use WPStaging\Pro\License\Licensing;
9 use WPStaging\Staging\Service\StagingSetup;
10
11
12
13
14 trait WithStagingRequirementLogs
15 {
16
17
18
19 protected function writeAdvancedSettingsToLogs()
20 {
21 $settingsToLog = $this->getAdvancedSettingsToLog();
22 if (empty($settingsToLog)) {
23 return;
24 }
25
26 $this->logger->add('Advanced Settings', Logger::TYPE_INFO);
27
28 foreach ($settingsToLog as $setting) {
29 $this->writeAdvancedSettingToLogs($setting);
30 }
31 }
32
33
34
35
36 private function getAdvancedSettingsToLog(): array
37 {
38 if (!$this->isProRequirementLog() || !method_exists($this->jobDataDto, 'getJobType')) {
39 return [];
40 }
41
42 switch ($this->jobDataDto->getJobType()) {
43 case StagingSetup::JOB_NEW_STAGING_SITE:
44 return $this->getCreateAdvancedSettingsToLog();
45 case StagingSetup::JOB_UPDATE:
46 return $this->getUpdateAdvancedSettingsToLog();
47 case StagingSetup::JOB_PUSH:
48 return $this->getPushAdvancedSettingsToLog();
49 }
50
51 return [];
52 }
53
54
55
56
57 private function getCreateAdvancedSettingsToLog(): array
58 {
59 $settingsToLog = [
60 $this->booleanSetting('New Admin Account', 'getUseNewAdminAccount'),
61 $this->stringSetting('Email', 'getAdminEmail'),
62 $this->sensitiveStringSetting('Password', 'getAdminPassword'),
63 $this->stringSetting('Database Server', 'getDatabaseServer'),
64 $this->stringSetting('Database User', 'getDatabaseUser'),
65 $this->sensitiveStringSetting('Database Password', 'getDatabasePassword'),
66 $this->stringSetting('Database', 'getDatabaseName'),
67 $this->stringSetting('Database Prefix', 'getDatabasePrefix'),
68 $this->booleanSetting('Database SSL', 'getDatabaseSsl'),
69 $this->stringSetting('Clone Directory', 'getCustomPath'),
70 $this->stringSetting('Clone Host', 'getCustomUrl'),
71 $this->booleanSetting('Symlink Uploads Folder', 'getIsUploadsSymlinked'),
72 $this->booleanSetting('WP CRON Enabled', 'getIsCronEnabled'),
73 $this->booleanSetting('Emails Sending Allowed', 'getIsEmailsAllowed'),
74 $this->booleanSetting('Email Reminder Enabled', 'getIsEmailsReminderEnabled'),
75 $this->booleanSetting('Auto Update Plugins Enabled', 'getIsAutoUpdatePlugins'),
76 ];
77
78 if ($this->isWooSchedulerSettingRendered()) {
79 $settingsToLog[] = $this->booleanSetting(
80 'WooCommerce Scheduler Enabled',
81 'getIsWooSchedulerEnabled'
82 );
83 }
84
85 return $settingsToLog;
86 }
87
88
89
90
91 private function getUpdateAdvancedSettingsToLog(): array
92 {
93 return [
94 $this->booleanSetting('Emails Sending Allowed', 'getIsEmailsAllowed'),
95 $this->booleanSetting('Email Reminder Enabled', 'getIsEmailsReminderEnabled'),
96 $this->booleanSetting('Auto Update Plugins Enabled', 'getIsAutoUpdatePlugins'),
97 $this->booleanSetting('Clean Plugins/Themes', 'getIsCleanPluginsThemes'),
98 $this->booleanSetting('Clean Uploads', 'getIsCleanUploads'),
99 ];
100 }
101
102
103
104
105 private function getPushAdvancedSettingsToLog(): array
106 {
107 return [
108 $this->booleanSetting('Clean Plugins/Themes', 'getIsCleanPluginsThemes'),
109 $this->booleanSetting('Clean Uploads', 'getIsCleanUploads'),
110 $this->booleanSetting('Backup Uploads', 'getIsBackupUploads'),
111 $this->booleanSetting('Create Database Backup', 'getIsCreateDatabaseBackup'),
112 ];
113 }
114
115
116
117
118
119 private function writeAdvancedSettingToLogs(array $setting)
120 {
121 switch ($setting['type']) {
122 case 'boolean':
123 $this->writeBooleanSettingToLogs($setting['label'], $setting['methods']);
124 break;
125 case 'sensitive':
126 $this->writeSensitiveStringSettingToLogs($setting['label'], $setting['methods']);
127 break;
128 default:
129 $this->writeStringSettingToLogs($setting['label'], $setting['methods']);
130 break;
131 }
132 }
133
134
135
136
137
138
139 private function stringSetting(string $label, $methods): array
140 {
141 return [
142 'type' => 'string',
143 'label' => $label,
144 'methods' => $methods,
145 ];
146 }
147
148
149
150
151
152
153 private function sensitiveStringSetting(string $label, $methods): array
154 {
155 return [
156 'type' => 'sensitive',
157 'label' => $label,
158 'methods' => $methods,
159 ];
160 }
161
162
163
164
165
166
167 private function booleanSetting(string $label, $methods): array
168 {
169 return [
170 'type' => 'boolean',
171 'label' => $label,
172 'methods' => $methods,
173 ];
174 }
175
176
177
178
179 private function isProRequirementLog(): bool
180 {
181 return strpos(static::class, '\\Pro\\') !== false;
182 }
183
184
185
186
187 private function isWooSchedulerSettingRendered(): bool
188 {
189 if (!class_exists(Licensing::class)) {
190 return false;
191 }
192
193 return WPStaging::make(Licensing::class)->licenseAllows(LicenseCapabilities::WOO_SCHEDULER);
194 }
195
196
197
198
199
200
201 private function writeStringSettingToLogs(string $label, $methods)
202 {
203 $value = $this->getLogSettingValue((array)$methods);
204 if ($value === null) {
205 return;
206 }
207
208 $this->logger->add(sprintf('- %s : %s', $label, $value !== '' ? $value : 'Not Set'), Logger::TYPE_INFO_SUB);
209 }
210
211
212
213
214
215
216 private function writeSensitiveStringSettingToLogs(string $label, $methods)
217 {
218 $value = $this->getLogSettingValue((array)$methods);
219 if ($value === null) {
220 return;
221 }
222
223 $value = $value !== '' ? '**************' : 'Not Set';
224
225 $this->logger->add(sprintf('- %s : %s', $label, $value), Logger::TYPE_INFO_SUB);
226 }
227
228
229
230
231
232
233 private function writeBooleanSettingToLogs(string $label, $methods)
234 {
235 $value = $this->getLogSettingValue((array)$methods);
236 if ($value === null) {
237 return;
238 }
239
240 $value = $value ? 'True' : 'False';
241
242 $this->logger->add(sprintf('- %s : %s', $label, $value), Logger::TYPE_INFO_SUB);
243 }
244
245
246
247
248
249 private function getLogSettingValue(array $methods)
250 {
251 $fallbackValue = null;
252 foreach ($this->getLogSettingSources() as $source) {
253 foreach ($methods as $method) {
254 if (!method_exists($source, $method)) {
255 continue;
256 }
257
258 $value = $source->{$method}();
259 if ($value !== '' && $value !== null) {
260 return $value;
261 }
262
263 $fallbackValue = $value;
264 }
265 }
266
267 return $fallbackValue;
268 }
269
270
271
272
273 private function getLogSettingSources(): array
274 {
275 return [$this->jobDataDto];
276 }
277 }
278