@@ -160,30 +160,29 @@ public function create(IShare $share) {
160160 $ share ->setSharedWith ($ cloudId ->getId ());
161161
162162 try {
163- $ remoteShare = $ this ->getShareFromExternalShareTable ($ share );
163+ $ remoteShare = $ this ->getShareFromExternalShareTable ($ share-> getShareOwner (), $ share -> getTarget () );
164164 } catch (ShareNotFound $ e ) {
165165 $ remoteShare = null ;
166166 }
167167
168168 if ($ remoteShare ) {
169- try {
170- $ ownerCloudId = $ this ->cloudIdManager ->getCloudId ($ remoteShare ['owner ' ], $ remoteShare ['remote ' ]);
171- $ shareId = $ this ->addShareToDB ($ itemSource , $ itemType , $ shareWith , $ sharedBy , $ ownerCloudId ->getId (), $ permissions , 'tmp_token_ ' . time (), $ shareType , $ expirationDate );
172- $ share ->setId ($ shareId );
173- [$ token , $ remoteId ] = $ this ->askOwnerToReShare ($ shareWith , $ share , $ shareId );
174- // remote share was create successfully if we get a valid token as return
175- $ send = is_string ($ token ) && $ token !== '' ;
176- } catch (\Exception $ e ) {
177- // fall back to old re-share behavior if the remote server
178- // doesn't support flat re-shares (was introduced with Nextcloud 9.1)
179- $ this ->removeShareFromTable ($ share );
180- $ shareId = $ this ->createFederatedShare ($ share );
181- }
182- if ($ send ) {
169+ $ ownerCloudId = $ this ->cloudIdManager ->getCloudId ($ remoteShare ['owner ' ], $ remoteShare ['remote ' ]);
170+ $ shareId = $ this ->addShareToDB ($ itemSource , $ itemType , $ shareWith , $ sharedBy , $ ownerCloudId ->getId (), $ permissions , 'tmp_token_ ' . time (), $ shareType , $ expirationDate );
171+ [$ token , $ remoteId ] = $ this ->notifications ->requestReShare (
172+ $ remoteShare ['share_token ' ],
173+ $ remoteShare ['remote_id ' ],
174+ $ shareId ,
175+ $ remoteShare ['remote ' ],
176+ $ shareWith ,
177+ $ permissions ,
178+ $ share ->getNode ()->getName (),
179+ );
180+ // remote share was create successfully if we get a valid token as return
181+ if (is_string ($ token ) && $ token !== '' ) {
183182 $ this ->updateSuccessfulReshare ($ shareId , $ token );
184183 $ this ->storeRemoteId ($ shareId , $ remoteId );
185184 } else {
186- $ this ->removeShareFromTable ($ share );
185+ $ this ->removeShareFromTable ($ shareId );
187186 $ message_t = $ this ->l ->t ('File is already shared with %s ' , [$ shareWith ]);
188187 throw new \Exception ($ message_t );
189188 }
@@ -250,7 +249,7 @@ protected function createFederatedShare(IShare $share) {
250249 }
251250
252251 if ($ failure ) {
253- $ this ->removeShareFromTableById ($ shareId );
252+ $ this ->removeShareFromTable ($ shareId );
254253 $ message_t = $ this ->l ->t ('Sharing %1$s failed, could not find %2$s, maybe the server is currently unreachable or uses a self-signed certificate. ' ,
255254 [$ share ->getNode ()->getName (), $ share ->getSharedWith ()]);
256255 throw new \Exception ($ message_t );
@@ -259,45 +258,18 @@ protected function createFederatedShare(IShare $share) {
259258 return $ shareId ;
260259 }
261260
262- /**
263- * @param string $shareWith
264- * @param IShare $share
265- * @param string $shareId internal share Id
266- * @return array
267- * @throws \Exception
268- */
269- protected function askOwnerToReShare ($ shareWith , IShare $ share , $ shareId ) {
270- $ remoteShare = $ this ->getShareFromExternalShareTable ($ share );
271- $ token = $ remoteShare ['share_token ' ];
272- $ remoteId = $ remoteShare ['remote_id ' ];
273- $ remote = $ remoteShare ['remote ' ];
274-
275- [$ token , $ remoteId ] = $ this ->notifications ->requestReShare (
276- $ token ,
277- $ remoteId ,
278- $ shareId ,
279- $ remote ,
280- $ shareWith ,
281- $ share ->getPermissions (),
282- $ share ->getNode ()->getName ()
283- );
284-
285- return [$ token , $ remoteId ];
286- }
287-
288261 /**
289262 * get federated share from the share_external table but exclude mounted link shares
290263 *
291- * @param IShare $share
292264 * @return array
293265 * @throws ShareNotFound
294266 */
295- protected function getShareFromExternalShareTable (IShare $ share ) {
267+ protected function getShareFromExternalShareTable (string $ owner , string $ target ) {
296268 $ query = $ this ->dbConnection ->getQueryBuilder ();
297269 $ query ->select ('* ' )->from ($ this ->externalShareTable )
298- ->where ($ query ->expr ()->eq ('user ' , $ query ->createNamedParameter ($ share -> getShareOwner () )))
299- ->andWhere ($ query ->expr ()->eq ('mountpoint ' , $ query ->createNamedParameter ($ share -> getTarget () )));
300- $ qResult = $ query ->execute ();
270+ ->where ($ query ->expr ()->eq ('user ' , $ query ->createNamedParameter ($ owner )))
271+ ->andWhere ($ query ->expr ()->eq ('mountpoint ' , $ query ->createNamedParameter ($ target )));
272+ $ qResult = $ query ->executeQuery ();
301273 $ result = $ qResult ->fetchAll ();
302274 $ qResult ->closeCursor ();
303275
@@ -319,7 +291,7 @@ protected function getShareFromExternalShareTable(IShare $share) {
319291 * @param int $permissions
320292 * @param string $token
321293 * @param int $shareType
322- * @param \DateTime $expirationDate
294+ * @param ? \DateTime $expirationDate
323295 * @return int
324296 */
325297 private function addShareToDB ($ itemSource , $ itemType , $ shareWith , $ sharedBy , $ uidOwner , $ permissions , $ token , $ shareType , $ expirationDate ) {
@@ -505,7 +477,7 @@ public function delete(IShare $share) {
505477
506478 // only remove the share when all messages are send to not lose information
507479 // about the share to early
508- $ this ->removeShareFromTable ($ share );
480+ $ this ->removeShareFromTable (( int ) $ share-> getId () );
509481 }
510482
511483 /**
@@ -536,20 +508,9 @@ protected function revokeShare($share, $isOwner) {
536508 }
537509
538510 /**
539- * remove share from table
540- *
541- * @param IShare $share
542- */
543- public function removeShareFromTable (IShare $ share ) {
544- $ this ->removeShareFromTableById ($ share ->getId ());
545- }
546-
547- /**
548- * remove share from table
549- *
550- * @param string $shareId
511+ * Remove share from table.
551512 */
552- private function removeShareFromTableById ( $ shareId ) {
513+ public function removeShareFromTable ( int $ shareId ): void {
553514 $ qb = $ this ->dbConnection ->getQueryBuilder ();
554515 $ qb ->delete ('share ' )
555516 ->where ($ qb ->expr ()->eq ('id ' , $ qb ->createNamedParameter ($ shareId )))
0 commit comments