@@ -379,12 +379,12 @@ private function getFileMetadata(\OCP\Files\Node $node): array {
379379 'extension ' => $ extension ,
380380 ];
381381 if ($ metadata ['extension ' ] === 'pdf ' ) {
382+ $ pdfParser = $ this ->pdfParserService ->setFile ($ node );
382383 $ metadata = array_merge (
383384 $ metadata ,
384- $ this ->pdfParserService
385- ->setFile ($ node )
386- ->getPageDimensions ()
385+ $ pdfParser ->getPageDimensions ()
387386 );
387+ $ metadata ['pdfVersion ' ] = $ pdfParser ->getPdfVersion ();
388388 }
389389 }
390390 return $ metadata ;
@@ -503,62 +503,26 @@ private function saveVisibleElements(array $data, FileEntity $file): array {
503503 }
504504 $ persisted = [];
505505 foreach ($ data ['visibleElements ' ] as $ element ) {
506- $ toPersist = $ this ->buildPropagatedElements ($ file , $ element );
507- foreach ($ toPersist as $ item ) {
508- $ persisted [] = $ this ->fileElementService ->saveVisibleElement ($ item );
509- }
510- }
511- return $ persisted ;
512- }
513-
514- private function buildPropagatedElements (FileEntity $ file , array $ element ): array {
515- $ targetFileId = null ;
516- if (!empty ($ element ['fileId ' ])) {
517- $ targetFileId = (int )$ element ['fileId ' ];
518- } elseif (!empty ($ element ['uuid ' ])) {
519- try {
520- $ targetFile = $ this ->fileMapper ->getByUuid ($ element ['uuid ' ]);
521- $ targetFileId = $ targetFile ->getId ();
522- $ element ['fileId ' ] = $ targetFileId ;
523- unset($ element ['uuid ' ]);
524- } catch (\Throwable ) {
525- $ targetFileId = null ;
526- }
527- }
528-
529- if ($ file ->isEnvelope () && !empty ($ element ['signRequestId ' ])) {
530- $ childrenSignRequests = $ this ->signRequestMapper ->getByEnvelopeChildrenAndIdentifyMethod ($ file ->getId (), (int )$ element ['signRequestId ' ]);
531- if (empty ($ childrenSignRequests )) {
532- $ identifyMethods = $ this ->identifyMethod ->getIdentifyMethodsFromSignRequestId ((int )$ element ['signRequestId ' ]);
533- $ firstIdentifyMethodGroup = current (reset ($ identifyMethods ));
534- $ childFiles = $ this ->fileMapper ->getChildrenFiles ($ file ->getId ());
535- foreach ($ childFiles as $ childFile ) {
536- $ childSr = $ this ->signRequestService ->getSignRequestByIdentifyMethod ($ firstIdentifyMethodGroup , $ childFile ->getId ());
537- if ($ childSr && $ childSr ->getId ()) {
538- $ childrenSignRequests [] = $ childSr ;
506+ if ($ file ->isEnvelope () && !empty ($ element ['signRequestId ' ])) {
507+ $ envelopeSignRequest = $ this ->signRequestMapper ->getById ((int )$ element ['signRequestId ' ]);
508+ // Only translate if the provided SR belongs to the envelope itself
509+ if ($ envelopeSignRequest && $ envelopeSignRequest ->getFileId () === $ file ->getId ()) {
510+ $ childrenSrs = $ this ->signRequestMapper ->getByEnvelopeChildrenAndIdentifyMethod ($ file ->getId (), (int )$ element ['signRequestId ' ]);
511+ foreach ($ childrenSrs as $ childSr ) {
512+ if ($ childSr ->getFileId () === (int )$ element ['fileId ' ]) {
513+ $ element ['signRequestId ' ] = $ childSr ->getId ();
514+ break ;
515+ }
539516 }
540517 }
541518 }
542519
543- $ persistList = [];
544- $ envelopeElement = $ element ;
545- $ envelopeElement ['fileId ' ] = $ file ->getId ();
546- unset($ envelopeElement ['uuid ' ]);
547- $ persistList [] = $ envelopeElement ;
548-
549- foreach ($ childrenSignRequests as $ childSignRequest ) {
550- $ clone = $ element ;
551- $ clone ['signRequestId ' ] = $ childSignRequest ->getId ();
552- $ clone ['fileId ' ] = $ childSignRequest ->getFileId ();
553- unset($ clone ['uuid ' ]);
554- $ persistList [] = $ clone ;
555- }
556- return $ persistList ;
520+ $ persisted [] = $ this ->fileElementService ->saveVisibleElement ($ element );
557521 }
558-
559- return [$ element ];
522+ return $ persisted ;
560523 }
561524
525+
562526 public function validateNewRequestToFile (array $ data ): void {
563527 $ this ->validateNewFile ($ data );
564528 $ this ->validateUsers ($ data );
0 commit comments