protected function execute(InputInterface $input, OutputInterface $output)
 {
     parent::execute($input, $output);
     $importer = new ArticleStatisticImporter($this->connection, $this->em, $this->logger, $output);
     $stopwatch = new Stopwatch();
     $stopwatch->start('stats_import');
     $importer->importArticleStatistics();
     $event = $stopwatch->stop('stats_import');
     $output->writeln('Duration: ' . StringHelper::formatMilliseconds($event->getDuration()));
 }
 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('journals_import');
     $givenJournalsImporter = new GivenJournalsImporter($this->connection, $this->em, $this->logger, $output, $userImporter);
     $givenJournalsImporter->importJournals($input->getArgument('ids'));
     $event = $stopwatch->stop('journals_import');
     $output->writeln('Duration: ' . StringHelper::formatMilliseconds($event->getDuration()));
 }
Пример #3
0
 /**
  * Creates a new AdminFileentity.
  *
  * @param  Request                                                                                       $request
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function createAction(Request $request)
 {
     $entity = new AdminFile();
     $form = $this->createCreateForm($entity);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $rootDir = $this->getParameter('kernel.root_dir');
         $path = $rootDir . '/../web/uploads/files/' . $entity->getPath();
         $entity->setSize(StringHelper::formatBytes(filesize($path)));
         $em = $this->getDoctrine()->getManager();
         $em->persist($entity);
         $em->flush();
         $this->successFlashBag('successful.create');
         return $this->redirectToRoute('ojs_admin_file_show', ['id' => $entity->getId()]);
     }
     return $this->render('OjsAdminBundle:AdminFile:new.html.twig', array('entity' => $entity, 'form' => $form->createView()));
 }
Пример #4
0
 /**
  * @return array
  */
 public function getApiKeyParams()
 {
     $qb = $this->em->createQueryBuilder();
     $qb->select('u')->from('OjsUserBundle:User', 'u')->where('u.roles LIKE :roles')->setParameter('roles', '%ROLE_SUPER_ADMIN%')->getQuery()->getResult();
     $getAdminUsers = $qb->getQuery()->getResult();
     if (count($getAdminUsers) < 1) {
         throw new NotFoundHttpException('Create an admin user');
     }
     /** @var User $getAdminUser */
     $getAdminUser = $getAdminUsers[0];
     if (empty($getAdminUser->getApiKey())) {
         $getAdminUser->setApiKey(StringHelper::generateKey());
         $this->em->persist($getAdminUser);
         $this->em->flush();
     }
     return ['apikey' => $getAdminUser->getApiKey()];
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     parent::execute($input, $output);
     $importer = new JournalContactImporter($this->connection, $this->em, $this->logger, $output);
     $journalsSql = 'SELECT journal_id, path FROM journals';
     $journalsStatement = $this->connection->executeQuery($journalsSql);
     $journals = $journalsStatement->fetchAll();
     $stopwatch = new Stopwatch();
     $stopwatch->start('stats_import');
     foreach ($journals as $journal) {
         $existingJournal = $this->em->getRepository('OjsJournalBundle:Journal')->findOneBy(['slug' => $journal['path']]);
         if ($existingJournal !== null && $existingJournal->getJournalContacts()->isEmpty()) {
             $importer->importContacts($existingJournal, $journal['journal_id']);
             $this->em->persist($existingJournal);
             $this->em->flush();
         }
     }
     $event = $stopwatch->stop('stats_import');
     $output->writeln('Duration: ' . StringHelper::formatMilliseconds($event->getDuration()));
 }
Пример #6
0
 /**
  * Creates a new JournalFile entity.
  *
  * @param  Request $request
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function createAction(Request $request)
 {
     $journal = $this->get('ojs.journal_service')->getSelectedJournal();
     if (!$this->isGranted('CREATE', $journal, 'files')) {
         throw new AccessDeniedException("You are not authorized for this file!");
     }
     $entity = new JournalFile();
     $form = $this->createCreateForm($entity);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $rootDir = $this->getParameter('kernel.root_dir');
         $path = $rootDir . '/../web/uploads/files/' . $entity->getPath();
         $entity->setSize(StringHelper::formatBytes(filesize($path)));
         $entity->setJournal($journal);
         $em = $this->getDoctrine()->getManager();
         $em->persist($entity);
         $em->flush();
         $this->successFlashBag('successful.create');
         return $this->redirectToRoute('ojs_journal_filemanager_show', ['id' => $entity->getId(), 'journalId' => $journal->getId()]);
     }
     return $this->render('OjsJournalBundle:JournalFile:new.html.twig', ['entity' => $entity, 'form' => $form->createView()]);
 }
Пример #7
0
 /**
  * Action for the list sets verb
  * @param Request $request
  * @return Response
  */
 public function listSetsAction(Request $request)
 {
     /** @var EntityManager $em */
     $em = $this->getDoctrine()->getManager();
     $slug = $request->get('slug', false);
     $this->throw404IfNotFound($slug);
     $builder = $em->createQueryBuilder();
     $builder->select('section')->from('OjsJournalBundle:Section', 'section');
     $builder->join('section.journal', 'journal', 'WITH');
     $builder->where($builder->expr()->eq('journal.slug', ':slug'))->setParameter('slug', $slug);
     $fileCache = $this->get('file_cache');
     $resumptionToken = $request->get('resumptionToken');
     if ($resumptionToken) {
         $token = $fileCache->fetch($resumptionToken);
         $currentPage = (int) $token['page'];
     } else {
         $currentPage = 1;
     }
     $generatedToken = md5(StringHelper::generateKey());
     $paginator = $this->get('knp_paginator');
     /** @var AbstractPagination $records */
     $records = $paginator->paginate($builder->getQuery(), $currentPage, 100);
     $data = ['records' => $records, 'currentPage' => $currentPage, 'resumptionToken' => $generatedToken, 'isLast' => $records->getTotalItemCount() >= $currentPage * 100];
     return $this->response('OjsOAIBundle:Journal:sets.xml.twig', $data);
 }
