fix(schema): aligner mappings et sortie machine
This commit is contained in:
@@ -9,7 +9,8 @@ doctrine:
|
||||
profiling_collect_backtrace: '%kernel.debug%'
|
||||
orm:
|
||||
validate_xml_mapping: true
|
||||
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
|
||||
naming_strategy: doctrine.orm.naming_strategy.default
|
||||
quote_strategy: doctrine.orm.quote_strategy.default
|
||||
identity_generation_preferences:
|
||||
Doctrine\DBAL\Platforms\PostgreSQLPlatform: identity
|
||||
auto_mapping: true
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
INSERT INTO public.profiles (id, firstname, lastname, isactive, createdat, updatedat)
|
||||
INSERT INTO public.profiles (id, firstname, lastname, email, isactive, createdat, updatedat)
|
||||
VALUES
|
||||
('admin-default-profile', 'Admin', 'General', true, '2025-09-23 13:09:47.804', '2025-09-23 13:09:47.804'),
|
||||
('cmhab2j3x003g47v77xhnm1ff', 'Elodie', 'Souriau', true, '2025-10-28 08:29:25.437', '2025-10-28 08:29:25.437')
|
||||
('admin-default-profile', 'Admin', 'General', 'admin@admin.fr', true, '2025-09-23 13:09:47.804', '2025-09-23 13:09:47.804'),
|
||||
('cmhab2j3x003g47v77xhnm1ff', 'Elodie', 'Souriau', 'elodie@gg.fr', true, '2025-10-28 08:29:25.437', '2025-10-28 08:29:25.437')
|
||||
ON CONFLICT (id) DO NOTHING;
|
||||
|
||||
@@ -400,13 +400,27 @@ class MachineSkeletonController extends AbstractController
|
||||
|
||||
private function normalizeMachine(Machine $machine): array
|
||||
{
|
||||
$site = $machine->getSite();
|
||||
$typeMachine = $machine->getTypeMachine();
|
||||
|
||||
return [
|
||||
'id' => $machine->getId(),
|
||||
'name' => $machine->getName(),
|
||||
'reference' => $machine->getReference(),
|
||||
'prix' => $machine->getPrix(),
|
||||
'siteId' => $machine->getSite()->getId(),
|
||||
'typeMachineId' => $machine->getTypeMachine()?->getId(),
|
||||
'siteId' => $site->getId(),
|
||||
'site' => [
|
||||
'id' => $site->getId(),
|
||||
'name' => $site->getName(),
|
||||
],
|
||||
'typeMachineId' => $typeMachine?->getId(),
|
||||
'typeMachine' => $typeMachine ? [
|
||||
'id' => $typeMachine->getId(),
|
||||
'name' => $typeMachine->getName(),
|
||||
'category' => $typeMachine->getCategory(),
|
||||
'description' => $typeMachine->getDescription(),
|
||||
] : null,
|
||||
'constructeurs' => $this->normalizeConstructeurs($machine->getConstructeurs()),
|
||||
'documents' => null,
|
||||
'customFieldValues' => null,
|
||||
];
|
||||
|
||||
110
src/Doctrine/QuoteStrategy/AlwaysQuoteStrategy.php
Normal file
110
src/Doctrine/QuoteStrategy/AlwaysQuoteStrategy.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Doctrine\QuoteStrategy;
|
||||
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\ORM\Internal\SQLResultCasing;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\Mapping\JoinColumnMapping;
|
||||
use Doctrine\ORM\Mapping\ManyToManyOwningSideMapping;
|
||||
use Doctrine\ORM\Mapping\QuoteStrategy;
|
||||
|
||||
use function array_map;
|
||||
use function array_merge;
|
||||
use function assert;
|
||||
use function explode;
|
||||
use function implode;
|
||||
|
||||
/**
|
||||
* Quote all identifiers to preserve camelCase column names in Postgres.
|
||||
*/
|
||||
final class AlwaysQuoteStrategy implements QuoteStrategy
|
||||
{
|
||||
use SQLResultCasing;
|
||||
|
||||
public function getColumnName(string $fieldName, ClassMetadata $class, AbstractPlatform $platform): string
|
||||
{
|
||||
return $platform->quoteSingleIdentifier($class->fieldMappings[$fieldName]->columnName);
|
||||
}
|
||||
|
||||
public function getTableName(ClassMetadata $class, AbstractPlatform $platform): string
|
||||
{
|
||||
$tableName = $platform->quoteSingleIdentifier($class->table['name']);
|
||||
|
||||
if (! empty($class->table['schema'])) {
|
||||
return $platform->quoteSingleIdentifier($class->table['schema']) . '.' . $tableName;
|
||||
}
|
||||
|
||||
return $tableName;
|
||||
}
|
||||
|
||||
public function getSequenceName(array $definition, ClassMetadata $class, AbstractPlatform $platform): string
|
||||
{
|
||||
return implode('.', array_map(
|
||||
static fn (string $part) => $platform->quoteSingleIdentifier($part),
|
||||
explode('.', $definition['sequenceName']),
|
||||
));
|
||||
}
|
||||
|
||||
public function getJoinTableName(
|
||||
ManyToManyOwningSideMapping $association,
|
||||
ClassMetadata $class,
|
||||
AbstractPlatform $platform,
|
||||
): string {
|
||||
$schema = '';
|
||||
|
||||
if (isset($association->joinTable->schema)) {
|
||||
$schema = $platform->quoteSingleIdentifier($association->joinTable->schema) . '.';
|
||||
}
|
||||
|
||||
return $schema . $platform->quoteSingleIdentifier($association->joinTable->name);
|
||||
}
|
||||
|
||||
public function getJoinColumnName(JoinColumnMapping $joinColumn, ClassMetadata $class, AbstractPlatform $platform): string
|
||||
{
|
||||
return $platform->quoteSingleIdentifier($joinColumn->name);
|
||||
}
|
||||
|
||||
public function getReferencedJoinColumnName(
|
||||
JoinColumnMapping $joinColumn,
|
||||
ClassMetadata $class,
|
||||
AbstractPlatform $platform,
|
||||
): string {
|
||||
return $platform->quoteSingleIdentifier($joinColumn->referencedColumnName);
|
||||
}
|
||||
|
||||
public function getIdentifierColumnNames(ClassMetadata $class, AbstractPlatform $platform): array
|
||||
{
|
||||
$quotedColumnNames = [];
|
||||
|
||||
foreach ($class->identifier as $fieldName) {
|
||||
if (isset($class->fieldMappings[$fieldName])) {
|
||||
$quotedColumnNames[] = $this->getColumnName($fieldName, $class, $platform);
|
||||
continue;
|
||||
}
|
||||
|
||||
$assoc = $class->associationMappings[$fieldName];
|
||||
assert($assoc->isToOneOwningSide());
|
||||
$joinColumns = $assoc->joinColumns;
|
||||
$assocQuotedColumnNames = array_map(
|
||||
static fn (JoinColumnMapping $joinColumn) => $platform->quoteSingleIdentifier($joinColumn->name),
|
||||
$joinColumns,
|
||||
);
|
||||
|
||||
$quotedColumnNames = array_merge($quotedColumnNames, $assocQuotedColumnNames);
|
||||
}
|
||||
|
||||
return $quotedColumnNames;
|
||||
}
|
||||
|
||||
public function getColumnAlias(
|
||||
string $columnName,
|
||||
int $counter,
|
||||
AbstractPlatform $platform,
|
||||
ClassMetadata|null $class = null,
|
||||
): string {
|
||||
return $this->getSQLResultCasing($platform, $columnName . '_' . $counter);
|
||||
}
|
||||
}
|
||||
@@ -45,17 +45,17 @@ class Profile implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
#[Groups(['profile:read', 'profile:write'])]
|
||||
private ?string $email = null;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 100, name: 'firstName')]
|
||||
#[ORM\Column(type: 'string', length: 100, name: 'firstname')]
|
||||
#[Assert\NotBlank]
|
||||
#[Groups(['profile:read', 'profile:write'])]
|
||||
private string $firstName;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 100, name: 'lastName')]
|
||||
#[ORM\Column(type: 'string', length: 100, name: 'lastname')]
|
||||
#[Assert\NotBlank]
|
||||
#[Groups(['profile:read', 'profile:write'])]
|
||||
private string $lastName;
|
||||
|
||||
#[ORM\Column(type: 'boolean', options: ['default' => true], name: 'isActive')]
|
||||
#[ORM\Column(type: 'boolean', options: ['default' => true], name: 'isactive')]
|
||||
#[Groups(['profile:read', 'profile:write'])]
|
||||
private bool $isActive = true;
|
||||
|
||||
@@ -73,11 +73,11 @@ class Profile implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
#[Groups(['profile:write'])]
|
||||
private ?string $password = null;
|
||||
|
||||
#[ORM\Column(type: 'datetime_immutable', name: 'createdAt')]
|
||||
#[ORM\Column(type: 'datetime_immutable', name: 'createdat')]
|
||||
#[Groups(['profile:read'])]
|
||||
private DateTimeImmutable $createdAt;
|
||||
|
||||
#[ORM\Column(type: 'datetime_immutable', name: 'updatedAt')]
|
||||
#[ORM\Column(type: 'datetime_immutable', name: 'updatedat')]
|
||||
#[Groups(['profile:read'])]
|
||||
private DateTimeImmutable $updatedAt;
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ class TypeMachine
|
||||
#[Groups(['type_machine:read', 'type_machine:write'])]
|
||||
private ?string $description = null;
|
||||
|
||||
#[ORM\Column(type: Types::STRING, length: 255, nullable: true, name: 'maintenanceFrequency')]
|
||||
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
|
||||
#[Groups(['type_machine:read', 'type_machine:write'])]
|
||||
private ?string $category = null;
|
||||
|
||||
@@ -58,11 +58,11 @@ class TypeMachine
|
||||
#[Groups(['type_machine:read', 'type_machine:write'])]
|
||||
private ?string $maintenanceFrequency = null;
|
||||
|
||||
#[ORM\Column(type: Types::JSON, nullable: true, name: 'criticalParts')]
|
||||
#[ORM\Column(type: Types::JSON, nullable: true)]
|
||||
#[Groups(['type_machine:read', 'type_machine:write'])]
|
||||
private ?array $components = null;
|
||||
|
||||
#[ORM\Column(type: Types::JSON, nullable: true, name: 'machinePieces')]
|
||||
#[ORM\Column(type: Types::JSON, nullable: true)]
|
||||
#[Groups(['type_machine:read', 'type_machine:write'])]
|
||||
private ?array $criticalParts = null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user