Browse Source

Merge pull request #793 from asulibraries/version_files

Version files
pull/795/head
Mark Jordan 4 years ago committed by GitHub
parent
commit
173483ef52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      composer.json
  2. 1
      islandora.info.yml
  3. 27
      src/Flysystem/Adapter/FedoraAdapter.php
  4. 15
      tests/src/Kernel/FedoraAdapterTest.php

1
composer.json

@ -28,6 +28,7 @@
"drupal/migrate_source_csv" : "^2.1",
"drupal/token" : "^1.3",
"drupal/flysystem" : "^1.0",
"drupal/file_replace": "^1.1",
"islandora/crayfish-commons": "dev-dev"
},
"require-dev": {

1
islandora.info.yml

@ -31,3 +31,4 @@ dependencies:
- content_translation
- flysystem
- token
- file_replace

27
src/Flysystem/Adapter/FedoraAdapter.php

@ -11,6 +11,7 @@ use GuzzleHttp\Psr7;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\StreamWrapper;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
use DateTime;
/**
* Fedora adapter for Flysystem.
@ -252,6 +253,32 @@ class FedoraAdapter implements AdapterInterface {
$headers = [
'Content-Type' => $this->mimeTypeGuesser->guess($path),
];
if ($this->has($path)) {
$fedora_url = $path;
$date = new DateTime();
$timestamp = $date->format("D, d M Y H:i:s O");
// Create version in Fedora.
try {
$response = $this->fedora->createVersion(
$fedora_url,
$timestamp,
NULL,
$headers
);
if (isset($response) && $response->getStatusCode() == 201) {
\Drupal::logger('fedora_flysystem')->info('Created a version in Fedora for ' . $fedora_url);
}
else {
\Drupal::logger('fedora_flysystem')->error(
"Client error: `Failed to create a Fedora version of $fedora_url`. Response is " . print_r($response, TRUE)
);
}
}
catch (\Exception $e) {
\Drupal::logger('fedora_flysystem')->error('Caught exception when creating version: ' . $e->getMessage() . "\n");
}
}
$response = $this->fedora->saveResource(
$path,

15
tests/src/Kernel/FedoraAdapterTest.php

@ -84,6 +84,10 @@ class FedoraAdapterTest extends IslandoraKernelTestBase {
protected function createAdapterForWrite() {
$fedora_prophecy = $this->prophesize(IFedoraApi::class);
$prophecy = $this->prophesize(Response::class);
$prophecy->getStatusCode()->willReturn(201);
$fedora_prophecy->createVersion('', Argument::any(), NULL,
Argument::any())->willReturn($prophecy->reveal());
$prophecy = $this->prophesize(Response::class);
$prophecy->getStatusCode()->willReturn(201);
@ -111,6 +115,9 @@ class FedoraAdapterTest extends IslandoraKernelTestBase {
*/
protected function createAdapterForWriteFail() {
$fedora_prophecy = $this->prophesize(IFedoraApi::class);
$prophecy = $this->prophesize(Response::class);
$prophecy->getStatusCode()->willReturn(500);
$fedora_prophecy->getResourceHeaders('')->willReturn($prophecy->reveal());
$prophecy = $this->prophesize(Response::class);
$prophecy->getStatusCode()->willReturn(500);
@ -562,6 +569,14 @@ class FedoraAdapterTest extends IslandoraKernelTestBase {
$prophecy->getStatusCode()->willReturn(201);
$response = $prophecy->reveal();
$date = new \DateTime();
$timestamp = $date->format("D, d M Y H:i:s O");
$fedora_prophecy->createVersion('',
Argument::any(), NULL,
Argument::any())->willReturn($prophecy->reveal());
$prophecy = $this->prophesize(Response::class);
$prophecy->getStatusCode()->willReturn(201);
$fedora_prophecy->saveResource(Argument::any(), Argument::any(), Argument::any())->willReturn($response);
$prophecy = $this->prophesize(Response::class);

Loading…
Cancel
Save