/** * Get an absolute path to a processing directory for the journal. * * @param string $dirname * @param Journal $journal * * @return string */ protected function absolutePath($dirname, Journal $journal = null) { $path = $this->rootPath() . '/' . $dirname; if (substr($dirname, -1) !== '/') { $path .= '/'; } if (!$this->fs->exists($path)) { $this->fs->mkdir($path); } if ($journal !== null) { return $path . $journal->getUuid(); } return realpath($path); }
/** * {@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); }
/** * Download all the content from one journal. * * Requests a SWORD deposit statement from LOCKSSOMatic, and uses the * sword:originalDeposit element to fetch the content. * * @param Journal $journal */ public function downloadJournal(Journal $journal) { foreach ($journal->getDeposits() as $deposit) { $statement = $this->swordClient->statement($deposit); $originals = $statement->xpath('//sword:originalDeposit'); foreach ($originals as $element) { $this->fetch($deposit, $element['href']); } } }
/** * 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; }
/** * 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; }
/** * 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; } }
/** * Fetch the service document by HTTP. * * @param Journal $journal * * @throws RequestException */ public function serviceDocument(Journal $journal) { $client = $this->getClient(); $headers = array('On-Behalf-Of' => $this->serverUuid, 'Journal-Url' => $journal->getUrl()); try { $response = $client->get($this->sdIri, ['headers' => $headers]); } catch (RequestException $e) { $this->logger->critical($e->getMessage()); if ($e->hasResponse()) { $xml = $e->getResponse()->xml(); $xml->registerXPathNamespace('atom', 'http://www.w3.org/2005/Atom'); $this->logger->critical((string) $xml->xpath('//atom:summary')[0]); } throw $e; } $xml = new SimpleXMLElement($response->getBody()); $this->namespaces->registerNamespaces($xml); $this->maxUpload = (string) $xml->xpath('sword:maxUploadSize')[0]; $this->uploadChecksum = (string) $xml->xpath('lom:uploadChecksumType')[0]; $this->siteName = (string) $xml->xpath('.//atom:title')[0]; $this->colIri = (string) $xml->xpath('.//app:collection/@href')[0]; }
/** * Figure out which message to return for the network status widget in OJS. * * @param Journal $journal * * @return string */ private function getNetworkMessage(Journal $journal) { if ($journal->getOjsVersion() === null) { return $this->container->getParameter('network_default'); } if (version_compare($journal->getOjsVersion(), $this->container->getParameter('min_ojs_version'), '>=')) { return $this->container->getParameter('network_accepting'); } return $this->container->getParameter('network_oldojs'); }