9
9
use Drupal \os2forms_get_organized \Exception \ArchivingMethodException ;
10
10
use Drupal \os2forms_get_organized \Exception \CitizenArchivingException ;
11
11
use Drupal \os2forms_get_organized \Exception \GetOrganizedCaseIdException ;
12
+ use Drupal \os2web_audit \Service \Logger ;
12
13
use Drupal \webform \Entity \WebformSubmission ;
13
14
use Drupal \webform_attachment \Element \WebformAttachmentBase ;
14
15
use ItkDev \GetOrganized \Client ;
@@ -44,27 +45,6 @@ class ArchiveHelper {
44
45
*/
45
46
private ?Cases $ caseService = NULL ;
46
47
47
- /**
48
- * The EntityTypeManagerInterface.
49
- *
50
- * @var \Drupal\Core\Entity\EntityTypeManagerInterface
51
- */
52
- private EntityTypeManagerInterface $ entityTypeManager ;
53
-
54
- /**
55
- * The EventDispatcherInterface.
56
- *
57
- * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
58
- */
59
- private EventDispatcherInterface $ eventDispatcher ;
60
-
61
- /**
62
- * The settings.
63
- *
64
- * @var \Drupal\os2forms_get_organized\Helper\Settings
65
- */
66
- private Settings $ settings ;
67
-
68
48
/**
69
49
* File element types.
70
50
*/
@@ -79,10 +59,12 @@ class ArchiveHelper {
79
59
/**
80
60
* Constructs an ArchiveHelper object.
81
61
*/
82
- public function __construct (EntityTypeManagerInterface $ entityTypeManager , EventDispatcherInterface $ eventDispatcher , Settings $ settings ) {
83
- $ this ->entityTypeManager = $ entityTypeManager ;
84
- $ this ->eventDispatcher = $ eventDispatcher ;
85
- $ this ->settings = $ settings ;
62
+ public function __construct (
63
+ private readonly EntityTypeManagerInterface $ entityTypeManager ,
64
+ private readonly EventDispatcherInterface $ eventDispatcher ,
65
+ private readonly Settings $ settings ,
66
+ private readonly Logger $ auditLogger ,
67
+ ) {
86
68
}
87
69
88
70
/**
@@ -303,9 +285,15 @@ private function createCitizenCase(string $cprElementValue, string $cprNameEleme
303
285
if (empty ($ response )) {
304
286
throw new CitizenArchivingException ('Could not create citizen case ' );
305
287
}
288
+
306
289
// Example response.
307
290
// {"CaseID":"BOR-2022-000046","CaseRelativeUrl":"\/cases\/BOR12\/BOR-2022-000046",...}.
308
- return $ response ['CaseID ' ];
291
+ $ caseId = $ response ['CaseID ' ];
292
+
293
+ $ msg = sprintf ('Created GetOrganized case %s ' , $ caseId );
294
+ $ this ->auditLogger ->info ('GetOrganized ' , $ msg );
295
+
296
+ return $ caseId ;
309
297
}
310
298
311
299
/**
@@ -325,7 +313,12 @@ private function createSubCase(string $caseId, string $caseName): string {
325
313
326
314
// Example response.
327
315
// {"CaseID":"BOR-2022-000046-001","CaseRelativeUrl":"\/cases\/BOR12\/BOR-2022-000046",...}.
328
- return $ response ['CaseID ' ];
316
+ $ caseId = $ response ['CaseID ' ];
317
+
318
+ $ msg = sprintf ('Created GetOrganized case %s ' , $ caseId );
319
+ $ this ->auditLogger ->info ('GetOrganized ' , $ msg );
320
+
321
+ return $ caseId ;
329
322
}
330
323
331
324
/**
@@ -382,11 +375,19 @@ private function uploadDocumentToCase(string $caseId, string $webformAttachmentE
382
375
383
376
$ documentIdsForFinalizing = array_merge ($ documentIdsForFinalizing , $ childDocumentIds );
384
377
385
- $ this ->documentService ->RelateDocuments ($ parentDocumentId , $ childDocumentIds , 1 );
378
+ if (!empty ($ childDocumentIds )) {
379
+ $ this ->documentService ->RelateDocuments ($ parentDocumentId , $ childDocumentIds , 1 );
380
+
381
+ $ msg = sprintf ('Added relation between document %s and documents %s ' , $ parentDocumentId , implode (', ' , $ childDocumentIds ));
382
+ $ this ->auditLogger ->info ('GetOrganized ' , $ msg );
383
+ }
386
384
}
387
385
388
386
if ($ shouldBeFinalized ) {
389
387
$ this ->documentService ->FinalizeMultiple ($ documentIdsForFinalizing );
388
+
389
+ $ msg = sprintf ('Finalized documents %s ' , implode (', ' , $ documentIdsForFinalizing ));
390
+ $ this ->auditLogger ->info ('GetOrganized ' , $ msg );
390
391
}
391
392
}
392
393
@@ -427,6 +428,9 @@ private function archiveDocumentToGetOrganizedCase(string $caseId, string $getOr
427
428
unlink ($ tempFile );
428
429
}
429
430
431
+ $ msg = sprintf ('Archived document %s to GetOrganized case %s ' , $ getOrganizedFileName , $ caseId );
432
+ $ this ->auditLogger ->info ('GetOrganized ' , $ msg );
433
+
430
434
return (int ) $ documentId ;
431
435
}
432
436
0 commit comments