Skip to content

Commit

Permalink
chore: PHP 8.3 + start improving logs...
Browse files Browse the repository at this point in the history
  • Loading branch information
mborne committed Dec 3, 2024
1 parent 11cd92a commit 77cbb17
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 135 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "project",
"license": "AGPL-3.0-or-later",
"require": {
"php": "^7.2 || ^8.0",
"php": "^8.3",
"ext-ctype": "*",
"ext-iconv": "*",
"ext-zip": "*",
Expand Down
20 changes: 0 additions & 20 deletions config/packages/dev/monolog.yaml

This file was deleted.

42 changes: 17 additions & 25 deletions config/packages/monolog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,24 @@ when@dev:
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: ["!event"]
# uncomment to get logging in your browser
# you may have to allow bigger header sizes in your Web server configuration
#firephp:
# type: firephp
# level: info
#chromephp:
# type: chromephp
# level: info
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine", "!console"]

when@test:
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
excluded_http_codes: [404, 405]
channels: ["!event"]
nested:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
deprecation:
path: "%kernel.logs_dir%/deprecation.log"
channels: ["deprecation"]
type: rotating_file
max_files: 1


when@prod:
monolog:
Expand All @@ -54,9 +46,9 @@ when@prod:
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine"]
deprecation:
type: stream
channels: [deprecation]
path: php://stderr
formatter: monolog.formatter.json
channels: ["!event", "!doctrine", "!deprecation"]
# deprecation:
# type: stream
# channels: [deprecation]
# path: php://stderr
# formatter: monolog.formatter.json
16 changes: 0 additions & 16 deletions config/packages/prod/monolog.yaml

This file was deleted.

12 changes: 0 additions & 12 deletions config/packages/test/monolog.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ services:
- http_proxy=${HTTP_PROXY}
- https_proxy=${HTTPS_PROXY}
- APP_ENV=${APP_ENV}
- DB_CREATE=1
- DB_UPGRADE=1
- DB_CREATE=${DB_CREATE:-1}
- DB_UPGRADE=${DB_UPGRADE:-1}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@database:5432/validator_api?serverVersion=13&charset=utf8
Expand Down
88 changes: 29 additions & 59 deletions src/Controller/Api/ValidationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use JMS\Serializer\Serializer;
use JMS\Serializer\SerializerInterface;
use League\Flysystem\FilesystemOperator;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand All @@ -25,54 +26,16 @@
*/
class ValidationsController extends AbstractController
{

/**
* @var ValidationsStorage
*/
private $storage;

/**
* Helper class to validate arguments.
*
* @var ValidatorArgumentsService
*/
private $valArgsService;

/**
* @var MimeTypeGuesserService
*/
private $mimeTypeGuesserService;

/**
* @var Serializer
*/
private $serializer;

/**
* @var ValidationRepository
*/
private $repository;

/**
* @var FilesystemOperator
*/
private $dataStorage;

public function __construct(
ValidationRepository $repository,
SerializerInterface $serializer,
ValidationsStorage $storage,
FilesystemOperator $dataStorage,
ValidatorArgumentsService $valArgsService,
MimeTypeGuesserService $mimeTypeGuesserService
)
{
$this->repository = $repository;
$this->storage = $storage;
$this->dataStorage = $dataStorage;
$this->valArgsService = $valArgsService;
$this->mimeTypeGuesserService = $mimeTypeGuesserService;
$this->serializer = $serializer;
private ValidationRepository $repository,
private SerializerInterface $serializer,
private ValidationsStorage $storage,
private FilesystemOperator $dataStorage,
private ValidatorArgumentsService $valArgsService,
private MimeTypeGuesserService $mimeTypeGuesserService,
private LoggerInterface $logger
) {

}

/**
Expand Down Expand Up @@ -122,7 +85,7 @@ public function readConsole($uid)
throw new ApiException("Validation has been archived", Response::HTTP_FORBIDDEN);
}

$validationDirectory = $this->storage->getDirectory($validation) ;
$validationDirectory = $this->storage->getDirectory($validation);
$filepath = $validationDirectory . '/validator-debug.log';

$content = $this->dataStorage->read($filepath);
Expand Down Expand Up @@ -152,8 +115,8 @@ public function getValidationCsv($uid, CsvReportWriter $csvWriter)
$csvWriter->write($validation);
});
$response->headers->set('Content-Type', 'application/force-download');
$filename = $uid.'-results.csv';
$response->headers->set('Content-Disposition', 'attachment; filename="'.$filename.'"');
$filename = $uid . '-results.csv';
$response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');

return $response;
}
Expand All @@ -175,6 +138,12 @@ public function uploadDataset(Request $request)
if (!$file) {
throw new ApiException("Argument [dataset] is missing", Response::HTTP_BAD_REQUEST);
}

$this->logger->info('handle new upload...',[
'path_name' => $file->getPathName(),
'client_original_name' => $file->getClientOriginalName()
]);

/*
* Ensure that input file is a ZIP file.
*/
Expand All @@ -193,11 +162,11 @@ public function uploadDataset(Request $request)

// Save file to storage
$uploadDirectory = $validation->getUid() . '/upload/';
if (! $this->dataStorage->directoryExists($uploadDirectory)) {
if (!$this->dataStorage->directoryExists($uploadDirectory)) {
$this->dataStorage->createDirectory($uploadDirectory);
}
$fileLocation = $uploadDirectory . $validation->getDatasetName().'.zip';
if ($this->dataStorage->fileExists($fileLocation)){
$fileLocation = $uploadDirectory . $validation->getDatasetName() . '.zip';
if ($this->dataStorage->fileExists($fileLocation)) {
$this->dataStorage->delete($fileLocation);
}
$stream = fopen($file->getRealPath(), 'r+');
Expand Down Expand Up @@ -275,13 +244,13 @@ public function deleteValidation($uid)
$em->flush();

$fs = new FileSystem();
$validationDirectory = $this->storage->getDirectory($validation) ;
$validationDirectory = $this->storage->getDirectory($validation);
if ($fs->exists($validationDirectory)) {
$fs->remove($validationDirectory);
}

// Delete from storage
if ($this->dataStorage->directoryExists($validationDirectory)){
if ($this->dataStorage->directoryExists($validationDirectory)) {
$this->dataStorage->deleteDirectory($validationDirectory);
}

Expand Down Expand Up @@ -314,7 +283,7 @@ public function downloadNormalizedData($uid)
throw new ApiException("Validation hasn't been executed yet", Response::HTTP_FORBIDDEN);
}

$validationDirectory = $this->storage->getDirectory($validation) ;
$validationDirectory = $this->storage->getDirectory($validation);
$zipFilepath = $validationDirectory . '/validation/' . $validation->getDatasetName() . '.zip';
return $this->getDownloadResponse($zipFilepath, $validation->getDatasetName() . "-normalized.zip");
}
Expand All @@ -337,7 +306,7 @@ public function downloadSourceData($uid)
throw new ApiException("Validation has been archived", Response::HTTP_FORBIDDEN);
}

$uploadDirectory = $validation->getUid() . '/upload/' ;
$uploadDirectory = $validation->getUid() . '/upload/';
$zipFilepath = $uploadDirectory . $validation->getDatasetName() . '.zip';
return $this->getDownloadResponse($zipFilepath, $validation->getDatasetName() . "-source.zip");
}
Expand All @@ -351,7 +320,7 @@ public function downloadSourceData($uid)
*/
private function getDownloadResponse($filepath, $filename)
{
if (! $this->dataStorage->has($filepath)) {
if (!$this->dataStorage->has($filepath)) {
throw new ApiException("Requested files not found for this validation", Response::HTTP_FORBIDDEN);
}

Expand All @@ -361,7 +330,8 @@ private function getDownloadResponse($filepath, $filename)
fpassthru($stream);
exit();
}, 200, [
'Content-Transfer-Encoding', 'binary',
'Content-Transfer-Encoding',
'binary',
'Content-Type' => 'application/zip',
'Content-Disposition' => sprintf('attachment; filename="%s"', $filename),
'Content-Length' => fstat($stream)['size']
Expand Down

0 comments on commit 77cbb17

Please sign in to comment.