Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
ManagementLogDetailLogic | |
0.00% |
0 / 18 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
validateImpl | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
executeImpl | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\App\Models\Domain\Page\Management; |
6 | |
7 | use ZipArchive; |
8 | use PeServer\Core\Mime; |
9 | use PeServer\Core\Binary; |
10 | use PeServer\Core\Archiver; |
11 | use PeServer\Core\IO\File; |
12 | use PeServer\Core\IO\Path; |
13 | use PeServer\Core\Text; |
14 | use PeServer\Core\Mvc\LogicCallMode; |
15 | use PeServer\Core\Mvc\LogicParameter; |
16 | use PeServer\App\Models\AppConfiguration; |
17 | use PeServer\Core\Throws\FileNotFoundException; |
18 | use PeServer\App\Models\Domain\Page\PageLogicBase; |
19 | |
20 | ini_set('memory_limit', '-1'); |
21 | |
22 | class ManagementLogDetailLogic extends PageLogicBase |
23 | { |
24 | public function __construct(LogicParameter $parameter, private AppConfiguration $config) |
25 | { |
26 | parent::__construct($parameter); |
27 | } |
28 | |
29 | protected function validateImpl(LogicCallMode $callMode): void |
30 | { |
31 | //NOP |
32 | } |
33 | |
34 | protected function executeImpl(LogicCallMode $callMode): void |
35 | { |
36 | $logging = $this->config->setting->logging; |
37 | /** @var string */ |
38 | $dirPath = $logging->loggers['file']->configuration['directory']; |
39 | |
40 | $fileName = Text::trim($this->getRequest('log_name'), '/\\.'); |
41 | $filePath = Path::combine($dirPath, $fileName); |
42 | if (!File::exists($filePath)) { |
43 | throw new FileNotFoundException(); |
44 | } |
45 | |
46 | $binary = File::readContent($filePath); |
47 | |
48 | $archiveSize = $logging->archiveSize; |
49 | $fileSize = File::getFileSize($filePath); |
50 | |
51 | if ($archiveSize <= $fileSize || $callMode === LogicCallMode::Submit) { |
52 | $this->result['download'] = true; |
53 | |
54 | $compressed = Archiver::compressGzip($binary, 9); |
55 | |
56 | $this->setDownloadContent(Mime::GZ, $fileName . '.gz', $compressed); |
57 | } else { |
58 | $this->setValue('log_name', $fileName); |
59 | $this->setValue('log_file', $filePath); |
60 | $this->setValue('log_value', $binary->raw); |
61 | } |
62 | } |
63 | } |