PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.11.1
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.11.1
4.11.2 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 / Backend / Modules / Jobs / Finish.php
wp-staging / Backend / Modules / Jobs Last commit date
Cleaners 1 week ago Exceptions 1 week ago Cancel.php 1 week ago CancelUpdate.php 1 week ago Cloning.php 1 week ago CloningProcess.php 1 week ago Data.php 1 week ago Database.php 1 week ago Delete.php 1 week ago Directories.php 1 week ago Files.php 1 week ago Finish.php 1 week ago Job.php 1 week ago JobExecutable.php 1 week ago Logs.php 1 week ago PreserveDataFirstStep.php 1 week ago PreserveDataSecondStep.php 1 week ago ProcessLock.php 1 week ago Scan.php 1 week ago SearchReplace.php 1 week ago TotalStepsAreNumberOfTables.php 1 week ago Updating.php 1 week ago
Finish.php
198 lines
1 <?php
2
3 namespace WPStaging\Backend\Modules\Jobs;
4
5 use WPStaging\Core\WPStaging;
6 use WPStaging\Framework\Analytics\Actions\AnalyticsStagingCreate;
7 use WPStaging\Framework\Analytics\Actions\AnalyticsStagingReset;
8 use WPStaging\Framework\Analytics\Actions\AnalyticsStagingUpdate;
9 use WPStaging\Framework\Logger\EventLoggerConst;
10 use WPStaging\Staging\Sites;
11 use WPStaging\Framework\Traits\EventLoggerTrait;
12 use WPStaging\Framework\Utils\Urls;
13 use WPStaging\Staging\Jobs\StagingSiteCreate;
14
15
16
17
18
19 class Finish extends Job
20 {
21 use EventLoggerTrait;
22
23
24
25
26
27 private $clone = '';
28
29
30
31
32 private $urls;
33
34
35
36
37
38
39 public function start()
40 {
41 $this->urls = WPStaging::make(Urls::class);
42
43
44 $this->clone = preg_replace("#\W+#", '-', strtolower($this->options->clone));
45
46 $this->deleteCacheFiles();
47
48
49 $this->prepareCloneDataRecords();
50
51 $this->options->isRunning = false;
52
53 $return = [
54 "directoryName" => $this->options->cloneDirectoryName,
55 "path" => trailingslashit($this->options->destinationDir),
56 "url" => $this->getDestinationUrl(),
57 "number" => $this->options->cloneNumber,
58 "version" => WPStaging::getVersion(),
59 "status" => 'finished',
60 "prefix" => $this->options->prefix,
61 "last_msg" => $this->logger->getLastLogMsg(),
62 "job" => $this->options->currentJob,
63 "percentage" => 100,
64 ];
65
66 $processType = EventLoggerConst::PROCESS_PREFIX_CLONE;
67 $successMessage = "Staging site successfully created";
68 switch ($this->options->mainJob) {
69 case Job::STAGING:
70 WPStaging::make(AnalyticsStagingCreate::class)->enqueueFinishEvent($this->options->jobIdentifier, $this->options);
71 do_action(StagingSiteCreate::ACTION_STAGING_SITE_CREATED, $this->options);
72 break;
73 case Job::UPDATE:
74 $processType = EventLoggerConst::PROCESS_PREFIX_CLONE_UPDATE;
75 $successMessage = 'Staging site successfully updated';
76 WPStaging::make(AnalyticsStagingUpdate::class)->enqueueFinishEvent($this->options->jobIdentifier, $this->options);
77 break;
78 case Job::RESET:
79 $processType = EventLoggerConst::PROCESS_PREFIX_CLONE_RESET;
80 $successMessage = 'Staging site successfully reset';
81 WPStaging::make(AnalyticsStagingReset::class)->enqueueFinishEvent($this->options->jobIdentifier, $this->options);
82 break;
83 }
84
85 do_action(StagingSiteCreate::ACTION_CLONING_COMPLETE, $this->options);
86
87 $this->logger->info("" . $successMessage);
88 $this->logCloneCompleted($processType);
89 return (object) $return;
90 }
91
92
93
94
95
96 protected function deleteCacheFiles()
97 {
98 $this->log("Finish: Deleting clone job's cache files...");
99
100 $this->cloneOptionCache->delete();
101 $this->filesIndexCache->delete();
102
103 $this->log("Finish: Clone job's cache files have been deleted!");
104 }
105
106
107
108
109
110
111 protected function prepareCloneDataRecords()
112 {
113
114 $this->log("Finish: Verifying existing clones...");
115
116
117 if (isset($this->options->existingClones[$this->options->clone])) {
118 if ($this->isMultisiteAndPro()) {
119 $this->options->existingClones[$this->options->clone]['url'] = $this->getDestinationUrl();
120 }
121
122 $this->options->existingClones[$this->options->clone]['datetime'] = time();
123 $this->options->existingClones[$this->options->clone]['status'] = 'finished';
124 $this->options->existingClones[$this->options->clone]['prefix'] = $this->options->prefix;
125 $this->options->existingClones[$this->options->clone]['useCustomDatabase'] = $this->isExternalDatabase();
126 $this->options->existingClones[$this->options->clone]['isCronEnabled'] = empty($this->options->isCronEnabled) ? false : true;
127 $this->options->existingClones[$this->options->clone]['isEmailsAllowed'] = (bool) $this->options->isEmailsAllowed;
128 $this->options->existingClones[$this->options->clone]['uploadsSymlinked'] = (bool) $this->options->uploadsSymlinked;
129 $this->options->existingClones[$this->options->clone]['includedTables'] = $this->options->tables;
130 $this->options->existingClones[$this->options->clone]['excludeSizeRules'] = $this->options->excludeSizeRules;
131 $this->options->existingClones[$this->options->clone]['excludeGlobRules'] = $this->options->excludeGlobRules;
132 $this->options->existingClones[$this->options->clone]['excludedDirectories'] = $this->options->excludedDirectories;
133 $this->options->existingClones[$this->options->clone]['extraDirectories'] = $this->options->extraDirectories;
134 $this->options->existingClones[$this->options->clone]['isWooSchedulerEnabled'] = empty($this->options->isWooSchedulerEnabled) ? false : true;
135 $this->options->existingClones[$this->options->clone]['isEmailsReminderEnabled'] = empty($this->options->isEmailsReminderEnabled) ? false : true;
136 $this->options->existingClones[$this->options->clone]['isAutoUpdatePlugins'] = empty($this->options->isAutoUpdatePlugins) ? false : true;
137 update_option(Sites::STAGING_SITES_OPTION, $this->options->existingClones, false);
138 $this->log("Finish: The job finished!");
139 return true;
140 }
141
142 $this->log("Finish: {$this->options->clone}'s clone job's data is not in database, generating data");
143
144 $this->options->existingClones[$this->clone] = [
145 "directoryName" => $this->options->cloneDirectoryName,
146 "path" => trailingslashit($this->options->destinationDir),
147 "url" => $this->getDestinationUrl(),
148 "number" => $this->options->cloneNumber,
149 "version" => WPStaging::getVersion(),
150 "status" => "finished",
151 "prefix" => $this->options->prefix,
152 "datetime" => time(),
153 "useCustomDatabase" => $this->isExternalDatabase(),
154 "databaseUser" => $this->options->databaseUser,
155 "databasePassword" => $this->options->databasePassword,
156 "databaseDatabase" => $this->options->databaseDatabase,
157 "databaseServer" => $this->options->databaseServer,
158 "databasePrefix" => $this->options->databasePrefix,
159 "databaseSsl" => (bool)$this->options->databaseSsl,
160 "isEmailsAllowed" => (bool) $this->options->isEmailsAllowed,
161 "uploadsSymlinked" => (bool) $this->options->uploadsSymlinked,
162 "includedTables" => $this->options->tables,
163 "excludeSizeRules" => $this->options->excludeSizeRules,
164 "excludeGlobRules" => $this->options->excludeGlobRules,
165 "excludedDirectories" => $this->options->excludedDirectories,
166 "extraDirectories" => $this->options->extraDirectories,
167 "networkClone" => $this->isNetworkClone(),
168 ];
169
170 if (update_option(Sites::STAGING_SITES_OPTION, $this->options->existingClones) === false) {
171 $this->log("Finish: Failed to save {$this->options->clone}'s clone job data to database'");
172 return false;
173 }
174
175 return true;
176 }
177
178
179
180
181
182 private function getDestinationUrl()
183 {
184 if (!empty($this->options->cloneHostname)) {
185 return $this->options->cloneHostname;
186 }
187
188
189 if (!$this->isMultisiteAndPro()) {
190 return trailingslashit(get_site_url()) . $this->options->cloneDirectoryName;
191 }
192
193
194 $multisitePath = defined('PATH_CURRENT_SITE') ? PATH_CURRENT_SITE : '/';
195 return rtrim($this->urls->getBaseUrl(), '/\\') . $multisitePath . $this->options->cloneDirectoryName;
196 }
197 }
198