コード例 #1
0
 /**
  * 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();
     $days = $this->getContainer()->getParameter('days_silent');
     $journals = $em->getRepository('AppBundle:Journal')->findSilent($days);
     $count = count($journals);
     $this->logger->notice("Found {$count} silent journals.");
     if (count($journals) === 0) {
         return;
     }
     $users = $em->getRepository('AppUserBundle:User')->findUserToNotify();
     if (count($users) === 0) {
         $this->logger->error('No users to notify.');
         return;
     }
     $this->sendNotifications($days, $users, $journals);
     foreach ($journals as $journal) {
         if ($this->pingJournal($journal)) {
             $this->logger->notice("Ping Success {$journal->getUrl()})");
             $journal->setStatus('healthy');
             $journal->setContacted(new DateTime());
         } else {
             $journal->setStatus('unhealthy');
             $journal->setNotified(new DateTime());
         }
     }
     if (!$input->getOption('dry-run')) {
         $em->flush();
     }
 }
コード例 #2
0
 /**
  * Get the checksum for a harvested deposit file.
  *
  * @param Deposit $deposit
  *
  * @return string
  */
 private function getChecksum(Deposit $deposit)
 {
     $filePath = $this->filePaths->getHarvestFile($deposit);
     switch (strtoupper($deposit->getChecksumType())) {
         case 'SHA-1':
         case 'SHA1':
             return sha1_file($filePath);
         case 'MD5':
             return md5_file($filePath);
         default:
             $this->logger->error("Deposit checksum type {$deposit->getChecksumType()} unknown.");
     }
 }
コード例 #3
0
 /**
  * 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();
     $days = $this->getContainer()->getParameter('days_reminder');
     $journals = $em->getRepository('AppBundle:Journal')->findOverdue($days);
     $count = count($journals);
     $this->logger->notice("Found {$count} overdue journals.");
     if (count($journals) === 0) {
         return;
     }
     $users = $em->getRepository('AppUserBundle:User')->findUserToNotify();
     if (count($users) === 0) {
         $this->logger->error('No users to notify.');
         return;
     }
     $this->sendReminders($days, $users, $journals);
     foreach ($journals as $journal) {
         $journal->setNotified(new DateTime());
     }
     if (!$input->getOption('dry-run')) {
         $em->flush();
     }
 }
コード例 #4
0
 /**
  * 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();
     }
 }