コード例 #1
0
 protected function import(InputInterface $input, OutputInterface $output, $agency_to_import)
 {
     // Getting php array of data from CSV
     $data = $this->get($input, $output, $agency_to_import);
     // Getting doctrine manager
     $em = $this->getContainer()->get('doctrine')->getManager();
     // Turning off doctrine default logs queries for saving memory
     $em->getConnection()->getConfiguration()->setSQLLogger(null);
     // Define the size of record, the frequency for persisting the data and the current index of records
     $size = count($data);
     $batchSize = 20;
     $i = 1;
     // Starting progress
     $progress = new ProgressBar($output, $size);
     $progress->start();
     // Processing on each row of data
     foreach ($data as $row) {
         //Create new collaborator, find his agency, format his birth date
         $collaborator = new Collaborator();
         $birthDate = \DateTime::createFromFormat('d/m/Y', $row['Date_Naissance']);
         $agency = $em->getRepository('CharlestownAgencyBundle:Agency')->find($row['group_name']);
         //Update is infos
         $collaborator->setUsername($row['users_login']);
         $collaborator->setPlainPassword($row['password']);
         $collaborator->setEmail($row['users_email']);
         $collaborator->setLastName($row['users_surname']);
         $collaborator->setFirstName($row['users_name']);
         $collaborator->setEnabled($row['active']);
         $collaborator->setAgency($agency);
         $collaborator->setAddress($row['adresse']);
         $collaborator->setPc($row['code_postal']);
         $collaborator->setTown($row['ville']);
         $collaborator->setPortPhoneNumber($row['portable']);
         $collaborator->setPhoneNumber($row['telephone']);
         $collaborator->setBirthDate($birthDate);
         // Do stuff here !
         // Persisting the current user
         $em->persist($collaborator);
         // Each 20 users persisted we flush everything
         if ($i % $batchSize === 0) {
             $em->flush();
             // Detaches all objects from Doctrine for memory save
             $em->clear();
             // Advancing for progress display on console
             $progress->advance($batchSize);
             $now = new \DateTime();
             $output->writeln(' of users imported ... | ' . $now->format('d-m-Y G:i:s'));
         }
         $i++;
     }
     // Flushing and clear data on queue
     $em->flush();
     $em->clear();
     // Ending the progress bar process
     $progress->finish();
 }
コード例 #2
0
 protected function import(InputInterface $input, OutputInterface $output)
 {
     // Getting php array of data from CSV
     $data = $this->get($input, $output);
     // Getting doctrine manager
     $em = $this->getContainer()->get('doctrine')->getManager();
     // Turning off doctrine default logs queries for saving memory
     $em->getConnection()->getConfiguration()->setSQLLogger(null);
     // Define the size of record, the frequency for persisting the data and the current index of records
     $size = count($data);
     $batchSize = 10;
     $i = 1;
     // Starting progress
     $progress = new ProgressBar($output, $size);
     $progress->start();
     // Processing on each row of data
     foreach ($data as $row) {
         //Create new collaborator, find his agency
         $collaborator = new Collaborator();
         $agency = $em->getRepository('CharlestownAgencyBundle:Agency')->find($row['code_agence']);
         //Update is infos
         $collaborator->setUsername($row['id']);
         $collaborator->setPlainPassword($row['password']);
         $collaborator->setAgency($agency);
         $collaborator->setEmail($row['mail']);
         $collaborator->setLastName($row['nom']);
         $collaborator->setFirstName($row['prenom']);
         $collaborator->setPortPhoneNumber($row['portable']);
         $collaborator->setPhoneNumber($row['fixe']);
         $collaborator->addRole('ROLE_USER');
         $collaborator->addRole('ROLE_ADMIN');
         $collaborator->addRole('ROLE_AE');
         $collaborator->addRole('ROLE_EVENT');
         $collaborator->setEnabled(true);
         // Persisting the current user
         $em->persist($collaborator);
         // Each 20 users persisted we flush everything
         if ($i % $batchSize === 0) {
             $em->flush();
             // Detaches all objects from Doctrine for memory save
             $em->clear();
             // Advancing for progress display on console
             $progress->advance($batchSize);
             $now = new \DateTime();
             $output->writeln(' of admins imported ... | ' . $now->format('d-m-Y G:i:s'));
         }
         $i++;
     }
     // Flushing and clear data on queue
     $em->flush();
     $em->clear();
     // Ending the progress bar process
     $progress->finish();
 }
