コード例 #1
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;
 }