/**
  * {@inheritDoc}
  */
 protected function doLoad(ObjectManager $manager)
 {
     $data = array(array('FC1EFBBA-BFA4-4505-A398-006FDBE6A9D7', 'this is a comment that is searchable'), array('9B6DDEFD-F74F-47FC-A6F2-4CDC549637C9', 'cheese is good for you'), array('4B84F713-7167-4F3F-A2CD-028E5C9F2A05', 'very model of a modern major'), array('A5ABCD90-4226-4B9A-849B-C78A856008B1', 'something about a general here'));
     foreach ($data as $d) {
         $entry = new Whitelist();
         $entry->setComment($d[1]);
         $entry->setUuid($d[0]);
         $manager->persist($entry);
     }
     $manager->flush();
 }
 /**
  * {@inheritDoc}
  */
 protected function doLoad(ObjectManager $manager)
 {
     $e0 = new Whitelist();
     $e0->setComment('Test entry');
     $e0->setUuid('6646afaa-beba-40c8-a286-c64a3e90d0f6');
     $manager->persist($e0);
     $e1 = new Whitelist();
     $e1->setComment('Test journal');
     $e1->setUuid('c0a65967-32bd-4ee8-96de-c469743e563a');
     $manager->persist($e1);
     $manager->flush();
     $this->setReference('wl', $e0);
 }
 /**
  * Execute the runall command, which executes all the commands.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->getContainer()->get('doctrine')->getManager();
     $router = $this->getContainer()->get('router');
     $bwlist = $this->getContainer()->get('blackwhitelist');
     $ping = $this->getContainer()->get('ping');
     $ping->setLogger($this->logger);
     /*
      * @var Journal[]
      */
     $journals = $em->getRepository('AppBundle:Journal')->findAll();
     $minVersion = $input->getArgument('minVersion');
     if (!$minVersion) {
         $minVersion = $this->getContainer()->getParameter('min_ojs_version');
     }
     $all = $input->getOption('all');
     $count = count($journals);
     $i = 0;
     foreach ($journals as $journal) {
         ++$i;
         $fmt = sprintf('%5d', $i);
         $url = $router->generate('journal_show', array('id' => $journal->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
         $uuid = $journal->getUuid();
         if (!$all && $journal->getStatus() === 'ping-error') {
             $this->logger->notice("{$fmt}/{$count} - skipped (previous ping-error) - - {$journal->getUrl()}");
             continue;
         }
         if (!$all && $bwlist->isWhitelisted($uuid)) {
             $this->logger->notice("{$fmt}/{$count} - skipped (whitelisted) - - {$journal->getUrl()}");
             continue;
         }
         if (!$all && $bwlist->isBlacklisted($uuid)) {
             $this->logger->notice("{$fmt}/{$count} - skipped (blacklisted) - - {$journal->getUrl()}");
             continue;
         }
         try {
             $response = $ping->ping($journal);
         } catch (Exception $e) {
             $this->logger->error("Ping - HTTP ERROR: {$e->getMessage()} - {$journal->getUrl()} - {$url}");
             $journal->setStatus('ping-error');
             $em->flush($journal);
             continue;
         }
         if ($response->getHttpStatus() !== 200) {
             $this->logger->error("Ping - HTTP {$response->getHttpStatus()} - - {$journal->getUrl()} - {$url} - {$response->getError()}");
             $journal->setStatus('ping-error');
             $em->flush($journal);
             continue;
         }
         if (!$response->getOjsRelease()) {
             $this->logger->warning("Ping - HTTP {$response->getHttpStatus()} - no version number found - {$journal->getUrl()} - {$url}");
             $journal->setStatus('ping-error');
             $em->flush($journal);
             continue;
         }
         $this->logger->notice("Ping - {$response->getHttpStatus()} - {$response->getOjsRelease()} - {$journal->getUrl()} - {$url}");
         if (version_compare($response->getOjsRelease(), $minVersion, '<')) {
             continue;
         }
         if ($input->getOption('dry-run')) {
             continue;
         }
         if ($bwlist->isWhitelisted($uuid) || $bwlist->isBlacklisted($uuid)) {
             continue;
         }
         $whitelist = new Whitelist();
         $whitelist->setUuid($journal->getUuid());
         $whitelist->setComment("{$journal->getUrl()} added automatically by ping-whitelist command.");
         $em->persist($whitelist);
         $em->flush();
     }
 }