Member Entity Update
Allows nullable first and lastname Change-Id: I0cef969f994365d332785260e24548597202346e Signed-off-by: smarcet <smarcet@gmail.com>
This commit is contained in:
parent
41385d5579
commit
49987ec57b
@ -114,12 +114,24 @@ final class OAuth2SummitOrdersApiController
|
||||
'owner_email' => 'required|string|max:255|email',
|
||||
], $validation_rules);
|
||||
}
|
||||
else{
|
||||
if(empty($owner->getFirstName())){
|
||||
$validation_rules = array_merge([
|
||||
'owner_first_name' => 'required|string|max:255',
|
||||
], $validation_rules);
|
||||
}
|
||||
if(empty($owner->getLastName())){
|
||||
$validation_rules = array_merge([
|
||||
'owner_last_name' => 'required|string|max:255',
|
||||
], $validation_rules);
|
||||
}
|
||||
}
|
||||
|
||||
$payload = $this->getJsonPayload($validation_rules);
|
||||
if(!is_null($owner)){
|
||||
$payload_ex = [
|
||||
'owner_first_name' => $owner->getFirstName(),
|
||||
'owner_last_name' => $owner->getLastName(),
|
||||
'owner_first_name' => !empty($owner->getFirstName()) ? $owner->getFirstName() : $payload['owner_first_name'],
|
||||
'owner_last_name' => !empty($owner->getLastName()) ? $owner->getLastName() : $payload['owner_last_name'],
|
||||
'owner_email' => $owner->getEmail(),
|
||||
];
|
||||
$payload = array_merge($payload, $payload_ex);
|
||||
|
@ -630,17 +630,17 @@ class Member extends SilverstripeBaseModel
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLastName()
|
||||
public function getLastName():?string
|
||||
{
|
||||
return $this->last_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @return string|null
|
||||
*/
|
||||
public function getFirstName()
|
||||
public function getFirstName():?string
|
||||
{
|
||||
return $this->first_name;
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ class SummitOrder extends SilverstripeBaseModel implements IQREntity
|
||||
|
||||
$lname = $this->getOwnerSurname();
|
||||
if(empty($lname))
|
||||
throw new ValidationException("owner first last name is null");
|
||||
throw new ValidationException("owner last name is null");
|
||||
|
||||
$token = $this->number.'.'.$email.'.'.$fname.".".$lname;
|
||||
$token = $token . random_bytes(16).time();
|
||||
|
@ -897,6 +897,21 @@ final class SummitOrderService
|
||||
{
|
||||
|
||||
try {
|
||||
$owner = $this->tx_service->transaction(function () use ($owner, $payload) {
|
||||
if (is_null($owner)) return null;
|
||||
|
||||
$owner = $this->member_repository->getByIdExclusiveLock($owner->getId());
|
||||
|
||||
if (empty($owner->getFirstName())) {
|
||||
$owner->setFirstName($payload['owner_first_name']);
|
||||
}
|
||||
|
||||
if (empty($owner->getLastName())) {
|
||||
$owner->setLastName($payload['owner_last_name']);
|
||||
}
|
||||
|
||||
return $owner;
|
||||
});
|
||||
$state = Saga::start()
|
||||
->addTask(new PreOrderValidationTask($summit, $payload, $this->tx_service))
|
||||
->addTask(new PreProcessReservationTask($payload))
|
||||
@ -1785,14 +1800,14 @@ final class SummitOrderService
|
||||
Log::debug(sprintf("SummitOrderService::createOrderSingleTicket attendee is null"));
|
||||
//first name
|
||||
$first_name = isset($payload['owner_first_name']) ? trim($payload['owner_first_name']) : null;
|
||||
if (empty($first_name) && !is_null($owner)) $first_name = $owner->getFirstName();
|
||||
if (empty($first_name) && !is_null($owner) && !empty($owner->getFirstName())) $first_name = $owner->getFirstName();
|
||||
if (empty($first_name)) {
|
||||
Log::warning("SummitOrderService::createOrderSingleTicket owner firstname is null");
|
||||
throw new ValidationException("you must provide an owner_first_name or a valid owner_id");
|
||||
}
|
||||
// surname
|
||||
$surname = isset($payload['owner_last_name']) ? trim($payload['owner_last_name']) : null;
|
||||
if (empty($surname) && !is_null($owner)) $surname = $owner->getLastName();
|
||||
if (empty($surname) && !is_null($owner) && !empty($owner->getLastName())) $surname = $owner->getLastName();
|
||||
if (empty($surname)) {
|
||||
Log::warning("SummitOrderService::createOrderSingleTicket owner surname is null");
|
||||
throw new ValidationException("you must provide an owner_last_name or a valid owner_id");
|
||||
|
@ -55,7 +55,7 @@ class ExternalUserDTO
|
||||
* @param bool $active
|
||||
* @param bool $email_verified
|
||||
*/
|
||||
public function __construct($id, string $email, string $first_name, string $last_name, bool $active = false, bool $email_verified = false)
|
||||
public function __construct($id, string $email, ?string $first_name, ?string $last_name, bool $active = false, bool $email_verified = false)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->email = $email;
|
||||
@ -82,7 +82,7 @@ class ExternalUserDTO
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @return string|null
|
||||
*/
|
||||
public function getFirstName(): ?string
|
||||
{
|
||||
@ -90,7 +90,7 @@ class ExternalUserDTO
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLastName(): ?string
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user