PluginProbe
404 Solution / 4.3.0
404 Solution v4.3.0
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / diagnostics / DebugLogArchiveBuilder.php

DebugLogArchiveBuilder.php in 404 Solution 4.3.0, at includes/diagnostics/DebugLogArchiveBuilder.php

60 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 if (!defined('ABSPATH')) {
5 exit;
6 }
7
8 // allow-no-test-found: covered by tests/LoggingTest.php zip-failure mail fallback entry-point test.
9
10 /**
11 * Builds the developer-feedback debug-log zip attachment.
12 *
13 * The builder only creates the archive from paths supplied by the caller. It
14 * does not send mail and does not decide whether a missing/failed archive
15 * should abort the report.
16 */
17 class ABJ_404_Solution_DebugLogArchiveBuilder {
18
19 /**
20 * Create a zip containing the current and rotated debug logs.
21 *
22 * @param string $zipPath
23 * @param string $debugFilePath
24 * @param string $oldDebugFilePath
25 * @return string The requested zip path, or an empty string when ZipArchive is unavailable.
26 */
27 public function build(string $zipPath, string $debugFilePath, string $oldDebugFilePath): string {
28 if (file_exists($zipPath)) {
29 ABJ_404_Solution_FileSystemService::safeUnlink($zipPath);
30 }
31 if (!class_exists('ZipArchive')) {
32 return '';
33 }
34 $zipDirectory = dirname($zipPath);
35 if (!is_dir($zipDirectory)) {
36 abj404_logPhpFallback('logger-internal', 'debug log zip directory does not exist: ' . $zipDirectory);
37 return $zipPath;
38 }
39 $zip = new ZipArchive;
40 $openResult = $zip->open($zipPath, ZipArchive::CREATE);
41 if ($openResult === true) {
42 if (file_exists($debugFilePath)) {
43 $zip->addFile($debugFilePath, basename($debugFilePath));
44 }
45 if (file_exists($oldDebugFilePath)) {
46 $zip->addFile($oldDebugFilePath, basename($oldDebugFilePath));
47 }
48 if (!$zip->close()) {
49 abj404_logPhpFallback('logger-internal', 'debug log zip close failed for ' . $zipPath);
50 }
51 } else {
52 abj404_logPhpFallback(
53 'logger-internal',
54 'debug log zip open failed for ' . $zipPath . ' (status ' . (string)$openResult . ')'
55 );
56 }
57 return $zipPath;
58 }
59 }
60