Database
1 day ago
AbstractStagingSetup.php
1 day ago
DirectoryScanner.php
1 day ago
FileCopier.php
1 day ago
LegacyOptionsCache.php
1 day ago
StagingEngine.php
1 day ago
StagingSetup.php
1 day ago
TableScanner.php
1 day ago
AbstractStagingSetup.php
280 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 | |
| 13 | |
| 14 | abstract class AbstractStagingSetup |
| 15 | { |
| 16 | |
| 17 | const JOB_NEW_STAGING_SITE = 'new'; |
| 18 | |
| 19 | |
| 20 | const JOB_UPDATE = 'update'; |
| 21 | |
| 22 | |
| 23 | const JOB_RESET = 'reset'; |
| 24 | |
| 25 | |
| 26 | const JOB_PUSH = 'push'; |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | protected $stagingSiteDto; |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | protected $templateEngine; |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | protected $openDisabledSettingsSectionByDefault = true; |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | protected $stagingJob; |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | private $infoIcon; |
| 52 | |
| 53 | |
| 54 | |
| 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 | |
| 67 | |
| 68 | public function initNewStagingSite() |
| 69 | { |
| 70 | $this->stagingJob = StagingSetup::JOB_NEW_STAGING_SITE; |
| 71 | $this->stagingSiteDto = new StagingSiteDto(); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | public function initUpdateJob(StagingSiteDto $stagingSiteDto) |
| 79 | { |
| 80 | $this->stagingJob = StagingSetup::JOB_UPDATE; |
| 81 | $this->stagingSiteDto = $stagingSiteDto; |
| 82 | } |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 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 | |
| 135 | |
| 136 | |
| 137 | public function renderSettings(string $name, string $label, string $description, bool $checked = false, bool $disabled = false, string $additionalClasses = '', string $dataId = '', string $summary = '', string $content = '', $tooltip = null) |
| 138 | { |
| 139 | $view = $this->templateEngine->render( |
| 140 | 'staging/_partials/settings.php', |
| 141 | [ |
| 142 | 'name' => $name, |
| 143 | 'label' => $label, |
| 144 | 'description' => $description, |
| 145 | 'summary' => $summary, |
| 146 | 'checked' => $checked, |
| 147 | 'disabled' => $disabled, |
| 148 | 'classes' => $additionalClasses, |
| 149 | 'dataId' => $dataId, |
| 150 | 'infoIcon' => $this->infoIcon, |
| 151 | 'content' => $content, |
| 152 | 'tooltip' => $tooltip === null ? $description : $tooltip, |
| 153 | ] |
| 154 | ); |
| 155 | |
| 156 | echo $view; // phpcs:ignore |
| 157 | } |
| 158 | |
| 159 | public function getSymlinkUploadDescription(): string |
| 160 | { |
| 161 | return sprintf(esc_html__('Activate to symlink the folder %s%s%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>'); |
| 162 | } |
| 163 | |
| 164 | public function getCustomDirectoryDescription(): string |
| 165 | { |
| 166 | return $this->templateEngine->render( |
| 167 | 'staging/setup/custom-directory-desc.php', |
| 168 | [ |
| 169 | 'systemInfo' => new SystemInfo(), |
| 170 | ] |
| 171 | ); |
| 172 | } |
| 173 | |
| 174 | public function getIsOpenDisabledSettingsSectionByDefault(): bool |
| 175 | { |
| 176 | return $this->openDisabledSettingsSectionByDefault; |
| 177 | } |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | public function isProLicenseActive(): bool |
| 188 | { |
| 189 | return false; |
| 190 | } |
| 191 | |
| 192 | abstract public function renderNetworkCloneSettings(); |
| 193 | |
| 194 | abstract public function getAdvanceSettingsTitle(): string; |
| 195 | |
| 196 | abstract public function renderAdvanceSettingsHeader(); |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | abstract public function renderAdvanceSettings(string $name, string $label, string $description, bool $checked = false, string $additionalClasses = '', string $dataId = '', string $summary = '', string $content = '', $tooltip = null); |
| 202 | |
| 203 | abstract public function renderNewAdminSettings(); |
| 204 | |
| 205 | abstract public function renderExternalDatabaseSettings(); |
| 206 | |
| 207 | abstract public function renderCustomDirectorySettings(); |
| 208 | |
| 209 | abstract public function renderEnableWooSchedulerSettings(); |
| 210 | |
| 211 | protected function renderSettingsFields(array $fields) |
| 212 | { |
| 213 | foreach ($fields as $field) { |
| 214 | $type = $field['type'] ?? 'text'; |
| 215 | if ($type === 'checkbox') { |
| 216 | $this->renderCheckbox( |
| 217 | $field['name'], |
| 218 | $field['label'], |
| 219 | $field['value'] ?? 'true', |
| 220 | $field['checked'] ?? false, |
| 221 | $field['disabled'] ?? false |
| 222 | ); |
| 223 | |
| 224 | continue; |
| 225 | } |
| 226 | |
| 227 | $this->renderField( |
| 228 | $field['name'], |
| 229 | $field['label'], |
| 230 | $type, |
| 231 | $field['placeholder'] ?? '', |
| 232 | $field['description'] ?? '', |
| 233 | $field['disabled'] ?? false, |
| 234 | $field['autocapitalize'] ?? true, |
| 235 | $field['autocomplete'] ?? true |
| 236 | ); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | protected function renderField(string $name, string $label, string $type = 'text', string $placeholder = '', string $description = '', bool $disabled = false, bool $autocapitalize = true, bool $autocomplete = true) |
| 241 | { |
| 242 | $view = $this->templateEngine->render( |
| 243 | 'staging/_partials/settings-field.php', |
| 244 | [ |
| 245 | 'name' => $name, |
| 246 | 'label' => $label, |
| 247 | 'type' => $type, |
| 248 | 'placeholder' => $placeholder, |
| 249 | 'description' => $description, |
| 250 | 'disabled' => $disabled, |
| 251 | 'autocapitalize' => $autocapitalize, |
| 252 | 'autocomplete' => $autocomplete, |
| 253 | ] |
| 254 | ); |
| 255 | |
| 256 | if ($type === 'password') { |
| 257 | echo '<form>' . $view . '</form>'; // phpcs:ignore |
| 258 | return; |
| 259 | } |
| 260 | |
| 261 | echo $view; // phpcs:ignore |
| 262 | } |
| 263 | |
| 264 | protected function renderCheckbox(string $name, string $label, string $value, bool $checked = false, bool $disabled = false) |
| 265 | { |
| 266 | $view = $this->templateEngine->render( |
| 267 | 'staging/_partials/settings-checkbox.php', |
| 268 | [ |
| 269 | 'name' => $name, |
| 270 | 'label' => $label, |
| 271 | 'value' => $value, |
| 272 | 'checked' => $checked, |
| 273 | 'disabled' => $disabled, |
| 274 | ] |
| 275 | ); |
| 276 | |
| 277 | echo $view; // phpcs:ignore |
| 278 | } |
| 279 | } |
| 280 |