/** * Imports all journals on the database * @throws \Doctrine\DBAL\DBALException */ public function importJournals() { $journalsSql = "SELECT journal_id, path FROM journals"; $journalsStatement = $this->dbalConnection->prepare($journalsSql); $journalsStatement->execute(); $journals = $journalsStatement->fetchAll(); foreach ($journals as $journal) { $existingJournal = $this->em->getRepository('OjsJournalBundle:Journal')->findOneBy(['slug' => $journal['path']]); if (!$existingJournal) { $journalImporter = new JournalImporter($this->dbalConnection, $this->em, $this->logger, $this->consoleOutput, $this->ui); try { $ids = $journalImporter->importJournal($journal['journal_id']); $journalUserImporter = new JournalUserImporter($this->dbalConnection, $this->em, $this->logger, $this->consoleOutput); $journalUserImporter->importJournalUsers($ids['new'], $ids['old'], $this->ui); } catch (Exception $exception) { $message = sprintf('%s: %s (uncaught exception) at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()); $this->consoleOutput->writeln('Importing of journal #' . $journal['journal_id'] . ' failed.'); $this->consoleOutput->writeln($message); $this->consoleOutput->writeln($exception->getTraceAsString()); } } else { $this->consoleOutput->writeln('Journal #' . $journal['journal_id'] . ' already imported. Skipped.'); } } }
protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $userManager = $this->getContainer()->get('fos_user.user_manager'); $locale = $this->getContainer()->getParameter('locale'); $tokenGenrator = $this->getContainer()->get('fos_user.util.token_generator'); $userImporter = new UserImporter($this->connection, $this->em, $this->logger, $output, $userManager, $tokenGenrator, $locale); $stopwatch = new Stopwatch(); $stopwatch->start('journal_import'); $journalImporter = new JournalImporter($this->connection, $this->em, $this->logger, $output, $userImporter); $ids = $journalImporter->importJournal($input->getArgument('id')); $journalUserImporter = new JournalUserImporter($this->connection, $this->em, $this->logger, $output); $journalUserImporter->importJournalUsers($ids['new'], $ids['old'], $userImporter); $event = $stopwatch->stop('journal_import'); $output->writeln('Duration: ' . StringHelper::formatMilliseconds($event->getDuration())); }