Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
AjaxLogFileDeleteLogic | |
0.00% |
0 / 17 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
validateImpl | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
executeImpl | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\App\Models\Domain\Page\Ajax; |
6 | |
7 | use Exception; |
8 | use PeServer\App\Models\AppConfiguration; |
9 | use PeServer\App\Models\Domain\Page\PageLogicBase; |
10 | use PeServer\App\Models\ResponseJson; |
11 | use PeServer\Core\IO\File; |
12 | use PeServer\Core\IO\Path; |
13 | use PeServer\Core\Mvc\LogicCallMode; |
14 | use PeServer\Core\Mvc\LogicParameter; |
15 | use PeServer\Core\Throws\FileNotFoundException; |
16 | |
17 | class AjaxLogFileDeleteLogic extends PageLogicBase |
18 | { |
19 | public function __construct(LogicParameter $parameter, private AppConfiguration $config) |
20 | { |
21 | parent::__construct($parameter); |
22 | } |
23 | |
24 | #region PageLogicBase |
25 | |
26 | protected function validateImpl(LogicCallMode $callMode): void |
27 | { |
28 | $logging = $this->config->setting->logging; |
29 | /** @var string */ |
30 | $dirPath = $logging->loggers['file']->configuration['directory']; |
31 | $logName = $this->getRequest('log_name'); |
32 | $logPath = Path::combine($dirPath, $logName); |
33 | |
34 | if (!File::exists($logPath)) { |
35 | throw new FileNotFoundException(); |
36 | } |
37 | } |
38 | |
39 | protected function executeImpl(LogicCallMode $callMode): void |
40 | { |
41 | $logging = $this->config->setting->logging; |
42 | /** @var string */ |
43 | $dirPath = $logging->loggers['file']->configuration['directory']; |
44 | $logName = $this->getRequest('log_name'); |
45 | $logPath = Path::combine($dirPath, $logName); |
46 | |
47 | $result = [ |
48 | 'path' => $logPath, |
49 | 'size' => File::getFileSize($logPath), |
50 | ]; |
51 | |
52 | File::removeFile($logPath); |
53 | |
54 | $this->setResponseJson(ResponseJson::success($result)); |
55 | } |
56 | |
57 | #endregion |
58 | } |