PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 3.8.2
WP STAGING – WordPress Backup, Restore, Migration & Clone v3.8.2
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 / Updating.php
wp-staging / Backend / Modules / Jobs Last commit date
Cleaners 5 years ago Exceptions 5 years ago Cancel.php 2 years ago CancelUpdate.php 2 years ago Cloning.php 2 years ago CloningProcess.php 2 years ago Data.php 2 years ago Database.php 2 years ago Delete.php 2 years ago Directories.php 2 years ago Files.php 2 years ago Finish.php 1 year ago Job.php 2 years ago JobExecutable.php 2 years ago Logs.php 3 years ago PreserveDataFirstStep.php 3 years ago PreserveDataSecondStep.php 2 years ago ProcessLock.php 2 years ago Scan.php 2 years ago SearchReplace.php 2 years ago TotalStepsAreNumberOfTables.php 5 years ago Updating.php 2 years ago
Updating.php
261 lines
1 <?php
2
3 namespace WPStaging\Backend\Modules\Jobs;
4
5 use Exception;
6 use stdClass;
7 use WPStaging\Core\WPStaging;
8 use WPStaging\Framework\Database\SelectedTables;
9 use WPStaging\Framework\Filesystem\PathIdentifier;
10 use WPStaging\Framework\Filesystem\Scanning\ScanConst;
11 use WPStaging\Framework\Utils\Urls;
12 use WPStaging\Framework\Utils\Sanitize;
13 use WPStaging\Framework\Utils\WpDefaultDirectories;
14 use WPStaging\Framework\Traits\ValueGetterTrait;
15
16 /**
17 * Class Cloning
18 * @package WPStaging\Backend\Modules\Jobs
19 */
20 class Updating extends Job
21 {
22 use ValueGetterTrait;
23
24 /**
25 * External Database Used
26 * @var bool
27 */
28 public $isExternalDb;
29
30 /**
31 * @var string
32 */
33 private $mainJob;
34
35 /**
36 * @var WpDefaultDirectories
37 */
38 private $dirUtils;
39
40 /**
41 * @var Sanitize
42 */
43 private $sanitize;
44
45 /**
46 * @var Urls
47 */
48 private $urls;
49
50 /**
51 * Initialize is called in \Job
52 */
53 public function initialize()
54 {
55 $this->mainJob = Job::UPDATE;
56 $this->dirUtils = new WpDefaultDirectories();
57 $this->sanitize = WPStaging::make(Sanitize::class);
58 $this->urls = WPStaging::make(Urls::class);
59 }
60
61 /**
62 * @param $mainJob
63 */
64 public function setMainJob($mainJob)
65 {
66 $this->mainJob = $mainJob;
67 }
68
69 /**
70 * @return string
71 */
72 public function getMainJob()
73 {
74 return $this->mainJob;
75 }
76
77 /**
78 * Save Chosen Cloning Settings
79 * @return bool
80 * @throws Exception
81 */
82 public function save()
83 {
84 if (!isset($_POST) || !isset($_POST["cloneID"])) {
85 return false;
86 }
87
88 // Delete files to copy listing
89 $this->filesIndexCache->delete();
90
91 // Generate Options
92 $this->options->clone = preg_replace("#\W+#", '-', strtolower($this->sanitize->sanitizeString($_POST["cloneID"])));
93 $this->options->cloneNumber = 1;
94 $this->options->includedDirectories = [];
95 $this->options->excludedDirectories = [];
96 $this->options->extraDirectories = [];
97 $this->options->excludeGlobRules = [];
98 $this->options->excludeSizeRules = [];
99 $this->options->excludedFiles = [
100 '.htaccess',
101 '.DS_Store',
102 '*.git',
103 '*.svn',
104 '*.tmp',
105 'desktop.ini',
106 '.gitignore',
107 '*.log',
108 'object-cache.php',
109 'web.config', // Important: Windows IIS configuration file. Do not copy this to the staging site is staging site is placed into subfolder
110 '.wp-staging-cloneable', // File which make staging site to be cloneable
111 ];
112
113 $this->options->excludedFilesFullPath = [
114 PathIdentifier::IDENTIFIER_WP_CONTENT . 'db.php',
115 PathIdentifier::IDENTIFIER_WP_CONTENT . 'object-cache.php',
116 PathIdentifier::IDENTIFIER_WP_CONTENT . 'advanced-cache.php'
117 ];
118
119 // Define mainJob to differentiate between cloning, updating and pushing
120 $this->options->mainJob = $this->mainJob;
121
122 // Only exclude wp-config.php during UPDATE not RESET
123 if ($this->excludeWpConfigDuringUpdate()) {
124 $this->options->excludedFilesFullPath[] = 'wp-config.php';
125 }
126
127 // Job
128 $this->options->job = new stdClass();
129
130 // Check if clone data already exists and use that one
131 if (isset($this->options->existingClones[$this->options->clone])) {
132 $currentStagingSite = $this->options->existingClones[$this->options->clone];
133 $this->options->cloneName = $this->getValueFromArray('cloneName', $currentStagingSite);
134 $this->options->cloneDirectoryName = $this->getValueFromArray('directoryName', $currentStagingSite);
135 $this->options->cloneNumber = $this->getValueFromArray('number', $currentStagingSite);
136 $this->options->databaseUser = $this->getValueFromArray('databaseUser', $currentStagingSite);
137 $this->options->databasePassword = $this->getValueFromArray('databasePassword', $currentStagingSite);
138 $this->options->databaseDatabase = $this->getValueFromArray('databaseDatabase', $currentStagingSite);
139 $this->options->databaseServer = $this->getValueFromArray('databaseServer', $currentStagingSite);
140 $this->options->databasePrefix = $this->getValueFromArray('databasePrefix', $currentStagingSite);
141 $this->options->databaseSsl = $this->getValueFromArray('databaseSsl', $currentStagingSite);
142 $this->options->destinationHostname = $this->getValueFromArray('url', $currentStagingSite);
143 $this->options->uploadsSymlinked = $this->getValueFromArray('uploadsSymlinked', $currentStagingSite);
144 $this->options->prefix = $this->getValueFromArray('prefix', $currentStagingSite);
145 $this->options->emailsAllowed = $this->getValueFromArray('emailsAllowed', $currentStagingSite);
146 $this->options->networkClone = filter_var($this->getValueFromArray('networkClone', $currentStagingSite), FILTER_VALIDATE_BOOLEAN);
147 $this->options->homeHostname = $this->urls->getHomeUrlWithoutScheme();
148 $this->options->useNewAdminAccount = $this->getValueFromArray('useNewAdminAccount', $currentStagingSite);
149 $this->options->adminEmail = $this->getValueFromArray('adminEmail', $currentStagingSite);
150 $this->options->adminPassword = $this->getValueFromArray('adminPassword', $currentStagingSite);
151 } else {
152 $job = 'update';
153 if ($this->mainJob === Job::RESET) {
154 $job = 'reset';
155 }
156
157 wp_die(sprintf("Fatal Error: Can not %s clone because there is no clone data.", esc_html($job)));
158 }
159
160 $this->isExternalDb = !(empty($this->options->databaseUser) && empty($this->options->databasePassword));
161
162 /**
163 * @see /WPStaging/Framework/CloningProcess/ExcludedPlugins.php to exclude plugins
164 * Only add other directories here
165 */
166 $excludedDirectories = [
167 PathIdentifier::IDENTIFIER_WP_CONTENT . 'cache',
168 ];
169
170 // Add upload folder to list of excluded directories for push if symlink option is enabled
171 if ($this->options->uploadsSymlinked) {
172 $excludedDirectories[] = PathIdentifier::IDENTIFIER_UPLOADS;
173 }
174
175 $this->options->excludedDirectories = $excludedDirectories;
176
177 $this->setTablesForUpdateJob();
178 $this->setDirectoriesForUpdateJob();
179
180 // Make sure it is always enabled for free version
181 $this->options->emailsAllowed = true;
182 if (defined('WPSTGPRO_VERSION')) {
183 $this->options->emailsAllowed = isset($_POST['emailsAllowed']) && $this->sanitize->sanitizeBool($_POST['emailsAllowed']);
184 }
185
186 $this->options->cloneDir = $this->options->existingClones[$this->options->clone]['path'];
187 $this->options->destinationDir = $this->getDestinationDir();
188 $this->options->cloneHostname = $this->options->destinationHostname;
189
190 // Process lock state
191 $this->options->isRunning = true;
192
193 return $this->saveOptions();
194 }
195
196 /**
197 * Get Destination Directory including staging subdirectory
198 * @return string
199 */
200 private function getDestinationDir()
201 {
202 if (empty($this->options->cloneDir)) {
203 return trailingslashit(WPStaging::getWPpath() . $this->options->cloneDirectoryName);
204 }
205
206 return trailingslashit($this->options->cloneDir);
207 }
208
209 private function setDirectoriesForUpdateJob()
210 {
211 // Exclude Glob Rules
212 $this->options->excludeGlobRules = [];
213 if (!empty($_POST["excludeGlobRules"])) {
214 $this->options->excludeGlobRules = $this->sanitize->sanitizeExcludeRules($_POST["excludeGlobRules"]);
215 }
216
217 $this->options->excludeSizeRules = [];
218 if (!empty($_POST["excludeSizeRules"])) {
219 $this->options->excludeSizeRules = $this->sanitize->sanitizeExcludeRules($_POST["excludeSizeRules"]);
220 }
221
222 // Excluded Directories
223 $excludedDirectoriesRequest = isset($_POST["excludedDirectories"]) ? $this->sanitize->sanitizeString($_POST["excludedDirectories"]) : '';
224 $excludedDirectoriesRequest = $this->dirUtils->getExcludedDirectories($excludedDirectoriesRequest);
225 $this->options->excludedDirectories = array_merge($this->options->excludedDirectories, $excludedDirectoriesRequest);
226 // Extra Directories
227 if (isset($_POST["extraDirectories"])) {
228 $this->options->extraDirectories = explode(ScanConst::DIRECTORIES_SEPARATOR, $this->sanitize->sanitizeString($_POST["extraDirectories"]));
229 }
230
231 // delete uploads folder before copying if uploads is not symlinked
232 $this->options->deleteUploadsFolder = !$this->options->uploadsSymlinked && isset($_POST['cleanUploadsDir']) && $this->sanitize->sanitizeBool($_POST['cleanUploadsDir']);
233 // should not backup uploads during update process
234 $this->options->backupUploadsFolder = false;
235 // clean plugins and themes dir before updating
236 $this->options->deletePluginsAndThemes = isset($_POST['cleanPluginsThemes']) && $this->sanitize->sanitizeBool($_POST['cleanPluginsThemes']);
237 // set default statuses for backup of uploads dir and cleaning of uploads, themes and plugins dirs
238 $this->options->statusBackupUploadsDir = 'skipped';
239 $this->options->statusContentCleaner = 'pending';
240 }
241
242 private function setTablesForUpdateJob()
243 {
244 // Included Tables / Prefixed Table - Excluded Tables
245 $includedTables = isset($_POST['includedTables']) ? $this->sanitize->sanitizeString($_POST['includedTables']) : '';
246 $excludedTables = isset($_POST['excludedTables']) ? $this->sanitize->sanitizeString($_POST['excludedTables']) : '';
247 $selectedTablesWithoutPrefix = isset($_POST['selectedTablesWithoutPrefix']) ? $this->sanitize->sanitizeString($_POST['selectedTablesWithoutPrefix']) : '';
248 $selectedTables = new SelectedTables($includedTables, $excludedTables, $selectedTablesWithoutPrefix);
249 $selectedTables->setAllTablesExcluded(empty($_POST['allTablesExcluded']) ? false : $this->sanitize->sanitizeBool($_POST['allTablesExcluded']));
250 $this->options->tables = $selectedTables->getSelectedTables($this->options->networkClone);
251 }
252
253 /**
254 * Start the cloning job
255 * not used but is abstract
256 */
257 public function start()
258 {
259 }
260 }
261