PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.11.0
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.11.0
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 / Backup / Entity / FileBeingExtracted.php
wp-staging / Backup / Entity Last commit date
AbstractBackupMetadata.php 1 day ago BackupMetadata.php 1 day ago FileBeingExtracted.php 1 day ago ListableBackup.php 1 day ago MultipartMetadata.php 1 day ago
FileBeingExtracted.php
216 lines
1 <?php
2
3 namespace WPStaging\Backup\Entity;
4
5 use WPStaging\Backup\Interfaces\IndexLineInterface;
6 use WPStaging\Framework\Filesystem\PathIdentifier;
7
8
9
10
11
12
13
14
15
16
17
18 class FileBeingExtracted
19 {
20
21
22
23
24
25 private $identifiablePath;
26
27
28 private $relativePath;
29
30
31 private $start;
32
33
34 private $totalBytes;
35
36
37 private $writtenBytes = 0;
38
39
40 private $readBytes = 0;
41
42
43 protected $extractFolder;
44
45
46 protected $pathIdentifier;
47
48
49 protected $isCompressed;
50
51
52 protected $headerBytesRemoved = 0;
53
54 public function __construct(string $identifiablePath, string $extractFolder, PathIdentifier $pathIdentifier, IndexLineInterface $backupFileIndex)
55 {
56 $this->identifiablePath = $identifiablePath;
57 $this->extractFolder = rtrim($extractFolder, '/') . '/';
58 $this->start = $backupFileIndex->getContentStartOffset();
59 $this->totalBytes = $backupFileIndex->getUnCompressedSize();
60 $this->pathIdentifier = $pathIdentifier;
61 $this->isCompressed = (int)$backupFileIndex->getIsCompressed();
62 $this->relativePath = $this->pathIdentifier->getPathWithoutIdentifier($this->identifiablePath);
63 }
64
65
66
67
68
69
70 public function getBackupPath()
71 {
72 return $this->extractFolder . $this->relativePath;
73 }
74
75
76
77
78
79
80
81 public function findReadTo()
82 {
83 $maxLengthToRead = 512 * KB_IN_BYTES;
84
85 $remainingBytesToRead = $this->totalBytes - $this->readBytes;
86
87 return max(0, min($remainingBytesToRead, $maxLengthToRead));
88 }
89
90
91
92
93 public function getPath()
94 {
95 return $this->identifiablePath;
96 }
97
98
99
100
101 public function getRelativePath()
102 {
103 return $this->relativePath;
104 }
105
106
107
108
109 public function getStart()
110 {
111 return $this->start;
112 }
113
114
115
116
117 public function getTotalBytes()
118 {
119 return $this->totalBytes;
120 }
121
122
123
124
125 public function getWrittenBytes()
126 {
127 return $this->writtenBytes;
128 }
129
130
131
132
133 public function setWrittenBytes($writtenBytes)
134 {
135 $this->writtenBytes = $writtenBytes;
136 }
137
138 public function addWrittenBytes($writtenBytes)
139 {
140 $this->writtenBytes += $writtenBytes;
141 }
142
143 public function getReadBytes(): int
144 {
145 return $this->readBytes;
146 }
147
148
149
150
151
152 public function setReadBytes(int $readBytes)
153 {
154 $this->readBytes = $readBytes;
155 }
156
157
158
159
160
161 public function addReadBytes(int $readBytes)
162 {
163 $this->readBytes += $readBytes;
164 }
165
166 public function isFinished()
167 {
168 if (!$this->areHeaderBytesRemoved()) {
169 return $this->writtenBytes >= $this->totalBytes;
170 }
171
172 return $this->writtenBytes >= ($this->totalBytes - $this->headerBytesRemoved);
173 }
174
175
176
177
178 public function getIsCompressed()
179 {
180 return $this->isCompressed;
181 }
182
183 public function getCurrentOffset(): int
184 {
185 return $this->start + $this->readBytes;
186 }
187
188
189
190
191
192 public function addHeaderBytesRemoved(int $headerBytesRemoved)
193 {
194 $this->headerBytesRemoved += $headerBytesRemoved;
195 }
196
197 public function getHeaderBytesRemoved(): int
198 {
199 return $this->headerBytesRemoved;
200 }
201
202
203
204
205
206 public function setHeaderBytesRemoved(int $headerBytesRemoved)
207 {
208 $this->headerBytesRemoved = $headerBytesRemoved;
209 }
210
211 public function areHeaderBytesRemoved(): bool
212 {
213 return $this->headerBytesRemoved > 0;
214 }
215 }
216