Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entities refactor #269

Merged
merged 1 commit into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions config/doctrine/Mod/AbstractMod.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
<entity name="App\Entity\Mod\AbstractMod" table="mods" repository-class="App\Repository\Mod\ModRepository" inheritance-type="SINGLE_TABLE">
<field name="name" type="string" length="255"/>
<field name="description" type="string" length="255" nullable="true"/>

<field name="type" type="mod_type_enum" length="255"/>
<field name="status" type="mod_status_enum" length="255" nullable="true"/>

<discriminator-column name="source" type="string" length="255"/>
Expand Down
1 change: 1 addition & 0 deletions config/doctrine/Mod/SteamWorkshopMod.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<entity name="App\Entity\Mod\SteamWorkshopMod" repository-class="App\Repository\Mod\SteamWorkshopModRepository">
<field name="type" type="mod_type_enum" length="255"/>
<field name="itemId" type="bigint" unique="true"/>
</entity>

Expand Down
33 changes: 33 additions & 0 deletions migrations/Version20230814124403.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20230814124403 extends AbstractMigration
{
public function getDescription(): string
{
return 'Remove mod type from directory mod entity';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE mods CHANGE type type VARCHAR(255) DEFAULT NULL COMMENT \'(DC2Type:mod_type_enum)\'');
$this->addSql("UPDATE mods SET type = NULL WHERE source = 'directory'");
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql("UPDATE mods SET type = 'server_side' WHERE source = 'directory'");
$this->addSql('ALTER TABLE mods CHANGE type type VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci` COMMENT \'(DC2Type:mod_type_enum)\'');
}
}
4 changes: 2 additions & 2 deletions src/Api/Controller/GetModListByNameAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Api\Controller;

use App\Entity\ModList\ModListInterface;
use App\Entity\ModList\ModList;
use App\Repository\ModList\ModListRepository;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

Expand All @@ -15,7 +15,7 @@ public function __construct(
) {
}

