1414use OCA \Files_Sharing \AppInfo \Application ;
1515use OCA \Files_Sharing \SharedStorage ;
1616use OCA \ShareByMail \ShareByMailProvider ;
17+ use OCP \EventDispatcher \Event ;
1718use OCP \EventDispatcher \IEventDispatcher ;
1819use OCP \Files \File ;
1920use OCP \Files \Folder ;
@@ -717,7 +718,7 @@ public function createShare(IShare $share) {
717718
718719 // Pre share event
719720 $ event = new Share \Events \BeforeShareCreatedEvent ($ share );
720- $ this ->dispatcher -> dispatchTyped ($ event );
721+ $ this ->dispatchEvent ($ event, ' before share created ' );
721722 if ($ event ->isPropagationStopped () && $ event ->getError ()) {
722723 throw new \Exception ($ event ->getError ());
723724 }
@@ -744,7 +745,7 @@ public function createShare(IShare $share) {
744745 }
745746
746747 // Post share event
747- $ this ->dispatcher -> dispatchTyped (new ShareCreatedEvent ($ share ));
748+ $ this ->dispatchEvent (new ShareCreatedEvent ($ share ), ' share created ' );
748749
749750 // Send email if needed
750751 if ($ this ->config ->getSystemValueBool ('sharing.enable_share_mail ' , true )) {
@@ -934,7 +935,7 @@ public function acceptShare(IShare $share, string $recipientId): IShare {
934935 $ provider ->acceptShare ($ share , $ recipientId );
935936
936937 $ event = new ShareAcceptedEvent ($ share );
937- $ this ->dispatcher -> dispatchTyped ($ event );
938+ $ this ->dispatchEvent ($ event, ' share accepted ' );
938939
939940 return $ share ;
940941 }
@@ -1016,13 +1017,13 @@ protected function deleteChildren(IShare $share) {
10161017 $ provider = $ this ->factory ->getProviderForType ($ share ->getShareType ());
10171018
10181019 foreach ($ provider ->getChildren ($ share ) as $ child ) {
1019- $ this ->dispatcher -> dispatchTyped (new BeforeShareDeletedEvent ($ child ));
1020+ $ this ->dispatchEvent (new BeforeShareDeletedEvent ($ child ), ' before share deleted ' );
10201021
10211022 $ deletedChildren = $ this ->deleteChildren ($ child );
10221023 $ deletedShares = array_merge ($ deletedShares , $ deletedChildren );
10231024
10241025 $ provider ->delete ($ child );
1025- $ this ->dispatcher -> dispatchTyped (new ShareDeletedEvent ($ child ));
1026+ $ this ->dispatchEvent (new ShareDeletedEvent ($ child ), ' share deleted ' );
10261027 $ deletedShares [] = $ child ;
10271028 }
10281029
@@ -1131,7 +1132,7 @@ public function deleteShare(IShare $share) {
11311132 throw new \InvalidArgumentException ($ this ->l ->t ('Share does not have a full ID ' ));
11321133 }
11331134
1134- $ this ->dispatcher -> dispatchTyped (new BeforeShareDeletedEvent ($ share ));
1135+ $ this ->dispatchEvent (new BeforeShareDeletedEvent ($ share ), ' before share deleted ' );
11351136
11361137 // Get all children and delete them as well
11371138 $ this ->deleteChildren ($ share );
@@ -1140,7 +1141,7 @@ public function deleteShare(IShare $share) {
11401141 $ provider = $ this ->factory ->getProviderForType ($ share ->getShareType ());
11411142 $ provider ->delete ($ share );
11421143
1143- $ this ->dispatcher -> dispatchTyped (new ShareDeletedEvent ($ share ));
1144+ $ this ->dispatchEvent (new ShareDeletedEvent ($ share ), ' share deleted ' );
11441145
11451146 // Promote reshares of the deleted share
11461147 $ this ->promoteReshares ($ share );
@@ -1162,7 +1163,7 @@ public function deleteFromSelf(IShare $share, $recipientId) {
11621163
11631164 $ provider ->deleteFromSelf ($ share , $ recipientId );
11641165 $ event = new ShareDeletedFromSelfEvent ($ share );
1165- $ this ->dispatcher -> dispatchTyped ($ event );
1166+ $ this ->dispatchEvent ($ event, ' leave share ' );
11661167 }
11671168
11681169 public function restoreShare (IShare $ share , string $ recipientId ): IShare {
@@ -2063,4 +2064,12 @@ public function generateToken(): string {
20632064
20642065 return $ token ;
20652066 }
2067+
2068+ private function dispatchEvent (Event $ event , string $ name ): void {
2069+ try {
2070+ $ this ->dispatcher ->dispatchTyped ($ event );
2071+ } catch (\Exception $ e ) {
2072+ $ this ->logger ->error ("Error while sending ' . $ name . ' event " , ['exception ' => $ e ]);
2073+ }
2074+ }
20662075}
0 commit comments