Beispiel #1
0
 public function createTestFixtures()
 {
     $env = $this->container->getParameter("kernel.environment");
     if ($env == 'test') {
         $this->runSqlScript('Country.sql');
         $this->runSqlScript('State.sql');
         $this->runSqlScript('PostalCode.sql');
         $this->runSqlScript('Role.sql');
         $factory = $this->get('security.encoder_factory');
         $encoder = $factory->getEncoder(new Actor());
         //User admin
         $password = '******';
         $user = new Actor();
         $user->setUsername('admin');
         $user->setEmail('*****@*****.**');
         $user->addRole($this->getManager()->getRepository('CoreBundle:Role')->findOneByRole(Role::ADMIN));
         $encodePassword = $encoder->encodePassword($password, $user->getSalt());
         $user->setPassword($encodePassword);
         $user->setName('Admin 1');
         $user->setSurnames('Surnames Admin');
         $user->setNewsletter(true);
         $this->getManager()->persist($user);
         $this->getManager()->flush();
     }
 }
 public function load($line, $lineNo)
 {
     //        print_r($line);die();
     if ($lineNo != 1) {
         $email = trim($line[0]);
         $names = trim($line[1]);
         $postalCode = trim($line[2]);
         //names
         if (count(explode(' ', $names)) > 1) {
             if (count($arr = explode(' ', $names)) == 2) {
                 $firstname = $arr[0];
                 $lastname = $arr[1];
             } elseif (count($arr = explode(' ', $names)) == 3) {
                 $firstname = $arr[0];
                 $lastname = $arr[1] . ' ' . $arr[2];
             } elseif (count($arr = explode(' ', $names)) == 4) {
                 $firstname = $arr[0] . ' ' . $arr[1];
                 $lastname = $arr[2] . ' ' . $arr[3];
             }
         } else {
             $firstname = $names;
             $lastname = '';
         }
         $actor = $this->manager->getRepository('CoreBundle:Actor')->findOneByEmail($email);
         if (!$actor instanceof Actor) {
             $optic = $this->manager->getRepository('CoreBundle:Optic')->findOneByEmail($email);
             if (!$optic instanceof Optic) {
                 //create new user
                 $this->output->writeln('<error>Actor or Optic  ' . $email . '  does not exist, proced to created(actor) and swith on newsletter notification.</error>');
                 $actor = new Actor();
                 $actor->setUsername($email);
                 $actor->setEmail($email);
                 $actor->setPassword($email);
                 $actor->setName($firstname);
                 $actor->setSurnames($lastname);
                 $actor->setIsActive(true);
                 $actor->setNewsletter(true);
                 try {
                     $this->manager->persist($actor);
                     $this->manager->flush();
                 } catch (\Exception $ex) {
                     $this->output->writeln('<error>' . $ex->getMessage() . '</error>');
                 }
             } else {
                 //active newsletter
                 $this->output->writeln('<comment>Optic ' . $email . ' already exist and have been swith on newsletter notification .</comment>');
                 $optic->setNewsletter(true);
                 $this->manager->flush();
             }
         } else {
             //active newsletter
             $this->output->writeln('<comment>Actor ' . $email . ' already exist and have been swith on newsletter notification .</comment>');
             $actor->setNewsletter(true);
             $this->manager->flush();
         }
     }
 }