PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.11.2
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.11.2
4.11.2 4.11.1 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 / Service / BackupMetadataEditor.php
wp-staging / Backup / Service Last commit date
Compression 2 weeks ago Database 2 weeks ago DirectoryExplorer 2 weeks ago AbstractBackgroundBackupRequest.php 4 days ago AbstractBackupsFinder.php 2 weeks ago AbstractExtractor.php 2 weeks ago AbstractServiceProvider.php 2 weeks ago Archiver.php 1 week ago BackupAssets.php 2 weeks ago BackupContent.php 2 weeks ago BackupMetadataEditor.php 1 week ago BackupMetadataReader.php 2 weeks ago BackupSigner.php 2 weeks ago BackupsDirectoryResolver.php 2 weeks ago BackupsFinder.php 2 weeks ago BeforeUpdateBackupRequest.php 2 weeks ago BeforeUpdateBackupsService.php 2 weeks ago Extractor.php 2 weeks ago FileBackupService.php 2 weeks ago FileBackupServiceProvider.php 2 weeks ago ServiceInterface.php 2 weeks ago TmpBackupCleaner.php 2 weeks ago UpdateProtectionHealth.php 2 weeks ago UpdateProtectionSettings.php 4 days ago ZlibCompressor.php 2 weeks ago
BackupMetadataEditor.php
58 lines
1 <?php
2
3 namespace WPStaging\Backup\Service;
4
5 use WPStaging\Backup\BackupHeader;
6 use WPStaging\Framework\Filesystem\FileObject;
7 use WPStaging\Backup\Entity\BackupMetadata;
8
9 class BackupMetadataEditor
10 {
11
12
13
14
15 public function setBackupMetadata(FileObject $backupFile, BackupMetadata $newMetadata)
16 {
17 $backupMetadataReader = new BackupMetadataReader($backupFile);
18 $existingMetadataPosition = $backupMetadataReader->getExistingMetadataPosition();
19
20 $backupFile->fseek($existingMetadataPosition);
21
22 $maybeMetadataLine = $backupFile->readAndMoveNext();
23
24
25 if (!is_array($backupMetadataReader->extractMetadata($maybeMetadataLine))) {
26 throw new \UnexpectedValueException('Could not find the existing metadata from the backup.');
27 }
28
29 $backupFile->ftruncate($existingMetadataPosition);
30 $backupFile->fseek($existingMetadataPosition);
31
32 $prepandForSql = '';
33 if ($backupFile->isSqlFile()) {
34 $prepandForSql = '-- ';
35 }
36
37 $backupFile->fwrite($prepandForSql . json_encode($newMetadata) . BackupHeader::LINE_TERMINATOR);
38 }
39
40
41
42
43
44
45
46 public function getLineTerminatorOverhead(FileObject $backupFile): int
47 {
48 $existingMetadataPosition = (new BackupMetadataReader($backupFile))->getExistingMetadataPosition();
49
50 $backupFile->fseek($existingMetadataPosition);
51 $existingLine = $backupFile->readAndMoveNext();
52
53 $existingTerminatorLength = strlen($existingLine) - strlen(rtrim($existingLine, "\r\n"));
54
55 return $existingTerminatorLength - strlen(BackupHeader::LINE_TERMINATOR);
56 }
57 }
58