private function createSuperAdmin(Command $command, OutputInterface $output)
    {
        $groupRepository = $this->container->get('ekyna_user.group.repository');
        $userRepository = $this->container->get('ekyna_user.user.repository');

        /** @var \Ekyna\Bundle\UserBundle\Model\GroupInterface $group */
        if (null === $group = $groupRepository->findOneBy(['name' => array_keys($this->defaultGroups)[0]])) {
            $output->writeln('Super admin group not found, aborting.');
            return;
        }

        /** @var \Ekyna\Bundle\UserBundle\Model\UserInterface $superAdmin */
        if (null !== $superAdmin = $userRepository->findOneBy(['group' => $group])) {
            $output->writeln(sprintf('Super admin already exists (<comment>%s</comment>).', $superAdmin->getEmail()));
            return;
        }

        $output->writeln('<question>Please provide initial informations ...</question>');

        /** @var \Symfony\Component\Console\Helper\DialogHelper $dialog */
        $dialog = $command->getHelperSet()->get('dialog');

        $email = $dialog->askAndValidate($output, 'Email: ', function ($answer) use ($userRepository) {
            if (!filter_var($answer, FILTER_VALIDATE_EMAIL)) {
                throw new \RuntimeException('This is not a valid email address.');
            }
            if (null !== $userRepository->findOneBy(['email' => $answer])) {
                throw new \RuntimeException('This email address is already used.');
            }
            return $answer;
        }, 3);

        $password = $dialog->askAndValidate($output, 'Password: ', function ($answer) {
            if (!(preg_match('#^[a-zA-Z0-9]+$#', $answer) && strlen($answer) > 5)) {
                throw new \RuntimeException('Password should be composed of at least 6 letters and numbers.');
            }
            return $answer;
        }, 3);

        $notBlankValidator = function ($answer) {
            if (0 === strlen($answer)) {
                throw new \RuntimeException('This cannot be blank.');
            }
            return $answer;
        };

        $firstName = $dialog->askAndValidate($output, 'First name: ', $notBlankValidator, 3);
        $lastName = $dialog->askAndValidate($output, 'Last name: ', $notBlankValidator, 3);

        $userManager = $this->container->get('fos_user.user_manager');
        /** @var \Ekyna\Bundle\UserBundle\Model\UserInterface $user */
        $user = $userManager->createUser();
        $user
            ->setGroup($group)
            ->setGender('mr')
            ->setFirstName($firstName)
            ->setLastName($lastName)
            ->setPlainPassword($password)
            ->setEmail($email)
            ->setEnabled(true);
        $userManager->updateUser($user);

        $output->writeln('Super Admin has been successfully created.');
    }
private function createSuperAdmin(Command $command, OutputInterface $output)
    {
        $groupRepository = $this->container->get('ekyna_user.group.repository');
        $userRepository = $this->container->get('ekyna_user.user.repository');

        /** @var \Ekyna\Bundle\UserBundle\Model\GroupInterface $group */
        if (null === $group = $groupRepository->findOneBy(['name' => array_keys($this->defaultGroups)[0]])) {
            $output->writeln('Super admin group not found, aborting.');
            return;
        }

        /** @var \Ekyna\Bundle\UserBundle\Model\UserInterface $superAdmin */
        if (null !== $superAdmin = $userRepository->findOneBy(['group' => $group])) {
            $output->writeln(sprintf('Super admin already exists (<comment>%s</comment>).', $superAdmin->getEmail()));
            return;
        }

        $output->writeln('<question>Please provide initial informations ...</question>');

        /** @var \Symfony\Component\Console\Helper\DialogHelper $dialog */
        $dialog = $command->getHelperSet()->get('dialog');

        $email = $dialog->askAndValidate($output, 'Email: ', function ($answer) use ($userRepository) {
            if (!filter_var($answer, FILTER_VALIDATE_EMAIL)) {
                throw new \RuntimeException('This is not a valid email address.');
            }
            if (null !== $userRepository->findOneBy(['email' => $answer])) {
                throw new \RuntimeException('This email address is already used.');
            }
            return $answer;
        }, 3);

        $password = $dialog->askAndValidate($output, 'Password: ', function ($answer) {
            if (!(preg_match('#^[a-zA-Z0-9]+$#', $answer) && strlen($answer) > 5)) {
                throw new \RuntimeException('Password should be composed of at least 6 letters and numbers.');
            }
            return $answer;
        }, 3);

        $notBlankValidator = function ($answer) {
            if (0 === strlen($answer)) {
                throw new \RuntimeException('This cannot be blank.');
            }
            return $answer;
        };

        $firstName = $dialog->askAndValidate($output, 'First name: ', $notBlankValidator, 3);
        $lastName = $dialog->askAndValidate($output, 'Last name: ', $notBlankValidator, 3);

        $userManager = $this->container->get('fos_user.user_manager');
        /** @var \Ekyna\Bundle\UserBundle\Model\UserInterface $user */
        $user = $userManager->createUser();
        $user
            ->setGroup($group)
            ->setGender('mr')
            ->setFirstName($firstName)
            ->setLastName($lastName)
            ->setPlainPassword($password)
            ->setEmail($email)
            ->setEnabled(true);
        $userManager->updateUser($user);

        $output->writeln('Super Admin has been successfully created.');
    }
