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,15 +327,17 @@ private function uploadAttachment(string $submissionId, array $handlerConfigurat
317327 * The original filename.
318328 * @param string $tempFilename
319329 * The temp filename.
320- *
330+ * @param string $webformId
331+ * The webform id.
332+ *
321333 * @throws \Drupal\os2forms_fasit\Exception\CertificateLocatorException
322334 * Certificate locator exception.
323335 * @throws \Drupal\os2forms_fasit\Exception\FasitResponseException
324336 * Fasit response exception.
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,11 @@ 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 to a citizen case in Fasit yet.
387+ // This is done later by uploadDocument. The file has simply been made ready.
388+ $ msg = sprintf ('Successfully uploaded file %s to Fasit. Webform id: %s ' , $ originalFilename , $ webformId );
389+ $ this ->auditLogger ->info ('Fasit ' , $ msg );
390+
374391 return ['filename ' => $ originalFilename , 'id ' => $ content ['id ' ]];
375392 }
376393
@@ -392,6 +409,7 @@ private function uploadFileElements(string $submissionId): array {
392409 // Fetch element ids that may contain pdf files.
393410 /** @var \Drupal\webform\Entity\WebformSubmission $submission */
394411 $ submission = $ this ->getSubmission ($ submissionId );
412+ $ webformId = $ submission ->getWebform ()->id ();
395413 $ fileIds = $ this ->getFileElementKeysFromSubmission ($ submission );
396414 $ fileStorage = $ this ->entityTypeManager ->getStorage ('file ' );
397415
@@ -412,7 +430,7 @@ private function uploadFileElements(string $submissionId): array {
412430 $ tempFilename = tempnam (sys_get_temp_dir (), 'attachment ' );
413431 file_put_contents ($ tempFilename , $ fileContent );
414432
415- $ uploads [] = $ this ->uploadFile ($ filename , $ tempFilename );
433+ $ uploads [] = $ this ->uploadFile ($ filename , $ tempFilename, $ webformId );
416434 }
417435
418436 return $ uploads ;
0 commit comments