Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
ManagementDatabaseDownloadLogic | |
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 / 1 |
|
0.00% |
0 / 1 |
2 | |||
executeImpl | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\App\Models\Domain\Page\Management; |
6 | |
7 | use Throwable; |
8 | use PeServer\App\Models\AppConfiguration; |
9 | use PeServer\App\Models\AppDatabaseConnection; |
10 | use PeServer\App\Models\AuditLog; |
11 | use PeServer\App\Models\Domain\Page\PageLogicBase; |
12 | use PeServer\Core\Archiver; |
13 | use PeServer\Core\Collection\Arr; |
14 | use PeServer\Core\Database\DatabaseTableResult; |
15 | use PeServer\Core\Database\IDatabaseContext; |
16 | use PeServer\Core\Http\HttpStatus; |
17 | use PeServer\Core\IO\File; |
18 | use PeServer\Core\IO\Path; |
19 | use PeServer\Core\Mime; |
20 | use PeServer\Core\Mvc\DownloadFileContent; |
21 | use PeServer\Core\Mvc\LogicCallMode; |
22 | use PeServer\Core\Mvc\LogicParameter; |
23 | use PeServer\Core\Mvc\Validator; |
24 | use PeServer\Core\Regex; |
25 | use PeServer\Core\Text; |
26 | use PeServer\Core\Throws\HttpStatusException; |
27 | |
28 | class ManagementDatabaseDownloadLogic extends PageLogicBase |
29 | { |
30 | public function __construct(LogicParameter $parameter, private AppConfiguration $config) |
31 | { |
32 | parent::__construct($parameter); |
33 | } |
34 | |
35 | protected function validateImpl(LogicCallMode $callMode): void |
36 | { |
37 | //nop |
38 | } |
39 | |
40 | |
41 | protected function executeImpl(LogicCallMode $callMode): void |
42 | { |
43 | if ($callMode !== LogicCallMode::Submit) { |
44 | throw new HttpStatusException(HttpStatus::InternalServerError); |
45 | } |
46 | |
47 | $target = AppDatabaseConnection::getSqliteFilePath($this->config->setting->persistence->default->connection); |
48 | $name = Path::getFileName($target); |
49 | $content = File::readContent($target); |
50 | |
51 | $archive = [ |
52 | 'mime' => Mime::GZ, |
53 | 'name' => "$name.gz", |
54 | 'content' => Archiver::compressGzip($content, 9), |
55 | ]; |
56 | |
57 | $this->writeAuditLogCurrentUser(AuditLog::ADMINISTRATOR_DOWNLOAD_DATABASE, [ |
58 | "path" => $target, |
59 | "size" => $content->count(), |
60 | ]); |
61 | |
62 | $this->setDownloadContent($archive['mime'], $archive['name'], $archive['content']); |
63 | } |
64 | } |