PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / trunk
WP STAGING – WordPress Backups, Restore, Migration & Clone vtrunk
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 / Framework / Onboarding / QueuedBackup.php
wp-staging / Framework / Onboarding Last commit date
BackupPluginsDetector.php 1 week ago FirstInstall.php 1 week ago FreeOnboarding.php 1 week ago NextStepRenderer.php 1 week ago OnboardingAjax.php 1 week ago OnboardingJourney.php 5 days ago QueuedBackup.php 5 days ago
QueuedBackup.php
230 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
37
38
39
40
41
42 public function queue(string $stagingJobId): bool
43 {
44 if ($this->isPendingFor($stagingJobId) || $this->getStatus() === self::STATUS_RUNNING) {
45 return false;
46 }
47
48 $this->write([
49 'status' => self::STATUS_QUEUED,
50 'staging_job_id' => $stagingJobId,
51 'queued_at' => time(),
52 'backup_job_id' => '',
53 ]);
54
55 return true;
56 }
57
58
59
60
61
62
63
64
65
66 public function getReportedStatus(): string
67 {
68 if ($this->isPending()) {
69 return self::STATUS_RUNNING;
70 }
71
72 $reason = WPStaging::make(OnboardingJourney::class)->getCompletionReason();
73
74 return $reason === OnboardingJourney::REASON_TWO_CAPABILITIES ? self::STATUS_COMPLETED : $this->getStatus();
75 }
76
77
78
79
80
81
82
83
84
85
86
87 public function isPendingFor(string $stagingJobId): bool
88 {
89 if (!$this->isPending()) {
90 return false;
91 }
92
93 $state = $this->read();
94
95 return isset($state['staging_job_id']) && $state['staging_job_id'] === $stagingJobId;
96 }
97
98
99
100
101
102
103
104 public function startAfterStagingCreated()
105 {
106 if ($this->getStatus() !== self::STATUS_QUEUED) {
107 return;
108 }
109
110 $this->start(['isAutomatedBackup' => false]);
111 }
112
113
114
115
116
117
118
119
120 public function discardOnStagingRequest()
121 {
122 if (!WPStaging::make(Auth::class)->isAuthenticatedRequest('', 'manage_options')) {
123 return;
124 }
125
126 $this->discard();
127 }
128
129
130
131
132
133
134
135
136
137
138
139
140
141 public function discard()
142 {
143 if (!$this->isPending()) {
144 return;
145 }
146
147 if ($this->getStatus() === self::STATUS_RUNNING && !$this->cancelRunningBackup()) {
148 return;
149 }
150
151 $this->clear();
152
153 WPStaging::make(OnboardingJourney::class)->cancelSecondAction();
154 }
155
156
157
158
159 protected function getOptionName(): string
160 {
161 return self::OPTION_STATE;
162 }
163
164
165
166
167 public function clearUnlessPending()
168 {
169 if ($this->isPending()) {
170 return;
171 }
172
173 $this->clear();
174 }
175
176
177
178
179 protected function getNudgeTransientName(): string
180 {
181 return self::TRANSIENT_NUDGE_LOCK;
182 }
183
184
185
186
187 protected function getEventNames(): array
188 {
189 return [
190 'started' => self::EVENT_STARTED,
191 'completed' => self::EVENT_COMPLETED,
192 'failed' => self::EVENT_FAILED,
193 ];
194 }
195
196
197
198
199 protected function getAnalyticsGroup(): string
200 {
201 return FreeOnboarding::ANALYTICS_GROUP;
202 }
203
204
205
206
207 protected function getLogContext(): string
208 {
209 return 'WP STAGING Onboarding';
210 }
211
212
213
214
215
216
217 protected function afterStarted()
218 {
219 WPStaging::make(OnboardingJourney::class)->startAction();
220 }
221
222
223
224
225 protected function afterFailed(string $reason = '')
226 {
227 WPStaging::make(OnboardingJourney::class)->cancelSecondAction();
228 }
229 }
230