Пример #1
0
 /**
  * @return User
  */
 public static function createAdminUser()
 {
     $user = new User();
     $user->setFullName('Admin ADMIN');
     $user->setLogin('admin');
     $user->setMail('*****@*****.**');
     $user->setIsAdmin(true);
     $user->setAvatar('admin.png');
     $user->testingContext = true;
     $reflection = new \ReflectionObject($user);
     $property = $reflection->getProperty('id');
     $property->setAccessible(true);
     $property->setValue($user, 1);
     return $user;
 }
Пример #2
0
 /**
  * @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");
 }
Пример #3
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $admin = new User();
     $admin->setFullName('Admin ADMIN');
     $admin->setLogin('admin');
     $admin->setMail('*****@*****.**');
     $admin->setIsAdmin(true);
     $admin->setAvatar('admin.png');
     $admin->setBirthday(new \DateTime());
     $admin->setLastVisitHome(new \DateTime());
     $admin->setReadOnlyExpirationDate(new \DateTime());
     $user = new User();
     $user->setFullName('User USER');
     $user->setLogin('user');
     $user->setMail('*****@*****.**');
     $user->setIsAdmin(false);
     $user->setAvatar('user.png');
     $user->setBirthday(new \DateTime());
     $user->setLastVisitHome(new \DateTime());
     $user->setReadOnlyExpirationDate(new \DateTime());
     $orga = new Organization();
     $orga->setName('Orga ORGA');
     $orga->setLogin('orga');
     $orga->setContactMail('*****@*****.**');
     $manager->persist($admin);
     $manager->persist($user);
     $manager->persist($orga);
     $membership = new Member();
     $membership->setOrganization($orga);
     $membership->setUser($user);
     $membership->addPermission('daymail');
     $manager->persist($membership);
     $manager->flush();
     $this->addReference('user_admin', $admin);
     $this->addReference('user_user', $user);
     $this->addReference('user_orga', $orga);
     $this->addReference('user_membership', $orga);
 }
Пример #4
0
 /**
  * @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");
 }