@@ -482,28 +482,11 @@ private function getSignRequestByIdentifyMethod(IIdentifyMethod $identifyMethod,
482482 public function unassociateToUser (int $ fileId , int $ signRequestId ): void {
483483 $ signRequest = $ this ->signRequestMapper ->getByFileIdAndSignRequestId ($ fileId , $ signRequestId );
484484 $ deletedOrder = $ signRequest ->getSigningOrder ();
485-
486- // Get identify methods before deletion
487485 $ groupedIdentifyMethods = $ this ->identifyMethod ->getIdentifyMethodsFromSignRequestId ($ signRequestId );
488486
489- // Dispatch canceled event if status is ABLE_TO_SIGN (1)
490- if ($ signRequest ->getStatus () === \OCA \Libresign \Enum \SignRequestStatus::ABLE_TO_SIGN ->value ) {
491- try {
492- $ libreSignFile = $ this ->fileMapper ->getByFileId ($ fileId );
493- foreach ($ groupedIdentifyMethods as $ identifyMethods ) {
494- foreach ($ identifyMethods as $ identifyMethod ) {
495- $ event = new SignRequestCanceledEvent (
496- $ signRequest ,
497- $ libreSignFile ,
498- $ identifyMethod ,
499- );
500- $ this ->eventDispatcher ->dispatchTyped ($ event );
501- }
502- }
503- } catch (\Throwable $ e ) {
504- $ this ->logger ->error ('Error dispatching SignRequestCanceledEvent: ' . $ e ->getMessage (), ['exception ' => $ e ]);
505- }
506- } try {
487+ $ this ->dispatchCancellationEventIfNeeded ($ signRequest , $ fileId , $ groupedIdentifyMethods );
488+
489+ try {
507490 $ this ->signRequestMapper ->delete ($ signRequest );
508491 foreach ($ groupedIdentifyMethods as $ identifyMethods ) {
509492 foreach ($ identifyMethods as $ identifyMethod ) {
@@ -520,6 +503,32 @@ public function unassociateToUser(int $fileId, int $signRequestId): void {
520503 }
521504 }
522505
506+ private function dispatchCancellationEventIfNeeded (
507+ SignRequestEntity $ signRequest ,
508+ int $ fileId ,
509+ array $ groupedIdentifyMethods
510+ ): void {
511+ if ($ signRequest ->getStatus () !== \OCA \Libresign \Enum \SignRequestStatus::ABLE_TO_SIGN ->value ) {
512+ return ;
513+ }
514+
515+ try {
516+ $ libreSignFile = $ this ->fileMapper ->getByFileId ($ fileId );
517+ foreach ($ groupedIdentifyMethods as $ identifyMethods ) {
518+ foreach ($ identifyMethods as $ identifyMethod ) {
519+ $ event = new SignRequestCanceledEvent (
520+ $ signRequest ,
521+ $ libreSignFile ,
522+ $ identifyMethod ,
523+ );
524+ $ this ->eventDispatcher ->dispatchTyped ($ event );
525+ }
526+ }
527+ } catch (\Throwable $ e ) {
528+ $ this ->logger ->error ('Error dispatching SignRequestCanceledEvent: ' . $ e ->getMessage (), ['exception ' => $ e ]);
529+ }
530+ }
531+
523532 public function deleteRequestSignature (array $ data ): void {
524533 if (!empty ($ data ['uuid ' ])) {
525534 $ signatures = $ this ->signRequestMapper ->getByFileUuid ($ data ['uuid ' ]);
0 commit comments