PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 3.8.4
WP STAGING – WordPress Backups, Restore, Migration & Clone v3.8.4
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 2 years ago BackgroundProcessing 2 years ago Dto 2 years ago Entity 2 years ago Exceptions 2 years ago Interfaces 2 years ago Job 2 years ago Request 2 years ago Service 2 years ago Storage 2 years ago Task 2 years ago AfterRestore.php 2 years ago BackupDeleter.php 2 years ago BackupDownload.php 2 years ago BackupFileIndex.php 2 years ago BackupHeader.php 2 years ago BackupRepairer.php 2 years ago BackupRetentionHandler.php 2 years ago BackupScheduler.php 2 years ago BackupServiceProvider.php 2 years ago BackupValidator.php 2 years ago FileHeader.php 2 years ago FileHeaderAttribute.php 2 years ago WithBackupIdentifier.php 2 years ago
WithBackupIdentifier.php
107 lines
1 <?php
2
3 namespace WPStaging\Backup;
4
5 use WPStaging\Backup\Task\Tasks\JobBackup\DatabaseBackupTask;
6 use WPStaging\Framework\Filesystem\PartIdentifier;
7
8 trait WithBackupIdentifier
9 {
10 /**
11 * @var string[]
12 */
13 protected $listedMultipartBackups = [];
14
15 /**
16 * @param string $identifier
17 * @param string $input
18 * @return bool
19 */
20 public function checkPartByIdentifier(string $identifier, string $input)
21 {
22 return preg_match("#{$identifier}(.[0-9]+)?.wpstg$#", $input);
23 }
24
25 /**
26 * @param string $name
27 * @return bool
28 */
29 public function isBackupPart(string $name)
30 {
31 $dbExtension = DatabaseBackupTask::FILE_FORMAT;
32 $dbIdentifier = PartIdentifier::DATABASE_PART_IDENTIFIER;
33 if (preg_match("#{$dbIdentifier}(.[0-9]+)?.{$dbExtension}$#", $name)) {
34 return true;
35 }
36
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 = "({$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 * @return void
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 * @param string $filename
77 * @return string
78 */
79 public function extractBackupIdFromFilename(string $filename)
80 {
81 if (strpos($filename, '.' . PartIdentifier::DATABASE_PART_IDENTIFIER . '.' . DatabaseBackupTask::FILE_FORMAT) !== false) {
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 * @param string $filename
92 * @return string
93 */
94 protected function extractBackupIdFromDatabaseBackupFilename(string $filename)
95 {
96 // This is required if the table prefix contains underscore like wp_some
97 $filename = str_replace('.' . PartIdentifier::DATABASE_PART_IDENTIFIER . '.' . DatabaseBackupTask::FILE_FORMAT, '', $filename);
98 // Get position of last dot . in filename
99 $lastDotPosition = strrpos($filename, '.');
100 // Get filename until last dot to remove the table prefix
101 $filename = substr($filename, 0, $lastDotPosition);
102
103 $fileInfos = explode('_', $filename);
104 return $fileInfos[count($fileInfos) - 1];
105 }
106 }
107