11
11
use Drupal \os2forms_fasit \Exception \InvalidSettingException ;
12
12
use Drupal \os2forms_fasit \Exception \InvalidSubmissionException ;
13
13
use Drupal \os2forms_fasit \Plugin \WebformHandler \FasitWebformHandler ;
14
+ use Drupal \os2web_audit \Service \Logger ;
14
15
use Drupal \webform \Entity \WebformSubmission ;
15
16
use GuzzleHttp \ClientInterface ;
16
17
use GuzzleHttp \Exception \GuzzleException ;
@@ -33,7 +34,13 @@ class FasitHelper {
33
34
'managed_file ' ,
34
35
];
35
36
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
+ ) {
37
44
}
38
45
39
46
/**
@@ -231,6 +238,9 @@ private function uploadDocument(array $uploads, string $submissionId, array $han
231
238
if (Response::HTTP_OK !== $ response ->getStatusCode ()) {
232
239
throw new FasitResponseException (sprintf ('Expected status code 200, received %d ' , $ response ->getStatusCode ()));
233
240
}
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 );
234
244
}
235
245
236
246
/**
@@ -307,7 +317,7 @@ private function uploadAttachment(string $submissionId, array $handlerConfigurat
307
317
$ tempAttachmentFilename = tempnam (sys_get_temp_dir (), 'attachment ' );
308
318
file_put_contents ($ tempAttachmentFilename , $ fileContent );
309
319
310
- return $ this ->uploadFile ($ fileName , $ tempAttachmentFilename );
320
+ return $ this ->uploadFile ($ fileName , $ tempAttachmentFilename, $ submission -> getWebform ()-> id () );
311
321
}
312
322
313
323
/**
@@ -317,6 +327,8 @@ private function uploadAttachment(string $submissionId, array $handlerConfigurat
317
327
* The original filename.
318
328
* @param string $tempFilename
319
329
* The temp filename.
330
+ * @param string $webformId
331
+ * The webform id.
320
332
*
321
333
* @throws \Drupal\os2forms_fasit\Exception\CertificateLocatorException
322
334
* Certificate locator exception.
@@ -325,7 +337,7 @@ private function uploadAttachment(string $submissionId, array $handlerConfigurat
325
337
*
326
338
* @phpstan-return array<string, mixed>
327
339
*/
328
- private function uploadFile (string $ originalFilename , string $ tempFilename ): array {
340
+ private function uploadFile (string $ originalFilename , string $ tempFilename, string $ webformId ): array {
329
341
$ endpoint = sprintf ('%s/%s/%s/documents/%s ' ,
330
342
$ this ->settings ->getFasitApiBaseUrl (),
331
343
$ this ->settings ->getFasitApiTenant (),
@@ -371,6 +383,12 @@ private function uploadFile(string $originalFilename, string $tempFilename): arr
371
383
throw new FasitResponseException ('Could not get upload id from response ' );
372
384
}
373
385
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
+
374
392
return ['filename ' => $ originalFilename , 'id ' => $ content ['id ' ]];
375
393
}
376
394
@@ -392,6 +410,7 @@ private function uploadFileElements(string $submissionId): array {
392
410
// Fetch element ids that may contain pdf files.
393
411
/** @var \Drupal\webform\Entity\WebformSubmission $submission */
394
412
$ submission = $ this ->getSubmission ($ submissionId );
413
+ $ webformId = $ submission ->getWebform ()->id ();
395
414
$ fileIds = $ this ->getFileElementKeysFromSubmission ($ submission );
396
415
$ fileStorage = $ this ->entityTypeManager ->getStorage ('file ' );
397
416
@@ -412,7 +431,7 @@ private function uploadFileElements(string $submissionId): array {
412
431
$ tempFilename = tempnam (sys_get_temp_dir (), 'attachment ' );
413
432
file_put_contents ($ tempFilename , $ fileContent );
414
433
415
- $ uploads [] = $ this ->uploadFile ($ filename , $ tempFilename );
434
+ $ uploads [] = $ this ->uploadFile ($ filename , $ tempFilename, $ webformId );
416
435
}
417
436
418
437
return $ uploads ;
0 commit comments