Compression
1 day ago
Database
1 day ago
DirectoryExplorer
1 day ago
AbstractBackgroundBackupRequest.php
1 day ago
AbstractBackupsFinder.php
1 day ago
AbstractExtractor.php
1 day ago
AbstractServiceProvider.php
1 day ago
Archiver.php
1 day ago
BackupAssets.php
1 day ago
BackupContent.php
1 day ago
BackupMetadataEditor.php
1 day ago
BackupMetadataReader.php
1 day ago
BackupSigner.php
1 day ago
BackupsDirectoryResolver.php
1 day ago
BackupsFinder.php
1 day ago
BeforeUpdateBackupRequest.php
1 day ago
BeforeUpdateBackupsService.php
1 day ago
Extractor.php
1 day ago
FileBackupService.php
1 day ago
FileBackupServiceProvider.php
1 day ago
ServiceInterface.php
1 day ago
TmpBackupCleaner.php
1 day ago
UpdateProtectionHealth.php
1 day ago
UpdateProtectionSettings.php
1 day ago
ZlibCompressor.php
1 day ago
UpdateProtectionSettings.php
102 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Backup\Service; |
| 4 | |
| 5 | use WPStaging\Core\DTO\Settings; |
| 6 | use WPStaging\Core\WPStaging; |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | class UpdateProtectionSettings |
| 15 | { |
| 16 | |
| 17 | const INTRO_SURFACES = ['modal', 'notice']; |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | public function isEnabled(): bool |
| 23 | { |
| 24 | return WPStaging::make(Settings::class)->isBackupBeforeUpdateEnabled(); |
| 25 | } |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | public function getMode(): string |
| 31 | { |
| 32 | $mode = (string)get_option(Settings::OPTION_BACKUP_BEFORE_UPDATE_MODE, ''); |
| 33 | |
| 34 | return $mode === '' ? 'ask' : $mode; |
| 35 | } |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | public function forgetMode() |
| 44 | { |
| 45 | delete_option(Settings::OPTION_BACKUP_BEFORE_UPDATE_MODE); |
| 46 | } |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | public function setEnabled(bool $isEnabled) |
| 56 | { |
| 57 | $settings = json_decode(json_encode(get_option('wpstg_settings', [])), true); |
| 58 | if (!is_array($settings)) { |
| 59 | $settings = []; |
| 60 | } |
| 61 | |
| 62 | $settings['enableBackupBeforeUpdate'] = $isEnabled ? '1' : '0'; |
| 63 | update_option('wpstg_settings', $settings); |
| 64 | |
| 65 | if (!$isEnabled) { |
| 66 | $this->forgetMode(); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | public function getIntrosSeen(): array |
| 74 | { |
| 75 | return array_values(array_filter(explode(',', (string)get_option(Settings::OPTION_BACKUP_BEFORE_UPDATE_INTRO_SEEN, '')))); |
| 76 | } |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | public function hasSeenIntro(string $surface): bool |
| 83 | { |
| 84 | return in_array($surface, $this->getIntrosSeen(), true); |
| 85 | } |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | public function markIntroSeen(string $surface) |
| 92 | { |
| 93 | $seen = $this->getIntrosSeen(); |
| 94 | if (in_array($surface, $seen, true)) { |
| 95 | return; |
| 96 | } |
| 97 | |
| 98 | $seen[] = $surface; |
| 99 | update_option(Settings::OPTION_BACKUP_BEFORE_UPDATE_INTRO_SEEN, implode(',', $seen)); |
| 100 | } |
| 101 | } |
| 102 |