From c6eb662e5eb51a7fa8e15b919082e7cd5182af8c Mon Sep 17 00:00:00 2001 From: Marko Jovanovic Date: Thu, 16 Oct 2025 15:07:02 +0200 Subject: [PATCH] Submit generated study_id to Umfragetool backend --- composer.lock | 12 ++++++------ src/Command/CleanMobileCommand.php | 22 ++++++++++++++++++++-- symfony.lock | 9 +++++++++ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/composer.lock b/composer.lock index b5dd677..eb941a5 100644 --- a/composer.lock +++ b/composer.lock @@ -2731,16 +2731,16 @@ }, { "name": "symfony/http-client", - "version": "v7.3.3", + "version": "v7.3.4", "source": { "type": "git", "url": "https://github.com/symfony/http-client.git", - "reference": "333b9bd7639cbdaecd25a3a48a9d2dcfaa86e019" + "reference": "4b62871a01c49457cf2a8e560af7ee8a94b87a62" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client/zipball/333b9bd7639cbdaecd25a3a48a9d2dcfaa86e019", - "reference": "333b9bd7639cbdaecd25a3a48a9d2dcfaa86e019", + "url": "https://api.github.com/repos/symfony/http-client/zipball/4b62871a01c49457cf2a8e560af7ee8a94b87a62", + "reference": "4b62871a01c49457cf2a8e560af7ee8a94b87a62", "shasum": "" }, "require": { @@ -2807,7 +2807,7 @@ "http" ], "support": { - "source": "https://github.com/symfony/http-client/tree/v7.3.3" + "source": "https://github.com/symfony/http-client/tree/v7.3.4" }, "funding": [ { @@ -2827,7 +2827,7 @@ "type": "tidelift" } ], - "time": "2025-08-27T07:45:05+00:00" + "time": "2025-09-11T10:12:26+00:00" }, { "name": "symfony/http-client-contracts", diff --git a/src/Command/CleanMobileCommand.php b/src/Command/CleanMobileCommand.php index 346f570..2382b52 100644 --- a/src/Command/CleanMobileCommand.php +++ b/src/Command/CleanMobileCommand.php @@ -15,6 +15,8 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; 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. @@ -28,6 +30,9 @@ use Symfony\Component\Console\Style\SymfonyStyle; )] 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( private readonly EntityManagerInterface $em ) { @@ -151,6 +156,7 @@ final class CleanMobileCommand extends Command $validContacts = []; $rowCount = 0; $invalid = 0; + $backendErrorCount = 0; foreach ($csvReader->getRecords() as $row) { $rowCount++; @@ -185,6 +191,7 @@ final class CleanMobileCommand extends Command if ($row['HANDY_E164']) { $uuid = Uuid::v4(); + $study_id = "QMBEFR-" . $uuid->toString(); // Create a Contact entity for DB insertion $contact = new Contacts(); @@ -194,10 +201,20 @@ final class CleanMobileCommand extends Command $contact->setContacted(false); $contact->setParsedFilename($inputPath); $contact->setParsedAt(new \DateTimeImmutable()); - $contact->setStudyId($uuid->toString()); + $contact->setStudyId($study_id); $contact->setParsedFileLinenum($rowCount + 1); $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); @@ -227,6 +244,7 @@ final class CleanMobileCommand extends Command "Rows read : $rowCount", "Valid mobile numbers : " . \count($validContacts), "Invalid / empty numbers : $invalid", + "Could not contact backend for numbers : $backendErrorCount" , "Cleaned CSV written to : $outputPath", ]); diff --git a/symfony.lock b/symfony.lock index a2dcd60..0892883 100644 --- a/symfony.lock +++ b/symfony.lock @@ -101,5 +101,14 @@ "config/packages/routing.yaml", "config/routes.yaml" ] + }, + "symfony/uid": { + "version": "7.3", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "7.0", + "ref": "0df5844274d871b37fc3816c57a768ffc60a43a5" + } } }