Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
AdministratorApiPeVersionLogic | |
0.00% |
0 / 16 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
validateImpl | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
executeImpl | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\App\Models\Domain\Api\AdministratorApi; |
6 | |
7 | use Exception; |
8 | use PeServer\App\Models\AppConfiguration; |
9 | use PeServer\App\Models\AppDatabaseCache; |
10 | use PeServer\App\Models\AuditLog; |
11 | use PeServer\App\Models\Dao\Entities\PeSettingEntityDao; |
12 | use PeServer\App\Models\Dao\Entities\PluginUrlsEntityDao; |
13 | use PeServer\App\Models\Domain\Api\ApiLogicBase; |
14 | use PeServer\App\Models\Domain\AppArchiver; |
15 | use PeServer\App\Models\Domain\DefaultPlugin; |
16 | use PeServer\App\Models\Domain\PeVersionUpdater; |
17 | use PeServer\App\Models\Domain\PluginUrlKey; |
18 | use PeServer\App\Models\ResponseJson; |
19 | use PeServer\Core\Collection\Arr; |
20 | use PeServer\Core\Database\IDatabaseContext; |
21 | use PeServer\Core\Mvc\LogicCallMode; |
22 | use PeServer\Core\Mvc\LogicParameter; |
23 | use PeServer\Core\Text; |
24 | |
25 | class AdministratorApiPeVersionLogic extends ApiLogicBase |
26 | { |
27 | #region variable |
28 | |
29 | /** |
30 | * 要求JSON |
31 | * |
32 | * @var array<string,mixed> |
33 | */ |
34 | private array $requestJson; |
35 | |
36 | #endregion |
37 | |
38 | public function __construct(LogicParameter $parameter, private AppConfiguration $appConfig, private AppDatabaseCache $dbCache) |
39 | { |
40 | parent::__construct($parameter); |
41 | |
42 | $this->requestJson = $this->getRequestJson(); |
43 | } |
44 | |
45 | #region ApiLogicBase |
46 | |
47 | protected function validateImpl(LogicCallMode $callMode): void |
48 | { |
49 | $this->validateJsonProperty($this->requestJson, 'version', self::VALIDATE_JSON_PROPERTY_NON_EMPTY_TEXT); |
50 | |
51 | // 完全に実装ミス |
52 | if ($this->hasError()) { |
53 | throw new Exception(); |
54 | } |
55 | } |
56 | |
57 | protected function executeImpl(LogicCallMode $callMode): void |
58 | { |
59 | $database = $this->openDatabase(); |
60 | |
61 | $version = $this->requestJson['version']; |
62 | |
63 | $result = $database->transaction(function (IDatabaseContext $context) use ($version) { |
64 | $peVersionUpdater = new PeVersionUpdater(); |
65 | |
66 | $peVersionUpdater->updateDatabase($context, $this->appConfig->setting->config->address->families->pluginUpdateInfoUrlBase, $version); |
67 | |
68 | return true; |
69 | }); |
70 | if (!$result) { |
71 | throw new Exception(); |
72 | } |
73 | |
74 | $this->dbCache->exportPluginInformation(); |
75 | |
76 | $this->setResponseJson(ResponseJson::success([])); |
77 | } |
78 | |
79 | #endregion |
80 | } |