Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
60.00% |
12 / 20 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
SetupVersionLast | |
60.00% |
12 / 20 |
|
66.67% |
2 / 3 |
6.60 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
migrateIOSystem | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
migrateDatabase | |
52.94% |
9 / 17 |
|
0.00% |
0 / 1 |
3.94 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\App\Models\Setup\Versions; |
6 | |
7 | use PeServer\App\Models\AppConfiguration; |
8 | use PeServer\App\Models\Setup\DatabaseSetupArgument; |
9 | use PeServer\App\Models\Setup\IOSetupArgument; |
10 | use PeServer\Core\IO\Directory; |
11 | use PeServer\Core\Log\ILoggerFactory; |
12 | |
13 | #[Version(-1)] |
14 | class SetupVersionLast extends SetupVersionBase |
15 | { |
16 | public function __construct( |
17 | private int $oldVersion, |
18 | private int $newVersion, |
19 | AppConfiguration $appConfig, |
20 | ILoggerFactory $loggerFactory |
21 | ) { |
22 | parent::__construct($appConfig, $loggerFactory); |
23 | } |
24 | |
25 | #region SetupVersionBase |
26 | |
27 | protected function migrateIOSystem(IOSetupArgument $argument): void |
28 | { |
29 | $this->logger->info('テンプレートキャッシュ全削除: {0}', $this->appConfig->setting->cache->template); |
30 | Directory::cleanupDirectory($this->appConfig->setting->cache->template); |
31 | } |
32 | |
33 | protected function migrateDatabase(DatabaseSetupArgument $argument): void |
34 | { |
35 | if ($this->oldVersion === $this->newVersion) { |
36 | return; |
37 | } |
38 | |
39 | if ($this->oldVersion === -1) { |
40 | $argument->default->insertSingle( |
41 | <<<SQL |
42 | |
43 | insert into |
44 | database_version |
45 | ( |
46 | version |
47 | ) |
48 | values |
49 | ( |
50 | :version |
51 | ) |
52 | |
53 | SQL, |
54 | [ |
55 | 'version' => $this->newVersion, |
56 | ] |
57 | ); |
58 | } else { |
59 | $argument->default->updateByKey( |
60 | <<<SQL |
61 | |
62 | update |
63 | database_version |
64 | set |
65 | version = :version |
66 | where |
67 | version < :version |
68 | |
69 | SQL, |
70 | [ |
71 | 'version' => $this->newVersion, |
72 | ] |
73 | ); |
74 | } |
75 | } |
76 | |
77 | #endregion |
78 | } |