Пример #8
0
 /**
  * @param Request $request
  * @return Response
  */
 public function listSetsAction(Request $request)
 {
     $fileCache = $this->get('file_cache');
     $data = [];
     /** @var \Doctrine\ORM\EntityManager $em */
     $em = $this->getDoctrine()->getManager();
     $from = $request->get('from', false);
     $until = $request->get('until', false);
     $qb = $em->createQueryBuilder();
     $qb->select("j")->from("OjsJournalBundle:Journal", 'j');
     $qb->andWhere('j.status = ' . JournalStatuses::STATUS_PUBLISHED);
     if ($from) {
         $_from = new \DateTime();
         $_from->setTimestamp(strtotime($from));
         $qb->where($qb->expr()->gte('j.created', ':from'))->setParameter('from', $_from);
     }
     if ($until) {
         $_until = new \DateTime();
         $_until->setTimestamp(strtotime($until));
         $condition = $qb->expr()->lte('j.created', ':until');
         if ($from) {
             $qb->andWhere($condition);
         } else {
             $qb->where($condition);
         }
         $qb->setParameter('until', $_until);
     }
     $paginator = $this->get('knp_paginator');
     $resumptionToken = $request->get('resumptionToken');
     if ($resumptionToken) {
         $currentPage = (int) $fileCache->fetch($resumptionToken);
     } else {
         $currentPage = 1;
     }
     $sets = $paginator->paginate($qb->getQuery(), $currentPage, 100);
     $data['records'] = $sets;
     $key = md5(StringHelper::generateKey());
     $fileCache->save($key, $currentPage + 1, 60 * 60 * 24);
     $data['resumptionToken'] = $key;
     $data['isLast'] = $sets->getTotalItemCount() >= $currentPage * 100 ? true : false;
     $data['currentPage'] = $currentPage;
     $data['metadataPrefix'] = $request->get('metadataPrefix', 'oai_dc');
     return $this->response('OjsOAIBundle:Default:sets.xml.twig', $data);
 }
Пример #9
0
 /**
  * Generates an API Key
  */
 public function generateApiKey()
 {
     $this->apiKey = StringHelper::generateKey();
 }
Пример #10
0
 public function registerAction(Request $request)
 {
     $allowanceSetting = $this->getDoctrine()->getRepository('OjsAdminBundle:SystemSetting')->findOneBy(['name' => 'user_registration']);
     if ($allowanceSetting) {
         if (!$allowanceSetting->getValue()) {
             return $this->render('OjsSiteBundle:Site:not_available.html.twig', ['title' => 'title.register', 'message' => 'message.registration_not_available']);
         }
     }
     /** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */
     $formFactory = $this->get('fos_user.registration.form.factory');
     /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
     $userManager = $this->get('ojs_user.manager');
     /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
     $dispatcher = $this->get('event_dispatcher');
     /** @var User $user */
     $user = $userManager->createUser();
     $user->setEnabled(true);
     //Add default data for oauth login
     $session = $this->get('session');
     $oauth_login = $session->get('oauth_login', false);
     if ($oauth_login) {
         $name = explode(' ', $oauth_login['full_name']);
         $firstName = $name[0];
         unset($name[0]);
         $lastName = implode(' ', $name);
         $user->setFirstName($firstName)->setLastName($lastName)->setUsername(StringHelper::slugify($oauth_login['full_name']));
     }
     $event = new GetResponseUserEvent($user, $request);
     $dispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE, $event);
     if (null !== $event->getResponse()) {
         return $event->getResponse();
     }
     $form = $formFactory->createForm();
     $form->setData($user);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $event = new FormEvent($form, $request);
         $dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);
         $user->generateApiKey();
         $userManager->updateUser($user);
         $tokenGenerator = new TokenGenerator();
         $user->setConfirmationToken($tokenGenerator->generateToken());
         if (null === ($response = $event->getResponse())) {
             $url = $this->generateUrl('login');
             $response = new RedirectResponse($url);
         }
         $dispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
         if ($oauth_login) {
             $em = $this->getDoctrine()->getManager();
             $oauth = new UserOauthAccount();
             $oauth->setProvider($oauth_login['provider'])->setProviderAccessToken($oauth_login['access_token'])->setProviderRefreshToken($oauth_login['refresh_token'])->setProviderUserId($oauth_login['user_id'])->setUser($user);
             $em->persist($oauth);
             $user->addOauthAccount($oauth);
             $em->persist($user);
         }
         $session->getFlashBag()->add('success', 'registration.activation');
         $session->remove('oauth_login');
         $session->save();
         $event = new UserEvent($user);
         $dispatcher = $this->get('event_dispatcher');
         $dispatcher->dispatch('user.register.complete', $event);
         return $response;
     }
     return $this->render('OjsUserBundle:Registration:register.html.twig', array('form' => $form->createView()));
 }