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

[WIP] Update crayfits to symfony 5.4 #180

Draft
wants to merge 1 commit into
base: 4.x
Choose a base branch
from
Draft
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
28 changes: 13 additions & 15 deletions CrayFits/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@
"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": {
"*": "dist"
},
"sort-packages": true,
"allow-plugins": {
"symfony/flex": true
"symfony/flex": true,
"symfony/runtime": true
}
},
"autoload": {
Expand Down Expand Up @@ -50,18 +51,15 @@
],
"post-update-cmd": [
"@auto-scripts"
],
"test": [
"@check"
]
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "^4.4"
"require": "5.4.*"
}
}
}
}
6 changes: 0 additions & 6 deletions CrayFits/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
24 changes: 9 additions & 15 deletions CrayFits/src/Controller/FitsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -19,47 +17,43 @@ class FitsController {
/**
* FitsController constructor.
*/

public function __construct(FitsGenerator $fitsGenerator) {
$options = ['base_uri' => $_ENV['FITS_WEBSERVICE_URI']];
$this->client = new Client($options);
}

/**
* @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("<h2>The Fits microservice is up and running.</h2>");
}
$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') {
Expand Down
Loading