コード例 #3
0
 protected function import(InputInterface $input, OutputInterface $output, $type)
 {
     $output->writeln($type . ' is starting....');
     // Getting php array of data from CSV
     $data = $this->get($input, $output, $type);
     // Getting doctrine manager
     $em = $this->getContainer()->get('doctrine')->getManager();
     // Turning off doctrine default logs queries for saving memory
     $em->getConnection()->getConfiguration()->setSQLLogger(null);
     // Define the size of record, the frequency for persisting the data and the current index of records
     $size = count($data);
     $batchSize = 20;
     $i = 1;
     if ($type == "collaborator" || $type == "collaborator-test") {
         $user_repository = $em->getRepository("CharlestownCollaboratorBundle:Collaborator");
         $collaborators = $user_repository->findAE();
         if (!empty($collaborators)) {
             foreach ($collaborators as $collaborator) {
                 if (!$collaborator->hasRole('ROLE_ADMIN') && $type != "  ") {
                     $collaborator->setEnabled(false);
                     $em->persist($collaborator);
                 }
             }
         }
         $em->flush();
         foreach ($data as $row) {
             if ($row['users_login']) {
                 $user = $user_repository->findOneBy(array('email' => $row['users_email']));
                 if (!$user instanceof Collaborator) {
                     $user = $user_repository->findOneBy(array('username' => $row['users_login']));
                 }
                 if ($user instanceof Collaborator) {
                     $birthDate = \DateTime::createFromFormat('d/m/Y', $row['Date_Naissance']);
                     $agency = $em->getRepository('CharlestownAgencyBundle:Agency')->find($this->getAgencyCorrespondance($row['group_name']));
                     //Update is infos
                     if ($row['users_email'] != $user->getEmail()) {
                         $user->setEmail($row['users_email']);
                     }
                     $user->setLastName($row['users_surname']);
                     $user->setFirstName($row['users_name']);
                     $user->setEnabled($row['active']);
                     $user->setAgency($agency);
                     $user->setAddress($row['adresse']);
                     $user->setPc($row['code_postal']);
                     $user->setTown($row['ville']);
                     $user->setPortPhoneNumber($row['portable']);
                     $user->setPhoneNumber($row['telephone']);
                     $user->setBirthDate($birthDate);
                     $user->setEnabled(true);
                 } else {
                     $user = new Collaborator();
                     $birthDate = \DateTime::createFromFormat('d/m/Y', $row['Date_Naissance']);
                     $agency = $em->getRepository('CharlestownAgencyBundle:Agency')->find($row['group_name']);
                     //Update is infos
                     $user->setUsername($row['users_login']);
                     $user->setPlainPassword($row['password']);
                     $user->setEmail($row['users_email']);
                     $user->setLastName($row['users_surname']);
                     $user->setFirstName($row['users_name']);
                     $user->setEnabled($row['active']);
                     $user->setAgency($agency);
                     $user->setAddress($row['adresse']);
                     $user->setPc($row['code_postal']);
                     $user->setTown($row['ville']);
                     $user->setPortPhoneNumber($row['portable']);
                     $user->setPhoneNumber($row['telephone']);
                     $user->setBirthDate($birthDate);
                     try {
                         $this->getContainer()->get('charlestown.mailer')->sendCollaboratorId($row['users_login'], $row['password'], $row['users_email'], $row['users_name'], $row['users_surname']);
                     } catch (Exception $e) {
                         $output->writeln($e->getMessage());
                     }
                 }
                 $em->persist($user);
                 // Each 20 users persisted we flush everything
                 if ($i % $batchSize === 0) {
                     $em->flush();
                     // Detaches all objects from Doctrine for memory save
                     $em->clear();
                 }
                 $birthDate = $birthDate->format('d-m');
                 $today = new \DateTime('today');
                 $today = $today->format('d-m');
                 if ($birthDate == $today) {
                     $this->getContainer()->get('charlestown.mailer')->sendCollaboratorBirthdayCard($row['users_email'], $row['users_name']);
                 }
                 $i++;
             }
         }
     } elseif ($type == "customer" || $type == "customer-test") {
         foreach ($data as $row) {
             if ($row['client_matricule']) {
                 $customer = $em->getRepository("CharlestownCustomerBundle:Customer")->findBy(array('email' => $row['email_contact']));
                 $customerBis = $em->getRepository("CharlestownCustomerBundle:Customer")->findBy(array('username' => $row['client_matricule']));
                 if ($customer == null && $customerBis == null) {
                     $customer = new Customer();
                     $agency = $em->getRepository('CharlestownAgencyBundle:Agency')->find($row['numero_agence']);
                     $pw = "charlestown";
                     $customer->setAgency($agency);
                     $customer->setEmail($row['email_contact']);
                     $customer->setUsername($row['client_matricule']);
                     $customer->setPlainPassword($pw);
                     $customer->setCompanyName($row['raison_sociale']);
                     $customer->addRole('ROLE_CUSTOMER');
                     $em->persist($customer);
                     try {
                         if ($type == "customer-test") {
                             $this->getContainer()->get('charlestown.mailer')->sendCustomerId($row['client_matricule'], $pw, $row['email_contact'], $row['raison_sociale'], $agency, true);
                         } else {
                             $this->getContainer()->get('charlestown.mailer')->sendCustomerId($row['client_matricule'], $pw, $row['email_contact'], $row['raison_sociale'], $agency, false);
                         }
                     } catch (Exception $e) {
                         $output->writeln("LALA " . $e->getMessage());
                     }
                 }
                 $em->flush();
             }
         }
     }
     //we flush the end
     $em->flush();
 }
