PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.7.0
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.7.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 / Staging / Service / AbstractStagingSetup.php
wp-staging / Staging / Service Last commit date
Database 6 months ago AbstractStagingSetup.php 6 months ago DirectoryScanner.php 6 months ago FileCopier.php 6 months ago StagingSetup.php 6 months ago TableScanner.php 10 months ago
AbstractStagingSetup.php
258 lines
1 <?php
2
3 namespace WPStaging\Staging\Service;
4
5 use WPStaging\Backend\Modules\SystemInfo;
6 use WPStaging\Framework\Assets\Assets;
7 use WPStaging\Framework\TemplateEngine\TemplateEngine;
8 use WPStaging\Framework\Utils\WpDefaultDirectories;
9 use WPStaging\Staging\Dto\StagingSiteDto;
10
11 /**
12 * @package WPStaging\Staging\Service
13 */
14 abstract class AbstractStagingSetup
15 {
16 /** @var string */
17 const JOB_NEW_STAGING_SITE = 'new';
18
19 /** @var string */
20 const JOB_UPDATE = 'update';
21
22 /** @var string */
23 const JOB_RESET = 'reset';
24
25 /** @var string */
26 const JOB_PUSH = 'push';
27
28 /**
29 * @var StagingSiteDto
30 */
31 protected $stagingSiteDto;
32
33 /**
34 * @var TemplateEngine
35 */
36 protected $templateEngine;
37
38 /**
39 * @var bool
40 */
41 protected $openDisabledSettingsSectionByDefault = true;
42
43 /**
44 * @var string
45 */
46 protected $stagingJob;
47
48 /**
49 * @var string
50 */
51 private $infoIcon;
52
53 /**
54 * @var WpDefaultDirectories
55 */
56 private $wpDefaultDirectories;
57
58 public function __construct(TemplateEngine $templateEngine, Assets $assets, WpDefaultDirectories $wpDefaultDirectories)
59 {
60 $this->templateEngine = $templateEngine;
61 $this->infoIcon = $assets->getAssetsUrl('svg/info-outline.svg');
62 $this->wpDefaultDirectories = $wpDefaultDirectories;
63 }
64
65 /**
66 * @return void
67 */
68 public function initNewStagingSite()
69 {
70 $this->stagingJob = StagingSetup::JOB_NEW_STAGING_SITE;
71 $this->stagingSiteDto = new StagingSiteDto();
72 }
73
74 /**
75 * @param StagingSiteDto $stagingSiteDto
76 * @return void
77 */
78 public function initUpdateJob(StagingSiteDto $stagingSiteDto)
79 {
80 $this->stagingJob = StagingSetup::JOB_UPDATE;
81 $this->stagingSiteDto = $stagingSiteDto;
82 }
83
84 /**
85 * @param StagingSiteDto $stagingSiteDto
86 * @return void
87 */
88 public function initResetJob(StagingSiteDto $stagingSiteDto)
89 {
90 $this->stagingJob = StagingSetup::JOB_RESET;
91 $this->stagingSiteDto = $stagingSiteDto;
92 }
93
94 public function isNewStagingSite(): bool
95 {
96 return $this->stagingJob === StagingSetup::JOB_NEW_STAGING_SITE;
97 }
98
99 public function isUpdateJob(): bool
100 {
101 return $this->stagingJob === StagingSetup::JOB_UPDATE;
102 }
103
104 public function isResetJob(): bool
105 {
106 return $this->stagingJob === StagingSetup::JOB_RESET;
107 }
108
109 public function isPushJob(): bool
110 {
111 return $this->stagingJob === StagingSetup::JOB_PUSH;
112 }
113
114 public function isUpdateOrResetJob(): bool
115 {
116 return $this->isUpdateJob() || $this->isResetJob();
117 }
118
119 public function setStagingSiteDto(StagingSiteDto $stagingSiteDto)
120 {
121 $this->stagingSiteDto = $stagingSiteDto;
122 }
123
124 public function getStagingSiteDto(): StagingSiteDto
125 {
126 return $this->stagingSiteDto;
127 }
128
129 public function getRoot(): string
130 {
131 return wp_normalize_path(ABSPATH);
132 }
133
134 public function renderSettings(string $name, string $label, string $description, bool $checked = false, bool $disabled = false, string $additionalClasses = '', string $dataId = '')
135 {
136 $view = $this->templateEngine->render(
137 'staging/_partials/settings.php',
138 [
139 'name' => $name,
140 'label' => $label,
141 'description' => $description,
142 'checked' => $checked,
143 'disabled' => $disabled,
144 'classes' => $additionalClasses,
145 'dataId' => $dataId,
146 'infoIcon' => $this->infoIcon,
147 ]
148 );
149
150 echo $view; // phpcs:ignore
151 }
152
153 public function getSymlinkUploadDescription(): string
154 {
155 return sprintf(esc_html__('Activate to symlink the folder %s to the production site. %s All files including images on the production site\'s uploads folder will be linked to the staging site uploads folder. This will speed up the cloning and pushing process tremendously as no files from the uploads folder are copied between both sites. %s Warning: this can lead to mixed and shared content issues if both sites load (custom) stylesheet files from the same uploads folder. %s Using this option means changing images on the staging site will change images on the production site as well. Use this with care! %s', 'wp-staging'), '<code>' . esc_html($this->wpDefaultDirectories->getRelativeUploadPath()) . '</code>', '<br><br>', '<br><br><span class="wpstg--red">', '<br><br>', '</span>');
156 }
157
158 public function getCustomDirectoryDescription(): string
159 {
160 return $this->templateEngine->render(
161 'staging/setup/custom-directory-desc.php',
162 [
163 'systemInfo' => new SystemInfo(),
164 ]
165 );
166 }
167
168 public function getIsOpenDisabledSettingsSectionByDefault(): bool
169 {
170 return $this->openDisabledSettingsSectionByDefault;
171 }
172
173 abstract public function renderNetworkCloneSettings();
174
175 abstract public function getAdvanceSettingsTitle(): string;
176
177 abstract public function renderAdvanceSettingsHeader();
178
179 abstract public function renderAdvanceSettings(string $name, string $label, string $description, bool $checked = false, string $additionalClasses = '', string $dataId = '');
180
181 abstract public function renderNewAdminSettings();
182
183 abstract public function renderExternalDatabaseSettings();
184
185 abstract public function renderCustomDirectorySettings();
186
187 abstract public function renderEnableWooSchedulerSettings();
188
189 protected function renderSettingsFields(array $fields)
190 {
191 foreach ($fields as $field) {
192 $type = $field['type'] ?? 'text';
193 if ($type === 'checkbox') {
194 $this->renderCheckbox(
195 $field['name'],
196 $field['label'],
197 $field['value'] ?? 'true',
198 $field['checked'] ?? false,
199 $field['disabled'] ?? false
200 );
201
202 continue;
203 }
204
205 $this->renderField(
206 $field['name'],
207 $field['label'],
208 $type,
209 $field['placeholder'] ?? '',
210 $field['description'] ?? '',
211 $field['disabled'] ?? false,
212 $field['autocapitalize'] ?? true,
213 $field['autocomplete'] ?? true
214 );
215 }
216 }
217
218 protected function renderField(string $name, string $label, string $type = 'text', string $placeholder = '', string $description = '', bool $disabled = false, bool $autocapitalize = true, bool $autocomplete = true)
219 {
220 $view = $this->templateEngine->render(
221 'staging/_partials/settings-field.php',
222 [
223 'name' => $name,
224 'label' => $label,
225 'type' => $type,
226 'placeholder' => $placeholder,
227 'description' => $description,
228 'disabled' => $disabled,
229 'autocapitalize' => $autocapitalize,
230 'autocomplete' => $autocomplete,
231 ]
232 );
233
234 if ($type === 'password') {
235 echo '<form>' . $view . '</form>'; // phpcs:ignore
236 return;
237 }
238
239 echo $view; // phpcs:ignore
240 }
241
242 protected function renderCheckbox(string $name, string $label, string $value, bool $checked = false, bool $disabled = false)
243 {
244 $view = $this->templateEngine->render(
245 'staging/_partials/settings-checkbox.php',
246 [
247 'name' => $name,
248 'label' => $label,
249 'value' => $value,
250 'checked' => $checked,
251 'disabled' => $disabled,
252 ]
253 );
254
255 echo $view; // phpcs:ignore
256 }
257 }
258