-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[stable9.1] Fix unmerged shares repair targetdecision #25812
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,7 +93,7 @@ private function buildPreparedQueries() { | |
*/ | ||
$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'))) | ||
|
@@ -148,6 +148,54 @@ private function getSharesWithUser($shareType, $shareWiths) { | |
return $groupedShares; | ||
} | ||
|
||
/** | ||
* Decide on the best target name based on all group shares and subshares, | ||
* goal is to increase the likeliness that the chosen name matches what | ||
* the user is expecting. | ||
* | ||
* For this, we discard the entries with parenthesis "(2)". | ||
* In case the user also renamed the duplicates to a legitimate name, this logic | ||
* will still pick the most recent one as it's the one the user is most likely to | ||
* remember renaming. | ||
* | ||
* 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 | ||
* | ||
* @return string chosen target name | ||
*/ | ||
private function findBestTargetName($groupShares, $subShares) { | ||
$pickedShare = null; | ||
// 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we might be matching more entries than we should. Some files that would match:
Maybe a regex like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, the reason I decided against adding a "$" was so we can also match "test (2).txt". Maybe I should spend the time to build a proper regexp then... or trim the extension before checking ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After checking how the names are generated,
but not
|
||
continue; | ||
} | ||
// pick any share found that would match, the last being the most recent | ||
$pickedShare = $subShare; | ||
} | ||
|
||
// no suitable subshare found | ||
if ($pickedShare === null) { | ||
// use least recent group share target instead | ||
$pickedShare = $groupShares[0]; | ||
} | ||
|
||
return $pickedShare['file_target']; | ||
} | ||
|
||
/** | ||
* Fix the given received share represented by the set of group shares | ||
* and matching sub shares | ||
|
@@ -171,7 +219,7 @@ private function fixThisShare($groupShares, $subShares) { | |
return false; | ||
} | ||
|
||
$targetPath = $groupShares[0]['file_target']; | ||
$targetPath = $this->findBestTargetName($groupShares, $subShares); | ||
|
||
// check whether the user opted out completely of all subshares | ||
$optedOut = true; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth to consider this solution to sort this: http://stackoverflow.com/a/2852918