99use Drupal \os2forms_get_organized \Exception \ArchivingMethodException ;
1010use Drupal \os2forms_get_organized \Exception \CitizenArchivingException ;
1111use Drupal \os2forms_get_organized \Exception \GetOrganizedCaseIdException ;
12+ use Drupal \os2web_audit \Service \Logger ;
1213use Drupal \webform \Entity \WebformSubmission ;
1314use Drupal \webform_attachment \Element \WebformAttachmentBase ;
1415use ItkDev \GetOrganized \Client ;
@@ -44,27 +45,6 @@ class ArchiveHelper {
4445 */
4546 private ?Cases $ caseService = NULL ;
4647
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-
6848 /**
6949 * File element types.
7050 */
@@ -79,10 +59,12 @@ class ArchiveHelper {
7959 /**
8060 * Constructs an ArchiveHelper object.
8161 */
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+ ) {
8668 }
8769
8870 /**
@@ -303,9 +285,15 @@ private function createCitizenCase(string $cprElementValue, string $cprNameEleme
303285 if (empty ($ response )) {
304286 throw new CitizenArchivingException ('Could not create citizen case ' );
305287 }
288+
306289 // Example response.
307290 // {"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 ;
309297 }
310298
311299 /**
@@ -325,7 +313,12 @@ private function createSubCase(string $caseId, string $caseName): string {
325313
326314 // Example response.
327315 // {"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 ;
329322 }
330323
331324 /**
@@ -382,11 +375,19 @@ private function uploadDocumentToCase(string $caseId, string $webformAttachmentE
382375
383376 $ documentIdsForFinalizing = array_merge ($ documentIdsForFinalizing , $ childDocumentIds );
384377
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+ }
386384 }
387385
388386 if ($ shouldBeFinalized ) {
389387 $ this ->documentService ->FinalizeMultiple ($ documentIdsForFinalizing );
388+
389+ $ msg = sprintf ('Finalized documents %s ' , implode (', ' , $ documentIdsForFinalizing ));
390+ $ this ->auditLogger ->info ('GetOrganized ' , $ msg );
390391 }
391392 }
392393
@@ -427,6 +428,9 @@ private function archiveDocumentToGetOrganizedCase(string $caseId, string $getOr
427428 unlink ($ tempFile );
428429 }
429430
431+ $ msg = sprintf ('Archived document %s to GetOrganized case %s ' , $ getOrganizedFileName , $ caseId );
432+ $ this ->auditLogger ->info ('GetOrganized ' , $ msg );
433+
430434 return (int ) $ documentId ;
431435 }
432436
0 commit comments