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

Remove dependency on Crayfish-Commons #936

Merged
merged 7 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@
"drupal/prepopulate" : "^2.2",
"drupal/search_api": "^1.8",
"drupal/token" : "^1.3",
"islandora/crayfish-commons": "^3",
"islandora/chullo": "^2.0",
"islandora/fedora-entity-mapper": "^1.0",
"islandora/jsonld": "^2",
"stomp-php/stomp-php": "4.* || ^5"
},
"require-dev": {
"phpunit/phpunit": "^6",
"squizlabs/php_codesniffer": "2.7.1",
"squizlabs/php_codesniffer": "^2.7.1",
"drupal/coder": "*",
"sebastian/phpcpd": "*"
},
Expand Down
5 changes: 4 additions & 1 deletion islandora.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ services:
logger.channel.islandora:
parent: logger.channel_base
arguments: ['islandora']
logger.channel.fedora_flysystem:
parent: logger.channel_base
arguments: ['fedora_flysystem']
islandora.media_route_context_provider:
class: Drupal\islandora\ContextProvider\MediaRouteContextProvider
arguments: ['@current_route_match']
Expand All @@ -53,7 +56,7 @@ services:
class: Drupal\islandora\IslandoraUtils
arguments: ['@entity_type.manager', '@entity_field.manager', '@context.manager', '@flysystem_factory', '@language_manager']
islandora.entity_mapper:
class: Islandora\Crayfish\Commons\EntityMapper\EntityMapper
class: Islandora\EntityMapper\EntityMapper
islandora.stomp.auth_header_listener:
class: Drupal\islandora\EventSubscriber\StompHeaderEventSubscriber
arguments: ['@jwt.authentication.jwt']
Expand Down
31 changes: 23 additions & 8 deletions src/Flysystem/Adapter/FedoraAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace Drupal\islandora\Flysystem\Adapter;

use Drupal\Core\Logger\LoggerChannelInterface;
use Islandora\Chullo\IFedoraApi;
use League\Flysystem\AdapterInterface;
use League\Flysystem\Adapter\Polyfill\NotSupportingVisibilityTrait;
use League\Flysystem\Adapter\Polyfill\StreamedCopyTrait;
use League\Flysystem\Config;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\StreamWrapper;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
use Symfony\Component\Mime\MimeTypeGuesserInterface;

/**
* Fedora adapter for Flysystem.
Expand All @@ -29,21 +30,35 @@ class FedoraAdapter implements AdapterInterface {
/**
* Mimetype guesser.
*
* @var \Symfony\Component\HttpFoundation\File\Mimetype\MimeTypeGuesserInterface
* @var \Symfony\Component\Mime\MimeTypeGuesserInterface
*/
protected $mimeTypeGuesser;

/**
* Logger.
*
* @var \Drupal\Core\Logger\LoggerChannelInterface
*/
protected $logger;

