/** * {@inheritDoc} */ protected function doLoad(ObjectManager $manager) { $j0 = new Journal(); $j0->setEmail('*****@*****.**'); $j0->setIssn('1234-1234'); $j0->setPublisherName('Test Publisher'); $j0->setPublisherUrl('http://example.com'); $j0->setTitle('I J Testing'); $j0->setUrl('http://journal.example.com'); $j0->setStatus('healthy'); $j0->setUuid('c0a65967-32bd-4ee8-96de-c469743e563a'); $j0->setOjsVersion('2.4.8.0'); $manager->persist($j0); $j0->setContacted(new DateTime('-10 days')); $j0->setNotified(new DateTime('-5 days')); $j1 = new Journal(); $j1->setEmail('*****@*****.**'); $j1->setIssn('4321-4321'); $j1->setPublisherName('Orange Inc'); $j1->setPublisherUrl('http://orangula.dev'); $j1->setTitle('J Oranges'); $j1->setUrl('http://journal.orangula.dev'); $j1->setStatus('new'); $j1->setUuid('A556CBF2-B674-444F-87B7-23DEE36F013D'); $j1->setContacted(new DateTime()); $manager->persist($j1); $manager->flush(); $this->setReference('journal', $j0); }
/** * 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; } }
/** * Build and persist a journal from XML. * * @param SimpleXMLElement $xml * @param string $journal_uuid * * @return Journal */ public function fromXml(SimpleXMLElement $xml, $journal_uuid) { $journal = $this->em->getRepository('AppBundle:Journal')->findOneBy(array('uuid' => $journal_uuid)); if ($journal === null) { $journal = new Journal(); } $journal->setUuid($journal_uuid); $journal->setTitle($this->getXmlValue($xml, '//atom:title')); $journal->setUrl(html_entity_decode($this->getXmlValue($xml, '//pkp:journal_url'))); // & -> & $journal->setEmail($this->getXmlValue($xml, '//atom:email')); $journal->setIssn($this->getXmlValue($xml, '//pkp:issn')); $journal->setPublisherName($this->getXmlValue($xml, '//pkp:publisherName')); $journal->setPublisherUrl(html_entity_decode($this->getXmlValue($xml, '//pkp:publisherUrl'))); // & -> & $this->em->persist($journal); $this->em->flush($journal); return $journal; }
/** * The journal with UUID $uuid has contacted the PLN. Add a record for the * journal if there isn't one, otherwise update the timestamp. * * @param string $uuid * @param string $url * * @return Journal */ private function journalContact($uuid, $url) { $logger = $this->get('monolog.logger.sword'); $em = $this->getDoctrine()->getManager(); $journalRepo = $em->getRepository('AppBundle:Journal'); $journal = $journalRepo->findOneBy(array('uuid' => $uuid)); if ($journal !== null) { $journal->setTimestamp(); if ($journal->getUrl() !== $url) { $logger->warning("journal URL mismatch - {$uuid} - {$journal->getUrl()} - {$url}"); $journal->setUrl($url); } } else { $journal = new Journal(); $journal->setUuid($uuid); $journal->setUrl($url); $journal->setTimestamp(); $journal->setTitle('unknown'); $journal->setIssn('unknown'); $journal->setStatus('new'); $journal->setEmail('*****@*****.**'); $em->persist($journal); } if ($journal->getStatus() !== 'new') { $journal->setStatus('healthy'); } $em->flush($journal); return $journal; }