3434use OCP \Search \ISearchQuery ;
3535use OCP \Security \ISecureRandom ;
3636use OCP \Share \IShare ;
37+ use Psr \Log \LoggerInterface ;
3738
3839/**
3940 * Trait for getting forms information in a service
@@ -62,6 +63,7 @@ public function __construct(
6263 private IRootFolder $ rootFolder ,
6364 private IL10N $ l10n ,
6465 private IEventDispatcher $ eventDispatcher ,
66+ private LoggerInterface $ logger ,
6567 ) {
6668 $ this ->currentUser = $ userSession ->getUser ();
6769 }
@@ -562,19 +564,30 @@ public function getShareDisplayName(array $share): string {
562564 * @param Share $share The new Share
563565 */
564566 public function notifyNewShares (Form $ form , Share $ share ): void {
565- switch ($ share ->getShareType ()) {
566- case IShare::TYPE_USER :
567- $ this ->activityManager ->publishNewShare ($ form , $ share ->getShareWith ());
568- break ;
569- case IShare::TYPE_GROUP :
570- $ this ->activityManager ->publishNewGroupShare ($ form , $ share ->getShareWith ());
571- break ;
572- case IShare::TYPE_CIRCLE :
573- $ this ->activityManager ->publishNewCircleShare ($ form , $ share ->getShareWith ());
574- break ;
575- default :
576- // Do nothing.
567+ try {
568+ switch ($ share ->getShareType ()) {
569+ case IShare::TYPE_USER :
570+ $ this ->activityManager ->publishNewShare ($ form , $ share ->getShareWith ());
571+ break ;
572+ case IShare::TYPE_GROUP :
573+ $ this ->activityManager ->publishNewGroupShare ($ form , $ share ->getShareWith ());
574+ break ;
575+ case IShare::TYPE_CIRCLE :
576+ $ this ->activityManager ->publishNewCircleShare ($ form , $ share ->getShareWith ());
577+ break ;
578+ default :
579+ // Do nothing.
580+ }
581+ } catch (\Exception $ e ) {
582+ // Handle exceptions silently, as this is not critical.
583+ // We don't want to break the share creation process just because of an activity error.
584+ $ this ->logger ->error (
585+ 'Error while publishing new share activity ' ,
586+ [$ e ]
587+ );
588+
577589 }
590+
578591 }
579592
580593 /**
@@ -585,14 +598,31 @@ public function notifyNewShares(Form $form, Share $share): void {
585598 */
586599 public function notifyNewSubmission (Form $ form , Submission $ submission ): void {
587600 $ shares = $ this ->getShares ($ form ->getId ());
588- $ this ->activityManager ->publishNewSubmission ($ form , $ submission ->getUserId ());
601+ try {
602+ $ this ->activityManager ->publishNewSubmission ($ form , $ submission ->getUserId ());
603+ } catch (\Exception $ e ) {
604+ // Handle exceptions silently, as this is not critical.
605+ // We don't want to break the submission process just because of an activity error.
606+ $ this ->logger ->error (
607+ 'Error while publishing new submission activity ' ,
608+ [$ e ]
609+ );
610+ }
589611
590612 foreach ($ shares as $ share ) {
591613 if (!in_array (Constants::PERMISSION_RESULTS , $ share ['permissions ' ])) {
592614 continue ;
593615 }
594-
595- $ this ->activityManager ->publishNewSharedSubmission ($ form , $ share ['shareType ' ], $ share ['shareWith ' ], $ submission ->getUserId ());
616+ try {
617+ $ this ->activityManager ->publishNewSharedSubmission ($ form , $ share ['shareType ' ], $ share ['shareWith ' ], $ submission ->getUserId ());
618+ } catch (\Exception $ e ) {
619+ // Handle exceptions silently, as this is not critical.
620+ // We don't want to break the submission process just because of an activity error.
621+ $ this ->logger ->error (
622+ 'Error while publishing new shared submission activity ' ,
623+ [$ e ]
624+ );
625+ }
596626 }
597627
598628 $ this ->eventDispatcher ->dispatchTyped (new FormSubmittedEvent ($ form , $ submission ));
0 commit comments