PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 3.0.6
WP STAGING – WordPress Backups, Restore, Migration & Clone v3.0.6
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 / Verify.php
wp-staging / Backend / Modules / Jobs Last commit date
Cleaners 5 years ago Exceptions 5 years ago Cancel.php 3 years ago CancelUpdate.php 4 years ago Cloning.php 3 years ago CloningProcess.php 3 years ago Data.php 3 years ago Database.php 3 years ago Delete.php 3 years ago Directories.php 2 years ago Files.php 2 years ago Finish.php 2 years ago Job.php 2 years ago JobExecutable.php 3 years ago Logs.php 3 years ago PreserveDataFirstStep.php 3 years ago PreserveDataSecondStep.php 3 years ago ProcessLock.php 3 years ago Scan.php 2 years ago SearchReplace.php 3 years ago TotalStepsAreNumberOfTables.php 5 years ago Updating.php 3 years ago Verify.php 3 years ago
Verify.php
178 lines
1 <?php
2
3 namespace WPStaging\Backend\Modules\Jobs;
4
5 // No Direct Access
6 use WPStaging\Core\Utils\Logger;
7
8 if (!defined("WPINC")) {
9 die;
10 }
11
12 /**
13 * Class Files
14 * @package WPStaging\Backend\Modules\Jobs
15 */
16 class Verify extends JobExecutable
17 {
18
19 /**
20 * @var array
21 */
22 private $files = [];
23
24 /**
25 * @var array
26 */
27 private $verifyFiles = [];
28
29 /**
30 * @var int
31 */
32 private $maxFilesPerRun;
33
34 /**
35 * @var string
36 */
37 private $destination;
38
39 /**
40 * Initialization
41 */
42 public function initialize()
43 {
44 $this->destination = ABSPATH . $this->options->cloneDirectoryName . DIRECTORY_SEPARATOR;
45
46 $this->getCopyFiles();
47 $this->getVerifyFiles();
48
49 // Informational logs
50 if ($this->options->currentStep == 0) {
51 $this->log("Verifying files...");
52 }
53
54 $this->settings->batchSize = $this->settings->batchSize * 1000000;
55 $this->maxFilesPerRun = 1;
56 $this->options->verifiedFiles = 0;
57 }
58
59 /**
60 * Calculate Total Steps in This Job and Assign It to $this->options->totalSteps
61 * @return void
62 */
63 protected function calculateTotalSteps()
64 {
65 $this->options->totalSteps = ceil($this->options->totalFiles / $this->maxFilesPerRun);
66 }
67
68 /**
69 * Execute the Current Step
70 * Returns false when over threshold limits are hit or when the job is done, true otherwise
71 * @return bool
72 */
73 protected function execute()
74 {
75 // Finished
76 if ($this->isFinished()) {
77 $this->log("Verifying files finished");
78 $this->prepareResponse(true, false);
79 return false;
80 }
81
82 // Get files and copy'em
83 if (!$this->getFilesAndVerify()) {
84 $this->prepareResponse(false, false);
85 $this->saveOptions();
86 return false;
87 }
88
89 // Prepare and return response
90 $this->prepareResponse();
91
92 // Not finished
93 return true;
94 }
95
96 /**
97 * Get files and copy
98 * @return bool
99 */
100 private function getFilesAndVerify()
101 {
102 // Over limits threshold
103 if ($this->isOverThreshold()) {
104 // Prepare response and save current progress
105 $this->prepareResponse(false, false);
106 $this->saveOptions();
107 return false;
108 }
109 $this->saveVerifyFiles();
110 $this->saveOptions();
111 //$this->log(json_encode(array_diff($this->files, $this->verifyFiles)));
112 //wp_die(print_r(array_diff($this->files, $this->verifyFiles)));
113 return true;
114 }
115
116 /**
117 * Get files
118 * @return void
119 */
120 protected function getVerifyFiles()
121 {
122 $file = $this->cache->getCacheDir() . "files_to_verify." . $this->cache->getCacheExtension();
123
124 $fileContent = file_get_contents($file);
125 if ($fileContent === false) {
126 $this->verifyFiles = [];
127 return;
128 }
129
130 $this->verifyFiles = explode(PHP_EOL, $fileContent);
131 }
132
133 /**
134 * Get files
135 * @return void
136 */
137 protected function getCopyFiles()
138 {
139 $file = $this->cache->getCacheDir() . "files_to_copy." . $this->cache->getCacheExtension();
140
141 $fileContent = file_get_contents($file);
142 if ($fileContent === false) {
143 $this->verifyFiles = [];
144 return;
145 }
146
147 $this->verifyFiles = explode(PHP_EOL, $fileContent);
148 }
149
150 /**
151 * Save Result of File Verification
152 * @return bool
153 */
154 protected function saveVerifyFiles()
155 {
156
157 // Get file copy differences
158 $filesVerified = array_diff($this->files, $this->verifyFiles);
159
160 $fileName = $this->cache->getCacheDir() . "files_verified" . $this->cache->getCacheExtension();
161 $files = implode(PHP_EOL, $filesVerified);
162
163 return (@wpstg_put_contents($fileName, $files) !== false);
164 }
165
166 /**
167 * Checks Whether There is Any Job to Execute or Not
168 * @return bool
169 */
170 private function isFinished()
171 {
172 return (
173 $this->options->currentStep > $this->options->totalSteps ||
174 $this->options->verifiedFiles >= $this->options->totalFiles
175 );
176 }
177 }
178