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 / BackupRepairer.php
wp-staging / Backup Last commit date
Ajax 1 day ago BackgroundProcessing 1 day ago Dto 1 day ago Entity 1 day ago Exceptions 1 day ago FileHeader 1 day ago Interfaces 1 day ago Job 1 day ago Request 1 day ago Service 1 day ago Storage 1 day ago Task 1 day ago Traits 1 day ago Utils 1 day ago AfterRestore.php 1 day ago BackupDeleter.php 1 day ago BackupDownload.php 1 day ago BackupFileIndex.php 1 day ago BackupGlitchReason.php 1 day ago BackupHeader.php 1 day ago BackupNextOffer.php 1 day ago BackupRepairer.php 1 day ago BackupRetentionHandler.php 1 day ago BackupScheduler.php 1 day ago BackupServiceProvider.php 1 day ago BackupValidator.php 1 day ago BeforeUpdateRowStatus.php 1 day ago FileHeader.php 1 day ago FileHeaderAttribute.php 1 day ago UpdateProtectionPausedNotice.php 1 day ago WithBackupIdentifier.php 1 day ago
BackupRepairer.php
99 lines
1 <?php
2
3 namespace WPStaging\Backup;
4
5 use Exception;
6 use RuntimeException;
7 use UnexpectedValueException;
8 use WPStaging\Backup\Entity\BackupMetadata;
9 use WPStaging\Framework\Job\Exception\DiskNotWritableException;
10 use WPStaging\Backup\Service\BackupMetadataEditor;
11 use WPStaging\Framework\Filesystem\FileObject;
12
13 class BackupRepairer
14 {
15
16 private $metadataEditor;
17
18
19 private $error = false;
20
21 public function __construct(BackupMetadataEditor $metadataEditor)
22 {
23 $this->metadataEditor = $metadataEditor;
24 }
25
26
27 public function getError()
28 {
29 return $this->error;
30 }
31
32
33
34
35
36 public function repairMetadataSize($filePath)
37 {
38 $this->error = false;
39
40 $file = null;
41 try {
42 $file = new FileObject($filePath, FileObject::MODE_APPEND_AND_READ);
43 } catch (DiskNotWritableException $ex) {
44 $this->error = $ex->getMessage();
45 return false;
46 } catch (Exception $ex) {
47 $this->error = $ex->getMessage();
48 return false;
49 }
50
51
52 if ($file->getExtension() !== 'wpstg') {
53 return true;
54 }
55
56 $backupMetadata = new BackupMetadata();
57 try {
58 $backupMetadata->hydrateByFile($file);
59 } catch (RuntimeException $ex) {
60 $this->error = $ex->getMessage();
61 return false;
62 }
63
64
65 if ($backupMetadata->getBackupSize() !== 0) {
66 return true;
67 }
68
69
70
71
72
73
74
75 $fileSize = $file->getSize();
76 if ($fileSize === false || $fileSize < 1) {
77 $this->error = __('Backup size cannot be determined or is zero', 'wp-staging');
78 return false;
79 }
80
81 $backupSize = $fileSize - 2 + strlen((string)$fileSize);
82 if ($backupSize < 1) {
83 $this->error = __('Backup size cannot be zero or less', 'wp-staging');
84 return false;
85 }
86
87 $backupMetadata->setBackupSize($backupSize);
88
89 try {
90 $this->metadataEditor->setBackupMetadata($file, $backupMetadata);
91 } catch (UnexpectedValueException $ex) {
92 $this->error = $ex->getMessage();
93 return false;
94 }
95
96 return true;
97 }
98 }
99