Submit generated study_id to Umfragetool backend

This commit is contained in:
Marko Jovanovic 2025-10-16 15:07:02 +02:00
parent 2aff09e6ba
commit c6eb662e5e
3 changed files with 35 additions and 8 deletions

12
composer.lock generated
View File

@ -2731,16 +2731,16 @@
}, },
{ {
"name": "symfony/http-client", "name": "symfony/http-client",
"version": "v7.3.3", "version": "v7.3.4",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/http-client.git", "url": "https://github.com/symfony/http-client.git",
"reference": "333b9bd7639cbdaecd25a3a48a9d2dcfaa86e019" "reference": "4b62871a01c49457cf2a8e560af7ee8a94b87a62"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/http-client/zipball/333b9bd7639cbdaecd25a3a48a9d2dcfaa86e019", "url": "https://api.github.com/repos/symfony/http-client/zipball/4b62871a01c49457cf2a8e560af7ee8a94b87a62",
"reference": "333b9bd7639cbdaecd25a3a48a9d2dcfaa86e019", "reference": "4b62871a01c49457cf2a8e560af7ee8a94b87a62",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2807,7 +2807,7 @@
"http" "http"
], ],
"support": { "support": {
"source": "https://github.com/symfony/http-client/tree/v7.3.3" "source": "https://github.com/symfony/http-client/tree/v7.3.4"
}, },
"funding": [ "funding": [
{ {
@ -2827,7 +2827,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2025-08-27T07:45:05+00:00" "time": "2025-09-11T10:12:26+00:00"
}, },
{ {
"name": "symfony/http-client-contracts", "name": "symfony/http-client-contracts",

View File

@ -15,6 +15,8 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
/** /**
* Normalises German mobile numbers from a CSV and stores the valid ones in the DB. * Normalises German mobile numbers from a CSV and stores the valid ones in the DB.
@ -28,6 +30,9 @@ use Symfony\Component\Console\Style\SymfonyStyle;
)] )]
final class CleanMobileCommand extends Command final class CleanMobileCommand extends Command
{ {
private HttpClientInterface $http;
private string $backendApiURL = 'https://umfragetool.ukbonn.de/api/api/participant/create-qm-befr-participant';
public function __construct( public function __construct(
private readonly EntityManagerInterface $em private readonly EntityManagerInterface $em
) { ) {
@ -151,6 +156,7 @@ final class CleanMobileCommand extends Command
$validContacts = []; $validContacts = [];
$rowCount = 0; $rowCount = 0;
$invalid = 0; $invalid = 0;
$backendErrorCount = 0;
foreach ($csvReader->getRecords() as $row) { foreach ($csvReader->getRecords() as $row) {
$rowCount++; $rowCount++;
@ -185,6 +191,7 @@ final class CleanMobileCommand extends Command
if ($row['HANDY_E164']) { if ($row['HANDY_E164']) {
$uuid = Uuid::v4(); $uuid = Uuid::v4();
$study_id = "QMBEFR-" . $uuid->toString();
// Create a Contact entity for DB insertion // Create a Contact entity for DB insertion
$contact = new Contacts(); $contact = new Contacts();
@ -194,10 +201,20 @@ final class CleanMobileCommand extends Command
$contact->setContacted(false); $contact->setContacted(false);
$contact->setParsedFilename($inputPath); $contact->setParsedFilename($inputPath);
$contact->setParsedAt(new \DateTimeImmutable()); $contact->setParsedAt(new \DateTimeImmutable());
$contact->setStudyId($uuid->toString()); $contact->setStudyId($study_id);
$contact->setParsedFileLinenum($rowCount + 1); $contact->setParsedFileLinenum($rowCount + 1);
$contact->setParsedFileLine(implode(';', $row)); $contact->setParsedFileLine(implode(';', $row));
$validContacts[] = $contact;
try {
$this->http->request('POST', $this->backendApiURL . "/" . $study_id, [
'body' => '',
'headers' => [],
]);
$validContacts[] = $contact;
} catch (TransportExceptionInterface $e) {
$backendErrorCount++;
}
} }
$csvWriter->insertOne($row); $csvWriter->insertOne($row);
@ -227,6 +244,7 @@ final class CleanMobileCommand extends Command
"Rows read : $rowCount", "Rows read : $rowCount",
"Valid mobile numbers : " . \count($validContacts), "Valid mobile numbers : " . \count($validContacts),
"Invalid / empty numbers : $invalid", "Invalid / empty numbers : $invalid",
"Could not contact backend for numbers : $backendErrorCount" ,
"Cleaned CSV written to : $outputPath", "Cleaned CSV written to : $outputPath",
]); ]);

View File

@ -101,5 +101,14 @@
"config/packages/routing.yaml", "config/packages/routing.yaml",
"config/routes.yaml" "config/routes.yaml"
] ]
},
"symfony/uid": {
"version": "7.3",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "7.0",
"ref": "0df5844274d871b37fc3816c57a768ffc60a43a5"
}
} }
} }