BackupPluginsDetector.php
1 day ago
FirstInstall.php
1 day ago
FreeOnboarding.php
1 day ago
NextStepRenderer.php
1 day ago
OnboardingAjax.php
1 day ago
OnboardingJourney.php
1 day ago
QueuedBackup.php
1 day ago
QueuedBackup.php
182 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Framework\Onboarding; |
| 4 | |
| 5 | use WPStaging\Backup\Service\AbstractBackgroundBackupRequest; |
| 6 | use WPStaging\Core\WPStaging; |
| 7 | use WPStaging\Framework\Security\Auth; |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | class QueuedBackup extends AbstractBackgroundBackupRequest |
| 17 | { |
| 18 | |
| 19 | const OPTION_STATE = 'wpstg_onboarding_queued_backup'; |
| 20 | |
| 21 | |
| 22 | const TRANSIENT_NUDGE_LOCK = 'wpstg_onboarding_backup_nudge'; |
| 23 | |
| 24 | const EVENT_STARTED = 'queued_backup_started'; |
| 25 | const EVENT_COMPLETED = 'queued_backup_completed'; |
| 26 | const EVENT_FAILED = 'queued_backup_failed'; |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | public function queue(string $stagingJobId): bool |
| 37 | { |
| 38 | if ($this->isPending()) { |
| 39 | return false; |
| 40 | } |
| 41 | |
| 42 | $this->write([ |
| 43 | 'status' => self::STATUS_QUEUED, |
| 44 | 'staging_job_id' => $stagingJobId, |
| 45 | 'queued_at' => time(), |
| 46 | 'backup_job_id' => '', |
| 47 | ]); |
| 48 | |
| 49 | return true; |
| 50 | } |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | public function getReportedStatus(): string |
| 62 | { |
| 63 | if ($this->isPending()) { |
| 64 | return self::STATUS_RUNNING; |
| 65 | } |
| 66 | |
| 67 | $reason = WPStaging::make(OnboardingJourney::class)->getCompletionReason(); |
| 68 | |
| 69 | return $reason === OnboardingJourney::REASON_TWO_CAPABILITIES ? self::STATUS_COMPLETED : $this->getStatus(); |
| 70 | } |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | public function startAfterStagingCreated() |
| 79 | { |
| 80 | if ($this->getStatus() !== self::STATUS_QUEUED) { |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | $this->start(['isAutomatedBackup' => false]); |
| 85 | } |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | public function discardOnStagingRequest() |
| 95 | { |
| 96 | if (!WPStaging::make(Auth::class)->isAuthenticatedRequest('', 'manage_options')) { |
| 97 | return; |
| 98 | } |
| 99 | |
| 100 | $this->discard(); |
| 101 | } |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | public function discard() |
| 110 | { |
| 111 | if ($this->getStatus() !== self::STATUS_QUEUED) { |
| 112 | return; |
| 113 | } |
| 114 | |
| 115 | $this->clear(); |
| 116 | |
| 117 | WPStaging::make(OnboardingJourney::class)->cancelSecondAction(); |
| 118 | } |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | protected function getOptionName(): string |
| 124 | { |
| 125 | return self::OPTION_STATE; |
| 126 | } |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | protected function getNudgeTransientName(): string |
| 132 | { |
| 133 | return self::TRANSIENT_NUDGE_LOCK; |
| 134 | } |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | protected function getEventNames(): array |
| 140 | { |
| 141 | return [ |
| 142 | 'started' => self::EVENT_STARTED, |
| 143 | 'completed' => self::EVENT_COMPLETED, |
| 144 | 'failed' => self::EVENT_FAILED, |
| 145 | ]; |
| 146 | } |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | protected function getAnalyticsGroup(): string |
| 152 | { |
| 153 | return FreeOnboarding::ANALYTICS_GROUP; |
| 154 | } |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | protected function getLogContext(): string |
| 160 | { |
| 161 | return 'WP STAGING Onboarding'; |
| 162 | } |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | protected function afterStarted() |
| 170 | { |
| 171 | WPStaging::make(OnboardingJourney::class)->startAction(); |
| 172 | } |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | protected function afterFailed(string $reason = '') |
| 178 | { |
| 179 | WPStaging::make(OnboardingJourney::class)->cancelSecondAction(); |
| 180 | } |
| 181 | } |
| 182 |