/** * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * @return void * @throws \RuntimeException */ protected function execute(InputInterface $input, OutputInterface $output) { $dialog = $this->getHelperSet()->get('dialog'); /** @var EntityManager $em */ $em = $this->getContainer()->get('doctrine')->getManager(); $login = $input->getOption('login') !== null ? $input->getOption('login') : $dialog->ask($output, 'Login: '******'firstName') !== null ? $input->getOption('firstName') : $dialog->ask($output, 'First name: '); $lastName = $input->getOption('lastName') !== null ? $input->getOption('lastName') : $dialog->ask($output, 'Last name: '); $password = $input->getOption('password') !== null ? $input->getOption('password') : $dialog->ask($output, 'Password: '******'email') !== null ? $input->getOption('email') : $dialog->ask($output, 'Public e-mail: '); $user = new User(); $user->setKeepActive(true); $user->setLogin($login); $user->setFirstName($firstName); $user->setLastName($lastName); $user->setFullName($user->getFirstName() . ' ' . $user->getLastName()); $user->setPassword($this->getContainer()->get('etu.user.crypting')->encrypt($password)); $user->setMail($email); $em->persist($user); $em->flush(); $output->writeln("\nDone.\n"); }
/** * Keep the user in the database and set a password for external connexion */ public function keep($encryptedPassword) { $this->element->setPassword($encryptedPassword); $this->element->setKeepActive(true); $this->doctrine->getManager()->persist($this->element); }
/** * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * @return void * @throws \RuntimeException */ protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln("\nConnecting to database ..."); $output->writeln('----------------------------------------'); $dialog = $this->getHelperSet()->get('dialog'); $host = $dialog->ask($output, 'Host: '); $name = $dialog->ask($output, 'Name: '); $user = $dialog->ask($output, 'User: '******'Pass: '******'mysql:host=' . $host . ';dbname=' . $name, $user, $pass); $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $output->writeln("\nFinding users differences ..."); $output->writeln('----------------------------------------'); /** @var EntityManager $em */ $em = $this->getContainer()->get('doctrine')->getManager(); /* * Imported */ $imported = $pdo->query('SELECT * FROM admis')->fetchAll(\PDO::FETCH_OBJ); $importedLogins = []; $importedRegistry = []; foreach ($imported as $import) { $importedRegistry[$import->login] = $import; $importedLogins[] = $import->login; } /* * Database */ $qb = $em->createQueryBuilder(); $dbUsers = $qb->select('u.login')->from('EtuUserBundle:User', 'u')->where($qb->expr()->in('u.login', $importedLogins))->getQuery()->getArrayResult(); $dbLogins = []; foreach ($dbUsers as $dbUser) { $dbLogins[] = $dbUser['login']; } $toImport = array_diff($importedLogins, $dbLogins); $output->writeln(sprintf('%s users to import', count($toImport))); $output->writeln("\nImporting users ..."); if (count($toImport) > 0) { $bar = new ProgressBar('%fraction% [%bar%] %percent%', '=>', ' ', 80, count($toImport)); $bar->update(0); $i = 1; foreach ($toImport as $loginToImport) { $import = $importedRegistry[$loginToImport]; $user = new User(); $user->setLogin($import->login); $user->setPassword($this->getContainer()->get('etu.user.crypting')->encrypt($import->password)); $user->setFullName($import->prenom . ' ' . $import->nom); $user->setSex($import->sexe == 'M' ? User::SEX_MALE : User::SEX_FEMALE); $user->setSexPrivacy(User::PRIVACY_PRIVATE); $user->setCity(ucfirst(strtolower($import->ville))); $user->setCityPrivacy(User::PRIVACY_PRIVATE); $user->setPostalCode($import->codePostal); $user->setPostalCodePrivacy(User::PRIVACY_PRIVATE); $user->setCountry(ucfirst(strtolower($import->pays))); $user->setCountryPrivacy(User::PRIVACY_PRIVATE); $user->setPersonnalMail($import->email); $user->setPersonnalMailPrivacy(User::PRIVACY_PRIVATE); $user->setBranch($import->branche); $user->setFiliere($import->specialite); $user->setNiveau(intval($import->niveau)); $user->setFormation('Inconnue'); $user->setLanguage('fr'); $user->setKeepActive(false); $em->persist($user); $em->flush(); $bar->update($i); $i++; } } $output->write("\nDone\n"); }