|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Stu\Module\Spacecraft\Lib\Creation; |
|
4
|
|
|
|
|
5
|
|
|
use Override; |
|
|
|
|
|
|
6
|
|
|
use Stu\Module\Logging\StuLogger; |
|
7
|
|
|
use Stu\Module\Message\Lib\PrivateMessageFolderTypeEnum; |
|
8
|
|
|
use Stu\Module\Message\Lib\PrivateMessageSenderInterface; |
|
9
|
|
|
use Stu\Module\PlayerSetting\Lib\UserEnum; |
|
|
|
|
|
|
10
|
|
|
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperFactoryInterface; |
|
11
|
|
|
use Stu\Orm\Entity\SpacecraftBuildplanInterface; |
|
12
|
|
|
use Stu\Orm\Entity\SpacecraftInterface; |
|
13
|
|
|
use Stu\Orm\Repository\ConstructionProgressRepositoryInterface; |
|
14
|
|
|
use Stu\Orm\Repository\SpacecraftBuildplanRepositoryInterface; |
|
15
|
|
|
|
|
16
|
|
|
class SpacecraftCorrector implements SpacecraftCorrectorInterface |
|
17
|
|
|
{ |
|
18
|
1 |
|
public function __construct( |
|
19
|
|
|
private SpacecraftBuildplanRepositoryInterface $spacecraftBuildplanRepository, |
|
20
|
|
|
private ConstructionProgressRepositoryInterface $constructionProgressRepository, |
|
21
|
|
|
private SpacecraftWrapperFactoryInterface $spacecraftWrapperFactory, |
|
22
|
|
|
private PrivateMessageSenderInterface $privateMessageSender |
|
23
|
1 |
|
) {} |
|
24
|
|
|
|
|
25
|
|
|
#[Override] |
|
26
|
|
|
public function correctAllSpacecrafts(): void |
|
27
|
|
|
{ |
|
28
|
|
|
$count = 0; |
|
29
|
|
|
|
|
30
|
|
|
// correct all ships |
|
31
|
|
|
foreach ($this->spacecraftBuildplanRepository->getAllNonNpcBuildplans() as $buildplan) { |
|
32
|
|
|
|
|
33
|
|
|
$spacecrafts = $buildplan->getSpacecraftList(); |
|
34
|
|
|
if ($spacecrafts->isEmpty()) { |
|
35
|
|
|
continue; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
foreach ($spacecrafts as $spacecraft) { |
|
39
|
|
|
if ($this->correctSpacecraft($spacecraft, $buildplan)) { |
|
40
|
|
|
$count++; |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
// correct all stations |
|
46
|
|
|
foreach ($this->constructionProgressRepository->findAll() as $progress) { |
|
47
|
|
|
|
|
48
|
|
|
$station = $progress->getStation(); |
|
49
|
|
|
$buildplan = $station->getBuildplan(); |
|
50
|
|
|
if ( |
|
51
|
|
|
$buildplan === null |
|
52
|
|
|
|| $progress->getRemainingTicks() !== 0 |
|
53
|
|
|
) { |
|
54
|
|
|
continue; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
if ($this->correctSpacecraft( |
|
58
|
|
|
$progress->getStation(), |
|
59
|
|
|
$buildplan |
|
60
|
|
|
)) { |
|
61
|
|
|
$count++; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if ($count > 0) { |
|
66
|
|
|
StuLogger::logf('corrected %d spacecrafts.', $count); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
private function correctSpacecraft(SpacecraftInterface $spacecraft, SpacecraftBuildplanInterface $buildplan): bool |
|
71
|
|
|
{ |
|
72
|
|
|
$rump = $buildplan->getRump(); |
|
73
|
|
|
$wrapper = $this->spacecraftWrapperFactory->wrapSpacecraft($spacecraft); |
|
74
|
|
|
$toStringBefore = $wrapper->__toString(); |
|
75
|
|
|
|
|
76
|
|
|
foreach ($buildplan->getModules() as $buildplanModule) { |
|
77
|
|
|
$moduleType = $buildplanModule->getModuleType(); |
|
78
|
|
|
$moduleRumpWrapper = $moduleType->getModuleRumpWrapperCallable()($rump, $buildplan); |
|
79
|
|
|
$moduleRumpWrapper->apply($wrapper); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
$toStringAfter = $wrapper->__toString(); |
|
83
|
|
|
$diff = xdiff_string_diff($toStringBefore, $toStringAfter); |
|
84
|
|
|
|
|
85
|
|
|
if ($diff !== '') { |
|
86
|
|
|
StuLogger::logf( |
|
87
|
|
|
'spacecraftId %d corrected: %s', |
|
88
|
|
|
$spacecraft->getId(), |
|
89
|
|
|
$diff |
|
|
|
|
|
|
90
|
|
|
); |
|
91
|
|
|
|
|
92
|
|
|
$this->sendPmToOwner($spacecraft, $diff); |
|
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
return true; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
return false; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
private function sendPmToOwner(SpacecraftInterface $spacecraft, string $diff): void |
|
101
|
|
|
{ |
|
102
|
|
|
$this->privateMessageSender |
|
103
|
|
|
->send( |
|
104
|
|
|
UserEnum::USER_NOONE, |
|
105
|
|
|
$spacecraft->getUser()->getId(), |
|
106
|
|
|
sprintf( |
|
107
|
|
|
"Die Werte der %s wurden automatisch wie folgt korrigiert:\n\n%s", |
|
108
|
|
|
$spacecraft->getName(), |
|
109
|
|
|
$diff |
|
110
|
|
|
), |
|
111
|
|
|
PrivateMessageFolderTypeEnum::SPECIAL_SYSTEM, |
|
112
|
|
|
$spacecraft->getHref() |
|
113
|
|
|
); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths