PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 3.7.1
WP STAGING – WordPress Backup, Restore, Migration & Clone v3.7.1
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
BackupMetadata.php 2 years ago FileBeingExtracted.php 2 years ago ListableBackup.php 2 years ago MultipartMetadata.php 2 years ago
FileBeingExtracted.php
143 lines
1 <?php
2
3 namespace WPStaging\Backup\Entity;
4
5 use WPStaging\Backup\Interfaces\IndexLineInterface;
6 use WPStaging\Framework\Filesystem\PathIdentifier;
7 use WPStaging\Framework\Traits\ResourceTrait;
8
9 /**
10 * Class ExtractingFileEntity
11 *
12 * This is a OOP representation of a file being extracted.
13 * @todo Add strict types in separate PR
14 *
15 * @see \WPStaging\Backup\Service\Extractor
16 *
17 * @package WPStaging\Backup\Entity\Service
18 */
19 class FileBeingExtracted
20 {
21 use ResourceTrait;
22
23 /** @var string */
24 private $identifiablePath;
25
26 /** @var string */
27 private $relativePath;
28
29 /** @var int */
30 private $start;
31
32 /** @var int */
33 private $totalBytes;
34
35 /** @var int */
36 private $writtenBytes = 0;
37
38 /** @var string */
39 protected $extractFolder;
40
41 /** @var PathIdentifier */
42 protected $pathIdentifier;
43
44 /** @var int 1 if yes, 0 if no. */
45 protected $isCompressed;
46
47 public function __construct(string $identifiablePath, string $extractFolder, PathIdentifier $pathIdentifier, IndexLineInterface $backupFileIndex)
48 {
49 $this->identifiablePath = $identifiablePath;
50 $this->extractFolder = trailingslashit($extractFolder);
51 $this->start = $backupFileIndex->getContentStartOffset();
52 $this->totalBytes = $backupFileIndex->getCompressedSize();
53 $this->pathIdentifier = $pathIdentifier;
54 $this->isCompressed = (int)$backupFileIndex->getIsCompressed();
55 $this->relativePath = $this->pathIdentifier->getPathWithoutIdentifier($this->identifiablePath);
56 }
57
58 public function getBackupPath()
59 {
60 return $this->extractFolder . $this->relativePath;
61 }
62
63 public function findReadTo()
64 {
65 $maxLengthToWrite = 512 * KB_IN_BYTES;
66
67 $remainingBytesToWrite = $this->totalBytes - $this->writtenBytes;
68
69 return max(0, min($remainingBytesToWrite, $maxLengthToWrite));
70 }
71
72 /**
73 * @return string
74 */
75 public function getPath()
76 {
77 return $this->identifiablePath;
78 }
79
80 /**
81 * @return string
82 */
83 public function getRelativePath()
84 {
85 return $this->relativePath;
86 }
87
88 /**
89 * @return int
90 */
91 public function getStart()
92 {
93 return $this->start;
94 }
95
96 /**
97 * @return int
98 */
99 public function getTotalBytes()
100 {
101 return $this->totalBytes;
102 }
103
104 /**
105 * @return int
106 */
107 public function getWrittenBytes()
108 {
109 return $this->writtenBytes;
110 }
111
112 /**
113 * @param int $writtenBytes
114 */
115 public function setWrittenBytes($writtenBytes)
116 {
117 $this->writtenBytes = $writtenBytes;
118 }
119
120 public function addWrittenBytes($writtenBytes)
121 {
122 $this->writtenBytes += $writtenBytes;
123 }
124
125 public function isFinished()
126 {
127 return $this->writtenBytes >= $this->totalBytes;
128 }
129
130 /**
131 * @return bool|int
132 */
133 public function getIsCompressed()
134 {
135 return $this->isCompressed;
136 }
137
138 public function getCurrentOffset(): int
139 {
140 return $this->start + $this->writtenBytes;
141 }
142 }
143