/**
* Constructs a Fedora adapter for Flysystem.
*
* @param \Islandora\Chullo\IFedoraApi $fedora
* Fedora client.
* @param \Symfony\Component\HttpFoundation\File\Mimetype\MimeTypeGuesserInterface $mime_type_guesser
* @param \Symfony\Component\Mime\MimeTypeGuesserInterface $mime_type_guesser
* Mimetype guesser.
* @param \Drupal\Core\Logger\LoggerChannelInterface $logger
* The fedora adapter logger channel.
*/
public function __construct(IFedoraApi $fedora, MimeTypeGuesserInterface $mime_type_guesser) {
public function __construct(
IFedoraApi $fedora,
MimeTypeGuesserInterface $mime_type_guesser,
LoggerChannelInterface $logger
) {
$this->fedora = $fedora;
$this->mimeTypeGuesser = $mime_type_guesser;
$this->logger = $logger;
}

/**
Expand Down Expand Up @@ -259,7 +274,7 @@ protected function transformToMetadata($uri) {
*/
public function write($path, $contents, Config $config) {
$headers = [
'Content-Type' => $this->mimeTypeGuesser->guess($path),
'Content-Type' => $this->mimeTypeGuesser->guessMimeType($path),
];
if ($this->has($path)) {
$fedora_url = $path;
Expand All @@ -274,17 +289,17 @@ public function write($path, $contents, Config $config) {
$headers
);
if (isset($response) && $response->getStatusCode() == 201) {
\Drupal::logger('fedora_flysystem')->info('Created a version in Fedora for ' . $fedora_url);
$this->logger->info('Created a version in Fedora for ' . $fedora_url);
}
else {
\Drupal::logger('fedora_flysystem')->error(
$this->logger->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");
$this->logger->error('Caught exception when creating version: ' . $e->getMessage() . "\n");
}
}

Expand Down
34 changes: 21 additions & 13 deletions src/Flysystem/Fedora.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Drupal\islandora\Flysystem;

use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\Core\Logger\RfcLogLevel;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Url;
Expand All @@ -12,12 +13,11 @@
use Drupal\jwt\Authentication\Provider\JwtAuth;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Client;
use Islandora\Chullo\IFedoraApi;
use Islandora\Chullo\FedoraApi;
use Islandora\Chullo\IFedoraApi;
use Psr\Http\Message\RequestInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
use Symfony\Component\Mime\MimeTypeGuesserInterface;

/**
* Drupal plugin for the Fedora Flysystem adapter.
Expand All @@ -38,7 +38,7 @@ class Fedora implements FlysystemPluginInterface, ContainerFactoryPluginInterfac
/**
* Mimetype guesser.
*
* @var \Symfony\Component\HttpFoundation\File\Mimetype\MimeTypeGuesserInterface
* @var \Symfony\Component\Mime\MimeTypeGuesserInterface
*/
protected $mimeTypeGuesser;

Expand All @@ -49,24 +49,35 @@ class Fedora implements FlysystemPluginInterface, ContainerFactoryPluginInterfac
*/
protected $languageManager;

/**
* Logger.
*
* @var \Drupal\Core\Logger\LoggerChannelInterface
*/
protected $logger;

/**
* Constructs a Fedora plugin for Flysystem.
*
* @param \Islandora\Chullo\IFedoraApi $fedora
* Fedora client.
* @param \Symfony\Component\HttpFoundation\File\Mimetype\MimeTypeGuesserInterface $mime_type_guesser
* @param \Symfony\Component\Mime\MimeTypeGuesserInterface $mime_type_guesser
* Mimetype guesser.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* Language manager.
* @param \Drupal\Core\Logger\LoggerChannelInterface $logger
* The fedora adapter logger channel.
*/
public function __construct(
IFedoraApi $fedora,
MimeTypeGuesserInterface $mime_type_guesser,
LanguageManagerInterface $language_manager
LanguageManagerInterface $language_manager,
LoggerChannelInterface $logger
) {
$this->fedora = $fedora;
$this->mimeTypeGuesser = $mime_type_guesser;
$this->languageManager = $language_manager;
$this->logger = $logger;
}

/**
Expand All @@ -77,17 +88,14 @@ public static function create(ContainerInterface $container, array $configuratio
// Construct guzzle client to middleware that adds JWT.
$stack = HandlerStack::create();
$stack->push(static::addJwt($container->get('jwt.authentication.jwt')));
$client = new Client([
'handler' => $stack,
'base_uri' => $configuration['root'],
]);
$fedora = new FedoraApi($client);
$fedora = FedoraApi::createWithHandler($configuration['root'], $stack);

// Return it.
return new static(
$fedora,
$container->get('file.mime_type.guesser'),
$container->get('language_manager')
$container->get('language_manager'),
$container->get('logger.channel.fedora_flysystem')
);
}

Expand Down Expand Up @@ -116,7 +124,7 @@ public static function addJwt(JwtAuth $jwt) {
* {@inheritdoc}
*/
public function getAdapter() {
return new FedoraAdapter($this->fedora, $this->mimeTypeGuesser);
return new FedoraAdapter($this->fedora, $this->mimeTypeGuesser, $this->logger);
}

/**
Expand Down
Loading