/**
  * @param UserImporter $userImporter
  */
 public function importArticleSubmitter($userImporter)
 {
     $this->consoleOutput->writeln("Importing article submitters...");
     $result = $this->em->getRepository(PendingSubmitterImport::class)->createQueryBuilder('import')->select('import.id')->getQuery()->getScalarResult();
     $ids = array_column($result, 'id');
     $counter = 0;
     foreach ($ids as $id) {
         $import = $this->em->find(PendingSubmitterImport::class, $id);
         if (!$import || !$import->getArticle()) {
             continue;
         }
         $user = $userImporter->importUser($import->getOldId());
         if ($user) {
             try {
                 /** @var Article $article */
                 $article = $import->getArticle();
                 $article->setSubmitterUser($user);
                 $this->em->persist($article);
             } catch (EntityNotFoundException $e) {
                 $this->consoleOutput->writeln("Article not found, skipping #" . $import->getId());
                 continue;
             }
         }
         $this->em->remove($import);
         $counter++;
         if ($counter % 10 == 0) {
             $this->em->flush();
             $this->em->clear();
         }
     }
     $this->em->flush();
 }
 public function importBoardMember($oldUserId, $seq, $newBoardId)
 {
     $user = $this->ui->importUser($oldUserId);
     $board = $this->em->getReference('OjsJournalBundle:Board', $newBoardId);
     $member = new BoardMember();
     $member->setUser($user)->setBoard($board)->setSeq($seq);
     return $member;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     parent::execute($input, $output);
     $id = $input->getArgument('id');
     $um = $this->getContainer()->get('fos_user.user_manager');
     $tokenGenrator = $this->getContainer()->get('fos_user.util.token_generator');
     $locale = $this->getContainer()->getParameter('locale');
     $importer = new UserImporter($this->connection, $this->em, $this->logger, $output, $um, $tokenGenrator, $locale);
     $importer->importUser($id);
 }
 /**
  * Imports users of the given journal
  * @param int $newJournalId New journal's ID
  * @param int $oldJournalId Old journal's ID
  * @param UserImporter $userImporter User importer class
  * @throws \Doctrine\DBAL\DBALException
  */
 public function importJournalUsers($newJournalId, $oldJournalId, $userImporter)
 {
     $this->em->clear();
     $journal = $this->em->getRepository('OjsJournalBundle:Journal')->find($newJournalId);
     $roleMap = ['1' => "ROLE_ADMIN", '2' => "ROLE_USER", '10' => "ROLE_JOURNAL_MANAGER", '100' => "ROLE_EDITOR", '200' => 'ROLE_SECTION_EDITOR', '300' => 'ROLE_LAYOUT_EDITOR', '1000' => "ROLE_REVIEWER", '2000' => 'ROLE_COPYEDITOR', '3000' => "ROLE_PROOFREADER", '10000' => "ROLE_AUTHOR", '100000' => 'ROLE_READER', '200000' => "ROLE_SUBSCRIPTION_MANAGER"];
     // Replace role names with role entities
     foreach ($roleMap as $id => $name) {
         $role = $this->em->getRepository('OjsUserBundle:Role')->findOneBy(['role' => $name]);
         if (!$role) {
             $role = new Role();
             $role->setName($name);
             $role->setRole($name);
         }
         $roleMap[$id] = $role;
     }
     $roleStatement = $this->dbalConnection->prepare("SELECT roles.journal_id, roles.user_id, roles.role_id, users.email FROM " . "roles JOIN users ON roles.user_id = users.user_id WHERE roles.journal_id" . "= :id " . ImportHelper::spamUsersFilterSql());
     $roleStatement->bindValue('id', $oldJournalId);
     $roleStatement->execute();
     $roles = $roleStatement->fetchAll();
     $cache = array();
     foreach ($roles as $role) {
         $email = $role['email'];
         // Put the user from DB to cache
         if (empty($cache[$email]['user'])) {
             $cache[$email]['user'] = $this->em->getRepository('OjsUserBundle:User')->findOneBy(['email' => $email]);
         }
         // Create the user and put it to cache
         if (empty($cache[$email]['user'])) {
             $cache[$email]['user'] = $userImporter->importUser($role['user_id'], false);
         }
         /** @var JournalUser $journalUser */
         $journalUser = $this->getJournalUser($cache, $email, $journal);
         $journalUser->addRole($roleMap[dechex($role['role_id'])]);
     }
     $this->consoleOutput->writeln("Writing data...");
     $this->em->flush();
     $this->consoleOutput->writeln("Imported users.");
 }