@@ -637,11 +637,12 @@ private function getSignRequestByIdentifyMethod(IIdentifyMethod $identifyMethod,
637637 }
638638
639639 public function unassociateToUser (int $ fileId , int $ signRequestId ): void {
640- $ signRequest = $ this ->signRequestMapper ->getByFileIdAndSignRequestId ($ fileId , $ signRequestId );
640+ $ file = $ this ->fileMapper ->getByFileId ($ fileId );
641+ $ signRequest = $ this ->signRequestMapper ->getByFileIdAndSignRequestId ($ file ->getId (), $ signRequestId );
641642 $ deletedOrder = $ signRequest ->getSigningOrder ();
642643 $ groupedIdentifyMethods = $ this ->identifyMethod ->getIdentifyMethodsFromSignRequestId ($ signRequestId );
643644
644- $ this ->dispatchCancellationEventIfNeeded ($ signRequest , $ fileId , $ groupedIdentifyMethods );
645+ $ this ->dispatchCancellationEventIfNeeded ($ signRequest , $ file -> getId () , $ groupedIdentifyMethods );
645646
646647 try {
647648 $ this ->signRequestMapper ->delete ($ signRequest );
@@ -650,16 +651,46 @@ public function unassociateToUser(int $fileId, int $signRequestId): void {
650651 $ identifyMethod ->delete ();
651652 }
652653 }
653- $ visibleElements = $ this ->fileElementMapper ->getByFileIdAndSignRequestId ($ fileId , $ signRequestId );
654+ $ visibleElements = $ this ->fileElementMapper ->getByFileIdAndSignRequestId ($ file -> getId () , $ signRequestId );
654655 foreach ($ visibleElements as $ visibleElement ) {
655656 $ this ->fileElementMapper ->delete ($ visibleElement );
656657 }
657658
658- $ this ->sequentialSigningService ->reorderAfterDeletion ($ fileId , $ deletedOrder );
659+ $ this ->sequentialSigningService ->reorderAfterDeletion ($ file ->getId (), $ deletedOrder );
660+
661+ $ this ->propagateSignerDeletionToChildren ($ file , $ signRequest );
659662 } catch (\Throwable ) {
660663 }
661664 }
662665
666+ private function propagateSignerDeletionToChildren (FileEntity $ envelope , SignRequestEntity $ deletedSignRequest ): void {
667+ if ($ envelope ->getNodeType () !== 'envelope ' ) {
668+ return ;
669+ }
670+
671+ $ children = $ this ->fileMapper ->getChildrenFiles ($ envelope ->getId ());
672+
673+ $ identifyMethods = $ this ->identifyMethod ->getIdentifyMethodsFromSignRequestId ($ deletedSignRequest ->getId ());
674+ if (empty ($ identifyMethods )) {
675+ return ;
676+ }
677+
678+ foreach ($ children as $ child ) {
679+ try {
680+ $ childSignRequest = $ this ->getSignRequestByIdentifyMethod (
681+ current (reset ($ identifyMethods )),
682+ $ child ->getId ()
683+ );
684+
685+ if ($ childSignRequest ->getId ()) {
686+ $ this ->unassociateToUser ($ child ->getNodeId (), $ childSignRequest ->getId ());
687+ }
688+ } catch (\Throwable $ e ) {
689+ continue ;
690+ }
691+ }
692+ }
693+
663694 private function dispatchCancellationEventIfNeeded (
664695 SignRequestEntity $ signRequest ,
665696 int $ fileId ,
0 commit comments