|
|
@ -250,39 +250,36 @@ class FedoraAdapter implements AdapterInterface { |
|
|
|
* {@inheritdoc} |
|
|
|
* {@inheritdoc} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function write($path, $contents, Config $config) { |
|
|
|
public function write($path, $contents, Config $config) { |
|
|
|
|
|
|
|
$headers = [ |
|
|
|
|
|
|
|
'Content-Type' => $this->mimeTypeGuesser->guess($path), |
|
|
|
|
|
|
|
]; |
|
|
|
if ($this->has($path)) { |
|
|
|
if ($this->has($path)) { |
|
|
|
$fedora_url = $path; |
|
|
|
$fedora_url = $path; |
|
|
|
$headers = []; |
|
|
|
|
|
|
|
$date = new DateTime(); |
|
|
|
$date = new DateTime(); |
|
|
|
$timestamp = $date->format("D, d M Y H:i:s O"); |
|
|
|
$timestamp = $date->format("D, d M Y H:i:s O"); |
|
|
|
// Create version in Fedora. |
|
|
|
// Create version in Fedora. |
|
|
|
try { |
|
|
|
try { |
|
|
|
\Drupal::logger('flysystem')->info('Request being sent to Fedora to make a version for ' . $fedora_url); |
|
|
|
|
|
|
|
$response = $this->fedora->createVersion( |
|
|
|
$response = $this->fedora->createVersion( |
|
|
|
$fedora_url, |
|
|
|
$fedora_url, |
|
|
|
$timestamp, |
|
|
|
$timestamp, |
|
|
|
NULL, |
|
|
|
NULL, |
|
|
|
$headers |
|
|
|
$headers |
|
|
|
); |
|
|
|
); |
|
|
|
$status = $response->getStatusCode(); |
|
|
|
if (isset($response) && $response->getStatusCode() == 201) { |
|
|
|
if (!in_array($status, [201])) { |
|
|
|
\Drupal::logger('fedora_flysystem')->info('Created a version in Fedora for ' . $fedora_url); |
|
|
|
$reason = $response->getReasonPhrase(); |
|
|
|
} |
|
|
|
throw new \RuntimeException( |
|
|
|
else { |
|
|
|
"Client error: `POST $fedora_url` resulted in `$status $reason` response: " . |
|
|
|
\Drupal::logger('fedora_flysystem')->error( |
|
|
|
$response->getBody(), |
|
|
|
"Client error: `Failed to create a Fedora version of $fedora_url`. Response is " . print_r($response, TRUE) |
|
|
|
$status |
|
|
|
|
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
catch (\Exception $e) { |
|
|
|
catch (\Exception $e) { |
|
|
|
\Drupal::logger('flysystem')->error('Caught exception when creating version: ' . $e->getMessage() . "\n"); |
|
|
|
\Drupal::logger('fedora_flysystem')->error('Caught exception when creating version: ' . $e->getMessage() . "\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$headers = [ |
|
|
|
|
|
|
|
'Content-Type' => $this->mimeTypeGuesser->guess($path), |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$response = $this->fedora->saveResource( |
|
|
|
$response = $this->fedora->saveResource( |
|
|
|
$path, |
|
|
|
$path, |
|
|
|
$contents, |
|
|
|
$contents, |
|
|
|