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 / WithBackupIdentifier.php
wp-staging / Backup Last commit date
Ajax 1 week ago BackgroundProcessing 1 week ago Dto 1 week ago Entity 1 week ago Exceptions 3 days ago FileHeader 1 week ago Interfaces 1 week ago Job 3 days ago Request 1 week ago Service 3 days ago Storage 1 week ago Task 3 days ago Traits 1 week ago Utils 1 week ago AdminMenuBadge.php 3 days ago AfterRestore.php 1 week ago BackupDeleter.php 1 week ago BackupDownload.php 1 week ago BackupFileIndex.php 1 week ago BackupGlitchReason.php 1 week ago BackupHeader.php 1 week ago BackupNextOffer.php 3 days ago BackupRepairer.php 1 week ago BackupRetentionHandler.php 1 week ago BackupScheduler.php 3 days ago BackupServiceProvider.php 1 week ago BackupValidator.php 1 week ago BeforeUpdateRowStatus.php 1 week ago FileHeader.php 1 week ago FileHeaderAttribute.php 1 week ago UpdateProtectionPausedNotice.php 1 week ago WithBackupIdentifier.php 1 week ago
WithBackupIdentifier.php
115 lines
1 <?php
2
3 namespace WPStaging\Backup;
4
5 use WPStaging\Backup\Service\Database\DatabaseImporter;
6 use WPStaging\Framework\Filesystem\PartIdentifier;
7
8 trait WithBackupIdentifier
9 {
10
11
12
13
14 protected $listedMultipartBackups = [];
15
16
17
18
19
20
21 public function checkPartByIdentifier(string $identifier, string $input)
22 {
23 return preg_match("#{$identifier}(.[0-9]+)?.wpstg$#", $input);
24 }
25
26
27
28
29
30 public function isBackupPart(string $name)
31 {
32 if (preg_match($this->getDatabasePartSuffixPattern(), $name)) {
33 return true;
34 }
35
36 $dbIdentifier = PartIdentifier::DATABASE_PART_IDENTIFIER;
37 $pluginIdentifier = PartIdentifier::PLUGIN_PART_IDENTIFIER;
38 $mupluginIdentifier = PartIdentifier::MU_PLUGIN_PART_IDENTIFIER;
39 $themeIdentifier = PartIdentifier::THEME_PART_IDENTIFIER;
40 $uploadIdentifier = PartIdentifier::UPLOAD_PART_IDENTIFIER;
41 $otherIdentifier = PartIdentifier::OTHER_WP_CONTENT_PART_IDENTIFIER;
42 $otherWpRootIdentifier = PartIdentifier::OTHER_WP_ROOT_PART_IDENTIFIER;
43
44 $identifiers = "({$dbIdentifier}|{$pluginIdentifier}|{$mupluginIdentifier}|{$themeIdentifier}|{$uploadIdentifier}|{$otherIdentifier}|{$otherWpRootIdentifier})";
45
46 if ($this->checkPartByIdentifier($identifiers, $name)) {
47 return true;
48 }
49
50 return false;
51 }
52
53
54
55
56 public function clearListedMultipartBackups()
57 {
58 $this->listedMultipartBackups = [];
59 }
60
61 public function isListedMultipartBackup(string $filename, bool $shouldAddBackup = true)
62 {
63 $id = $this->extractBackupIdFromFilename($filename);
64 if (in_array($id, $this->listedMultipartBackups)) {
65 return true;
66 }
67
68 if ($shouldAddBackup) {
69 $this->listedMultipartBackups[] = $id;
70 }
71
72 return false;
73 }
74
75
76
77
78
79 public function extractBackupIdFromFilename(string $filename)
80 {
81 if (preg_match($this->getDatabasePartSuffixPattern(), $filename)) {
82 return $this->extractBackupIdFromDatabaseBackupFilename($filename);
83 }
84
85 $fileInfos = explode('_', $filename);
86 $fileInfos = $fileInfos[count($fileInfos) - 1];
87 return explode('.', $fileInfos)[0];
88 }
89
90
91
92
93
94 protected function extractBackupIdFromDatabaseBackupFilename(string $filename)
95 {
96 $filename = preg_replace($this->getDatabasePartSuffixPattern(), '', $filename);
97
98 $lastDotPosition = strrpos($filename, '.');
99 if ($lastDotPosition !== false) {
100 $filename = substr($filename, 0, $lastDotPosition);
101 }
102
103 $fileInfos = explode('_', $filename);
104 return $fileInfos[count($fileInfos) - 1];
105 }
106
107
108
109
110 protected function getDatabasePartSuffixPattern(): string
111 {
112 return '#\.' . PartIdentifier::DATABASE_PART_IDENTIFIER . '(\.\d+)?\.' . DatabaseImporter::FILE_FORMAT . '$#';
113 }
114 }
115