Hey there,
I get a really strange error when I try to create a user from a registration object in Flow.
I hope I can explain it well enough.
The problem:
All fields are written to the database except for the field “activation_code” which is persisted as “NULL”.
It must have something to do with the fact that I set this field to the registration object first and after that I get it from the registration to write it to the user.
When I set the activation code to the user directly it is correctly persisted to the database.
Funnily enough I also pass the registration object to send a notification mail (via emitRegistrationSuccessful) which gets and sends the correct (!) activation code.
The strange:
Funnily, this behaviour happens only on my test server an NOT in my local environment (so debugging is rather difficult…).
I have already found out that is has got something to do with the setter of the registration object:
When I omit the registration setter and set the activation code directly to the user object, then everything works (but I want to pass the registration to the notification mail so I need this setter or I have to rewrite my notification).
/**
* Creates a new user from a registration
*
* @param Registration $registration
* @Flow\Validate(argumentName="registration", type="Acme.MyPackage:Registration")
*/
public function registerAction(Registration $registration) {
$activationCode = strtolower(Algorithms::generateRandomString(32));
$registration->setActivationCode($activationCode);
$this->userFactory->createUserFromRegistration($registration);
//this is used to send a mail with an activation url
$this->emitRegistrationSuccessful($registration);
//...
}
In the user factory:
/**
* Creates a user from a registration
*
* @param Registration $registration
* @return User
*/
public function createUserFromRegistration(Registration $registration) {
//creates a new user object and adds it to the respective repository
$user = $this->createUser($registration->getEmail(), $registration->getPassword());
//theses fields are saved correctly!
$user->setSalutation($registration->getSalutation());
$user->setForename($registration->getForename());
//..
//the activation code is persisted as NULL (?!)
$user->setActivationCode($registration->getActivationCode());
//this prints the correct values:
//
//echo $user->getActivationCode();
//echo $registration->getActivationCode();
return $user;
}
I suppose that it has something to do with the object lifecycle but as my local code works flawlessly I cannot even debug properly.
When I use the Production context on my local machine it works as well.
I have cleared the cache on my test server.
Both machines have PHP 5.6 but different minor versions (local machine 5.6.15, test server 5.6.18).
Any other ideas? Where (which keywords) can I search in the manual?