creation from an existing user works

This commit is contained in:
Baptiste Lemoine 2019-11-06 12:49:30 +01:00
parent 6b4994b35a
commit 7340b020ec
1 changed files with 5 additions and 2 deletions

View File

@ -98,8 +98,8 @@ class DefaultController extends AbstractController {
$data = json_decode( $data, true );
// die( $data );
$em = $this->getDoctrine()->getRepository( Owner::class );
$foundOwner = $em->findByEmail( $data[ 'owner' ][ 'email' ] );
die( $foundOwner );
$foundOwner = $em->findOneBy( [ 'email' => $data[ 'owner' ][ 'email' ] ] );
$userWasFound = false;
if ( ! $foundOwner ) {
//create a new owner
@ -109,12 +109,15 @@ class DefaultController extends AbstractController {
$owner->setEmail( $data[ 'owner' ][ 'email' ] );
$foundOwner = $owner;
} else {
// die( $foundOwner->getPseudo() );
$userWasFound = true;
}
// link the owner and the poll
$newpoll->setOwner( $foundOwner );
$foundOwner->addPoll( $newpoll );
$em = $this->getDoctrine()->getManager();
$em->persist( $newpoll );
$em->persist( $foundOwner );
$em->flush();
$precision = '';
if ( $userWasFound ) {