private function createSuperAdmin ( Command $ command , OutputInterface $ output ) { $ groupRepository = $ this -> container -> get ( 'ekyna_user.group.repository' ) ; $ userRepository = $ this -> container -> get ( 'ekyna_user.user.repository' ) ; /** @var \Ekyna\Bundle\UserBundle\Model\GroupInterface $group */ if ( null === $ group = $ groupRepository -> findOneBy ( [ 'name' => array_keys ( $ this -> defaultGroups ) [ 0 ] ] ) ) { $ output -> writeln ( 'Super admin group not found, aborting.' ) ; return ; } /** @var \Ekyna\Bundle\UserBundle\Model\UserInterface $superAdmin */ if ( null !== $ superAdmin = $ userRepository -> findOneBy ( [ 'group' => $ group ] ) ) { $ output -> writeln ( sprintf ( 'Super admin already exists (<comment>%s</comment>).' , $ superAdmin -> getEmail ( ) ) ) ; return ; } $ output -> writeln ( '<question>Please provide initial informations ...</question>' ) ; /** @var \Symfony\Component\Console\Helper\DialogHelper $dialog */ $ dialog = $ command -> getHelperSet ( ) -> get ( 'dialog' ) ; $ email = $ dialog -> askAndValidate ( $ output , 'Email: ' , function ( $ answer ) use ( $ userRepository ) { if ( ! filter_var ( $ answer , FILTER_VALIDATE_EMAIL ) ) { throw new \ RuntimeException ( 'This is not a valid email address.' ) ; } if ( null !== $ userRepository -> findOneBy ( [ 'email' => $ answer ] ) ) { throw new \ RuntimeException ( 'This email address is already used.' ) ; } return $ answer ; } , 3 ) ; $ password = $ dialog -> askAndValidate ( $ output , 'Password: ' , function ( $ answer ) { if ( ! ( preg_match ( '#^[a-zA-Z0-9]+$#' , $ answer ) && strlen ( $ answer ) > 5 ) ) { throw new \ RuntimeException ( 'Password should be composed of at least 6 letters and numbers.' ) ; } return $ answer ; } , 3 ) ; $ notBlankValidator = function ( $ answer ) { if ( 0 === strlen ( $ answer ) ) { throw new \ RuntimeException ( 'This cannot be blank.' ) ; } return $ answer ; } ; $ firstName = $ dialog -> askAndValidate ( $ output , 'First name: ' , $ notBlankValidator , 3 ) ; $ lastName = $ dialog -> askAndValidate ( $ output , 'Last name: ' , $ notBlankValidator , 3 ) ; $ userManager = $ this -> container -> get ( 'fos_user.user_manager' ) ; /** @var \Ekyna\Bundle\UserBundle\Model\UserInterface $user */ $ user = $ userManager -> createUser ( ) ; $ user -> setGroup ( $ group ) -> setGender ( 'mr' ) -> setFirstName ( $ firstName ) -> setLastName ( $ lastName ) -> setPlainPassword ( $ password ) -> setEmail ( $ email ) -> setEnabled ( true ) ; $ userManager -> updateUser ( $ user ) ; $ output -> writeln ( 'Super Admin has been successfully created.' ) ; }
Creates the super admin user.

@param Command $command
@param OutputInterface $output
Creates the super admin user .