1111use Drupal \os2forms_fasit \Exception \InvalidSettingException ;
1212use Drupal \os2forms_fasit \Exception \InvalidSubmissionException ;
1313use Drupal \os2forms_fasit \Plugin \WebformHandler \FasitWebformHandler ;
14+ use Drupal \os2web_audit \Service \Logger ;
1415use Drupal \webform \Entity \WebformSubmission ;
1516use GuzzleHttp \ClientInterface ;
1617use GuzzleHttp \Exception \GuzzleException ;
@@ -33,7 +34,13 @@ class FasitHelper {
3334 'managed_file ' ,
3435 ];
3536
36- public function __construct (private readonly ClientInterface $ client , private readonly EntityTypeManagerInterface $ entityTypeManager , private readonly Settings $ settings , private readonly CertificateLocatorHelper $ certificateLocator ) {
37+ public function __construct (
38+ private readonly ClientInterface $ client ,
39+ private readonly EntityTypeManagerInterface $ entityTypeManager ,
40+ private readonly Settings $ settings ,
41+ private readonly CertificateLocatorHelper $ certificateLocator ,
42+ private readonly Logger $ auditLogger ,
43+ ) {
3744 }
3845
3946 /**
@@ -231,6 +238,9 @@ private function uploadDocument(array $uploads, string $submissionId, array $han
231238 if (Response::HTTP_OK !== $ response ->getStatusCode ()) {
232239 throw new FasitResponseException (sprintf ('Expected status code 200, received %d ' , $ response ->getStatusCode ()));
233240 }
241+
242+ $ msg = sprintf ('Successfully uploaded document %s to cpr %s in Fasit. Webform id %s. ' , $ fasitDocumentTitle , $ fasitCpr , $ submission ->getWebform ()->id ());
243+ $ this ->auditLogger ->info ('Fasit ' , $ msg );
234244 }
235245
236246 /**
@@ -307,7 +317,7 @@ private function uploadAttachment(string $submissionId, array $handlerConfigurat
307317 $ tempAttachmentFilename = tempnam (sys_get_temp_dir (), 'attachment ' );
308318 file_put_contents ($ tempAttachmentFilename , $ fileContent );
309319
310- return $ this ->uploadFile ($ fileName , $ tempAttachmentFilename );
320+ return $ this ->uploadFile ($ fileName , $ tempAttachmentFilename, $ submission -> getWebform ()-> id () );
311321 }
312322
313323 /**
@@ -317,6 +327,8 @@ private function uploadAttachment(string $submissionId, array $handlerConfigurat
317327 * The original filename.
318328 * @param string $tempFilename
319329 * The temp filename.
330+ * @param string $webformId
331+ * The webform id.
320332 *
321333 * @throws \Drupal\os2forms_fasit\Exception\CertificateLocatorException
322334 * Certificate locator exception.
@@ -325,7 +337,7 @@ private function uploadAttachment(string $submissionId, array $handlerConfigurat
325337 *
326338 * @phpstan-return array<string, mixed>
327339 */
328- private function uploadFile (string $ originalFilename , string $ tempFilename ): array {
340+ private function uploadFile (string $ originalFilename , string $ tempFilename, string $ webformId ): array {
329341 $ endpoint = sprintf ('%s/%s/%s/documents/%s ' ,
330342 $ this ->settings ->getFasitApiBaseUrl (),
331343 $ this ->settings ->getFasitApiTenant (),
@@ -371,6 +383,12 @@ private function uploadFile(string $originalFilename, string $tempFilename): arr
371383 throw new FasitResponseException ('Could not get upload id from response ' );
372384 }
373385
386+ // Note, that this does not mean a document has been sent,
387+ // to a citizen case in Fasit yet. This is done later by uploadDocument.
388+ // The file has simply been made ready.
389+ $ msg = sprintf ('Successfully uploaded file %s to Fasit. Webform id %s. ' , $ originalFilename , $ webformId );
390+ $ this ->auditLogger ->info ('Fasit ' , $ msg );
391+
374392 return ['filename ' => $ originalFilename , 'id ' => $ content ['id ' ]];
375393 }
376394
@@ -392,6 +410,7 @@ private function uploadFileElements(string $submissionId): array {
392410 // Fetch element ids that may contain pdf files.
393411 /** @var \Drupal\webform\Entity\WebformSubmission $submission */
394412 $ submission = $ this ->getSubmission ($ submissionId );
413+ $ webformId = $ submission ->getWebform ()->id ();
395414 $ fileIds = $ this ->getFileElementKeysFromSubmission ($ submission );
396415 $ fileStorage = $ this ->entityTypeManager ->getStorage ('file ' );
397416
@@ -412,7 +431,7 @@ private function uploadFileElements(string $submissionId): array {
412431 $ tempFilename = tempnam (sys_get_temp_dir (), 'attachment ' );
413432 file_put_contents ($ tempFilename , $ fileContent );
414433
415- $ uploads [] = $ this ->uploadFile ($ filename , $ tempFilename );
434+ $ uploads [] = $ this ->uploadFile ($ filename , $ tempFilename, $ webformId );
416435 }
417436
418437 return $ uploads ;
0 commit comments