Browse Source

Remove deprecate MimeTypeGuesser

Use test upgraded Crayfish-Commons
MNPALS-2.x
Jared Whiklo 2 years ago committed by Rosie Le Faive
parent
commit
8ce1ad2cda
  1. 2
      composer.json
  2. 3
      islandora.services.yml
  3. 30
      src/Flysystem/Adapter/FedoraAdapter.php
  4. 24
      src/Flysystem/Fedora.php

2
composer.json

@ -27,7 +27,7 @@
"drupal/prepopulate" : "^2.2",
"drupal/search_api": "^1.8",
"drupal/token" : "^1.3",
"islandora/crayfish-commons": "^3",
"islandora/crayfish-commons": "dev-upgrade-5.4-symfony",
"islandora/jsonld": "^2",
"stomp-php/stomp-php": "4.* || ^5"
},

3
islandora.services.yml

@ -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']

30
src/Flysystem/Adapter/FedoraAdapter.php

@ -2,6 +2,7 @@
namespace Drupal\islandora\Flysystem\Adapter;
use Drupal\Core\Logger\LoggerChannelInterface;
use Islandora\Chullo\IFedoraApi;
use League\Flysystem\AdapterInterface;
use League\Flysystem\Adapter\Polyfill\NotSupportingVisibilityTrait;
@ -9,7 +10,7 @@ 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.
@ -29,21 +30,34 @@ 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
*/
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;
}
/**
@ -259,7 +273,7 @@ class FedoraAdapter implements AdapterInterface {
*/
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;
@ -274,17 +288,17 @@ class FedoraAdapter implements AdapterInterface {
$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");
}
}

24
src/Flysystem/Fedora.php

@ -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;
@ -17,7 +18,7 @@ use Islandora\Chullo\IFedoraApi;
use Islandora\Chullo\FedoraApi;
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.
@ -38,7 +39,7 @@ class Fedora implements FlysystemPluginInterface, ContainerFactoryPluginInterfac
/**
* Mimetype guesser.
*
* @var \Symfony\Component\HttpFoundation\File\Mimetype\MimeTypeGuesserInterface
* @var \Symfony\Component\Mime\MimeTypeGuesserInterface
*/
protected $mimeTypeGuesser;
@ -49,24 +50,34 @@ 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
*/
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;
}
/**
@ -87,7 +98,8 @@ class Fedora implements FlysystemPluginInterface, ContainerFactoryPluginInterfac
return new static(
$fedora,
$container->get('file.mime_type.guesser'),
$container->get('language_manager')
$container->get('language_manager'),
$container->get('logger.channel.fedora_flysystem')
);
}
@ -116,7 +128,7 @@ class Fedora implements FlysystemPluginInterface, ContainerFactoryPluginInterfac
* {@inheritdoc}
*/
public function getAdapter() {
return new FedoraAdapter($this->fedora, $this->mimeTypeGuesser);
return new FedoraAdapter($this->fedora, $this->mimeTypeGuesser, $this->logger);
}
/**

Loading…
Cancel
Save