/** * Get the checksum for a harvested deposit file. * * @param Deposit $deposit * * @return string */ private function getChecksum(Deposit $deposit) { $filePath = $this->filePaths->getHarvestFile($deposit); switch (strtoupper($deposit->getChecksumType())) { case 'SHA-1': case 'SHA1': return sha1_file($filePath); case 'MD5': return md5_file($filePath); default: $this->logger->error("Deposit checksum type {$deposit->getChecksumType()} unknown."); } }
/** * Process one deposit. Fetch the data and write it to the file system. * Updates the deposit status, and may remove the processing files if * LOCKSSOatic reports agreement. * * @param Deposit $deposit * * @return type */ protected function processDeposit(Deposit $deposit, $force = false) { if ($deposit->getPlnState() === 'agreement') { $this->logger->notice($deposit->getDepositUuid()); $this->delFileTree($this->filePaths->getHarvestFile($deposit), $force); $this->delFileTree($this->filePaths->getProcessingBagPath($deposit), $force); // $this->delFileTree($this->filePaths->getStagingBagPath($deposit), $force); } }
/** * 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()); } }
/** * 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; }
public function testGetOnixPath() { $path = $this->fp->getOnixPath(); $this->assertEquals(self::$tmpPath . '/onix.xml', $path); }