public function __invoke(string $name): ?ModListInterface
public function __invoke(string $name): ?ModList
{
$modList = $this->modListRepository->findOneBy([
'name' => $name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use ApiPlatform\Core\Validator\ValidatorInterface;
use App\Api\Input\Attendance\AttendanceInput;
use App\Entity\Attendance\Attendance;
use App\Entity\Attendance\AttendanceInterface;
use Ramsey\Uuid\Uuid;

class AttendanceInputDataTransformer implements DataTransformerInterface
Expand All @@ -28,7 +27,7 @@ public function transform($object, string $to, array $context = []): Attendance

public function supportsTransformation($data, string $to, array $context = []): bool
{
if ($data instanceof AttendanceInterface) {
if ($data instanceof Attendance) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

use ApiPlatform\Core\DataTransformer\DataTransformerInterface;
use App\Api\Output\Attendance\AttendanceOutput;
use App\Entity\Attendance\AttendanceInterface;
use App\Entity\Attendance\Attendance;

class AttendanceOutputDataTransformer implements DataTransformerInterface
{
public function transform($object, string $to, array $context = []): AttendanceOutput
{
/** @var AttendanceInterface $object */
/** @var Attendance $object */
$output = new AttendanceOutput();

$output->setId($object->getId()->toString());
Expand All @@ -25,6 +25,6 @@ public function transform($object, string $to, array $context = []): AttendanceO

public function supportsTransformation($data, string $to, array $context = []): bool
{
return AttendanceOutput::class === $to && $data instanceof AttendanceInterface;
return AttendanceOutput::class === $to && $data instanceof Attendance;
}
}
6 changes: 3 additions & 3 deletions src/Api/DataTransformer/Dlc/DlcOutputDataTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

use ApiPlatform\Core\DataTransformer\DataTransformerInterface;
use App\Api\Output\Dlc\DlcOutput;
use App\Entity\Dlc\DlcInterface;
use App\Entity\Dlc\Dlc;

class DlcOutputDataTransformer implements DataTransformerInterface
{
public function transform($object, string $to, array $context = []): DlcOutput
{
/** @var DlcInterface $object */
/** @var Dlc $object */
$output = new DlcOutput();

$output->setId($object->getId()->toString());
Expand All @@ -27,6 +27,6 @@ public function transform($object, string $to, array $context = []): DlcOutput

public function supportsTransformation($data, string $to, array $context = []): bool
{
return DlcOutput::class === $to && $data instanceof DlcInterface;
return DlcOutput::class === $to && $data instanceof Dlc;
}
}
11 changes: 6 additions & 5 deletions src/Api/DataTransformer/Mod/ModOutputDataTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,34 @@

use ApiPlatform\Core\DataTransformer\DataTransformerInterface;
use App\Api\Output\Mod\ModOutput;
use App\Entity\Mod\AbstractMod;
use App\Entity\Mod\DirectoryMod;
use App\Entity\Mod\Enum\ModSourceEnum;
use App\Entity\Mod\ModInterface;
use App\Entity\Mod\Enum\ModTypeEnum;
use App\Entity\Mod\SteamWorkshopMod;

class ModOutputDataTransformer implements DataTransformerInterface
{
public function transform($object, string $to, array $context = []): ModOutput
{
/** @var ModInterface $object */
/** @var AbstractMod $object */
$output = new ModOutput();

$output->setId($object->getId()->toString());
$output->setName($object->getName());
$output->setCreatedAt($object->getCreatedAt());
$output->setLastUpdatedAt($object->getLastUpdatedAt());

$output->setType($object->getType()->getValue());

/** @var null|string $status */
$status = $object->getStatus() ? $object->getStatus()->getValue() : null;
$output->setStatus($status);

if ($object instanceof SteamWorkshopMod) {
$output->setType($object->getType()->getValue());
$output->setSource(ModSourceEnum::STEAM_WORKSHOP);
$output->setItemId($object->getItemId());
} elseif ($object instanceof DirectoryMod) {
$output->setType(ModTypeEnum::SERVER_SIDE);
$output->setSource(ModSourceEnum::DIRECTORY);
$output->setDirectory($object->getDirectory());
}
Expand All @@ -42,6 +43,6 @@ public function transform($object, string $to, array $context = []): ModOutput

public function supportsTransformation($data, string $to, array $context = []): bool
{
return ModOutput::class === $to && $data instanceof ModInterface;
return ModOutput::class === $to && $data instanceof AbstractMod;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
use App\Api\Output\Mod\ModOutput;
use App\Api\Output\ModList\ModListDetailsOutput;
use App\Api\Output\ModList\ModListOutput;
use App\Entity\Dlc\DlcInterface;
use App\Entity\Dlc\Dlc;
use App\Entity\ModList\ModList;
use App\Entity\ModList\ModListInterface;
use App\Repository\Mod\ModRepository;

class ModListDetailsOutputDataTransformer implements DataTransformerInterface
Expand All @@ -27,7 +26,7 @@ public function __construct(

public function transform($object, string $to, array $context = []): ModListOutput
{
/** @var ModListInterface $object */
/** @var ModList $object */
$output = new ModListDetailsOutput();

$output->setId($object->getId()->toString());
Expand All @@ -44,7 +43,7 @@ public function transform($object, string $to, array $context = []): ModListOutp
$output->setMods($mods);

$dlcs = array_map(
fn (DlcInterface $dlc) => $this->dlcOutputDataTransformer->transform($dlc, DlcOutput::class, $context),
fn (Dlc $dlc) => $this->dlcOutputDataTransformer->transform($dlc, DlcOutput::class, $context),
$object->getDlcs()
);
$output->setDlcs($dlcs);
Expand Down
1 change: 1 addition & 0 deletions src/DataFixtures/Dlc/CslaIronCurtain.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function load(ObjectManager $manager): void
$dlc = new Dlc(
Uuid::fromString(self::ID),
'Arma 3 Creator DLC: CSLA Iron Curtain',
null,
1294440,
'csla'
);
Expand Down
1 change: 1 addition & 0 deletions src/DataFixtures/Dlc/GlobalMobilizationFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function load(ObjectManager $manager): void
$dlc = new Dlc(
Uuid::fromString(self::ID),
'Arma 3 Creator DLC: Global Mobilization - Cold War Germany',
null,
1042220,
'gm'
);
Expand Down
1 change: 1 addition & 0 deletions src/DataFixtures/Dlc/SogPrairieFireFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function load(ObjectManager $manager): void
$dlc = new Dlc(
Uuid::fromString(self::ID),
'Arma 3 Creator DLC: S.O.G. Prairie Fire',
null,
1227700,
'vn'
);
Expand Down
1 change: 1 addition & 0 deletions src/DataFixtures/Dlc/WesternSaharaFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function load(ObjectManager $manager): void
$dlc = new Dlc(
Uuid::fromString(self::ID),
'Arma 3 Creator DLC: Western Sahara',
null,
1681170,
'ws'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public function load(ObjectManager $manager): void
$mod = new SteamWorkshopMod(
Uuid::fromString(self::ID),
'ACE Interaction Menu Expansion',
null,
null,
ModTypeEnum::get(ModTypeEnum::OPTIONAL),
1376867375
);
Expand Down
2 changes: 2 additions & 0 deletions src/DataFixtures/Mod/Required/ArmaForcesModsModFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public function load(ObjectManager $manager): void
$mod = new SteamWorkshopMod(
Uuid::fromString(self::ID),
'ArmaForces - Mods',
null,
null,
ModTypeEnum::get(ModTypeEnum::REQUIRED),
1934142795
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public function load(ObjectManager $manager): void
$mod = new SteamWorkshopMod(
Uuid::fromString(self::ID),
'ArmaForces - ACE Medical [OBSOLETE]',
null,
ModStatusEnum::get(ModStatusEnum::BROKEN),
ModTypeEnum::get(ModTypeEnum::REQUIRED),
1704054308
);
$mod->setStatus(ModStatusEnum::get(ModStatusEnum::BROKEN));
$mod->setCreatedAt(\DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2020-01-01 00:00:00'));

$manager->persist($mod);
$manager->flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public function load(ObjectManager $manager): void
$mod = new SteamWorkshopMod(
Uuid::fromString(self::ID),
'[legacy] ArmaForces - Mods',
null,
ModStatusEnum::get(ModStatusEnum::DEPRECATED),
ModTypeEnum::get(ModTypeEnum::REQUIRED),
1639399387
);
$mod->setStatus(ModStatusEnum::get(ModStatusEnum::DEPRECATED));
$mod->setCreatedAt(\DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2020-01-01 00:00:00'));

$manager->persist($mod);
$manager->flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public function load(ObjectManager $manager): void
$mod = new SteamWorkshopMod(
Uuid::fromString(self::ID),
'[OBSOLETE] ArmaForces - JBAD Building Fix',
null,
ModStatusEnum::get(ModStatusEnum::DISABLED),
ModTypeEnum::get(ModTypeEnum::REQUIRED),
1781106281
);
$mod->setStatus(ModStatusEnum::get(ModStatusEnum::DISABLED));
$mod->setCreatedAt(\DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2020-01-01 00:00:00'));

$manager->persist($mod);
$manager->flush();
Expand Down
4 changes: 3 additions & 1 deletion src/DataFixtures/ModGroup/RhsModGroupFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public function load(ObjectManager $manager): void
{
$modGroup = new ModGroup(
Uuid::fromString(self::ID),
'RHS'
'RHS',
null,
[]
);
$modGroup->setCreatedAt(\DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2020-01-01 00:00:00'));

Expand Down
21 changes: 12 additions & 9 deletions src/DataFixtures/ModList/DefaultModListFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ class DefaultModListFixture extends Fixture

public function load(ObjectManager $manager): void
{
$modList = new ModList(
Uuid::fromString(self::ID),
'Default'
);
$modList->setCreatedAt(\DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2020-01-01 00:00:00'));

$mods = [
$this->getReference(Optional\AceInteractionMenuExpansionModFixture::ID),
$this->getReference(Required\ArmaForcesModsModFixture::ID),
Expand All @@ -31,9 +25,18 @@ public function load(ObjectManager $manager): void
$this->getReference(Required\Disabled\ArmaForcesJbadBuildingFixModFixture::ID),
];

foreach ($mods as $mod) {
$modList->addMod($mod);
}
$modList = new ModList(
Uuid::fromString(self::ID),
'Default',
null,
$mods,
[],
[],
null,
true,
false,
);
$modList->setCreatedAt(\DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2020-01-01 00:00:00'));

$manager->persist($modList);
$manager->flush();
Expand Down
5 changes: 4 additions & 1 deletion src/DataFixtures/User/AdminUserFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ public function load(ObjectManager $manager): void
'admin#1111',
'[email protected]',
self::ID,
$permissions
$permissions,
[],
null,
null
);

$manager->persist($permissions);
Expand Down
5 changes: 4 additions & 1 deletion src/DataFixtures/User/RegularUserFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ public function load(ObjectManager $manager): void
'regular#2222',
'[email protected]',
self::ID,
$permissions
$permissions,
[],
null,
null
);

$manager->persist($permissions);
Expand Down
Loading
Loading