Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version files #793

Merged
merged 10 commits into from
Aug 28, 2020
34 changes: 34 additions & 0 deletions src/Flysystem/Adapter/FedoraAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\StreamWrapper;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
use DateTime;

/**
* Fedora adapter for Flysystem.
Expand Down Expand Up @@ -249,6 +250,39 @@ protected function transformToMetadata($uri) {
* {@inheritdoc}
*/
public function write($path, $contents, Config $config) {
\Drupal::logger('flysystem adapter')->info('in write for flysystem');
if ($this->has($path)) {
\Drupal::logger('flysystem adapter')->info('in write for flysystem and already exists in fedora');
$fedora_url = $path;
$headers = [];
$date = new DateTime();
$timestamp = $date->format("D, d M Y H:i:s O");
// Create version in Fedora.
try {
\Drupal::logger('flysystem')->info('right before make version ' . $fedora_url);
$response = $this->fedora->createVersion(
$fedora_url,
$timestamp,
NULL,
$headers
);
$status = $response->getStatusCode();
if (!in_array($status, [201])) {
$reason = $response->getReasonPhrase();
throw new \RuntimeException(
"Client error: `POST $fedora_url` resulted in `$status $reason` response: " .
$response->getBody(),
$status
);
}
// Return the response from Fedora.
\Drupal::logger('flysystem')->info('past making a version with status ' . $status);
}
catch (\Exception $e) {
\Drupal::logger('flysystem')->error('Caught exception when creating version: ', $e->getMessage(), "\n");
}
}

$headers = [
'Content-Type' => $this->mimeTypeGuesser->guess($path),
];
Expand Down