Skip to content

Commit

Permalink
fix database entry references
Browse files Browse the repository at this point in the history
  • Loading branch information
g5bot committed Aug 16, 2024
1 parent 29507ea commit 6431409
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 24 deletions.
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -903,11 +903,6 @@ parameters:
count: 1
path: src/Module/Control/GameController.php

-
message: "#^Method Stu\\\\Module\\\\Control\\\\GameController\\:\\:checkDatabaseItem\\(\\) has parameter \\$databaseEntryId with no type specified\\.$#"
count: 1
path: src/Module/Control/GameController.php

-
message: "#^Method Stu\\\\Module\\\\Control\\\\GameController\\:\\:getAchievements\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -943,11 +938,6 @@ parameters:
count: 1
path: src/Module/Control/GameControllerInterface.php

-
message: "#^Method Stu\\\\Module\\\\Control\\\\GameControllerInterface\\:\\:checkDatabaseItem\\(\\) has parameter \\$databaseEntryId with no type specified\\.$#"
count: 1
path: src/Module/Control/GameControllerInterface.php

-
message: "#^Method Stu\\\\Module\\\\Control\\\\GameControllerInterface\\:\\:getAchievements\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down
34 changes: 34 additions & 0 deletions src/Component/Migrations/Version20240816121145_DatabaseEntry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Stu\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20240816121145_DatabaseEntry extends AbstractMigration
{
public function getDescription(): string
{
return 'Add database entry foreign keys and indices';
}

public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE stu_ships ALTER database_id DROP NOT NULL');
$this->addSql('UPDATE stu_ships SET database_id = null WHERE database_id = 0');
$this->addSql('ALTER TABLE stu_colonies ADD CONSTRAINT FK_D1C60F73F0AA09DB FOREIGN KEY (database_id) REFERENCES stu_database_entrys (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE UNIQUE INDEX UNIQ_D1C60F73F0AA09DB ON stu_colonies (database_id)');
$this->addSql('ALTER TABLE stu_ships ADD CONSTRAINT FK_A560DD56F0AA09DB FOREIGN KEY (database_id) REFERENCES stu_database_entrys (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE UNIQUE INDEX UNIQ_A560DD56F0AA09DB ON stu_ships (database_id)');
}

public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE stu_ships DROP CONSTRAINT FK_A560DD56F0AA09DB');
$this->addSql('DROP INDEX UNIQ_A560DD56F0AA09DB');
$this->addSql('ALTER TABLE stu_colonies DROP CONSTRAINT FK_D1C60F73F0AA09DB');
$this->addSql('DROP INDEX UNIQ_D1C60F73F0AA09DB');
}
}
9 changes: 8 additions & 1 deletion src/Module/Control/GameController.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,15 @@ public function getJavascriptPath(): string
}

#[Override]
public function checkDatabaseItem($databaseEntryId): void
public function checkDatabaseItem(?int $databaseEntryId): void
{
if (
$databaseEntryId === null
|| $databaseEntryId === 0
) {
return;
}

$userId = $this->getUser()->getId();

if (
Expand Down
2 changes: 1 addition & 1 deletion src/Module/Control/GameControllerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function getCurrentRound(): GameTurnInterface;

public function getJavascriptPath(): string;

public function checkDatabaseItem($databaseEntryId): void;
public function checkDatabaseItem(?int $databaseEntryId): void;

public function getAchievements(): array;

Expand Down
11 changes: 3 additions & 8 deletions src/Module/Ship/View/ShowScan/ShowScan.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public function __construct(
private InteractionCheckerInterface $interactionChecker,
private PirateReactionInterface $pirateReaction,
private PrivateMessageSenderInterface $privateMessageSender
) {
}
) {}

#[Override]
public function handle(GameControllerInterface $game): void
Expand Down Expand Up @@ -75,12 +74,8 @@ public function handle(GameControllerInterface $game): void

$epsSystem->lowerEps(1)->update();

if ($target->getDatabaseId() !== 0) {
$game->checkDatabaseItem($target->getDatabaseId());
}
if ($target->getRump()->getDatabaseId()) {
$game->checkDatabaseItem($target->getRump()->getDatabaseId());
}
$game->checkDatabaseItem($target->getDatabaseId());
$game->checkDatabaseItem($target->getRump()->getDatabaseId());

$href = sprintf('ship.php?%s=1&id=%d', ShowShip::VIEW_IDENTIFIER, $target->getId());

Expand Down
6 changes: 3 additions & 3 deletions src/Orm/Entity/Ship.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ class Ship implements ShipInterface
#[Column(type: 'smallint', length: 1, enumType: SpacecraftTypeEnum::class)]
private SpacecraftTypeEnum $type = SpacecraftTypeEnum::SPACECRAFT_TYPE_SHIP;

#[Column(type: 'integer')]
private int $database_id = 0;
#[Column(type: 'integer', nullable: true)]
private ?int $database_id = null;

#[Column(type: 'boolean')]
private bool $is_destroyed = false;
Expand Down Expand Up @@ -629,7 +629,7 @@ public function setSpacecraftType(SpacecraftTypeEnum $type): ShipInterface
}

#[Override]
public function getDatabaseId(): int
public function getDatabaseId(): ?int
{
return $this->database_id;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Orm/Entity/ShipInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function getSpacecraftType(): SpacecraftTypeEnum;

public function setSpacecraftType(SpacecraftTypeEnum $type): ShipInterface;

public function getDatabaseId(): int;
public function getDatabaseId(): ?int;

public function setDatabaseEntry(DatabaseEntryInterface $entry): ShipInterface;

Expand Down

0 comments on commit 6431409

Please sign in to comment.