/**
  * Request a ping from a journal.
  *
  * @todo Use the Ping service
  *
  * @param Journal $journal
  *
  * @return bool
  */
 protected function pingJournal(Journal $journal)
 {
     $client = new Client();
     try {
         $response = $client->get($journal->getGatewayUrl());
         if ($response->getStatusCode() !== 200) {
             return false;
         }
         $xml = $response->xml();
         $element = $xml->xpath('//terms')[0];
         if ($element && isset($element['termsAccepted']) && (string) $element['termsAccepted'] === 'yes') {
             return true;
         }
     } catch (RequestException $e) {
         $this->logger->error("Cannot ping {$journal->getUrl()}: {$e->getMessage()}");
         if ($e->hasResponse()) {
             $this->logger->error($e->getResponse()->getStatusCode() . ' ' . $this->logger->error($e->getResponse()->getReasonPhrase()));
         }
     } catch (XmlParseException $e) {
         $this->logger->error("Cannot parse journal ping response {$journal->getUrl()}: {$e->getMessage()}");
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Ping a journal, check on it's health, etc.
  *
  * @param Journal $journal
  *
  * @return PingResult
  *
  * @throws Exception
  */
 public function ping(Journal $journal)
 {
     $this->logger->notice("Pinging {$journal}");
     $url = $journal->getGatewayUrl();
     $client = $this->getClient();
     try {
         $response = $client->get($url, array('allow_redirects' => false, 'headers' => array('User-Agent' => 'PkpPlnBot 1.0; http://pkp.sfu.ca', 'Accept' => 'application/xml,text/xml,*/*;q=0.1')));
         $pingResponse = new PingResult($response);
         if ($pingResponse->getHttpStatus() === 200) {
             $journal->setContacted(new DateTime());
             $journal->setTitle($pingResponse->getJournalTitle('(unknown title)'));
             $journal->setOjsVersion($pingResponse->getOjsRelease());
             $journal->setTermsAccepted($pingResponse->areTermsAccepted() === 'yes');
         } else {
             $journal->setStatus('ping-error');
         }
         $this->em->flush($journal);
         return $pingResponse;
     } catch (RequestException $e) {
         $journal->setStatus('ping-error');
         $this->em->flush($journal);
         if ($e->hasResponse()) {
             return new PingResult($e->getResponse());
         }
         throw $e;
     } catch (XmlParseException $e) {
         $journal->setStatus('ping-error');
         $this->em->flush($journal);
         return new PingResult($e->getResponse());
     } catch (Exception $e) {
         $journal->setStatus('ping-error');
         $this->em->flush($journal);
         throw $e;
     }
 }