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