0

I have a problem in the Security Account/Party Module of Flow3.

I've tried to change the first and last name of a Person as Party:

$person = $account->getParty();
$name = $person->getName();
$name->setFirstName($firstName);
$name->setLastName($lastName);
$this->accountRepository->update($account);
$this->partyRepository->update($person);

$account is a valid \TYPO3\FLOW3\Security\Account Object.

When using this Code and changing $firstName and $lastname, flow3 is doing a rollback.

I found a workaround:

$personName = new \TYPO3\Party\Domain\Model\PersonName('', $firstName,'', $lastName);
$person->setName($personName);

This works correctly, but why ??

Richard J. Ross III
  • 53,315
  • 24
  • 127
  • 192
ridcully
  • 294
  • 1
  • 9

1 Answers1

1

It's because Person::getName() returns a copy of PersonName and not a reference. That means that PersonName is not updated inside ($this->name) of $person if you change it on the outside ($name).

This would be one solution:

$person = $account->getParty();
$name = $person->getName();
$name->setFirstName($firstName);
$name->setLastName($lastName);
$person->setName($name);
$this->accountRepository->update($account);
$this->partyRepository->update($person);

Just set PersonName again.

This anwser is nice too: https://stackoverflow.com/a/746322/782920

PHP: returning by reference: http://php.net/manual/en/language.references.return.php

Community
  • 1
  • 1
PeterTheOne
  • 333
  • 5
  • 15