/** * Add the metadata from the database to the bag-info.txt file. * * @param BagIt $bag * @param Deposit $deposit */ protected function addMetadata(BagIt $bag, Deposit $deposit) { $bag->bagInfoData = array(); // @todo this is very very bad. Once BagItPHP is updated it should be $bag->clearAllBagInfo(); $bag->setBagInfoData('External-Identifier', $deposit->getDepositUuid()); $bag->setBagInfoData('PKP-PLN-Deposit-UUID', $deposit->getDepositUuid()); $bag->setBagInfoData('PKP-PLN-Deposit-Received', $deposit->getReceived()->format('c')); $bag->setBagInfoData('PKP-PLN-Deposit-Volume', $deposit->getVolume()); $bag->setBagInfoData('PKP-PLN-Deposit-Issue', $deposit->getIssue()); $bag->setBagInfoData('PKP-PLN-Deposit-PubDate', $deposit->getPubDate()->format('c')); $journal = $deposit->getJournal(); $bag->setBagInfoData('PKP-PLN-Journal-UUID', $journal->getUuid()); $bag->setBagInfoData('PKP-PLN-Journal-Title', $journal->getTitle()); $bag->setBagInfoData('PKP-PLN-Journal-ISSN', $journal->getIssn()); $bag->setBagInfoData('PKP-PLN-Journal-URL', $journal->getUrl()); $bag->setBagInfoData('PKP-PLN-Journal-Email', $journal->getEmail()); $bag->setBagInfoData('PKP-PLN-Publisher-Name', $journal->getPublisherName()); $bag->setBagInfoData('PKP-PLN-Publisher-URL', $journal->getPublisherUrl()); foreach ($deposit->getLicense() as $key => $value) { $bag->setBagInfoData('PKP-PLN-' . $key, $value); } }
/** * Get the path to a processed, staged, bag. * * @param Deposit $deposit * * @return type */ public final function getStagingBagPath(Deposit $deposit) { $path = $this->getStagingDir($deposit->getJournal()); return $path . '/' . $deposit->getDepositUuid() . '.zip'; }
/** * Fetch one deposit from LOCKSSOMatic. * * @param Deposit $deposit * @param string $href */ public function fetch(Deposit $deposit, $href) { $client = $this->getHttpClient(); $filepath = $this->filePaths->getRestoreDir($deposit->getJournal()) . '/' . basename($href); $this->logger->notice("Saving {$deposit->getJournal()->getTitle()} vol. {$deposit->getVolume()} no. {$deposit->getIssue()} to {$filepath}"); try { $client->get($href, array('allow_redirects' => false, 'decode_content' => false, 'save_to' => $filepath)); $hash = strtoupper(hash_file($deposit->getPackageChecksumType(), $filepath)); if ($hash !== $deposit->getPackageChecksumValue()) { $this->logger->warning("Package checksum failed. Expected {$deposit->getPackageChecksumValue()} but got {$hash}"); } } catch (Exception $ex) { $this->logger->error($ex->getMessage()); } }
public function testJournal() { $journal = $this->deposit->getJournal(); $this->assertInstanceOf('AppBundle\\Entity\\Journal', $journal); $this->assertEquals('C0A65967-32BD-4EE8-96DE-C469743E563A', $journal->getUuid()); }
/** * Build the URL for the deposit receipt. * * @param Deposit $deposit * * @return string */ public function buildDepositReceiptUrl(Deposit $deposit) { return $this->router->getGenerator()->generate('statement', array('journal_uuid' => $deposit->getJournal()->getUuid(), 'deposit_uuid' => $deposit->getDepositUuid()), UrlGeneratorInterface::ABSOLUTE_URL); }
/** * 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; }