diff --git a/src/Controller/SetupController.php b/src/Controller/SetupController.php index a61fbbc..0d06aef 100644 --- a/src/Controller/SetupController.php +++ b/src/Controller/SetupController.php @@ -73,17 +73,22 @@ public function index(Request $request, UserPasswordHasherInterface $userPasswor } else { - $doctrinemigrations = $this->em->createQueryBuilder() + try { + $doctrinemigrations = $this->em->createQueryBuilder() ->select('m.version') ->from(DoctrineMigrationVersions::class, 'm') ->orderBy('m.version', 'ASC') ->getQuery() ->getResult(); - $migrations=array(); - foreach ($doctrinemigrations as $migration) { - $migrations[] = $migration['version']; + $migrations=array(); + foreach ($doctrinemigrations as $migration) { + $migrations[] = $migration['version']; + } + } catch (\Exception $e) { + $migrations=array(); } + $migrationfiles=array(); $finder = new Finder(); $finder->files()->in(__DIR__.'/../../migrations'); @@ -110,31 +115,35 @@ public function index(Request $request, UserPasswordHasherInterface $userPasswor $setup['missingmigrations_list'] = $migrationdifferences_missingfiles; } - // check if there are users in the database - $number_of_users = $this->em->getRepository(Users::class)->getTotalRows(); - if($number_of_users > 0){ - $setup['users'] = true; - } else { - $setup['users'] = false; - $form = $this->createForm(RegistrationFormType::class); - - $form->handleRequest($request); - if ($form->isSubmitted() && $form->isValid()){ - $formdata = $form->getData(); - $formdata->setPassword( - $userPasswordHasher->hashPassword( - $formdata, - $form->get('plainPassword')->getData() - ) - ); - $formdata->SetRoles(array('ROLE_ADMIN')); - $formdata->setIsVerified(true); - $this->em->persist($formdata); - $this->em->flush(); - - return $this->redirectToRoute('app_setup'); + try { + // check if there are users in the database + $number_of_users = $this->em->getRepository(Users::class)->getTotalRows(); + if($number_of_users > 0){ + $setup['users'] = true; + } else { + $setup['users'] = false; + $form = $this->createForm(RegistrationFormType::class); + + $form->handleRequest($request); + if ($form->isSubmitted() && $form->isValid()){ + $formdata = $form->getData(); + $formdata->setPassword( + $userPasswordHasher->hashPassword( + $formdata, + $form->get('plainPassword')->getData() + ) + ); + $formdata->SetRoles(array('ROLE_ADMIN')); + $formdata->setIsVerified(true); + $this->em->persist($formdata); + $this->em->flush(); + + return $this->redirectToRoute('app_setup'); + } + $setup['users_form'] = $form->createView(); } - $setup['users_form'] = $form->createView(); + } catch (\Exception $e) { + $setup['users'] = false; } }