Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 23 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
ManagementConfigurationEditLogic | |
0.00% |
0 / 23 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
startup | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
validateImpl | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
executeImpl | |
0.00% |
0 / 9 |
|
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 Exception; |
8 | use PeServer\App\Models\AppConfiguration; |
9 | use PeServer\App\Models\AuditLog; |
10 | use PeServer\App\Models\Domain\AppArchiver; |
11 | use PeServer\App\Models\Domain\Page\PageLogicBase; |
12 | use PeServer\Core\Binary; |
13 | use PeServer\Core\Collection\Arr; |
14 | use PeServer\Core\Database\IDatabaseContext; |
15 | use PeServer\Core\Environment; |
16 | use PeServer\Core\IO\File; |
17 | use PeServer\Core\IO\Path; |
18 | use PeServer\Core\Mvc\LogicCallMode; |
19 | use PeServer\Core\Mvc\LogicParameter; |
20 | use PeServer\Core\Serialization\JsonSerializer; |
21 | use PeServer\Core\Text; |
22 | |
23 | class ManagementConfigurationEditLogic extends PageLogicBase |
24 | { |
25 | private string $settingPath = ''; |
26 | |
27 | public function __construct( |
28 | LogicParameter $parameter, |
29 | private AppArchiver $appArchiver, |
30 | private AppConfiguration $config |
31 | ) { |
32 | parent::__construct($parameter); |
33 | } |
34 | |
35 | protected function startup(LogicCallMode $callMode): void |
36 | { |
37 | $settingName = Path::setEnvironmentName('setting.json', $this->environment->get()); |
38 | $this->settingPath = Path::combine($this->config->settingDirectoryPath, $settingName); |
39 | |
40 | $this->setValue('env_name', $this->environment->get()); |
41 | $this->setValue('path', $this->settingPath); |
42 | |
43 | $this->registerParameterKeys([ |
44 | 'json', |
45 | ], true); |
46 | } |
47 | |
48 | protected function validateImpl(LogicCallMode $callMode): void |
49 | { |
50 | if ($callMode === LogicCallMode::Submit) { |
51 | $jsonSerializer = new JsonSerializer(); |
52 | $json = $this->getRequest('json'); |
53 | try { |
54 | $jsonSerializer->load(new Binary($json)); |
55 | } catch (Exception $ex) { |
56 | $this->addError('json', $ex->getMessage()); |
57 | } |
58 | } |
59 | } |
60 | |
61 | protected function executeImpl(LogicCallMode $callMode): void |
62 | { |
63 | if ($callMode === LogicCallMode::Initialize) { |
64 | $json = File::readContent($this->settingPath); |
65 | $this->setValue('json', $json); |
66 | } else { |
67 | $jsonSerializer = new JsonSerializer(); |
68 | $json = $this->getRequest('json'); |
69 | $data = $jsonSerializer->load(new Binary($json)); |
70 | |
71 | // 保存前にバックアップ |
72 | $this->appArchiver->backup(); |
73 | |
74 | File::writeJsonFile($this->settingPath, $data, $jsonSerializer); |
75 | |
76 | $this->writeAuditLogCurrentUser(AuditLog::ADMINISTRATOR_SAVE_CONFIGURATION); |
77 | } |
78 | } |
79 | } |