From 81ba9d53346d554cb856af9f28fb0b6fe507d826 Mon Sep 17 00:00:00 2001 From: Joe Corall Date: Thu, 7 Dec 2023 16:14:53 -0500 Subject: [PATCH] Update crayfits symfony --- CrayFits/composer.json | 28 ++++++++++------------ CrayFits/public/index.php | 6 ----- CrayFits/src/Controller/FitsController.php | 24 +++++++------------ 3 files changed, 22 insertions(+), 36 deletions(-) diff --git a/CrayFits/composer.json b/CrayFits/composer.json index f1ad856f..552beda4 100644 --- a/CrayFits/composer.json +++ b/CrayFits/composer.json @@ -4,14 +4,14 @@ "require": { "ext-ctype": "*", "ext-iconv": "*", - "guzzlehttp/guzzle": "^6.3", - "monolog/monolog": "^1.24", - "symfony/console": "^4.4", - "symfony/dotenv": "^4.4", - "symfony/flex": "^1.1", - "symfony/framework-bundle": "^4.4", - "symfony/monolog-bundle": "^3.3", - "symfony/yaml": "^4.4" + "islandora/crayfish-commons": "^4.0", + "symfony/dotenv": "5.4.*", + "symfony/flex": "^1.3.1", + "symfony/framework-bundle": "5.4.*", + "symfony/runtime": "5.4.*", + "symfony/string": "5.4.*", + "symfony/translation": "5.4.*", + "symfony/yaml": "5.4.*" }, "config": { "preferred-install": { @@ -19,7 +19,8 @@ }, "sort-packages": true, "allow-plugins": { - "symfony/flex": true + "symfony/flex": true, + "symfony/runtime": true } }, "autoload": { @@ -50,10 +51,7 @@ ], "post-update-cmd": [ "@auto-scripts" - ], - "test": [ - "@check" - ] + ] }, "conflict": { "symfony/symfony": "*" @@ -61,7 +59,7 @@ "extra": { "symfony": { "allow-contrib": false, - "require": "^4.4" + "require": "5.4.*" } } -} +} \ No newline at end of file diff --git a/CrayFits/public/index.php b/CrayFits/public/index.php index e30f90c0..9f49805b 100644 --- a/CrayFits/public/index.php +++ b/CrayFits/public/index.php @@ -6,12 +6,6 @@ require dirname(__DIR__).'/config/bootstrap.php'; -if ($_SERVER['APP_DEBUG']) { - umask(0000); - - Debug::enable(); -} - if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) { Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST); } diff --git a/CrayFits/src/Controller/FitsController.php b/CrayFits/src/Controller/FitsController.php index f6d85416..503fd60a 100644 --- a/CrayFits/src/Controller/FitsController.php +++ b/CrayFits/src/Controller/FitsController.php @@ -2,15 +2,13 @@ namespace App\Controller; -use Islandora\Chullo\IFedoraApi; +use GuzzleHttp\Psr7\StreamWrapper; use App\Service\FitsGenerator; use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\HttpFoundation\Request; use GuzzleHttp\Client; use Psr\Log\LoggerInterface; use Symfony\Component\HttpFoundation\Response; -use Monolog\Logger; -use Monolog\Handler\StreamHandler; class FitsController { @@ -19,7 +17,6 @@ class FitsController { /** * FitsController constructor. */ - public function __construct(FitsGenerator $fitsGenerator) { $options = ['base_uri' => $_ENV['FITS_WEBSERVICE_URI']]; $this->client = new Client($options); @@ -27,39 +24,36 @@ public function __construct(FitsGenerator $fitsGenerator) { /** * @param Request $request - * @param LoggerInterface $loggerger * @return StreamedResponse | Response; */ public function generate_fits(Request $request) { set_time_limit(0); - $logger = new Logger('islandora_fits'); - $logger->pushHandler(new StreamHandler('/var/log/islandora/fits.log', Logger::DEBUG)); $token = $request->headers->get('Authorization'); $file_uri = $request->headers->get('Apix-Ldp-Resource'); + // If no file has been passed it probably because someone is testing the url from their browser. if (!$file_uri) { return new Response("

The Fits microservice is up and running.

"); } - $context = stream_context_create([ - "http" => [ - "header" => "Authorization: $token", - ], - ]); + try { + $fedora_resource = $request->attributes->get('fedora_resource'); + $body = StreamWrapper::getResource($fedora_resource->getBody()); + $response = $this->client->post('examine', [ 'multipart' => [ [ 'name' => 'datafile', 'filename' => $file_uri, - 'contents' => fopen($file_uri, 'r', FALSE, $context), + 'contents' => $body, ], ], ]); } catch (\Exception $e) { - $logger->addError('ERROR', [$e->getMessage()]); + return new Response("Failed to receive FITS XML", Response::HTTP_INTERNAL_SERVER_ERROR); } - $logger->addInfo('Response Status', ["Status" => $response->getStatusCode(), "URI" => $file_uri]); + $fits_xml = $response->getBody()->getContents(); $encoding = mb_detect_encoding($fits_xml, 'UTF-8', TRUE); if ($encoding != 'UTF-8') {