@@ -1233,6 +1233,71 @@ protected function deleteChildren(IShare $share) {
12331233 return $ deletedShares ;
12341234 }
12351235
1236+ protected function deleteReshare (IShare $ share ) {
1237+ // If the user has another shares, we don't delete the shares by this user
1238+ if ($ share ->getShareType () === IShare::TYPE_USER ) {
1239+ $ groupShares = $ this ->getSharedWith ($ share ->getSharedWith (), IShare::TYPE_GROUP , $ share ->getNode (), -1 , 0 );
1240+
1241+ if (count ($ groupShares ) !== 0 ) {
1242+ return ;
1243+ }
1244+ }
1245+
1246+ // Delete re-share records (shared by "share with user") inside folder
1247+ if ($ share ->getNodeType () === 'folder ' && $ share ->getShareType () === IShare::TYPE_USER ) {
1248+ $ sharesInFolder = $ this ->getSharesInFolder ($ share ->getSharedWith (), $ share ->getNode (), true , false );
1249+
1250+ foreach ($ sharesInFolder as $ nodeId => $ shares ) {
1251+ foreach ($ shares as $ child ) {
1252+ $ this ->deleteShare ($ child );
1253+ }
1254+ }
1255+ }
1256+
1257+ $ shareTypes = [
1258+ IShare::TYPE_GROUP ,
1259+ IShare::TYPE_USER ,
1260+ IShare::TYPE_LINK ,
1261+ IShare::TYPE_REMOTE ,
1262+ IShare::TYPE_EMAIL
1263+ ];
1264+
1265+ // Delete re-share records which shared by "share with user"
1266+ if ($ share ->getShareType () === IShare::TYPE_USER || $ share ->getShareType () === IShare::TYPE_USERGROUP ) {
1267+ foreach ($ shareTypes as $ shareType ) {
1268+ $ provider = $ this ->factory ->getProviderForType ($ shareType );
1269+ $ shares = $ provider ->getSharesBy ($ share ->getSharedWith (), $ shareType , $ share ->getNode (), false , -1 , 0 );
1270+ foreach ($ shares as $ child ) {
1271+ $ this ->deleteShare ($ child );
1272+ }
1273+ }
1274+ }
1275+
1276+ // Delete re-share records which shared by users in "share with group"
1277+ if ($ share ->getShareType () === IShare::TYPE_GROUP ) {
1278+ $ group = $ this ->groupManager ->get ($ share ->getSharedWith ());
1279+ $ users = $ group ->getUsers ();
1280+
1281+ foreach ($ users as $ user ) {
1282+ $ anotherShares = $ this ->getSharedWith ($ user ->getUID (), IShare::TYPE_USER , $ share ->getNode (), -1 , 0 );
1283+ $ groupShares = $ this ->getSharedWith ($ user ->getUID (), IShare::TYPE_GROUP , $ share ->getNode (), -1 , 0 );
1284+
1285+ // If the user has another shares, we don't delete the shares by this user
1286+ if (count ($ anotherShares ) !== 0 || count ($ groupShares ) > 1 ) {
1287+ continue ;
1288+ }
1289+
1290+ foreach ($ shareTypes as $ shareType ) {
1291+ $ provider = $ this ->factory ->getProviderForType ($ shareType );
1292+ $ shares = $ provider ->getSharesBy ($ user ->getUID (), $ shareType , $ share ->getNode (), false , -1 , 0 );
1293+ foreach ($ shares as $ child ) {
1294+ $ this ->deleteShare ($ child );
1295+ }
1296+ }
1297+ }
1298+ }
1299+ }
1300+
12361301 /**
12371302 * Delete a share
12381303 *
@@ -1249,6 +1314,9 @@ public function deleteShare(IShare $share) {
12491314
12501315 $ this ->dispatcher ->dispatchTyped (new BeforeShareDeletedEvent ($ share ));
12511316
1317+ // Delete shares that shared by the "share with user/group"
1318+ $ this ->deleteReshare ($ share );
1319+
12521320 // Get all children and delete them as well
12531321 $ this ->deleteChildren ($ share );
12541322
0 commit comments