PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.11.1
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.11.1
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 / AbstractBackupsFinder.php
wp-staging / Backup / Service Last commit date
Compression 1 week ago Database 1 week ago DirectoryExplorer 1 week ago AbstractBackgroundBackupRequest.php 1 week ago AbstractBackupsFinder.php 1 week ago AbstractExtractor.php 1 week ago AbstractServiceProvider.php 1 week ago Archiver.php 1 week ago BackupAssets.php 1 week ago BackupContent.php 1 week ago BackupMetadataEditor.php 1 week ago BackupMetadataReader.php 1 week ago BackupSigner.php 1 week ago BackupsDirectoryResolver.php 1 week ago BackupsFinder.php 1 week ago BeforeUpdateBackupRequest.php 1 week ago BeforeUpdateBackupsService.php 1 week ago Extractor.php 1 week ago FileBackupService.php 1 week ago FileBackupServiceProvider.php 1 week ago ServiceInterface.php 1 week ago TmpBackupCleaner.php 1 week ago UpdateProtectionHealth.php 1 week ago UpdateProtectionSettings.php 1 week ago ZlibCompressor.php 1 week ago
AbstractBackupsFinder.php
114 lines
1 <?php
2
3 namespace WPStaging\Backup\Service;
4
5 use WPStaging\Backup\WithBackupIdentifier;
6 use WPStaging\Framework\Traits\DebugLogTrait;
7 use WPStaging\Framework\Traits\WindowsOsTrait;
8
9
10
11
12
13
14
15
16
17 abstract class AbstractBackupsFinder
18 {
19 use WithBackupIdentifier;
20 use DebugLogTrait;
21 use WindowsOsTrait;
22
23
24 const MAX_BACKUP_FILE_TO_SCAN = 1000;
25
26
27 protected $backupsDirectory;
28
29
30 protected $backupsCount;
31
32 public function resetBackupsCount()
33 {
34 $this->backupsCount = 0;
35 }
36
37
38
39
40
41 public function setBackupsDirectory(string $backupsDirectory)
42 {
43 $this->backupsDirectory = $backupsDirectory;
44 }
45
46
47
48
49
50 public function getBackupsDirectory(bool $refresh = false): string
51 {
52 return $this->backupsDirectory;
53 }
54
55
56
57
58 public function findBackups(): array
59 {
60 try {
61 $it = new \DirectoryIterator($this->getBackupsDirectory(true));
62 } catch (\Exception $e) {
63 $this->debugLog('WP STAGING: Could not find backup directory ' . $e->getMessage());
64 return [];
65 }
66
67 $backups = [];
68
69 $this->clearListedMultipartBackups();
70
71
72 foreach ($it as $file) {
73 if (($file->getExtension() === 'wpstg' || $file->getExtension() === 'sql') && !$file->isLink()) {
74 if ($this->backupsCount >= self::MAX_BACKUP_FILE_TO_SCAN) {
75 break;
76 }
77
78 if ($this->isBackupPart($file->getFilename()) && $this->isListedMultipartBackup($file->getFilename())) {
79 continue;
80 }
81
82
83 if ($this->isWindowsOs() && !file_exists($file->getPathname())) {
84 continue;
85 }
86
87 $backups[] = clone $file;
88
89 $this->backupsCount++;
90 }
91 }
92
93 return $backups;
94 }
95
96
97
98
99
100
101 public function findBackupByMd5Hash(string $md5): \SplFileInfo
102 {
103 $backup = array_filter($this->findBackups(), function ($splFileInfo) use ($md5) {
104 return md5($splFileInfo->getBasename()) === $md5;
105 });
106
107 if (empty($backup)) {
108 throw new \UnexpectedValueException('WP STAGING: Could not find backup by hash ' . $md5);
109 }
110
111 return array_shift($backup);
112 }
113 }
114