Skip to content

Commit

Permalink
dont fail when you cant check the database in setup
Browse files Browse the repository at this point in the history
  • Loading branch information
antedebaas committed Aug 21, 2023
1 parent 59de7ca commit 76a8707
Showing 1 changed file with 37 additions and 28 deletions.
65 changes: 37 additions & 28 deletions src/Controller/SetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
}
}

Expand Down

0 comments on commit 76a8707

Please sign in to comment.