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();
         }
     }
 }
Beispiel #3
0
 public function createFixtures()
 {
     $core = $this->container->getParameter('core');
     $factory = $this->get('security.encoder_factory');
     $encoder = $factory->getEncoder(new Actor());
     $this->runSqlScript('Country.sql');
     $this->runSqlScript('State.sql');
     $this->runSqlScript('PostalCode.sql');
     //Roles
     $userRole = new Role();
     $userRole->setName('user');
     $userRole->setRole(Role::USER);
     $this->getManager()->persist($userRole);
     $companyRole = new Role();
     $companyRole->setName('company');
     $companyRole->setRole(Role::COMPANY);
     $this->getManager()->persist($companyRole);
     $adminRole = new Role();
     $adminRole->setName('admin');
     $adminRole->setRole(Role::ADMIN);
     $this->getManager()->persist($adminRole);
     $superRole = new Role();
     $superRole->setName('root');
     $superRole->setRole(Role::SUPER_ADMIN);
     $this->getManager()->persist($superRole);
     $this->getManager()->flush();
     //User admin
     $password = '******';
     $admin = new Actor();
     $admin->setUsername('admin');
     $admin->setEmail('*****@*****.**');
     $admin->addRole($adminRole);
     $encodePassword = $encoder->encodePassword($password, $admin->getSalt());
     $admin->setPassword($encodePassword);
     $admin->setName('Admin');
     $admin->setSurnames('Lastname');
     $this->getManager()->persist($admin);
     $password = '******';
     $user = new Actor();
     $user->setUsername('user');
     $user->setEmail('*****@*****.**');
     $user->addRole($userRole);
     $encodePassword = $encoder->encodePassword($password, $user->getSalt());
     $user->setPassword($encodePassword);
     $user->setName('User');
     $user->setSurnames('Lastname');
     $this->getManager()->persist($user);
     $password2 = 'user2';
     $user2 = new Actor();
     $user2->setUsername('user2');
     $user2->setEmail('*****@*****.**');
     $user2->addRole($userRole);
     $encodePassword2 = $encoder->encodePassword($password2, $user2->getSalt());
     $user2->setPassword($encodePassword2);
     $user2->setName('User2');
     $user2->setSurnames('Lastname2');
     $this->getManager()->persist($user2);
     $this->getManager()->flush();
     //copy profile imges
     //self::recurseCopy(__DIR__.'/images', __DIR__.'/../../../../../../web/uploads/images/');
     //self::recurseCopy(__DIR__.'/images/profile', __DIR__.'/../../../../../../web/uploads/images/profile');
     //self::recurseCopy(__DIR__.'/images/product', __DIR__.'/../../../../../../web/uploads/images/product');
     //slider
     //$this->createSliderFixtures();
 }