Example #1
0
 /**
  * {@inheritDoc}
  */
 protected function doLoad(ObjectManager $manager)
 {
     $d0 = new Deposit();
     $d0->setAction('add');
     $d0->setChecksumType('SHA1');
     $d0->setChecksumValue('b4b0bfbaadf33f8e678ad9cd0c1da2c9a6e7d204');
     $d0->setDepositUuid('d38e7ecb-7d7e-408d-94b0-b00d434fdbd2');
     $d0->setDepositReceipt('http://example.com/path/to/receipt');
     $d0->setFileType('application/zip');
     $d0->setIssue(2);
     $d0->setJournal($this->getReference('journal'));
     $d0->setPubDate(new DateTime());
     $d0->setSize(100);
     $d0->setState('depositedByJournal');
     $d0->setUrl('http://journal.example.com/path/to/deposit');
     $d0->setVolume(1);
     $manager->persist($d0);
     $d1 = new Deposit();
     $d1->setAction('add');
     $d1->setChecksumType('SHA1');
     $d1->setChecksumValue('f1d2d2f924e986ac86fdf7b36c94bcdf32beec15');
     $d1->setDepositUuid('578205CB-0947-4CD3-A384-CDF186F5E86B');
     $d1->setDepositReceipt('http://example2.com/path/to/receipt');
     $d1->setFileType('application/zip');
     $d1->setIssue(4);
     $d1->setJournal($this->getReference('journal'));
     $d1->setPubDate(new DateTime());
     $d1->setSize(1000);
     $d1->setState('harvested');
     $d1->setUrl('http://journal.example2.com/path/to/deposit');
     $d1->setVolume(2);
     $manager->persist($d1);
     $manager->flush();
     $this->setReference('deposit', $d0);
 }
 /**
  * Build a deposit from XML.
  *
  * @param Journal          $journal
  * @param SimpleXMLElement $xml
  * @param string           $action
  *
  * @return Deposit
  */
 public function fromXml(Journal $journal, SimpleXMLElement $xml)
 {
     $id = $this->getXmlValue($xml, '//atom:id');
     $deposit_uuid = strtoupper(substr($id, 9, 36));
     $deposit = $this->em->getRepository('AppBundle:Deposit')->findOneBy(array('depositUuid' => $deposit_uuid));
     $action = 'edit';
     if (!$deposit) {
         $action = 'add';
         $deposit = new Deposit();
     }
     $deposit->setAction($action);
     $deposit->setState('depositedByJournal');
     $deposit->setChecksumType($this->getXmlValue($xml, 'pkp:content/@checksumType'));
     $deposit->setChecksumValue($this->getXmlValue($xml, 'pkp:content/@checksumValue'));
     $deposit->setDepositUuid($deposit_uuid);
     $deposit->setFileType('');
     $deposit->setIssue($this->getXmlValue($xml, 'pkp:content/@issue'));
     $deposit->setVolume($this->getXmlValue($xml, 'pkp:content/@volume'));
     $deposit->setPubDate(new DateTime($this->getXmlValue($xml, 'pkp:content/@pubdate')));
     $deposit->setJournal($journal);
     $deposit->setSize($this->getXmlValue($xml, 'pkp:content/@size'));
     $deposit->setUrl(html_entity_decode($this->getXmlValue($xml, 'pkp:content')));
     $deposit->setDepositReceipt($this->buildDepositReceiptUrl($deposit));
     $this->getLicensingInfo($deposit, $xml);
     if ($action === 'add') {
         $deposit->addToProcessingLog('Deposit received.');
     } else {
         $deposit->addToProcessingLog('Deposit edited or reset by journal manager.');
     }
     $this->em->persist($deposit);
     $this->em->flush();
     return $deposit;
 }
Example #3
0
 /**
  * Send a deposit to LOM via HTTP.
  *
  * @param Deposit $deposit
  *
  * @return bool true on success
  */
 public function createDeposit(Deposit $deposit)
 {
     $this->serviceDocument($deposit->getJournal());
     $xml = $this->templating->render('AppBundle:SwordClient:deposit.xml.twig', array('title' => 'Deposit from OJS part ' . $deposit->getAuContainer()->getId(), 'publisher' => 'Public Knowledge Project Staging Server', 'deposit' => $deposit, 'baseUri' => $this->router->generate('home', array(), UrlGeneratorInterface::ABSOLUTE_URL), 'plnJournalTitle' => $this->plnJournalTitle));
     if ($this->saveDepositXml) {
         $atomPath = $this->filePaths->getStagingDir($deposit->getJournal()) . '/' . $deposit->getDepositUuid() . '.xml';
         file_put_contents($atomPath, $xml);
     }
     try {
         $client = $this->getClient();
         $request = $client->createRequest('POST', $this->colIri);
         $request->setBody(Stream::factory($xml));
         $response = $client->send($request);
         $responseXml = new SimpleXMLElement($response->getBody());
     } catch (RequestException $e) {
         $this->logger->critical($e->getMessage());
         if ($e->hasResponse()) {
             $xml = $e->getResponse()->xml();
             $xml->registerXPathNamespace('atom', 'http://www.w3.org/2005/Atom');
             $xml->registerXPathNamespace('sword', 'http://purl.org/net/sword/');
             $this->logger->critical('Summary: ' . (string) $xml->xpath('//atom:summary')[0]);
             $this->logger->warning('Detail: ' . (string) $xml->xpath('//sword:verboseDescription')[0]);
         }
         return false;
     } catch (Exception $e) {
         $this->logger->critical("Error parsing deposit response from server: {$e->getMessage()}");
         return false;
     }
     $deposit->setDepositReceipt($response->getHeader('Location'));
     $deposit->setDepositDate(new DateTime());
     // TODO should I do something wtih responseXML here?
     $this->namespaces->registerNamespaces($responseXml);
     return true;
 }