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