PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / trunk
WP STAGING – WordPress Backups, Restore, Migration & Clone vtrunk
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 / Framework / Filesystem / LogFiles.php
wp-staging / Framework / Filesystem Last commit date
Filters 1 week ago Scanning 1 week ago AbstractFileObject.php 1 week ago AbstractFilesystemScanner.php 1 week ago DebugLogReader.php 1 week ago DirectoryListing.php 1 week ago DirectorySize.php 1 week ago DiskWriteCheck.php 1 week ago FileObject.php 1 week ago Filesystem.php 1 week ago FilesystemExceptions.php 5 years ago FilesystemScanner.php 1 week ago FilesystemScannerDto.php 1 week ago FilterableDirectoryIterator.php 1 week ago LegacyFileRulesTrait.php 1 week ago LogCleanup.php 1 week ago LogFiles.php 1 week ago MissingFileException.php 3 years ago OPcache.php 1 week ago PartIdentifier.php 1 week ago PathChecker.php 1 week ago PathIdentifier.php 1 week ago Permissions.php 1 week ago WpUploadsFolderSymlinker.php 1 week ago
LogFiles.php
117 lines
1 <?php
2
3 namespace WPStaging\Framework\Filesystem;
4
5 use WPStaging\Framework\Adapter\Directory;
6
7 class LogFiles
8 {
9
10
11
12 private $logsDirectory;
13
14
15
16
17 private $availableLogFileTypes;
18
19
20
21
22 private $latestLogFiles;
23
24
25
26
27 public function __construct(Directory $directory)
28 {
29 $this->logsDirectory = $directory->getLogDirectory();
30 $this->availableLogFileTypes = ['push', 'backup_restore', 'cloning', 'backup_job', 'staging_plugins_updater'];
31 $this->latestLogFiles = [];
32 }
33
34
35
36
37 public function getLatestLogFiles(): array
38 {
39 $logFiles = scandir($this->logsDirectory);
40 foreach ($logFiles as $logFile) {
41 $this->findLatestLogFiles($logFile);
42 }
43
44 return $this->latestLogFiles;
45 }
46
47
48
49
50
51 private function findLatestLogFiles(string $fileName)
52 {
53 foreach ($this->availableLogFileTypes as $logFilePrefix) {
54 if (strpos($fileName, $logFilePrefix) !== 0) {
55 continue;
56 }
57
58 $logFilePath = trailingslashit($this->logsDirectory) . $fileName;
59 if (!isset($this->latestLogFiles[$logFilePrefix]) || filemtime($logFilePath) > filemtime($this->latestLogFiles[$logFilePrefix])) {
60 $this->latestLogFiles[$logFilePrefix] = $logFilePath;
61 }
62
63 break;
64 }
65 }
66
67
68
69
70 public function getLogsDirectory(): string
71 {
72 return trailingslashit($this->logsDirectory);
73 }
74
75 public function getAvailableLogFileTypes(): array
76 {
77 return $this->availableLogFileTypes;
78 }
79
80
81
82
83
84 public function getRetentionLogFiles(int $days = 14): array
85 {
86 $logPrefix = implode('|', $this->availableLogFileTypes);
87 $logFiles = [];
88 $dayStart = strtotime('-' . $days);
89
90 $dirIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->logsDirectory));
91 foreach ($dirIterator as $fileInfo) {
92 if (!$fileInfo->isFile() || $fileInfo->isLink() || $fileInfo->getExtension() !== 'log') {
93 continue;
94 }
95
96 $filePath = $fileInfo->getRealPath();
97 $fileName = $fileInfo->getFilename();
98
99 if (!preg_match('@^(' . $logPrefix . ')@', $fileName, $matches)) {
100 continue;
101 }
102
103 $fileType = $matches[1];
104 $fileMTime = $fileInfo->getMTime();
105 if (!$fileMTime) {
106 continue;
107 }
108
109 if ($dayStart >= $fileMTime) {
110 $logFiles[$fileType][] = $filePath;
111 }
112 }
113
114 return $logFiles;
115 }
116 }
117