Skip to content

Commit 72d0404

Browse files
committed
fix ticket 1011
1 parent 2d74f86 commit 72d0404

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/Module/Communication/Action/AddKnPost/AddKnPost.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public function handle(GameControllerInterface $game): void
8585
$characterIdsInput = $this->addKnPostRequest->getCharacterIds();
8686
$idsRaw = explode(',', $characterIdsInput);
8787
$validIds = [];
88+
$addedCharacterIds = [];
8889

8990
foreach ($idsRaw as $idRaw) {
9091
$idTrimmed = trim($idRaw);
@@ -99,14 +100,18 @@ public function handle(GameControllerInterface $game): void
99100
$game->getInfo()->addInformation(_("Kein Character mit der ID $id gefunden."));
100101
continue;
101102
}
103+
if ($userCharacter->getUser()->getId() === UserConstants::USER_NOONE) {
104+
continue;
105+
}
102106

103107
$character = $this->knCharactersRepository->prototype();
104108
$character->setUserCharacter($userCharacter);
105109
$character->setKnPost($post);
106110
$this->knCharactersRepository->save($character);
107111
$post->getKnCharacters()->add($character);
112+
$addedCharacterIds[] = $id;
108113
}
109-
$this->notifyCharacterOwners($post, $validIds);
114+
$this->notifyCharacterOwners($post, $addedCharacterIds);
110115

111116
if ($plot !== null) {
112117
$this->newKnPostNotificator->notify($post, $plot);
@@ -134,6 +139,9 @@ private function notifyCharacterOwners(KnPost $post, array $characterIds): void
134139
$character = $this->userCharactersRepository->find($characterId);
135140
if ($character !== null) {
136141
$ownerId = $character->getUser()->getId();
142+
if ($ownerId === UserConstants::USER_NOONE) {
143+
continue;
144+
}
137145

138146
$characterNameWithId = sprintf('%s (%d)', $character->getName(), $characterId);
139147
if (!array_key_exists($ownerId, $userCharactersMap)) {

src/Module/Communication/Action/EditKnPost/EditKnPost.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,23 @@ public function handle(GameControllerInterface $game): void
8686

8787
foreach ($charactersToAdd as $characterId) {
8888
$character = $this->userCharactersRepository->find($characterId);
89-
if ($character !== null && $character->getUser()->getId() !== $userId) {
89+
if (
90+
$character !== null
91+
&& $character->getUser()->getId() !== $userId
92+
&& $character->getUser()->getId() !== UserConstants::USER_NOONE
93+
) {
9094
$ownerId = $character->getUser()->getId();
9195
$charactersAddedMapping[$ownerId][] = sprintf('%s (%d)', $character->getName(), $characterId);
9296
}
9397
}
9498

9599
foreach ($charactersToRemove as $characterId) {
96100
$character = $this->userCharactersRepository->find($characterId);
97-
if ($character !== null && $character->getUser()->getId() !== $userId) {
101+
if (
102+
$character !== null
103+
&& $character->getUser()->getId() !== $userId
104+
&& $character->getUser()->getId() !== UserConstants::USER_NOONE
105+
) {
98106
$ownerId = $character->getUser()->getId();
99107
$charactersRemovedMapping[$ownerId][] = sprintf('%s (%d)', $character->getName(), $characterId);
100108
}
@@ -152,7 +160,10 @@ public function handle(GameControllerInterface $game): void
152160
foreach ($newCharacterIds as $newCharacterId) {
153161
if (!in_array($newCharacterId, $currentCharacterIds)) {
154162
$userCharacter = $this->userCharactersRepository->find($newCharacterId);
155-
if ($userCharacter) {
163+
if (
164+
$userCharacter !== null
165+
&& $userCharacter->getUser()->getId() !== UserConstants::USER_NOONE
166+
) {
156167
$newEntity = $this->knCharactersRepository->prototype();
157168
$newEntity->setUserCharacter($userCharacter);
158169
$newEntity->setKnPost($post);

tests/unit/Module/Alliance/View/Diplomatic/DiplomaticRelationsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function testHandleRenders(): void
7070
)
7171
->once();
7272

73-
$this->allianceRelationRepository->shouldReceive('findAll')
73+
$this->allianceRelationRepository->shouldReceive('getActive')
7474
->withNoArgs()
7575
->once()
7676
->andReturn([$relation]);

0 commit comments

Comments
 (0)