Skip to content

Commit

Permalink
fix tag population for the shares of the same file
Browse files Browse the repository at this point in the history
  • Loading branch information
karakayasemi committed Mar 6, 2020
1 parent d797555 commit 6ba198c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 29 deletions.
40 changes: 13 additions & 27 deletions apps/files/lib/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,42 +207,28 @@ public static function getFiles($dir, $sortAttribute = 'name', $sortDescending =
/**
* Populate the result set with file tags
*
* @param array $fileList
* @param string $fileIdentifier identifier attribute name for values in $fileList
* @return array file list populated with tags
* @param array $shareList
* @return array share list populated with tags
*/
public static function populateTags(array $fileList, $fileIdentifier = 'fileid') {
$filesById = [];
foreach ($fileList as $fileData) {
$filesById[$fileData[$fileIdentifier]] = $fileData;
public static function populateTagsForShares($shareList) {
$fileIdList = [];
foreach ($shareList as $share) {
$fileIdList[] = $share['file_source'];
}
$fileIdList = \array_unique($fileIdList);
$tagger = \OC::$server->getTagManager()->load('files');
$tags = $tagger->getTagsForObjects(\array_keys($filesById));

$tags = $tagger->getTagsForObjects($fileIdList);
if (!\is_array($tags)) {
throw new \UnexpectedValueException('$tags must be an array');
}

if (!empty($tags)) {
foreach ($tags as $fileId => $fileTags) {
$filesById[$fileId]['tags'] = $fileTags;
}

foreach ($filesById as $key => $fileWithTags) {
foreach ($fileList as $key2 => $file) {
if ($file[$fileIdentifier] == $key) {
$fileList[$key2] = $fileWithTags;
}
}
}

foreach ($fileList as $key => $file) {
if (!\array_key_exists('tags', $file)) {
$fileList[$key]['tags'] = [];
}
foreach ($shareList as $key => $share) {
$shareList[$key]['tags'] = [];
if (\array_key_exists($share['file_source'], $tags)) {
$shareList[$key]['tags'] = $tags[$share['file_source']];
}
}
return $fileList;
return $shareList;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions apps/files_sharing/lib/Controller/Share20OcsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ private function getSharedWithMe($node = null, $includeTags, $stateFilter = 0) {
}

if ($includeTags) {
$formatted = \OCA\Files\Helper::populateTags($formatted, 'file_source');
$formatted = \OCA\Files\Helper::populateTagsForShares($formatted);
}

return new Result($formatted);
Expand Down Expand Up @@ -716,7 +716,7 @@ public function getShares() {
}

if ($includeTags) {
$formatted = \OCA\Files\Helper::populateTags($formatted, 'file_source');
$formatted = \OCA\Files\Helper::populateTagsForShares($formatted);
}

if ($path !== null) {
Expand Down

0 comments on commit 6ba198c

Please sign in to comment.