diff options
author | Vincent Petry <pvince81@owncloud.com> | 2016-08-12 12:06:57 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2016-08-17 15:31:36 +0200 |
commit | 7a2d25fab4bb2b452b513e41adda4dec68e81bbe (patch) | |
tree | 1dbcf4456f800f4584f8339f50ce4b401aa4b0f8 /lib | |
parent | 56b94b220da4d947438ffee7a4e889ef7f61bbde (diff) | |
download | nextcloud-server-7a2d25fab4bb2b452b513e41adda4dec68e81bbe.tar.gz nextcloud-server-7a2d25fab4bb2b452b513e41adda4dec68e81bbe.zip |
Fix unmerged shares repair with mixed group and direct shares
Whenever a group share is created after a direct share, the stime order
needs to be properly considered in the repair routine, considering that
the direct user share is appended to the $subShares array and breaking
its order.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Repair/RepairUnmergedShares.php | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/private/Repair/RepairUnmergedShares.php b/lib/private/Repair/RepairUnmergedShares.php index f14e98c1761..c29de87c4e8 100644 --- a/lib/private/Repair/RepairUnmergedShares.php +++ b/lib/private/Repair/RepairUnmergedShares.php @@ -93,7 +93,7 @@ class RepairUnmergedShares implements IRepairStep { */ $query = $this->connection->getQueryBuilder(); $query - ->select('item_source', 'id', 'file_target', 'permissions', 'parent', 'share_type') + ->select('item_source', 'id', 'file_target', 'permissions', 'parent', 'share_type', 'stime') ->from('share') ->where($query->expr()->eq('share_type', $query->createParameter('shareType'))) ->andWhere($query->expr()->in('share_with', $query->createParameter('shareWiths'))) @@ -161,13 +161,23 @@ class RepairUnmergedShares implements IRepairStep { * If no suitable subshare is found, use the least recent group share instead. * * @param array $groupShares group share entries - * @param array $subShares sub share entries, sorted by stime + * @param array $subShares sub share entries * * @return string chosen target name */ private function findBestTargetName($groupShares, $subShares) { $pickedShare = null; - // note subShares are sorted by stime from oldest to newest + // sort by stime, this also properly sorts the direct user share if any + @usort($subShares, function($a, $b) { + if ($a['stime'] < $b['stime']) { + return -1; + } else if ($a['stime'] > $b['stime']) { + return 1; + } + + return 0; + }); + foreach ($subShares as $subShare) { // skip entries that have parenthesis with numbers if (preg_match('/\([0-9]*\)/', $subShare['file_target']) === 1) { |