Ajax
1 day ago
BackgroundProcessing
1 day ago
Dto
1 day ago
Entity
1 day ago
Exceptions
1 day ago
FileHeader
1 day ago
Interfaces
1 day ago
Job
1 day ago
Request
1 day ago
Service
1 day ago
Storage
1 day ago
Task
1 day ago
Traits
1 day ago
Utils
1 day ago
AfterRestore.php
1 day ago
BackupDeleter.php
1 day ago
BackupDownload.php
1 day ago
BackupFileIndex.php
1 day ago
BackupGlitchReason.php
1 day ago
BackupHeader.php
1 day ago
BackupNextOffer.php
1 day ago
BackupRepairer.php
1 day ago
BackupRetentionHandler.php
1 day ago
BackupScheduler.php
1 day ago
BackupServiceProvider.php
1 day ago
BackupValidator.php
1 day ago
BeforeUpdateRowStatus.php
1 day ago
FileHeader.php
1 day ago
FileHeaderAttribute.php
1 day ago
UpdateProtectionPausedNotice.php
1 day ago
WithBackupIdentifier.php
1 day ago
BackupNextOffer.php
123 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Backup; |
| 4 | |
| 5 | use WPStaging\Backup\Service\BackupsFinder; |
| 6 | use WPStaging\Core\WPStaging; |
| 7 | use WPStaging\Framework\Onboarding\QueuedBackup; |
| 8 | use WPStaging\Framework\SiteInfo; |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | class BackupNextOffer |
| 23 | { |
| 24 | |
| 25 | private $queuedBackup; |
| 26 | |
| 27 | |
| 28 | private $backupsFinder; |
| 29 | |
| 30 | |
| 31 | private $backupScheduler; |
| 32 | |
| 33 | |
| 34 | private $siteInfo; |
| 35 | |
| 36 | |
| 37 | private $isEligible = null; |
| 38 | |
| 39 | public function __construct( |
| 40 | QueuedBackup $queuedBackup, |
| 41 | BackupsFinder $backupsFinder, |
| 42 | BackupScheduler $backupScheduler, |
| 43 | SiteInfo $siteInfo |
| 44 | ) { |
| 45 | $this->queuedBackup = $queuedBackup; |
| 46 | $this->backupsFinder = $backupsFinder; |
| 47 | $this->backupScheduler = $backupScheduler; |
| 48 | $this->siteInfo = $siteInfo; |
| 49 | } |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | public static function resolve() |
| 58 | { |
| 59 | try { |
| 60 | return WPStaging::make(self::class); |
| 61 | } catch (\Throwable $e) { |
| 62 | return null; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | public function isEligible(): bool |
| 73 | { |
| 74 | if ($this->isEligible === null) { |
| 75 | $this->isEligible = $this->check(); |
| 76 | } |
| 77 | |
| 78 | return $this->isEligible; |
| 79 | } |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | public function getStatus(): string |
| 85 | { |
| 86 | return $this->queuedBackup->getStatus(); |
| 87 | } |
| 88 | |
| 89 | private function check(): bool |
| 90 | { |
| 91 | if (!current_user_can('manage_options') || $this->siteInfo->isStagingSite()) { |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | |
| 96 | if ($this->queuedBackup->isPending()) { |
| 97 | return true; |
| 98 | } |
| 99 | |
| 100 | return !$this->hasSchedules() || !$this->hasBackups(); |
| 101 | } |
| 102 | |
| 103 | private function hasBackups(): bool |
| 104 | { |
| 105 | try { |
| 106 | return $this->backupsFinder->findBackups() !== []; |
| 107 | } catch (\Throwable $e) { |
| 108 | |
| 109 | |
| 110 | return true; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | private function hasSchedules(): bool |
| 115 | { |
| 116 | try { |
| 117 | return $this->backupScheduler->getSchedules() !== []; |
| 118 | } catch (\Throwable $e) { |
| 119 | return true; |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 |