From 46999dfbc74619fe7a24bdc67c5749a6364401fd Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Thu, 9 Jan 2025 12:47:15 +0100 Subject: [PATCH] refs #1089. Partition assistant. Partition cpt=0 --- src/Service/CreatePartitionService.php | 14 ++++++++++---- src/Service/Utils/GetPartitionCodeService.php | 13 +++++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Service/CreatePartitionService.php b/src/Service/CreatePartitionService.php index cd777db..5b63ea8 100644 --- a/src/Service/CreatePartitionService.php +++ b/src/Service/CreatePartitionService.php @@ -6,13 +6,15 @@ use App\Entity\Client; use App\Entity\OperativeSystem; use App\Entity\Partition; use App\Model\PartitionTypes; +use App\Service\Utils\GetPartitionCodeService; use Doctrine\ORM\EntityManagerInterface; use Exception; class CreatePartitionService { public function __construct( - protected EntityManagerInterface $entityManager + protected EntityManagerInterface $entityManager, + protected GetPartitionCodeService $partitionCodeService ) { } @@ -54,11 +56,15 @@ class CreatePartitionService $partitionEntity->setSize($cfg['tam']); if (isset($cfg['cpt']) && $cfg['cpt'] !== '') { - $decimalValue = hexdec($cfg['cpt']); - $partitionType = PartitionTypes::getPartitionType($decimalValue); + if ($cfg['par'] === "0") { + $partitionType = $this->partitionCodeService->__invoke($cfg['cpt']); + } else { + $decimalValue = hexdec($cfg['cpt']); + $partitionType = PartitionTypes::getPartitionType($decimalValue); + } if ($partitionType) { - $partitionEntity->setPartitionCode($partitionType['name']); + $partitionEntity->setPartitionCode($partitionType['name'] ?? $partitionType); } } else { $partitionEntity->setPartitionCode(PartitionTypes::getPartitionType(0)['name']); diff --git a/src/Service/Utils/GetPartitionCodeService.php b/src/Service/Utils/GetPartitionCodeService.php index 9933c29..4188164 100644 --- a/src/Service/Utils/GetPartitionCodeService.php +++ b/src/Service/Utils/GetPartitionCodeService.php @@ -2,7 +2,16 @@ namespace App\Service\Utils; -class GetPartitionCode +class GetPartitionCodeService { - + public function __invoke(string $partitionCode): string + { + return match ($partitionCode) { + "1" => "MSDOS", + "2" => "GPT", + "3" => "LVM", + "4" => "ZPOOL", + default => "UNKNOWN", + }; + } } \ No newline at end of file