コード例 #4
0
 /**
  * @Route("/importK2", name="import")
  * @Template()
  */
 public function importAction()
 {
     $converter = $this->getContainer()->get('import.csvtoarray');
     $em = $this->getDoctrine()->getManager();
     //Import collaborator
     $fileName = 'web/uploads/csv/Charles_users.csv';
     $data = $converter->convert($fileName, ';');
     //Import customer
     $fileNameCustomer = 'web/uploads/csv/Charles_users.csv';
     $dataCustomer = $converter->convert($fileNameCustomer, ';');
     $user_repository = $em->getRepository("CharlestownCollaboratorBundle:Collaborator");
     $collaborators = $user_repository->findAE();
     //Disable all AE collaborators
     if (!empty($collaborators)) {
         foreach ($collaborators as $collaborator) {
             if (!$collaborator->hasRole('ROLE_ADMIN')) {
                 $collaborator->setEnabled(false);
                 $em->persist($collaborator);
             }
         }
     }
     //Flush them
     $em->flush();
     //Update all AE working for Charlestown ATM
     if (!empty($data)) {
         foreach ($data as $row) {
             if ($row['users_login']) {
                 $user = $user_repository->findOneBy(array('username' => $row['users_login']));
                 if ($user instanceof Collaborator) {
                     $birthDate = \DateTime::createFromFormat('d/m/Y', $row['Date_Naissance']);
                     $agency = $em->getRepository('CharlestownAgencyBundle:Agency')->find($row['group_name']);
                     //Update is infos
                     if ($row['users_email'] != $user->getEmail()) {
                         $user->setEmail($row['users_email']);
                     }
                     $user->setLastName($row['users_surname']);
                     $user->setFirstName($row['users_name']);
                     $user->setEnabled($row['active']);
                     $user->setAgency($agency);
                     $user->setAddress($row['adresse']);
                     $user->setPc($row['code_postal']);
                     $user->setTown($row['ville']);
                     $user->setPortPhoneNumber($row['portable']);
                     $user->setPhoneNumber($row['telephone']);
                     $user->setBirthDate($birthDate);
                     $user->setEnabled(true);
                 } else {
                     $user = new Collaborator();
                     $birthDate = \DateTime::createFromFormat('d/m/Y', $row['Date_Naissance']);
                     $agency = $em->getRepository('CharlestownAgencyBundle:Agency')->find($row['group_name']);
                     //Update is infos
                     $user->setUsername($row['users_login']);
                     $user->setPlainPassword($row['password']);
                     $user->setEmail($row['users_email']);
                     $user->setLastName($row['users_surname']);
                     $user->setFirstName($row['users_name']);
                     $user->setEnabled($row['active']);
                     $user->setAgency($agency);
                     $user->setAddress($row['adresse']);
                     $user->setPc($row['code_postal']);
                     $user->setTown($row['ville']);
                     $user->setPortPhoneNumber($row['portable']);
                     $user->setPhoneNumber($row['telephone']);
                     $user->setBirthDate($birthDate);
                     $this->getContainer()->get('charlestown.mailer')->sendCollaboratorId($row['users_login'], $row['password'], $row['users_email'], $row['users_name'], $row['users_surname']);
                 }
                 $em->persist($user);
                 $em->flush();
                 $em->clear();
             }
             $birthDate = $birthDate->format('d-m');
             $today = new \DateTime('today');
             $today = $today->format('d-m');
             if ($birthDate == $today) {
                 $this->getContainer()->get('charlestown.mailer')->sendCollaboratorBirthdayCard($row['users_email'], $row['users_name']);
             }
         }
     }
     //Update all Customer of Charlestown
     if (!empty($dataCustomer)) {
         foreach ($dataCustomer as $row) {
             if ($row['client_matricule']) {
                 $customer = $em->getRepository("CharlestownCustomerBundle:Customer")->findBy(array('email' => $row['email_contact']));
                 $customerBis = $em->getRepository("CharlestownCustomerBundle:Customer")->findBy(array('username' => $row['client_matricule']));
                 if ($customer == null && $customerBis == null) {
                     $customer = new Customer();
                     $agency = $em->getRepository('CharlestownAgencyBundle:Agency')->find($row['numero_agence']);
                     $pw = "charlestown";
                     $customer->setAgency($agency);
                     $customer->setEmail($row['email_contact']);
                     $customer->setUsername($row['client_matricule']);
                     $customer->setPlainPassword($pw);
                     $customer->setCompanyName($row['raison_sociale']);
                     $customer->addRole('ROLE_CUSTOMER');
                     $em->persist($customer);
                     $this->getContainer()->get('charlestown.mailer')->sendCustomerId($row['client_matricule'], $pw, $row['email_contact'], $row['raison_sociale'], $agency, false);
                 }
                 $em->flush();
             }
         }
     }
     return array();
 }