October 22, 2024
Chicago 12, Melborne City, USA
PHP

Sporadic functionality in Symfony 7 registration method


I have a registration method in my Symfony 7 application which is working for the most part, however certain parts seem like they aren’t being called and logging isn’t working at all.

public function register(Request $request): Response
    {
        $this->logger->critical('Testing first line of function');

        $userRegistrationDTO = new UserRegistrationDTO();
        $form                = $this->createForm(UserRegistrationType::class, $userRegistrationDTO);

        $form->handleRequest($request);

        $this->logger->critical('testing logger before form submit');

        if ($form->isSubmitted() && $form->isValid()) {
            $user = User::createUserRegistration($userRegistrationDTO);
            $this->logger->critical('test logger');

            if ($clickId = $request->cookies->get('client_id')) {
                $this->logger->critical('Creating customer with referral', ['click_id' => $clickId, 'user' => $user]);
                $this->tapAffiliateService->createCustomer($clickId, $user->email);
                $user->referralId = $clickId;
            }
            $user->referralId = 'test this is running';

            $user->password = $this->userRepository->hashPassword($user, $userRegistrationDTO->getPlainPassword());
            $this->userRepository->persist($user);
            $this->securityHelper->login($user);

            $notification = new UserRegistrationNotification($user);

            try {
                $this->notifier->notify($notification);
            } catch (\Exception $e) {
                $this->logger->critical('Failed to send registration email', ['user' => $user, 'exception' => $e]);
            }

            return $this->redirect('/app/subscribe');
        }

        $this->logger->critical('testing logger after form submit');

        return $this->render('registration/register.html.twig', [
            'registrationForm' => $form->createView(),
        ]);
    }

The template is loaded correctly and, on form submission, a user account is created, the welcome email is sent successfully and the user is logged in so it’s clear the function is running however:

  • The interactions with the tapAffiliateService do not occur, even when the cookie exists.
  • None of the test logs, both inside and outside of form submission, are written to the logs.
  • The user is redirected to /app, not /app/subscribe.
  • The test assignment $user->referralId = 'test this is running'; does not work and is not set when checking the user record.

I believe the redirection may be because of $this->securityHelper->login($user) because my security.yaml is set to redirect the user to /app on login. Am I correct in saying this?

Why would the logs not be written? I have added critical logs to a number of other controller methods and they all work fine.

This issue only occurs on my production server. I’ve tested extensively locally and it works with no issues.



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video