@@ -171,43 +171,40 @@ public function create(IShare $share) {
171171 try {
172172 $ uidOwner = $ remoteShare ['owner ' ] . '@ ' . $ remoteShare ['remote ' ];
173173 $ shareId = $ this ->addShareToDB ($ itemSource , $ itemType , $ shareWith , $ sharedBy , $ uidOwner , $ permissions , 'tmp_token_ ' . time ());
174+ $ share ->setId ($ shareId );
174175 list ($ token , $ remoteId ) = $ this ->askOwnerToReShare ($ shareWith , $ share , $ shareId );
175176 // remote share was create successfully if we get a valid token as return
176177 $ send = is_string ($ token ) && $ token !== '' ;
177- if ($ send ) {
178- $ this ->updateSuccessfulReshare ($ shareId , $ token );
179- $ this ->storeRemoteId ($ shareId , $ remoteId );
180- }
181178 } catch (\Exception $ e ) {
182179 // fall back to old re-share behavior if the remote server
183180 // doesn't support flat re-shares (was introduced with ownCloud 9.1)
184- $ data = $ this ->getRawShare ($ shareId );
185- $ brokenShare = $ this ->createShareObject ($ data );
186- $ this ->removeShareFromTable ($ brokenShare );
187- list ($ shareId , $ send ) = $ this ->createFederatedShare ($ share );
181+ $ this ->removeShareFromTable ($ share );
182+ $ this ->createFederatedShare ($ share );
188183 }
184+ if ($ send ) {
185+ $ this ->updateSuccessfulReshare ($ shareId , $ token );
186+ $ this ->storeRemoteId ($ shareId , $ remoteId );
187+ } else {
188+ $ this ->removeShareFromTable ($ share );
189+ $ message_t = $ this ->l ->t ('File is already shared with %s ' , [$ shareWith ]);
190+ throw new \Exception ($ message_t );
191+ }
192+
189193 } else {
190- list ( $ shareId , $ send ) = $ this ->createFederatedShare ($ share );
194+ $ this ->createFederatedShare ($ share );
191195 }
192196
193197 $ data = $ this ->getRawShare ($ shareId );
194- $ share = $ this ->createShareObject ($ data );
195-
196- if ($ send === false ) {
197- $ this ->removeShareFromTable ($ share );
198- $ message_t = $ this ->l ->t ('Sharing %s failed, could not find %s, maybe the server is currently unreachable. ' ,
199- [$ share ->getNode ()->getName (), $ shareWith ]);
200- throw new \Exception ($ message_t );
201- }
202-
203- return $ share ;
198+ return $ this ->createShareObject ($ data );
204199 }
205200
206201 /**
207202 * create federated share and inform the recipient
208203 *
209204 * @param IShare $share
210205 * @return array
206+ * @throws ShareNotFound
207+ * @throws \Exception
211208 */
212209 protected function createFederatedShare (IShare $ share ) {
213210 $ token = $ this ->tokenHandler ->generateToken ();
@@ -235,7 +232,15 @@ protected function createFederatedShare(IShare $share) {
235232 $ sharedByFederatedId
236233 );
237234
238- return [$ shareId , $ send ];
235+ if ($ send === false ) {
236+ $ data = $ this ->getRawShare ($ shareId );
237+ $ share = $ this ->createShareObject ($ data );
238+ $ this ->removeShareFromTable ($ share );
239+ $ message_t = $ this ->l ->t ('Sharing %s failed, could not find %s, maybe the server is currently unreachable. ' ,
240+ [$ share ->getNode ()->getName (), $ share ->getSharedWith ()]);
241+ throw new \Exception ($ message_t );
242+ }
243+
239244 }
240245
241246 /**
0 commit comments