mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-03-03 12:39:42 +00:00
Add missing fields
This commit is contained in:
@@ -28,6 +28,18 @@ readonly class PersonUpsertHandler
|
||||
private EntityManagerInterface $entityManager,
|
||||
) {}
|
||||
|
||||
private function _handlePersonMessage(UpsertMessage $message, Person $person): Person
|
||||
{
|
||||
if (null !== $message->firstName) {
|
||||
$person->setFirstName($message->firstName);
|
||||
}
|
||||
if (null !== $message->lastName) {
|
||||
$person->setLastName($message->lastName);
|
||||
}
|
||||
|
||||
return $person;
|
||||
}
|
||||
|
||||
public function __invoke(UpsertMessage $message): void
|
||||
{
|
||||
// 1. Retrieve definition
|
||||
@@ -46,12 +58,7 @@ readonly class PersonUpsertHandler
|
||||
if (0 === count($identifiers)) {
|
||||
// 3. Create new entity Person
|
||||
$person = new Person();
|
||||
if (null !== $message->firstName) {
|
||||
$person->setFirstName($message->firstName);
|
||||
}
|
||||
if (null !== $message->lastName) {
|
||||
$person->setLastName($message->lastName);
|
||||
}
|
||||
$person = $this->_handlePersonMessage($message, $person);
|
||||
$this->entityManager->persist($person);
|
||||
|
||||
// Create and bound identifier
|
||||
@@ -64,12 +71,7 @@ readonly class PersonUpsertHandler
|
||||
/** @var PersonIdentifier $identifier */
|
||||
$identifier = $identifiers[0];
|
||||
$person = $identifier->getPerson();
|
||||
if (null !== $message->firstName) {
|
||||
$person->setFirstName($message->firstName);
|
||||
}
|
||||
if (null !== $message->lastName) {
|
||||
$person->setLastName($message->lastName);
|
||||
}
|
||||
$person = $this->_handlePersonMessage($message, $person);
|
||||
}
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
Reference in New Issue
Block a user